Completed
Branch TASK-10784-decaf-about-page (d55fb3)
by
unknown
130:57 queued 118:59
created
core/EE_System.core.php 2 patches
Indentation   +1407 added lines, -1407 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,1412 +19,1412 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
-     */
26
-    const req_type_normal = 0;
27
-
28
-    /**
29
-     * Indicates this is a brand new installation of EE so we should install
30
-     * tables and default data etc
31
-     */
32
-    const req_type_new_activation = 1;
33
-
34
-    /**
35
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
-     * and we just exited maintenance mode). We MUST check the database is setup properly
37
-     * and that default data is setup too
38
-     */
39
-    const req_type_reactivation = 2;
40
-
41
-    /**
42
-     * indicates that EE has been upgraded since its previous request.
43
-     * We may have data migration scripts to call and will want to trigger maintenance mode
44
-     */
45
-    const req_type_upgrade = 3;
46
-
47
-    /**
48
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
-     */
50
-    const req_type_downgrade = 4;
51
-
52
-    /**
53
-     * @deprecated since version 4.6.0.dev.006
54
-     * Now whenever a new_activation is detected the request type is still just
55
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
-     * (Specifically, when the migration manager indicates migrations are finished
59
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
-     */
61
-    const req_type_activation_but_not_installed = 5;
62
-
63
-    /**
64
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
-     */
66
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
-
68
-
69
-    /**
70
-     *    instance of the EE_System object
71
-     *
72
-     * @var    $_instance
73
-     * @access    private
74
-     */
75
-    private static $_instance = null;
76
-
77
-    /**
78
-     * @type  EE_Registry $Registry
79
-     * @access    protected
80
-     */
81
-    protected $registry;
82
-
83
-    /**
84
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
-     *
87
-     * @var int
88
-     */
89
-    private $_req_type;
90
-
91
-    /**
92
-     * Whether or not there was a non-micro version change in EE core version during this request
93
-     *
94
-     * @var boolean
95
-     */
96
-    private $_major_version_change = false;
97
-
98
-
99
-
100
-    /**
101
-     * @singleton method used to instantiate class object
102
-     * @access    public
103
-     * @param  \EE_Registry $Registry
104
-     * @return \EE_System
105
-     */
106
-    public static function instance(EE_Registry $Registry = null)
107
-    {
108
-        // check if class object is instantiated
109
-        if ( ! self::$_instance instanceof EE_System) {
110
-            self::$_instance = new self($Registry);
111
-        }
112
-        return self::$_instance;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * resets the instance and returns it
119
-     *
120
-     * @return EE_System
121
-     */
122
-    public static function reset()
123
-    {
124
-        self::$_instance->_req_type = null;
125
-        //make sure none of the old hooks are left hanging around
126
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
-        //we need to reset the migration manager in order for it to detect DMSs properly
128
-        EE_Data_Migration_Manager::reset();
129
-        self::instance()->detect_activations_or_upgrades();
130
-        self::instance()->perform_activations_upgrades_and_migrations();
131
-        return self::instance();
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     *    sets hooks for running rest of system
138
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
-     *    starting EE Addons from any other point may lead to problems
140
-     *
141
-     * @access private
142
-     * @param  \EE_Registry $Registry
143
-     */
144
-    private function __construct(EE_Registry $Registry)
145
-    {
146
-        $this->registry = $Registry;
147
-        do_action('AHEE__EE_System__construct__begin', $this);
148
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
-        // when an ee addon is activated, we want to call the core hook(s) again
151
-        // because the newly-activated addon didn't get a chance to run at all
152
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
-        // detect whether install or upgrade
154
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
-            3);
156
-        // load EE_Config, EE_Textdomain, etc
157
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
-        // load EE_Config, EE_Textdomain, etc
159
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
-        // you wanna get going? I wanna get going... let's get going!
162
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
-        //other housekeeping
164
-        //exclude EE critical pages from wp_list_pages
165
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
-        // ALL EE Addons should use the following hook point to attach their initial setup too
167
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
-        do_action('AHEE__EE_System__construct__complete', $this);
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * load_espresso_addons
175
-     * allow addons to load first so that they can set hooks for running DMS's, etc
176
-     * this is hooked into both:
177
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
178
-     *        which runs during the WP 'plugins_loaded' action at priority 5
179
-     *    and the WP 'activate_plugin' hookpoint
180
-     *
181
-     * @access public
182
-     * @return void
183
-     */
184
-    public function load_espresso_addons()
185
-    {
186
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
187
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
-        //load and setup EE_Capabilities
190
-        $this->registry->load_core('Capabilities');
191
-        //caps need to be initialized on every request so that capability maps are set.
192
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
-        $this->registry->CAP->init_caps();
194
-        do_action('AHEE__EE_System__load_espresso_addons');
195
-        //if the WP API basic auth plugin isn't already loaded, load it now.
196
-        //We want it for mobile apps. Just include the entire plugin
197
-        //also, don't load the basic auth when a plugin is getting activated, because
198
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
-        //and causes a fatal error
200
-        if ( ! function_exists('json_basic_auth_handler')
201
-             && ! function_exists('json_basic_auth_error')
202
-             && ! (
203
-                isset($_GET['action'])
204
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
205
-            )
206
-             && ! (
207
-                isset($_GET['activate'])
208
-                && $_GET['activate'] === 'true'
209
-            )
210
-        ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
-        }
213
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * detect_activations_or_upgrades
220
-     * Checks for activation or upgrade of core first;
221
-     * then also checks if any registered addons have been activated or upgraded
222
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
-     * which runs during the WP 'plugins_loaded' action at priority 3
224
-     *
225
-     * @access public
226
-     * @return void
227
-     */
228
-    public function detect_activations_or_upgrades()
229
-    {
230
-        //first off: let's make sure to handle core
231
-        $this->detect_if_activation_or_upgrade();
232
-        foreach ($this->registry->addons as $addon) {
233
-            //detect teh request type for that addon
234
-            $addon->detect_activation_or_upgrade();
235
-        }
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * detect_if_activation_or_upgrade
242
-     * Takes care of detecting whether this is a brand new install or code upgrade,
243
-     * and either setting up the DB or setting up maintenance mode etc.
244
-     *
245
-     * @access public
246
-     * @return void
247
-     */
248
-    public function detect_if_activation_or_upgrade()
249
-    {
250
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
-        // load M-Mode class
252
-        $this->registry->load_core('Maintenance_Mode');
253
-        // check if db has been updated, or if its a brand-new installation
254
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
-        $request_type = $this->detect_req_type($espresso_db_update);
256
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
-        switch ($request_type) {
258
-            case EE_System::req_type_new_activation:
259
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
-                $this->_handle_core_version_change($espresso_db_update);
261
-                break;
262
-            case EE_System::req_type_reactivation:
263
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
-                $this->_handle_core_version_change($espresso_db_update);
265
-                break;
266
-            case EE_System::req_type_upgrade:
267
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
-                //migrations may be required now that we've upgraded
269
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
-                $this->_handle_core_version_change($espresso_db_update);
271
-                //				echo "done upgrade";die;
272
-                break;
273
-            case EE_System::req_type_downgrade:
274
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
-                //its possible migrations are no longer required
276
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
-                $this->_handle_core_version_change($espresso_db_update);
278
-                break;
279
-            case EE_System::req_type_normal:
280
-            default:
281
-                //				$this->_maybe_redirect_to_ee_about();
282
-                break;
283
-        }
284
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Updates the list of installed versions and sets hooks for
291
-     * initializing the database later during the request
292
-     *
293
-     * @param array $espresso_db_update
294
-     */
295
-    protected function _handle_core_version_change($espresso_db_update)
296
-    {
297
-        $this->update_list_of_installed_versions($espresso_db_update);
298
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
-            array($this, 'initialize_db_if_no_migrations_required'));
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
-     * information about what versions of EE have been installed and activated,
308
-     * NOT necessarily the state of the database
309
-     *
310
-     * @param null $espresso_db_update
311
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
-     *           from the options table
313
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
-     */
315
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
-    {
317
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
-        if ( ! $espresso_db_update) {
319
-            $espresso_db_update = get_option('espresso_db_update');
320
-        }
321
-        // check that option is an array
322
-        if ( ! is_array($espresso_db_update)) {
323
-            // if option is FALSE, then it never existed
324
-            if ($espresso_db_update === false) {
325
-                // make $espresso_db_update an array and save option with autoload OFF
326
-                $espresso_db_update = array();
327
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
-            } else {
329
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
330
-                $espresso_db_update = array($espresso_db_update => array());
331
-                update_option('espresso_db_update', $espresso_db_update);
332
-            }
333
-        } else {
334
-            $corrected_db_update = array();
335
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
-                    //the key is an int, and the value IS NOT an array
339
-                    //so it must be numerically-indexed, where values are versions installed...
340
-                    //fix it!
341
-                    $version_string = $should_be_array;
342
-                    $corrected_db_update[$version_string] = array('unknown-date');
343
-                } else {
344
-                    //ok it checks out
345
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
346
-                }
347
-            }
348
-            $espresso_db_update = $corrected_db_update;
349
-            update_option('espresso_db_update', $espresso_db_update);
350
-        }
351
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
-        return $espresso_db_update;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Does the traditional work of setting up the plugin's database and adding default data.
359
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
-     * so that it will be done when migrations are finished
363
-     *
364
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
-     *                                       This is a resource-intensive job
367
-     *                                       so we prefer to only do it when necessary
368
-     * @return void
369
-     */
370
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
-    {
372
-        $request_type = $this->detect_req_type();
373
-        //only initialize system if we're not in maintenance mode.
374
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
-            update_option('ee_flush_rewrite_rules', true);
376
-            if ($verify_schema) {
377
-                EEH_Activation::initialize_db_and_folders();
378
-            }
379
-            EEH_Activation::initialize_db_content();
380
-            EEH_Activation::system_initialization();
381
-            if ($initialize_addons_too) {
382
-                $this->initialize_addons();
383
-            }
384
-        } else {
385
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
-        }
387
-        if ($request_type === EE_System::req_type_new_activation
388
-            || $request_type === EE_System::req_type_reactivation
389
-            || (
390
-                $request_type === EE_System::req_type_upgrade
391
-                && $this->is_major_version_change()
392
-            )
393
-        ) {
394
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
-        }
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Initializes the db for all registered addons
402
-     */
403
-    public function initialize_addons()
404
-    {
405
-        //foreach registered addon, make sure its db is up-to-date too
406
-        foreach ($this->registry->addons as $addon) {
407
-            $addon->initialize_db_if_no_migrations_required();
408
-        }
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
-     *
416
-     * @param    array  $version_history
417
-     * @param    string $current_version_to_add version to be added to the version history
418
-     * @return    boolean success as to whether or not this option was changed
419
-     */
420
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
-    {
422
-        if ( ! $version_history) {
423
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
-        }
425
-        if ($current_version_to_add == null) {
426
-            $current_version_to_add = espresso_version();
427
-        }
428
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
-        // re-save
430
-        return update_option('espresso_db_update', $version_history);
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * Detects if the current version indicated in the has existed in the list of
437
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
-     *
439
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
-     *                                  If not supplied, fetches it from the options table.
441
-     *                                  Also, caches its result so later parts of the code can also know whether
442
-     *                                  there's been an update or not. This way we can add the current version to
443
-     *                                  espresso_db_update, but still know if this is a new install or not
444
-     * @return int one of the constants on EE_System::req_type_
445
-     */
446
-    public function detect_req_type($espresso_db_update = null)
447
-    {
448
-        if ($this->_req_type === null) {
449
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
-                : $this->fix_espresso_db_upgrade_option();
451
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
-                'ee_espresso_activation', espresso_version());
453
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
-        }
455
-        return $this->_req_type;
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * Returns whether or not there was a non-micro version change (ie, change in either
462
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
-     *
465
-     * @param $activation_history
466
-     * @return bool
467
-     */
468
-    protected function _detect_major_version_change($activation_history)
469
-    {
470
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
-        $previous_version_parts = explode('.', $previous_version);
472
-        $current_version_parts = explode('.', espresso_version());
473
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
-               && ($previous_version_parts[0] !== $current_version_parts[0]
475
-                   || $previous_version_parts[1] !== $current_version_parts[1]
476
-               );
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Returns true if either the major or minor version of EE changed during this request.
483
-     * 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
484
-     *
485
-     * @return bool
486
-     */
487
-    public function is_major_version_change()
488
-    {
489
-        return $this->_major_version_change;
490
-    }
491
-
492
-
493
-
494
-    /**
495
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
-     * just activated to (for core that will always be espresso_version())
499
-     *
500
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
-     *                                                 ee plugin. for core that's 'espresso_db_update'
502
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
-     *                                                 indicate that this plugin was just activated
504
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
-     *                                                 espresso_version())
506
-     * @return int one of the constants on EE_System::req_type_*
507
-     */
508
-    public static function detect_req_type_given_activation_history(
509
-        $activation_history_for_addon,
510
-        $activation_indicator_option_name,
511
-        $version_to_upgrade_to
512
-    ) {
513
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
-        if ($activation_history_for_addon) {
515
-            //it exists, so this isn't a completely new install
516
-            //check if this version already in that list of previously installed versions
517
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
-                //it a version we haven't seen before
519
-                if ($version_is_higher === 1) {
520
-                    $req_type = EE_System::req_type_upgrade;
521
-                } else {
522
-                    $req_type = EE_System::req_type_downgrade;
523
-                }
524
-                delete_option($activation_indicator_option_name);
525
-            } else {
526
-                // its not an update. maybe a reactivation?
527
-                if (get_option($activation_indicator_option_name, false)) {
528
-                    if ($version_is_higher === -1) {
529
-                        $req_type = EE_System::req_type_downgrade;
530
-                    } elseif ($version_is_higher === 0) {
531
-                        //we've seen this version before, but it's an activation. must be a reactivation
532
-                        $req_type = EE_System::req_type_reactivation;
533
-                    } else {//$version_is_higher === 1
534
-                        $req_type = EE_System::req_type_upgrade;
535
-                    }
536
-                    delete_option($activation_indicator_option_name);
537
-                } else {
538
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
539
-                    if ($version_is_higher === -1) {
540
-                        $req_type = EE_System::req_type_downgrade;
541
-                    } elseif ($version_is_higher === 0) {
542
-                        //we've seen this version before and it's not an activation. its normal request
543
-                        $req_type = EE_System::req_type_normal;
544
-                    } else {//$version_is_higher === 1
545
-                        $req_type = EE_System::req_type_upgrade;
546
-                    }
547
-                }
548
-            }
549
-        } else {
550
-            //brand new install
551
-            $req_type = EE_System::req_type_new_activation;
552
-            delete_option($activation_indicator_option_name);
553
-        }
554
-        return $req_type;
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
-     * the $activation_history_for_addon
562
-     *
563
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
-     *                                             sometimes containing 'unknown-date'
565
-     * @param string $version_to_upgrade_to        (current version)
566
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
-     */
571
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
-    {
573
-        //find the most recently-activated version
574
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * Gets the most recently active version listed in the activation history,
582
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
-     *
584
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
-     *                                   sometimes containing 'unknown-date'
586
-     * @return string
587
-     */
588
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
-    {
590
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
591
-        $most_recently_active_version = '0.0.0.dev.000';
592
-        if (is_array($activation_history)) {
593
-            foreach ($activation_history as $version => $times_activated) {
594
-                //check there is a record of when this version was activated. Otherwise,
595
-                //mark it as unknown
596
-                if ( ! $times_activated) {
597
-                    $times_activated = array('unknown-date');
598
-                }
599
-                if (is_string($times_activated)) {
600
-                    $times_activated = array($times_activated);
601
-                }
602
-                foreach ($times_activated as $an_activation) {
603
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
-                        $most_recently_active_version = $version;
605
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
606
-                            ? '1970-01-01 00:00:00' : $an_activation;
607
-                    }
608
-                }
609
-            }
610
-        }
611
-        return $most_recently_active_version;
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This redirects to the about EE page after activation
618
-     *
619
-     * @return void
620
-     */
621
-    public function redirect_to_about_ee()
622
-    {
623
-        $notices = EE_Error::get_notices(false);
624
-        //if current user is an admin and it's not an ajax or rest request
625
-        if (
626
-            ! (defined('DOING_AJAX') && DOING_AJAX)
627
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
628
-            && ! isset($notices['errors'])
629
-            && apply_filters(
630
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
-            )
633
-        ) {
634
-            $query_params = array('page' => 'espresso_about');
635
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
-                $query_params['new_activation'] = true;
637
-            }
638
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
-                $query_params['reactivation'] = true;
640
-            }
641
-            $url = add_query_arg($query_params, admin_url('admin.php'));
642
-            wp_safe_redirect($url);
643
-            exit();
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * load_core_configuration
651
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
-     * which runs during the WP 'plugins_loaded' action at priority 5
653
-     *
654
-     * @return void
655
-     */
656
-    public function load_core_configuration()
657
-    {
658
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
-        $this->registry->load_core('EE_Load_Textdomain');
660
-        //load textdomain
661
-        EE_Load_Textdomain::load_textdomain();
662
-        // load and setup EE_Config and EE_Network_Config
663
-        $this->registry->load_core('Config');
664
-        $this->registry->load_core('Network_Config');
665
-        // setup autoloaders
666
-        // enable logging?
667
-        if ($this->registry->CFG->admin->use_full_logging) {
668
-            $this->registry->load_core('Log');
669
-        }
670
-        // check for activation errors
671
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
672
-        if ($activation_errors) {
673
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
-            update_option('ee_plugin_activation_errors', false);
675
-        }
676
-        // get model names
677
-        $this->_parse_model_names();
678
-        //load caf stuff a chance to play during the activation process too.
679
-        $this->_maybe_brew_regular();
680
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
687
-     *
688
-     * @return void
689
-     */
690
-    private function _parse_model_names()
691
-    {
692
-        //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
694
-        $model_names = array();
695
-        $non_abstract_db_models = array();
696
-        foreach ($models as $model) {
697
-            // get model classname
698
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
-            $short_name = str_replace('EEM_', '', $classname);
700
-            $reflectionClass = new ReflectionClass($classname);
701
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
-                $non_abstract_db_models[$short_name] = $classname;
703
-            }
704
-            $model_names[$short_name] = $classname;
705
-        }
706
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
-            $non_abstract_db_models);
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
-     * that need to be setup before our EE_System launches.
716
-     *
717
-     * @return void
718
-     */
719
-    private function _maybe_brew_regular()
720
-    {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
723
-        }
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * register_shortcodes_modules_and_widgets
730
-     * generate lists of shortcodes and modules, then verify paths and classes
731
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
-     * which runs during the WP 'plugins_loaded' action at priority 7
733
-     *
734
-     * @access public
735
-     * @return void
736
-     */
737
-    public function register_shortcodes_modules_and_widgets()
738
-    {
739
-        try {
740
-            // load, register, and add shortcodes the new way
741
-            new ShortcodesManager(
742
-            // and the old way, but we'll put it under control of the new system
743
-                EE_Config::getLegacyShortcodesManager()
744
-            );
745
-        } catch (Exception $exception) {
746
-            new ExceptionStackTraceDisplay($exception);
747
-        }
748
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
-        // check for addons using old hookpoint
750
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
-            $this->_incompatible_addon_error();
752
-        }
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * _incompatible_addon_error
759
-     *
760
-     * @access public
761
-     * @return void
762
-     */
763
-    private function _incompatible_addon_error()
764
-    {
765
-        // get array of classes hooking into here
766
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
-        if ( ! empty($class_names)) {
768
-            $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:',
769
-                'event_espresso');
770
-            $msg .= '<ul>';
771
-            foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
774
-            }
775
-            $msg .= '</ul>';
776
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
-                'event_espresso');
778
-            // save list of incompatible addons to wp-options for later use
779
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
780
-            if (is_admin()) {
781
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
-            }
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * brew_espresso
790
-     * begins the process of setting hooks for initializing EE in the correct order
791
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
-     * which runs during the WP 'plugins_loaded' action at priority 9
793
-     *
794
-     * @return void
795
-     */
796
-    public function brew_espresso()
797
-    {
798
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
-        // load some final core systems
800
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
801
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
-        add_action('init', array($this, 'load_controllers'), 7);
804
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
-        add_action('init', array($this, 'initialize'), 10);
806
-        add_action('init', array($this, 'initialize_last'), 100);
807
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
-            // pew pew pew
810
-            $this->registry->load_core('PUE');
811
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
-        }
813
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     *    set_hooks_for_core
820
-     *
821
-     * @access public
822
-     * @return    void
823
-     */
824
-    public function set_hooks_for_core()
825
-    {
826
-        $this->_deactivate_incompatible_addons();
827
-        do_action('AHEE__EE_System__set_hooks_for_core');
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * Using the information gathered in EE_System::_incompatible_addon_error,
834
-     * deactivates any addons considered incompatible with the current version of EE
835
-     */
836
-    private function _deactivate_incompatible_addons()
837
-    {
838
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
839
-        if ( ! empty($incompatible_addons)) {
840
-            $active_plugins = get_option('active_plugins', array());
841
-            foreach ($active_plugins as $active_plugin) {
842
-                foreach ($incompatible_addons as $incompatible_addon) {
843
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
844
-                        unset($_GET['activate']);
845
-                        espresso_deactivate_plugin($active_plugin);
846
-                    }
847
-                }
848
-            }
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     *    perform_activations_upgrades_and_migrations
856
-     *
857
-     * @access public
858
-     * @return    void
859
-     */
860
-    public function perform_activations_upgrades_and_migrations()
861
-    {
862
-        //first check if we had previously attempted to setup EE's directories but failed
863
-        if (EEH_Activation::upload_directories_incomplete()) {
864
-            EEH_Activation::create_upload_directories();
865
-        }
866
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     *    load_CPTs_and_session
873
-     *
874
-     * @access public
875
-     * @return    void
876
-     */
877
-    public function load_CPTs_and_session()
878
-    {
879
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
-        // register Custom Post Types
881
-        $this->registry->load_core('Register_CPTs');
882
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * load_controllers
889
-     * this is the best place to load any additional controllers that needs access to EE core.
890
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
-     * time
892
-     *
893
-     * @access public
894
-     * @return void
895
-     */
896
-    public function load_controllers()
897
-    {
898
-        do_action('AHEE__EE_System__load_controllers__start');
899
-        // let's get it started
900
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
-            $this->registry->load_core('Front_Controller');
903
-        } else if ( ! EE_FRONT_AJAX) {
904
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
-            EE_Registry::instance()->load_core('Admin');
906
-        }
907
-        do_action('AHEE__EE_System__load_controllers__complete');
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * core_loaded_and_ready
914
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
-     *
916
-     * @access public
917
-     * @return void
918
-     */
919
-    public function core_loaded_and_ready()
920
-    {
921
-        $this->registry->load_core('Session');
922
-        do_action('AHEE__EE_System__core_loaded_and_ready');
923
-        // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
926
-        }
927
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
-        $this->registry->create('EventEspresso\core\services\assets\Registry');
929
-        wp_enqueue_script('espresso_core');
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * initialize
936
-     * this is the best place to begin initializing client code
937
-     *
938
-     * @access public
939
-     * @return void
940
-     */
941
-    public function initialize()
942
-    {
943
-        do_action('AHEE__EE_System__initialize');
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * initialize_last
950
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
951
-     * initialize has done so
952
-     *
953
-     * @access public
954
-     * @return void
955
-     */
956
-    public function initialize_last()
957
-    {
958
-        do_action('AHEE__EE_System__initialize_last');
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * set_hooks_for_shortcodes_modules_and_addons
965
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
966
-     * this happens at the very beginning of the wp_loaded hookpoint
967
-     *
968
-     * @access public
969
-     * @return void
970
-     */
971
-    public function set_hooks_for_shortcodes_modules_and_addons()
972
-    {
973
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * do_not_cache
980
-     * sets no cache headers and defines no cache constants for WP plugins
981
-     *
982
-     * @access public
983
-     * @return void
984
-     */
985
-    public static function do_not_cache()
986
-    {
987
-        // set no cache constants
988
-        if ( ! defined('DONOTCACHEPAGE')) {
989
-            define('DONOTCACHEPAGE', true);
990
-        }
991
-        if ( ! defined('DONOTCACHCEOBJECT')) {
992
-            define('DONOTCACHCEOBJECT', true);
993
-        }
994
-        if ( ! defined('DONOTCACHEDB')) {
995
-            define('DONOTCACHEDB', true);
996
-        }
997
-        // add no cache headers
998
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
999
-        // plus a little extra for nginx and Google Chrome
1000
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1001
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1002
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1003
-    }
1004
-
1005
-
1006
-
1007
-    /**
1008
-     *    extra_nocache_headers
1009
-     *
1010
-     * @access    public
1011
-     * @param $headers
1012
-     * @return    array
1013
-     */
1014
-    public static function extra_nocache_headers($headers)
1015
-    {
1016
-        // for NGINX
1017
-        $headers['X-Accel-Expires'] = 0;
1018
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1019
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1020
-        return $headers;
1021
-    }
1022
-
1023
-
1024
-
1025
-    /**
1026
-     *    nocache_headers
1027
-     *
1028
-     * @access    public
1029
-     * @return    void
1030
-     */
1031
-    public static function nocache_headers()
1032
-    {
1033
-        nocache_headers();
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     *    espresso_toolbar_items
1040
-     *
1041
-     * @access public
1042
-     * @param  WP_Admin_Bar $admin_bar
1043
-     * @return void
1044
-     */
1045
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1046
-    {
1047
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1048
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1049
-            || defined('DOING_AJAX')
1050
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1051
-        ) {
1052
-            return;
1053
-        }
1054
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1055
-        $menu_class = 'espresso_menu_item_class';
1056
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1057
-        //because they're only defined in each of their respective constructors
1058
-        //and this might be a frontend request, in which case they aren't available
1059
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1060
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1061
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1062
-        //Top Level
1063
-        $admin_bar->add_menu(array(
1064
-            'id'    => 'espresso-toolbar',
1065
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1066
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1067
-                       . '</span>',
1068
-            'href'  => $events_admin_url,
1069
-            'meta'  => array(
1070
-                'title' => __('Event Espresso', 'event_espresso'),
1071
-                'class' => $menu_class . 'first',
1072
-            ),
1073
-        ));
1074
-        //Events
1075
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1076
-            $admin_bar->add_menu(array(
1077
-                'id'     => 'espresso-toolbar-events',
1078
-                'parent' => 'espresso-toolbar',
1079
-                'title'  => __('Events', 'event_espresso'),
1080
-                'href'   => $events_admin_url,
1081
-                'meta'   => array(
1082
-                    'title'  => __('Events', 'event_espresso'),
1083
-                    'target' => '',
1084
-                    'class'  => $menu_class,
1085
-                ),
1086
-            ));
1087
-        }
1088
-        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1089
-            //Events Add New
1090
-            $admin_bar->add_menu(array(
1091
-                'id'     => 'espresso-toolbar-events-new',
1092
-                'parent' => 'espresso-toolbar-events',
1093
-                'title'  => __('Add New', 'event_espresso'),
1094
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1095
-                'meta'   => array(
1096
-                    'title'  => __('Add New', 'event_espresso'),
1097
-                    'target' => '',
1098
-                    'class'  => $menu_class,
1099
-                ),
1100
-            ));
1101
-        }
1102
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1103
-            //Current post
1104
-            global $post;
1105
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1106
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1107
-            ) {
1108
-                //Events Edit Current Event
1109
-                $admin_bar->add_menu(array(
1110
-                    'id'     => 'espresso-toolbar-events-edit',
1111
-                    'parent' => 'espresso-toolbar-events',
1112
-                    'title'  => __('Edit Event', 'event_espresso'),
1113
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1114
-                        $events_admin_url),
1115
-                    'meta'   => array(
1116
-                        'title'  => __('Edit Event', 'event_espresso'),
1117
-                        'target' => '',
1118
-                        'class'  => $menu_class,
1119
-                    ),
1120
-                ));
1121
-            }
1122
-        }
1123
-        //Events View
1124
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1125
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1126
-        ) {
1127
-            $admin_bar->add_menu(array(
1128
-                'id'     => 'espresso-toolbar-events-view',
1129
-                'parent' => 'espresso-toolbar-events',
1130
-                'title'  => __('View', 'event_espresso'),
1131
-                'href'   => $events_admin_url,
1132
-                'meta'   => array(
1133
-                    'title'  => __('View', 'event_espresso'),
1134
-                    'target' => '',
1135
-                    'class'  => $menu_class,
1136
-                ),
1137
-            ));
1138
-        }
1139
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1140
-            //Events View All
1141
-            $admin_bar->add_menu(array(
1142
-                'id'     => 'espresso-toolbar-events-all',
1143
-                'parent' => 'espresso-toolbar-events-view',
1144
-                'title'  => __('All', 'event_espresso'),
1145
-                'href'   => $events_admin_url,
1146
-                'meta'   => array(
1147
-                    'title'  => __('All', 'event_espresso'),
1148
-                    'target' => '',
1149
-                    'class'  => $menu_class,
1150
-                ),
1151
-            ));
1152
-        }
1153
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1154
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1155
-        ) {
1156
-            //Events View Today
1157
-            $admin_bar->add_menu(array(
1158
-                'id'     => 'espresso-toolbar-events-today',
1159
-                'parent' => 'espresso-toolbar-events-view',
1160
-                'title'  => __('Today', 'event_espresso'),
1161
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1162
-                    $events_admin_url),
1163
-                'meta'   => array(
1164
-                    'title'  => __('Today', 'event_espresso'),
1165
-                    'target' => '',
1166
-                    'class'  => $menu_class,
1167
-                ),
1168
-            ));
1169
-        }
1170
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1171
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1172
-        ) {
1173
-            //Events View This Month
1174
-            $admin_bar->add_menu(array(
1175
-                'id'     => 'espresso-toolbar-events-month',
1176
-                'parent' => 'espresso-toolbar-events-view',
1177
-                'title'  => __('This Month', 'event_espresso'),
1178
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1179
-                    $events_admin_url),
1180
-                'meta'   => array(
1181
-                    'title'  => __('This Month', 'event_espresso'),
1182
-                    'target' => '',
1183
-                    'class'  => $menu_class,
1184
-                ),
1185
-            ));
1186
-        }
1187
-        //Registration Overview
1188
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1189
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1190
-        ) {
1191
-            $admin_bar->add_menu(array(
1192
-                'id'     => 'espresso-toolbar-registrations',
1193
-                'parent' => 'espresso-toolbar',
1194
-                'title'  => __('Registrations', 'event_espresso'),
1195
-                'href'   => $reg_admin_url,
1196
-                'meta'   => array(
1197
-                    'title'  => __('Registrations', 'event_espresso'),
1198
-                    'target' => '',
1199
-                    'class'  => $menu_class,
1200
-                ),
1201
-            ));
1202
-        }
1203
-        //Registration Overview Today
1204
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1205
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1206
-        ) {
1207
-            $admin_bar->add_menu(array(
1208
-                'id'     => 'espresso-toolbar-registrations-today',
1209
-                'parent' => 'espresso-toolbar-registrations',
1210
-                'title'  => __('Today', 'event_espresso'),
1211
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1212
-                    $reg_admin_url),
1213
-                'meta'   => array(
1214
-                    'title'  => __('Today', 'event_espresso'),
1215
-                    'target' => '',
1216
-                    'class'  => $menu_class,
1217
-                ),
1218
-            ));
1219
-        }
1220
-        //Registration Overview Today Completed
1221
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1222
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1223
-        ) {
1224
-            $admin_bar->add_menu(array(
1225
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1226
-                'parent' => 'espresso-toolbar-registrations-today',
1227
-                'title'  => __('Approved', 'event_espresso'),
1228
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1229
-                    'action'      => 'default',
1230
-                    'status'      => 'today',
1231
-                    '_reg_status' => EEM_Registration::status_id_approved,
1232
-                ), $reg_admin_url),
1233
-                'meta'   => array(
1234
-                    'title'  => __('Approved', 'event_espresso'),
1235
-                    'target' => '',
1236
-                    'class'  => $menu_class,
1237
-                ),
1238
-            ));
1239
-        }
1240
-        //Registration Overview Today Pending\
1241
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1242
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1243
-        ) {
1244
-            $admin_bar->add_menu(array(
1245
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1246
-                'parent' => 'espresso-toolbar-registrations-today',
1247
-                'title'  => __('Pending', 'event_espresso'),
1248
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1249
-                    'action'     => 'default',
1250
-                    'status'     => 'today',
1251
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1252
-                ), $reg_admin_url),
1253
-                'meta'   => array(
1254
-                    'title'  => __('Pending Payment', 'event_espresso'),
1255
-                    'target' => '',
1256
-                    'class'  => $menu_class,
1257
-                ),
1258
-            ));
1259
-        }
1260
-        //Registration Overview Today Incomplete
1261
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1262
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1263
-        ) {
1264
-            $admin_bar->add_menu(array(
1265
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1266
-                'parent' => 'espresso-toolbar-registrations-today',
1267
-                'title'  => __('Not Approved', 'event_espresso'),
1268
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1269
-                    'action'      => 'default',
1270
-                    'status'      => 'today',
1271
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1272
-                ), $reg_admin_url),
1273
-                'meta'   => array(
1274
-                    'title'  => __('Not Approved', 'event_espresso'),
1275
-                    'target' => '',
1276
-                    'class'  => $menu_class,
1277
-                ),
1278
-            ));
1279
-        }
1280
-        //Registration Overview Today Incomplete
1281
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1282
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1283
-        ) {
1284
-            $admin_bar->add_menu(array(
1285
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1286
-                'parent' => 'espresso-toolbar-registrations-today',
1287
-                'title'  => __('Cancelled', 'event_espresso'),
1288
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1289
-                    'action'      => 'default',
1290
-                    'status'      => 'today',
1291
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1292
-                ), $reg_admin_url),
1293
-                'meta'   => array(
1294
-                    'title'  => __('Cancelled', 'event_espresso'),
1295
-                    'target' => '',
1296
-                    'class'  => $menu_class,
1297
-                ),
1298
-            ));
1299
-        }
1300
-        //Registration Overview This Month
1301
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1302
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1303
-        ) {
1304
-            $admin_bar->add_menu(array(
1305
-                'id'     => 'espresso-toolbar-registrations-month',
1306
-                'parent' => 'espresso-toolbar-registrations',
1307
-                'title'  => __('This Month', 'event_espresso'),
1308
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1309
-                    $reg_admin_url),
1310
-                'meta'   => array(
1311
-                    'title'  => __('This Month', 'event_espresso'),
1312
-                    'target' => '',
1313
-                    'class'  => $menu_class,
1314
-                ),
1315
-            ));
1316
-        }
1317
-        //Registration Overview This Month Approved
1318
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1319
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1320
-        ) {
1321
-            $admin_bar->add_menu(array(
1322
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1323
-                'parent' => 'espresso-toolbar-registrations-month',
1324
-                'title'  => __('Approved', 'event_espresso'),
1325
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1326
-                    'action'      => 'default',
1327
-                    'status'      => 'month',
1328
-                    '_reg_status' => EEM_Registration::status_id_approved,
1329
-                ), $reg_admin_url),
1330
-                'meta'   => array(
1331
-                    'title'  => __('Approved', 'event_espresso'),
1332
-                    'target' => '',
1333
-                    'class'  => $menu_class,
1334
-                ),
1335
-            ));
1336
-        }
1337
-        //Registration Overview This Month Pending
1338
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1339
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1340
-        ) {
1341
-            $admin_bar->add_menu(array(
1342
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1343
-                'parent' => 'espresso-toolbar-registrations-month',
1344
-                'title'  => __('Pending', 'event_espresso'),
1345
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1346
-                    'action'      => 'default',
1347
-                    'status'      => 'month',
1348
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1349
-                ), $reg_admin_url),
1350
-                'meta'   => array(
1351
-                    'title'  => __('Pending', 'event_espresso'),
1352
-                    'target' => '',
1353
-                    'class'  => $menu_class,
1354
-                ),
1355
-            ));
1356
-        }
1357
-        //Registration Overview This Month Not Approved
1358
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1359
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1360
-        ) {
1361
-            $admin_bar->add_menu(array(
1362
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1363
-                'parent' => 'espresso-toolbar-registrations-month',
1364
-                'title'  => __('Not Approved', 'event_espresso'),
1365
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1366
-                    'action'      => 'default',
1367
-                    'status'      => 'month',
1368
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1369
-                ), $reg_admin_url),
1370
-                'meta'   => array(
1371
-                    'title'  => __('Not Approved', 'event_espresso'),
1372
-                    'target' => '',
1373
-                    'class'  => $menu_class,
1374
-                ),
1375
-            ));
1376
-        }
1377
-        //Registration Overview This Month Cancelled
1378
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1379
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1380
-        ) {
1381
-            $admin_bar->add_menu(array(
1382
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1383
-                'parent' => 'espresso-toolbar-registrations-month',
1384
-                'title'  => __('Cancelled', 'event_espresso'),
1385
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1386
-                    'action'      => 'default',
1387
-                    'status'      => 'month',
1388
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1389
-                ), $reg_admin_url),
1390
-                'meta'   => array(
1391
-                    'title'  => __('Cancelled', 'event_espresso'),
1392
-                    'target' => '',
1393
-                    'class'  => $menu_class,
1394
-                ),
1395
-            ));
1396
-        }
1397
-        //Extensions & Services
1398
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1399
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1400
-        ) {
1401
-            $admin_bar->add_menu(array(
1402
-                'id'     => 'espresso-toolbar-extensions-and-services',
1403
-                'parent' => 'espresso-toolbar',
1404
-                'title'  => __('Extensions & Services', 'event_espresso'),
1405
-                'href'   => $extensions_admin_url,
1406
-                'meta'   => array(
1407
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1408
-                    'target' => '',
1409
-                    'class'  => $menu_class,
1410
-                ),
1411
-            ));
1412
-        }
1413
-    }
1414
-
1415
-
1416
-
1417
-    /**
1418
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1419
-     * never returned with the function.
1420
-     *
1421
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1422
-     * @return array
1423
-     */
1424
-    public function remove_pages_from_wp_list_pages($exclude_array)
1425
-    {
1426
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1427
-    }
22
+	/**
23
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
+	 */
26
+	const req_type_normal = 0;
27
+
28
+	/**
29
+	 * Indicates this is a brand new installation of EE so we should install
30
+	 * tables and default data etc
31
+	 */
32
+	const req_type_new_activation = 1;
33
+
34
+	/**
35
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
37
+	 * and that default data is setup too
38
+	 */
39
+	const req_type_reactivation = 2;
40
+
41
+	/**
42
+	 * indicates that EE has been upgraded since its previous request.
43
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
44
+	 */
45
+	const req_type_upgrade = 3;
46
+
47
+	/**
48
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
+	 */
50
+	const req_type_downgrade = 4;
51
+
52
+	/**
53
+	 * @deprecated since version 4.6.0.dev.006
54
+	 * Now whenever a new_activation is detected the request type is still just
55
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
+	 * (Specifically, when the migration manager indicates migrations are finished
59
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
+	 */
61
+	const req_type_activation_but_not_installed = 5;
62
+
63
+	/**
64
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
+	 */
66
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
+
68
+
69
+	/**
70
+	 *    instance of the EE_System object
71
+	 *
72
+	 * @var    $_instance
73
+	 * @access    private
74
+	 */
75
+	private static $_instance = null;
76
+
77
+	/**
78
+	 * @type  EE_Registry $Registry
79
+	 * @access    protected
80
+	 */
81
+	protected $registry;
82
+
83
+	/**
84
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
+	 *
87
+	 * @var int
88
+	 */
89
+	private $_req_type;
90
+
91
+	/**
92
+	 * Whether or not there was a non-micro version change in EE core version during this request
93
+	 *
94
+	 * @var boolean
95
+	 */
96
+	private $_major_version_change = false;
97
+
98
+
99
+
100
+	/**
101
+	 * @singleton method used to instantiate class object
102
+	 * @access    public
103
+	 * @param  \EE_Registry $Registry
104
+	 * @return \EE_System
105
+	 */
106
+	public static function instance(EE_Registry $Registry = null)
107
+	{
108
+		// check if class object is instantiated
109
+		if ( ! self::$_instance instanceof EE_System) {
110
+			self::$_instance = new self($Registry);
111
+		}
112
+		return self::$_instance;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * resets the instance and returns it
119
+	 *
120
+	 * @return EE_System
121
+	 */
122
+	public static function reset()
123
+	{
124
+		self::$_instance->_req_type = null;
125
+		//make sure none of the old hooks are left hanging around
126
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
+		//we need to reset the migration manager in order for it to detect DMSs properly
128
+		EE_Data_Migration_Manager::reset();
129
+		self::instance()->detect_activations_or_upgrades();
130
+		self::instance()->perform_activations_upgrades_and_migrations();
131
+		return self::instance();
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 *    sets hooks for running rest of system
138
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
+	 *    starting EE Addons from any other point may lead to problems
140
+	 *
141
+	 * @access private
142
+	 * @param  \EE_Registry $Registry
143
+	 */
144
+	private function __construct(EE_Registry $Registry)
145
+	{
146
+		$this->registry = $Registry;
147
+		do_action('AHEE__EE_System__construct__begin', $this);
148
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
+		// when an ee addon is activated, we want to call the core hook(s) again
151
+		// because the newly-activated addon didn't get a chance to run at all
152
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
+		// detect whether install or upgrade
154
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
+			3);
156
+		// load EE_Config, EE_Textdomain, etc
157
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
+		// load EE_Config, EE_Textdomain, etc
159
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
+		// you wanna get going? I wanna get going... let's get going!
162
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
+		//other housekeeping
164
+		//exclude EE critical pages from wp_list_pages
165
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
+		// ALL EE Addons should use the following hook point to attach their initial setup too
167
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
+		do_action('AHEE__EE_System__construct__complete', $this);
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * load_espresso_addons
175
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
176
+	 * this is hooked into both:
177
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
178
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
179
+	 *    and the WP 'activate_plugin' hookpoint
180
+	 *
181
+	 * @access public
182
+	 * @return void
183
+	 */
184
+	public function load_espresso_addons()
185
+	{
186
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
187
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
188
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
+		//load and setup EE_Capabilities
190
+		$this->registry->load_core('Capabilities');
191
+		//caps need to be initialized on every request so that capability maps are set.
192
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
+		$this->registry->CAP->init_caps();
194
+		do_action('AHEE__EE_System__load_espresso_addons');
195
+		//if the WP API basic auth plugin isn't already loaded, load it now.
196
+		//We want it for mobile apps. Just include the entire plugin
197
+		//also, don't load the basic auth when a plugin is getting activated, because
198
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
+		//and causes a fatal error
200
+		if ( ! function_exists('json_basic_auth_handler')
201
+			 && ! function_exists('json_basic_auth_error')
202
+			 && ! (
203
+				isset($_GET['action'])
204
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
205
+			)
206
+			 && ! (
207
+				isset($_GET['activate'])
208
+				&& $_GET['activate'] === 'true'
209
+			)
210
+		) {
211
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
+		}
213
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * detect_activations_or_upgrades
220
+	 * Checks for activation or upgrade of core first;
221
+	 * then also checks if any registered addons have been activated or upgraded
222
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
+	 * which runs during the WP 'plugins_loaded' action at priority 3
224
+	 *
225
+	 * @access public
226
+	 * @return void
227
+	 */
228
+	public function detect_activations_or_upgrades()
229
+	{
230
+		//first off: let's make sure to handle core
231
+		$this->detect_if_activation_or_upgrade();
232
+		foreach ($this->registry->addons as $addon) {
233
+			//detect teh request type for that addon
234
+			$addon->detect_activation_or_upgrade();
235
+		}
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * detect_if_activation_or_upgrade
242
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
243
+	 * and either setting up the DB or setting up maintenance mode etc.
244
+	 *
245
+	 * @access public
246
+	 * @return void
247
+	 */
248
+	public function detect_if_activation_or_upgrade()
249
+	{
250
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
+		// load M-Mode class
252
+		$this->registry->load_core('Maintenance_Mode');
253
+		// check if db has been updated, or if its a brand-new installation
254
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
+		$request_type = $this->detect_req_type($espresso_db_update);
256
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
+		switch ($request_type) {
258
+			case EE_System::req_type_new_activation:
259
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
+				$this->_handle_core_version_change($espresso_db_update);
261
+				break;
262
+			case EE_System::req_type_reactivation:
263
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
+				$this->_handle_core_version_change($espresso_db_update);
265
+				break;
266
+			case EE_System::req_type_upgrade:
267
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
+				//migrations may be required now that we've upgraded
269
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
+				$this->_handle_core_version_change($espresso_db_update);
271
+				//				echo "done upgrade";die;
272
+				break;
273
+			case EE_System::req_type_downgrade:
274
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
+				//its possible migrations are no longer required
276
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
+				$this->_handle_core_version_change($espresso_db_update);
278
+				break;
279
+			case EE_System::req_type_normal:
280
+			default:
281
+				//				$this->_maybe_redirect_to_ee_about();
282
+				break;
283
+		}
284
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * Updates the list of installed versions and sets hooks for
291
+	 * initializing the database later during the request
292
+	 *
293
+	 * @param array $espresso_db_update
294
+	 */
295
+	protected function _handle_core_version_change($espresso_db_update)
296
+	{
297
+		$this->update_list_of_installed_versions($espresso_db_update);
298
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
+			array($this, 'initialize_db_if_no_migrations_required'));
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
+	 * information about what versions of EE have been installed and activated,
308
+	 * NOT necessarily the state of the database
309
+	 *
310
+	 * @param null $espresso_db_update
311
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
+	 *           from the options table
313
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
+	 */
315
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
+	{
317
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
+		if ( ! $espresso_db_update) {
319
+			$espresso_db_update = get_option('espresso_db_update');
320
+		}
321
+		// check that option is an array
322
+		if ( ! is_array($espresso_db_update)) {
323
+			// if option is FALSE, then it never existed
324
+			if ($espresso_db_update === false) {
325
+				// make $espresso_db_update an array and save option with autoload OFF
326
+				$espresso_db_update = array();
327
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
+			} else {
329
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
330
+				$espresso_db_update = array($espresso_db_update => array());
331
+				update_option('espresso_db_update', $espresso_db_update);
332
+			}
333
+		} else {
334
+			$corrected_db_update = array();
335
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
+					//the key is an int, and the value IS NOT an array
339
+					//so it must be numerically-indexed, where values are versions installed...
340
+					//fix it!
341
+					$version_string = $should_be_array;
342
+					$corrected_db_update[$version_string] = array('unknown-date');
343
+				} else {
344
+					//ok it checks out
345
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
346
+				}
347
+			}
348
+			$espresso_db_update = $corrected_db_update;
349
+			update_option('espresso_db_update', $espresso_db_update);
350
+		}
351
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
+		return $espresso_db_update;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Does the traditional work of setting up the plugin's database and adding default data.
359
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
+	 * so that it will be done when migrations are finished
363
+	 *
364
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
+	 *                                       This is a resource-intensive job
367
+	 *                                       so we prefer to only do it when necessary
368
+	 * @return void
369
+	 */
370
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
+	{
372
+		$request_type = $this->detect_req_type();
373
+		//only initialize system if we're not in maintenance mode.
374
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
+			update_option('ee_flush_rewrite_rules', true);
376
+			if ($verify_schema) {
377
+				EEH_Activation::initialize_db_and_folders();
378
+			}
379
+			EEH_Activation::initialize_db_content();
380
+			EEH_Activation::system_initialization();
381
+			if ($initialize_addons_too) {
382
+				$this->initialize_addons();
383
+			}
384
+		} else {
385
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
+		}
387
+		if ($request_type === EE_System::req_type_new_activation
388
+			|| $request_type === EE_System::req_type_reactivation
389
+			|| (
390
+				$request_type === EE_System::req_type_upgrade
391
+				&& $this->is_major_version_change()
392
+			)
393
+		) {
394
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
+		}
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Initializes the db for all registered addons
402
+	 */
403
+	public function initialize_addons()
404
+	{
405
+		//foreach registered addon, make sure its db is up-to-date too
406
+		foreach ($this->registry->addons as $addon) {
407
+			$addon->initialize_db_if_no_migrations_required();
408
+		}
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
+	 *
416
+	 * @param    array  $version_history
417
+	 * @param    string $current_version_to_add version to be added to the version history
418
+	 * @return    boolean success as to whether or not this option was changed
419
+	 */
420
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
+	{
422
+		if ( ! $version_history) {
423
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
+		}
425
+		if ($current_version_to_add == null) {
426
+			$current_version_to_add = espresso_version();
427
+		}
428
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
+		// re-save
430
+		return update_option('espresso_db_update', $version_history);
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * Detects if the current version indicated in the has existed in the list of
437
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
+	 *
439
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
+	 *                                  If not supplied, fetches it from the options table.
441
+	 *                                  Also, caches its result so later parts of the code can also know whether
442
+	 *                                  there's been an update or not. This way we can add the current version to
443
+	 *                                  espresso_db_update, but still know if this is a new install or not
444
+	 * @return int one of the constants on EE_System::req_type_
445
+	 */
446
+	public function detect_req_type($espresso_db_update = null)
447
+	{
448
+		if ($this->_req_type === null) {
449
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
+				: $this->fix_espresso_db_upgrade_option();
451
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
+				'ee_espresso_activation', espresso_version());
453
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
+		}
455
+		return $this->_req_type;
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * Returns whether or not there was a non-micro version change (ie, change in either
462
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
+	 *
465
+	 * @param $activation_history
466
+	 * @return bool
467
+	 */
468
+	protected function _detect_major_version_change($activation_history)
469
+	{
470
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
+		$previous_version_parts = explode('.', $previous_version);
472
+		$current_version_parts = explode('.', espresso_version());
473
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
475
+				   || $previous_version_parts[1] !== $current_version_parts[1]
476
+			   );
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Returns true if either the major or minor version of EE changed during this request.
483
+	 * 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
484
+	 *
485
+	 * @return bool
486
+	 */
487
+	public function is_major_version_change()
488
+	{
489
+		return $this->_major_version_change;
490
+	}
491
+
492
+
493
+
494
+	/**
495
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
+	 * just activated to (for core that will always be espresso_version())
499
+	 *
500
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
502
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
+	 *                                                 indicate that this plugin was just activated
504
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
+	 *                                                 espresso_version())
506
+	 * @return int one of the constants on EE_System::req_type_*
507
+	 */
508
+	public static function detect_req_type_given_activation_history(
509
+		$activation_history_for_addon,
510
+		$activation_indicator_option_name,
511
+		$version_to_upgrade_to
512
+	) {
513
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
+		if ($activation_history_for_addon) {
515
+			//it exists, so this isn't a completely new install
516
+			//check if this version already in that list of previously installed versions
517
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
+				//it a version we haven't seen before
519
+				if ($version_is_higher === 1) {
520
+					$req_type = EE_System::req_type_upgrade;
521
+				} else {
522
+					$req_type = EE_System::req_type_downgrade;
523
+				}
524
+				delete_option($activation_indicator_option_name);
525
+			} else {
526
+				// its not an update. maybe a reactivation?
527
+				if (get_option($activation_indicator_option_name, false)) {
528
+					if ($version_is_higher === -1) {
529
+						$req_type = EE_System::req_type_downgrade;
530
+					} elseif ($version_is_higher === 0) {
531
+						//we've seen this version before, but it's an activation. must be a reactivation
532
+						$req_type = EE_System::req_type_reactivation;
533
+					} else {//$version_is_higher === 1
534
+						$req_type = EE_System::req_type_upgrade;
535
+					}
536
+					delete_option($activation_indicator_option_name);
537
+				} else {
538
+					//we've seen this version before and the activation indicate doesn't show it was just activated
539
+					if ($version_is_higher === -1) {
540
+						$req_type = EE_System::req_type_downgrade;
541
+					} elseif ($version_is_higher === 0) {
542
+						//we've seen this version before and it's not an activation. its normal request
543
+						$req_type = EE_System::req_type_normal;
544
+					} else {//$version_is_higher === 1
545
+						$req_type = EE_System::req_type_upgrade;
546
+					}
547
+				}
548
+			}
549
+		} else {
550
+			//brand new install
551
+			$req_type = EE_System::req_type_new_activation;
552
+			delete_option($activation_indicator_option_name);
553
+		}
554
+		return $req_type;
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
+	 * the $activation_history_for_addon
562
+	 *
563
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
+	 *                                             sometimes containing 'unknown-date'
565
+	 * @param string $version_to_upgrade_to        (current version)
566
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
+	 */
571
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
+	{
573
+		//find the most recently-activated version
574
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * Gets the most recently active version listed in the activation history,
582
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
+	 *
584
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
+	 *                                   sometimes containing 'unknown-date'
586
+	 * @return string
587
+	 */
588
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
+	{
590
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
591
+		$most_recently_active_version = '0.0.0.dev.000';
592
+		if (is_array($activation_history)) {
593
+			foreach ($activation_history as $version => $times_activated) {
594
+				//check there is a record of when this version was activated. Otherwise,
595
+				//mark it as unknown
596
+				if ( ! $times_activated) {
597
+					$times_activated = array('unknown-date');
598
+				}
599
+				if (is_string($times_activated)) {
600
+					$times_activated = array($times_activated);
601
+				}
602
+				foreach ($times_activated as $an_activation) {
603
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
+						$most_recently_active_version = $version;
605
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
606
+							? '1970-01-01 00:00:00' : $an_activation;
607
+					}
608
+				}
609
+			}
610
+		}
611
+		return $most_recently_active_version;
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This redirects to the about EE page after activation
618
+	 *
619
+	 * @return void
620
+	 */
621
+	public function redirect_to_about_ee()
622
+	{
623
+		$notices = EE_Error::get_notices(false);
624
+		//if current user is an admin and it's not an ajax or rest request
625
+		if (
626
+			! (defined('DOING_AJAX') && DOING_AJAX)
627
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
628
+			&& ! isset($notices['errors'])
629
+			&& apply_filters(
630
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
+			)
633
+		) {
634
+			$query_params = array('page' => 'espresso_about');
635
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
+				$query_params['new_activation'] = true;
637
+			}
638
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
+				$query_params['reactivation'] = true;
640
+			}
641
+			$url = add_query_arg($query_params, admin_url('admin.php'));
642
+			wp_safe_redirect($url);
643
+			exit();
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * load_core_configuration
651
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
+	 * which runs during the WP 'plugins_loaded' action at priority 5
653
+	 *
654
+	 * @return void
655
+	 */
656
+	public function load_core_configuration()
657
+	{
658
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
+		$this->registry->load_core('EE_Load_Textdomain');
660
+		//load textdomain
661
+		EE_Load_Textdomain::load_textdomain();
662
+		// load and setup EE_Config and EE_Network_Config
663
+		$this->registry->load_core('Config');
664
+		$this->registry->load_core('Network_Config');
665
+		// setup autoloaders
666
+		// enable logging?
667
+		if ($this->registry->CFG->admin->use_full_logging) {
668
+			$this->registry->load_core('Log');
669
+		}
670
+		// check for activation errors
671
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
672
+		if ($activation_errors) {
673
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
+			update_option('ee_plugin_activation_errors', false);
675
+		}
676
+		// get model names
677
+		$this->_parse_model_names();
678
+		//load caf stuff a chance to play during the activation process too.
679
+		$this->_maybe_brew_regular();
680
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
687
+	 *
688
+	 * @return void
689
+	 */
690
+	private function _parse_model_names()
691
+	{
692
+		//get all the files in the EE_MODELS folder that end in .model.php
693
+		$models = glob(EE_MODELS . '*.model.php');
694
+		$model_names = array();
695
+		$non_abstract_db_models = array();
696
+		foreach ($models as $model) {
697
+			// get model classname
698
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
+			$short_name = str_replace('EEM_', '', $classname);
700
+			$reflectionClass = new ReflectionClass($classname);
701
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
+				$non_abstract_db_models[$short_name] = $classname;
703
+			}
704
+			$model_names[$short_name] = $classname;
705
+		}
706
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
+			$non_abstract_db_models);
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
+	 * that need to be setup before our EE_System launches.
716
+	 *
717
+	 * @return void
718
+	 */
719
+	private function _maybe_brew_regular()
720
+	{
721
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
723
+		}
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * register_shortcodes_modules_and_widgets
730
+	 * generate lists of shortcodes and modules, then verify paths and classes
731
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
+	 * which runs during the WP 'plugins_loaded' action at priority 7
733
+	 *
734
+	 * @access public
735
+	 * @return void
736
+	 */
737
+	public function register_shortcodes_modules_and_widgets()
738
+	{
739
+		try {
740
+			// load, register, and add shortcodes the new way
741
+			new ShortcodesManager(
742
+			// and the old way, but we'll put it under control of the new system
743
+				EE_Config::getLegacyShortcodesManager()
744
+			);
745
+		} catch (Exception $exception) {
746
+			new ExceptionStackTraceDisplay($exception);
747
+		}
748
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
+		// check for addons using old hookpoint
750
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
+			$this->_incompatible_addon_error();
752
+		}
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * _incompatible_addon_error
759
+	 *
760
+	 * @access public
761
+	 * @return void
762
+	 */
763
+	private function _incompatible_addon_error()
764
+	{
765
+		// get array of classes hooking into here
766
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
+		if ( ! empty($class_names)) {
768
+			$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:',
769
+				'event_espresso');
770
+			$msg .= '<ul>';
771
+			foreach ($class_names as $class_name) {
772
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+						$class_name) . '</b></li>';
774
+			}
775
+			$msg .= '</ul>';
776
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
+				'event_espresso');
778
+			// save list of incompatible addons to wp-options for later use
779
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
780
+			if (is_admin()) {
781
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
+			}
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * brew_espresso
790
+	 * begins the process of setting hooks for initializing EE in the correct order
791
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
+	 * which runs during the WP 'plugins_loaded' action at priority 9
793
+	 *
794
+	 * @return void
795
+	 */
796
+	public function brew_espresso()
797
+	{
798
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
+		// load some final core systems
800
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
801
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
+		add_action('init', array($this, 'load_controllers'), 7);
804
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
+		add_action('init', array($this, 'initialize'), 10);
806
+		add_action('init', array($this, 'initialize_last'), 100);
807
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
+			// pew pew pew
810
+			$this->registry->load_core('PUE');
811
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
+		}
813
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 *    set_hooks_for_core
820
+	 *
821
+	 * @access public
822
+	 * @return    void
823
+	 */
824
+	public function set_hooks_for_core()
825
+	{
826
+		$this->_deactivate_incompatible_addons();
827
+		do_action('AHEE__EE_System__set_hooks_for_core');
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
834
+	 * deactivates any addons considered incompatible with the current version of EE
835
+	 */
836
+	private function _deactivate_incompatible_addons()
837
+	{
838
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
839
+		if ( ! empty($incompatible_addons)) {
840
+			$active_plugins = get_option('active_plugins', array());
841
+			foreach ($active_plugins as $active_plugin) {
842
+				foreach ($incompatible_addons as $incompatible_addon) {
843
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
844
+						unset($_GET['activate']);
845
+						espresso_deactivate_plugin($active_plugin);
846
+					}
847
+				}
848
+			}
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 *    perform_activations_upgrades_and_migrations
856
+	 *
857
+	 * @access public
858
+	 * @return    void
859
+	 */
860
+	public function perform_activations_upgrades_and_migrations()
861
+	{
862
+		//first check if we had previously attempted to setup EE's directories but failed
863
+		if (EEH_Activation::upload_directories_incomplete()) {
864
+			EEH_Activation::create_upload_directories();
865
+		}
866
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 *    load_CPTs_and_session
873
+	 *
874
+	 * @access public
875
+	 * @return    void
876
+	 */
877
+	public function load_CPTs_and_session()
878
+	{
879
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
+		// register Custom Post Types
881
+		$this->registry->load_core('Register_CPTs');
882
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * load_controllers
889
+	 * this is the best place to load any additional controllers that needs access to EE core.
890
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
+	 * time
892
+	 *
893
+	 * @access public
894
+	 * @return void
895
+	 */
896
+	public function load_controllers()
897
+	{
898
+		do_action('AHEE__EE_System__load_controllers__start');
899
+		// let's get it started
900
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
+			$this->registry->load_core('Front_Controller');
903
+		} else if ( ! EE_FRONT_AJAX) {
904
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
+			EE_Registry::instance()->load_core('Admin');
906
+		}
907
+		do_action('AHEE__EE_System__load_controllers__complete');
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * core_loaded_and_ready
914
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
+	 *
916
+	 * @access public
917
+	 * @return void
918
+	 */
919
+	public function core_loaded_and_ready()
920
+	{
921
+		$this->registry->load_core('Session');
922
+		do_action('AHEE__EE_System__core_loaded_and_ready');
923
+		// load_espresso_template_tags
924
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
+			require_once(EE_PUBLIC . 'template_tags.php');
926
+		}
927
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
+		$this->registry->create('EventEspresso\core\services\assets\Registry');
929
+		wp_enqueue_script('espresso_core');
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * initialize
936
+	 * this is the best place to begin initializing client code
937
+	 *
938
+	 * @access public
939
+	 * @return void
940
+	 */
941
+	public function initialize()
942
+	{
943
+		do_action('AHEE__EE_System__initialize');
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * initialize_last
950
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
951
+	 * initialize has done so
952
+	 *
953
+	 * @access public
954
+	 * @return void
955
+	 */
956
+	public function initialize_last()
957
+	{
958
+		do_action('AHEE__EE_System__initialize_last');
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * set_hooks_for_shortcodes_modules_and_addons
965
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
966
+	 * this happens at the very beginning of the wp_loaded hookpoint
967
+	 *
968
+	 * @access public
969
+	 * @return void
970
+	 */
971
+	public function set_hooks_for_shortcodes_modules_and_addons()
972
+	{
973
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * do_not_cache
980
+	 * sets no cache headers and defines no cache constants for WP plugins
981
+	 *
982
+	 * @access public
983
+	 * @return void
984
+	 */
985
+	public static function do_not_cache()
986
+	{
987
+		// set no cache constants
988
+		if ( ! defined('DONOTCACHEPAGE')) {
989
+			define('DONOTCACHEPAGE', true);
990
+		}
991
+		if ( ! defined('DONOTCACHCEOBJECT')) {
992
+			define('DONOTCACHCEOBJECT', true);
993
+		}
994
+		if ( ! defined('DONOTCACHEDB')) {
995
+			define('DONOTCACHEDB', true);
996
+		}
997
+		// add no cache headers
998
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
999
+		// plus a little extra for nginx and Google Chrome
1000
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1001
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1002
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1003
+	}
1004
+
1005
+
1006
+
1007
+	/**
1008
+	 *    extra_nocache_headers
1009
+	 *
1010
+	 * @access    public
1011
+	 * @param $headers
1012
+	 * @return    array
1013
+	 */
1014
+	public static function extra_nocache_headers($headers)
1015
+	{
1016
+		// for NGINX
1017
+		$headers['X-Accel-Expires'] = 0;
1018
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1019
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1020
+		return $headers;
1021
+	}
1022
+
1023
+
1024
+
1025
+	/**
1026
+	 *    nocache_headers
1027
+	 *
1028
+	 * @access    public
1029
+	 * @return    void
1030
+	 */
1031
+	public static function nocache_headers()
1032
+	{
1033
+		nocache_headers();
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 *    espresso_toolbar_items
1040
+	 *
1041
+	 * @access public
1042
+	 * @param  WP_Admin_Bar $admin_bar
1043
+	 * @return void
1044
+	 */
1045
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1046
+	{
1047
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1048
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1049
+			|| defined('DOING_AJAX')
1050
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1051
+		) {
1052
+			return;
1053
+		}
1054
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1055
+		$menu_class = 'espresso_menu_item_class';
1056
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1057
+		//because they're only defined in each of their respective constructors
1058
+		//and this might be a frontend request, in which case they aren't available
1059
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1060
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1061
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1062
+		//Top Level
1063
+		$admin_bar->add_menu(array(
1064
+			'id'    => 'espresso-toolbar',
1065
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1066
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1067
+					   . '</span>',
1068
+			'href'  => $events_admin_url,
1069
+			'meta'  => array(
1070
+				'title' => __('Event Espresso', 'event_espresso'),
1071
+				'class' => $menu_class . 'first',
1072
+			),
1073
+		));
1074
+		//Events
1075
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1076
+			$admin_bar->add_menu(array(
1077
+				'id'     => 'espresso-toolbar-events',
1078
+				'parent' => 'espresso-toolbar',
1079
+				'title'  => __('Events', 'event_espresso'),
1080
+				'href'   => $events_admin_url,
1081
+				'meta'   => array(
1082
+					'title'  => __('Events', 'event_espresso'),
1083
+					'target' => '',
1084
+					'class'  => $menu_class,
1085
+				),
1086
+			));
1087
+		}
1088
+		if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1089
+			//Events Add New
1090
+			$admin_bar->add_menu(array(
1091
+				'id'     => 'espresso-toolbar-events-new',
1092
+				'parent' => 'espresso-toolbar-events',
1093
+				'title'  => __('Add New', 'event_espresso'),
1094
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1095
+				'meta'   => array(
1096
+					'title'  => __('Add New', 'event_espresso'),
1097
+					'target' => '',
1098
+					'class'  => $menu_class,
1099
+				),
1100
+			));
1101
+		}
1102
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1103
+			//Current post
1104
+			global $post;
1105
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1106
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1107
+			) {
1108
+				//Events Edit Current Event
1109
+				$admin_bar->add_menu(array(
1110
+					'id'     => 'espresso-toolbar-events-edit',
1111
+					'parent' => 'espresso-toolbar-events',
1112
+					'title'  => __('Edit Event', 'event_espresso'),
1113
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1114
+						$events_admin_url),
1115
+					'meta'   => array(
1116
+						'title'  => __('Edit Event', 'event_espresso'),
1117
+						'target' => '',
1118
+						'class'  => $menu_class,
1119
+					),
1120
+				));
1121
+			}
1122
+		}
1123
+		//Events View
1124
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1125
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1126
+		) {
1127
+			$admin_bar->add_menu(array(
1128
+				'id'     => 'espresso-toolbar-events-view',
1129
+				'parent' => 'espresso-toolbar-events',
1130
+				'title'  => __('View', 'event_espresso'),
1131
+				'href'   => $events_admin_url,
1132
+				'meta'   => array(
1133
+					'title'  => __('View', 'event_espresso'),
1134
+					'target' => '',
1135
+					'class'  => $menu_class,
1136
+				),
1137
+			));
1138
+		}
1139
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1140
+			//Events View All
1141
+			$admin_bar->add_menu(array(
1142
+				'id'     => 'espresso-toolbar-events-all',
1143
+				'parent' => 'espresso-toolbar-events-view',
1144
+				'title'  => __('All', 'event_espresso'),
1145
+				'href'   => $events_admin_url,
1146
+				'meta'   => array(
1147
+					'title'  => __('All', 'event_espresso'),
1148
+					'target' => '',
1149
+					'class'  => $menu_class,
1150
+				),
1151
+			));
1152
+		}
1153
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1154
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1155
+		) {
1156
+			//Events View Today
1157
+			$admin_bar->add_menu(array(
1158
+				'id'     => 'espresso-toolbar-events-today',
1159
+				'parent' => 'espresso-toolbar-events-view',
1160
+				'title'  => __('Today', 'event_espresso'),
1161
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1162
+					$events_admin_url),
1163
+				'meta'   => array(
1164
+					'title'  => __('Today', 'event_espresso'),
1165
+					'target' => '',
1166
+					'class'  => $menu_class,
1167
+				),
1168
+			));
1169
+		}
1170
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1171
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1172
+		) {
1173
+			//Events View This Month
1174
+			$admin_bar->add_menu(array(
1175
+				'id'     => 'espresso-toolbar-events-month',
1176
+				'parent' => 'espresso-toolbar-events-view',
1177
+				'title'  => __('This Month', 'event_espresso'),
1178
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1179
+					$events_admin_url),
1180
+				'meta'   => array(
1181
+					'title'  => __('This Month', 'event_espresso'),
1182
+					'target' => '',
1183
+					'class'  => $menu_class,
1184
+				),
1185
+			));
1186
+		}
1187
+		//Registration Overview
1188
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1189
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1190
+		) {
1191
+			$admin_bar->add_menu(array(
1192
+				'id'     => 'espresso-toolbar-registrations',
1193
+				'parent' => 'espresso-toolbar',
1194
+				'title'  => __('Registrations', 'event_espresso'),
1195
+				'href'   => $reg_admin_url,
1196
+				'meta'   => array(
1197
+					'title'  => __('Registrations', 'event_espresso'),
1198
+					'target' => '',
1199
+					'class'  => $menu_class,
1200
+				),
1201
+			));
1202
+		}
1203
+		//Registration Overview Today
1204
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1205
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1206
+		) {
1207
+			$admin_bar->add_menu(array(
1208
+				'id'     => 'espresso-toolbar-registrations-today',
1209
+				'parent' => 'espresso-toolbar-registrations',
1210
+				'title'  => __('Today', 'event_espresso'),
1211
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1212
+					$reg_admin_url),
1213
+				'meta'   => array(
1214
+					'title'  => __('Today', 'event_espresso'),
1215
+					'target' => '',
1216
+					'class'  => $menu_class,
1217
+				),
1218
+			));
1219
+		}
1220
+		//Registration Overview Today Completed
1221
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1222
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1223
+		) {
1224
+			$admin_bar->add_menu(array(
1225
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1226
+				'parent' => 'espresso-toolbar-registrations-today',
1227
+				'title'  => __('Approved', 'event_espresso'),
1228
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1229
+					'action'      => 'default',
1230
+					'status'      => 'today',
1231
+					'_reg_status' => EEM_Registration::status_id_approved,
1232
+				), $reg_admin_url),
1233
+				'meta'   => array(
1234
+					'title'  => __('Approved', 'event_espresso'),
1235
+					'target' => '',
1236
+					'class'  => $menu_class,
1237
+				),
1238
+			));
1239
+		}
1240
+		//Registration Overview Today Pending\
1241
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1242
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1243
+		) {
1244
+			$admin_bar->add_menu(array(
1245
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1246
+				'parent' => 'espresso-toolbar-registrations-today',
1247
+				'title'  => __('Pending', 'event_espresso'),
1248
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1249
+					'action'     => 'default',
1250
+					'status'     => 'today',
1251
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1252
+				), $reg_admin_url),
1253
+				'meta'   => array(
1254
+					'title'  => __('Pending Payment', 'event_espresso'),
1255
+					'target' => '',
1256
+					'class'  => $menu_class,
1257
+				),
1258
+			));
1259
+		}
1260
+		//Registration Overview Today Incomplete
1261
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1262
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1263
+		) {
1264
+			$admin_bar->add_menu(array(
1265
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1266
+				'parent' => 'espresso-toolbar-registrations-today',
1267
+				'title'  => __('Not Approved', 'event_espresso'),
1268
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1269
+					'action'      => 'default',
1270
+					'status'      => 'today',
1271
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1272
+				), $reg_admin_url),
1273
+				'meta'   => array(
1274
+					'title'  => __('Not Approved', 'event_espresso'),
1275
+					'target' => '',
1276
+					'class'  => $menu_class,
1277
+				),
1278
+			));
1279
+		}
1280
+		//Registration Overview Today Incomplete
1281
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1282
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1283
+		) {
1284
+			$admin_bar->add_menu(array(
1285
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1286
+				'parent' => 'espresso-toolbar-registrations-today',
1287
+				'title'  => __('Cancelled', 'event_espresso'),
1288
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1289
+					'action'      => 'default',
1290
+					'status'      => 'today',
1291
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1292
+				), $reg_admin_url),
1293
+				'meta'   => array(
1294
+					'title'  => __('Cancelled', 'event_espresso'),
1295
+					'target' => '',
1296
+					'class'  => $menu_class,
1297
+				),
1298
+			));
1299
+		}
1300
+		//Registration Overview This Month
1301
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1302
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1303
+		) {
1304
+			$admin_bar->add_menu(array(
1305
+				'id'     => 'espresso-toolbar-registrations-month',
1306
+				'parent' => 'espresso-toolbar-registrations',
1307
+				'title'  => __('This Month', 'event_espresso'),
1308
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1309
+					$reg_admin_url),
1310
+				'meta'   => array(
1311
+					'title'  => __('This Month', 'event_espresso'),
1312
+					'target' => '',
1313
+					'class'  => $menu_class,
1314
+				),
1315
+			));
1316
+		}
1317
+		//Registration Overview This Month Approved
1318
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1319
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1320
+		) {
1321
+			$admin_bar->add_menu(array(
1322
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1323
+				'parent' => 'espresso-toolbar-registrations-month',
1324
+				'title'  => __('Approved', 'event_espresso'),
1325
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1326
+					'action'      => 'default',
1327
+					'status'      => 'month',
1328
+					'_reg_status' => EEM_Registration::status_id_approved,
1329
+				), $reg_admin_url),
1330
+				'meta'   => array(
1331
+					'title'  => __('Approved', 'event_espresso'),
1332
+					'target' => '',
1333
+					'class'  => $menu_class,
1334
+				),
1335
+			));
1336
+		}
1337
+		//Registration Overview This Month Pending
1338
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1339
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1340
+		) {
1341
+			$admin_bar->add_menu(array(
1342
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1343
+				'parent' => 'espresso-toolbar-registrations-month',
1344
+				'title'  => __('Pending', 'event_espresso'),
1345
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1346
+					'action'      => 'default',
1347
+					'status'      => 'month',
1348
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1349
+				), $reg_admin_url),
1350
+				'meta'   => array(
1351
+					'title'  => __('Pending', 'event_espresso'),
1352
+					'target' => '',
1353
+					'class'  => $menu_class,
1354
+				),
1355
+			));
1356
+		}
1357
+		//Registration Overview This Month Not Approved
1358
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1359
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1360
+		) {
1361
+			$admin_bar->add_menu(array(
1362
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1363
+				'parent' => 'espresso-toolbar-registrations-month',
1364
+				'title'  => __('Not Approved', 'event_espresso'),
1365
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1366
+					'action'      => 'default',
1367
+					'status'      => 'month',
1368
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1369
+				), $reg_admin_url),
1370
+				'meta'   => array(
1371
+					'title'  => __('Not Approved', 'event_espresso'),
1372
+					'target' => '',
1373
+					'class'  => $menu_class,
1374
+				),
1375
+			));
1376
+		}
1377
+		//Registration Overview This Month Cancelled
1378
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1379
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1380
+		) {
1381
+			$admin_bar->add_menu(array(
1382
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1383
+				'parent' => 'espresso-toolbar-registrations-month',
1384
+				'title'  => __('Cancelled', 'event_espresso'),
1385
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1386
+					'action'      => 'default',
1387
+					'status'      => 'month',
1388
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1389
+				), $reg_admin_url),
1390
+				'meta'   => array(
1391
+					'title'  => __('Cancelled', 'event_espresso'),
1392
+					'target' => '',
1393
+					'class'  => $menu_class,
1394
+				),
1395
+			));
1396
+		}
1397
+		//Extensions & Services
1398
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1399
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1400
+		) {
1401
+			$admin_bar->add_menu(array(
1402
+				'id'     => 'espresso-toolbar-extensions-and-services',
1403
+				'parent' => 'espresso-toolbar',
1404
+				'title'  => __('Extensions & Services', 'event_espresso'),
1405
+				'href'   => $extensions_admin_url,
1406
+				'meta'   => array(
1407
+					'title'  => __('Extensions & Services', 'event_espresso'),
1408
+					'target' => '',
1409
+					'class'  => $menu_class,
1410
+				),
1411
+			));
1412
+		}
1413
+	}
1414
+
1415
+
1416
+
1417
+	/**
1418
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1419
+	 * never returned with the function.
1420
+	 *
1421
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1422
+	 * @return array
1423
+	 */
1424
+	public function remove_pages_from_wp_list_pages($exclude_array)
1425
+	{
1426
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1427
+	}
1428 1428
 
