Completed
Branch FET-10768-extract-admin-bar (79a636)
by
unknown
95:29 queued 84:14
created
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.031');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.031');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Registry.core.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -296,13 +296,13 @@  discard block
 block discarded – undo
296 296
      */
297 297
     public static function localize_i18n_js_strings()
298 298
     {
299
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
299
+        $i18n_js_strings = (array) EE_Registry::$i18n_js_strings;
300 300
         foreach ($i18n_js_strings as $key => $value) {
301 301
             if (is_scalar($value)) {
302
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
302
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
303 303
             }
304 304
         }
305
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
305
+        return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */';
306 306
     }
307 307
 
308 308
 
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
                 EE_CORE,
354 354
                 EE_ADMIN,
355 355
                 EE_CPTS,
356
-                EE_CORE . 'data_migration_scripts' . DS,
357
-                EE_CORE . 'request_stack' . DS,
358
-                EE_CORE . 'middleware' . DS,
356
+                EE_CORE.'data_migration_scripts'.DS,
357
+                EE_CORE.'request_stack'.DS,
358
+                EE_CORE.'middleware'.DS,
359 359
             )
360 360
         );
361 361
         // retrieve instantiated class
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         $service_paths = apply_filters(
379 379
             'FHEE__EE_Registry__load_service__service_paths',
380 380
             array(
381
-                EE_CORE . 'services' . DS,
381
+                EE_CORE.'services'.DS,
382 382
             )
383 383
         );
384 384
         // retrieve instantiated class
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
     {
459 459
         $paths = array(
460 460
             EE_LIBRARIES,
461
-            EE_LIBRARIES . 'messages' . DS,
462
-            EE_LIBRARIES . 'shortcodes' . DS,
463
-            EE_LIBRARIES . 'qtips' . DS,
464
-            EE_LIBRARIES . 'payment_methods' . DS,
461
+            EE_LIBRARIES.'messages'.DS,
462
+            EE_LIBRARIES.'shortcodes'.DS,
463
+            EE_LIBRARIES.'qtips'.DS,
464
+            EE_LIBRARIES.'payment_methods'.DS,
465 465
         );
466 466
         // retrieve instantiated class
467 467
         return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
@@ -500,10 +500,10 @@  discard block
 block discarded – undo
500 500
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
501 501
     {
502 502
         $paths = array(
503
-            EE_MODELS . 'fields' . DS,
504
-            EE_MODELS . 'helpers' . DS,
505
-            EE_MODELS . 'relations' . DS,
506
-            EE_MODELS . 'strategies' . DS,
503
+            EE_MODELS.'fields'.DS,
504
+            EE_MODELS.'helpers'.DS,
505
+            EE_MODELS.'relations'.DS,
506
+            EE_MODELS.'strategies'.DS,
507 507
         );
508 508
         // retrieve instantiated class
509 509
         return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
         $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
593 593
         // if a non-FQCN was passed, then verifyClassExists() might return an object
594 594
         // or it could return null if the class just could not be found anywhere
595
-        if ($class_exists instanceof $class_name || $class_exists === null){
595
+        if ($class_exists instanceof $class_name || $class_exists === null) {
596 596
             // either way, return the results
597 597
             return $class_exists;
598 598
         }
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
         // instantiate the requested object
616 616
         $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
617 617
         // if caching is turned on OR this class is cached in a class property
618
-        if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) {
618
+        if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[$class_name])) {
619 619
             // save it for later... kinda like gum  { : $
620 620
             $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
621 621
         }
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
             case 1:
642 642
                 // if it's a FQCN then maybe the class is registered with a preceding \
643 643
                 $class_name = strpos($class_name, '\\') !== false
644
-                    ? '\\' . ltrim($class_name, '\\')
644
+                    ? '\\'.ltrim($class_name, '\\')
645 645
                     : $class_name;
646 646
                 break;
647 647
             case 2:
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
             // make sure $class_prefix is uppercase
697 697
             $class_prefix = strtoupper(trim($class_prefix));
698 698
             // add class prefix ONCE!!!
699
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
699
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
700 700
         }
701 701
         $class_name = $this->_dependency_map->get_alias($class_name);
702 702
         $class_exists = class_exists($class_name);
@@ -759,8 +759,8 @@  discard block
 block discarded – undo
759 759
             return $this;
760 760
         }
761 761
         // have to specify something, but not anything that will conflict
762
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
763
-            ? $this->_class_abbreviations[ $class_name ]
762
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
763
+            ? $this->_class_abbreviations[$class_name]
764 764
             : 'FANCY_BATMAN_PANTS';
765 765
         $class_name = str_replace('\\', '_', $class_name);
766 766
         // check if class has already been loaded, and return it if it has been
@@ -791,8 +791,8 @@  discard block
 block discarded – undo
791 791
     public function clear_cached_class($class_name, $addon = false)
