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