1429 1429
 
1430 1430
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     {
186 186
         // set autoloaders for all of the classes implementing EEI_Plugin_API
187 187
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
188
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
189 189
         //load and setup EE_Capabilities
190 190
         $this->registry->load_core('Capabilities');
191 191
         //caps need to be initialized on every request so that capability maps are set.
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 && $_GET['activate'] === 'true'
209 209
             )
210 210
         ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
211
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
212 212
         }
213 213
         do_action('AHEE__EE_System__load_espresso_addons__complete');
214 214
     }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     private function _parse_model_names()
691 691
     {
692 692
         //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
693
+        $models = glob(EE_MODELS.'*.model.php');
694 694
         $model_names = array();
695 695
         $non_abstract_db_models = array();
696 696
         foreach ($models as $model) {
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
      */
719 719
     private function _maybe_brew_regular()
720 720
     {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
721
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
722
+            require_once EE_CAFF_PATH.'brewing_regular.php';
723 723
         }
724 724
     }
725 725
 
@@ -769,8 +769,8 @@  discard block
 block discarded – undo
769 769
                 'event_espresso');
770 770
             $msg .= '<ul>';
771 771
             foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
772
+                $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+                        $class_name).'</b></li>';
774 774
             }
775 775
             $msg .= '</ul>';