792 792
     {
793 793
         // have to specify something, but not anything that will conflict
794
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
795
-            ? $this->_class_abbreviations[ $class_name ]
794
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
795
+            ? $this->_class_abbreviations[$class_name]
796 796
             : 'FANCY_BATMAN_PANTS';
797 797
         $class_name = str_replace('\\', '_', $class_name);
798 798
         // check if class has already been loaded, and return it if it has been
@@ -837,9 +837,9 @@  discard block
 block discarded – undo
837 837
             // convert all separators to proper DS, if no filepath, then use EE_CLASSES
838 838
             $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
839 839
             // prep file type
840
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
840
+            $type = ! empty($type) ? trim($type, '.').'.' : '';
841 841
             // build full file path
842
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
842
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
843 843
             //does the file exist and can be read ?
844 844
             if (is_readable($file_paths[$key])) {
845 845
                 return $file_paths[$key];
@@ -870,12 +870,12 @@  discard block
 block discarded – undo
870 870
             //does the file exist and can it be read ?
871 871
             if ( ! $path) {
872 872
                 // so sorry, can't find the file
873
-                throw new EE_Error (
873
+                throw new EE_Error(
874 874
                     sprintf(
875 875
                         __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
876 876
                         trim($type, '.'),
877 877
                         $class_name,
878
-                        '<br />' . implode(',<br />', $file_paths)
878
+                        '<br />'.implode(',<br />', $file_paths)
879 879
                     )
880 880
                 );
881 881
             }
Please login to merge, or discard this patch.
Indentation   +1466 added lines, -1466 removed lines patch added patch discarded remove patch
@@ -19,1502 +19,1502 @@
 block discarded – undo
19 19
 class EE_Registry implements ResettableInterface
20 20
 {
21 21
 
22
-    /**
23
-     *    EE_Registry Object
24
-     *
25
-     * @var EE_Registry $_instance
26
-     * @access    private
27
-     */
28
-    private static $_instance = null;
29
-
30
-    /**
31
-     * @var EE_Dependency_Map $_dependency_map
32
-     * @access    protected
33
-     */
34
-    protected $_dependency_map = null;
35
-
36
-    /**
37
-     * @var array $_class_abbreviations
38
-     * @access    protected
39
-     */
40
-    protected $_class_abbreviations = array();
41
-
42
-    /**
43
-     * @access public
44
-     * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
45
-     */
46
-    public $BUS;
47
-
48
-    /**
49
-     *    EE_Cart Object
50
-     *
51
-     * @access    public
52
-     * @var    EE_Cart $CART
53
-     */
54
-    public $CART = null;
55
-
56
-    /**
57
-     *    EE_Config Object
58
-     *
59
-     * @access    public
60
-     * @var    EE_Config $CFG
61
-     */
62
-    public $CFG = null;
63
-
64
-    /**
65
-     * EE_Network_Config Object
66
-     *
67
-     * @access public
68
-     * @var EE_Network_Config $NET_CFG
69
-     */
70
-    public $NET_CFG = null;
71
-
72
-    /**
73
-     *    StdClass object for storing library classes in
74
-     *
75
-     * @public LIB
76
-     * @var StdClass $LIB
77
-     */
78
-    public $LIB = null;
79
-
80
-    /**
81
-     *    EE_Request_Handler Object
82
-     *
83
-     * @access    public
84
-     * @var    EE_Request_Handler $REQ
85
-     */
86
-    public $REQ = null;
87
-
88
-    /**
89
-     *    EE_Session Object
90
-     *
91
-     * @access    public
92
-     * @var    EE_Session $SSN
93
-     */
94
-    public $SSN = null;
95
-
96
-    /**
97
-     * holds the ee capabilities object.
98
-     *
99
-     * @since 4.5.0
100
-     * @var EE_Capabilities
101
-     */
102
-    public $CAP = null;
103
-
104
-    /**
105
-     * holds the EE_Message_Resource_Manager object.
106
-     *
107
-     * @since 4.9.0
108
-     * @var EE_Message_Resource_Manager
109
-     */
110
-    public $MRM = null;
111
-
112
-
113
-    /**
114
-     * Holds the Assets Registry instance
115
-     * @var Registry
116
-     */
117
-    public $AssetsRegistry = null;
118
-
119
-    /**
120
-     *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
121
-     *
122
-     * @access    public
123
-     * @var    EE_Addon[]
124
-     */
125
-    public $addons = null;
126
-
127
-    /**
128
-     *    $models
129
-     * @access    public
130
-     * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
131
-     */
132
-    public $models = array();
133
-
134
-    /**
135
-     *    $modules
136
-     * @access    public
137
-     * @var    EED_Module[] $modules
138
-     */
139
-    public $modules = null;
140
-
141
-    /**
142
-     *    $shortcodes
143
-     * @access    public
144
-     * @var    EES_Shortcode[] $shortcodes
145
-     */
146
-    public $shortcodes = null;
147
-
148
-    /**
149
-     *    $widgets
150
-     * @access    public
151
-     * @var    WP_Widget[] $widgets
152
-     */
153
-    public $widgets = null;
154
-
155
-    /**
156
-     * $non_abstract_db_models
157
-     * @access public
158
-     * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
159
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
160
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
161
-     * classnames (eg "EEM_Event")
162
-     */
163
-    public $non_abstract_db_models = array();
164
-
165
-
166
-    /**
167
-     *    $i18n_js_strings - internationalization for JS strings
168
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
169
-     *    in js file:  var translatedString = eei18n.string_key;
170
-     *
171
-     * @access    public
172
-     * @var    array
173
-     */
174
-    public static $i18n_js_strings = array();
175
-
176
-
177
-    /**
178
-     *    $main_file - path to espresso.php
179
-     *
180
-     * @access    public
181
-     * @var    array
182
-     */
183
-    public $main_file;
184
-
185
-    /**
186
-     * array of ReflectionClass objects where the key is the class name
187
-     *
188
-     * @access    public
189
-     * @var ReflectionClass[]
190
-     */
191
-    public $_reflectors;
192
-
193
-    /**
194
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
195
-     *
196
-     * @access    protected
197
-     * @var boolean $_cache_on
198
-     */
199
-    protected $_cache_on = true;
200
-
201
-
202
-
203
-    /**
204
-     * @singleton method used to instantiate class object
205
-     * @access    public
206
-     * @param  \EE_Dependency_Map $dependency_map
207
-     * @return \EE_Registry instance
208
-     */
209
-    public static function instance(\EE_Dependency_Map $dependency_map = null)
210
-    {
211
-        // check if class object is instantiated
212
-        if ( ! self::$_instance instanceof EE_Registry) {
213
-            self::$_instance = new EE_Registry($dependency_map);
214
-        }
215
-        return self::$_instance;
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     *protected constructor to prevent direct creation
222
-     *
223
-     * @Constructor
224
-     * @access protected
225
-     * @param  \EE_Dependency_Map $dependency_map
226
-     */
227
-    protected function __construct(\EE_Dependency_Map $dependency_map)
228
-    {
229
-        $this->_dependency_map = $dependency_map;
230
-        $this->LIB = new stdClass();
231
-        $this->addons = new stdClass();
232
-        $this->modules = new stdClass();
233
-        $this->shortcodes = new stdClass();
234
-        $this->widgets = new stdClass();
235
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * initialize
242
-     */
243
-    public function initialize()
244
-    {
245
-        $this->_class_abbreviations = apply_filters(
246
-            'FHEE__EE_Registry____construct___class_abbreviations',
247
-            array(
248
-                'EE_Config'                                       => 'CFG',
249
-                'EE_Session'                                      => 'SSN',
250
-                'EE_Capabilities'                                 => 'CAP',
251
-                'EE_Cart'                                         => 'CART',
252
-                'EE_Network_Config'                               => 'NET_CFG',
253
-                'EE_Request_Handler'                              => 'REQ',
254
-                'EE_Message_Resource_Manager'                     => 'MRM',
255
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
256
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
257
-            )
258
-        );
259
-        $this->load_core('Base', array(), true);
260
-        // add our request and response objects to the cache
261
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
262
-        $this->_set_cached_class(
263
-            $request_loader(),
264
-            'EE_Request'
265
-        );
266
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
267
-        $this->_set_cached_class(
268
-            $response_loader(),
269
-            'EE_Response'
270
-        );
271
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     *    init
278
-     *
279
-     * @access    public
280
-     * @return    void
281
-     */
282
-    public function init()
283
-    {
284
-        // Get current page protocol
285
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
286
-        // Output admin-ajax.php URL with same protocol as current page
287
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
288
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * localize_i18n_js_strings
295
-     *
296
-     * @return string
297
-     */
298
-    public static function localize_i18n_js_strings()
299
-    {
300
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
301
-        foreach ($i18n_js_strings as $key => $value) {
302
-            if (is_scalar($value)) {
303
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
304
-            }
305
-        }
306
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * @param mixed string | EED_Module $module
313
-     */
314
-    public function add_module($module)
315
-    {
316
-        if ($module instanceof EED_Module) {
317
-            $module_class = get_class($module);
318
-            $this->modules->{$module_class} = $module;
319
-        } else {
320
-            if ( ! class_exists('EE_Module_Request_Router')) {
321
-                $this->load_core('Module_Request_Router');
322
-            }
323
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
324
-        }
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * @param string $module_name
331
-     * @return mixed EED_Module | NULL
332
-     */
333
-    public function get_module($module_name = '')
334
-    {
335
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     *    loads core classes - must be singletons
342
-     *
343
-     * @access    public
344
-     * @param string $class_name - simple class name ie: session
345
-     * @param mixed  $arguments
346
-     * @param bool   $load_only
347
-     * @return mixed
348
-     */
349
-    public function load_core($class_name, $arguments = array(), $load_only = false)
350
-    {
351
-        $core_paths = apply_filters(
352
-            'FHEE__EE_Registry__load_core__core_paths',
353
-            array(
354
-                EE_CORE,
355
-                EE_ADMIN,
356
-                EE_CPTS,
357
-                EE_CORE . 'data_migration_scripts' . DS,
358
-                EE_CORE . 'request_stack' . DS,
359
-                EE_CORE . 'middleware' . DS,
360
-            )
361
-        );
362
-        // retrieve instantiated class
363
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     *    loads service classes
370
-     *
371
-     * @access    public
372
-     * @param string $class_name - simple class name ie: session
373
-     * @param mixed  $arguments
374
-     * @param bool   $load_only
375
-     * @return mixed
376
-     */
377
-    public function load_service($class_name, $arguments = array(), $load_only = false)
378
-    {
379
-        $service_paths = apply_filters(
380
-            'FHEE__EE_Registry__load_service__service_paths',
381
-            array(
382
-                EE_CORE . 'services' . DS,
383
-            )
384
-        );
385
-        // retrieve instantiated class
386
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     *    loads data_migration_scripts
393
-     *
394
-     * @access    public
395
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
396
-     * @param mixed  $arguments
397
-     * @return EE_Data_Migration_Script_Base|mixed
398
-     */
399
-    public function load_dms($class_name, $arguments = array())
400
-    {
401
-        // retrieve instantiated class
402
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     *    loads object creating classes - must be singletons
409
-     *
410
-     * @param string $class_name - simple class name ie: attendee
411
-     * @param mixed  $arguments  - an array of arguments to pass to the class
412
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
413
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
414
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
415
-     * @return EE_Base_Class | bool
416
-     */
417
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
418
-    {
419
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
420
-            EE_CORE,
421
-            EE_CLASSES,
422
-            EE_BUSINESS,
423
-        ));
424
-        // retrieve instantiated class
425
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
426
-    }
427
-
428
-
429
-
430
-    /**
431
-     *    loads helper classes - must be singletons
432
-     *
433
-     * @param string $class_name - simple class name ie: price
434
-     * @param mixed  $arguments
435
-     * @param bool   $load_only
436
-     * @return EEH_Base | bool
437
-     */
438
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
439
-    {
440
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
441
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
442
-        // retrieve instantiated class
443
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
444
-    }
445
-
446
-
447
-
448
-    /**
449
-     *    loads core classes - must be singletons
450
-     *
451
-     * @access    public
452
-     * @param string $class_name - simple class name ie: session
453
-     * @param mixed  $arguments
454
-     * @param bool   $load_only
455
-     * @param bool   $cache      whether to cache the object or not.
456
-     * @return mixed
457
-     */
458
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
459
-    {
460
-        $paths = array(
461
-            EE_LIBRARIES,
462
-            EE_LIBRARIES . 'messages' . DS,
463
-            EE_LIBRARIES . 'shortcodes' . DS,
464
-            EE_LIBRARIES . 'qtips' . DS,
465
-            EE_LIBRARIES . 'payment_methods' . DS,
466
-        );
467
-        // retrieve instantiated class
468
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     *    loads model classes - must be singletons
475
-     *
476
-     * @param string $class_name - simple class name ie: price
477
-     * @param mixed  $arguments
478
-     * @param bool   $load_only
479
-     * @return EEM_Base | bool
480
-     */
481
-    public function load_model($class_name, $arguments = array(), $load_only = false)
482
-    {
483
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
484
-            EE_MODELS,
485
-            EE_CORE,
486
-        ));
487
-        // retrieve instantiated class
488
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
489
-    }
490
-
491
-
492
-
493
-    /**
494
-     *    loads model classes - must be singletons
495
-     *
496
-     * @param string $class_name - simple class name ie: price
497
-     * @param mixed  $arguments
498
-     * @param bool   $load_only
499
-     * @return mixed | bool
500
-     */
501
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
502
-    {
503
-        $paths = array(
504
-            EE_MODELS . 'fields' . DS,
505
-            EE_MODELS . 'helpers' . DS,
506
-            EE_MODELS . 'relations' . DS,
507
-            EE_MODELS . 'strategies' . DS,
508
-        );
509
-        // retrieve instantiated class
510
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
511
-    }
512
-
513
-
514
-
515
-    /**
516
-     * Determines if $model_name is the name of an actual EE model.
517
-     *
518
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
519
-     * @return boolean
520
-     */
521
-    public function is_model_name($model_name)
522
-    {
523
-        return isset($this->models[$model_name]) ? true : false;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    generic class loader
530
-     *
531
-     * @param string $path_to_file - directory path to file location, not including filename
532
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
533
-     * @param string $type         - file type - core? class? helper? model?
534
-     * @param mixed  $arguments
535
-     * @param bool   $load_only
536
-     * @return mixed
537
-     */
538
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
539
-    {
540
-        // retrieve instantiated class
541
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     *    load_addon
548
-     *
549
-     * @param string $path_to_file - directory path to file location, not including filename
550
-     * @param string $class_name   - full class name  ie:  My_Class
551
-     * @param string $type         - file type - core? class? helper? model?
552
-     * @param mixed  $arguments
553
-     * @param bool   $load_only
554
-     * @return EE_Addon
555
-     */
556
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
557
-    {
558
-        // retrieve instantiated class
559
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
560
-    }
561
-
562
-
563
-
564
-    /**
565
-     * instantiates, caches, and automatically resolves dependencies
566
-     * for classes that use a Fully Qualified Class Name.
567
-     * if the class is not capable of being loaded using PSR-4 autoloading,
568
-     * then you need to use one of the existing load_*() methods
569
-     * which can resolve the classname and filepath from the passed arguments
570
-     *
571
-     * @param bool|string $class_name   Fully Qualified Class Name
572
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
573
-     * @param bool        $cache        whether to cache the instantiated object for reuse
574
-     * @param bool        $from_db      some classes are instantiated from the db
575
-     *                                  and thus call a different method to instantiate
576
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
577
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
578
-     * @return mixed null = failure to load or instantiate class object.
579
-     *                                  object = class loaded and instantiated successfully.
580
-     *                                  bool = fail or success when $load_only is true
581
-     * @throws EE_Error
582
-     */
583
-    public function create(
584
-        $class_name = false,
585
-        $arguments = array(),
586
-        $cache = false,
587
-        $from_db = false,
588
-        $load_only = false,
589
-        $addon = false
590
-    ) {
591
-        $class_name = ltrim($class_name, '\\');
592
-        $class_name = $this->_dependency_map->get_alias($class_name);
593
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
594
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
595
-        // or it could return null if the class just could not be found anywhere
596
-        if ($class_exists instanceof $class_name || $class_exists === null){
597
-            // either way, return the results
598
-            return $class_exists;
599
-        }
600
-        $class_name = $class_exists;
601
-        // if we're only loading the class and it already exists, then let's just return true immediately
602
-        if ($load_only) {
603
-            return true;
604
-        }
605
-        $addon = $addon ? 'addon' : '';
606
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
607
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
608
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
609
-        if ($this->_cache_on && $cache && ! $load_only) {
610
-            // return object if it's already cached
611
-            $cached_class = $this->_get_cached_class($class_name, $addon);
612
-            if ($cached_class !== null) {
613
-                return $cached_class;
614
-            }
615
-        }
616
-        // instantiate the requested object
617
-        $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
618
-        // if caching is turned on OR this class is cached in a class property
619
-        if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) {
620
-            // save it for later... kinda like gum  { : $
621
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
622
-        }
623
-        $this->_cache_on = true;
624
-        return $class_obj;
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
631
-     *
632
-     * @param string $class_name
633
-     * @param array  $arguments
634
-     * @param int    $attempt
635
-     * @return mixed
636
-     */
637
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
638
-        if (is_object($class_name) || class_exists($class_name)) {
639
-            return $class_name;
640
-        }
641
-        switch ($attempt) {
642
-            case 1:
643
-                // if it's a FQCN then maybe the class is registered with a preceding \
644
-                $class_name = strpos($class_name, '\\') !== false
645
-                    ? '\\' . ltrim($class_name, '\\')
646
-                    : $class_name;
647
-                break;
648
-            case 2:
649
-                //
650
-                $loader = $this->_dependency_map->class_loader($class_name);
651
-                if ($loader && method_exists($this, $loader)) {
652
-                    return $this->{$loader}($class_name, $arguments);
653
-                }
654
-                break;
655
-            case 3:
656
-            default;
657
-                return null;
658
-        }
659
-        $attempt++;
660
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
661
-    }
662
-
663
-
664
-
665
-    /**
666
-     * instantiates, caches, and injects dependencies for classes
667
-     *
668
-     * @param array       $file_paths   an array of paths to folders to look in
669
-     * @param string      $class_prefix EE  or EEM or... ???
670
-     * @param bool|string $class_name   $class name
671
-     * @param string      $type         file type - core? class? helper? model?
672
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
673
-     * @param bool        $from_db      some classes are instantiated from the db
674
-     *                                  and thus call a different method to instantiate
675
-     * @param bool        $cache        whether to cache the instantiated object for reuse
676
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
677
-     * @return bool|null|object null = failure to load or instantiate class object.
678
-     *                                  object = class loaded and instantiated successfully.
679
-     *                                  bool = fail or success when $load_only is true
680
-     * @throws EE_Error
681
-     */
682
-    protected function _load(
683
-        $file_paths = array(),
684
-        $class_prefix = 'EE_',
685
-        $class_name = false,
686
-        $type = 'class',
687
-        $arguments = array(),
688
-        $from_db = false,
689
-        $cache = true,
690
-        $load_only = false
691
-    ) {
692
-        $class_name = ltrim($class_name, '\\');
693
-        // strip php file extension
694
-        $class_name = str_replace('.php', '', trim($class_name));
695
-        // does the class have a prefix ?
696
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
697
-            // make sure $class_prefix is uppercase
698
-            $class_prefix = strtoupper(trim($class_prefix));
699
-            // add class prefix ONCE!!!
700
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
701
-        }
702
-        $class_name = $this->_dependency_map->get_alias($class_name);
703
-        $class_exists = class_exists($class_name);
704
-        // if we're only loading the class and it already exists, then let's just return true immediately
705
-        if ($load_only && $class_exists) {
706
-            return true;
707
-        }
708
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
709
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
710
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
711
-        if ($this->_cache_on && $cache && ! $load_only) {
712
-            // return object if it's already cached
713
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
714
-            if ($cached_class !== null) {
715
-                return $cached_class;
716
-            }
717
-        }
718
-        // if the class doesn't already exist.. then we need to try and find the file and load it
719
-        if ( ! $class_exists) {
720
-            // get full path to file
721
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
722
-            // load the file
723
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
724
-            // if loading failed, or we are only loading a file but NOT instantiating an object
725
-            if ( ! $loaded || $load_only) {
726
-                // return boolean if only loading, or null if an object was expected
727
-                return $load_only ? $loaded : null;
728
-            }
729
-        }
730
-        // instantiate the requested object
731
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
732
-        if ($this->_cache_on && $cache) {
733
-            // save it for later... kinda like gum  { : $
734
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
735
-        }
736
-        $this->_cache_on = true;
737
-        return $class_obj;
738
-    }
739
-
740
-
741
-
742
-
743
-    /**
744
-     * _get_cached_class
745
-     * attempts to find a cached version of the requested class
746
-     * by looking in the following places:
747
-     *        $this->{$class_abbreviation}            ie:    $this->CART
748
-     *        $this->{$class_name}                        ie:    $this->Some_Class
749
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
750
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
751
-     *
752
-     * @access protected
753
-     * @param string $class_name
754
-     * @param string $class_prefix
755
-     * @return mixed
756
-     */
757
-    protected function _get_cached_class($class_name, $class_prefix = '')
758
-    {
759
-        if ($class_name === 'EE_Registry') {
760
-            return $this;
761
-        }
762
-        // have to specify something, but not anything that will conflict
763
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
764
-            ? $this->_class_abbreviations[ $class_name ]
765
-            : 'FANCY_BATMAN_PANTS';
766
-        $class_name = str_replace('\\', '_', $class_name);
767
-        // check if class has already been loaded, and return it if it has been
768
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
769
-            return $this->{$class_abbreviation};
770
-        }
771
-        if (isset ($this->{$class_name})) {
772
-            return $this->{$class_name};
773
-        }
774
-        if (isset ($this->LIB->{$class_name})) {
775
-            return $this->LIB->{$class_name};
776
-        }
777
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
778
-            return $this->addons->{$class_name};
779
-        }
780
-        return null;
781
-    }
782
-
783
-
784
-
785
-    /**
786
-     * removes a cached version of the requested class
787
-     *
788
-     * @param string $class_name
789
-     * @param boolean $addon
790
-     * @return boolean
791
-     */
792
-    public function clear_cached_class($class_name, $addon = false)
793
-    {
794
-        // have to specify something, but not anything that will conflict
795
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
796
-            ? $this->_class_abbreviations[ $class_name ]
797
-            : 'FANCY_BATMAN_PANTS';
798
-        $class_name = str_replace('\\', '_', $class_name);
799
-        // check if class has already been loaded, and return it if it has been
800
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
801
-            $this->{$class_abbreviation} = null;
802
-            return true;
803
-        }
804
-        if (isset($this->{$class_name})) {
805
-            $this->{$class_name} = null;
806
-            return true;
807
-        }
808
-        if (isset($this->LIB->{$class_name})) {
809
-            unset($this->LIB->{$class_name});
810
-            return true;
811
-        }
812
-        if ($addon && isset($this->addons->{$class_name})) {
813
-            unset($this->addons->{$class_name});
814
-            return true;
815
-        }
816
-        return false;
817
-    }
818
-
819
-
820
-    /**
821
-     * _resolve_path
822
-     * attempts to find a full valid filepath for the requested class.
823
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
824
-     * then returns that path if the target file has been found and is readable
825
-     *
826
-     * @access protected
827
-     * @param string $class_name
828
-     * @param string $type
829
-     * @param array  $file_paths
830
-     * @return string | bool
831
-     */
832
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
833
-    {
834
-        // make sure $file_paths is an array
835
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
836
-        // cycle thru paths
837
-        foreach ($file_paths as $key => $file_path) {
838
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
839
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
840
-            // prep file type
841
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
842
-            // build full file path
843
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
844
-            //does the file exist and can be read ?
845
-            if (is_readable($file_paths[$key])) {
846
-                return $file_paths[$key];
847
-            }
848
-        }
849
-        return false;
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     * _require_file
856
-     * basically just performs a require_once()
857
-     * but with some error handling
858
-     *
859
-     * @access protected
860
-     * @param  string $path
861
-     * @param  string $class_name
862
-     * @param  string $type
863
-     * @param  array  $file_paths
864
-     * @return boolean
865
-     * @throws \EE_Error
866
-     */
867
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
868
-    {
869
-        // don't give up! you gotta...
870
-        try {
871
-            //does the file exist and can it be read ?
872
-            if ( ! $path) {
873
-                // so sorry, can't find the file
874
-                throw new EE_Error (
875
-                    sprintf(
876
-                        __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
877
-                        trim($type, '.'),
878
-                        $class_name,
879
-                        '<br />' . implode(',<br />', $file_paths)
880
-                    )
881
-                );
882
-            }
883
-            // get the file
884
-            require_once($path);
885
-            // if the class isn't already declared somewhere
886
-            if (class_exists($class_name, false) === false) {
887
-                // so sorry, not a class
888
-                throw new EE_Error(
889
-                    sprintf(
890
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
891
-                        $type,
892
-                        $path,
893
-                        $class_name
894
-                    )
895
-                );
896
-            }
897
-        } catch (EE_Error $e) {
898
-            $e->get_error();
899
-            return false;
900
-        }
901
-        return true;
902
-    }
903
-
904
-
905
-
906
-    /**
907
-     * _create_object
908
-     * Attempts to instantiate the requested class via any of the
909
-     * commonly used instantiation methods employed throughout EE.
910
-     * The priority for instantiation is as follows:
911
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
912
-     *        - model objects via their 'new_instance_from_db' method
913
-     *        - model objects via their 'new_instance' method
914
-     *        - "singleton" classes" via their 'instance' method
915
-     *    - standard instantiable classes via their __constructor
916
-     * Prior to instantiation, if the classname exists in the dependency_map,
917
-     * then the constructor for the requested class will be examined to determine
918
-     * if any dependencies exist, and if they can be injected.
919
-     * If so, then those classes will be added to the array of arguments passed to the constructor
920
-     *
921
-     * @access protected
922
-     * @param string $class_name
923
-     * @param array  $arguments
924
-     * @param string $type
925
-     * @param bool   $from_db
926
-     * @return null | object
927
-     * @throws \EE_Error
928
-     */
929
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
930
-    {
931
-        $class_obj = null;
932
-        $instantiation_mode = '0) none';
933
-        // don't give up! you gotta...
934
-        try {
935
-            // create reflection
936
-            $reflector = $this->get_ReflectionClass($class_name);
937
-            // make sure arguments are an array
938
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
939
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
940
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
941
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
942
-                ? $arguments
943
-                : array($arguments);
944
-            // attempt to inject dependencies ?
945
-            if ($this->_dependency_map->has($class_name)) {
946
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
947
-            }
948
-            // instantiate the class if possible
949
-            if ($reflector->isAbstract()) {
950
-                // nothing to instantiate, loading file was enough
951
-                // does not throw an exception so $instantiation_mode is unused
952
-                // $instantiation_mode = "1) no constructor abstract class";
953
-                $class_obj = true;
954
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
955
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
956
-                $instantiation_mode = "2) no constructor but instantiable";
957
-                $class_obj = $reflector->newInstance();
958
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
959
-                $instantiation_mode = "3) new_instance_from_db()";
960
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
961
-            } else if (method_exists($class_name, 'new_instance')) {
962
-                $instantiation_mode = "4) new_instance()";
963
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
964
-            } else if (method_exists($class_name, 'instance')) {
965
-                $instantiation_mode = "5) instance()";
966
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
967
-            } else if ($reflector->isInstantiable()) {
968
-                $instantiation_mode = "6) constructor";
969
-                $class_obj = $reflector->newInstanceArgs($arguments);
970
-            } else {
971
-                // heh ? something's not right !
972
-                throw new EE_Error(
973
-                    sprintf(
974
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
975
-                        $type,
976
-                        $class_name
977
-                    )
978
-                );
979
-            }
980
-        } catch (Exception $e) {
981
-            if ( ! $e instanceof EE_Error) {
982
-                $e = new EE_Error(
983
-                    sprintf(
984
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
985
-                        $class_name,
986
-                        '<br />',
987
-                        $e->getMessage(),
988
-                        $instantiation_mode
989
-                    )
990
-                );
991
-            }
992
-            $e->get_error();
993
-        }
994
-        return $class_obj;
995
-    }
996
-
997
-
998
-
999
-    /**
1000
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1001
-     * @param array $array
1002
-     * @return bool
1003
-     */
1004
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1005
-    {
1006
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * getReflectionClass
1013
-     * checks if a ReflectionClass object has already been generated for a class
1014
-     * and returns that instead of creating a new one
1015
-     *
1016
-     * @access public
1017
-     * @param string $class_name
1018
-     * @return ReflectionClass
1019
-     */
1020
-    public function get_ReflectionClass($class_name)
1021
-    {
1022
-        if (
1023
-            ! isset($this->_reflectors[$class_name])
1024
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1025
-        ) {
1026
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1027
-        }
1028
-        return $this->_reflectors[$class_name];
1029
-    }
1030
-
1031
-
1032
-
1033
-    /**
1034
-     * _resolve_dependencies
1035
-     * examines the constructor for the requested class to determine
1036
-     * if any dependencies exist, and if they can be injected.
1037
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1038
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1039
-     * For example:
1040
-     *        if attempting to load a class "Foo" with the following constructor:
1041
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1042
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1043
-     *        but only IF they are NOT already present in the incoming arguments array,
1044
-     *        and the correct classes can be loaded
1045
-     *
1046
-     * @access protected
1047
-     * @param ReflectionClass $reflector
1048
-     * @param string          $class_name
1049
-     * @param array           $arguments
1050
-     * @return array
1051
-     * @throws \ReflectionException
1052
-     */
1053
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1054
-    {
1055
-        // let's examine the constructor
1056
-        $constructor = $reflector->getConstructor();
1057
-        // whu? huh? nothing?
1058
-        if ( ! $constructor) {
1059
-            return $arguments;
1060
-        }
1061
-        // get constructor parameters
1062
-        $params = $constructor->getParameters();
1063
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1064
-        $argument_keys = array_keys($arguments);
1065
-        // now loop thru all of the constructors expected parameters
1066
-        foreach ($params as $index => $param) {
1067
-            // is this a dependency for a specific class ?
1068
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
1069
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1070
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1071
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1072
-                : $param_class;
1073
-            if (
1074
-                // param is not even a class
1075
-                empty($param_class)
1076
-                // and something already exists in the incoming arguments for this param
1077
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1078
-            ) {
1079
-                // so let's skip this argument and move on to the next
1080
-                continue;
1081
-            }
1082
-            if (
1083
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1084
-                ! empty($param_class)
1085
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1086
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1087
-            ) {
1088
-                // skip this argument and move on to the next
1089
-                continue;
1090
-            }
1091
-            if (
1092
-                // parameter is type hinted as a class, and should be injected
1093
-                ! empty($param_class)
1094
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1095
-            ) {
1096
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1097
-            } else {
1098
-                try {
1099
-                    $arguments[$index] = $param->getDefaultValue();
1100
-                } catch (ReflectionException $e) {
1101
-                    throw new ReflectionException(
1102
-                        sprintf(
1103
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1104
-                            $e->getMessage(),
1105
-                            $param->getName()
1106
-                        )
1107
-                    );
1108
-                }
1109
-            }
1110
-        }
1111
-        return $arguments;
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * @access protected
1118
-     * @param string $class_name
1119
-     * @param string $param_class
1120
-     * @param array  $arguments
1121
-     * @param mixed  $index
1122
-     * @return array
1123
-     */
1124
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1125
-    {
1126
-        $dependency = null;
1127
-        // should dependency be loaded from cache ?
1128
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1129
-                    !== EE_Dependency_Map::load_new_object
1130
-            ? true
1131
-            : false;
1132
-        // we might have a dependency...
1133
-        // let's MAYBE try and find it in our cache if that's what's been requested
1134
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1135
-        // and grab it if it exists
1136
-        if ($cached_class instanceof $param_class) {
1137
-            $dependency = $cached_class;
1138
-        } else if ($param_class !== $class_name) {
1139
-            // obtain the loader method from the dependency map
1140
-            $loader = $this->_dependency_map->class_loader($param_class);
1141
-            // is loader a custom closure ?
1142
-            if ($loader instanceof Closure) {
1143
-                $dependency = $loader();
1144
-            } else {
1145
-                // set the cache on property for the recursive loading call
1146
-                $this->_cache_on = $cache_on;
1147
-                // if not, then let's try and load it via the registry
1148
-                if ($loader && method_exists($this, $loader)) {
1149
-                    $dependency = $this->{$loader}($param_class);
1150
-                } else {
1151
-                    $dependency = $this->create($param_class, array(), $cache_on);
1152
-                }
1153
-            }
1154
-        }
1155
-        // did we successfully find the correct dependency ?
1156
-        if ($dependency instanceof $param_class) {
1157
-            // then let's inject it into the incoming array of arguments at the correct location
1158
-            if (isset($argument_keys[$index])) {
1159
-                $arguments[$argument_keys[$index]] = $dependency;
1160
-            } else {
1161
-                $arguments[$index] = $dependency;
1162
-            }
1163
-        }
1164
-        return $arguments;
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     * _set_cached_class
1171
-     * attempts to cache the instantiated class locally
1172
-     * in one of the following places, in the following order:
1173
-     *        $this->{class_abbreviation}   ie:    $this->CART
1174
-     *        $this->{$class_name}          ie:    $this->Some_Class
1175
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1176
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1177
-     *
1178
-     * @access protected
1179
-     * @param object $class_obj
1180
-     * @param string $class_name
1181
-     * @param string $class_prefix
1182
-     * @param bool   $from_db
1183
-     * @return void
1184
-     */
1185
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1186
-    {
1187
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1188
-            return;
1189
-        }
1190
-        // return newly instantiated class
1191
-        if (isset($this->_class_abbreviations[$class_name])) {
1192
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1193
-            $this->{$class_abbreviation} = $class_obj;
1194
-            return;
1195
-        }
1196
-        $class_name = str_replace('\\', '_', $class_name);
1197
-        if (property_exists($this, $class_name)) {
1198
-            $this->{$class_name} = $class_obj;
1199
-            return;
1200
-        }
1201
-        if ($class_prefix === 'addon') {
1202
-            $this->addons->{$class_name} = $class_obj;
1203
-            return;
1204
-        }
1205
-        if ( ! $from_db) {
1206
-            $this->LIB->{$class_name} = $class_obj;
1207
-        }
1208
-    }
1209
-
1210
-
1211
-
1212
-    /**
1213
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1214
-     *
1215
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1216
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1217
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1218
-     * @param array  $arguments
1219
-     * @return object
1220
-     */
1221
-    public static function factory($classname, $arguments = array())
1222
-    {
1223
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1224
-        if ($loader instanceof Closure) {
1225
-            return $loader($arguments);
1226
-        }
1227
-        if (method_exists(EE_Registry::instance(), $loader)) {
1228
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1229
-        }
1230
-        return null;
1231
-    }
1232
-
1233
-
1234
-
1235
-    /**
1236
-     * Gets the addon by its name/slug (not classname. For that, just
1237
-     * use the classname as the property name on EE_Config::instance()->addons)
1238
-     *
1239
-     * @param string $name
1240
-     * @return EE_Addon
1241
-     */
1242
-    public function get_addon_by_name($name)
1243
-    {
1244
-        foreach ($this->addons as $addon) {
1245
-            if ($addon->name() == $name) {
1246
-                return $addon;
1247
-            }
1248
-        }
1249
-        return null;
1250
-    }
1251
-
1252
-
1253
-
1254
-    /**
1255
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1256
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1257
-     *
1258
-     * @return EE_Addon[] where the KEYS are the addon's name()
1259
-     */
1260
-    public function get_addons_by_name()
1261
-    {
1262
-        $addons = array();
1263
-        foreach ($this->addons as $addon) {
1264
-            $addons[$addon->name()] = $addon;
1265
-        }
1266
-        return $addons;
1267
-    }
1268
-
1269
-
1270
-
1271
-    /**
1272
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1273
-     * a stale copy of it around
1274
-     *
1275
-     * @param string $model_name
1276
-     * @return \EEM_Base
1277
-     * @throws \EE_Error
1278
-     */
1279
-    public function reset_model($model_name)
1280
-    {
1281
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1282
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1283
-            return null;
1284
-        }
1285
-        //get that model reset it and make sure we nuke the old reference to it
1286
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1287
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1288
-        } else {
1289
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1290
-        }
1291
-        return $this->LIB->{$model_class_name};
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     * Resets the registry.
1298
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1299
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1300
-     * - $_dependency_map
1301
-     * - $_class_abbreviations
1302
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1303
-     * - $REQ:  Still on the same request so no need to change.
1304
-     * - $CAP: There is no site specific state in the EE_Capability class.
1305
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1306
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1307
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1308
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1309
-     *             switch or on the restore.
1310
-     * - $modules
1311
-     * - $shortcodes
1312
-     * - $widgets
1313
-     *
1314
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1315
-     *                                  the Registry to its state at the beginning of the request
1316
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1317
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1318
-     *                                  currently reinstantiate the singletons at the moment)
1319
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1320
-     *                                  code instead can just change the model context to a different blog id if necessary
1321
-     * @return EE_Registry
1322
-     */
1323
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1324
-    {
1325
-        $instance = self::instance();
1326
-        $instance->_cache_on = true;
1327
-        // reset some "special" classes
1328
-        EEH_Activation::reset();
1329
-        $instance->CFG = $instance->CFG->reset($hard, $reinstantiate);
1330
-        $instance->CART = null;
1331
-        $instance->MRM = null;
1332
-        $instance->AssetsRegistry = null;
1333
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1334
-        //messages reset
1335
-        EED_Messages::reset();
1336
-        //handle of objects cached on LIB
1337
-        foreach (array('LIB', 'modules', 'shortcodes') as $cache) {
1338
-            foreach ($instance->{$cache} as $class_name => $class) {
1339
-                if (EE_Registry::_reset_and_unset_object($class, $reset_models)) {
1340
-                    unset($instance->{$cache}->{$class_name});
1341
-                }
1342
-            }
1343
-        }
1344
-        return $instance;
1345
-    }
1346
-
1347
-
1348
-
1349
-    /**
1350
-     * if passed object implements ResettableInterface, then call it's reset() method
1351
-     * if passed object implements InterminableInterface, then return false,
1352
-     * to indicate that it should NOT be cleared from the Registry cache
1353
-     *
1354
-     * @param      $object
1355
-     * @param bool $reset_models
1356
-     * @return bool returns true if cached object should be unset
1357
-     */
1358
-    private static function _reset_and_unset_object($object, $reset_models)
1359
-    {
1360
-        static $count = 0;
1361
-        $count++;
1362
-        if ($object instanceof ResettableInterface) {
1363
-            if ($object instanceof EEM_Base) {
1364
-                if ($reset_models) {
1365
-                    $object->reset();
1366
-                    return true;
1367
-                }
1368
-                return false;
1369
-            }
1370
-            $object->reset();
1371
-            return true;
1372
-        }
1373
-        if ( ! $object instanceof InterminableInterface) {
1374
-            return true;
1375
-        }
1376
-        return false;
1377
-    }
1378
-
1379
-
1380
-
1381
-    /**
1382
-     * @override magic methods
1383
-     * @return void
1384
-     */
1385
-    public final function __destruct()
1386
-    {
1387
-    }
1388
-
1389
-
1390
-
1391
-    /**
1392
-     * @param $a
1393
-     * @param $b
1394
-     */
1395
-    public final function __call($a, $b)
1396
-    {
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     * @param $a
1403
-     */
1404
-    public final function __get($a)
1405
-    {
1406
-    }
1407
-
1408
-
1409
-
1410
-    /**
1411
-     * @param $a
1412
-     * @param $b
1413
-     */
1414
-    public final function __set($a, $b)
1415
-    {
1416
-    }
1417
-
1418
-
1419
-
1420
-    /**
1421
-     * @param $a
1422
-     */
1423
-    public final function __isset($a)
1424
-    {
1425
-    }
22
+	/**
23
+	 *    EE_Registry Object
24
+	 *
25
+	 * @var EE_Registry $_instance
26
+	 * @access    private
27
+	 */
28
+	private static $_instance = null;
29
+
30
+	/**
31
+	 * @var EE_Dependency_Map $_dependency_map
32
+	 * @access    protected
33
+	 */
34
+	protected $_dependency_map = null;
35
+
36
+	/**
37
+	 * @var array $_class_abbreviations
38
+	 * @access    protected
39
+	 */
40
+	protected $_class_abbreviations = array();
41
+
42
+	/**
43
+	 * @access public
44
+	 * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
45
+	 */
46
+	public $BUS;
47
+
48
+	/**
49
+	 *    EE_Cart Object
50
+	 *
51
+	 * @access    public
52
+	 * @var    EE_Cart $CART
53
+	 */
54
+	public $CART = null;
55
+
56
+	/**
57
+	 *    EE_Config Object
58
+	 *
59
+	 * @access    public
60
+	 * @var    EE_Config $CFG
61
+	 */
62
+	public $CFG = null;
63
+
64
+	/**
65
+	 * EE_Network_Config Object
66
+	 *
67
+	 * @access public
68
+	 * @var EE_Network_Config $NET_CFG
69
+	 */
70
+	public $NET_CFG = null;
71
+
72
+	/**
73
+	 *    StdClass object for storing library classes in
74
+	 *
75
+	 * @public LIB
76
+	 * @var StdClass $LIB
77
+	 */
78
+	public $LIB = null;
79
+
80
+	/**
81
+	 *    EE_Request_Handler Object
82
+	 *
83
+	 * @access    public
84
+	 * @var    EE_Request_Handler $REQ
85
+	 */
86
+	public $REQ = null;
87
+
88
+	/**
89
+	 *    EE_Session Object
90
+	 *
91
+	 * @access    public
92
+	 * @var    EE_Session $SSN
93
+	 */
94
+	public $SSN = null;
95
+
96
+	/**
97
+	 * holds the ee capabilities object.
98
+	 *
99
+	 * @since 4.5.0
100
+	 * @var EE_Capabilities
101
+	 */
102
+	public $CAP = null;
103
+
104
+	/**
105
+	 * holds the EE_Message_Resource_Manager object.
106
+	 *
107
+	 * @since 4.9.0
108
+	 * @var EE_Message_Resource_Manager
109
+	 */
110
+	public $MRM = null;
111
+
112
+
113
+	/**
114
+	 * Holds the Assets Registry instance
115
+	 * @var Registry
116
+	 */
117
+	public $AssetsRegistry = null;
118
+
119
+	/**
120
+	 *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
121
+	 *
122
+	 * @access    public
123
+	 * @var    EE_Addon[]
124
+	 */
125
+	public $addons = null;
126
+
127
+	/**
128
+	 *    $models
129
+	 * @access    public
130
+	 * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
131
+	 */
132
+	public $models = array();
133
+
134
+	/**
135
+	 *    $modules
136
+	 * @access    public
137
+	 * @var    EED_Module[] $modules
138
+	 */
139
+	public $modules = null;
140
+
141
+	/**
142
+	 *    $shortcodes
143
+	 * @access    public
144
+	 * @var    EES_Shortcode[] $shortcodes
145
+	 */
146
+	public $shortcodes = null;
147
+
148
+	/**
149
+	 *    $widgets
150
+	 * @access    public
151
+	 * @var    WP_Widget[] $widgets
152
+	 */
153
+	public $widgets = null;
154
+
155
+	/**
156
+	 * $non_abstract_db_models
157
+	 * @access public
158
+	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
159
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
160
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
161
+	 * classnames (eg "EEM_Event")
162
+	 */
163
+	public $non_abstract_db_models = array();
164
+
165
+
166
+	/**
167
+	 *    $i18n_js_strings - internationalization for JS strings
168
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
169
+	 *    in js file:  var translatedString = eei18n.string_key;
170
+	 *
171
+	 * @access    public
172
+	 * @var    array
173
+	 */
174
+	public static $i18n_js_strings = array();
175
+
176
+
177
+	/**
178
+	 *    $main_file - path to espresso.php
179
+	 *
180
+	 * @access    public
181
+	 * @var    array
182
+	 */
183
+	public $main_file;
184
+
185
+	/**
186
+	 * array of ReflectionClass objects where the key is the class name
187
+	 *
188
+	 * @access    public
189
+	 * @var ReflectionClass[]
190
+	 */
191
+	public $_reflectors;
192
+
193
+	/**
194
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
195
+	 *
196
+	 * @access    protected
197
+	 * @var boolean $_cache_on
198
+	 */
199
+	protected $_cache_on = true;
200
+
201
+
202
+
203
+	/**
204
+	 * @singleton method used to instantiate class object
205
+	 * @access    public
206
+	 * @param  \EE_Dependency_Map $dependency_map
207
+	 * @return \EE_Registry instance
208
+	 */
209
+	public static function instance(\EE_Dependency_Map $dependency_map = null)
210
+	{
211
+		// check if class object is instantiated
212
+		if ( ! self::$_instance instanceof EE_Registry) {
213
+			self::$_instance = new EE_Registry($dependency_map);
214
+		}
215
+		return self::$_instance;
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 *protected constructor to prevent direct creation
222
+	 *
223
+	 * @Constructor
224
+	 * @access protected
225
+	 * @param  \EE_Dependency_Map $dependency_map
226
+	 */
227
+	protected function __construct(\EE_Dependency_Map $dependency_map)
228
+	{
229
+		$this->_dependency_map = $dependency_map;
230
+		$this->LIB = new stdClass();
231
+		$this->addons = new stdClass();
232
+		$this->modules = new stdClass();
233
+		$this->shortcodes = new stdClass();
234
+		$this->widgets = new stdClass();
235
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * initialize
242
+	 */
243
+	public function initialize()
244
+	{
245
+		$this->_class_abbreviations = apply_filters(
246
+			'FHEE__EE_Registry____construct___class_abbreviations',
247
+			array(
248
+				'EE_Config'                                       => 'CFG',
249
+				'EE_Session'                                      => 'SSN',
250
+				'EE_Capabilities'                                 => 'CAP',
251
+				'EE_Cart'                                         => 'CART',
252
+				'EE_Network_Config'                               => 'NET_CFG',
253
+				'EE_Request_Handler'                              => 'REQ',
254
+				'EE_Message_Resource_Manager'                     => 'MRM',
255
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
256
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
257
+			)
258
+		);
259
+		$this->load_core('Base', array(), true);
260
+		// add our request and response objects to the cache
261
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
262
+		$this->_set_cached_class(
263
+			$request_loader(),
264
+			'EE_Request'
265
+		);
266
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
267
+		$this->_set_cached_class(
268
+			$response_loader(),
269
+			'EE_Response'
270
+		);
271
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 *    init
278
+	 *
279
+	 * @access    public
280
+	 * @return    void
281
+	 */
282
+	public function init()
283
+	{
284
+		// Get current page protocol
285
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
286
+		// Output admin-ajax.php URL with same protocol as current page
287
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
288
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * localize_i18n_js_strings
295
+	 *
296
+	 * @return string
297
+	 */
298
+	public static function localize_i18n_js_strings()
299
+	{
300
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
301
+		foreach ($i18n_js_strings as $key => $value) {
302
+			if (is_scalar($value)) {
303
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
304
+			}
305
+		}
306
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * @param mixed string | EED_Module $module
313
+	 */
314
+	public function add_module($module)
315
+	{
316
+		if ($module instanceof EED_Module) {
317
+			$module_class = get_class($module);
318
+			$this->modules->{$module_class} = $module;
319
+		} else {
320
+			if ( ! class_exists('EE_Module_Request_Router')) {
321
+				$this->load_core('Module_Request_Router');
322
+			}
323
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
324
+		}
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * @param string $module_name
331
+	 * @return mixed EED_Module | NULL
332
+	 */
333
+	public function get_module($module_name = '')
334
+	{
335
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 *    loads core classes - must be singletons
342
+	 *
343
+	 * @access    public
344
+	 * @param string $class_name - simple class name ie: session
345
+	 * @param mixed  $arguments
346
+	 * @param bool   $load_only
347
+	 * @return mixed
348
+	 */
349
+	public function load_core($class_name, $arguments = array(), $load_only = false)
350
+	{
351
+		$core_paths = apply_filters(
352
+			'FHEE__EE_Registry__load_core__core_paths',
353
+			array(
354
+				EE_CORE,
355
+				EE_ADMIN,
356
+				EE_CPTS,
357
+				EE_CORE . 'data_migration_scripts' . DS,
358
+				EE_CORE . 'request_stack' . DS,
359
+				EE_CORE . 'middleware' . DS,
360
+			)
361
+		);
362
+		// retrieve instantiated class
363
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 *    loads service classes
370
+	 *
371
+	 * @access    public
372
+	 * @param string $class_name - simple class name ie: session
373
+	 * @param mixed  $arguments
374
+	 * @param bool   $load_only
375
+	 * @return mixed
376
+	 */
377
+	public function load_service($class_name, $arguments = array(), $load_only = false)
378
+	{
379
+		$service_paths = apply_filters(
380
+			'FHEE__EE_Registry__load_service__service_paths',
381
+			array(
382
+				EE_CORE . 'services' . DS,
383
+			)
384
+		);
385
+		// retrieve instantiated class
386
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 *    loads data_migration_scripts
393
+	 *
394
+	 * @access    public
395
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
396
+	 * @param mixed  $arguments
397
+	 * @return EE_Data_Migration_Script_Base|mixed
398
+	 */
399
+	public function load_dms($class_name, $arguments = array())
400
+	{
401
+		// retrieve instantiated class
402
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 *    loads object creating classes - must be singletons
409
+	 *
410
+	 * @param string $class_name - simple class name ie: attendee
411
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
412
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
413
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
414
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
415
+	 * @return EE_Base_Class | bool
416
+	 */
417
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
418
+	{
419
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
420
+			EE_CORE,
421
+			EE_CLASSES,
422
+			EE_BUSINESS,
423
+		));
424
+		// retrieve instantiated class
425
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
426
+	}
427
+
428
+
429
+
430
+	/**
431
+	 *    loads helper classes - must be singletons
432
+	 *
433
+	 * @param string $class_name - simple class name ie: price
434
+	 * @param mixed  $arguments
435
+	 * @param bool   $load_only
436
+	 * @return EEH_Base | bool
437
+	 */
438
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
439
+	{
440
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
441
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
442
+		// retrieve instantiated class
443
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
444
+	}
445
+
446
+
447
+
448
+	/**
449
+	 *    loads core classes - must be singletons
450
+	 *
451
+	 * @access    public
452
+	 * @param string $class_name - simple class name ie: session
453
+	 * @param mixed  $arguments
454
+	 * @param bool   $load_only
455
+	 * @param bool   $cache      whether to cache the object or not.
456
+	 * @return mixed
457
+	 */
458
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
459
+	{
460
+		$paths = array(
461
+			EE_LIBRARIES,
462
+			EE_LIBRARIES . 'messages' . DS,
463
+			EE_LIBRARIES . 'shortcodes' . DS,
464
+			EE_LIBRARIES . 'qtips' . DS,
465
+			EE_LIBRARIES . 'payment_methods' . DS,
466
+		);
467
+		// retrieve instantiated class
468
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 *    loads model classes - must be singletons
475
+	 *
476
+	 * @param string $class_name - simple class name ie: price
477
+	 * @param mixed  $arguments
478
+	 * @param bool   $load_only
479
+	 * @return EEM_Base | bool
480
+	 */
481
+	public function load_model($class_name, $arguments = array(), $load_only = false)
482
+	{
483
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
484
+			EE_MODELS,
485
+			EE_CORE,
486
+		));
487
+		// retrieve instantiated class
488
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
489
+	}
490
+
491
+
492
+
493
+	/**
494
+	 *    loads model classes - must be singletons
495
+	 *
496
+	 * @param string $class_name - simple class name ie: price
497
+	 * @param mixed  $arguments
498
+	 * @param bool   $load_only
499
+	 * @return mixed | bool
500
+	 */
501
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
502
+	{
503
+		$paths = array(
504
+			EE_MODELS . 'fields' . DS,
505
+			EE_MODELS . 'helpers' . DS,
506
+			EE_MODELS . 'relations' . DS,
507
+			EE_MODELS . 'strategies' . DS,
508
+		);
509
+		// retrieve instantiated class
510
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
511
+	}
512
+
513
+
514
+
515
+	/**
516
+	 * Determines if $model_name is the name of an actual EE model.
517
+	 *
518
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
519
+	 * @return boolean
520
+	 */
521
+	public function is_model_name($model_name)
522
+	{
523
+		return isset($this->models[$model_name]) ? true : false;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    generic class loader
530
+	 *
531
+	 * @param string $path_to_file - directory path to file location, not including filename
532
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
533
+	 * @param string $type         - file type - core? class? helper? model?
534
+	 * @param mixed  $arguments
535
+	 * @param bool   $load_only
536
+	 * @return mixed
537
+	 */
538
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
539
+	{
540
+		// retrieve instantiated class
541
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 *    load_addon
548
+	 *
549
+	 * @param string $path_to_file - directory path to file location, not including filename
550
+	 * @param string $class_name   - full class name  ie:  My_Class
551
+	 * @param string $type         - file type - core? class? helper? model?
552
+	 * @param mixed  $arguments
553
+	 * @param bool   $load_only
554
+	 * @return EE_Addon
555
+	 */
556
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
557
+	{
558
+		// retrieve instantiated class
559
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
560
+	}
561
+
562
+
563
+
564
+	/**
565
+	 * instantiates, caches, and automatically resolves dependencies
566
+	 * for classes that use a Fully Qualified Class Name.
567
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
568
+	 * then you need to use one of the existing load_*() methods
569
+	 * which can resolve the classname and filepath from the passed arguments
570
+	 *
571
+	 * @param bool|string $class_name   Fully Qualified Class Name
572
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
573
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
574
+	 * @param bool        $from_db      some classes are instantiated from the db
575
+	 *                                  and thus call a different method to instantiate
576
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
577
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
578
+	 * @return mixed null = failure to load or instantiate class object.
579
+	 *                                  object = class loaded and instantiated successfully.
580
+	 *                                  bool = fail or success when $load_only is true
581
+	 * @throws EE_Error
582
+	 */
583
+	public function create(
584
+		$class_name = false,
585
+		$arguments = array(),
586
+		$cache = false,
587
+		$from_db = false,
588
+		$load_only = false,
589
+		$addon = false
590
+	) {
591
+		$class_name = ltrim($class_name, '\\');
592
+		$class_name = $this->_dependency_map->get_alias($class_name);
593
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
594
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
595
+		// or it could return null if the class just could not be found anywhere
596
+		if ($class_exists instanceof $class_name || $class_exists === null){
597
+			// either way, return the results
598
+			return $class_exists;
599
+		}
600
+		$class_name = $class_exists;
601
+		// if we're only loading the class and it already exists, then let's just return true immediately
602
+		if ($load_only) {
603
+			return true;
604
+		}
605
+		$addon = $addon ? 'addon' : '';
606
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
607
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
608
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
609
+		if ($this->_cache_on && $cache && ! $load_only) {
610
+			// return object if it's already cached
611
+			$cached_class = $this->_get_cached_class($class_name, $addon);
612
+			if ($cached_class !== null) {
613
+				return $cached_class;
614
+			}
615
+		}
616
+		// instantiate the requested object
617
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
618
+		// if caching is turned on OR this class is cached in a class property
619
+		if (($this->_cache_on && $cache) || isset($this->_class_abbreviations[ $class_name ])) {
620
+			// save it for later... kinda like gum  { : $
621
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
622
+		}
623
+		$this->_cache_on = true;
624
+		return $class_obj;
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
631
+	 *
632
+	 * @param string $class_name
633
+	 * @param array  $arguments
634
+	 * @param int    $attempt
635
+	 * @return mixed
636
+	 */
637
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
638
+		if (is_object($class_name) || class_exists($class_name)) {
639
+			return $class_name;
640
+		}
641
+		switch ($attempt) {
642
+			case 1:
643
+				// if it's a FQCN then maybe the class is registered with a preceding \
644
+				$class_name = strpos($class_name, '\\') !== false
645
+					? '\\' . ltrim($class_name, '\\')
646
+					: $class_name;
647
+				break;
648
+			case 2:
649
+				//
650
+				$loader = $this->_dependency_map->class_loader($class_name);
651
+				if ($loader && method_exists($this, $loader)) {
652
+					return $this->{$loader}($class_name, $arguments);
653
+				}
654
+				break;
655
+			case 3:
656
+			default;
657
+				return null;
658
+		}
659
+		$attempt++;
660
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
661
+	}
662
+
663
+
664
+
665
+	/**
666
+	 * instantiates, caches, and injects dependencies for classes
667
+	 *
668
+	 * @param array       $file_paths   an array of paths to folders to look in
669
+	 * @param string      $class_prefix EE  or EEM or... ???
670
+	 * @param bool|string $class_name   $class name
671
+	 * @param string      $type         file type - core? class? helper? model?
672
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
673
+	 * @param bool        $from_db      some classes are instantiated from the db
674
+	 *                                  and thus call a different method to instantiate
675
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
676
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
677
+	 * @return bool|null|object null = failure to load or instantiate class object.
678
+	 *                                  object = class loaded and instantiated successfully.
679
+	 *                                  bool = fail or success when $load_only is true
680
+	 * @throws EE_Error
681
+	 */
682
+	protected function _load(
683
+		$file_paths = array(),
684
+		$class_prefix = 'EE_',
685
+		$class_name = false,
686
+		$type = 'class',
687
+		$arguments = array(),
688
+		$from_db = false,
689
+		$cache = true,
690
+		$load_only = false
691
+	) {
692
+		$class_name = ltrim($class_name, '\\');
693
+		// strip php file extension
694
+		$class_name = str_replace('.php', '', trim($class_name));
695
+		// does the class have a prefix ?
696
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
697
+			// make sure $class_prefix is uppercase
698
+			$class_prefix = strtoupper(trim($class_prefix));
699
+			// add class prefix ONCE!!!
700
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
701
+		}
702
+		$class_name = $this->_dependency_map->get_alias($class_name);
703
+		$class_exists = class_exists($class_name);
704
+		// if we're only loading the class and it already exists, then let's just return true immediately
705
+		if ($load_only && $class_exists) {
706
+			return true;
707
+		}
708
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
709
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
710
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
711
+		if ($this->_cache_on && $cache && ! $load_only) {
712
+			// return object if it's already cached
713
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
714
+			if ($cached_class !== null) {
715
+				return $cached_class;
716
+			}
717
+		}
718
+		// if the class doesn't already exist.. then we need to try and find the file and load it
719
+		if ( ! $class_exists) {
720
+			// get full path to file
721
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
722
+			// load the file
723
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
724
+			// if loading failed, or we are only loading a file but NOT instantiating an object
725
+			if ( ! $loaded || $load_only) {
726
+				// return boolean if only loading, or null if an object was expected
727
+				return $load_only ? $loaded : null;
728
+			}
729
+		}
730
+		// instantiate the requested object
731
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
732
+		if ($this->_cache_on && $cache) {
733
+			// save it for later... kinda like gum  { : $
734
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
735
+		}
736
+		$this->_cache_on = true;
737
+		return $class_obj;
738
+	}
739
+
740
+
741
+
742
+
743
+	/**
744
+	 * _get_cached_class
745
+	 * attempts to find a cached version of the requested class
746
+	 * by looking in the following places:
747
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
748
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
749
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
750
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
751
+	 *
752
+	 * @access protected
753
+	 * @param string $class_name
754
+	 * @param string $class_prefix
755
+	 * @return mixed
756
+	 */
757
+	protected function _get_cached_class($class_name, $class_prefix = '')
758
+	{
759
+		if ($class_name === 'EE_Registry') {
760
+			return $this;
761
+		}
762
+		// have to specify something, but not anything that will conflict
763
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
764
+			? $this->_class_abbreviations[ $class_name ]
765
+			: 'FANCY_BATMAN_PANTS';
766
+		$class_name = str_replace('\\', '_', $class_name);
767
+		// check if class has already been loaded, and return it if it has been
768
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
769
+			return $this->{$class_abbreviation};
770
+		}
771
+		if (isset ($this->{$class_name})) {
772
+			return $this->{$class_name};
773
+		}
774
+		if (isset ($this->LIB->{$class_name})) {
775
+			return $this->LIB->{$class_name};
776
+		}
777
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
778
+			return $this->addons->{$class_name};
779
+		}
780
+		return null;
781
+	}
782
+
783
+
784
+
785
+	/**
786
+	 * removes a cached version of the requested class
787
+	 *
788
+	 * @param string $class_name
789
+	 * @param boolean $addon
790
+	 * @return boolean
791
+	 */
792
+	public function clear_cached_class($class_name, $addon = false)
793
+	{
794
+		// have to specify something, but not anything that will conflict
795
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
796
+			? $this->_class_abbreviations[ $class_name ]
797
+			: 'FANCY_BATMAN_PANTS';
798
+		$class_name = str_replace('\\', '_', $class_name);
799
+		// check if class has already been loaded, and return it if it has been
800
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
801
+			$this->{$class_abbreviation} = null;
802
+			return true;
803
+		}
804
+		if (isset($this->{$class_name})) {
805
+			$this->{$class_name} = null;
806
+			return true;
807
+		}
808
+		if (isset($this->LIB->{$class_name})) {
809
+			unset($this->LIB->{$class_name});
810
+			return true;
811
+		}
812
+		if ($addon && isset($this->addons->{$class_name})) {
813
+			unset($this->addons->{$class_name});
814
+			return true;
815
+		}
816
+		return false;
817
+	}
818
+
819
+
820
+	/**
821
+	 * _resolve_path
822
+	 * attempts to find a full valid filepath for the requested class.
823
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
824
+	 * then returns that path if the target file has been found and is readable
825
+	 *
826
+	 * @access protected
827
+	 * @param string $class_name
828
+	 * @param string $type
829
+	 * @param array  $file_paths
830
+	 * @return string | bool
831
+	 */
832
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
833
+	{
834
+		// make sure $file_paths is an array
835
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
836
+		// cycle thru paths
837
+		foreach ($file_paths as $key => $file_path) {
838
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
839
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
840
+			// prep file type
841
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
842
+			// build full file path
843
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
844
+			//does the file exist and can be read ?
845
+			if (is_readable($file_paths[$key])) {
846
+				return $file_paths[$key];
847
+			}
848
+		}
849
+		return false;
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 * _require_file
856
+	 * basically just performs a require_once()
857
+	 * but with some error handling
858
+	 *
859
+	 * @access protected
860
+	 * @param  string $path
861
+	 * @param  string $class_name
862
+	 * @param  string $type
863
+	 * @param  array  $file_paths
864
+	 * @return boolean
865
+	 * @throws \EE_Error
866
+	 */
867
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
868
+	{
869
+		// don't give up! you gotta...
870
+		try {
871
+			//does the file exist and can it be read ?
872
+			if ( ! $path) {
873
+				// so sorry, can't find the file
874
+				throw new EE_Error (
875
+					sprintf(
876
+						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
877
+						trim($type, '.'),
878
+						$class_name,
879
+						'<br />' . implode(',<br />', $file_paths)
880
+					)
881
+				);
882
+			}
883
+			// get the file
884
+			require_once($path);
885
+			// if the class isn't already declared somewhere
886
+			if (class_exists($class_name, false) === false) {
887
+				// so sorry, not a class
888
+				throw new EE_Error(
889
+					sprintf(
890
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
891
+						$type,
892
+						$path,
893
+						$class_name
894
+					)
895
+				);
896
+			}
897
+		} catch (EE_Error $e) {
898
+			$e->get_error();
899
+			return false;
900
+		}
901
+		return true;
902
+	}
903
+
904
+
905
+
906
+	/**
907
+	 * _create_object
908
+	 * Attempts to instantiate the requested class via any of the
909
+	 * commonly used instantiation methods employed throughout EE.
910
+	 * The priority for instantiation is as follows:
911
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
912
+	 *        - model objects via their 'new_instance_from_db' method
913
+	 *        - model objects via their 'new_instance' method
914
+	 *        - "singleton" classes" via their 'instance' method
915
+	 *    - standard instantiable classes via their __constructor
916
+	 * Prior to instantiation, if the classname exists in the dependency_map,
917
+	 * then the constructor for the requested class will be examined to determine
918
+	 * if any dependencies exist, and if they can be injected.
919
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
920
+	 *
921
+	 * @access protected
922
+	 * @param string $class_name
923
+	 * @param array  $arguments
924
+	 * @param string $type
925
+	 * @param bool   $from_db
926
+	 * @return null | object
927
+	 * @throws \EE_Error
928
+	 */
929
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
930
+	{
931
+		$class_obj = null;
932
+		$instantiation_mode = '0) none';
933
+		// don't give up! you gotta...
934
+		try {
935
+			// create reflection
936
+			$reflector = $this->get_ReflectionClass($class_name);
937
+			// make sure arguments are an array
938
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
939
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
940
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
941
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
942
+				? $arguments
943
+				: array($arguments);
944
+			// attempt to inject dependencies ?
945
+			if ($this->_dependency_map->has($class_name)) {
946
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
947
+			}
948
+			// instantiate the class if possible
949
+			if ($reflector->isAbstract()) {
950
+				// nothing to instantiate, loading file was enough
951
+				// does not throw an exception so $instantiation_mode is unused
952
+				// $instantiation_mode = "1) no constructor abstract class";
953
+				$class_obj = true;
954
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
955
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
956
+				$instantiation_mode = "2) no constructor but instantiable";
957
+				$class_obj = $reflector->newInstance();
958
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
959
+				$instantiation_mode = "3) new_instance_from_db()";
960
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
961
+			} else if (method_exists($class_name, 'new_instance')) {
962
+				$instantiation_mode = "4) new_instance()";
963
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
964
+			} else if (method_exists($class_name, 'instance')) {
965
+				$instantiation_mode = "5) instance()";
966
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
967
+			} else if ($reflector->isInstantiable()) {
968
+				$instantiation_mode = "6) constructor";
969
+				$class_obj = $reflector->newInstanceArgs($arguments);
970
+			} else {
971
+				// heh ? something's not right !
972
+				throw new EE_Error(
973
+					sprintf(
974
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
975
+						$type,
976
+						$class_name
977
+					)
978
+				);
979
+			}
980
+		} catch (Exception $e) {
981
+			if ( ! $e instanceof EE_Error) {
982
+				$e = new EE_Error(
983
+					sprintf(
984
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
985
+						$class_name,
986
+						'<br />',
987
+						$e->getMessage(),
988
+						$instantiation_mode
989
+					)
990
+				);
991
+			}
992
+			$e->get_error();
993
+		}
994
+		return $class_obj;
995
+	}
996
+
997
+
998
+
999
+	/**
1000
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1001
+	 * @param array $array
1002
+	 * @return bool
1003
+	 */
1004
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1005
+	{
1006
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * getReflectionClass
1013
+	 * checks if a ReflectionClass object has already been generated for a class
1014
+	 * and returns that instead of creating a new one
1015
+	 *
1016
+	 * @access public
1017
+	 * @param string $class_name
1018
+	 * @return ReflectionClass
1019
+	 */
1020
+	public function get_ReflectionClass($class_name)
1021
+	{
1022
+		if (
1023
+			! isset($this->_reflectors[$class_name])
1024
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1025
+		) {
1026
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1027
+		}
1028
+		return $this->_reflectors[$class_name];
1029
+	}
1030
+
1031
+
1032
+
1033
+	/**
1034
+	 * _resolve_dependencies
1035
+	 * examines the constructor for the requested class to determine
1036
+	 * if any dependencies exist, and if they can be injected.
1037
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1038
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1039
+	 * For example:
1040
+	 *        if attempting to load a class "Foo" with the following constructor:
1041
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1042
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1043
+	 *        but only IF they are NOT already present in the incoming arguments array,
1044
+	 *        and the correct classes can be loaded
1045
+	 *
1046
+	 * @access protected
1047
+	 * @param ReflectionClass $reflector
1048
+	 * @param string          $class_name
1049
+	 * @param array           $arguments
1050
+	 * @return array
1051
+	 * @throws \ReflectionException
1052
+	 */
1053
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1054
+	{
1055
+		// let's examine the constructor
1056
+		$constructor = $reflector->getConstructor();
1057
+		// whu? huh? nothing?
1058
+		if ( ! $constructor) {
1059
+			return $arguments;
1060
+		}
1061
+		// get constructor parameters
1062
+		$params = $constructor->getParameters();
1063
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1064
+		$argument_keys = array_keys($arguments);
1065
+		// now loop thru all of the constructors expected parameters
1066
+		foreach ($params as $index => $param) {
1067
+			// is this a dependency for a specific class ?
1068
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
1069
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1070
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1071
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1072
+				: $param_class;
1073
+			if (
1074
+				// param is not even a class
1075
+				empty($param_class)
1076
+				// and something already exists in the incoming arguments for this param
1077
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1078
+			) {
1079
+				// so let's skip this argument and move on to the next
1080
+				continue;
1081
+			}
1082
+			if (
1083
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1084
+				! empty($param_class)
1085
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1086
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1087
+			) {
1088
+				// skip this argument and move on to the next
1089
+				continue;
1090
+			}
1091
+			if (
1092
+				// parameter is type hinted as a class, and should be injected
1093
+				! empty($param_class)
1094
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1095
+			) {
1096
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1097
+			} else {
1098
+				try {
1099
+					$arguments[$index] = $param->getDefaultValue();
1100
+				} catch (ReflectionException $e) {
1101
+					throw new ReflectionException(
1102
+						sprintf(
1103
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1104
+							$e->getMessage(),
1105
+							$param->getName()
1106
+						)
1107
+					);
1108
+				}
1109
+			}
1110
+		}
1111
+		return $arguments;
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * @access protected
1118
+	 * @param string $class_name
1119
+	 * @param string $param_class
1120
+	 * @param array  $arguments
1121
+	 * @param mixed  $index
1122
+	 * @return array
1123
+	 */
1124
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1125
+	{
1126
+		$dependency = null;
1127
+		// should dependency be loaded from cache ?
1128
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1129
+					!== EE_Dependency_Map::load_new_object
1130
+			? true
1131
+			: false;
1132
+		// we might have a dependency...
1133
+		// let's MAYBE try and find it in our cache if that's what's been requested
1134
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1135
+		// and grab it if it exists
1136
+		if ($cached_class instanceof $param_class) {
1137
+			$dependency = $cached_class;
1138
+		} else if ($param_class !== $class_name) {
1139
+			// obtain the loader method from the dependency map
1140
+			$loader = $this->_dependency_map->class_loader($param_class);
1141
+			// is loader a custom closure ?
1142
+			if ($loader instanceof Closure) {
1143
+				$dependency = $loader();
1144
+			} else {
1145
+				// set the cache on property for the recursive loading call
1146
+				$this->_cache_on = $cache_on;
1147
+				// if not, then let's try and load it via the registry
1148
+				if ($loader && method_exists($this, $loader)) {
1149
+					$dependency = $this->{$loader}($param_class);
1150
+				} else {
1151
+					$dependency = $this->create($param_class, array(), $cache_on);
1152
+				}
1153
+			}
1154
+		}
1155
+		// did we successfully find the correct dependency ?
1156
+		if ($dependency instanceof $param_class) {
1157
+			// then let's inject it into the incoming array of arguments at the correct location
1158
+			if (isset($argument_keys[$index])) {
1159
+				$arguments[$argument_keys[$index]] = $dependency;
1160
+			} else {
1161
+				$arguments[$index] = $dependency;
1162
+			}
1163
+		}
1164
+		return $arguments;
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 * _set_cached_class
1171
+	 * attempts to cache the instantiated class locally
1172
+	 * in one of the following places, in the following order:
1173
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1174
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1175
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1176
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1177
+	 *
1178
+	 * @access protected
1179
+	 * @param object $class_obj
1180
+	 * @param string $class_name
1181
+	 * @param string $class_prefix
1182
+	 * @param bool   $from_db
1183
+	 * @return void
1184
+	 */
1185
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1186
+	{
1187
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1188
+			return;
1189
+		}
1190
+		// return newly instantiated class
1191
+		if (isset($this->_class_abbreviations[$class_name])) {
1192
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1193
+			$this->{$class_abbreviation} = $class_obj;
1194
+			return;
1195
+		}
1196
+		$class_name = str_replace('\\', '_', $class_name);
1197
+		if (property_exists($this, $class_name)) {
1198
+			$this->{$class_name} = $class_obj;
1199
+			return;
1200
+		}
1201
+		if ($class_prefix === 'addon') {
1202
+			$this->addons->{$class_name} = $class_obj;
1203
+			return;
1204
+		}
1205
+		if ( ! $from_db) {
1206
+			$this->LIB->{$class_name} = $class_obj;
1207
+		}
1208
+	}
1209
+
1210
+
1211
+
1212
+	/**
1213
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1214
+	 *
1215
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1216
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1217
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1218
+	 * @param array  $arguments
1219
+	 * @return object
1220
+	 */
1221
+	public static function factory($classname, $arguments = array())
1222
+	{
1223
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1224
+		if ($loader instanceof Closure) {
1225
+			return $loader($arguments);
1226
+		}
1227
+		if (method_exists(EE_Registry::instance(), $loader)) {
1228
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1229
+		}
1230
+		return null;
1231
+	}
1232
+
1233
+
1234
+
1235
+	/**
1236
+	 * Gets the addon by its name/slug (not classname. For that, just
1237
+	 * use the classname as the property name on EE_Config::instance()->addons)
1238
+	 *
1239
+	 * @param string $name
1240
+	 * @return EE_Addon
1241
+	 */
1242
+	public function get_addon_by_name($name)
1243
+	{
1244
+		foreach ($this->addons as $addon) {
1245
+			if ($addon->name() == $name) {
1246
+				return $addon;
1247
+			}
1248
+		}
1249
+		return null;
1250
+	}
1251
+
1252
+
1253
+
1254
+	/**
1255
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1256
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1257
+	 *
1258
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1259
+	 */
1260
+	public function get_addons_by_name()
1261
+	{
1262
+		$addons = array();
1263
+		foreach ($this->addons as $addon) {
1264
+			$addons[$addon->name()] = $addon;
1265
+		}
1266
+		return $addons;
1267
+	}
1268
+
1269
+
1270
+
1271
+	/**
1272
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1273
+	 * a stale copy of it around
1274
+	 *
1275
+	 * @param string $model_name
1276
+	 * @return \EEM_Base
1277
+	 * @throws \EE_Error
1278
+	 */
1279
+	public function reset_model($model_name)
1280
+	{
1281
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1282
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1283
+			return null;
1284
+		}
1285
+		//get that model reset it and make sure we nuke the old reference to it
1286
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1287
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1288
+		} else {
1289
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1290
+		}
1291
+		return $this->LIB->{$model_class_name};
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 * Resets the registry.
1298
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1299
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1300
+	 * - $_dependency_map
1301
+	 * - $_class_abbreviations
1302
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1303
+	 * - $REQ:  Still on the same request so no need to change.
1304
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1305
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1306
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1307
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1308
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1309
+	 *             switch or on the restore.
1310
+	 * - $modules
1311
+	 * - $shortcodes
1312
+	 * - $widgets
1313
+	 *
1314
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1315
+	 *                                  the Registry to its state at the beginning of the request
1316
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1317
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1318
+	 *                                  currently reinstantiate the singletons at the moment)
1319
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1320
+	 *                                  code instead can just change the model context to a different blog id if necessary
1321
+	 * @return EE_Registry
1322
+	 */
1323
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1324
+	{
1325
+		$instance = self::instance();
1326
+		$instance->_cache_on = true;
1327
+		// reset some "special" classes
1328
+		EEH_Activation::reset();
1329
+		$instance->CFG = $instance->CFG->reset($hard, $reinstantiate);
1330
+		$instance->CART = null;
1331
+		$instance->MRM = null;
1332
+		$instance->AssetsRegistry = null;
1333
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1334
+		//messages reset
1335
+		EED_Messages::reset();
1336
+		//handle of objects cached on LIB
1337
+		foreach (array('LIB', 'modules', 'shortcodes') as $cache) {
1338
+			foreach ($instance->{$cache} as $class_name => $class) {
1339
+				if (EE_Registry::_reset_and_unset_object($class, $reset_models)) {
1340
+					unset($instance->{$cache}->{$class_name});
1341
+				}
1342
+			}
1343
+		}
1344
+		return $instance;
1345
+	}
1346
+
1347
+
1348
+
1349
+	/**
1350
+	 * if passed object implements ResettableInterface, then call it's reset() method
1351
+	 * if passed object implements InterminableInterface, then return false,
1352
+	 * to indicate that it should NOT be cleared from the Registry cache
1353
+	 *
1354
+	 * @param      $object
1355
+	 * @param bool $reset_models
1356
+	 * @return bool returns true if cached object should be unset
1357
+	 */
1358
+	private static function _reset_and_unset_object($object, $reset_models)
1359
+	{
1360
+		static $count = 0;
1361
+		$count++;
1362
+		if ($object instanceof ResettableInterface) {
1363
+			if ($object instanceof EEM_Base) {
1364
+				if ($reset_models) {
1365
+					$object->reset();
1366
+					return true;
1367
+				}
1368
+				return false;
1369
+			}
1370
+			$object->reset();
1371
+			return true;
1372
+		}
1373
+		if ( ! $object instanceof InterminableInterface) {
1374
+			return true;
1375
+		}
1376
+		return false;
1377
+	}
1378
+
1379
+
1380
+
1381
+	/**
1382
+	 * @override magic methods
1383
+	 * @return void
1384
+	 */
1385
+	public final function __destruct()
1386
+	{
1387
+	}
1388
+
1389
+
1390
+
1391
+	/**
1392
+	 * @param $a
1393
+	 * @param $b
1394
+	 */
1395
+	public final function __call($a, $b)
1396
+	{
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 * @param $a
1403
+	 */
1404
+	public final function __get($a)
1405
+	{
1406
+	}
1407
+
1408
+
1409
+
1410
+	/**
1411
+	 * @param $a
1412
+	 * @param $b
1413
+	 */
1414
+	public final function __set($a, $b)
1415
+	{
1416
+	}
1417
+
1418
+
1419
+
1420
+	/**
1421
+	 * @param $a
1422
+	 */
1423
+	public final function __isset($a)
1424
+	{
1425
+	}
1426 1426
 
1427 1427
 
1428 1428
 
1429
-    /**
1430
-     * @param $a
1431
-     */
1432
-    public final function __unset($a)
1433
-    {
1434
-    }
1429
+	/**
1430
+	 * @param $a
1431
+	 */
1432
+	public final function __unset($a)
1433
+	{
1434
+	}
1435 1435
 
1436 1436
 
1437 1437
 
1438
-    /**
1439
-     * @return array
1440
-     */
1441
-    public final function __sleep()
1442
-    {
1443
-        return array();
1444
-    }
1438
+	/**
1439
+	 * @return array
1440
+	 */
1441
+	public final function __sleep()
1442
+	{
1443
+		return array();
1444
+	}
1445 1445
 
1446 1446
 
1447 1447
 
1448
-    public final function __wakeup()
1449
-    {
1450
-    }
1448
+	public final function __wakeup()
1449
+	{
1450
+	}
1451 1451
 
1452 1452
 
1453 1453
 
1454
-    /**
1455
-     * @return string
1456
-     */
1457
-    public final function __toString()
1458
-    {
1459
-        return '';
1460
-    }
1454
+	/**
1455
+	 * @return string
1456
+	 */
1457
+	public final function __toString()
1458
+	{
1459
+		return '';
1460
+	}
1461 1461
 
1462 1462
 
1463 1463
 
1464
-    public final function __invoke()
1465
-    {
1466
-    }
1464
+	public final function __invoke()
1465
+	{
1466
+	}
1467 1467
 
1468 1468
 
1469 1469
 
1470
-    public final static function __set_state($array = array())
1471
-    {
1472
-        return EE_Registry::instance();
1473
-    }
1470
+	public final static function __set_state($array = array())
1471
+	{
1472
+		return EE_Registry::instance();
1473
+	}
1474 1474
 
1475 1475
 
1476 1476
 
1477
-    public final function __clone()
1478
-    {
1479
-    }
1477
+	public final function __clone()
1478
+	{
1479
+	}
1480 1480
 
1481 1481
 
1482 1482
 
1483
-    /**
1484
-     * @param $a
1485
-     * @param $b
1486
-     */
1487
-    public final static function __callStatic($a, $b)
1488
-    {
1489
-    }
1483
+	/**
1484
+	 * @param $a
1485
+	 * @param $b
1486
+	 */
1487
+	public final static function __callStatic($a, $b)
1488
+	{
1489
+	}
1490 1490
 
1491 1491
 
1492 1492
 
1493
-    /**
1494
-     * Gets all the custom post type models defined
1495
-     *
1496
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1497
-     */
1498
-    public function cpt_models()
1499
-    {
1500
-        $cpt_models = array();
1501
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1502
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1503
-                $cpt_models[$short_name] = $classname;
1504
-            }
1505
-        }
1506
-        return $cpt_models;
1507
-    }
1493
+	/**
1494
+	 * Gets all the custom post type models defined
1495
+	 *
1496
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1497
+	 */
1498
+	public function cpt_models()
1499
+	{
1500
+		$cpt_models = array();
1501
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1502
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1503
+				$cpt_models[$short_name] = $classname;
1504
+			}
1505
+		}
1506
+		return $cpt_models;
1507
+	}
1508 1508
 
1509 1509
 
1510 1510
 
1511
-    /**
1512
-     * @return \EE_Config
1513
-     */
1514
-    public static function CFG()
1515
-    {
1516
-        return self::instance()->CFG;
1517
-    }
1511
+	/**
1512
+	 * @return \EE_Config
1513
+	 */
1514
+	public static function CFG()
1515
+	{
1516
+		return self::instance()->CFG;
1517
+	}
1518 1518
 
1519 1519
 
1520 1520
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1090 added lines, -1090 removed lines patch added patch discarded remove patch
@@ -21,1096 +21,1096 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
-     */
28
-    const req_type_normal = 0;
29
-
30
-    /**
31
-     * Indicates this is a brand new installation of EE so we should install
32
-     * tables and default data etc
33
-     */
34
-    const req_type_new_activation = 1;
35
-
36
-    /**
37
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
-     * and we just exited maintenance mode). We MUST check the database is setup properly
39
-     * and that default data is setup too
40
-     */
41
-    const req_type_reactivation = 2;
42
-
43
-    /**
44
-     * indicates that EE has been upgraded since its previous request.
45
-     * We may have data migration scripts to call and will want to trigger maintenance mode
46
-     */
47
-    const req_type_upgrade = 3;
48
-
49
-    /**
50
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
-     */
52
-    const req_type_downgrade = 4;
53
-
54
-    /**
55
-     * @deprecated since version 4.6.0.dev.006
56
-     * Now whenever a new_activation is detected the request type is still just
57
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
-     * (Specifically, when the migration manager indicates migrations are finished
61
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
-     */
63
-    const req_type_activation_but_not_installed = 5;
64
-
65
-    /**
66
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
-     */
68
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
-
70
-
71
-    /**
72
-     * @var EE_System $_instance
73
-     */
74
-    private static $_instance;
75
-
76
-    /**
77
-     * @var EE_Registry $registry
78
-     */
79
-    private $registry;
80
-
81
-    /**
82
-     * @var LoaderInterface $loader
83
-     */
84
-    private $loader;
85
-
86
-    /**
87
-     * @var EE_Capabilities $capabilities
88
-     */
89
-    private $capabilities;
90
-
91
-    /**
92
-     * @var EE_Request $request
93
-     */
94
-    private $request;
95
-
96
-    /**
97
-     * @var EE_Maintenance_Mode $maintenance_mode
98
-     */
99
-    private $maintenance_mode;
100
-
101
-    /**
102
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
-     *
105
-     * @var int $_req_type
106
-     */
107
-    private $_req_type;
108
-
109
-    /**
110
-     * Whether or not there was a non-micro version change in EE core version during this request
111
-     *
112
-     * @var boolean $_major_version_change
113
-     */
114
-    private $_major_version_change = false;
115
-
116
-
117
-
118
-    /**
119
-     * @singleton method used to instantiate class object
120
-     * @param EE_Registry|null         $registry
121
-     * @param LoaderInterface|null     $loader
122
-     * @param EE_Capabilities|null     $capabilities
123
-     * @param EE_Request|null          $request
124
-     * @param EE_Maintenance_Mode|null $maintenance_mode
125
-     * @return EE_System
126
-     */
127
-    public static function instance(
128
-        EE_Registry $registry = null,
129
-        LoaderInterface $loader = null,
130
-        EE_Capabilities $capabilities = null,
131
-        EE_Request $request = null,
132
-        EE_Maintenance_Mode $maintenance_mode = null
133
-    ) {
134
-        // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
136
-            self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
-        }
138
-        return self::$_instance;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * resets the instance and returns it
145
-     *
146
-     * @return EE_System
147
-     */
148
-    public static function reset()
149
-    {
150
-        self::$_instance->_req_type = null;
151
-        //make sure none of the old hooks are left hanging around
152
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
-        //we need to reset the migration manager in order for it to detect DMSs properly
154
-        EE_Data_Migration_Manager::reset();
155
-        self::instance()->detect_activations_or_upgrades();
156
-        self::instance()->perform_activations_upgrades_and_migrations();
157
-        return self::instance();
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * sets hooks for running rest of system
164
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
-     * starting EE Addons from any other point may lead to problems
166
-     *
167
-     * @param EE_Registry         $registry
168
-     * @param LoaderInterface     $loader
169
-     * @param EE_Capabilities     $capabilities
170
-     * @param EE_Request          $request
171
-     * @param EE_Maintenance_Mode $maintenance_mode
172
-     */
173
-    private function __construct(
174
-        EE_Registry $registry,
175
-        LoaderInterface $loader,
176
-        EE_Capabilities $capabilities,
177
-        EE_Request $request,
178
-        EE_Maintenance_Mode $maintenance_mode
179
-    ) {
180
-        $this->registry = $registry;
181
-        $this->loader = $loader;
182
-        $this->capabilities = $capabilities;
183
-        $this->request = $request;
184
-        $this->maintenance_mode = $maintenance_mode;
185
-        do_action('AHEE__EE_System__construct__begin', $this);
186
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
187
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
188
-        // when an ee addon is activated, we want to call the core hook(s) again
189
-        // because the newly-activated addon didn't get a chance to run at all
190
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
191
-        // detect whether install or upgrade
192
-        add_action(
193
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
194
-            3
195
-        );
196
-        // load EE_Config, EE_Textdomain, etc
197
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
198
-        // load EE_Config, EE_Textdomain, etc
199
-        add_action(
200
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
201
-            array($this, 'register_shortcodes_modules_and_widgets'), 7
202
-        );
203
-        // you wanna get going? I wanna get going... let's get going!
204
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
205
-        //other housekeeping
206
-        //exclude EE critical pages from wp_list_pages
207
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
208
-        // ALL EE Addons should use the following hook point to attach their initial setup too
209
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
210
-        do_action('AHEE__EE_System__construct__complete', $this);
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * load_espresso_addons
217
-     * allow addons to load first so that they can set hooks for running DMS's, etc
218
-     * this is hooked into both:
219
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
220
-     *        which runs during the WP 'plugins_loaded' action at priority 5
221
-     *    and the WP 'activate_plugin' hook point
222
-     *
223
-     * @access public
224
-     * @return void
225
-     * @throws EE_Error
226
-     */
227
-    public function load_espresso_addons()
228
-    {
229
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
230
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
231
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
232
-        //caps need to be initialized on every request so that capability maps are set.
233
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
234
-        $this->capabilities->init_caps();
235
-        do_action('AHEE__EE_System__load_espresso_addons');
236
-        //if the WP API basic auth plugin isn't already loaded, load it now.
237
-        //We want it for mobile apps. Just include the entire plugin
238
-        //also, don't load the basic auth when a plugin is getting activated, because
239
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
240
-        //and causes a fatal error
241
-        if (
242
-            ! (
243
-                isset($_GET['activate'])
244
-                && $_GET['activate'] === 'true'
245
-            )
246
-            && ! function_exists('json_basic_auth_handler')
247
-            && ! function_exists('json_basic_auth_error')
248
-            && ! (
249
-                isset($_GET['action'])
250
-                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
251
-            )
252
-        ) {
253
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
254
-        }
255
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * detect_activations_or_upgrades
262
-     * Checks for activation or upgrade of core first;
263
-     * then also checks if any registered addons have been activated or upgraded
264
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
265
-     * which runs during the WP 'plugins_loaded' action at priority 3
266
-     *
267
-     * @access public
268
-     * @return void
269
-     */
270
-    public function detect_activations_or_upgrades()
271
-    {
272
-        //first off: let's make sure to handle core
273
-        $this->detect_if_activation_or_upgrade();
274
-        foreach ($this->registry->addons as $addon) {
275
-            if ($addon instanceof EE_Addon) {
276
-                //detect teh request type for that addon
277
-                $addon->detect_activation_or_upgrade();
278
-            }
279
-        }
280
-    }
281
-
282
-
283
-
284
-    /**
285
-     * detect_if_activation_or_upgrade
286
-     * Takes care of detecting whether this is a brand new install or code upgrade,
287
-     * and either setting up the DB or setting up maintenance mode etc.
288
-     *
289
-     * @access public
290
-     * @return void
291
-     */
292
-    public function detect_if_activation_or_upgrade()
293
-    {
294
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
295
-        // check if db has been updated, or if its a brand-new installation
296
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
297
-        $request_type = $this->detect_req_type($espresso_db_update);
298
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
299
-        switch ($request_type) {
300
-            case EE_System::req_type_new_activation:
301
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
302
-                $this->_handle_core_version_change($espresso_db_update);
303
-                break;
304
-            case EE_System::req_type_reactivation:
305
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
306
-                $this->_handle_core_version_change($espresso_db_update);
307
-                break;
308
-            case EE_System::req_type_upgrade:
309
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
310
-                //migrations may be required now that we've upgraded
311
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
312
-                $this->_handle_core_version_change($espresso_db_update);
313
-                //				echo "done upgrade";die;
314
-                break;
315
-            case EE_System::req_type_downgrade:
316
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
317
-                //its possible migrations are no longer required
318
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
319
-                $this->_handle_core_version_change($espresso_db_update);
320
-                break;
321
-            case EE_System::req_type_normal:
322
-            default:
323
-                //				$this->_maybe_redirect_to_ee_about();
324
-                break;
325
-        }
326
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     * Updates the list of installed versions and sets hooks for
333
-     * initializing the database later during the request
334
-     *
335
-     * @param array $espresso_db_update
336
-     */
337
-    private function _handle_core_version_change($espresso_db_update)
338
-    {
339
-        $this->update_list_of_installed_versions($espresso_db_update);
340
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
341
-        add_action(
342
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
-            array($this, 'initialize_db_if_no_migrations_required')
344
-        );
345
-    }
346
-
347
-
348
-
349
-    /**
350
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
351
-     * information about what versions of EE have been installed and activated,
352
-     * NOT necessarily the state of the database
353
-     *
354
-     * @param mixed $espresso_db_update the value of the WordPress option.
355
-     *                                            If not supplied, fetches it from the options table
356
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
357
-     */
358
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359
-    {
360
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
-        if (! $espresso_db_update) {
362
-            $espresso_db_update = get_option('espresso_db_update');
363
-        }
364
-        // check that option is an array
365
-        if (! is_array($espresso_db_update)) {
366
-            // if option is FALSE, then it never existed
367
-            if ($espresso_db_update === false) {
368
-                // make $espresso_db_update an array and save option with autoload OFF
369
-                $espresso_db_update = array();
370
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
371
-            } else {
372
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
373
-                $espresso_db_update = array($espresso_db_update => array());
374
-                update_option('espresso_db_update', $espresso_db_update);
375
-            }
376
-        } else {
377
-            $corrected_db_update = array();
378
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
379
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
380
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
381
-                    //the key is an int, and the value IS NOT an array
382
-                    //so it must be numerically-indexed, where values are versions installed...
383
-                    //fix it!
384
-                    $version_string = $should_be_array;
385
-                    $corrected_db_update[$version_string] = array('unknown-date');
386
-                } else {
387
-                    //ok it checks out
388
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
389
-                }
390
-            }
391
-            $espresso_db_update = $corrected_db_update;
392
-            update_option('espresso_db_update', $espresso_db_update);
393
-        }
394
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
395
-        return $espresso_db_update;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Does the traditional work of setting up the plugin's database and adding default data.
402
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
403
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
404
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
405
-     * so that it will be done when migrations are finished
406
-     *
407
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
408
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
409
-     *                                       This is a resource-intensive job
410
-     *                                       so we prefer to only do it when necessary
411
-     * @return void
412
-     * @throws EE_Error
413
-     */
414
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
415
-    {
416
-        $request_type = $this->detect_req_type();
417
-        //only initialize system if we're not in maintenance mode.
418
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
419
-            update_option('ee_flush_rewrite_rules', true);
420
-            if ($verify_schema) {
421
-                EEH_Activation::initialize_db_and_folders();
422
-            }
423
-            EEH_Activation::initialize_db_content();
424
-            EEH_Activation::system_initialization();
425
-            if ($initialize_addons_too) {
426
-                $this->initialize_addons();
427
-            }
428
-        } else {
429
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
430
-        }
431
-        if ($request_type === EE_System::req_type_new_activation
432
-            || $request_type === EE_System::req_type_reactivation
433
-            || (
434
-                $request_type === EE_System::req_type_upgrade
435
-                && $this->is_major_version_change()
436
-            )
437
-        ) {
438
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
439
-        }
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * Initializes the db for all registered addons
446
-     *
447
-     * @throws EE_Error
448
-     */
449
-    public function initialize_addons()
450
-    {
451
-        //foreach registered addon, make sure its db is up-to-date too
452
-        foreach ($this->registry->addons as $addon) {
453
-            if ($addon instanceof EE_Addon) {
454
-                $addon->initialize_db_if_no_migrations_required();
455
-            }
456
-        }
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
463
-     *
464
-     * @param    array  $version_history
465
-     * @param    string $current_version_to_add version to be added to the version history
466
-     * @return    boolean success as to whether or not this option was changed
467
-     */
468
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469
-    {
470
-        if (! $version_history) {
471
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
472
-        }
473
-        if ($current_version_to_add === null) {
474
-            $current_version_to_add = espresso_version();
475
-        }
476
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
477
-        // re-save
478
-        return update_option('espresso_db_update', $version_history);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * Detects if the current version indicated in the has existed in the list of
485
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
486
-     *
487
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
488
-     *                                  If not supplied, fetches it from the options table.
489
-     *                                  Also, caches its result so later parts of the code can also know whether
490
-     *                                  there's been an update or not. This way we can add the current version to
491
-     *                                  espresso_db_update, but still know if this is a new install or not
492
-     * @return int one of the constants on EE_System::req_type_
493
-     */
494
-    public function detect_req_type($espresso_db_update = null)
495
-    {
496
-        if ($this->_req_type === null) {
497
-            $espresso_db_update = ! empty($espresso_db_update)
498
-                ? $espresso_db_update
499
-                : $this->fix_espresso_db_upgrade_option();
500
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
501
-                $espresso_db_update,
502
-                'ee_espresso_activation', espresso_version()
503
-            );
504
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
505
-        }
506
-        return $this->_req_type;
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * Returns whether or not there was a non-micro version change (ie, change in either
513
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
514
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
515
-     *
516
-     * @param $activation_history
517
-     * @return bool
518
-     */
519
-    private function _detect_major_version_change($activation_history)
520
-    {
521
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
522
-        $previous_version_parts = explode('.', $previous_version);
523
-        $current_version_parts = explode('.', espresso_version());
524
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
525
-               && ($previous_version_parts[0] !== $current_version_parts[0]
526
-                   || $previous_version_parts[1] !== $current_version_parts[1]
527
-               );
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     * Returns true if either the major or minor version of EE changed during this request.
534
-     * 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
535
-     *
536
-     * @return bool
537
-     */
538
-    public function is_major_version_change()
539
-    {
540
-        return $this->_major_version_change;
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
547
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
548
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
549
-     * just activated to (for core that will always be espresso_version())
550
-     *
551
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
552
-     *                                                 ee plugin. for core that's 'espresso_db_update'
553
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
554
-     *                                                 indicate that this plugin was just activated
555
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
556
-     *                                                 espresso_version())
557
-     * @return int one of the constants on EE_System::req_type_*
558
-     */
559
-    public static function detect_req_type_given_activation_history(
560
-        $activation_history_for_addon,
561
-        $activation_indicator_option_name,
562
-        $version_to_upgrade_to
563
-    ) {
564
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
565
-        if ($activation_history_for_addon) {
566
-            //it exists, so this isn't a completely new install
567
-            //check if this version already in that list of previously installed versions
568
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569
-                //it a version we haven't seen before
570
-                if ($version_is_higher === 1) {
571
-                    $req_type = EE_System::req_type_upgrade;
572
-                } else {
573
-                    $req_type = EE_System::req_type_downgrade;
574
-                }
575
-                delete_option($activation_indicator_option_name);
576
-            } else {
577
-                // its not an update. maybe a reactivation?
578
-                if (get_option($activation_indicator_option_name, false)) {
579
-                    if ($version_is_higher === -1) {
580
-                        $req_type = EE_System::req_type_downgrade;
581
-                    } else if ($version_is_higher === 0) {
582
-                        //we've seen this version before, but it's an activation. must be a reactivation
583
-                        $req_type = EE_System::req_type_reactivation;
584
-                    } else {//$version_is_higher === 1
585
-                        $req_type = EE_System::req_type_upgrade;
586
-                    }
587
-                    delete_option($activation_indicator_option_name);
588
-                } else {
589
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
590
-                    if ($version_is_higher === -1) {
591
-                        $req_type = EE_System::req_type_downgrade;
592
-                    } else if ($version_is_higher === 0) {
593
-                        //we've seen this version before and it's not an activation. its normal request
594
-                        $req_type = EE_System::req_type_normal;
595
-                    } else {//$version_is_higher === 1
596
-                        $req_type = EE_System::req_type_upgrade;
597
-                    }
598
-                }
599
-            }
600
-        } else {
601
-            //brand new install
602
-            $req_type = EE_System::req_type_new_activation;
603
-            delete_option($activation_indicator_option_name);
604
-        }
605
-        return $req_type;
606
-    }
607
-
608
-
609
-
610
-    /**
611
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
612
-     * the $activation_history_for_addon
613
-     *
614
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
615
-     *                                             sometimes containing 'unknown-date'
616
-     * @param string $version_to_upgrade_to        (current version)
617
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
618
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
619
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
620
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
621
-     */
622
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
623
-    {
624
-        //find the most recently-activated version
625
-        $most_recently_active_version =
626
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
627
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * Gets the most recently active version listed in the activation history,
634
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
635
-     *
636
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
637
-     *                                   sometimes containing 'unknown-date'
638
-     * @return string
639
-     */
640
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
641
-    {
642
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
643
-        $most_recently_active_version = '0.0.0.dev.000';
644
-        if (is_array($activation_history)) {
645
-            foreach ($activation_history as $version => $times_activated) {
646
-                //check there is a record of when this version was activated. Otherwise,
647
-                //mark it as unknown
648
-                if (! $times_activated) {
649
-                    $times_activated = array('unknown-date');
650
-                }
651
-                if (is_string($times_activated)) {
652
-                    $times_activated = array($times_activated);
653
-                }
654
-                foreach ($times_activated as $an_activation) {
655
-                    if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
656
-                        $most_recently_active_version = $version;
657
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
658
-                            ? '1970-01-01 00:00:00'
659
-                            : $an_activation;
660
-                    }
661
-                }
662
-            }
663
-        }
664
-        return $most_recently_active_version;
665
-    }
666
-
667
-
668
-
669
-    /**
670
-     * This redirects to the about EE page after activation
671
-     *
672
-     * @return void
673
-     */
674
-    public function redirect_to_about_ee()
675
-    {
676
-        $notices = EE_Error::get_notices(false);
677
-        //if current user is an admin and it's not an ajax or rest request
678
-        if (
679
-            ! (defined('DOING_AJAX') && DOING_AJAX)
680
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
681
-            && ! isset($notices['errors'])
682
-            && apply_filters(
683
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
684
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
685
-            )
686
-        ) {
687
-            $query_params = array('page' => 'espresso_about');
688
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
689
-                $query_params['new_activation'] = true;
690
-            }
691
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
692
-                $query_params['reactivation'] = true;
693
-            }
694
-            $url = add_query_arg($query_params, admin_url('admin.php'));
695
-            wp_safe_redirect($url);
696
-            exit();
697
-        }
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * load_core_configuration
704
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
705
-     * which runs during the WP 'plugins_loaded' action at priority 5
706
-     *
707
-     * @return void
708
-     * @throws ReflectionException
709
-     */
710
-    public function load_core_configuration()
711
-    {
712
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
713
-        $this->loader->getShared('EE_Load_Textdomain');
714
-        //load textdomain
715
-        EE_Load_Textdomain::load_textdomain();
716
-        // load and setup EE_Config and EE_Network_Config
717
-        $config = $this->loader->getShared('EE_Config');
718
-        $this->loader->getShared('EE_Network_Config');
719
-        // setup autoloaders
720
-        // enable logging?
721
-        if ($config->admin->use_full_logging) {
722
-            $this->loader->getShared('EE_Log');
723
-        }
724
-        // check for activation errors
725
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
726
-        if ($activation_errors) {
727
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
728
-            update_option('ee_plugin_activation_errors', false);
729
-        }
730
-        // get model names
731
-        $this->_parse_model_names();
732
-        //load caf stuff a chance to play during the activation process too.
733
-        $this->_maybe_brew_regular();
734
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
735
-    }
736
-
737
-
738
-
739
-    /**
740
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
741
-     *
742
-     * @return void
743
-     * @throws ReflectionException
744
-     */
745
-    private function _parse_model_names()
746
-    {
747
-        //get all the files in the EE_MODELS folder that end in .model.php
748
-        $models = glob(EE_MODELS . '*.model.php');
749
-        $model_names = array();
750
-        $non_abstract_db_models = array();
751
-        foreach ($models as $model) {
752
-            // get model classname
753
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
754
-            $short_name = str_replace('EEM_', '', $classname);
755
-            $reflectionClass = new ReflectionClass($classname);
756
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
757
-                $non_abstract_db_models[$short_name] = $classname;
758
-            }
759
-            $model_names[$short_name] = $classname;
760
-        }
761
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
762
-        $this->registry->non_abstract_db_models = apply_filters(
763
-            'FHEE__EE_System__parse_implemented_model_names',
764
-            $non_abstract_db_models
765
-        );
766
-    }
767
-
768
-
769
-
770
-    /**
771
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
772
-     * that need to be setup before our EE_System launches.
773
-     *
774
-     * @return void
775
-     */
776
-    private function _maybe_brew_regular()
777
-    {
778
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
779
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
780
-        }
781
-    }
782
-
783
-
784
-
785
-    /**
786
-     * register_shortcodes_modules_and_widgets
787
-     * generate lists of shortcodes and modules, then verify paths and classes
788
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
789
-     * which runs during the WP 'plugins_loaded' action at priority 7
790
-     *
791
-     * @access public
792
-     * @return void
793
-     * @throws Exception
794
-     */
795
-    public function register_shortcodes_modules_and_widgets()
796
-    {
797
-        try {
798
-            // load, register, and add shortcodes the new way
799
-            new ShortcodesManager(
800
-            // and the old way, but we'll put it under control of the new system
801
-                EE_Config::getLegacyShortcodesManager()
802
-            );
803
-        } catch (Exception $exception) {
804
-            new ExceptionStackTraceDisplay($exception);
805
-        }
806
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
807
-        // check for addons using old hook point
808
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
809
-            $this->_incompatible_addon_error();
810
-        }
811
-    }
812
-
813
-
814
-
815
-    /**
816
-     * _incompatible_addon_error
817
-     *
818
-     * @access public
819
-     * @return void
820
-     */
821
-    private function _incompatible_addon_error()
822
-    {
823
-        // get array of classes hooking into here
824
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
825
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
826
-        );
827
-        if (! empty($class_names)) {
828
-            $msg = __(
829
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
830
-                'event_espresso'
831
-            );
832
-            $msg .= '<ul>';
833
-            foreach ($class_names as $class_name) {
834
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
835
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
836
-                        $class_name
837
-                    ) . '</b></li>';
838
-            }
839
-            $msg .= '</ul>';
840
-            $msg .= __(
841
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
842
-                'event_espresso'
843
-            );
844
-            // save list of incompatible addons to wp-options for later use
845
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
846
-            if (is_admin()) {
847
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
848
-            }
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     * brew_espresso
856
-     * begins the process of setting hooks for initializing EE in the correct order
857
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
858
-     * which runs during the WP 'plugins_loaded' action at priority 9
859
-     *
860
-     * @return void
861
-     */
862
-    public function brew_espresso()
863
-    {
864
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
865
-        // load some final core systems
866
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
867
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
868
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
869
-        add_action('init', array($this, 'load_controllers'), 7);
870
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
871
-        add_action('init', array($this, 'initialize'), 10);
872
-        add_action('init', array($this, 'initialize_last'), 100);
873
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
874
-            // pew pew pew
875
-            $this->loader->getShared('EE_PUE');
876
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
877
-        }
878
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     *    set_hooks_for_core
885
-     *
886
-     * @access public
887
-     * @return    void
888
-     */
889
-    public function set_hooks_for_core()
890
-    {
891
-        $this->_deactivate_incompatible_addons();
892
-        do_action('AHEE__EE_System__set_hooks_for_core');
893
-    }
894
-
895
-
896
-
897
-    /**
898
-     * Using the information gathered in EE_System::_incompatible_addon_error,
899
-     * deactivates any addons considered incompatible with the current version of EE
900
-     */
901
-    private function _deactivate_incompatible_addons()
902
-    {
903
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
904
-        if (! empty($incompatible_addons)) {
905
-            $active_plugins = get_option('active_plugins', array());
906
-            foreach ($active_plugins as $active_plugin) {
907
-                foreach ($incompatible_addons as $incompatible_addon) {
908
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
909
-                        unset($_GET['activate']);
910
-                        espresso_deactivate_plugin($active_plugin);
911
-                    }
912
-                }
913
-            }
914
-        }
915
-    }
916
-
917
-
918
-
919
-    /**
920
-     *    perform_activations_upgrades_and_migrations
921
-     *
922
-     * @access public
923
-     * @return    void
924
-     */
925
-    public function perform_activations_upgrades_and_migrations()
926
-    {
927
-        //first check if we had previously attempted to setup EE's directories but failed
928
-        if (EEH_Activation::upload_directories_incomplete()) {
929
-            EEH_Activation::create_upload_directories();
930
-        }
931
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     *    load_CPTs_and_session
938
-     *
939
-     * @access public
940
-     * @return    void
941
-     */
942
-    public function load_CPTs_and_session()
943
-    {
944
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
945
-        // register Custom Post Types
946
-        $this->loader->getShared('EE_Register_CPTs');
947
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
948
-    }
949
-
950
-
951
-
952
-    /**
953
-     * load_controllers
954
-     * this is the best place to load any additional controllers that needs access to EE core.
955
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
956
-     * time
957
-     *
958
-     * @access public
959
-     * @return void
960
-     */
961
-    public function load_controllers()
962
-    {
963
-        do_action('AHEE__EE_System__load_controllers__start');
964
-        // let's get it started
965
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
966
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
967
-            $this->loader->getShared('EE_Front_Controller');
968
-        } else if (! EE_FRONT_AJAX) {
969
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
970
-            $this->loader->getShared('EE_Admin');
971
-        }
972
-        do_action('AHEE__EE_System__load_controllers__complete');
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * core_loaded_and_ready
979
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
980
-     *
981
-     * @access public
982
-     * @return void
983
-     */
984
-    public function core_loaded_and_ready()
985
-    {
986
-        $this->loader->getShared('EE_Session');
987
-        do_action('AHEE__EE_System__core_loaded_and_ready');
988
-        // load_espresso_template_tags
989
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
990
-            require_once(EE_PUBLIC . 'template_tags.php');
991
-        }
992
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
993
-        $this->loader->getShared('EventEspresso\core\services\assets\Registry');
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     * initialize
1000
-     * this is the best place to begin initializing client code
1001
-     *
1002
-     * @access public
1003
-     * @return void
1004
-     */
1005
-    public function initialize()
1006
-    {
1007
-        do_action('AHEE__EE_System__initialize');
1008
-    }
1009
-
1010
-
1011
-
1012
-    /**
1013
-     * initialize_last
1014
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1015
-     * initialize has done so
1016
-     *
1017
-     * @access public
1018
-     * @return void
1019
-     */
1020
-    public function initialize_last()
1021
-    {
1022
-        do_action('AHEE__EE_System__initialize_last');
1023
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     * @return void
1030
-     * @throws EE_Error
1031
-     */
1032
-    public function addEspressoToolbar()
1033
-    {
1034
-        $this->registry->create(
1035
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1036
-            array($this->registry->CAP)
1037
-        );
1038
-    }
1039
-
1040
-
1041
-
1042
-    /**
1043
-     * do_not_cache
1044
-     * sets no cache headers and defines no cache constants for WP plugins
1045
-     *
1046
-     * @access public
1047
-     * @return void
1048
-     */
1049
-    public static function do_not_cache()
1050
-    {
1051
-        // set no cache constants
1052
-        if (! defined('DONOTCACHEPAGE')) {
1053
-            define('DONOTCACHEPAGE', true);
1054
-        }
1055
-        if (! defined('DONOTCACHCEOBJECT')) {
1056
-            define('DONOTCACHCEOBJECT', true);
1057
-        }
1058
-        if (! defined('DONOTCACHEDB')) {
1059
-            define('DONOTCACHEDB', true);
1060
-        }
1061
-        // add no cache headers
1062
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1063
-        // plus a little extra for nginx and Google Chrome
1064
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1065
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1066
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1067
-    }
1068
-
1069
-
1070
-
1071
-    /**
1072
-     *    extra_nocache_headers
1073
-     *
1074
-     * @access    public
1075
-     * @param $headers
1076
-     * @return    array
1077
-     */
1078
-    public static function extra_nocache_headers($headers)
1079
-    {
1080
-        // for NGINX
1081
-        $headers['X-Accel-Expires'] = 0;
1082
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1083
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1084
-        return $headers;
1085
-    }
1086
-
1087
-
1088
-
1089
-    /**
1090
-     *    nocache_headers
1091
-     *
1092
-     * @access    public
1093
-     * @return    void
1094
-     */
1095
-    public static function nocache_headers()
1096
-    {
1097
-        nocache_headers();
1098
-    }
1099
-
1100
-
1101
-
1102
-
1103
-    /**
1104
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1105
-     * never returned with the function.
1106
-     *
1107
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1108
-     * @return array
1109
-     */
1110
-    public function remove_pages_from_wp_list_pages($exclude_array)
1111
-    {
1112
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1113
-    }
24
+	/**
25
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
+	 */
28
+	const req_type_normal = 0;
29
+
30
+	/**
31
+	 * Indicates this is a brand new installation of EE so we should install
32
+	 * tables and default data etc
33
+	 */
34
+	const req_type_new_activation = 1;
35
+
36
+	/**
37
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
39
+	 * and that default data is setup too
40
+	 */
41
+	const req_type_reactivation = 2;
42
+
43
+	/**
44
+	 * indicates that EE has been upgraded since its previous request.
45
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
46
+	 */
47
+	const req_type_upgrade = 3;
48
+
49
+	/**
50
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
+	 */
52
+	const req_type_downgrade = 4;
53
+
54
+	/**
55
+	 * @deprecated since version 4.6.0.dev.006
56
+	 * Now whenever a new_activation is detected the request type is still just
57
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
+	 * (Specifically, when the migration manager indicates migrations are finished
61
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
+	 */
63
+	const req_type_activation_but_not_installed = 5;
64
+
65
+	/**
66
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
+	 */
68
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
+
70
+
71
+	/**
72
+	 * @var EE_System $_instance
73
+	 */
74
+	private static $_instance;
75
+
76
+	/**
77
+	 * @var EE_Registry $registry
78
+	 */
79
+	private $registry;
80
+
81
+	/**
82
+	 * @var LoaderInterface $loader
83
+	 */
84
+	private $loader;
85
+
86
+	/**
87
+	 * @var EE_Capabilities $capabilities
88
+	 */
89
+	private $capabilities;
90
+
91
+	/**
92
+	 * @var EE_Request $request
93
+	 */
94
+	private $request;
95
+
96
+	/**
97
+	 * @var EE_Maintenance_Mode $maintenance_mode
98
+	 */
99
+	private $maintenance_mode;
100
+
101
+	/**
102
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
+	 *
105
+	 * @var int $_req_type
106
+	 */
107
+	private $_req_type;
108
+
109
+	/**
110
+	 * Whether or not there was a non-micro version change in EE core version during this request
111
+	 *
112
+	 * @var boolean $_major_version_change
113
+	 */
114
+	private $_major_version_change = false;
115
+
116
+
117
+
118
+	/**
119
+	 * @singleton method used to instantiate class object
120
+	 * @param EE_Registry|null         $registry
121
+	 * @param LoaderInterface|null     $loader
122
+	 * @param EE_Capabilities|null     $capabilities
123
+	 * @param EE_Request|null          $request
124
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
125
+	 * @return EE_System
126
+	 */
127
+	public static function instance(
128
+		EE_Registry $registry = null,
129
+		LoaderInterface $loader = null,
130
+		EE_Capabilities $capabilities = null,
131
+		EE_Request $request = null,
132
+		EE_Maintenance_Mode $maintenance_mode = null
133
+	) {
134
+		// check if class object is instantiated
135
+		if (! self::$_instance instanceof EE_System) {
136
+			self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
+		}
138
+		return self::$_instance;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * resets the instance and returns it
145
+	 *
146
+	 * @return EE_System
147
+	 */
148
+	public static function reset()
149
+	{
150
+		self::$_instance->_req_type = null;
151
+		//make sure none of the old hooks are left hanging around
152
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
+		//we need to reset the migration manager in order for it to detect DMSs properly
154
+		EE_Data_Migration_Manager::reset();
155
+		self::instance()->detect_activations_or_upgrades();
156
+		self::instance()->perform_activations_upgrades_and_migrations();
157
+		return self::instance();
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * sets hooks for running rest of system
164
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
+	 * starting EE Addons from any other point may lead to problems
166
+	 *
167
+	 * @param EE_Registry         $registry
168
+	 * @param LoaderInterface     $loader
169
+	 * @param EE_Capabilities     $capabilities
170
+	 * @param EE_Request          $request
171
+	 * @param EE_Maintenance_Mode $maintenance_mode
172
+	 */
173
+	private function __construct(
174
+		EE_Registry $registry,
175
+		LoaderInterface $loader,
176
+		EE_Capabilities $capabilities,
177
+		EE_Request $request,
178
+		EE_Maintenance_Mode $maintenance_mode
179
+	) {
180
+		$this->registry = $registry;
181
+		$this->loader = $loader;
182
+		$this->capabilities = $capabilities;
183
+		$this->request = $request;
184
+		$this->maintenance_mode = $maintenance_mode;
185
+		do_action('AHEE__EE_System__construct__begin', $this);
186
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
187
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
188
+		// when an ee addon is activated, we want to call the core hook(s) again
189
+		// because the newly-activated addon didn't get a chance to run at all
190
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
191
+		// detect whether install or upgrade
192
+		add_action(
193
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
194
+			3
195
+		);
196
+		// load EE_Config, EE_Textdomain, etc
197
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
198
+		// load EE_Config, EE_Textdomain, etc
199
+		add_action(
200
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
201
+			array($this, 'register_shortcodes_modules_and_widgets'), 7
202
+		);
203
+		// you wanna get going? I wanna get going... let's get going!
204
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
205
+		//other housekeeping
206
+		//exclude EE critical pages from wp_list_pages
207
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
208
+		// ALL EE Addons should use the following hook point to attach their initial setup too
209
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
210
+		do_action('AHEE__EE_System__construct__complete', $this);
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * load_espresso_addons
217
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
218
+	 * this is hooked into both:
219
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
220
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
221
+	 *    and the WP 'activate_plugin' hook point
222
+	 *
223
+	 * @access public
224
+	 * @return void
225
+	 * @throws EE_Error
226
+	 */
227
+	public function load_espresso_addons()
228
+	{
229
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
230
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
231
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
232
+		//caps need to be initialized on every request so that capability maps are set.
233
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
234
+		$this->capabilities->init_caps();
235
+		do_action('AHEE__EE_System__load_espresso_addons');
236
+		//if the WP API basic auth plugin isn't already loaded, load it now.
237
+		//We want it for mobile apps. Just include the entire plugin
238
+		//also, don't load the basic auth when a plugin is getting activated, because
239
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
240
+		//and causes a fatal error
241
+		if (
242
+			! (
243
+				isset($_GET['activate'])
244
+				&& $_GET['activate'] === 'true'
245
+			)
246
+			&& ! function_exists('json_basic_auth_handler')
247
+			&& ! function_exists('json_basic_auth_error')
248
+			&& ! (
249
+				isset($_GET['action'])
250
+				&& in_array($_GET['action'], array('activate', 'activate-selected'), true)
251
+			)
252
+		) {
253
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
254
+		}
255
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * detect_activations_or_upgrades
262
+	 * Checks for activation or upgrade of core first;
263
+	 * then also checks if any registered addons have been activated or upgraded
264
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
265
+	 * which runs during the WP 'plugins_loaded' action at priority 3
266
+	 *
267
+	 * @access public
268
+	 * @return void
269
+	 */
270
+	public function detect_activations_or_upgrades()
271
+	{
272
+		//first off: let's make sure to handle core
273
+		$this->detect_if_activation_or_upgrade();
274
+		foreach ($this->registry->addons as $addon) {
275
+			if ($addon instanceof EE_Addon) {
276
+				//detect teh request type for that addon
277
+				$addon->detect_activation_or_upgrade();
278
+			}
279
+		}
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * detect_if_activation_or_upgrade
286
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
287
+	 * and either setting up the DB or setting up maintenance mode etc.
288
+	 *
289
+	 * @access public
290
+	 * @return void
291
+	 */
292
+	public function detect_if_activation_or_upgrade()
293
+	{
294
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
295
+		// check if db has been updated, or if its a brand-new installation
296
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
297
+		$request_type = $this->detect_req_type($espresso_db_update);
298
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
299
+		switch ($request_type) {
300
+			case EE_System::req_type_new_activation:
301
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
302
+				$this->_handle_core_version_change($espresso_db_update);
303
+				break;
304
+			case EE_System::req_type_reactivation:
305
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
306
+				$this->_handle_core_version_change($espresso_db_update);
307
+				break;
308
+			case EE_System::req_type_upgrade:
309
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
310
+				//migrations may be required now that we've upgraded
311
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
312
+				$this->_handle_core_version_change($espresso_db_update);
313
+				//				echo "done upgrade";die;
314
+				break;
315
+			case EE_System::req_type_downgrade:
316
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
317
+				//its possible migrations are no longer required
318
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
319
+				$this->_handle_core_version_change($espresso_db_update);
320
+				break;
321
+			case EE_System::req_type_normal:
322
+			default:
323
+				//				$this->_maybe_redirect_to_ee_about();
324
+				break;
325
+		}
326
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 * Updates the list of installed versions and sets hooks for
333
+	 * initializing the database later during the request
334
+	 *
335
+	 * @param array $espresso_db_update
336
+	 */
337
+	private function _handle_core_version_change($espresso_db_update)
338
+	{
339
+		$this->update_list_of_installed_versions($espresso_db_update);
340
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
341
+		add_action(
342
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
343
+			array($this, 'initialize_db_if_no_migrations_required')
344
+		);
345
+	}
346
+
347
+
348
+
349
+	/**
350
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
351
+	 * information about what versions of EE have been installed and activated,
352
+	 * NOT necessarily the state of the database
353
+	 *
354
+	 * @param mixed $espresso_db_update the value of the WordPress option.
355
+	 *                                            If not supplied, fetches it from the options table
356
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
357
+	 */
358
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359
+	{
360
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
+		if (! $espresso_db_update) {
362
+			$espresso_db_update = get_option('espresso_db_update');
363
+		}
364
+		// check that option is an array
365
+		if (! is_array($espresso_db_update)) {
366
+			// if option is FALSE, then it never existed
367
+			if ($espresso_db_update === false) {
368
+				// make $espresso_db_update an array and save option with autoload OFF
369
+				$espresso_db_update = array();
370
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
371
+			} else {
372
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
373
+				$espresso_db_update = array($espresso_db_update => array());
374
+				update_option('espresso_db_update', $espresso_db_update);
375
+			}
376
+		} else {
377
+			$corrected_db_update = array();
378
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
379
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
380
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
381
+					//the key is an int, and the value IS NOT an array
382
+					//so it must be numerically-indexed, where values are versions installed...
383
+					//fix it!
384
+					$version_string = $should_be_array;
385
+					$corrected_db_update[$version_string] = array('unknown-date');
386
+				} else {
387
+					//ok it checks out
388
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
389
+				}
390
+			}
391
+			$espresso_db_update = $corrected_db_update;
392
+			update_option('espresso_db_update', $espresso_db_update);
393
+		}
394
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
395
+		return $espresso_db_update;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Does the traditional work of setting up the plugin's database and adding default data.
402
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
403
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
404
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
405
+	 * so that it will be done when migrations are finished
406
+	 *
407
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
408
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
409
+	 *                                       This is a resource-intensive job
410
+	 *                                       so we prefer to only do it when necessary
411
+	 * @return void
412
+	 * @throws EE_Error
413
+	 */
414
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
415
+	{
416
+		$request_type = $this->detect_req_type();
417
+		//only initialize system if we're not in maintenance mode.
418
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
419
+			update_option('ee_flush_rewrite_rules', true);
420
+			if ($verify_schema) {
421
+				EEH_Activation::initialize_db_and_folders();
422
+			}
423
+			EEH_Activation::initialize_db_content();
424
+			EEH_Activation::system_initialization();
425
+			if ($initialize_addons_too) {
426
+				$this->initialize_addons();
427
+			}
428
+		} else {
429
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
430
+		}
431
+		if ($request_type === EE_System::req_type_new_activation
432
+			|| $request_type === EE_System::req_type_reactivation
433
+			|| (
434
+				$request_type === EE_System::req_type_upgrade
435
+				&& $this->is_major_version_change()
436
+			)
437
+		) {
438
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
439
+		}
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * Initializes the db for all registered addons
446
+	 *
447
+	 * @throws EE_Error
448
+	 */
449
+	public function initialize_addons()
450
+	{
451
+		//foreach registered addon, make sure its db is up-to-date too
452
+		foreach ($this->registry->addons as $addon) {
453
+			if ($addon instanceof EE_Addon) {
454
+				$addon->initialize_db_if_no_migrations_required();
455
+			}
456
+		}
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
463
+	 *
464
+	 * @param    array  $version_history
465
+	 * @param    string $current_version_to_add version to be added to the version history
466
+	 * @return    boolean success as to whether or not this option was changed
467
+	 */
468
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469
+	{
470
+		if (! $version_history) {
471
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
472
+		}
473
+		if ($current_version_to_add === null) {
474
+			$current_version_to_add = espresso_version();
475
+		}
476
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
477
+		// re-save
478
+		return update_option('espresso_db_update', $version_history);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * Detects if the current version indicated in the has existed in the list of
485
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
486
+	 *
487
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
488
+	 *                                  If not supplied, fetches it from the options table.
489
+	 *                                  Also, caches its result so later parts of the code can also know whether
490
+	 *                                  there's been an update or not. This way we can add the current version to
491
+	 *                                  espresso_db_update, but still know if this is a new install or not
492
+	 * @return int one of the constants on EE_System::req_type_
493
+	 */
494
+	public function detect_req_type($espresso_db_update = null)
495
+	{
496
+		if ($this->_req_type === null) {
497
+			$espresso_db_update = ! empty($espresso_db_update)
498
+				? $espresso_db_update
499
+				: $this->fix_espresso_db_upgrade_option();
500
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
501
+				$espresso_db_update,
502
+				'ee_espresso_activation', espresso_version()
503
+			);
504
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
505
+		}
506
+		return $this->_req_type;
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * Returns whether or not there was a non-micro version change (ie, change in either
513
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
514
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
515
+	 *
516
+	 * @param $activation_history
517
+	 * @return bool
518
+	 */
519
+	private function _detect_major_version_change($activation_history)
520
+	{
521
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
522
+		$previous_version_parts = explode('.', $previous_version);
523
+		$current_version_parts = explode('.', espresso_version());
524
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
525
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
526
+				   || $previous_version_parts[1] !== $current_version_parts[1]
527
+			   );
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 * Returns true if either the major or minor version of EE changed during this request.
534
+	 * 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
535
+	 *
536
+	 * @return bool
537
+	 */
538
+	public function is_major_version_change()
539
+	{
540
+		return $this->_major_version_change;
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
547
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
548
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
549
+	 * just activated to (for core that will always be espresso_version())
550
+	 *
551
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
552
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
553
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
554
+	 *                                                 indicate that this plugin was just activated
555
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
556
+	 *                                                 espresso_version())
557
+	 * @return int one of the constants on EE_System::req_type_*
558
+	 */
559
+	public static function detect_req_type_given_activation_history(
560
+		$activation_history_for_addon,
561
+		$activation_indicator_option_name,
562
+		$version_to_upgrade_to
563
+	) {
564
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
565
+		if ($activation_history_for_addon) {
566
+			//it exists, so this isn't a completely new install
567
+			//check if this version already in that list of previously installed versions
568
+			if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569
+				//it a version we haven't seen before
570
+				if ($version_is_higher === 1) {
571
+					$req_type = EE_System::req_type_upgrade;
572
+				} else {
573
+					$req_type = EE_System::req_type_downgrade;
574
+				}
575
+				delete_option($activation_indicator_option_name);
576
+			} else {
577
+				// its not an update. maybe a reactivation?
578
+				if (get_option($activation_indicator_option_name, false)) {
579
+					if ($version_is_higher === -1) {
580
+						$req_type = EE_System::req_type_downgrade;
581
+					} else if ($version_is_higher === 0) {
582
+						//we've seen this version before, but it's an activation. must be a reactivation
583
+						$req_type = EE_System::req_type_reactivation;
584
+					} else {//$version_is_higher === 1
585
+						$req_type = EE_System::req_type_upgrade;
586
+					}
587
+					delete_option($activation_indicator_option_name);
588
+				} else {
589
+					//we've seen this version before and the activation indicate doesn't show it was just activated
590
+					if ($version_is_higher === -1) {
591
+						$req_type = EE_System::req_type_downgrade;
592
+					} else if ($version_is_higher === 0) {
593
+						//we've seen this version before and it's not an activation. its normal request
594
+						$req_type = EE_System::req_type_normal;
595
+					} else {//$version_is_higher === 1
596
+						$req_type = EE_System::req_type_upgrade;
597
+					}
598
+				}
599
+			}
600
+		} else {
601
+			//brand new install
602
+			$req_type = EE_System::req_type_new_activation;
603
+			delete_option($activation_indicator_option_name);
604
+		}
605
+		return $req_type;
606
+	}
607
+
608
+
609
+
610
+	/**
611
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
612
+	 * the $activation_history_for_addon
613
+	 *
614
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
615
+	 *                                             sometimes containing 'unknown-date'
616
+	 * @param string $version_to_upgrade_to        (current version)
617
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
618
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
619
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
620
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
621
+	 */
622
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
623
+	{
624
+		//find the most recently-activated version
625
+		$most_recently_active_version =
626
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
627
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * Gets the most recently active version listed in the activation history,
634
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
635
+	 *
636
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
637
+	 *                                   sometimes containing 'unknown-date'
638
+	 * @return string
639
+	 */
640
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
641
+	{
642
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
643
+		$most_recently_active_version = '0.0.0.dev.000';
644
+		if (is_array($activation_history)) {
645
+			foreach ($activation_history as $version => $times_activated) {
646
+				//check there is a record of when this version was activated. Otherwise,
647
+				//mark it as unknown
648
+				if (! $times_activated) {
649
+					$times_activated = array('unknown-date');
650
+				}
651
+				if (is_string($times_activated)) {
652
+					$times_activated = array($times_activated);
653
+				}
654
+				foreach ($times_activated as $an_activation) {
655
+					if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
656
+						$most_recently_active_version = $version;
657
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
658
+							? '1970-01-01 00:00:00'
659
+							: $an_activation;
660
+					}
661
+				}
662
+			}
663
+		}
664
+		return $most_recently_active_version;
665
+	}
666
+
667
+
668
+
669
+	/**
670
+	 * This redirects to the about EE page after activation
671
+	 *
672
+	 * @return void
673
+	 */
674
+	public function redirect_to_about_ee()
675
+	{
676
+		$notices = EE_Error::get_notices(false);
677
+		//if current user is an admin and it's not an ajax or rest request
678
+		if (
679
+			! (defined('DOING_AJAX') && DOING_AJAX)
680
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
681
+			&& ! isset($notices['errors'])
682
+			&& apply_filters(
683
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
684
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
685
+			)
686
+		) {
687
+			$query_params = array('page' => 'espresso_about');
688
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
689
+				$query_params['new_activation'] = true;
690
+			}
691
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
692
+				$query_params['reactivation'] = true;
693
+			}
694
+			$url = add_query_arg($query_params, admin_url('admin.php'));
695
+			wp_safe_redirect($url);
696
+			exit();
697
+		}
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * load_core_configuration
704
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
705
+	 * which runs during the WP 'plugins_loaded' action at priority 5
706
+	 *
707
+	 * @return void
708
+	 * @throws ReflectionException
709
+	 */
710
+	public function load_core_configuration()
711
+	{
712
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
713
+		$this->loader->getShared('EE_Load_Textdomain');
714
+		//load textdomain
715
+		EE_Load_Textdomain::load_textdomain();
716
+		// load and setup EE_Config and EE_Network_Config
717
+		$config = $this->loader->getShared('EE_Config');
718
+		$this->loader->getShared('EE_Network_Config');
719
+		// setup autoloaders
720
+		// enable logging?
721
+		if ($config->admin->use_full_logging) {
722
+			$this->loader->getShared('EE_Log');
723
+		}
724
+		// check for activation errors
725
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
726
+		if ($activation_errors) {
727
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
728
+			update_option('ee_plugin_activation_errors', false);
729
+		}
730
+		// get model names
731
+		$this->_parse_model_names();
732
+		//load caf stuff a chance to play during the activation process too.
733
+		$this->_maybe_brew_regular();
734
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
735
+	}
736
+
737
+
738
+
739
+	/**
740
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
741
+	 *
742
+	 * @return void
743
+	 * @throws ReflectionException
744
+	 */
745
+	private function _parse_model_names()
746
+	{
747
+		//get all the files in the EE_MODELS folder that end in .model.php
748
+		$models = glob(EE_MODELS . '*.model.php');
749
+		$model_names = array();
750
+		$non_abstract_db_models = array();
751
+		foreach ($models as $model) {
752
+			// get model classname
753
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
754
+			$short_name = str_replace('EEM_', '', $classname);
755
+			$reflectionClass = new ReflectionClass($classname);
756
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
757
+				$non_abstract_db_models[$short_name] = $classname;
758
+			}
759
+			$model_names[$short_name] = $classname;
760
+		}
761
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
762
+		$this->registry->non_abstract_db_models = apply_filters(
763
+			'FHEE__EE_System__parse_implemented_model_names',
764
+			$non_abstract_db_models
765
+		);
766
+	}
767
+
768
+
769
+
770
+	/**
771
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
772
+	 * that need to be setup before our EE_System launches.
773
+	 *
774
+	 * @return void
775
+	 */
776
+	private function _maybe_brew_regular()
777
+	{
778
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
779
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
780
+		}
781
+	}
782
+
783
+
784
+
785
+	/**
786
+	 * register_shortcodes_modules_and_widgets
787
+	 * generate lists of shortcodes and modules, then verify paths and classes
788
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
789
+	 * which runs during the WP 'plugins_loaded' action at priority 7
790
+	 *
791
+	 * @access public
792
+	 * @return void
793
+	 * @throws Exception
794
+	 */
795
+	public function register_shortcodes_modules_and_widgets()
796
+	{
797
+		try {
798
+			// load, register, and add shortcodes the new way
799
+			new ShortcodesManager(
800
+			// and the old way, but we'll put it under control of the new system
801
+				EE_Config::getLegacyShortcodesManager()
802
+			);
803
+		} catch (Exception $exception) {
804
+			new ExceptionStackTraceDisplay($exception);
805
+		}
806
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
807
+		// check for addons using old hook point
808
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
809
+			$this->_incompatible_addon_error();
810
+		}
811
+	}
812
+
813
+
814
+
815
+	/**
816
+	 * _incompatible_addon_error
817
+	 *
818
+	 * @access public
819
+	 * @return void
820
+	 */
821
+	private function _incompatible_addon_error()
822
+	{
823
+		// get array of classes hooking into here
824
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
825
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
826
+		);
827
+		if (! empty($class_names)) {
828
+			$msg = __(
829
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
830
+				'event_espresso'
831
+			);
832
+			$msg .= '<ul>';
833
+			foreach ($class_names as $class_name) {
834
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
835
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
836
+						$class_name
837
+					) . '</b></li>';
838
+			}
839
+			$msg .= '</ul>';
840
+			$msg .= __(
841
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
842
+				'event_espresso'
843
+			);
844
+			// save list of incompatible addons to wp-options for later use
845
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
846
+			if (is_admin()) {
847
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
848
+			}
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 * brew_espresso
856
+	 * begins the process of setting hooks for initializing EE in the correct order
857
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
858
+	 * which runs during the WP 'plugins_loaded' action at priority 9
859
+	 *
860
+	 * @return void
861
+	 */
862
+	public function brew_espresso()
863
+	{
864
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
865
+		// load some final core systems
866
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
867
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
868
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
869
+		add_action('init', array($this, 'load_controllers'), 7);
870
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
871
+		add_action('init', array($this, 'initialize'), 10);
872
+		add_action('init', array($this, 'initialize_last'), 100);
873
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
874
+			// pew pew pew
875
+			$this->loader->getShared('EE_PUE');
876
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
877
+		}
878
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 *    set_hooks_for_core
885
+	 *
886
+	 * @access public
887
+	 * @return    void
888
+	 */
889
+	public function set_hooks_for_core()
890
+	{
891
+		$this->_deactivate_incompatible_addons();
892
+		do_action('AHEE__EE_System__set_hooks_for_core');
893
+	}
894
+
895
+
896
+
897
+	/**
898
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
899
+	 * deactivates any addons considered incompatible with the current version of EE
900
+	 */
901
+	private function _deactivate_incompatible_addons()
902
+	{
903
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
904
+		if (! empty($incompatible_addons)) {
905
+			$active_plugins = get_option('active_plugins', array());
906
+			foreach ($active_plugins as $active_plugin) {
907
+				foreach ($incompatible_addons as $incompatible_addon) {
908
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
909
+						unset($_GET['activate']);
910
+						espresso_deactivate_plugin($active_plugin);
911
+					}
912
+				}
913
+			}
914
+		}
915
+	}
916
+
917
+
918
+
919
+	/**
920
+	 *    perform_activations_upgrades_and_migrations
921
+	 *
922
+	 * @access public
923
+	 * @return    void
924
+	 */
925
+	public function perform_activations_upgrades_and_migrations()
926
+	{
927
+		//first check if we had previously attempted to setup EE's directories but failed
928
+		if (EEH_Activation::upload_directories_incomplete()) {
929
+			EEH_Activation::create_upload_directories();
930
+		}
931
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 *    load_CPTs_and_session
938
+	 *
939
+	 * @access public
940
+	 * @return    void
941
+	 */
942
+	public function load_CPTs_and_session()
943
+	{
944
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
945
+		// register Custom Post Types
946
+		$this->loader->getShared('EE_Register_CPTs');
947
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
948
+	}
949
+
950
+
951
+
952
+	/**
953
+	 * load_controllers
954
+	 * this is the best place to load any additional controllers that needs access to EE core.
955
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
956
+	 * time
957
+	 *
958
+	 * @access public
959
+	 * @return void
960
+	 */
961
+	public function load_controllers()
962
+	{
963
+		do_action('AHEE__EE_System__load_controllers__start');
964
+		// let's get it started
965
+		if (! is_admin() && ! $this->maintenance_mode->level()) {
966
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
967
+			$this->loader->getShared('EE_Front_Controller');
968
+		} else if (! EE_FRONT_AJAX) {
969
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
970
+			$this->loader->getShared('EE_Admin');
971
+		}
972
+		do_action('AHEE__EE_System__load_controllers__complete');
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * core_loaded_and_ready
979
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
980
+	 *
981
+	 * @access public
982
+	 * @return void
983
+	 */
984
+	public function core_loaded_and_ready()
985
+	{
986
+		$this->loader->getShared('EE_Session');
987
+		do_action('AHEE__EE_System__core_loaded_and_ready');
988
+		// load_espresso_template_tags
989
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
990
+			require_once(EE_PUBLIC . 'template_tags.php');
991
+		}
992
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
993
+		$this->loader->getShared('EventEspresso\core\services\assets\Registry');
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 * initialize
1000
+	 * this is the best place to begin initializing client code
1001
+	 *
1002
+	 * @access public
1003
+	 * @return void
1004
+	 */
1005
+	public function initialize()
1006
+	{
1007
+		do_action('AHEE__EE_System__initialize');
1008
+	}
1009
+
1010
+
1011
+
1012
+	/**
1013
+	 * initialize_last
1014
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1015
+	 * initialize has done so
1016
+	 *
1017
+	 * @access public
1018
+	 * @return void
1019
+	 */
1020
+	public function initialize_last()
1021
+	{
1022
+		do_action('AHEE__EE_System__initialize_last');
1023
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 * @return void
1030
+	 * @throws EE_Error
1031
+	 */
1032
+	public function addEspressoToolbar()
1033
+	{
1034
+		$this->registry->create(
1035
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1036
+			array($this->registry->CAP)
1037
+		);
1038
+	}
1039
+
1040
+
1041
+
1042
+	/**
1043
+	 * do_not_cache
1044
+	 * sets no cache headers and defines no cache constants for WP plugins
1045
+	 *
1046
+	 * @access public
1047
+	 * @return void
1048
+	 */
1049
+	public static function do_not_cache()
1050
+	{
1051
+		// set no cache constants
1052
+		if (! defined('DONOTCACHEPAGE')) {
1053
+			define('DONOTCACHEPAGE', true);
1054
+		}
1055
+		if (! defined('DONOTCACHCEOBJECT')) {
1056
+			define('DONOTCACHCEOBJECT', true);
1057
+		}
1058
+		if (! defined('DONOTCACHEDB')) {
1059
+			define('DONOTCACHEDB', true);
1060
+		}
1061
+		// add no cache headers
1062
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1063
+		// plus a little extra for nginx and Google Chrome
1064
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1065
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1066
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1067
+	}
1068
+
1069
+
1070
+
1071
+	/**
1072
+	 *    extra_nocache_headers
1073
+	 *
1074
+	 * @access    public
1075
+	 * @param $headers
1076
+	 * @return    array
1077
+	 */
1078
+	public static function extra_nocache_headers($headers)
1079
+	{
1080
+		// for NGINX
1081
+		$headers['X-Accel-Expires'] = 0;
1082
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1083
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1084
+		return $headers;
1085
+	}
1086
+
1087
+
1088
+
1089
+	/**
1090
+	 *    nocache_headers
1091
+	 *
1092
+	 * @access    public
1093
+	 * @return    void
1094
+	 */
1095
+	public static function nocache_headers()
1096
+	{
1097
+		nocache_headers();
1098
+	}
1099
+
1100
+
1101
+
1102
+
1103
+	/**
1104
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1105
+	 * never returned with the function.
1106
+	 *
1107
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1108
+	 * @return array
1109
+	 */
1110
+	public function remove_pages_from_wp_list_pages($exclude_array)
1111
+	{
1112
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1113
+	}
1114 1114
 
1115 1115
 
1116 1116
 
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         EE_Maintenance_Mode $maintenance_mode = null
133 133
     ) {
134 134
         // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
135
+        if ( ! self::$_instance instanceof EE_System) {
136 136
             self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137 137
         }
138 138
         return self::$_instance;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     {
229 229
         // set autoloaders for all of the classes implementing EEI_Plugin_API
230 230
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
231
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
231
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
232 232
         //caps need to be initialized on every request so that capability maps are set.
233 233
         //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
234 234
         $this->capabilities->init_caps();
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                 && in_array($_GET['action'], array('activate', 'activate-selected'), true)
251 251
             )
252 252
         ) {
253
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
253
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
254 254
         }
255 255
         do_action('AHEE__EE_System__load_espresso_addons__complete');
256 256
     }
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359 359
     {
360 360
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
-        if (! $espresso_db_update) {
361
+        if ( ! $espresso_db_update) {
362 362
             $espresso_db_update = get_option('espresso_db_update');
363 363
         }
364 364
         // check that option is an array
365
-        if (! is_array($espresso_db_update)) {
365
+        if ( ! is_array($espresso_db_update)) {
366 366
             // if option is FALSE, then it never existed
367 367
             if ($espresso_db_update === false) {
368 368
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469 469
     {
470
-        if (! $version_history) {
470
+        if ( ! $version_history) {
471 471
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
472 472
         }
473 473
         if ($current_version_to_add === null) {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         if ($activation_history_for_addon) {
566 566
             //it exists, so this isn't a completely new install
567 567
             //check if this version already in that list of previously installed versions
568
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
568
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569 569
                 //it a version we haven't seen before
570 570
                 if ($version_is_higher === 1) {
571 571
                     $req_type = EE_System::req_type_upgrade;
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
             foreach ($activation_history as $version => $times_activated) {
646 646
                 //check there is a record of when this version was activated. Otherwise,
647 647
                 //mark it as unknown
648
-                if (! $times_activated) {
648
+                if ( ! $times_activated) {
649 649
                     $times_activated = array('unknown-date');
650 650
                 }
651 651
                 if (is_string($times_activated)) {
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
     private function _parse_model_names()
746 746
     {
747 747
         //get all the files in the EE_MODELS folder that end in .model.php
748
-        $models = glob(EE_MODELS . '*.model.php');
748
+        $models = glob(EE_MODELS.'*.model.php');
749 749
         $model_names = array();
750 750
         $non_abstract_db_models = array();
751 751
         foreach ($models as $model) {
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
      */
776 776
     private function _maybe_brew_regular()
777 777
     {
778
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
779
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
778
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
779
+            require_once EE_CAFF_PATH.'brewing_regular.php';
780 780
         }
781 781
     }
782 782
 
@@ -824,17 +824,17 @@  discard block
 block discarded – undo
824 824
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
825 825
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
826 826
         );
827
-        if (! empty($class_names)) {
827
+        if ( ! empty($class_names)) {
828 828
             $msg = __(
829 829
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
830 830
                 'event_espresso'
831 831
             );
832 832
             $msg .= '<ul>';
833 833
             foreach ($class_names as $class_name) {
834
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
834
+                $msg .= '<li><b>Event Espresso - '.str_replace(
835 835
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
836 836
                         $class_name
837
-                    ) . '</b></li>';
837
+                    ).'</b></li>';
838 838
             }
839 839
             $msg .= '</ul>';
840 840
             $msg .= __(
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
     private function _deactivate_incompatible_addons()
902 902
     {
903 903
         $incompatible_addons = get_option('ee_incompatible_addons', array());
904
-        if (! empty($incompatible_addons)) {
904
+        if ( ! empty($incompatible_addons)) {
905 905
             $active_plugins = get_option('active_plugins', array());
906 906
             foreach ($active_plugins as $active_plugin) {
907 907
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -962,10 +962,10 @@  discard block
 block discarded – undo
962 962
     {
963 963
         do_action('AHEE__EE_System__load_controllers__start');
964 964
         // let's get it started
965
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
965
+        if ( ! is_admin() && ! $this->maintenance_mode->level()) {
966 966
             do_action('AHEE__EE_System__load_controllers__load_front_controllers');
967 967
             $this->loader->getShared('EE_Front_Controller');
968
-        } else if (! EE_FRONT_AJAX) {
968
+        } else if ( ! EE_FRONT_AJAX) {
969 969
             do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
970 970
             $this->loader->getShared('EE_Admin');
971 971
         }
@@ -986,8 +986,8 @@  discard block
 block discarded – undo
986 986
         $this->loader->getShared('EE_Session');
987 987
         do_action('AHEE__EE_System__core_loaded_and_ready');
988 988
         // load_espresso_template_tags
989
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
990
-            require_once(EE_PUBLIC . 'template_tags.php');
989
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
990
+            require_once(EE_PUBLIC.'template_tags.php');
991 991
         }
992 992
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
993 993
         $this->loader->getShared('EventEspresso\core\services\assets\Registry');
@@ -1049,13 +1049,13 @@  discard block
 block discarded – undo
1049 1049
     public static function do_not_cache()
1050 1050
     {
1051 1051
         // set no cache constants
1052
-        if (! defined('DONOTCACHEPAGE')) {
1052
+        if ( ! defined('DONOTCACHEPAGE')) {
1053 1053
             define('DONOTCACHEPAGE', true);
1054 1054
         }
1055
-        if (! defined('DONOTCACHCEOBJECT')) {
1055
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1056 1056
             define('DONOTCACHCEOBJECT', true);
1057 1057
         }
1058
-        if (! defined('DONOTCACHEDB')) {
1058
+        if ( ! defined('DONOTCACHEDB')) {
1059 1059
             define('DONOTCACHEDB', true);
1060 1060
         }
1061 1061
         // add no cache headers
Please login to merge, or discard this patch.