776 776
             $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
         $this->registry->load_core('Session');
922 922
         do_action('AHEE__EE_System__core_loaded_and_ready');
923 923
         // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
924
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
925
+            require_once(EE_PUBLIC.'template_tags.php');
926 926
         }
927 927
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928 928
         $this->registry->create('EventEspresso\core\services\assets\Registry');
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
             'href'  => $events_admin_url,
1069 1069
             'meta'  => array(
1070 1070
                 'title' => __('Event Espresso', 'event_espresso'),
1071
-                'class' => $menu_class . 'first',
1071
+                'class' => $menu_class.'first',
1072 1072
             ),
1073 1073
         ));
1074 1074
         //Events
Please login to merge, or discard this patch.
core/EE_Session.core.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidSessionDataException;
3 3
 use EventEspresso\core\services\cache\CacheStorageInterface;
4 4
 
5
-if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
6 6
 /**
7 7
  *
8 8
  * EE_Session class
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	  * array for defining default session vars
109 109
 	  * @var array
110 110
 	  */
111
-	 private $_default_session_vars = array (
111
+	 private $_default_session_vars = array(
112 112
         'id'            => null,
113 113
         'user_id'       => null,
114 114
         'ip_address'    => null,
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		// check if class object is instantiated
137 137
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
138 138
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
139
-		if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) {
140
-			self::$_instance = new self($cache_storage, $encryption );
139
+		if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
140
+			self::$_instance = new self($cache_storage, $encryption);
141 141
 		}
142 142
 		return self::$_instance;
143 143
 	}
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 	  * @throws \EE_Error
153 153
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
154 154
 	  */
155
-	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null ) {
155
+	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null) {
156 156
 
157 157
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
158
-		if ( ! apply_filters( 'FHEE_load_EE_Session', true ) ) {
158
+		if ( ! apply_filters('FHEE_load_EE_Session', true)) {
159 159
 			return;
160 160
 		}
161
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
162
-		if ( ! defined( 'ESPRESSO_SESSION' ) ) {
163
-			define( 'ESPRESSO_SESSION', true );
161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
162
+		if ( ! defined('ESPRESSO_SESSION')) {
163
+			define('ESPRESSO_SESSION', true);
164 164
 		}
165 165
 		// default session lifespan in seconds
166 166
 		$this->_lifespan = apply_filters(
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 		 * 		}
175 175
 		 */
176 176
 		// retrieve session options from db
177
-		$session_settings = (array) get_option( 'ee_session_settings', array() );
178
-		if ( ! empty( $session_settings )) {
177
+		$session_settings = (array) get_option('ee_session_settings', array());
178
+		if ( ! empty($session_settings)) {
179 179
 			// cycle though existing session options
180
-			foreach ( $session_settings as $var_name => $session_setting ) {
180
+			foreach ($session_settings as $var_name => $session_setting) {
181 181
 				// set values for class properties
182
-				$var_name = '_' . $var_name;
182
+				$var_name = '_'.$var_name;
183 183
 				$this->{$var_name} = $session_setting;
184 184
 			}
185 185
 		}
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
         // encrypt data via: $this->encryption->encrypt();
191 191
         $this->encryption = $encryption;
192 192
 		// filter hook allows outside functions/classes/plugins to change default empty cart
193
-		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
194
-		array_merge( $this->_default_session_vars, $extra_default_session_vars );
193
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
194
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
195 195
 		// apply default session vars
196 196
 		$this->_set_defaults();
197 197
          add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
198 198
          // check request for 'clear_session' param
199
-		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
199
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
200 200
 		// once everything is all said and done,
201
-		add_action( 'shutdown', array( $this, 'update' ), 100 );
201
+		add_action('shutdown', array($this, 'update'), 100);
202 202
          $this->configure_garbage_collection_filters();
203 203
 	}
204 204
 
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	private function _set_defaults() {
288 288
 		// set some defaults
289
-		foreach ( $this->_default_session_vars as $key => $default_var ) {
290
-			if ( is_array( $default_var )) {
291
-				$this->_session_data[ $key ] = array();
289
+		foreach ($this->_default_session_vars as $key => $default_var) {
290
+			if (is_array($default_var)) {
291
+				$this->_session_data[$key] = array();
292 292
 			} else {
293
-				$this->_session_data[ $key ] = '';
293
+				$this->_session_data[$key] = '';
294 294
 			}
295 295
 		}
296 296
 	}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	  * @param \EE_Checkout $checkout
346 346
 	  * @return bool
347 347
 	  */
348
-	 public function set_checkout( EE_Checkout $checkout ) {
348
+	 public function set_checkout(EE_Checkout $checkout) {
349 349
 		 $this->_session_data['checkout'] = $checkout;
350 350
 		 return TRUE;
351 351
 	 }
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	  * @return bool
379 379
 	  * @throws \EE_Error
380 380
 	  */
381
-	 public function set_transaction( EE_Transaction $transaction ) {
381
+	 public function set_transaction(EE_Transaction $transaction) {
382 382
 		 // first remove the session from the transaction before we save the transaction in the session
383
-		 $transaction->set_txn_session_data( NULL );
383
+		 $transaction->set_txn_session_data(NULL);
384 384
 		 $this->_session_data['transaction'] = $transaction;
385 385
 		 return TRUE;
386 386
 	 }
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 	  * @param bool $reset_cache
417 417
 	  * @return    array
418 418
 	  */
419
-	public function get_session_data( $key = NULL, $reset_cache = FALSE ) {
420
-		if ( $reset_cache ) {
419
+	public function get_session_data($key = NULL, $reset_cache = FALSE) {
420
+		if ($reset_cache) {
421 421
 			$this->reset_cart();
422 422
 			$this->reset_checkout();
423 423
 			$this->reset_transaction();
424 424
 		}
425
-		 if ( ! empty( $key ))  {
426
-			return  isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL;
427
-		}  else  {
425
+		 if ( ! empty($key)) {
426
+			return  isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL;
427
+		} else {
428 428
 			return $this->_session_data;
429 429
 		}
430 430
 	}
@@ -437,20 +437,20 @@  discard block
 block discarded – undo
437 437
 	  * @param 	array $data
438 438
 	  * @return 	TRUE on success, FALSE on fail
439 439
 	  */
440
-	public function set_session_data( $data ) {
440
+	public function set_session_data($data) {
441 441
 
442 442
 		// nothing ??? bad data ??? go home!
443
-		if ( empty( $data ) || ! is_array( $data )) {
444
-			EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
443
+		if (empty($data) || ! is_array($data)) {
444
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
445 445
 			return FALSE;
446 446
 		}
447 447
 
448
-		foreach ( $data as $key =>$value ) {
449
-			if ( isset( $this->_default_session_vars[ $key ] )) {
450
-				EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ );
448
+		foreach ($data as $key =>$value) {
449
+			if (isset($this->_default_session_vars[$key])) {
450
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
451 451
 				return FALSE;
452 452
 			} else {
453
-				$this->_session_data[ $key ] = $value;
453
+				$this->_session_data[$key] = $value;
454 454
 			}
455 455
 		}
456 456
 
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
 	  * @throws \EE_Error
469 469
 	  */
470 470
 	private function _espresso_session() {
471
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
471
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
472 472
 		// check that session has started
473
-		if ( session_id() === '' ) {
473
+		if (session_id() === '') {
474 474
 			//starts a new session if one doesn't already exist, or re-initiates an existing one
475 475
 			session_start();
476 476
 		}
@@ -479,39 +479,39 @@  discard block
 block discarded – undo
479 479
 		// and the visitors IP
480 480
 		$this->_ip_address = $this->_visitor_ip();
481 481
 		// set the "user agent"
482
-		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
482
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE;
483 483
 		// now let's retrieve what's in the db
484 484
         $session_data = $this->_retrieve_session_data();
485
-        if (! empty($session_data)) {
485
+        if ( ! empty($session_data)) {
486 486
             // get the current time in UTC
487
-			$this->_time = isset( $this->_time ) ? $this->_time : time();
487
+			$this->_time = isset($this->_time) ? $this->_time : time();
488 488
 			// and reset the session expiration
489
-			$this->_expiration = isset( $session_data['expiration'] )
489
+			$this->_expiration = isset($session_data['expiration'])
490 490
 				? $session_data['expiration']
491 491
 				: $this->_time + $this->_lifespan;
492 492
 		} else {
493 493
             // set initial site access time and the session expiration
494 494
 			$this->_set_init_access_and_expiration();
495 495
 			// set referer
496
-			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
497
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
496
+			$this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
497
+				? esc_attr($_SERVER['HTTP_REFERER'])
498 498
 				: '';
499 499
 			// no previous session = go back and create one (on top of the data above)
500 500
 			return FALSE;
501 501
 		}
502 502
         // now the user agent
503
-		if ( $session_data['user_agent'] !== $this->_user_agent ) {
503
+		if ($session_data['user_agent'] !== $this->_user_agent) {
504 504
 			return FALSE;
505 505
 		}
506 506
 		// wait a minute... how old are you?
507
-		if ( $this->_time > $this->_expiration ) {
507
+		if ($this->_time > $this->_expiration) {
508 508
 			// yer too old fer me!
509 509
             $this->_expired = true;
510 510
 			// wipe out everything that isn't a default session datum
511
-			$this->clear_session( __CLASS__, __FUNCTION__ );
511
+			$this->clear_session(__CLASS__, __FUNCTION__);
512 512
 		}
513 513
 		// make event espresso session data available to plugin
514
-		$this->_session_data = array_merge( $this->_session_data, $session_data );
514
+		$this->_session_data = array_merge($this->_session_data, $session_data);
515 515
 		return TRUE;
516 516
 
517 517
 	}
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
       */
528 528
      protected function _retrieve_session_data()
529 529
      {
530
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
530
+         $ssn_key = EE_Session::session_id_prefix.$this->_sid;
531 531
          try {
532 532
              // we're using WP's Transient API to store session data using the PHP session ID as the option name
533 533
              $session_data = $this->cache_storage->get($ssn_key, false);
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
              }
537 537
              if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
538 538
                  $hash_check = $this->cache_storage->get(
539
-                     EE_Session::hash_check_prefix . $this->_sid,
539
+                     EE_Session::hash_check_prefix.$this->_sid,
540 540
                      false
541 541
                  );
542 542
                  if ($hash_check && $hash_check !== md5($session_data)) {
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                                  'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
547 547
                                  'event_espresso'
548 548
                              ),
549
-                             EE_Session::session_id_prefix . $this->_sid
549
+                             EE_Session::session_id_prefix.$this->_sid
550 550
                          ),
551 551
                          __FILE__, __FUNCTION__, __LINE__
552 552
                      );
@@ -558,17 +558,17 @@  discard block
 block discarded – undo
558 558
              $row = $wpdb->get_row(
559 559
                  $wpdb->prepare(
560 560
                      "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
561
-                     '_transient_' . $ssn_key
561
+                     '_transient_'.$ssn_key
562 562
                  )
563 563
              );
564 564
              $session_data = is_object($row) ? $row->option_value : null;
565 565
              if ($session_data) {
566 566
                  $session_data = preg_replace_callback(
567 567
                      '!s:(d+):"(.*?)";!',
568
-                     function ($match) {
568
+                     function($match) {
569 569
                          return $match[1] === strlen($match[2])
570 570
                              ? $match[0]
571
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
571
+                             : 's:'.strlen($match[2]).':"'.$match[2].'";';
572 572
                      },
573 573
                      $session_data
574 574
                  );
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                      'event_espresso'
590 590
                  );
591 591
                  $msg .= WP_DEBUG
592
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
592
+                     ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
593 593
                      : '';
594 594
                  throw new InvalidSessionDataException($msg, 0, $e);
595 595
              }
@@ -602,11 +602,11 @@  discard block
 block discarded – undo
602 602
                  'event_espresso'
603 603
              );
604 604
              $msg .= WP_DEBUG
605
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
605
+                 ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
606 606
                  : '';
607 607
 	         throw new InvalidSessionDataException($msg);
608 608
          }
609
-	     if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) {
609
+	     if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
610 610
              $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
611 611
                  $session_data['transaction']
612 612
 	         );
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
 	  */
628 628
 	protected function _generate_session_id() {
629 629
 		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
630
-		if ( isset( $_REQUEST[ 'EESID' ] ) ) {
631
-			$session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] );
630
+		if (isset($_REQUEST['EESID'])) {
631
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
632 632
 		} else {
633
-			$session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() );
633
+			$session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
634 634
 		}
635
-		return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id );
635
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
636 636
 	}
637 637
 
638 638
 
@@ -644,20 +644,20 @@  discard block
 block discarded – undo
644 644
 	  */
645 645
 	protected function _get_sid_salt() {
646 646
 		// was session id salt already saved to db ?
647
-		if ( empty( $this->_sid_salt ) ) {
647
+		if (empty($this->_sid_salt)) {
648 648
 			// no?  then maybe use WP defined constant
649
-			if ( defined( 'AUTH_SALT' ) ) {
649
+			if (defined('AUTH_SALT')) {
650 650
 				$this->_sid_salt = AUTH_SALT;
651 651
 			}
652 652
 			// if salt doesn't exist or is too short
653
-			if ( strlen( $this->_sid_salt ) < 32 ) {
653
+			if (strlen($this->_sid_salt) < 32) {
654 654
 				// create a new one
655
-				$this->_sid_salt = wp_generate_password( 64 );
655
+				$this->_sid_salt = wp_generate_password(64);
656 656
 			}
657 657
 			// and save it as a permanent session setting
658
-			$session_settings = get_option( 'ee_session_settings' );
659
-			$session_settings[ 'sid_salt' ] = $this->_sid_salt;
660
-			update_option( 'ee_session_settings', $session_settings );
658
+			$session_settings = get_option('ee_session_settings');
659
+			$session_settings['sid_salt'] = $this->_sid_salt;
660
+			update_option('ee_session_settings', $session_settings);
661 661
 		}
662 662
 		return $this->_sid_salt;
663 663
 	}
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
       * @return TRUE on success, FALSE on fail
687 687
       * @throws \EE_Error
688 688
       */
689
-	public function update( $new_session = FALSE ) {
690
-		$this->_session_data = isset( $this->_session_data )
691
-			&& is_array( $this->_session_data )
692
-			&& isset( $this->_session_data['id'])
689
+	public function update($new_session = FALSE) {
690
+		$this->_session_data = isset($this->_session_data)
691
+			&& is_array($this->_session_data)
692
+			&& isset($this->_session_data['id'])
693 693
 			? $this->_session_data
694 694
 			: array();
695
-		if ( empty( $this->_session_data )) {
695
+		if (empty($this->_session_data)) {
696 696
 			$this->_set_defaults();
697 697
 		}
698 698
 		$session_data = array();
699
-		foreach ( $this->_session_data as $key => $value ) {
699
+		foreach ($this->_session_data as $key => $value) {
700 700
 
701
-			switch( $key ) {
701
+			switch ($key) {
702 702
 
703 703
 				case 'id' :
704 704
 					// session ID
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 				break;
717 717
 
718 718
 				case 'init_access' :
719
-					$session_data['init_access'] = absint( $value );
719
+					$session_data['init_access'] = absint($value);
720 720
 				break;
721 721
 
722 722
 				case 'last_access' :
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 
727 727
 				case 'expiration' :
728 728
 					// when the session expires
729
-					$session_data['expiration'] = ! empty( $this->_expiration )
729
+					$session_data['expiration'] = ! empty($this->_expiration)
730 730
 						? $this->_expiration
731 731
 						: $session_data['init_access'] + $this->_lifespan;
732 732
 				break;
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
 
739 739
 				case 'pages_visited' :
740 740
 					$page_visit = $this->_get_page_visit();
741
-					if ( $page_visit ) {
741
+					if ($page_visit) {
742 742
 						// set pages visited where the first will be the http referrer
743
-						$this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit;
743
+						$this->_session_data['pages_visited'][$this->_time] = $page_visit;
744 744
 						// we'll only save the last 10 page visits.
745
-						$session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 );
745
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
746 746
 					}
747 747
 				break;
748 748
 
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
 
757 757
 		$this->_session_data = $session_data;
758 758
 		// creating a new session does not require saving to the db just yet
759
-		if ( ! $new_session ) {
759
+		if ( ! $new_session) {
760 760
 			// ready? let's save
761
-			if ( $this->_save_session_to_db() ) {
761
+			if ($this->_save_session_to_db()) {
762 762
 				return TRUE;
763 763
 			} else {
764 764
 				return FALSE;
@@ -778,9 +778,9 @@  discard block
 block discarded – undo
778 778
       * @throws \EE_Error
779 779
       */
780 780
 	private function _create_espresso_session( ) {
781
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
781
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
782 782
 		// use the update function for now with $new_session arg set to TRUE
783
-		return  $this->update( TRUE ) ? TRUE : FALSE;
783
+		return  $this->update(TRUE) ? TRUE : FALSE;
784 784
 	}
785 785
 
786 786
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                 EE_Registry::instance()->REQ->front_ajax
801 801
                 || (
802 802
                     // OR an admin request that is NOT AJAX
803
-					! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
803
+					! (defined('DOING_AJAX') && DOING_AJAX)
804 804
                     && is_admin()
805 805
 				)
806 806
                 || (
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 			return false;
814 814
 		}
815 815
 		$transaction = $this->transaction();
816
-		if ( $transaction instanceof EE_Transaction ) {
817
-			if ( ! $transaction->ID() ) {
816
+		if ($transaction instanceof EE_Transaction) {
817
+			if ( ! $transaction->ID()) {
818 818
 				$transaction->save();
819 819
 			}
820 820
 			$this->_session_data['transaction'] = $transaction->ID();
@@ -823,19 +823,19 @@  discard block
 block discarded – undo
823 823
 		$session_data = serialize($this->_session_data);
824 824
 		// do we need to also encode it to avoid corrupted data when saved to the db?
825 825
 		$session_data = $this->_use_encryption
826
-            ? $this->encryption->base64_string_encode( $session_data )
826
+            ? $this->encryption->base64_string_encode($session_data)
827 827
             : $session_data;
828 828
 		// maybe save hash check
829
-		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
829
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
830 830
             $this->cache_storage->add(
831
-                EE_Session::hash_check_prefix . $this->_sid,
831
+                EE_Session::hash_check_prefix.$this->_sid,
832 832
                 md5($session_data),
833 833
                 $this->_lifespan
834 834
             );
835 835
         }
836 836
         // we're using the Transient API for storing session data,
837 837
         return $this->cache_storage->add(
838
-            EE_Session::session_id_prefix . $this->_sid,
838
+            EE_Session::session_id_prefix.$this->_sid,
839 839
             $session_data,
840 840
             $this->_lifespan
841 841
         );
@@ -864,10 +864,10 @@  discard block
 block discarded – undo
864 864
 			'HTTP_FORWARDED',
865 865
 			'REMOTE_ADDR'
866 866
 		);
867
-		foreach ( $server_keys as $key ){
868
-			if ( isset( $_SERVER[ $key ] )) {
869
-				foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) {
870
-					if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) {
867
+		foreach ($server_keys as $key) {
868
+			if (isset($_SERVER[$key])) {
869
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
870
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) {
871 871
 						$visitor_ip = $ip;
872 872
 					}
873 873
 				}
@@ -886,32 +886,32 @@  discard block
 block discarded – undo
886 886
 	 *			@return string
887 887
 	 */
888 888
 	public function _get_page_visit() {
889
-		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
889
+		$page_visit = home_url('/').'wp-admin/admin-ajax.php';
890 890
 		// check for request url
891
-		if ( isset( $_SERVER['REQUEST_URI'] )) {
891
+		if (isset($_SERVER['REQUEST_URI'])) {
892 892
 			$http_host = '';
893 893
 			$page_id = '?';
894 894
 			$e_reg = '';
895
-			$request_uri = esc_url( $_SERVER['REQUEST_URI'] );
896
-			$ru_bits = explode( '?', $request_uri );
895
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
896
+			$ru_bits = explode('?', $request_uri);
897 897
 			$request_uri = $ru_bits[0];
898 898
 			// check for and grab host as well
899
-			if ( isset( $_SERVER['HTTP_HOST'] )) {
900
-				$http_host = esc_url( $_SERVER['HTTP_HOST'] );
899
+			if (isset($_SERVER['HTTP_HOST'])) {
900
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
901 901
 			}
902 902
 			// check for page_id in SERVER REQUEST
903
-			if ( isset( $_REQUEST['page_id'] )) {
903
+			if (isset($_REQUEST['page_id'])) {
904 904
 				// rebuild $e_reg without any of the extra parameters
905
-				$page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&amp;';
905
+				$page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
906 906
 			}
907 907
 			// check for $e_reg in SERVER REQUEST
908
-			if ( isset( $_REQUEST['ee'] )) {
908
+			if (isset($_REQUEST['ee'])) {
909 909
 				// rebuild $e_reg without any of the extra parameters
910
-				$e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] );
910
+				$e_reg = 'ee='.esc_attr($_REQUEST['ee']);
911 911
 			}
912
-			$page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' );
912
+			$page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
913 913
 		}
914
-		return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : '';
914
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
915 915
 
916 916
 	}
917 917
 
@@ -941,14 +941,14 @@  discard block
 block discarded – undo
941 941
       * @return void
942 942
       * @throws \EE_Error
943 943
       */
944
-	public function clear_session( $class = '', $function = '' ) {
944
+	public function clear_session($class = '', $function = '') {
945 945
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
946
-        do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
946
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
947 947
 		$this->reset_cart();
948 948
 		$this->reset_checkout();
949 949
 		$this->reset_transaction();
950 950
 		// wipe out everything that isn't a default session datum
951
-		$this->reset_data( array_keys( $this->_session_data ));
951
+		$this->reset_data(array_keys($this->_session_data));
952 952
 		// reset initial site access time and the session expiration
953 953
 		$this->_set_init_access_and_expiration();
954 954
 		$this->_save_session_to_db();
@@ -963,42 +963,42 @@  discard block
 block discarded – undo
963 963
 	  * @param bool  $show_all_notices
964 964
 	  * @return TRUE on success, FALSE on fail
965 965
 	  */
966
-	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
966
+	public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) {
967 967
 		// if $data_to_reset is not in an array, then put it in one
968
-		if ( ! is_array( $data_to_reset ) ) {
969
-			$data_to_reset = array ( $data_to_reset );
968
+		if ( ! is_array($data_to_reset)) {
969
+			$data_to_reset = array($data_to_reset);
970 970
 		}
971 971
 		// nothing ??? go home!
972
-		if ( empty( $data_to_reset )) {
973
-			EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
972
+		if (empty($data_to_reset)) {
973
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
974 974
 			return FALSE;
975 975
 		}
976 976
 		$return_value = TRUE;
977 977
 		// since $data_to_reset is an array, cycle through the values
978
-		foreach ( $data_to_reset as $reset ) {
978
+		foreach ($data_to_reset as $reset) {
979 979
 
980 980
 			// first check to make sure it is a valid session var
981
-			if ( isset( $this->_session_data[ $reset ] )) {
981
+			if (isset($this->_session_data[$reset])) {
982 982
 				// then check to make sure it is not a default var
983
-				if ( ! array_key_exists( $reset, $this->_default_session_vars )) {
983
+				if ( ! array_key_exists($reset, $this->_default_session_vars)) {
984 984
 					// remove session var
985
-					unset( $this->_session_data[ $reset ] );
986
-					if ( $show_all_notices ) {
987
-						EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
985
+					unset($this->_session_data[$reset]);
986
+					if ($show_all_notices) {
987
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
988 988
 					}
989
-					$return_value = !isset($return_value) ? TRUE : $return_value;
989
+					$return_value = ! isset($return_value) ? TRUE : $return_value;
990 990
 
991 991
 				} else {
992 992
 					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
993
-					if ( $show_all_notices ) {
994
-						EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
993
+					if ($show_all_notices) {
994
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
995 995
 					}
996 996
 					$return_value = FALSE;
997 997
 				}
998 998
 
999
-			} else if ( $show_all_notices ) {
999
+			} else if ($show_all_notices) {
1000 1000
 				// oops! that session var does not exist!
1001
-				EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
1001
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1002 1002
 				$return_value = FALSE;
1003 1003
 			}
1004 1004
 
@@ -1017,8 +1017,8 @@  discard block
 block discarded – undo
1017 1017
       * @throws \EE_Error
1018 1018
       */
1019 1019
 	public function wp_loaded() {
1020
-		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
1021
-			$this->clear_session( __CLASS__, __FUNCTION__ );
1020
+		if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) {
1021
+			$this->clear_session(__CLASS__, __FUNCTION__);
1022 1022
 		}
1023 1023
 	}
1024 1024
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
              // or use that for the new transient cleanup query limit
1055 1055
              add_filter(
1056 1056
                  'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1057
-                 function () use ($expired_session_transient_delete_query_limit) {
1057
+                 function() use ($expired_session_transient_delete_query_limit) {
1058 1058
                      return $expired_session_transient_delete_query_limit;
1059 1059
                  }
1060 1060
              );
@@ -1068,34 +1068,34 @@  discard block
 block discarded – undo
1068 1068
 	  * @param $data1
1069 1069
 	  * @return string
1070 1070
 	  */
1071
-	 private function find_serialize_error( $data1 ) {
1071
+	 private function find_serialize_error($data1) {
1072 1072
 		$error = '<pre>';
1073 1073
 		 $data2 = preg_replace_callback(
1074 1074
 			 '!s:(\d+):"(.*?)";!',
1075
-			 function ( $match ) {
1076
-				 return ( $match[1] === strlen( $match[2] ) )
1075
+			 function($match) {
1076
+				 return ($match[1] === strlen($match[2]))
1077 1077
 					 ? $match[0]
1078 1078
 					 : 's:'
1079
-					   . strlen( $match[2] )
1079
+					   . strlen($match[2])
1080 1080
 					   . ':"'
1081 1081
 					   . $match[2]
1082 1082
 					   . '";';
1083 1083
 			 },
1084 1084
 			 $data1
1085 1085
 		 );
1086
-		$max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 );
1087
-		$error .= $data1 . PHP_EOL;
1088
-		$error .= $data2 . PHP_EOL;
1089
-		for ( $i = 0; $i < $max; $i++ ) {
1090
-			if ( @$data1[ $i ] !== @$data2[ $i ] ) {
1091
-				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1092
-				$error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . ' != ' . ord( @$data2[ $i ] ) . PHP_EOL;
1093
-				$error .= "\t-> Line Number = $i" . PHP_EOL;
1094
-				$start = ( $i - 20 );
1095
-				$start = ( $start < 0 ) ? 0 : $start;
1086
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1087
+		$error .= $data1.PHP_EOL;
1088
+		$error .= $data2.PHP_EOL;
1089
+		for ($i = 0; $i < $max; $i++) {
1090
+			if (@$data1[$i] !== @$data2[$i]) {
1091
+				$error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1092
+				$error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1093
+				$error .= "\t-> Line Number = $i".PHP_EOL;
1094
+				$start = ($i - 20);
1095
+				$start = ($start < 0) ? 0 : $start;
1096 1096
 				$length = 40;
1097 1097
 				$point = $max - $i;
1098
-				if ( $point < 20 ) {
1098
+				if ($point < 20) {
1099 1099
 					$rlength = 1;
1100 1100
 					$rpoint = -$point;
1101 1101
 				} else {
@@ -1104,16 +1104,16 @@  discard block
 block discarded – undo
1104 1104
 				}
1105 1105
 				$error .= "\t-> Section Data1  = ";
1106 1106
 				$error .= substr_replace(
1107
-					substr( $data1, $start, $length ),
1108
-					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1107
+					substr($data1, $start, $length),
1108
+					"<b style=\"color:green\">{$data1[$i]}</b>",
1109 1109
 					$rpoint,
1110 1110
 					$rlength
1111 1111
 				);
1112 1112
 				$error .= PHP_EOL;
1113 1113
 				$error .= "\t-> Section Data2  = ";
1114 1114
 				$error .= substr_replace(
1115
-					substr( $data2, $start, $length ),
1116
-					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1115
+					substr($data2, $start, $length),
1116
+					"<b style=\"color:red\">{$data2[$i]}</b>",
1117 1117
 					$rpoint,
1118 1118
 					$rlength
1119 1119
 				);
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -24,82 +24,82 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * the actual shortcode tag that gets registered with WordPress
29
-     *
30
-     * @return string
31
-     */
32
-    public function getTag()
33
-    {
34
-        return 'ESPRESSO_TICKET_SELECTOR';
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * the time in seconds to cache the results of the processShortcode() method
41
-     * 0 means the processShortcode() results will NOT be cached at all
42
-     *
43
-     * @return int
44
-     */
45
-    public function cacheExpiration()
46
-    {
47
-        return MINUTE_IN_SECONDS;
48
-    }
49
-
50
-
51
-    /**
52
-     * a place for adding any initialization code that needs to run prior to wp_header().
53
-     * this may be required for shortcodes that utilize a corresponding module,
54
-     * and need to enqueue assets for that module
55
-     *
56
-     * @return void
57
-     */
58
-    public function initializeShortcode()
59
-    {
60
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
61
-        $this->shortcodeHasBeenInitialized();
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * callback that runs when the shortcode is encountered in post content.
68
-     * IMPORTANT !!!
69
-     * remember that shortcode content should be RETURNED and NOT echoed out
70
-     *
71
-     * @param array $attributes
72
-     * @return string
73
-     * @throws InvalidArgumentException
74
-     */
75
-    public function processShortcode($attributes = array())
76
-    {
77
-        extract($attributes, EXTR_OVERWRITE);
78
-        $event_id = isset($event_id) ? $event_id : 0;
79
-        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
-        if (! $event instanceof EE_Event) {
81
-            new ExceptionStackTraceDisplay(
82
-                new InvalidArgumentException(
83
-                    sprintf(
84
-                        esc_html__(
85
-                            'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.',
86
-                            'event_espresso'
87
-                        ),
88
-                        $this->getTag(),
89
-                        $event_id,
90
-                        'event_id',
91
-                        '<br />'
92
-                    )
93
-                )
94
-            );
95
-            return '';
96
-        }
97
-        ob_start();
98
-        do_action('AHEE_event_details_before_post', $event_id);
99
-        espresso_ticket_selector($event);
100
-        do_action('AHEE_event_details_after_post');
101
-        return ob_get_clean();
102
-    }
27
+	/**
28
+	 * the actual shortcode tag that gets registered with WordPress
29
+	 *
30
+	 * @return string
31
+	 */
32
+	public function getTag()
33
+	{
34
+		return 'ESPRESSO_TICKET_SELECTOR';
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * the time in seconds to cache the results of the processShortcode() method
41
+	 * 0 means the processShortcode() results will NOT be cached at all
42
+	 *
43
+	 * @return int
44
+	 */
45
+	public function cacheExpiration()
46
+	{
47
+		return MINUTE_IN_SECONDS;
48
+	}
49
+
50
+
51
+	/**
52
+	 * a place for adding any initialization code that needs to run prior to wp_header().
53
+	 * this may be required for shortcodes that utilize a corresponding module,
54
+	 * and need to enqueue assets for that module
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function initializeShortcode()
59
+	{
60
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
61
+		$this->shortcodeHasBeenInitialized();
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * callback that runs when the shortcode is encountered in post content.
68
+	 * IMPORTANT !!!
69
+	 * remember that shortcode content should be RETURNED and NOT echoed out
70
+	 *
71
+	 * @param array $attributes
72
+	 * @return string
73
+	 * @throws InvalidArgumentException
74
+	 */
75
+	public function processShortcode($attributes = array())
76
+	{
77
+		extract($attributes, EXTR_OVERWRITE);
78
+		$event_id = isset($event_id) ? $event_id : 0;
79
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
+		if (! $event instanceof EE_Event) {
81
+			new ExceptionStackTraceDisplay(
82
+				new InvalidArgumentException(
83
+					sprintf(
84
+						esc_html__(
85
+							'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.',
86
+							'event_espresso'
87
+						),
88
+						$this->getTag(),
89
+						$event_id,
90
+						'event_id',
91
+						'<br />'
92
+					)
93
+				)
94
+			);
95
+			return '';
96
+		}
97
+		ob_start();
98
+		do_action('AHEE_event_details_before_post', $event_id);
99
+		espresso_ticket_selector($event);
100
+		do_action('AHEE_event_details_after_post');
101
+		return ob_get_clean();
102
+	}
103 103
 
104 104
 
105 105
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
         extract($attributes, EXTR_OVERWRITE);
78 78
         $event_id = isset($event_id) ? $event_id : 0;
79 79
         $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
-        if (! $event instanceof EE_Event) {
80
+        if ( ! $event instanceof EE_Event) {
81 81
             new ExceptionStackTraceDisplay(
82 82
                 new InvalidArgumentException(
83 83
                     sprintf(
Please login to merge, or discard this patch.
core/domain/services/session/SessionIdentifierInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@
 block discarded – undo
5 5
 interface SessionIdentifierInterface
6 6
 {
7 7
 
8
-    /**
9
-     * @return    string
10
-     */
11
-    public function id();
8
+	/**
9
+	 * @return    string
10
+	 */
11
+	public function id();
12 12
 
13 13
 }
14 14
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -199,13 +199,13 @@  discard block
 block discarded – undo
199 199
 			);
200 200
 			return CollectionLoader::ENTITY_ADDED;
201 201
 		}
202
-        do_action(
203
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
204
-            $this,
205
-            $this->collection_details->collectionName(),
206
-            $this->collection_details
207
-        );
208
-        return CollectionLoader::ENTITY_NOT_ADDED;
202
+		do_action(
203
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
204
+			$this,
205
+			$this->collection_details->collectionName(),
206
+			$this->collection_details
207
+		);
208
+		return CollectionLoader::ENTITY_NOT_ADDED;
209 209
 	}
210 210
 
211 211
 
@@ -220,37 +220,37 @@  discard block
 block discarded – undo
220 220
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
221 221
 	 */
222 222
 	protected function setIdentifier( $entity, $identifier ) {
223
-	    switch($this->collection_details->identifierType()) {
224
-	        // every unique object gets added to the collection, but not duplicates of the exact same object
225
-            case CollectionDetails::ID_OBJECT_HASH :
226
-                $identifier = spl_object_hash($entity);
227
-                break;
228
-            // only one entity per class can be added to collection, like a singleton
229
-            case CollectionDetails::ID_CLASS_NAME :
230
-                $identifier = get_class($entity);
231
-                break;
232
-            // objects added to the collection based on entity callback, so the entity itself decides
233
-            case CollectionDetails::ID_CALLBACK_METHOD :
234
-                $identifier_callback = $this->collection_details->identifierCallback();
235
-                if ( ! method_exists($entity, $identifier_callback)) {
236
-                    throw new InvalidEntityException(
237
-                        $entity,
238
-                        $this->collection_details->getCollectionInterface(),
239
-                        sprintf(
240
-                            __(
241
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
223
+		switch($this->collection_details->identifierType()) {
224
+			// every unique object gets added to the collection, but not duplicates of the exact same object
225
+			case CollectionDetails::ID_OBJECT_HASH :
226
+				$identifier = spl_object_hash($entity);
227
+				break;
228
+			// only one entity per class can be added to collection, like a singleton
229
+			case CollectionDetails::ID_CLASS_NAME :
230
+				$identifier = get_class($entity);
231
+				break;
232
+			// objects added to the collection based on entity callback, so the entity itself decides
233
+			case CollectionDetails::ID_CALLBACK_METHOD :
234
+				$identifier_callback = $this->collection_details->identifierCallback();
235
+				if ( ! method_exists($entity, $identifier_callback)) {
236
+					throw new InvalidEntityException(
237
+						$entity,
238
+						$this->collection_details->getCollectionInterface(),
239
+						sprintf(
240
+							__(
241
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
242 242
                                 of "%2$s", but does not contain this method.',
243
-                                'event_espresso'
244
-                            ),
245
-                            $identifier_callback,
246
-                            get_class($entity)
247
-                        )
248
-                    );
249
-                }
250
-                $identifier = $entity->{$identifier_callback}();
251
-                break;
252
-
253
-        }
243
+								'event_espresso'
244
+							),
245
+							$identifier_callback,
246
+							get_class($entity)
247
+						)
248
+					);
249
+				}
250
+				$identifier = $entity->{$identifier_callback}();
251
+				break;
252
+
253
+		}
254 254
 		return apply_filters(
255 255
 			'FHEE__CollectionLoader__addEntityToCollection__identifier',
256 256
 			$identifier,
Please login to merge, or discard this patch.
core/services/cache/BasicCacheManager.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         // with these parameters
141 141
         $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
142 142
         // then md5 the above to control it's length, add all of our prefixes, and truncate
143
-        return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
143
+        return substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182);
144 144
     }
145 145
 
146 146
 
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
         return '
171 171
 <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;">
172 172
     <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px">
173
-        <b>' . $type . '</b><span style="color:#999"> : </span>
174
-        <span>' . $cache_id . '</span>
175
-        <span style="margin-left:2em;">' . __FILE__ . '</span>
173
+        <b>' . $type.'</b><span style="color:#999"> : </span>
174
+        <span>' . $cache_id.'</span>
175
+        <span style="margin-left:2em;">' . __FILE__.'</span>
176 176
     </p>
177 177
 </div>';
178 178
     }
Please login to merge, or discard this patch.
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -19,140 +19,140 @@  discard block
 block discarded – undo
19 19
 class BasicCacheManager implements CacheManagerInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @type string
24
-     */
25
-    const CACHE_PREFIX = 'ee_cache_';
26
-
27
-
28
-    /**
29
-     * @var CacheStorageInterface $cache_storage
30
-     */
31
-    private $cache_storage;
32
-
33
-
34
-
35
-    /**
36
-     * BasicCacheManager constructor.
37
-     *
38
-     * @param CacheStorageInterface      $cache_storage [required]
39
-     */
40
-    public function __construct(CacheStorageInterface $cache_storage)
41
-    {
42
-        $this->cache_storage = $cache_storage;
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * returns a string that will be prepended to all cache identifiers
49
-     *
50
-     * @return string
51
-     */
52
-    public function cachePrefix()
53
-    {
54
-        return BasicCacheManager::CACHE_PREFIX;
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
61
-     *                           May also be helpful to include an additional specific identifier,
62
-     *                           such as a post ID as part of the $id_prefix so that individual caches
63
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
64
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
65
-     * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
66
-     *                           It is advisable to use some of the actual data
67
-     *                           that is used to generate the content being cached,
68
-     *                           in order to guarantee that the cache id is unique for that content.
69
-     *                           The cache id will be md5'd before usage to make it more db friendly,
70
-     *                           and the entire cache id string will be truncated to 190 characters.
71
-     * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
72
-     *                           necessary,
73
-     *                           we wrap our content creation in a Closure so that it is not executed until needed.
74
-     * @param int     $expiration
75
-     * @return Closure|mixed
76
-     */
77
-    public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
78
-    {
79
-        $content = '';
80
-        $expiration = absint(
81
-            apply_filters(
82
-                'FHEE__CacheManager__get__cache_expiration',
83
-                $expiration,
84
-                $id_prefix,
85
-                $cache_id
86
-            )
87
-        );
88
-        $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id);
89
-        // is caching enabled for this content ?
90
-        if ($expiration) {
91
-            $content = $this->cache_storage->get($cache_id);
92
-        }
93
-        // any existing content ?
94
-        if (empty($content)) {
95
-            // nope! let's generate some new stuff
96
-            $content = $callback();
97
-            // save the new content if caching is enabled
98
-            if ($expiration) {
99
-                $this->cache_storage->add($cache_id, $content, $expiration);
100
-                if (EE_DEBUG) {
101
-                    $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE');
102
-                }
103
-            }
104
-        } else {
105
-            if (EE_DEBUG) {
106
-                $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT');
107
-            }
108
-        }
109
-        return $content;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * Generates a unique identifier string for the cache
116
-     *
117
-     * @param string $id_prefix  [required] see BasicCacheManager::get()
118
-     * @param string $cache_id   [required] see BasicCacheManager::get()
119
-     * @return string
120
-     */
121
-    private function generateCacheIdentifier($id_prefix, $cache_id)
122
-    {
123
-        // let's make the cached content unique for this "page"
124
-        $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL);
125
-        // with these parameters
126
-        $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
127
-        // then md5 the above to control it's length, add all of our prefixes, and truncate
128
-        return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
135
-     *                               or a specific ID targeting a single cache item
136
-     * @return void
137
-     */
138
-    public function clear($cache_id)
139
-    {
140
-        // ensure incoming arg is in an array
141
-        $cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
142
-        // delete corresponding transients for the supplied id prefix
143
-        $this->cache_storage->deleteMany($cache_id);
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
150
-     *                               or a specific ID targeting a single cache item
151
-     * @param string       $type
152
-     * @return string
153
-     */
154
-    private function displayCacheNotice($cache_id, $type) {
155
-        return '
22
+	/**
23
+	 * @type string
24
+	 */
25
+	const CACHE_PREFIX = 'ee_cache_';
26
+
27
+
28
+	/**
29
+	 * @var CacheStorageInterface $cache_storage
30
+	 */
31
+	private $cache_storage;
32
+
33
+
34
+
35
+	/**
36
+	 * BasicCacheManager constructor.
37
+	 *
38
+	 * @param CacheStorageInterface      $cache_storage [required]
39
+	 */
40
+	public function __construct(CacheStorageInterface $cache_storage)
41
+	{
42
+		$this->cache_storage = $cache_storage;
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * returns a string that will be prepended to all cache identifiers
49
+	 *
50
+	 * @return string
51
+	 */
52
+	public function cachePrefix()
53
+	{
54
+		return BasicCacheManager::CACHE_PREFIX;
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
61
+	 *                           May also be helpful to include an additional specific identifier,
62
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
63
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
64
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
65
+	 * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
66
+	 *                           It is advisable to use some of the actual data
67
+	 *                           that is used to generate the content being cached,
68
+	 *                           in order to guarantee that the cache id is unique for that content.
69
+	 *                           The cache id will be md5'd before usage to make it more db friendly,
70
+	 *                           and the entire cache id string will be truncated to 190 characters.
71
+	 * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
72
+	 *                           necessary,
73
+	 *                           we wrap our content creation in a Closure so that it is not executed until needed.
74
+	 * @param int     $expiration
75
+	 * @return Closure|mixed
76
+	 */
77
+	public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
78
+	{
79
+		$content = '';
80
+		$expiration = absint(
81
+			apply_filters(
82
+				'FHEE__CacheManager__get__cache_expiration',
83
+				$expiration,
84
+				$id_prefix,
85
+				$cache_id
86
+			)
87
+		);
88
+		$cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id);
89
+		// is caching enabled for this content ?
90
+		if ($expiration) {
91
+			$content = $this->cache_storage->get($cache_id);
92
+		}
93
+		// any existing content ?
94
+		if (empty($content)) {
95
+			// nope! let's generate some new stuff
96
+			$content = $callback();
97
+			// save the new content if caching is enabled
98
+			if ($expiration) {
99
+				$this->cache_storage->add($cache_id, $content, $expiration);
100
+				if (EE_DEBUG) {
101
+					$content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE');
102
+				}
103
+			}
104
+		} else {
105
+			if (EE_DEBUG) {
106
+				$content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT');
107
+			}
108
+		}
109
+		return $content;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * Generates a unique identifier string for the cache
116
+	 *
117
+	 * @param string $id_prefix  [required] see BasicCacheManager::get()
118
+	 * @param string $cache_id   [required] see BasicCacheManager::get()
119
+	 * @return string
120
+	 */
121
+	private function generateCacheIdentifier($id_prefix, $cache_id)
122
+	{
123
+		// let's make the cached content unique for this "page"
124
+		$cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL);
125
+		// with these parameters
126
+		$cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
127
+		// then md5 the above to control it's length, add all of our prefixes, and truncate
128
+		return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
135
+	 *                               or a specific ID targeting a single cache item
136
+	 * @return void
137
+	 */
138
+	public function clear($cache_id)
139
+	{
140
+		// ensure incoming arg is in an array
141
+		$cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
142
+		// delete corresponding transients for the supplied id prefix
143
+		$this->cache_storage->deleteMany($cache_id);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
150
+	 *                               or a specific ID targeting a single cache item
151
+	 * @param string       $type
152
+	 * @return string
153
+	 */
154
+	private function displayCacheNotice($cache_id, $type) {
155
+		return '
156 156
 <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;">
157 157
     <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px">
158 158
         <b>' . $type . '</b><span style="color:#999"> : </span>
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         <span style="margin-left:2em;">' . __FILE__ . '</span>
161 161
     </p>
162 162
 </div>';
163
-    }
163
+	}
164 164
 
165 165
 }
166 166
 // End of file BasicCacheManager.php
Please login to merge, or discard this patch.
core/services/cache/PostRelatedCacheManager.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -18,93 +18,93 @@
 block discarded – undo
18 18
 class PostRelatedCacheManager extends BasicCacheManager
19 19
 {
20 20
 
21
-    /**
22
-     * @type string
23
-     */
24
-    const POST_CACHE_PREFIX = 'ee_cache_post_';
25
-
26
-    /**
27
-     * wp-option option_name for tracking post related cache
28
-     *
29
-     * @type string
30
-     */
31
-    const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
-
33
-
34
-
35
-    /**
36
-     * PostRelatedCacheManager constructor.
37
-     *
38
-     * @param CacheStorageInterface      $cache_storage
39
-     * @param SessionIdentifierInterface $session
40
-     */
41
-    public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session)
42
-    {
43
-        parent::__construct($cache_storage, $session);
44
-        add_action('save_post', array($this, 'clearPostRelatedCache'));
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * returns a string that will be prepended to all cache identifiers
51
-     *
52
-     * @return string
53
-     */
54
-    public function cachePrefix()
55
-    {
56
-        return PostRelatedCacheManager::POST_CACHE_PREFIX;
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * If you are caching content that pertains to a Post of any type,
63
-     * then it is recommended to pass the post id and cache id prefix to this method
64
-     * so that it can be added to the post related cache tracking.
65
-     * Then, whenever that post is updated, the cache will automatically be deleted,
66
-     * which helps to ensure that outdated cache content will not be served
67
-     *
68
-     * @param int    $post_ID    [required]
69
-     * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
70
-     *                           May also be helpful to include an additional specific identifier,
71
-     *                           such as a post ID as part of the $id_prefix so that individual caches
72
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
73
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
74
-     */
75
-    public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
76
-    {
77
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
78
-        // if post is not already being tracked
79
-        if ( ! isset($post_related_cache[$post_ID])) {
80
-            // add array to add cache ids to
81
-            $post_related_cache[$post_ID] = array();
82
-        }
83
-        // add cache id to be tracked
84
-        $post_related_cache[$post_ID][] = $id_prefix;
85
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * callback hooked into the WordPress "save_post" action
92
-     * deletes any cache content associated with the post
93
-     *
94
-     * @param int $post_ID [required]
95
-     */
96
-    public function clearPostRelatedCache($post_ID)
97
-    {
98
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
99
-        // if post is not being tracked
100
-        if ( ! isset($post_related_cache[$post_ID])) {
101
-            return;
102
-        }
103
-        // get cache id prefixes for post, and delete their corresponding transients
104
-        $this->clear($post_related_cache[$post_ID]);
105
-        unset($post_related_cache[$post_ID]);
106
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
107
-    }
21
+	/**
22
+	 * @type string
23
+	 */
24
+	const POST_CACHE_PREFIX = 'ee_cache_post_';
25
+
26
+	/**
27
+	 * wp-option option_name for tracking post related cache
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
+
33
+
34
+
35
+	/**
36
+	 * PostRelatedCacheManager constructor.
37
+	 *
38
+	 * @param CacheStorageInterface      $cache_storage
39
+	 * @param SessionIdentifierInterface $session
40
+	 */
41
+	public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session)
42
+	{
43
+		parent::__construct($cache_storage, $session);
44
+		add_action('save_post', array($this, 'clearPostRelatedCache'));
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * returns a string that will be prepended to all cache identifiers
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public function cachePrefix()
55
+	{
56
+		return PostRelatedCacheManager::POST_CACHE_PREFIX;
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * If you are caching content that pertains to a Post of any type,
63
+	 * then it is recommended to pass the post id and cache id prefix to this method
64
+	 * so that it can be added to the post related cache tracking.
65
+	 * Then, whenever that post is updated, the cache will automatically be deleted,
66
+	 * which helps to ensure that outdated cache content will not be served
67
+	 *
68
+	 * @param int    $post_ID    [required]
69
+	 * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
70
+	 *                           May also be helpful to include an additional specific identifier,
71
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
72
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
73
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
74
+	 */
75
+	public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
76
+	{
77
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
78
+		// if post is not already being tracked
79
+		if ( ! isset($post_related_cache[$post_ID])) {
80
+			// add array to add cache ids to
81
+			$post_related_cache[$post_ID] = array();
82
+		}
83
+		// add cache id to be tracked
84
+		$post_related_cache[$post_ID][] = $id_prefix;
85
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * callback hooked into the WordPress "save_post" action
92
+	 * deletes any cache content associated with the post
93
+	 *
94
+	 * @param int $post_ID [required]
95
+	 */
96
+	public function clearPostRelatedCache($post_ID)
97
+	{
98
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
99
+		// if post is not being tracked
100
+		if ( ! isset($post_related_cache[$post_ID])) {
101
+			return;
102
+		}
103
+		// get cache id prefixes for post, and delete their corresponding transients
104
+		$this->clear($post_related_cache[$post_ID]);
105
+		unset($post_related_cache[$post_ID]);
106
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
107
+	}
108 108
 
109 109
 
110 110
 }
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodesManager.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -32,211 +32,211 @@
 block discarded – undo
32 32
 class ShortcodesManager
33 33
 {
34 34
 
35
-    /**
36
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
37
-     */
38
-    private $legacy_shortcodes_manager;
39
-
40
-    /**
41
-     * @var ShortcodeInterface[] $shortcodes
42
-     */
43
-    private $shortcodes;
44
-
45
-
46
-
47
-    /**
48
-     * ShortcodesManager constructor
49
-     *
50
-     * @param LegacyShortcodesManager $legacy_shortcodes_manager
51
-     */
52
-    public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) {
53
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
54
-        // assemble a list of installed and active shortcodes
55
-        add_action(
56
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
57
-            array($this, 'registerShortcodes'),
58
-            999
59
-        );
60
-        //  call add_shortcode() for all installed shortcodes
61
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
62
-        // check content for shortcodes the old way
63
-        add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5);
64
-        // check content for shortcodes the NEW more efficient way
65
-        add_action('wp_head', array($this, 'wpHead'), 0);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return CollectionInterface|ShortcodeInterface[]
72
-     * @throws InvalidIdentifierException
73
-     * @throws InvalidInterfaceException
74
-     * @throws InvalidFilePathException
75
-     * @throws InvalidEntityException
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidClassException
78
-     */
79
-    public function getShortcodes()
80
-    {
81
-        if ( ! $this->shortcodes instanceof CollectionInterface) {
82
-            $this->shortcodes = $this->loadShortcodesCollection();
83
-        }
84
-        return $this->shortcodes;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * @return CollectionInterface|ShortcodeInterface[]
91
-     * @throws InvalidIdentifierException
92
-     * @throws InvalidInterfaceException
93
-     * @throws InvalidFilePathException
94
-     * @throws InvalidEntityException
95
-     * @throws InvalidDataTypeException
96
-     * @throws InvalidClassException
97
-     */
98
-    protected function loadShortcodesCollection()
99
-    {
100
-        $loader = new CollectionLoader(
101
-            new CollectionDetails(
102
-            // collection name
103
-                'shortcodes',
104
-                // collection interface
105
-                'EventEspresso\core\services\shortcodes\ShortcodeInterface',
106
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
107
-                array('EventEspresso\core\domain\entities\shortcodes'),
108
-                // filepaths to classes to add
109
-                array(),
110
-                // file mask to use if parsing folder for files to add
111
-                '',
112
-                // what to use as identifier for collection entities
113
-                // using CLASS NAME prevents duplicates (works like a singleton)
114
-                CollectionDetails::ID_CLASS_NAME
115
-            )
116
-        );
117
-        return $loader->getCollection();
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @return void
124
-     * @throws DomainException
125
-     * @throws InvalidInterfaceException
126
-     * @throws InvalidIdentifierException
127
-     * @throws InvalidFilePathException
128
-     * @throws InvalidEntityException
129
-     * @throws InvalidDataTypeException
130
-     * @throws InvalidClassException
131
-     */
132
-    public function registerShortcodes()
133
-    {
134
-        try {
135
-            $this->shortcodes = apply_filters(
136
-                'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
137
-                $this->getShortcodes()
138
-            );
139
-            if (! $this->shortcodes instanceof CollectionInterface) {
140
-                throw new InvalidEntityException(
141
-                    $this->shortcodes,
142
-                    'CollectionInterface',
143
-                    sprintf(
144
-                        esc_html__(
145
-                            'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
146
-                            'event_espresso'
147
-                        ),
148
-                        is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
149
-                    )
150
-                );
151
-            }
152
-            $this->legacy_shortcodes_manager->registerShortcodes();
153
-        } catch (Exception $exception) {
154
-            new ExceptionStackTraceDisplay($exception);
155
-        }
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * @return void
162
-     */
163
-    public function addShortcodes()
164
-    {
165
-        try {
166
-            // cycle thru shortcode folders
167
-            foreach ($this->shortcodes as $shortcode) {
168
-                /** @var ShortcodeInterface $shortcode */
169
-                if ( $shortcode instanceof EnqueueAssetsInterface) {
170
-                    add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
171
-                    add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
172
-                }
173
-                // add_shortcode() if it has not already been added
174
-                if ( ! shortcode_exists($shortcode->getTag())) {
175
-                    add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
176
-                }
177
-            }
178
-            $this->legacy_shortcodes_manager->addShortcodes();
179
-        } catch (Exception $exception) {
180
-            new ExceptionStackTraceDisplay($exception);
181
-        }
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * callback for the "wp_head" hook point
188
-     * checks posts for EE shortcodes, and initializes them,
189
-     * then toggles filter switch that loads core default assets
190
-     *
191
-     * @return void
192
-     */
193
-    public function wpHead()
194
-    {
195
-        global $wp_query;
196
-        if (empty($wp_query->posts)) {
197
-            return;
198
-        }
199
-        $load_assets = false;
200
-        // array of posts displayed in current request
201
-        $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
202
-        foreach ($posts as $post) {
203
-            // now check post content and excerpt for EE shortcodes
204
-            $load_assets = $this->parseContentForShortcodes($post->post_content)
205
-                ? true
206
-                : $load_assets;
207
-        }
208
-        if ($load_assets) {
209
-            $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true);
210
-            add_filter('FHEE_load_css', '__return_true');
211
-            add_filter('FHEE_load_js', '__return_true');
212
-        }
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * checks supplied content against list of shortcodes,
219
-     * then initializes any found shortcodes, and returns true.
220
-     * returns false if no shortcodes found.
221
-     *
222
-     * @param string $content
223
-     * @return bool
224
-     */
225
-    public function parseContentForShortcodes($content)
226
-    {
227
-        $has_shortcode = false;
228
-        if(empty($this->shortcodes)){
229
-            return $has_shortcode;
230
-        }
231
-        foreach ($this->shortcodes as $shortcode) {
232
-            /** @var ShortcodeInterface $shortcode */
233
-            if (has_shortcode($content, $shortcode->getTag())) {
234
-                $shortcode->initializeShortcode();
235
-                $has_shortcode = true;
236
-            }
237
-        }
238
-        return $has_shortcode;
239
-    }
35
+	/**
36
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
37
+	 */
38
+	private $legacy_shortcodes_manager;
39
+
40
+	/**
41
+	 * @var ShortcodeInterface[] $shortcodes
42
+	 */
43
+	private $shortcodes;
44
+
45
+
46
+
47
+	/**
48
+	 * ShortcodesManager constructor
49
+	 *
50
+	 * @param LegacyShortcodesManager $legacy_shortcodes_manager
51
+	 */
52
+	public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) {
53
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
54
+		// assemble a list of installed and active shortcodes
55
+		add_action(
56
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
57
+			array($this, 'registerShortcodes'),
58
+			999
59
+		);
60
+		//  call add_shortcode() for all installed shortcodes
61
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
62
+		// check content for shortcodes the old way
63
+		add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5);
64
+		// check content for shortcodes the NEW more efficient way
65
+		add_action('wp_head', array($this, 'wpHead'), 0);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return CollectionInterface|ShortcodeInterface[]
72
+	 * @throws InvalidIdentifierException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws InvalidFilePathException
75
+	 * @throws InvalidEntityException
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidClassException
78
+	 */
79
+	public function getShortcodes()
80
+	{
81
+		if ( ! $this->shortcodes instanceof CollectionInterface) {
82
+			$this->shortcodes = $this->loadShortcodesCollection();
83
+		}
84
+		return $this->shortcodes;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * @return CollectionInterface|ShortcodeInterface[]
91
+	 * @throws InvalidIdentifierException
92
+	 * @throws InvalidInterfaceException
93
+	 * @throws InvalidFilePathException
94
+	 * @throws InvalidEntityException
95
+	 * @throws InvalidDataTypeException
96
+	 * @throws InvalidClassException
97
+	 */
98
+	protected function loadShortcodesCollection()
99
+	{
100
+		$loader = new CollectionLoader(
101
+			new CollectionDetails(
102
+			// collection name
103
+				'shortcodes',
104
+				// collection interface
105
+				'EventEspresso\core\services\shortcodes\ShortcodeInterface',
106
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
107
+				array('EventEspresso\core\domain\entities\shortcodes'),
108
+				// filepaths to classes to add
109
+				array(),
110
+				// file mask to use if parsing folder for files to add
111
+				'',
112
+				// what to use as identifier for collection entities
113
+				// using CLASS NAME prevents duplicates (works like a singleton)
114
+				CollectionDetails::ID_CLASS_NAME
115
+			)
116
+		);
117
+		return $loader->getCollection();
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @return void
124
+	 * @throws DomainException
125
+	 * @throws InvalidInterfaceException
126
+	 * @throws InvalidIdentifierException
127
+	 * @throws InvalidFilePathException
128
+	 * @throws InvalidEntityException
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws InvalidClassException
131
+	 */
132
+	public function registerShortcodes()
133
+	{
134
+		try {
135
+			$this->shortcodes = apply_filters(
136
+				'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
137
+				$this->getShortcodes()
138
+			);
139
+			if (! $this->shortcodes instanceof CollectionInterface) {
140
+				throw new InvalidEntityException(
141
+					$this->shortcodes,
142
+					'CollectionInterface',
143
+					sprintf(
144
+						esc_html__(
145
+							'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
146
+							'event_espresso'
147
+						),
148
+						is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
149
+					)
150
+				);
151
+			}
152
+			$this->legacy_shortcodes_manager->registerShortcodes();
153
+		} catch (Exception $exception) {
154
+			new ExceptionStackTraceDisplay($exception);
155
+		}
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * @return void
162
+	 */
163
+	public function addShortcodes()
164
+	{
165
+		try {
166
+			// cycle thru shortcode folders
167
+			foreach ($this->shortcodes as $shortcode) {
168
+				/** @var ShortcodeInterface $shortcode */
169
+				if ( $shortcode instanceof EnqueueAssetsInterface) {
170
+					add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
171
+					add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
172
+				}
173
+				// add_shortcode() if it has not already been added
174
+				if ( ! shortcode_exists($shortcode->getTag())) {
175
+					add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
176
+				}
177
+			}
178
+			$this->legacy_shortcodes_manager->addShortcodes();
179
+		} catch (Exception $exception) {
180
+			new ExceptionStackTraceDisplay($exception);
181
+		}
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * callback for the "wp_head" hook point
188
+	 * checks posts for EE shortcodes, and initializes them,
189
+	 * then toggles filter switch that loads core default assets
190
+	 *
191
+	 * @return void
192
+	 */
193
+	public function wpHead()
194
+	{
195
+		global $wp_query;
196
+		if (empty($wp_query->posts)) {
197
+			return;
198
+		}
199
+		$load_assets = false;
200
+		// array of posts displayed in current request
201
+		$posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
202
+		foreach ($posts as $post) {
203
+			// now check post content and excerpt for EE shortcodes
204
+			$load_assets = $this->parseContentForShortcodes($post->post_content)
205
+				? true
206
+				: $load_assets;
207
+		}
208
+		if ($load_assets) {
209
+			$this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true);
210
+			add_filter('FHEE_load_css', '__return_true');
211
+			add_filter('FHEE_load_js', '__return_true');
212
+		}
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * checks supplied content against list of shortcodes,
219
+	 * then initializes any found shortcodes, and returns true.
220
+	 * returns false if no shortcodes found.
221
+	 *
222
+	 * @param string $content
223
+	 * @return bool
224
+	 */
225
+	public function parseContentForShortcodes($content)
226
+	{
227
+		$has_shortcode = false;
228
+		if(empty($this->shortcodes)){
229
+			return $has_shortcode;
230
+		}
231
+		foreach ($this->shortcodes as $shortcode) {
232
+			/** @var ShortcodeInterface $shortcode */
233
+			if (has_shortcode($content, $shortcode->getTag())) {
234
+				$shortcode->initializeShortcode();
235
+				$has_shortcode = true;
236
+			}
237
+		}
238
+		return $has_shortcode;
239
+	}
240 240
 
241 241
 }
242 242
 // End of file ShortcodesManager.php
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -21,219 +21,219 @@
 block discarded – undo
21 21
 abstract class EspressoShortcode implements ShortcodeInterface
22 22
 {
23 23
 
24
-    /**
25
-     * transient prefix
26
-     *
27
-     * @type string
28
-     */
29
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
30
-
31
-    /**
32
-     * @var PostRelatedCacheManager $cache_manager
33
-     */
34
-    private $cache_manager;
35
-
36
-    /**
37
-     * true if ShortcodeInterface::initializeShortcode() has been called
38
-     * if false, then that will get called before processing
39
-     *
40
-     * @var boolean $initialized
41
-     */
42
-    private $initialized = false;
43
-
44
-
45
-
46
-    /**
47
-     * EspressoShortcode constructor
48
-     *
49
-     * @param PostRelatedCacheManager $cache_manager
50
-     */
51
-    public function __construct(PostRelatedCacheManager $cache_manager)
52
-    {
53
-        $this->cache_manager = $cache_manager;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * @return void
60
-     */
61
-    public function shortcodeHasBeenInitialized()
62
-    {
63
-        $this->initialized = true;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * enqueues scripts then processes the shortcode
70
-     *
71
-     * @param array $attributes
72
-     * @return string
73
-     * @throws EE_Error
74
-     */
75
-    final public function processShortcodeCallback($attributes = array())
76
-    {
77
-        if ($this instanceof EnqueueAssetsInterface) {
78
-            if (is_admin()) {
79
-                $this->enqueueAdminScripts();
80
-            } else {
81
-                $this->enqueueScripts();
82
-            }
83
-        }
84
-        return $this->shortcodeContent(
85
-            $this->sanitizeAttributes((array)$attributes)
86
-        );
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * If shortcode caching is enabled for the shortcode,
93
-     * and cached results exist, then that will be returned
94
-     * else new content will be generated.
95
-     * If caching is enabled, then the new content will be cached for later.
96
-     *
97
-     * @param array $attributes
98
-     * @return mixed|string
99
-     * @throws EE_Error
100
-     */
101
-    private function shortcodeContent(array $attributes)
102
-    {
103
-        $shortcode = $this;
104
-        $post_ID = $this->currentPostID();
105
-        // something like "SC_EVENTS-123"
106
-        $cache_ID = $this->shortcodeCacheID($post_ID);
107
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
108
-        return $this->cache_manager->get(
109
-            $cache_ID,
110
-            // serialized attributes
111
-            wp_json_encode($attributes),
112
-            // Closure for generating content if cache is expired
113
-            function () use ($shortcode, $attributes) {
114
-                if($shortcode->initialized === false){
115
-                    $shortcode->initializeShortcode();
116
-                }
117
-                return $shortcode->processShortcode($attributes);
118
-            },
119
-            // filterable cache expiration set by each shortcode
120
-            apply_filters(
121
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
122
-                $this->cacheExpiration(),
123
-                $this->getTag(),
124
-                $this
125
-            )
126
-        );
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @return int
133
-     * @throws EE_Error
134
-     */
135
-    private function currentPostID()
136
-    {
137
-        // try to get EE_Event any way we can
138
-        $event = EEH_Event_View::get_event();
139
-        // then get some kind of ID
140
-        if ($event instanceof \EE_Event) {
141
-            $post_ID = $event->ID();
142
-        } else {
143
-            global $post;
144
-            $post_ID = $post->ID;
145
-        }
146
-        return $post_ID;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param int $post_ID
153
-     * @return string
154
-     * @throws EE_Error
155
-     */
156
-    private function shortcodeCacheID($post_ID)
157
-    {
158
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
159
-        return "SC_{$tag}-{$post_ID}";
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * array for defining custom attribute sanitization callbacks,
166
-     * where keys match keys in your attributes array,
167
-     * and values represent the sanitization function you wish to be applied to that attribute.
168
-     * So for example, if you had an integer attribute named "event_id"
169
-     * that you wanted to be sanitized using absint(),
170
-     * then you would return the following:
171
-     *      array('event_id' => 'absint')
172
-     * Entering 'skip_sanitization' for the callback value
173
-     * means that no sanitization will be applied
174
-     * on the assumption that the attribute
175
-     * will be sanitized at some point... right?
176
-     * You wouldn't pass around unsanitized attributes would you?
177
-     * That would be very Tom Foolery of you!!!
178
-     *
179
-     * @return array
180
-     */
181
-    protected function customAttributeSanitizationMap()
182
-    {
183
-        return array();
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Performs basic sanitization on shortcode attributes
190
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
191
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
192
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
193
-     * all other attributes would be sanitized using the defaults in the switch statement below
194
-     *
195
-     * @param array $attributes
196
-     * @return array
197
-     */
198
-    private function sanitizeAttributes(array $attributes)
199
-    {
200
-        $custom_sanitization = $this->customAttributeSanitizationMap();
201
-        foreach ($attributes as $key => $value) {
202
-            // is a custom sanitization callback specified ?
203
-            if (isset($custom_sanitization[$key])) {
204
-                $callback = $custom_sanitization[$key];
205
-                if ($callback === 'skip_sanitization') {
206
-                    $attributes[$key] = $value;
207
-                    continue;
208
-                }
209
-                if (function_exists($callback)) {
210
-                    $attributes[$key] = $callback($value);
211
-                    continue;
212
-                }
213
-            }
214
-            switch (true) {
215
-                case $value === null :
216
-                case is_int($value) :
217
-                case is_float($value) :
218
-                    // typical booleans
219
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
220
-                    $attributes[$key] = $value;
221
-                    break;
222
-                case is_string($value) :
223
-                    $attributes[$key] = sanitize_text_field($value);
224
-                    break;
225
-                case is_array($value) :
226
-                    $attributes[$key] = $this->sanitizeAttributes($value);
227
-                    break;
228
-                default :
229
-                    // only remaining data types are Object and Resource
230
-                    // which are not allowed as shortcode attributes
231
-                    $attributes[$key] = null;
232
-                    break;
233
-            }
234
-        }
235
-        return $attributes;
236
-    }
24
+	/**
25
+	 * transient prefix
26
+	 *
27
+	 * @type string
28
+	 */
29
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
30
+
31
+	/**
32
+	 * @var PostRelatedCacheManager $cache_manager
33
+	 */
34
+	private $cache_manager;
35
+
36
+	/**
37
+	 * true if ShortcodeInterface::initializeShortcode() has been called
38
+	 * if false, then that will get called before processing
39
+	 *
40
+	 * @var boolean $initialized
41
+	 */
42
+	private $initialized = false;
43
+
44
+
45
+
46
+	/**
47
+	 * EspressoShortcode constructor
48
+	 *
49
+	 * @param PostRelatedCacheManager $cache_manager
50
+	 */
51
+	public function __construct(PostRelatedCacheManager $cache_manager)
52
+	{
53
+		$this->cache_manager = $cache_manager;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * @return void
60
+	 */
61
+	public function shortcodeHasBeenInitialized()
62
+	{
63
+		$this->initialized = true;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * enqueues scripts then processes the shortcode
70
+	 *
71
+	 * @param array $attributes
72
+	 * @return string
73
+	 * @throws EE_Error
74
+	 */
75
+	final public function processShortcodeCallback($attributes = array())
76
+	{
77
+		if ($this instanceof EnqueueAssetsInterface) {
78
+			if (is_admin()) {
79
+				$this->enqueueAdminScripts();
80
+			} else {
81
+				$this->enqueueScripts();
82
+			}
83
+		}
84
+		return $this->shortcodeContent(
85
+			$this->sanitizeAttributes((array)$attributes)
86
+		);
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * If shortcode caching is enabled for the shortcode,
93
+	 * and cached results exist, then that will be returned
94
+	 * else new content will be generated.
95
+	 * If caching is enabled, then the new content will be cached for later.
96
+	 *
97
+	 * @param array $attributes
98
+	 * @return mixed|string
99
+	 * @throws EE_Error
100
+	 */
101
+	private function shortcodeContent(array $attributes)
102
+	{
103
+		$shortcode = $this;
104
+		$post_ID = $this->currentPostID();
105
+		// something like "SC_EVENTS-123"
106
+		$cache_ID = $this->shortcodeCacheID($post_ID);
107
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
108
+		return $this->cache_manager->get(
109
+			$cache_ID,
110
+			// serialized attributes
111
+			wp_json_encode($attributes),
112
+			// Closure for generating content if cache is expired
113
+			function () use ($shortcode, $attributes) {
114
+				if($shortcode->initialized === false){
115
+					$shortcode->initializeShortcode();
116
+				}
117
+				return $shortcode->processShortcode($attributes);
118
+			},
119
+			// filterable cache expiration set by each shortcode
120
+			apply_filters(
121
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
122
+				$this->cacheExpiration(),
123
+				$this->getTag(),
124
+				$this
125
+			)
126
+		);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @return int
133
+	 * @throws EE_Error
134
+	 */
135
+	private function currentPostID()
136
+	{
137
+		// try to get EE_Event any way we can
138
+		$event = EEH_Event_View::get_event();
139
+		// then get some kind of ID
140
+		if ($event instanceof \EE_Event) {
141
+			$post_ID = $event->ID();
142
+		} else {
143
+			global $post;
144
+			$post_ID = $post->ID;
145
+		}
146
+		return $post_ID;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param int $post_ID
153
+	 * @return string
154
+	 * @throws EE_Error
155
+	 */
156
+	private function shortcodeCacheID($post_ID)
157
+	{
158
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
159
+		return "SC_{$tag}-{$post_ID}";
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * array for defining custom attribute sanitization callbacks,
166
+	 * where keys match keys in your attributes array,
167
+	 * and values represent the sanitization function you wish to be applied to that attribute.
168
+	 * So for example, if you had an integer attribute named "event_id"
169
+	 * that you wanted to be sanitized using absint(),
170
+	 * then you would return the following:
171
+	 *      array('event_id' => 'absint')
172
+	 * Entering 'skip_sanitization' for the callback value
173
+	 * means that no sanitization will be applied
174
+	 * on the assumption that the attribute
175
+	 * will be sanitized at some point... right?
176
+	 * You wouldn't pass around unsanitized attributes would you?
177
+	 * That would be very Tom Foolery of you!!!
178
+	 *
179
+	 * @return array
180
+	 */
181
+	protected function customAttributeSanitizationMap()
182
+	{
183
+		return array();
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Performs basic sanitization on shortcode attributes
190
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
191
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
192
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
193
+	 * all other attributes would be sanitized using the defaults in the switch statement below
194
+	 *
195
+	 * @param array $attributes
196
+	 * @return array
197
+	 */
198
+	private function sanitizeAttributes(array $attributes)
199
+	{
200
+		$custom_sanitization = $this->customAttributeSanitizationMap();
201
+		foreach ($attributes as $key => $value) {
202
+			// is a custom sanitization callback specified ?
203
+			if (isset($custom_sanitization[$key])) {
204
+				$callback = $custom_sanitization[$key];
205
+				if ($callback === 'skip_sanitization') {
206
+					$attributes[$key] = $value;
207
+					continue;
208
+				}
209
+				if (function_exists($callback)) {
210
+					$attributes[$key] = $callback($value);
211
+					continue;
212
+				}
213
+			}
214
+			switch (true) {
215
+				case $value === null :
216
+				case is_int($value) :
217
+				case is_float($value) :
218
+					// typical booleans
219
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
220
+					$attributes[$key] = $value;
221
+					break;
222
+				case is_string($value) :
223
+					$attributes[$key] = sanitize_text_field($value);
224
+					break;
225
+				case is_array($value) :
226
+					$attributes[$key] = $this->sanitizeAttributes($value);
227
+					break;
228
+				default :
229
+					// only remaining data types are Object and Resource
230
+					// which are not allowed as shortcode attributes
231
+					$attributes[$key] = null;
232
+					break;
233
+			}
234
+		}
235
+		return $attributes;
236
+	}
237 237
 
238 238
 
239 239
 
Please login to merge, or discard this patch.