Completed
Branch FET-10416-autoload-b4-bootstra... (42a01c)
by
unknown
13:17
created
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -18,122 +18,122 @@
 block discarded – undo
18 18
 class EE_Register_Payment_Method implements EEI_Plugin_API
19 19
 {
20 20
 
21
-    /**
22
-     * Holds values for registered payment methods
23
-     *
24
-     * @var array
25
-     */
26
-    protected static $_settings = array();
21
+	/**
22
+	 * Holds values for registered payment methods
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected static $_settings = array();
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * Method for registering new EE_PMT_Base children
32
-     *
33
-     * @since    4.5.0
34
-     * @param string  $payment_method_id    a unique identifier for this set of modules Required.
35
-     * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
36
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
37
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
38
-     *                                      the files EE_PMT_Payomatic.pm.php)
39
-     *                                      }
40
-     * @throws EE_Error
41
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
-     *       children, or to the EED_Module files themselves
43
-     * @return void
44
-     */
45
-    public static function register($payment_method_id = null, $setup_args = array())
46
-    {
47
-        //required fields MUST be present, so let's make sure they are.
48
-        if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
49
-            throw new EE_Error(
50
-                esc_html__(
51
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
52
-                    'event_espresso'
53
-                )
54
-            );
55
-        }
56
-        //make sure we don't register twice
57
-        if (isset(self::$_settings[$payment_method_id])) {
58
-            return;
59
-        }
60
-        //make sure this was called in the right place!
61
-        if (
62
-            ! did_action('AHEE__EE_System__load_espresso_addons')
63
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
64
-        ) {
65
-            EE_Error::doing_it_wrong(
66
-                __METHOD__,
67
-                esc_html__(
68
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
69
-                    'event_espresso'
70
-                ),
71
-                '4.3.0'
72
-            );
73
-        }
74
-        //setup $_settings array from incoming values.
75
-        self::$_settings[$payment_method_id] = array(
76
-            // array of full server paths to any EE_PMT_Base children used
77
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
78
-                ? (array)$setup_args['payment_method_paths']
79
-                : array(),
80
-        );
81
-        // add to list of modules to be registered
82
-        add_filter(
83
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
84
-            array('EE_Register_Payment_Method', 'add_payment_methods')
85
-        );
86
-        /**
87
-         * If EE_Payment_Method_Manager::register_payment_methods has already been called,
88
-         * we need it to be called again (because it's missing the payment method we JUST registered here).
89
-         * We are assuming EE_Register_payment_method::register() will be called only once
90
-         * per payment method from an addon, so going with that assumption we should always do this.
91
-         * If that assumption is false, we should verify this newly-registered payment method
92
-         * isn't on the EE_Payment_Method_Manager::_payment_method_types array before calling this
93
-         * (this code should be changed to improve performance)
94
-         */
95
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
96
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
97
-            EE_Payment_Method_Manager::instance()->maybe_register_payment_methods(true);
98
-        }
99
-    }
30
+	/**
31
+	 * Method for registering new EE_PMT_Base children
32
+	 *
33
+	 * @since    4.5.0
34
+	 * @param string  $payment_method_id    a unique identifier for this set of modules Required.
35
+	 * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
36
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
37
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
38
+	 *                                      the files EE_PMT_Payomatic.pm.php)
39
+	 *                                      }
40
+	 * @throws EE_Error
41
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
+	 *       children, or to the EED_Module files themselves
43
+	 * @return void
44
+	 */
45
+	public static function register($payment_method_id = null, $setup_args = array())
46
+	{
47
+		//required fields MUST be present, so let's make sure they are.
48
+		if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
49
+			throw new EE_Error(
50
+				esc_html__(
51
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
52
+					'event_espresso'
53
+				)
54
+			);
55
+		}
56
+		//make sure we don't register twice
57
+		if (isset(self::$_settings[$payment_method_id])) {
58
+			return;
59
+		}
60
+		//make sure this was called in the right place!
61
+		if (
62
+			! did_action('AHEE__EE_System__load_espresso_addons')
63
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
64
+		) {
65
+			EE_Error::doing_it_wrong(
66
+				__METHOD__,
67
+				esc_html__(
68
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
69
+					'event_espresso'
70
+				),
71
+				'4.3.0'
72
+			);
73
+		}
74
+		//setup $_settings array from incoming values.
75
+		self::$_settings[$payment_method_id] = array(
76
+			// array of full server paths to any EE_PMT_Base children used
77
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
78
+				? (array)$setup_args['payment_method_paths']
79
+				: array(),
80
+		);
81
+		// add to list of modules to be registered
82
+		add_filter(
83
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
84
+			array('EE_Register_Payment_Method', 'add_payment_methods')
85
+		);
86
+		/**
87
+		 * If EE_Payment_Method_Manager::register_payment_methods has already been called,
88
+		 * we need it to be called again (because it's missing the payment method we JUST registered here).
89
+		 * We are assuming EE_Register_payment_method::register() will be called only once
90
+		 * per payment method from an addon, so going with that assumption we should always do this.
91
+		 * If that assumption is false, we should verify this newly-registered payment method
92
+		 * isn't on the EE_Payment_Method_Manager::_payment_method_types array before calling this
93
+		 * (this code should be changed to improve performance)
94
+		 */
95
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
96
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
97
+			EE_Payment_Method_Manager::instance()->maybe_register_payment_methods(true);
98
+		}
99
+	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * Filters the list of payment methods to add ours.
105
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
106
-     *
107
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
108
-     * @return array
109
-     */
110
-    public static function add_payment_methods($payment_method_folders)
111
-    {
112
-        foreach (self::$_settings as $settings) {
113
-            $payment_method_folders = array_merge(
114
-                $payment_method_folders,
115
-                $settings['payment_method_paths']
116
-            );
117
-        }
118
-        return $payment_method_folders;
119
-    }
103
+	/**
104
+	 * Filters the list of payment methods to add ours.
105
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
106
+	 *
107
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
108
+	 * @return array
109
+	 */
110
+	public static function add_payment_methods($payment_method_folders)
111
+	{
112
+		foreach (self::$_settings as $settings) {
113
+			$payment_method_folders = array_merge(
114
+				$payment_method_folders,
115
+				$settings['payment_method_paths']
116
+			);
117
+		}
118
+		return $payment_method_folders;
119
+	}
120 120
 
121 121
 
122 122
 
123
-    /**
124
-     * This deregisters a module that was previously registered with a specific $module_id.
125
-     *
126
-     * @since    4.3.0
127
-     *
128
-     * @param string $module_id the name for the module that was previously registered
129
-     * @return void
130
-     */
131
-    public static function deregister($module_id = null)
132
-    {
133
-        if (isset(self::$_settings[$module_id])) {
134
-            unset(self::$_settings[$module_id]);
135
-        }
136
-    }
123
+	/**
124
+	 * This deregisters a module that was previously registered with a specific $module_id.
125
+	 *
126
+	 * @since    4.3.0
127
+	 *
128
+	 * @param string $module_id the name for the module that was previously registered
129
+	 * @return void
130
+	 */
131
+	public static function deregister($module_id = null)
132
+	{
133
+		if (isset(self::$_settings[$module_id])) {
134
+			unset(self::$_settings[$module_id]);
135
+		}
136
+	}
137 137
 
138 138
 }
139 139
 // End of file EE_Register_Payment_Method.lib.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
         self::$_settings[$payment_method_id] = array(
76 76
             // array of full server paths to any EE_PMT_Base children used
77 77
             'payment_method_paths' => isset($setup_args['payment_method_paths'])
78
-                ? (array)$setup_args['payment_method_paths']
78
+                ? (array) $setup_args['payment_method_paths']
79 79
                 : array(),
80 80
         );
81 81
         // add to list of modules to be registered
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Indentation   +419 added lines, -419 removed lines patch added patch discarded remove patch
@@ -17,420 +17,420 @@  discard block
 block discarded – undo
17 17
 class EE_Payment_Method_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Payment_Method_Manager $_instance
22
-     */
23
-    private static $_instance;
24
-
25
-    /**
26
-     * @var array keys are class names without 'EE_PMT_', values are their filepaths
27
-     */
28
-    protected $_payment_method_types = array();
29
-
30
-
31
-
32
-    /**
33
-     * @singleton method used to instantiate class object
34
-     * @return EE_Payment_Method_Manager instance
35
-     */
36
-    public static function instance()
37
-    {
38
-        // check if class object is instantiated, and instantiated properly
39
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
40
-            self::$_instance = new self();
41
-        }
42
-        EE_Registry::instance()->load_lib('PMT_Base');
43
-        return self::$_instance;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * Resets the instance and returns a new one
50
-     *
51
-     * @return EE_Payment_Method_Manager
52
-     */
53
-    public static function reset()
54
-    {
55
-        self::$_instance = null;
56
-        return self::instance();
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * If necessary, re-register payment methods
63
-     *
64
-     * @param boolean $force_recheck whether to recheck for payment method types,
65
-     *                               or just re-use the PMTs we found last time we checked during this request (if
66
-     *                               we have not yet checked during this request, then we need to check anyways)
67
-     */
68
-    public function maybe_register_payment_methods($force_recheck = false)
69
-    {
70
-        if (! $this->_payment_method_types || $force_recheck) {
71
-            $this->_register_payment_methods();
72
-            //if in admin lets ensure caps are set.
73
-            if (is_admin()) {
74
-                add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
75
-                EE_Registry::instance()->CAP->init_caps();
76
-            }
77
-        }
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * register_payment_methods
84
-     *
85
-     * @return array
86
-     */
87
-    protected function _register_payment_methods()
88
-    {
89
-        // grab list of installed modules
90
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
91
-        // filter list of modules to register
92
-        $pm_to_register = apply_filters(
93
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
94
-            $pm_to_register
95
-        );
96
-        // loop through folders
97
-        foreach ($pm_to_register as $pm_path) {
98
-            $this->register_payment_method($pm_path);
99
-        }
100
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
101
-        // filter list of installed modules
102
-        //keep them organized alphabetically by the payment method type's name
103
-        ksort($this->_payment_method_types);
104
-        return apply_filters(
105
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
106
-            $this->_payment_method_types
107
-        );
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * register_payment_method- makes core aware of this payment method
114
-     *
115
-     * @param string $payment_method_path - full path up to and including payment method folder
116
-     * @return boolean
117
-     */
118
-    public function register_payment_method($payment_method_path = '')
119
-    {
120
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
121
-        $module_ext = '.pm.php';
122
-        // make all separators match
123
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
124
-        // grab and sanitize module name
125
-        $module_dir = basename($payment_method_path);
126
-        // create classname from module directory name
127
-        $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
128
-        // add class prefix
129
-        $module_class = 'EE_PMT_' . $module;
130
-        // does the module exist ?
131
-        if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
132
-            $msg = sprintf(
133
-                esc_html__(
134
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
135
-                    'event_espresso'
136
-                ), $module
137
-            );
138
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
139
-            return false;
140
-        }
141
-        // load the module class file
142
-        require_once($payment_method_path . DS . $module_class . $module_ext);
143
-        // verify that class exists
144
-        if (! class_exists($module_class)) {
145
-            $msg = sprintf(
146
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
147
-                $module_class
148
-            );
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
-            return false;
151
-        }
152
-        // add to array of registered modules
153
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
-        return true;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * Checks if a payment method has been registered, and if so includes it
161
-     *
162
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie classname without the prefix 'EEPM_')
163
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
-     * @return boolean
165
-     */
166
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
-    {
168
-        if (
169
-            $force_recheck
170
-            || ! is_array($this->_payment_method_types)
171
-            || ! isset($this->_payment_method_types[$payment_method_name])
172
-        ) {
173
-            $this->maybe_register_payment_methods($force_recheck);
174
-        }
175
-        if (isset($this->_payment_method_types[$payment_method_name])) {
176
-            require_once($this->_payment_method_types[$payment_method_name]);
177
-            return true;
178
-        }
179
-        return false;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * Returns all the class names of the various payment method types
186
-     *
187
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
188
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
189
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
190
-     * @return array
191
-     */
192
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
193
-    {
194
-        $this->maybe_register_payment_methods($force_recheck);
195
-        if ($with_prefixes) {
196
-            $classnames = array_keys($this->_payment_method_types);
197
-            $payment_methods = array();
198
-            foreach ($classnames as $classname) {
199
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
200
-            }
201
-            return $payment_methods;
202
-        }
203
-        return array_keys($this->_payment_method_types);
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * Gets an object of each payment method type, none of which are bound to a
210
-     * payment method instance
211
-     *
212
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
213
-     * @return EE_PMT_Base[]
214
-     */
215
-    public function payment_method_types($force_recheck = false)
216
-    {
217
-        $this->maybe_register_payment_methods($force_recheck);
218
-        $payment_method_objects = array();
219
-        foreach ($this->payment_method_type_names(true) as $classname) {
220
-            $payment_method_objects[] = new $classname;
221
-        }
222
-        return $payment_method_objects;
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * Changes the payment method's classname into the payment method type's name
229
-     * (as used on the payment method's table's PMD_type field)
230
-     *
231
-     * @param string $classname
232
-     * @return string
233
-     */
234
-    public function payment_method_type_sans_class_prefix($classname)
235
-    {
236
-        return str_replace('EE_PMT_', '', $classname);
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * Does the opposite of payment-method_type_sans_prefix
243
-     *
244
-     * @param string $type
245
-     * @return string
246
-     */
247
-    public function payment_method_class_from_type($type)
248
-    {
249
-        $this->maybe_register_payment_methods();
250
-        return 'EE_PMT_' . $type;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * Activates a payment method of the given type.
257
-     *
258
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
259
-     * @return EE_Payment_Method
260
-     * @throws EE_Error
261
-     */
262
-    public function activate_a_payment_method_of_type($payment_method_type)
263
-    {
264
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
265
-        if (! $payment_method instanceof EE_Payment_Method) {
266
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
267
-            if (class_exists($pm_type_class)) {
268
-                /** @var $pm_type_obj EE_PMT_Base */
269
-                $pm_type_obj = new $pm_type_class;
270
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
271
-                if (! $payment_method) {
272
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
273
-                }
274
-                $payment_method->set_type($payment_method_type);
275
-                $this->initialize_payment_method($payment_method);
276
-            } else {
277
-                throw new EE_Error(
278
-                    sprintf(
279
-                        esc_html__(
280
-                            'There is no payment method of type %1$s, so it could not be activated',
281
-                            'event_espresso'
282
-                        ),
283
-                        $pm_type_class
284
-                    )
285
-                );
286
-            }
287
-        }
288
-        $payment_method->set_active();
289
-        $payment_method->save();
290
-        if ($payment_method->type() === 'Invoice') {
291
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
292
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
293
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
294
-            $message_resource_manager->ensure_messenger_is_active('pdf');
295
-            EE_Error::add_persistent_admin_notice(
296
-                'invoice_pm_requirements_notice',
297
-                sprintf(
298
-                    esc_html__(
299
-                        'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
300
-                        'event_espresso'
301
-                    ),
302
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
303
-                    '</a>'
304
-                ),
305
-                true
306
-            );
307
-        }
308
-        return $payment_method;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * Creates a payment method of the specified type. Does not save it.
315
-     *
316
-     * @global WP_User    $current_user
317
-     * @param EE_PMT_Base $pm_type_obj
318
-     * @return EE_Payment_Method
319
-     * @throws EE_Error
320
-     */
321
-    public function create_payment_method_of_type($pm_type_obj)
322
-    {
323
-        global $current_user;
324
-        $payment_method = EE_Payment_Method::new_instance(
325
-            array(
326
-                'PMD_type'       => $pm_type_obj->system_name(),
327
-                'PMD_name'       => $pm_type_obj->pretty_name(),
328
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
329
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
330
-                'PMD_wp_user'    => $current_user->ID,
331
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
332
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
333
-                    ) * 10,
334
-            )
335
-        );
336
-        return $payment_method;
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * Sets the initial payment method properties (including extra meta)
343
-     *
344
-     * @param EE_Payment_Method $payment_method
345
-     * @return EE_Payment_Method
346
-     * @throws EE_Error
347
-     */
348
-    public function initialize_payment_method($payment_method)
349
-    {
350
-        $pm_type_obj = $payment_method->type_obj();
351
-        $payment_method->set_description($pm_type_obj->default_description());
352
-        if (! $payment_method->button_url()) {
353
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
354
-        }
355
-        //now add setup its default extra meta properties
356
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
357
-        if (! empty($extra_metas)) {
358
-            //verify the payment method has an ID before adding extra meta
359
-            if (! $payment_method->ID()) {
360
-                $payment_method->save();
361
-            }
362
-            foreach ($extra_metas as $meta_name => $input) {
363
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
364
-            }
365
-        }
366
-        return $payment_method;
367
-    }
368
-
369
-
370
-
371
-    /**
372
-     * Makes sure the payment method is related to the specified payment method
373
-     *
374
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
375
-     * @param EE_Payment_Method $payment_method
376
-     * @return EE_Payment_Method
377
-     * @throws EE_Error
378
-     */
379
-    public function set_usable_currencies_on_payment_method($payment_method)
380
-    {
381
-        EE_Error::doing_it_wrong(
382
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
383
-            esc_html__(
384
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
385
-                'event_espresso'
386
-            ),
387
-            '4.9.40'
388
-        );
389
-        return $payment_method;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * Deactivates a payment method of the given payment method slug.
396
-     *
397
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
398
-     * @return int count of rows updated.
399
-     * @throws EE_Error
400
-     */
401
-    public function deactivate_payment_method($payment_method_slug)
402
-    {
403
-        EE_Log::instance()->log(
404
-            __FILE__,
405
-            __FUNCTION__,
406
-            sprintf(
407
-                esc_html__(
408
-                    'Payment method with slug %1$s is being deactivated by site admin',
409
-                    'event_espresso'
410
-                ),
411
-                $payment_method_slug
412
-            ),
413
-            'payment_method_change'
414
-        );
415
-        $count_updated = EEM_Payment_Method::instance()->update(
416
-            array('PMD_scope' => array()),
417
-            array(array('PMD_slug' => $payment_method_slug))
418
-        );
419
-        return $count_updated;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
426
-     * access caps.
427
-     *
428
-     * @param array $caps capabilities being filtered
429
-     * @return array
430
-     */
431
-    public function add_payment_method_caps($caps)
432
-    {
433
-        /* add dynamic caps from payment methods
20
+	/**
21
+	 * @var EE_Payment_Method_Manager $_instance
22
+	 */
23
+	private static $_instance;
24
+
25
+	/**
26
+	 * @var array keys are class names without 'EE_PMT_', values are their filepaths
27
+	 */
28
+	protected $_payment_method_types = array();
29
+
30
+
31
+
32
+	/**
33
+	 * @singleton method used to instantiate class object
34
+	 * @return EE_Payment_Method_Manager instance
35
+	 */
36
+	public static function instance()
37
+	{
38
+		// check if class object is instantiated, and instantiated properly
39
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
40
+			self::$_instance = new self();
41
+		}
42
+		EE_Registry::instance()->load_lib('PMT_Base');
43
+		return self::$_instance;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * Resets the instance and returns a new one
50
+	 *
51
+	 * @return EE_Payment_Method_Manager
52
+	 */
53
+	public static function reset()
54
+	{
55
+		self::$_instance = null;
56
+		return self::instance();
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * If necessary, re-register payment methods
63
+	 *
64
+	 * @param boolean $force_recheck whether to recheck for payment method types,
65
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
66
+	 *                               we have not yet checked during this request, then we need to check anyways)
67
+	 */
68
+	public function maybe_register_payment_methods($force_recheck = false)
69
+	{
70
+		if (! $this->_payment_method_types || $force_recheck) {
71
+			$this->_register_payment_methods();
72
+			//if in admin lets ensure caps are set.
73
+			if (is_admin()) {
74
+				add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
75
+				EE_Registry::instance()->CAP->init_caps();
76
+			}
77
+		}
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * register_payment_methods
84
+	 *
85
+	 * @return array
86
+	 */
87
+	protected function _register_payment_methods()
88
+	{
89
+		// grab list of installed modules
90
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
91
+		// filter list of modules to register
92
+		$pm_to_register = apply_filters(
93
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
94
+			$pm_to_register
95
+		);
96
+		// loop through folders
97
+		foreach ($pm_to_register as $pm_path) {
98
+			$this->register_payment_method($pm_path);
99
+		}
100
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
101
+		// filter list of installed modules
102
+		//keep them organized alphabetically by the payment method type's name
103
+		ksort($this->_payment_method_types);
104
+		return apply_filters(
105
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
106
+			$this->_payment_method_types
107
+		);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * register_payment_method- makes core aware of this payment method
114
+	 *
115
+	 * @param string $payment_method_path - full path up to and including payment method folder
116
+	 * @return boolean
117
+	 */
118
+	public function register_payment_method($payment_method_path = '')
119
+	{
120
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
121
+		$module_ext = '.pm.php';
122
+		// make all separators match
123
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
124
+		// grab and sanitize module name
125
+		$module_dir = basename($payment_method_path);
126
+		// create classname from module directory name
127
+		$module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
128
+		// add class prefix
129
+		$module_class = 'EE_PMT_' . $module;
130
+		// does the module exist ?
131
+		if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
132
+			$msg = sprintf(
133
+				esc_html__(
134
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
135
+					'event_espresso'
136
+				), $module
137
+			);
138
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
139
+			return false;
140
+		}
141
+		// load the module class file
142
+		require_once($payment_method_path . DS . $module_class . $module_ext);
143
+		// verify that class exists
144
+		if (! class_exists($module_class)) {
145
+			$msg = sprintf(
146
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
147
+				$module_class
148
+			);
149
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
150
+			return false;
151
+		}
152
+		// add to array of registered modules
153
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
154
+		return true;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * Checks if a payment method has been registered, and if so includes it
161
+	 *
162
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie classname without the prefix 'EEPM_')
163
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
164
+	 * @return boolean
165
+	 */
166
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
167
+	{
168
+		if (
169
+			$force_recheck
170
+			|| ! is_array($this->_payment_method_types)
171
+			|| ! isset($this->_payment_method_types[$payment_method_name])
172
+		) {
173
+			$this->maybe_register_payment_methods($force_recheck);
174
+		}
175
+		if (isset($this->_payment_method_types[$payment_method_name])) {
176
+			require_once($this->_payment_method_types[$payment_method_name]);
177
+			return true;
178
+		}
179
+		return false;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Returns all the class names of the various payment method types
186
+	 *
187
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
188
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
189
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
190
+	 * @return array
191
+	 */
192
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
193
+	{
194
+		$this->maybe_register_payment_methods($force_recheck);
195
+		if ($with_prefixes) {
196
+			$classnames = array_keys($this->_payment_method_types);
197
+			$payment_methods = array();
198
+			foreach ($classnames as $classname) {
199
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
200
+			}
201
+			return $payment_methods;
202
+		}
203
+		return array_keys($this->_payment_method_types);
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * Gets an object of each payment method type, none of which are bound to a
210
+	 * payment method instance
211
+	 *
212
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
213
+	 * @return EE_PMT_Base[]
214
+	 */
215
+	public function payment_method_types($force_recheck = false)
216
+	{
217
+		$this->maybe_register_payment_methods($force_recheck);
218
+		$payment_method_objects = array();
219
+		foreach ($this->payment_method_type_names(true) as $classname) {
220
+			$payment_method_objects[] = new $classname;
221
+		}
222
+		return $payment_method_objects;
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * Changes the payment method's classname into the payment method type's name
229
+	 * (as used on the payment method's table's PMD_type field)
230
+	 *
231
+	 * @param string $classname
232
+	 * @return string
233
+	 */
234
+	public function payment_method_type_sans_class_prefix($classname)
235
+	{
236
+		return str_replace('EE_PMT_', '', $classname);
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * Does the opposite of payment-method_type_sans_prefix
243
+	 *
244
+	 * @param string $type
245
+	 * @return string
246
+	 */
247
+	public function payment_method_class_from_type($type)
248
+	{
249
+		$this->maybe_register_payment_methods();
250
+		return 'EE_PMT_' . $type;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * Activates a payment method of the given type.
257
+	 *
258
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
259
+	 * @return EE_Payment_Method
260
+	 * @throws EE_Error
261
+	 */
262
+	public function activate_a_payment_method_of_type($payment_method_type)
263
+	{
264
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
265
+		if (! $payment_method instanceof EE_Payment_Method) {
266
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
267
+			if (class_exists($pm_type_class)) {
268
+				/** @var $pm_type_obj EE_PMT_Base */
269
+				$pm_type_obj = new $pm_type_class;
270
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
271
+				if (! $payment_method) {
272
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
273
+				}
274
+				$payment_method->set_type($payment_method_type);
275
+				$this->initialize_payment_method($payment_method);
276
+			} else {
277
+				throw new EE_Error(
278
+					sprintf(
279
+						esc_html__(
280
+							'There is no payment method of type %1$s, so it could not be activated',
281
+							'event_espresso'
282
+						),
283
+						$pm_type_class
284
+					)
285
+				);
286
+			}
287
+		}
288
+		$payment_method->set_active();
289
+		$payment_method->save();
290
+		if ($payment_method->type() === 'Invoice') {
291
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
292
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
293
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
294
+			$message_resource_manager->ensure_messenger_is_active('pdf');
295
+			EE_Error::add_persistent_admin_notice(
296
+				'invoice_pm_requirements_notice',
297
+				sprintf(
298
+					esc_html__(
299
+						'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
300
+						'event_espresso'
301
+					),
302
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
303
+					'</a>'
304
+				),
305
+				true
306
+			);
307
+		}
308
+		return $payment_method;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * Creates a payment method of the specified type. Does not save it.
315
+	 *
316
+	 * @global WP_User    $current_user
317
+	 * @param EE_PMT_Base $pm_type_obj
318
+	 * @return EE_Payment_Method
319
+	 * @throws EE_Error
320
+	 */
321
+	public function create_payment_method_of_type($pm_type_obj)
322
+	{
323
+		global $current_user;
324
+		$payment_method = EE_Payment_Method::new_instance(
325
+			array(
326
+				'PMD_type'       => $pm_type_obj->system_name(),
327
+				'PMD_name'       => $pm_type_obj->pretty_name(),
328
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
329
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
330
+				'PMD_wp_user'    => $current_user->ID,
331
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
332
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
333
+					) * 10,
334
+			)
335
+		);
336
+		return $payment_method;
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * Sets the initial payment method properties (including extra meta)
343
+	 *
344
+	 * @param EE_Payment_Method $payment_method
345
+	 * @return EE_Payment_Method
346
+	 * @throws EE_Error
347
+	 */
348
+	public function initialize_payment_method($payment_method)
349
+	{
350
+		$pm_type_obj = $payment_method->type_obj();
351
+		$payment_method->set_description($pm_type_obj->default_description());
352
+		if (! $payment_method->button_url()) {
353
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
354
+		}
355
+		//now add setup its default extra meta properties
356
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
357
+		if (! empty($extra_metas)) {
358
+			//verify the payment method has an ID before adding extra meta
359
+			if (! $payment_method->ID()) {
360
+				$payment_method->save();
361
+			}
362
+			foreach ($extra_metas as $meta_name => $input) {
363
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
364
+			}
365
+		}
366
+		return $payment_method;
367
+	}
368
+
369
+
370
+
371
+	/**
372
+	 * Makes sure the payment method is related to the specified payment method
373
+	 *
374
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
375
+	 * @param EE_Payment_Method $payment_method
376
+	 * @return EE_Payment_Method
377
+	 * @throws EE_Error
378
+	 */
379
+	public function set_usable_currencies_on_payment_method($payment_method)
380
+	{
381
+		EE_Error::doing_it_wrong(
382
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
383
+			esc_html__(
384
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
385
+				'event_espresso'
386
+			),
387
+			'4.9.40'
388
+		);
389
+		return $payment_method;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * Deactivates a payment method of the given payment method slug.
396
+	 *
397
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
398
+	 * @return int count of rows updated.
399
+	 * @throws EE_Error
400
+	 */
401
+	public function deactivate_payment_method($payment_method_slug)
402
+	{
403
+		EE_Log::instance()->log(
404
+			__FILE__,
405
+			__FUNCTION__,
406
+			sprintf(
407
+				esc_html__(
408
+					'Payment method with slug %1$s is being deactivated by site admin',
409
+					'event_espresso'
410
+				),
411
+				$payment_method_slug
412
+			),
413
+			'payment_method_change'
414
+		);
415
+		$count_updated = EEM_Payment_Method::instance()->update(
416
+			array('PMD_scope' => array()),
417
+			array(array('PMD_slug' => $payment_method_slug))
418
+		);
419
+		return $count_updated;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
426
+	 * access caps.
427
+	 *
428
+	 * @param array $caps capabilities being filtered
429
+	 * @return array
430
+	 */
431
+	public function add_payment_method_caps($caps)
432
+	{
433
+		/* add dynamic caps from payment methods
434 434
          * at the time of writing, october 20 2014, these are the caps added:
435 435
          * ee_payment_method_admin_only
436 436
          * ee_payment_method_aim
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
          * their related capability automatically added too, so long as they are
445 445
          * registered properly using EE_Register_Payment_Method::register()
446 446
          */
447
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
448
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
449
-        }
450
-        return $caps;
451
-    }
447
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
448
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
449
+		}
450
+		return $caps;
451
+	}
452 452
 
453 453
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     public static function instance()
37 37
     {
38 38
         // check if class object is instantiated, and instantiated properly
39
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
39
+        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
40 40
             self::$_instance = new self();
41 41
         }
42 42
         EE_Registry::instance()->load_lib('PMT_Base');
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function maybe_register_payment_methods($force_recheck = false)
69 69
     {
70
-        if (! $this->_payment_method_types || $force_recheck) {
70
+        if ( ! $this->_payment_method_types || $force_recheck) {
71 71
             $this->_register_payment_methods();
72 72
             //if in admin lets ensure caps are set.
73 73
             if (is_admin()) {
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     protected function _register_payment_methods()
88 88
     {
89 89
         // grab list of installed modules
90
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
90
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
91 91
         // filter list of modules to register
92 92
         $pm_to_register = apply_filters(
93 93
             'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
@@ -126,31 +126,31 @@  discard block
 block discarded – undo
126 126
         // create classname from module directory name
127 127
         $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
128 128
         // add class prefix
129
-        $module_class = 'EE_PMT_' . $module;
129
+        $module_class = 'EE_PMT_'.$module;
130 130
         // does the module exist ?
131
-        if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
131
+        if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) {
132 132
             $msg = sprintf(
133 133
                 esc_html__(
134 134
                     'The requested %s payment method file could not be found or is not readable due to file permissions.',
135 135
                     'event_espresso'
136 136
                 ), $module
137 137
             );
138
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
138
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
139 139
             return false;
140 140
         }
141 141
         // load the module class file
142
-        require_once($payment_method_path . DS . $module_class . $module_ext);
142
+        require_once($payment_method_path.DS.$module_class.$module_ext);
143 143
         // verify that class exists
144
-        if (! class_exists($module_class)) {
144
+        if ( ! class_exists($module_class)) {
145 145
             $msg = sprintf(
146 146
                 esc_html__('The requested %s module class does not exist.', 'event_espresso'),
147 147
                 $module_class
148 148
             );
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
150 150
             return false;
151 151
         }
152 152
         // add to array of registered modules
153
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
153
+        $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext;
154 154
         return true;
155 155
     }
156 156
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function payment_method_class_from_type($type)
248 248
     {
249 249
         $this->maybe_register_payment_methods();
250
-        return 'EE_PMT_' . $type;
250
+        return 'EE_PMT_'.$type;
251 251
     }
252 252
 
253 253
 
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
     public function activate_a_payment_method_of_type($payment_method_type)
263 263
     {
264 264
         $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
265
-        if (! $payment_method instanceof EE_Payment_Method) {
265
+        if ( ! $payment_method instanceof EE_Payment_Method) {
266 266
             $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
267 267
             if (class_exists($pm_type_class)) {
268 268
                 /** @var $pm_type_obj EE_PMT_Base */
269 269
                 $pm_type_obj = new $pm_type_class;
270 270
                 $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
271
-                if (! $payment_method) {
271
+                if ( ! $payment_method) {
272 272
                     $payment_method = $this->create_payment_method_of_type($pm_type_obj);
273 273
                 }
274 274
                 $payment_method->set_type($payment_method_type);
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
                         'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
300 300
                         'event_espresso'
301 301
                     ),
302
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
302
+                    '<a href="'.admin_url('admin.php?page=espresso_messages').'">',
303 303
                     '</a>'
304 304
                 ),
305 305
                 true
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                 'PMD_type'       => $pm_type_obj->system_name(),
327 327
                 'PMD_name'       => $pm_type_obj->pretty_name(),
328 328
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
329
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
329
+                'PMD_slug'       => $pm_type_obj->system_name(), //automatically converted to slug
330 330
                 'PMD_wp_user'    => $current_user->ID,
331 331
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
332 332
                         array(array('PMD_type' => array('!=', 'Admin_Only')))
@@ -349,14 +349,14 @@  discard block
 block discarded – undo
349 349
     {
350 350
         $pm_type_obj = $payment_method->type_obj();
351 351
         $payment_method->set_description($pm_type_obj->default_description());
352
-        if (! $payment_method->button_url()) {
352
+        if ( ! $payment_method->button_url()) {
353 353
             $payment_method->set_button_url($pm_type_obj->default_button_url());
354 354
         }
355 355
         //now add setup its default extra meta properties
356 356
         $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
357
-        if (! empty($extra_metas)) {
357
+        if ( ! empty($extra_metas)) {
358 358
             //verify the payment method has an ID before adding extra meta
359
-            if (! $payment_method->ID()) {
359
+            if ( ! $payment_method->ID()) {
360 360
                 $payment_method->save();
361 361
             }
362 362
             foreach ($extra_metas as $meta_name => $input) {
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     {
186 186
         // set autoloaders for all of the classes implementing EEI_Plugin_API
187 187
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
188
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
189 189
         //load and setup EE_Capabilities
190 190
         $this->registry->load_core('Capabilities');
191 191
         //caps need to be initialized on every request so that capability maps are set.
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 && $_GET['activate'] === 'true'
209 209
             )
210 210
         ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
211
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
212 212
         }
213 213
         do_action('AHEE__EE_System__load_espresso_addons__complete');
214 214
     }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     private function _parse_model_names()
691 691
     {
692 692
         //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
693
+        $models = glob(EE_MODELS.'*.model.php');
694 694
         $model_names = array();
695 695
         $non_abstract_db_models = array();
696 696
         foreach ($models as $model) {
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
      */
719 719
     private function _maybe_brew_regular()
720 720
     {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
721
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
722
+            require_once EE_CAFF_PATH.'brewing_regular.php';
723 723
         }
724 724
     }
725 725
 
@@ -769,8 +769,8 @@  discard block
 block discarded – undo
769 769
                 'event_espresso');
770 770
             $msg .= '<ul>';
771 771
             foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
772
+                $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+                        $class_name).'</b></li>';
774 774
             }
775 775
             $msg .= '</ul>';
776 776
             $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
         $this->registry->load_core('Session');
922 922
         do_action('AHEE__EE_System__core_loaded_and_ready');
923 923
         // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
924
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
925
+            require_once(EE_PUBLIC.'template_tags.php');
926 926
         }
927 927
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928 928
         $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true);
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
             'href'  => $events_admin_url,
1069 1069
             'meta'  => array(
1070 1070
                 'title' => __('Event Espresso', 'event_espresso'),
1071
-                'class' => $menu_class . 'first',
1071
+                'class' => $menu_class.'first',
1072 1072
             ),
1073 1073
         ));
1074 1074
         //Events
Please login to merge, or discard this patch.
Indentation   +1406 added lines, -1406 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,1411 +19,1411 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
-     */
26
-    const req_type_normal = 0;
27
-
28
-    /**
29
-     * Indicates this is a brand new installation of EE so we should install
30
-     * tables and default data etc
31
-     */
32
-    const req_type_new_activation = 1;
33
-
34
-    /**
35
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
-     * and we just exited maintenance mode). We MUST check the database is setup properly
37
-     * and that default data is setup too
38
-     */
39
-    const req_type_reactivation = 2;
40
-
41
-    /**
42
-     * indicates that EE has been upgraded since its previous request.
43
-     * We may have data migration scripts to call and will want to trigger maintenance mode
44
-     */
45
-    const req_type_upgrade = 3;
46
-
47
-    /**
48
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
-     */
50
-    const req_type_downgrade = 4;
51
-
52
-    /**
53
-     * @deprecated since version 4.6.0.dev.006
54
-     * Now whenever a new_activation is detected the request type is still just
55
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
-     * (Specifically, when the migration manager indicates migrations are finished
59
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
-     */
61
-    const req_type_activation_but_not_installed = 5;
62
-
63
-    /**
64
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
-     */
66
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
-
68
-
69
-    /**
70
-     *    instance of the EE_System object
71
-     *
72
-     * @var    $_instance
73
-     * @access    private
74
-     */
75
-    private static $_instance = null;
76
-
77
-    /**
78
-     * @type  EE_Registry $Registry
79
-     * @access    protected
80
-     */
81
-    protected $registry;
82
-
83
-    /**
84
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
-     *
87
-     * @var int
88
-     */
89
-    private $_req_type;
90
-
91
-    /**
92
-     * Whether or not there was a non-micro version change in EE core version during this request
93
-     *
94
-     * @var boolean
95
-     */
96
-    private $_major_version_change = false;
97
-
98
-
99
-
100
-    /**
101
-     * @singleton method used to instantiate class object
102
-     * @access    public
103
-     * @param  \EE_Registry $Registry
104
-     * @return \EE_System
105
-     */
106
-    public static function instance(EE_Registry $Registry = null)
107
-    {
108
-        // check if class object is instantiated
109
-        if ( ! self::$_instance instanceof EE_System) {
110
-            self::$_instance = new self($Registry);
111
-        }
112
-        return self::$_instance;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * resets the instance and returns it
119
-     *
120
-     * @return EE_System
121
-     */
122
-    public static function reset()
123
-    {
124
-        self::$_instance->_req_type = null;
125
-        //make sure none of the old hooks are left hanging around
126
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
-        //we need to reset the migration manager in order for it to detect DMSs properly
128
-        EE_Data_Migration_Manager::reset();
129
-        self::instance()->detect_activations_or_upgrades();
130
-        self::instance()->perform_activations_upgrades_and_migrations();
131
-        return self::instance();
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     *    sets hooks for running rest of system
138
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
-     *    starting EE Addons from any other point may lead to problems
140
-     *
141
-     * @access private
142
-     * @param  \EE_Registry $Registry
143
-     */
144
-    private function __construct(EE_Registry $Registry)
145
-    {
146
-        $this->registry = $Registry;
147
-        do_action('AHEE__EE_System__construct__begin', $this);
148
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
-        // when an ee addon is activated, we want to call the core hook(s) again
151
-        // because the newly-activated addon didn't get a chance to run at all
152
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
-        // detect whether install or upgrade
154
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
-            3);
156
-        // load EE_Config, EE_Textdomain, etc
157
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
-        // load EE_Config, EE_Textdomain, etc
159
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
-        // you wanna get going? I wanna get going... let's get going!
162
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
-        //other housekeeping
164
-        //exclude EE critical pages from wp_list_pages
165
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
-        // ALL EE Addons should use the following hook point to attach their initial setup too
167
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
-        do_action('AHEE__EE_System__construct__complete', $this);
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * load_espresso_addons
175
-     * allow addons to load first so that they can set hooks for running DMS's, etc
176
-     * this is hooked into both:
177
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
178
-     *        which runs during the WP 'plugins_loaded' action at priority 5
179
-     *    and the WP 'activate_plugin' hookpoint
180
-     *
181
-     * @access public
182
-     * @return void
183
-     */
184
-    public function load_espresso_addons()
185
-    {
186
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
187
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
-        //load and setup EE_Capabilities
190
-        $this->registry->load_core('Capabilities');
191
-        //caps need to be initialized on every request so that capability maps are set.
192
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
-        $this->registry->CAP->init_caps();
194
-        do_action('AHEE__EE_System__load_espresso_addons');
195
-        //if the WP API basic auth plugin isn't already loaded, load it now.
196
-        //We want it for mobile apps. Just include the entire plugin
197
-        //also, don't load the basic auth when a plugin is getting activated, because
198
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
-        //and causes a fatal error
200
-        if ( ! function_exists('json_basic_auth_handler')
201
-             && ! function_exists('json_basic_auth_error')
202
-             && ! (
203
-                isset($_GET['action'])
204
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
205
-            )
206
-             && ! (
207
-                isset($_GET['activate'])
208
-                && $_GET['activate'] === 'true'
209
-            )
210
-        ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
-        }
213
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * detect_activations_or_upgrades
220
-     * Checks for activation or upgrade of core first;
221
-     * then also checks if any registered addons have been activated or upgraded
222
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
-     * which runs during the WP 'plugins_loaded' action at priority 3
224
-     *
225
-     * @access public
226
-     * @return void
227
-     */
228
-    public function detect_activations_or_upgrades()
229
-    {
230
-        //first off: let's make sure to handle core
231
-        $this->detect_if_activation_or_upgrade();
232
-        foreach ($this->registry->addons as $addon) {
233
-            //detect teh request type for that addon
234
-            $addon->detect_activation_or_upgrade();
235
-        }
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * detect_if_activation_or_upgrade
242
-     * Takes care of detecting whether this is a brand new install or code upgrade,
243
-     * and either setting up the DB or setting up maintenance mode etc.
244
-     *
245
-     * @access public
246
-     * @return void
247
-     */
248
-    public function detect_if_activation_or_upgrade()
249
-    {
250
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
-        // load M-Mode class
252
-        $this->registry->load_core('Maintenance_Mode');
253
-        // check if db has been updated, or if its a brand-new installation
254
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
-        $request_type = $this->detect_req_type($espresso_db_update);
256
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
-        switch ($request_type) {
258
-            case EE_System::req_type_new_activation:
259
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
-                $this->_handle_core_version_change($espresso_db_update);
261
-                break;
262
-            case EE_System::req_type_reactivation:
263
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
-                $this->_handle_core_version_change($espresso_db_update);
265
-                break;
266
-            case EE_System::req_type_upgrade:
267
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
-                //migrations may be required now that we've upgraded
269
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
-                $this->_handle_core_version_change($espresso_db_update);
271
-                //				echo "done upgrade";die;
272
-                break;
273
-            case EE_System::req_type_downgrade:
274
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
-                //its possible migrations are no longer required
276
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
-                $this->_handle_core_version_change($espresso_db_update);
278
-                break;
279
-            case EE_System::req_type_normal:
280
-            default:
281
-                //				$this->_maybe_redirect_to_ee_about();
282
-                break;
283
-        }
284
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Updates the list of installed versions and sets hooks for
291
-     * initializing the database later during the request
292
-     *
293
-     * @param array $espresso_db_update
294
-     */
295
-    protected function _handle_core_version_change($espresso_db_update)
296
-    {
297
-        $this->update_list_of_installed_versions($espresso_db_update);
298
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
-            array($this, 'initialize_db_if_no_migrations_required'));
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
-     * information about what versions of EE have been installed and activated,
308
-     * NOT necessarily the state of the database
309
-     *
310
-     * @param null $espresso_db_update
311
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
-     *           from the options table
313
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
-     */
315
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
-    {
317
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
-        if ( ! $espresso_db_update) {
319
-            $espresso_db_update = get_option('espresso_db_update');
320
-        }
321
-        // check that option is an array
322
-        if ( ! is_array($espresso_db_update)) {
323
-            // if option is FALSE, then it never existed
324
-            if ($espresso_db_update === false) {
325
-                // make $espresso_db_update an array and save option with autoload OFF
326
-                $espresso_db_update = array();
327
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
-            } else {
329
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
330
-                $espresso_db_update = array($espresso_db_update => array());
331
-                update_option('espresso_db_update', $espresso_db_update);
332
-            }
333
-        } else {
334
-            $corrected_db_update = array();
335
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
-                    //the key is an int, and the value IS NOT an array
339
-                    //so it must be numerically-indexed, where values are versions installed...
340
-                    //fix it!
341
-                    $version_string = $should_be_array;
342
-                    $corrected_db_update[$version_string] = array('unknown-date');
343
-                } else {
344
-                    //ok it checks out
345
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
346
-                }
347
-            }
348
-            $espresso_db_update = $corrected_db_update;
349
-            update_option('espresso_db_update', $espresso_db_update);
350
-        }
351
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
-        return $espresso_db_update;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Does the traditional work of setting up the plugin's database and adding default data.
359
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
-     * so that it will be done when migrations are finished
363
-     *
364
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
-     *                                       This is a resource-intensive job
367
-     *                                       so we prefer to only do it when necessary
368
-     * @return void
369
-     */
370
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
-    {
372
-        $request_type = $this->detect_req_type();
373
-        //only initialize system if we're not in maintenance mode.
374
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
-            update_option('ee_flush_rewrite_rules', true);
376
-            if ($verify_schema) {
377
-                EEH_Activation::initialize_db_and_folders();
378
-            }
379
-            EEH_Activation::initialize_db_content();
380
-            EEH_Activation::system_initialization();
381
-            if ($initialize_addons_too) {
382
-                $this->initialize_addons();
383
-            }
384
-        } else {
385
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
-        }
387
-        if ($request_type === EE_System::req_type_new_activation
388
-            || $request_type === EE_System::req_type_reactivation
389
-            || (
390
-                $request_type === EE_System::req_type_upgrade
391
-                && $this->is_major_version_change()
392
-            )
393
-        ) {
394
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
-        }
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Initializes the db for all registered addons
402
-     */
403
-    public function initialize_addons()
404
-    {
405
-        //foreach registered addon, make sure its db is up-to-date too
406
-        foreach ($this->registry->addons as $addon) {
407
-            $addon->initialize_db_if_no_migrations_required();
408
-        }
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
-     *
416
-     * @param    array  $version_history
417
-     * @param    string $current_version_to_add version to be added to the version history
418
-     * @return    boolean success as to whether or not this option was changed
419
-     */
420
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
-    {
422
-        if ( ! $version_history) {
423
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
-        }
425
-        if ($current_version_to_add == null) {
426
-            $current_version_to_add = espresso_version();
427
-        }
428
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
-        // re-save
430
-        return update_option('espresso_db_update', $version_history);
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * Detects if the current version indicated in the has existed in the list of
437
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
-     *
439
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
-     *                                  If not supplied, fetches it from the options table.
441
-     *                                  Also, caches its result so later parts of the code can also know whether
442
-     *                                  there's been an update or not. This way we can add the current version to
443
-     *                                  espresso_db_update, but still know if this is a new install or not
444
-     * @return int one of the constants on EE_System::req_type_
445
-     */
446
-    public function detect_req_type($espresso_db_update = null)
447
-    {
448
-        if ($this->_req_type === null) {
449
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
-                : $this->fix_espresso_db_upgrade_option();
451
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
-                'ee_espresso_activation', espresso_version());
453
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
-        }
455
-        return $this->_req_type;
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * Returns whether or not there was a non-micro version change (ie, change in either
462
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
-     *
465
-     * @param $activation_history
466
-     * @return bool
467
-     */
468
-    protected function _detect_major_version_change($activation_history)
469
-    {
470
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
-        $previous_version_parts = explode('.', $previous_version);
472
-        $current_version_parts = explode('.', espresso_version());
473
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
-               && ($previous_version_parts[0] !== $current_version_parts[0]
475
-                   || $previous_version_parts[1] !== $current_version_parts[1]
476
-               );
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Returns true if either the major or minor version of EE changed during this request.
483
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
484
-     *
485
-     * @return bool
486
-     */
487
-    public function is_major_version_change()
488
-    {
489
-        return $this->_major_version_change;
490
-    }
491
-
492
-
493
-
494
-    /**
495
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
-     * just activated to (for core that will always be espresso_version())
499
-     *
500
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
-     *                                                 ee plugin. for core that's 'espresso_db_update'
502
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
-     *                                                 indicate that this plugin was just activated
504
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
-     *                                                 espresso_version())
506
-     * @return int one of the constants on EE_System::req_type_*
507
-     */
508
-    public static function detect_req_type_given_activation_history(
509
-        $activation_history_for_addon,
510
-        $activation_indicator_option_name,
511
-        $version_to_upgrade_to
512
-    ) {
513
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
-        if ($activation_history_for_addon) {
515
-            //it exists, so this isn't a completely new install
516
-            //check if this version already in that list of previously installed versions
517
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
-                //it a version we haven't seen before
519
-                if ($version_is_higher === 1) {
520
-                    $req_type = EE_System::req_type_upgrade;
521
-                } else {
522
-                    $req_type = EE_System::req_type_downgrade;
523
-                }
524
-                delete_option($activation_indicator_option_name);
525
-            } else {
526
-                // its not an update. maybe a reactivation?
527
-                if (get_option($activation_indicator_option_name, false)) {
528
-                    if ($version_is_higher === -1) {
529
-                        $req_type = EE_System::req_type_downgrade;
530
-                    } elseif ($version_is_higher === 0) {
531
-                        //we've seen this version before, but it's an activation. must be a reactivation
532
-                        $req_type = EE_System::req_type_reactivation;
533
-                    } else {//$version_is_higher === 1
534
-                        $req_type = EE_System::req_type_upgrade;
535
-                    }
536
-                    delete_option($activation_indicator_option_name);
537
-                } else {
538
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
539
-                    if ($version_is_higher === -1) {
540
-                        $req_type = EE_System::req_type_downgrade;
541
-                    } elseif ($version_is_higher === 0) {
542
-                        //we've seen this version before and it's not an activation. its normal request
543
-                        $req_type = EE_System::req_type_normal;
544
-                    } else {//$version_is_higher === 1
545
-                        $req_type = EE_System::req_type_upgrade;
546
-                    }
547
-                }
548
-            }
549
-        } else {
550
-            //brand new install
551
-            $req_type = EE_System::req_type_new_activation;
552
-            delete_option($activation_indicator_option_name);
553
-        }
554
-        return $req_type;
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
-     * the $activation_history_for_addon
562
-     *
563
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
-     *                                             sometimes containing 'unknown-date'
565
-     * @param string $version_to_upgrade_to        (current version)
566
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
-     */
571
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
-    {
573
-        //find the most recently-activated version
574
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * Gets the most recently active version listed in the activation history,
582
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
-     *
584
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
-     *                                   sometimes containing 'unknown-date'
586
-     * @return string
587
-     */
588
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
-    {
590
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
591
-        $most_recently_active_version = '0.0.0.dev.000';
592
-        if (is_array($activation_history)) {
593
-            foreach ($activation_history as $version => $times_activated) {
594
-                //check there is a record of when this version was activated. Otherwise,
595
-                //mark it as unknown
596
-                if ( ! $times_activated) {
597
-                    $times_activated = array('unknown-date');
598
-                }
599
-                if (is_string($times_activated)) {
600
-                    $times_activated = array($times_activated);
601
-                }
602
-                foreach ($times_activated as $an_activation) {
603
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
-                        $most_recently_active_version = $version;
605
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
606
-                            ? '1970-01-01 00:00:00' : $an_activation;
607
-                    }
608
-                }
609
-            }
610
-        }
611
-        return $most_recently_active_version;
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This redirects to the about EE page after activation
618
-     *
619
-     * @return void
620
-     */
621
-    public function redirect_to_about_ee()
622
-    {
623
-        $notices = EE_Error::get_notices(false);
624
-        //if current user is an admin and it's not an ajax or rest request
625
-        if (
626
-            ! (defined('DOING_AJAX') && DOING_AJAX)
627
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
628
-            && ! isset($notices['errors'])
629
-            && apply_filters(
630
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
-            )
633
-        ) {
634
-            $query_params = array('page' => 'espresso_about');
635
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
-                $query_params['new_activation'] = true;
637
-            }
638
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
-                $query_params['reactivation'] = true;
640
-            }
641
-            $url = add_query_arg($query_params, admin_url('admin.php'));
642
-            wp_safe_redirect($url);
643
-            exit();
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * load_core_configuration
651
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
-     * which runs during the WP 'plugins_loaded' action at priority 5
653
-     *
654
-     * @return void
655
-     */
656
-    public function load_core_configuration()
657
-    {
658
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
-        $this->registry->load_core('EE_Load_Textdomain');
660
-        //load textdomain
661
-        EE_Load_Textdomain::load_textdomain();
662
-        // load and setup EE_Config and EE_Network_Config
663
-        $this->registry->load_core('Config');
664
-        $this->registry->load_core('Network_Config');
665
-        // setup autoloaders
666
-        // enable logging?
667
-        if ($this->registry->CFG->admin->use_full_logging) {
668
-            $this->registry->load_core('Log');
669
-        }
670
-        // check for activation errors
671
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
672
-        if ($activation_errors) {
673
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
-            update_option('ee_plugin_activation_errors', false);
675
-        }
676
-        // get model names
677
-        $this->_parse_model_names();
678
-        //load caf stuff a chance to play during the activation process too.
679
-        $this->_maybe_brew_regular();
680
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
687
-     *
688
-     * @return void
689
-     */
690
-    private function _parse_model_names()
691
-    {
692
-        //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
694
-        $model_names = array();
695
-        $non_abstract_db_models = array();
696
-        foreach ($models as $model) {
697
-            // get model classname
698
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
-            $short_name = str_replace('EEM_', '', $classname);
700
-            $reflectionClass = new ReflectionClass($classname);
701
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
-                $non_abstract_db_models[$short_name] = $classname;
703
-            }
704
-            $model_names[$short_name] = $classname;
705
-        }
706
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
-            $non_abstract_db_models);
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
-     * that need to be setup before our EE_System launches.
716
-     *
717
-     * @return void
718
-     */
719
-    private function _maybe_brew_regular()
720
-    {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
723
-        }
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * register_shortcodes_modules_and_widgets
730
-     * generate lists of shortcodes and modules, then verify paths and classes
731
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
-     * which runs during the WP 'plugins_loaded' action at priority 7
733
-     *
734
-     * @access public
735
-     * @return void
736
-     */
737
-    public function register_shortcodes_modules_and_widgets()
738
-    {
739
-        try {
740
-            // load, register, and add shortcodes the new way
741
-            new ShortcodesManager(
742
-            // and the old way, but we'll put it under control of the new system
743
-                EE_Config::getLegacyShortcodesManager()
744
-            );
745
-        } catch (Exception $exception) {
746
-            new ExceptionStackTraceDisplay($exception);
747
-        }
748
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
-        // check for addons using old hookpoint
750
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
-            $this->_incompatible_addon_error();
752
-        }
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * _incompatible_addon_error
759
-     *
760
-     * @access public
761
-     * @return void
762
-     */
763
-    private function _incompatible_addon_error()
764
-    {
765
-        // get array of classes hooking into here
766
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
-        if ( ! empty($class_names)) {
768
-            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
769
-                'event_espresso');
770
-            $msg .= '<ul>';
771
-            foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
774
-            }
775
-            $msg .= '</ul>';
776
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
-                'event_espresso');
778
-            // save list of incompatible addons to wp-options for later use
779
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
780
-            if (is_admin()) {
781
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
-            }
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * brew_espresso
790
-     * begins the process of setting hooks for initializing EE in the correct order
791
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
-     * which runs during the WP 'plugins_loaded' action at priority 9
793
-     *
794
-     * @return void
795
-     */
796
-    public function brew_espresso()
797
-    {
798
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
-        // load some final core systems
800
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
801
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
-        add_action('init', array($this, 'load_controllers'), 7);
804
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
-        add_action('init', array($this, 'initialize'), 10);
806
-        add_action('init', array($this, 'initialize_last'), 100);
807
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
-            // pew pew pew
810
-            $this->registry->load_core('PUE');
811
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
-        }
813
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     *    set_hooks_for_core
820
-     *
821
-     * @access public
822
-     * @return    void
823
-     */
824
-    public function set_hooks_for_core()
825
-    {
826
-        $this->_deactivate_incompatible_addons();
827
-        do_action('AHEE__EE_System__set_hooks_for_core');
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * Using the information gathered in EE_System::_incompatible_addon_error,
834
-     * deactivates any addons considered incompatible with the current version of EE
835
-     */
836
-    private function _deactivate_incompatible_addons()
837
-    {
838
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
839
-        if ( ! empty($incompatible_addons)) {
840
-            $active_plugins = get_option('active_plugins', array());
841
-            foreach ($active_plugins as $active_plugin) {
842
-                foreach ($incompatible_addons as $incompatible_addon) {
843
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
844
-                        unset($_GET['activate']);
845
-                        espresso_deactivate_plugin($active_plugin);
846
-                    }
847
-                }
848
-            }
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     *    perform_activations_upgrades_and_migrations
856
-     *
857
-     * @access public
858
-     * @return    void
859
-     */
860
-    public function perform_activations_upgrades_and_migrations()
861
-    {
862
-        //first check if we had previously attempted to setup EE's directories but failed
863
-        if (EEH_Activation::upload_directories_incomplete()) {
864
-            EEH_Activation::create_upload_directories();
865
-        }
866
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     *    load_CPTs_and_session
873
-     *
874
-     * @access public
875
-     * @return    void
876
-     */
877
-    public function load_CPTs_and_session()
878
-    {
879
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
-        // register Custom Post Types
881
-        $this->registry->load_core('Register_CPTs');
882
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * load_controllers
889
-     * this is the best place to load any additional controllers that needs access to EE core.
890
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
-     * time
892
-     *
893
-     * @access public
894
-     * @return void
895
-     */
896
-    public function load_controllers()
897
-    {
898
-        do_action('AHEE__EE_System__load_controllers__start');
899
-        // let's get it started
900
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
-            $this->registry->load_core('Front_Controller');
903
-        } else if ( ! EE_FRONT_AJAX) {
904
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
-            EE_Registry::instance()->load_core('Admin');
906
-        }
907
-        do_action('AHEE__EE_System__load_controllers__complete');
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * core_loaded_and_ready
914
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
-     *
916
-     * @access public
917
-     * @return void
918
-     */
919
-    public function core_loaded_and_ready()
920
-    {
921
-        $this->registry->load_core('Session');
922
-        do_action('AHEE__EE_System__core_loaded_and_ready');
923
-        // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
926
-        }
927
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
-        $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true);
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * initialize
935
-     * this is the best place to begin initializing client code
936
-     *
937
-     * @access public
938
-     * @return void
939
-     */
940
-    public function initialize()
941
-    {
942
-        do_action('AHEE__EE_System__initialize');
943
-    }
944
-
945
-
946
-
947
-    /**
948
-     * initialize_last
949
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
950
-     * initialize has done so
951
-     *
952
-     * @access public
953
-     * @return void
954
-     */
955
-    public function initialize_last()
956
-    {
957
-        do_action('AHEE__EE_System__initialize_last');
958
-    }
959
-
960
-
961
-
962
-    /**
963
-     * set_hooks_for_shortcodes_modules_and_addons
964
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
965
-     * this happens at the very beginning of the wp_loaded hookpoint
966
-     *
967
-     * @access public
968
-     * @return void
969
-     */
970
-    public function set_hooks_for_shortcodes_modules_and_addons()
971
-    {
972
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * do_not_cache
979
-     * sets no cache headers and defines no cache constants for WP plugins
980
-     *
981
-     * @access public
982
-     * @return void
983
-     */
984
-    public static function do_not_cache()
985
-    {
986
-        // set no cache constants
987
-        if ( ! defined('DONOTCACHEPAGE')) {
988
-            define('DONOTCACHEPAGE', true);
989
-        }
990
-        if ( ! defined('DONOTCACHCEOBJECT')) {
991
-            define('DONOTCACHCEOBJECT', true);
992
-        }
993
-        if ( ! defined('DONOTCACHEDB')) {
994
-            define('DONOTCACHEDB', true);
995
-        }
996
-        // add no cache headers
997
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
998
-        // plus a little extra for nginx and Google Chrome
999
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1000
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1001
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     *    extra_nocache_headers
1008
-     *
1009
-     * @access    public
1010
-     * @param $headers
1011
-     * @return    array
1012
-     */
1013
-    public static function extra_nocache_headers($headers)
1014
-    {
1015
-        // for NGINX
1016
-        $headers['X-Accel-Expires'] = 0;
1017
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1018
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1019
-        return $headers;
1020
-    }
1021
-
1022
-
1023
-
1024
-    /**
1025
-     *    nocache_headers
1026
-     *
1027
-     * @access    public
1028
-     * @return    void
1029
-     */
1030
-    public static function nocache_headers()
1031
-    {
1032
-        nocache_headers();
1033
-    }
1034
-
1035
-
1036
-
1037
-    /**
1038
-     *    espresso_toolbar_items
1039
-     *
1040
-     * @access public
1041
-     * @param  WP_Admin_Bar $admin_bar
1042
-     * @return void
1043
-     */
1044
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1045
-    {
1046
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1047
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1048
-            || defined('DOING_AJAX')
1049
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1050
-        ) {
1051
-            return;
1052
-        }
1053
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1054
-        $menu_class = 'espresso_menu_item_class';
1055
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1056
-        //because they're only defined in each of their respective constructors
1057
-        //and this might be a frontend request, in which case they aren't available
1058
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1059
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1060
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1061
-        //Top Level
1062
-        $admin_bar->add_menu(array(
1063
-            'id'    => 'espresso-toolbar',
1064
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1065
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1066
-                       . '</span>',
1067
-            'href'  => $events_admin_url,
1068
-            'meta'  => array(
1069
-                'title' => __('Event Espresso', 'event_espresso'),
1070
-                'class' => $menu_class . 'first',
1071
-            ),
1072
-        ));
1073
-        //Events
1074
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1075
-            $admin_bar->add_menu(array(
1076
-                'id'     => 'espresso-toolbar-events',
1077
-                'parent' => 'espresso-toolbar',
1078
-                'title'  => __('Events', 'event_espresso'),
1079
-                'href'   => $events_admin_url,
1080
-                'meta'   => array(
1081
-                    'title'  => __('Events', 'event_espresso'),
1082
-                    'target' => '',
1083
-                    'class'  => $menu_class,
1084
-                ),
1085
-            ));
1086
-        }
1087
-        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1088
-            //Events Add New
1089
-            $admin_bar->add_menu(array(
1090
-                'id'     => 'espresso-toolbar-events-new',
1091
-                'parent' => 'espresso-toolbar-events',
1092
-                'title'  => __('Add New', 'event_espresso'),
1093
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1094
-                'meta'   => array(
1095
-                    'title'  => __('Add New', 'event_espresso'),
1096
-                    'target' => '',
1097
-                    'class'  => $menu_class,
1098
-                ),
1099
-            ));
1100
-        }
1101
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1102
-            //Current post
1103
-            global $post;
1104
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1105
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1106
-            ) {
1107
-                //Events Edit Current Event
1108
-                $admin_bar->add_menu(array(
1109
-                    'id'     => 'espresso-toolbar-events-edit',
1110
-                    'parent' => 'espresso-toolbar-events',
1111
-                    'title'  => __('Edit Event', 'event_espresso'),
1112
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1113
-                        $events_admin_url),
1114
-                    'meta'   => array(
1115
-                        'title'  => __('Edit Event', 'event_espresso'),
1116
-                        'target' => '',
1117
-                        'class'  => $menu_class,
1118
-                    ),
1119
-                ));
1120
-            }
1121
-        }
1122
-        //Events View
1123
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1124
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1125
-        ) {
1126
-            $admin_bar->add_menu(array(
1127
-                'id'     => 'espresso-toolbar-events-view',
1128
-                'parent' => 'espresso-toolbar-events',
1129
-                'title'  => __('View', 'event_espresso'),
1130
-                'href'   => $events_admin_url,
1131
-                'meta'   => array(
1132
-                    'title'  => __('View', 'event_espresso'),
1133
-                    'target' => '',
1134
-                    'class'  => $menu_class,
1135
-                ),
1136
-            ));
1137
-        }
1138
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1139
-            //Events View All
1140
-            $admin_bar->add_menu(array(
1141
-                'id'     => 'espresso-toolbar-events-all',
1142
-                'parent' => 'espresso-toolbar-events-view',
1143
-                'title'  => __('All', 'event_espresso'),
1144
-                'href'   => $events_admin_url,
1145
-                'meta'   => array(
1146
-                    'title'  => __('All', 'event_espresso'),
1147
-                    'target' => '',
1148
-                    'class'  => $menu_class,
1149
-                ),
1150
-            ));
1151
-        }
1152
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1153
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1154
-        ) {
1155
-            //Events View Today
1156
-            $admin_bar->add_menu(array(
1157
-                'id'     => 'espresso-toolbar-events-today',
1158
-                'parent' => 'espresso-toolbar-events-view',
1159
-                'title'  => __('Today', 'event_espresso'),
1160
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1161
-                    $events_admin_url),
1162
-                'meta'   => array(
1163
-                    'title'  => __('Today', 'event_espresso'),
1164
-                    'target' => '',
1165
-                    'class'  => $menu_class,
1166
-                ),
1167
-            ));
1168
-        }
1169
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1170
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1171
-        ) {
1172
-            //Events View This Month
1173
-            $admin_bar->add_menu(array(
1174
-                'id'     => 'espresso-toolbar-events-month',
1175
-                'parent' => 'espresso-toolbar-events-view',
1176
-                'title'  => __('This Month', 'event_espresso'),
1177
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1178
-                    $events_admin_url),
1179
-                'meta'   => array(
1180
-                    'title'  => __('This Month', 'event_espresso'),
1181
-                    'target' => '',
1182
-                    'class'  => $menu_class,
1183
-                ),
1184
-            ));
1185
-        }
1186
-        //Registration Overview
1187
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1188
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1189
-        ) {
1190
-            $admin_bar->add_menu(array(
1191
-                'id'     => 'espresso-toolbar-registrations',
1192
-                'parent' => 'espresso-toolbar',
1193
-                'title'  => __('Registrations', 'event_espresso'),
1194
-                'href'   => $reg_admin_url,
1195
-                'meta'   => array(
1196
-                    'title'  => __('Registrations', 'event_espresso'),
1197
-                    'target' => '',
1198
-                    'class'  => $menu_class,
1199
-                ),
1200
-            ));
1201
-        }
1202
-        //Registration Overview Today
1203
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1204
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1205
-        ) {
1206
-            $admin_bar->add_menu(array(
1207
-                'id'     => 'espresso-toolbar-registrations-today',
1208
-                'parent' => 'espresso-toolbar-registrations',
1209
-                'title'  => __('Today', 'event_espresso'),
1210
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1211
-                    $reg_admin_url),
1212
-                'meta'   => array(
1213
-                    'title'  => __('Today', 'event_espresso'),
1214
-                    'target' => '',
1215
-                    'class'  => $menu_class,
1216
-                ),
1217
-            ));
1218
-        }
1219
-        //Registration Overview Today Completed
1220
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1221
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1222
-        ) {
1223
-            $admin_bar->add_menu(array(
1224
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1225
-                'parent' => 'espresso-toolbar-registrations-today',
1226
-                'title'  => __('Approved', 'event_espresso'),
1227
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1228
-                    'action'      => 'default',
1229
-                    'status'      => 'today',
1230
-                    '_reg_status' => EEM_Registration::status_id_approved,
1231
-                ), $reg_admin_url),
1232
-                'meta'   => array(
1233
-                    'title'  => __('Approved', 'event_espresso'),
1234
-                    'target' => '',
1235
-                    'class'  => $menu_class,
1236
-                ),
1237
-            ));
1238
-        }
1239
-        //Registration Overview Today Pending\
1240
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1241
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1242
-        ) {
1243
-            $admin_bar->add_menu(array(
1244
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1245
-                'parent' => 'espresso-toolbar-registrations-today',
1246
-                'title'  => __('Pending', 'event_espresso'),
1247
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1248
-                    'action'     => 'default',
1249
-                    'status'     => 'today',
1250
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1251
-                ), $reg_admin_url),
1252
-                'meta'   => array(
1253
-                    'title'  => __('Pending Payment', 'event_espresso'),
1254
-                    'target' => '',
1255
-                    'class'  => $menu_class,
1256
-                ),
1257
-            ));
1258
-        }
1259
-        //Registration Overview Today Incomplete
1260
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1261
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1262
-        ) {
1263
-            $admin_bar->add_menu(array(
1264
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1265
-                'parent' => 'espresso-toolbar-registrations-today',
1266
-                'title'  => __('Not Approved', 'event_espresso'),
1267
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1268
-                    'action'      => 'default',
1269
-                    'status'      => 'today',
1270
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1271
-                ), $reg_admin_url),
1272
-                'meta'   => array(
1273
-                    'title'  => __('Not Approved', 'event_espresso'),
1274
-                    'target' => '',
1275
-                    'class'  => $menu_class,
1276
-                ),
1277
-            ));
1278
-        }
1279
-        //Registration Overview Today Incomplete
1280
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1281
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1282
-        ) {
1283
-            $admin_bar->add_menu(array(
1284
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1285
-                'parent' => 'espresso-toolbar-registrations-today',
1286
-                'title'  => __('Cancelled', 'event_espresso'),
1287
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1288
-                    'action'      => 'default',
1289
-                    'status'      => 'today',
1290
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1291
-                ), $reg_admin_url),
1292
-                'meta'   => array(
1293
-                    'title'  => __('Cancelled', 'event_espresso'),
1294
-                    'target' => '',
1295
-                    'class'  => $menu_class,
1296
-                ),
1297
-            ));
1298
-        }
1299
-        //Registration Overview This Month
1300
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1301
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1302
-        ) {
1303
-            $admin_bar->add_menu(array(
1304
-                'id'     => 'espresso-toolbar-registrations-month',
1305
-                'parent' => 'espresso-toolbar-registrations',
1306
-                'title'  => __('This Month', 'event_espresso'),
1307
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1308
-                    $reg_admin_url),
1309
-                'meta'   => array(
1310
-                    'title'  => __('This Month', 'event_espresso'),
1311
-                    'target' => '',
1312
-                    'class'  => $menu_class,
1313
-                ),
1314
-            ));
1315
-        }
1316
-        //Registration Overview This Month Approved
1317
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1318
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1319
-        ) {
1320
-            $admin_bar->add_menu(array(
1321
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1322
-                'parent' => 'espresso-toolbar-registrations-month',
1323
-                'title'  => __('Approved', 'event_espresso'),
1324
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1325
-                    'action'      => 'default',
1326
-                    'status'      => 'month',
1327
-                    '_reg_status' => EEM_Registration::status_id_approved,
1328
-                ), $reg_admin_url),
1329
-                'meta'   => array(
1330
-                    'title'  => __('Approved', 'event_espresso'),
1331
-                    'target' => '',
1332
-                    'class'  => $menu_class,
1333
-                ),
1334
-            ));
1335
-        }
1336
-        //Registration Overview This Month Pending
1337
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1338
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1339
-        ) {
1340
-            $admin_bar->add_menu(array(
1341
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1342
-                'parent' => 'espresso-toolbar-registrations-month',
1343
-                'title'  => __('Pending', 'event_espresso'),
1344
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1345
-                    'action'      => 'default',
1346
-                    'status'      => 'month',
1347
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1348
-                ), $reg_admin_url),
1349
-                'meta'   => array(
1350
-                    'title'  => __('Pending', 'event_espresso'),
1351
-                    'target' => '',
1352
-                    'class'  => $menu_class,
1353
-                ),
1354
-            ));
1355
-        }
1356
-        //Registration Overview This Month Not Approved
1357
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1358
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1359
-        ) {
1360
-            $admin_bar->add_menu(array(
1361
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1362
-                'parent' => 'espresso-toolbar-registrations-month',
1363
-                'title'  => __('Not Approved', 'event_espresso'),
1364
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1365
-                    'action'      => 'default',
1366
-                    'status'      => 'month',
1367
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1368
-                ), $reg_admin_url),
1369
-                'meta'   => array(
1370
-                    'title'  => __('Not Approved', 'event_espresso'),
1371
-                    'target' => '',
1372
-                    'class'  => $menu_class,
1373
-                ),
1374
-            ));
1375
-        }
1376
-        //Registration Overview This Month Cancelled
1377
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1378
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1379
-        ) {
1380
-            $admin_bar->add_menu(array(
1381
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1382
-                'parent' => 'espresso-toolbar-registrations-month',
1383
-                'title'  => __('Cancelled', 'event_espresso'),
1384
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1385
-                    'action'      => 'default',
1386
-                    'status'      => 'month',
1387
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1388
-                ), $reg_admin_url),
1389
-                'meta'   => array(
1390
-                    'title'  => __('Cancelled', 'event_espresso'),
1391
-                    'target' => '',
1392
-                    'class'  => $menu_class,
1393
-                ),
1394
-            ));
1395
-        }
1396
-        //Extensions & Services
1397
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1398
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1399
-        ) {
1400
-            $admin_bar->add_menu(array(
1401
-                'id'     => 'espresso-toolbar-extensions-and-services',
1402
-                'parent' => 'espresso-toolbar',
1403
-                'title'  => __('Extensions & Services', 'event_espresso'),
1404
-                'href'   => $extensions_admin_url,
1405
-                'meta'   => array(
1406
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1407
-                    'target' => '',
1408
-                    'class'  => $menu_class,
1409
-                ),
1410
-            ));
1411
-        }
1412
-    }
1413
-
1414
-
1415
-
1416
-    /**
1417
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1418
-     * never returned with the function.
1419
-     *
1420
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1421
-     * @return array
1422
-     */
1423
-    public function remove_pages_from_wp_list_pages($exclude_array)
1424
-    {
1425
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1426
-    }
22
+	/**
23
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
+	 */
26
+	const req_type_normal = 0;
27
+
28
+	/**
29
+	 * Indicates this is a brand new installation of EE so we should install
30
+	 * tables and default data etc
31
+	 */
32
+	const req_type_new_activation = 1;
33
+
34
+	/**
35
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
37
+	 * and that default data is setup too
38
+	 */
39
+	const req_type_reactivation = 2;
40
+
41
+	/**
42
+	 * indicates that EE has been upgraded since its previous request.
43
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
44
+	 */
45
+	const req_type_upgrade = 3;
46
+
47
+	/**
48
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
+	 */
50
+	const req_type_downgrade = 4;
51
+
52
+	/**
53
+	 * @deprecated since version 4.6.0.dev.006
54
+	 * Now whenever a new_activation is detected the request type is still just
55
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
+	 * (Specifically, when the migration manager indicates migrations are finished
59
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
+	 */
61
+	const req_type_activation_but_not_installed = 5;
62
+
63
+	/**
64
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
+	 */
66
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
+
68
+
69
+	/**
70
+	 *    instance of the EE_System object
71
+	 *
72
+	 * @var    $_instance
73
+	 * @access    private
74
+	 */
75
+	private static $_instance = null;
76
+
77
+	/**
78
+	 * @type  EE_Registry $Registry
79
+	 * @access    protected
80
+	 */
81
+	protected $registry;
82
+
83
+	/**
84
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
+	 *
87
+	 * @var int
88
+	 */
89
+	private $_req_type;
90
+
91
+	/**
92
+	 * Whether or not there was a non-micro version change in EE core version during this request
93
+	 *
94
+	 * @var boolean
95
+	 */
96
+	private $_major_version_change = false;
97
+
98
+
99
+
100
+	/**
101
+	 * @singleton method used to instantiate class object
102
+	 * @access    public
103
+	 * @param  \EE_Registry $Registry
104
+	 * @return \EE_System
105
+	 */
106
+	public static function instance(EE_Registry $Registry = null)
107
+	{
108
+		// check if class object is instantiated
109
+		if ( ! self::$_instance instanceof EE_System) {
110
+			self::$_instance = new self($Registry);
111
+		}
112
+		return self::$_instance;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * resets the instance and returns it
119
+	 *
120
+	 * @return EE_System
121
+	 */
122
+	public static function reset()
123
+	{
124
+		self::$_instance->_req_type = null;
125
+		//make sure none of the old hooks are left hanging around
126
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
+		//we need to reset the migration manager in order for it to detect DMSs properly
128
+		EE_Data_Migration_Manager::reset();
129
+		self::instance()->detect_activations_or_upgrades();
130
+		self::instance()->perform_activations_upgrades_and_migrations();
131
+		return self::instance();
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 *    sets hooks for running rest of system
138
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
+	 *    starting EE Addons from any other point may lead to problems
140
+	 *
141
+	 * @access private
142
+	 * @param  \EE_Registry $Registry
143
+	 */
144
+	private function __construct(EE_Registry $Registry)
145
+	{
146
+		$this->registry = $Registry;
147
+		do_action('AHEE__EE_System__construct__begin', $this);
148
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
+		// when an ee addon is activated, we want to call the core hook(s) again
151
+		// because the newly-activated addon didn't get a chance to run at all
152
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
+		// detect whether install or upgrade
154
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
+			3);
156
+		// load EE_Config, EE_Textdomain, etc
157
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
+		// load EE_Config, EE_Textdomain, etc
159
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
+		// you wanna get going? I wanna get going... let's get going!
162
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
+		//other housekeeping
164
+		//exclude EE critical pages from wp_list_pages
165
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
+		// ALL EE Addons should use the following hook point to attach their initial setup too
167
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
+		do_action('AHEE__EE_System__construct__complete', $this);
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * load_espresso_addons
175
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
176
+	 * this is hooked into both:
177
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
178
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
179
+	 *    and the WP 'activate_plugin' hookpoint
180
+	 *
181
+	 * @access public
182
+	 * @return void
183
+	 */
184
+	public function load_espresso_addons()
185
+	{
186
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
187
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
188
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
+		//load and setup EE_Capabilities
190
+		$this->registry->load_core('Capabilities');
191
+		//caps need to be initialized on every request so that capability maps are set.
192
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
+		$this->registry->CAP->init_caps();
194
+		do_action('AHEE__EE_System__load_espresso_addons');
195
+		//if the WP API basic auth plugin isn't already loaded, load it now.
196
+		//We want it for mobile apps. Just include the entire plugin
197
+		//also, don't load the basic auth when a plugin is getting activated, because
198
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
+		//and causes a fatal error
200
+		if ( ! function_exists('json_basic_auth_handler')
201
+			 && ! function_exists('json_basic_auth_error')
202
+			 && ! (
203
+				isset($_GET['action'])
204
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
205
+			)
206
+			 && ! (
207
+				isset($_GET['activate'])
208
+				&& $_GET['activate'] === 'true'
209
+			)
210
+		) {
211
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
+		}
213
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * detect_activations_or_upgrades
220
+	 * Checks for activation or upgrade of core first;
221
+	 * then also checks if any registered addons have been activated or upgraded
222
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
+	 * which runs during the WP 'plugins_loaded' action at priority 3
224
+	 *
225
+	 * @access public
226
+	 * @return void
227
+	 */
228
+	public function detect_activations_or_upgrades()
229
+	{
230
+		//first off: let's make sure to handle core
231
+		$this->detect_if_activation_or_upgrade();
232
+		foreach ($this->registry->addons as $addon) {
233
+			//detect teh request type for that addon
234
+			$addon->detect_activation_or_upgrade();
235
+		}
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * detect_if_activation_or_upgrade
242
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
243
+	 * and either setting up the DB or setting up maintenance mode etc.
244
+	 *
245
+	 * @access public
246
+	 * @return void
247
+	 */
248
+	public function detect_if_activation_or_upgrade()
249
+	{
250
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
+		// load M-Mode class
252
+		$this->registry->load_core('Maintenance_Mode');
253
+		// check if db has been updated, or if its a brand-new installation
254
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
+		$request_type = $this->detect_req_type($espresso_db_update);
256
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
+		switch ($request_type) {
258
+			case EE_System::req_type_new_activation:
259
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
+				$this->_handle_core_version_change($espresso_db_update);
261
+				break;
262
+			case EE_System::req_type_reactivation:
263
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
+				$this->_handle_core_version_change($espresso_db_update);
265
+				break;
266
+			case EE_System::req_type_upgrade:
267
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
+				//migrations may be required now that we've upgraded
269
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
+				$this->_handle_core_version_change($espresso_db_update);
271
+				//				echo "done upgrade";die;
272
+				break;
273
+			case EE_System::req_type_downgrade:
274
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
+				//its possible migrations are no longer required
276
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
+				$this->_handle_core_version_change($espresso_db_update);
278
+				break;
279
+			case EE_System::req_type_normal:
280
+			default:
281
+				//				$this->_maybe_redirect_to_ee_about();
282
+				break;
283
+		}
284
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * Updates the list of installed versions and sets hooks for
291
+	 * initializing the database later during the request
292
+	 *
293
+	 * @param array $espresso_db_update
294
+	 */
295
+	protected function _handle_core_version_change($espresso_db_update)
296
+	{
297
+		$this->update_list_of_installed_versions($espresso_db_update);
298
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
+			array($this, 'initialize_db_if_no_migrations_required'));
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
+	 * information about what versions of EE have been installed and activated,
308
+	 * NOT necessarily the state of the database
309
+	 *
310
+	 * @param null $espresso_db_update
311
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
+	 *           from the options table
313
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
+	 */
315
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
+	{
317
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
+		if ( ! $espresso_db_update) {
319
+			$espresso_db_update = get_option('espresso_db_update');
320
+		}
321
+		// check that option is an array
322
+		if ( ! is_array($espresso_db_update)) {
323
+			// if option is FALSE, then it never existed
324
+			if ($espresso_db_update === false) {
325
+				// make $espresso_db_update an array and save option with autoload OFF
326
+				$espresso_db_update = array();
327
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
+			} else {
329
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
330
+				$espresso_db_update = array($espresso_db_update => array());
331
+				update_option('espresso_db_update', $espresso_db_update);
332
+			}
333
+		} else {
334
+			$corrected_db_update = array();
335
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
+					//the key is an int, and the value IS NOT an array
339
+					//so it must be numerically-indexed, where values are versions installed...
340
+					//fix it!
341
+					$version_string = $should_be_array;
342
+					$corrected_db_update[$version_string] = array('unknown-date');
343
+				} else {
344
+					//ok it checks out
345
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
346
+				}
347
+			}
348
+			$espresso_db_update = $corrected_db_update;
349
+			update_option('espresso_db_update', $espresso_db_update);
350
+		}
351
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
+		return $espresso_db_update;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Does the traditional work of setting up the plugin's database and adding default data.
359
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
+	 * so that it will be done when migrations are finished
363
+	 *
364
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
+	 *                                       This is a resource-intensive job
367
+	 *                                       so we prefer to only do it when necessary
368
+	 * @return void
369
+	 */
370
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
+	{
372
+		$request_type = $this->detect_req_type();
373
+		//only initialize system if we're not in maintenance mode.
374
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
+			update_option('ee_flush_rewrite_rules', true);
376
+			if ($verify_schema) {
377
+				EEH_Activation::initialize_db_and_folders();
378
+			}
379
+			EEH_Activation::initialize_db_content();
380
+			EEH_Activation::system_initialization();
381
+			if ($initialize_addons_too) {
382
+				$this->initialize_addons();
383
+			}
384
+		} else {
385
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
+		}
387
+		if ($request_type === EE_System::req_type_new_activation
388
+			|| $request_type === EE_System::req_type_reactivation
389
+			|| (
390
+				$request_type === EE_System::req_type_upgrade
391
+				&& $this->is_major_version_change()
392
+			)
393
+		) {
394
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
+		}
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Initializes the db for all registered addons
402
+	 */
403
+	public function initialize_addons()
404
+	{
405
+		//foreach registered addon, make sure its db is up-to-date too
406
+		foreach ($this->registry->addons as $addon) {
407
+			$addon->initialize_db_if_no_migrations_required();
408
+		}
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
+	 *
416
+	 * @param    array  $version_history
417
+	 * @param    string $current_version_to_add version to be added to the version history
418
+	 * @return    boolean success as to whether or not this option was changed
419
+	 */
420
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
+	{
422
+		if ( ! $version_history) {
423
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
+		}
425
+		if ($current_version_to_add == null) {
426
+			$current_version_to_add = espresso_version();
427
+		}
428
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
+		// re-save
430
+		return update_option('espresso_db_update', $version_history);
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * Detects if the current version indicated in the has existed in the list of
437
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
+	 *
439
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
+	 *                                  If not supplied, fetches it from the options table.
441
+	 *                                  Also, caches its result so later parts of the code can also know whether
442
+	 *                                  there's been an update or not. This way we can add the current version to
443
+	 *                                  espresso_db_update, but still know if this is a new install or not
444
+	 * @return int one of the constants on EE_System::req_type_
445
+	 */
446
+	public function detect_req_type($espresso_db_update = null)
447
+	{
448
+		if ($this->_req_type === null) {
449
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
+				: $this->fix_espresso_db_upgrade_option();
451
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
+				'ee_espresso_activation', espresso_version());
453
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
+		}
455
+		return $this->_req_type;
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * Returns whether or not there was a non-micro version change (ie, change in either
462
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
+	 *
465
+	 * @param $activation_history
466
+	 * @return bool
467
+	 */
468
+	protected function _detect_major_version_change($activation_history)
469
+	{
470
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
+		$previous_version_parts = explode('.', $previous_version);
472
+		$current_version_parts = explode('.', espresso_version());
473
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
475
+				   || $previous_version_parts[1] !== $current_version_parts[1]
476
+			   );
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Returns true if either the major or minor version of EE changed during this request.
483
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
484
+	 *
485
+	 * @return bool
486
+	 */
487
+	public function is_major_version_change()
488
+	{
489
+		return $this->_major_version_change;
490
+	}
491
+
492
+
493
+
494
+	/**
495
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
+	 * just activated to (for core that will always be espresso_version())
499
+	 *
500
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
502
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
+	 *                                                 indicate that this plugin was just activated
504
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
+	 *                                                 espresso_version())
506
+	 * @return int one of the constants on EE_System::req_type_*
507
+	 */
508
+	public static function detect_req_type_given_activation_history(
509
+		$activation_history_for_addon,
510
+		$activation_indicator_option_name,
511
+		$version_to_upgrade_to
512
+	) {
513
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
+		if ($activation_history_for_addon) {
515
+			//it exists, so this isn't a completely new install
516
+			//check if this version already in that list of previously installed versions
517
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
+				//it a version we haven't seen before
519
+				if ($version_is_higher === 1) {
520
+					$req_type = EE_System::req_type_upgrade;
521
+				} else {
522
+					$req_type = EE_System::req_type_downgrade;
523
+				}
524
+				delete_option($activation_indicator_option_name);
525
+			} else {
526
+				// its not an update. maybe a reactivation?
527
+				if (get_option($activation_indicator_option_name, false)) {
528
+					if ($version_is_higher === -1) {
529
+						$req_type = EE_System::req_type_downgrade;
530
+					} elseif ($version_is_higher === 0) {
531
+						//we've seen this version before, but it's an activation. must be a reactivation
532
+						$req_type = EE_System::req_type_reactivation;
533
+					} else {//$version_is_higher === 1
534
+						$req_type = EE_System::req_type_upgrade;
535
+					}
536
+					delete_option($activation_indicator_option_name);
537
+				} else {
538
+					//we've seen this version before and the activation indicate doesn't show it was just activated
539
+					if ($version_is_higher === -1) {
540
+						$req_type = EE_System::req_type_downgrade;
541
+					} elseif ($version_is_higher === 0) {
542
+						//we've seen this version before and it's not an activation. its normal request
543
+						$req_type = EE_System::req_type_normal;
544
+					} else {//$version_is_higher === 1
545
+						$req_type = EE_System::req_type_upgrade;
546
+					}
547
+				}
548
+			}
549
+		} else {
550
+			//brand new install
551
+			$req_type = EE_System::req_type_new_activation;
552
+			delete_option($activation_indicator_option_name);
553
+		}
554
+		return $req_type;
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
+	 * the $activation_history_for_addon
562
+	 *
563
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
+	 *                                             sometimes containing 'unknown-date'
565
+	 * @param string $version_to_upgrade_to        (current version)
566
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
+	 */
571
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
+	{
573
+		//find the most recently-activated version
574
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * Gets the most recently active version listed in the activation history,
582
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
+	 *
584
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
+	 *                                   sometimes containing 'unknown-date'
586
+	 * @return string
587
+	 */
588
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
+	{
590
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
591
+		$most_recently_active_version = '0.0.0.dev.000';
592
+		if (is_array($activation_history)) {
593
+			foreach ($activation_history as $version => $times_activated) {
594
+				//check there is a record of when this version was activated. Otherwise,
595
+				//mark it as unknown
596
+				if ( ! $times_activated) {
597
+					$times_activated = array('unknown-date');
598
+				}
599
+				if (is_string($times_activated)) {
600
+					$times_activated = array($times_activated);
601
+				}
602
+				foreach ($times_activated as $an_activation) {
603
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
+						$most_recently_active_version = $version;
605
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
606
+							? '1970-01-01 00:00:00' : $an_activation;
607
+					}
608
+				}
609
+			}
610
+		}
611
+		return $most_recently_active_version;
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This redirects to the about EE page after activation
618
+	 *
619
+	 * @return void
620
+	 */
621
+	public function redirect_to_about_ee()
622
+	{
623
+		$notices = EE_Error::get_notices(false);
624
+		//if current user is an admin and it's not an ajax or rest request
625
+		if (
626
+			! (defined('DOING_AJAX') && DOING_AJAX)
627
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
628
+			&& ! isset($notices['errors'])
629
+			&& apply_filters(
630
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
+			)
633
+		) {
634
+			$query_params = array('page' => 'espresso_about');
635
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
+				$query_params['new_activation'] = true;
637
+			}
638
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
+				$query_params['reactivation'] = true;
640
+			}
641
+			$url = add_query_arg($query_params, admin_url('admin.php'));
642
+			wp_safe_redirect($url);
643
+			exit();
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * load_core_configuration
651
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
+	 * which runs during the WP 'plugins_loaded' action at priority 5
653
+	 *
654
+	 * @return void
655
+	 */
656
+	public function load_core_configuration()
657
+	{
658
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
+		$this->registry->load_core('EE_Load_Textdomain');
660
+		//load textdomain
661
+		EE_Load_Textdomain::load_textdomain();
662
+		// load and setup EE_Config and EE_Network_Config
663
+		$this->registry->load_core('Config');
664
+		$this->registry->load_core('Network_Config');
665
+		// setup autoloaders
666
+		// enable logging?
667
+		if ($this->registry->CFG->admin->use_full_logging) {
668
+			$this->registry->load_core('Log');
669
+		}
670
+		// check for activation errors
671
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
672
+		if ($activation_errors) {
673
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
+			update_option('ee_plugin_activation_errors', false);
675
+		}
676
+		// get model names
677
+		$this->_parse_model_names();
678
+		//load caf stuff a chance to play during the activation process too.
679
+		$this->_maybe_brew_regular();
680
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
687
+	 *
688
+	 * @return void
689
+	 */
690
+	private function _parse_model_names()
691
+	{
692
+		//get all the files in the EE_MODELS folder that end in .model.php
693
+		$models = glob(EE_MODELS . '*.model.php');
694
+		$model_names = array();
695
+		$non_abstract_db_models = array();
696
+		foreach ($models as $model) {
697
+			// get model classname
698
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
+			$short_name = str_replace('EEM_', '', $classname);
700
+			$reflectionClass = new ReflectionClass($classname);
701
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
+				$non_abstract_db_models[$short_name] = $classname;
703
+			}
704
+			$model_names[$short_name] = $classname;
705
+		}
706
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
+			$non_abstract_db_models);
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
+	 * that need to be setup before our EE_System launches.
716
+	 *
717
+	 * @return void
718
+	 */
719
+	private function _maybe_brew_regular()
720
+	{
721
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
723
+		}
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * register_shortcodes_modules_and_widgets
730
+	 * generate lists of shortcodes and modules, then verify paths and classes
731
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
+	 * which runs during the WP 'plugins_loaded' action at priority 7
733
+	 *
734
+	 * @access public
735
+	 * @return void
736
+	 */
737
+	public function register_shortcodes_modules_and_widgets()
738
+	{
739
+		try {
740
+			// load, register, and add shortcodes the new way
741
+			new ShortcodesManager(
742
+			// and the old way, but we'll put it under control of the new system
743
+				EE_Config::getLegacyShortcodesManager()
744
+			);
745
+		} catch (Exception $exception) {
746
+			new ExceptionStackTraceDisplay($exception);
747
+		}
748
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
+		// check for addons using old hookpoint
750
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
+			$this->_incompatible_addon_error();
752
+		}
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * _incompatible_addon_error
759
+	 *
760
+	 * @access public
761
+	 * @return void
762
+	 */
763
+	private function _incompatible_addon_error()
764
+	{
765
+		// get array of classes hooking into here
766
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
+		if ( ! empty($class_names)) {
768
+			$msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
769
+				'event_espresso');
770
+			$msg .= '<ul>';
771
+			foreach ($class_names as $class_name) {
772
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+						$class_name) . '</b></li>';
774
+			}
775
+			$msg .= '</ul>';
776
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
+				'event_espresso');
778
+			// save list of incompatible addons to wp-options for later use
779
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
780
+			if (is_admin()) {
781
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
+			}
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * brew_espresso
790
+	 * begins the process of setting hooks for initializing EE in the correct order
791
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
+	 * which runs during the WP 'plugins_loaded' action at priority 9
793
+	 *
794
+	 * @return void
795
+	 */
796
+	public function brew_espresso()
797
+	{
798
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
+		// load some final core systems
800
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
801
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
+		add_action('init', array($this, 'load_controllers'), 7);
804
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
+		add_action('init', array($this, 'initialize'), 10);
806
+		add_action('init', array($this, 'initialize_last'), 100);
807
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
+			// pew pew pew
810
+			$this->registry->load_core('PUE');
811
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
+		}
813
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 *    set_hooks_for_core
820
+	 *
821
+	 * @access public
822
+	 * @return    void
823
+	 */
824
+	public function set_hooks_for_core()
825
+	{
826
+		$this->_deactivate_incompatible_addons();
827
+		do_action('AHEE__EE_System__set_hooks_for_core');
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
834
+	 * deactivates any addons considered incompatible with the current version of EE
835
+	 */
836
+	private function _deactivate_incompatible_addons()
837
+	{
838
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
839
+		if ( ! empty($incompatible_addons)) {
840
+			$active_plugins = get_option('active_plugins', array());
841
+			foreach ($active_plugins as $active_plugin) {
842
+				foreach ($incompatible_addons as $incompatible_addon) {
843
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
844
+						unset($_GET['activate']);
845
+						espresso_deactivate_plugin($active_plugin);
846
+					}
847
+				}
848
+			}
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 *    perform_activations_upgrades_and_migrations
856
+	 *
857
+	 * @access public
858
+	 * @return    void
859
+	 */
860
+	public function perform_activations_upgrades_and_migrations()
861
+	{
862
+		//first check if we had previously attempted to setup EE's directories but failed
863
+		if (EEH_Activation::upload_directories_incomplete()) {
864
+			EEH_Activation::create_upload_directories();
865
+		}
866
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 *    load_CPTs_and_session
873
+	 *
874
+	 * @access public
875
+	 * @return    void
876
+	 */
877
+	public function load_CPTs_and_session()
878
+	{
879
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
+		// register Custom Post Types
881
+		$this->registry->load_core('Register_CPTs');
882
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * load_controllers
889
+	 * this is the best place to load any additional controllers that needs access to EE core.
890
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
+	 * time
892
+	 *
893
+	 * @access public
894
+	 * @return void
895
+	 */
896
+	public function load_controllers()
897
+	{
898
+		do_action('AHEE__EE_System__load_controllers__start');
899
+		// let's get it started
900
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
+			$this->registry->load_core('Front_Controller');
903
+		} else if ( ! EE_FRONT_AJAX) {
904
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
+			EE_Registry::instance()->load_core('Admin');
906
+		}
907
+		do_action('AHEE__EE_System__load_controllers__complete');
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * core_loaded_and_ready
914
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
+	 *
916
+	 * @access public
917
+	 * @return void
918
+	 */
919
+	public function core_loaded_and_ready()
920
+	{
921
+		$this->registry->load_core('Session');
922
+		do_action('AHEE__EE_System__core_loaded_and_ready');
923
+		// load_espresso_template_tags
924
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
+			require_once(EE_PUBLIC . 'template_tags.php');
926
+		}
927
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
+		$this->registry->create('EventEspresso\core\services\assets\Registry', array(), true);
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * initialize
935
+	 * this is the best place to begin initializing client code
936
+	 *
937
+	 * @access public
938
+	 * @return void
939
+	 */
940
+	public function initialize()
941
+	{
942
+		do_action('AHEE__EE_System__initialize');
943
+	}
944
+
945
+
946
+
947
+	/**
948
+	 * initialize_last
949
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
950
+	 * initialize has done so
951
+	 *
952
+	 * @access public
953
+	 * @return void
954
+	 */
955
+	public function initialize_last()
956
+	{
957
+		do_action('AHEE__EE_System__initialize_last');
958
+	}
959
+
960
+
961
+
962
+	/**
963
+	 * set_hooks_for_shortcodes_modules_and_addons
964
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
965
+	 * this happens at the very beginning of the wp_loaded hookpoint
966
+	 *
967
+	 * @access public
968
+	 * @return void
969
+	 */
970
+	public function set_hooks_for_shortcodes_modules_and_addons()
971
+	{
972
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * do_not_cache
979
+	 * sets no cache headers and defines no cache constants for WP plugins
980
+	 *
981
+	 * @access public
982
+	 * @return void
983
+	 */
984
+	public static function do_not_cache()
985
+	{
986
+		// set no cache constants
987
+		if ( ! defined('DONOTCACHEPAGE')) {
988
+			define('DONOTCACHEPAGE', true);
989
+		}
990
+		if ( ! defined('DONOTCACHCEOBJECT')) {
991
+			define('DONOTCACHCEOBJECT', true);
992
+		}
993
+		if ( ! defined('DONOTCACHEDB')) {
994
+			define('DONOTCACHEDB', true);
995
+		}
996
+		// add no cache headers
997
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
998
+		// plus a little extra for nginx and Google Chrome
999
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1000
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1001
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 *    extra_nocache_headers
1008
+	 *
1009
+	 * @access    public
1010
+	 * @param $headers
1011
+	 * @return    array
1012
+	 */
1013
+	public static function extra_nocache_headers($headers)
1014
+	{
1015
+		// for NGINX
1016
+		$headers['X-Accel-Expires'] = 0;
1017
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1018
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1019
+		return $headers;
1020
+	}
1021
+
1022
+
1023
+
1024
+	/**
1025
+	 *    nocache_headers
1026
+	 *
1027
+	 * @access    public
1028
+	 * @return    void
1029
+	 */
1030
+	public static function nocache_headers()
1031
+	{
1032
+		nocache_headers();
1033
+	}
1034
+
1035
+
1036
+
1037
+	/**
1038
+	 *    espresso_toolbar_items
1039
+	 *
1040
+	 * @access public
1041
+	 * @param  WP_Admin_Bar $admin_bar
1042
+	 * @return void
1043
+	 */
1044
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1045
+	{
1046
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1047
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1048
+			|| defined('DOING_AJAX')
1049
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1050
+		) {
1051
+			return;
1052
+		}
1053
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1054
+		$menu_class = 'espresso_menu_item_class';
1055
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1056
+		//because they're only defined in each of their respective constructors
1057
+		//and this might be a frontend request, in which case they aren't available
1058
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1059
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1060
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1061
+		//Top Level
1062
+		$admin_bar->add_menu(array(
1063
+			'id'    => 'espresso-toolbar',
1064
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1065
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1066
+					   . '</span>',
1067
+			'href'  => $events_admin_url,
1068
+			'meta'  => array(
1069
+				'title' => __('Event Espresso', 'event_espresso'),
1070
+				'class' => $menu_class . 'first',
1071
+			),
1072
+		));
1073
+		//Events
1074
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1075
+			$admin_bar->add_menu(array(
1076
+				'id'     => 'espresso-toolbar-events',
1077
+				'parent' => 'espresso-toolbar',
1078
+				'title'  => __('Events', 'event_espresso'),
1079
+				'href'   => $events_admin_url,
1080
+				'meta'   => array(
1081
+					'title'  => __('Events', 'event_espresso'),
1082
+					'target' => '',
1083
+					'class'  => $menu_class,
1084
+				),
1085
+			));
1086
+		}
1087
+		if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1088
+			//Events Add New
1089
+			$admin_bar->add_menu(array(
1090
+				'id'     => 'espresso-toolbar-events-new',
1091
+				'parent' => 'espresso-toolbar-events',
1092
+				'title'  => __('Add New', 'event_espresso'),
1093
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1094
+				'meta'   => array(
1095
+					'title'  => __('Add New', 'event_espresso'),
1096
+					'target' => '',
1097
+					'class'  => $menu_class,
1098
+				),
1099
+			));
1100
+		}
1101
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1102
+			//Current post
1103
+			global $post;
1104
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1105
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1106
+			) {
1107
+				//Events Edit Current Event
1108
+				$admin_bar->add_menu(array(
1109
+					'id'     => 'espresso-toolbar-events-edit',
1110
+					'parent' => 'espresso-toolbar-events',
1111
+					'title'  => __('Edit Event', 'event_espresso'),
1112
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1113
+						$events_admin_url),
1114
+					'meta'   => array(
1115
+						'title'  => __('Edit Event', 'event_espresso'),
1116
+						'target' => '',
1117
+						'class'  => $menu_class,
1118
+					),
1119
+				));
1120
+			}
1121
+		}
1122
+		//Events View
1123
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1124
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1125
+		) {
1126
+			$admin_bar->add_menu(array(
1127
+				'id'     => 'espresso-toolbar-events-view',
1128
+				'parent' => 'espresso-toolbar-events',
1129
+				'title'  => __('View', 'event_espresso'),
1130
+				'href'   => $events_admin_url,
1131
+				'meta'   => array(
1132
+					'title'  => __('View', 'event_espresso'),
1133
+					'target' => '',
1134
+					'class'  => $menu_class,
1135
+				),
1136
+			));
1137
+		}
1138
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1139
+			//Events View All
1140
+			$admin_bar->add_menu(array(
1141
+				'id'     => 'espresso-toolbar-events-all',
1142
+				'parent' => 'espresso-toolbar-events-view',
1143
+				'title'  => __('All', 'event_espresso'),
1144
+				'href'   => $events_admin_url,
1145
+				'meta'   => array(
1146
+					'title'  => __('All', 'event_espresso'),
1147
+					'target' => '',
1148
+					'class'  => $menu_class,
1149
+				),
1150
+			));
1151
+		}
1152
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1153
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1154
+		) {
1155
+			//Events View Today
1156
+			$admin_bar->add_menu(array(
1157
+				'id'     => 'espresso-toolbar-events-today',
1158
+				'parent' => 'espresso-toolbar-events-view',
1159
+				'title'  => __('Today', 'event_espresso'),
1160
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1161
+					$events_admin_url),
1162
+				'meta'   => array(
1163
+					'title'  => __('Today', 'event_espresso'),
1164
+					'target' => '',
1165
+					'class'  => $menu_class,
1166
+				),
1167
+			));
1168
+		}
1169
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1170
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1171
+		) {
1172
+			//Events View This Month
1173
+			$admin_bar->add_menu(array(
1174
+				'id'     => 'espresso-toolbar-events-month',
1175
+				'parent' => 'espresso-toolbar-events-view',
1176
+				'title'  => __('This Month', 'event_espresso'),
1177
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1178
+					$events_admin_url),
1179
+				'meta'   => array(
1180
+					'title'  => __('This Month', 'event_espresso'),
1181
+					'target' => '',
1182
+					'class'  => $menu_class,
1183
+				),
1184
+			));
1185
+		}
1186
+		//Registration Overview
1187
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1188
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1189
+		) {
1190
+			$admin_bar->add_menu(array(
1191
+				'id'     => 'espresso-toolbar-registrations',
1192
+				'parent' => 'espresso-toolbar',
1193
+				'title'  => __('Registrations', 'event_espresso'),
1194
+				'href'   => $reg_admin_url,
1195
+				'meta'   => array(
1196
+					'title'  => __('Registrations', 'event_espresso'),
1197
+					'target' => '',
1198
+					'class'  => $menu_class,
1199
+				),
1200
+			));
1201
+		}
1202
+		//Registration Overview Today
1203
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1204
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1205
+		) {
1206
+			$admin_bar->add_menu(array(
1207
+				'id'     => 'espresso-toolbar-registrations-today',
1208
+				'parent' => 'espresso-toolbar-registrations',
1209
+				'title'  => __('Today', 'event_espresso'),
1210
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1211
+					$reg_admin_url),
1212
+				'meta'   => array(
1213
+					'title'  => __('Today', 'event_espresso'),
1214
+					'target' => '',
1215
+					'class'  => $menu_class,
1216
+				),
1217
+			));
1218
+		}
1219
+		//Registration Overview Today Completed
1220
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1221
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1222
+		) {
1223
+			$admin_bar->add_menu(array(
1224
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1225
+				'parent' => 'espresso-toolbar-registrations-today',
1226
+				'title'  => __('Approved', 'event_espresso'),
1227
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1228
+					'action'      => 'default',
1229
+					'status'      => 'today',
1230
+					'_reg_status' => EEM_Registration::status_id_approved,
1231
+				), $reg_admin_url),
1232
+				'meta'   => array(
1233
+					'title'  => __('Approved', 'event_espresso'),
1234
+					'target' => '',
1235
+					'class'  => $menu_class,
1236
+				),
1237
+			));
1238
+		}
1239
+		//Registration Overview Today Pending\
1240
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1241
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1242
+		) {
1243
+			$admin_bar->add_menu(array(
1244
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1245
+				'parent' => 'espresso-toolbar-registrations-today',
1246
+				'title'  => __('Pending', 'event_espresso'),
1247
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1248
+					'action'     => 'default',
1249
+					'status'     => 'today',
1250
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1251
+				), $reg_admin_url),
1252
+				'meta'   => array(
1253
+					'title'  => __('Pending Payment', 'event_espresso'),
1254
+					'target' => '',
1255
+					'class'  => $menu_class,
1256
+				),
1257
+			));
1258
+		}
1259
+		//Registration Overview Today Incomplete
1260
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1261
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1262
+		) {
1263
+			$admin_bar->add_menu(array(
1264
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1265
+				'parent' => 'espresso-toolbar-registrations-today',
1266
+				'title'  => __('Not Approved', 'event_espresso'),
1267
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1268
+					'action'      => 'default',
1269
+					'status'      => 'today',
1270
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1271
+				), $reg_admin_url),
1272
+				'meta'   => array(
1273
+					'title'  => __('Not Approved', 'event_espresso'),
1274
+					'target' => '',
1275
+					'class'  => $menu_class,
1276
+				),
1277
+			));
1278
+		}
1279
+		//Registration Overview Today Incomplete
1280
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1281
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1282
+		) {
1283
+			$admin_bar->add_menu(array(
1284
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1285
+				'parent' => 'espresso-toolbar-registrations-today',
1286
+				'title'  => __('Cancelled', 'event_espresso'),
1287
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1288
+					'action'      => 'default',
1289
+					'status'      => 'today',
1290
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1291
+				), $reg_admin_url),
1292
+				'meta'   => array(
1293
+					'title'  => __('Cancelled', 'event_espresso'),
1294
+					'target' => '',
1295
+					'class'  => $menu_class,
1296
+				),
1297
+			));
1298
+		}
1299
+		//Registration Overview This Month
1300
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1301
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1302
+		) {
1303
+			$admin_bar->add_menu(array(
1304
+				'id'     => 'espresso-toolbar-registrations-month',
1305
+				'parent' => 'espresso-toolbar-registrations',
1306
+				'title'  => __('This Month', 'event_espresso'),
1307
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1308
+					$reg_admin_url),
1309
+				'meta'   => array(
1310
+					'title'  => __('This Month', 'event_espresso'),
1311
+					'target' => '',
1312
+					'class'  => $menu_class,
1313
+				),
1314
+			));
1315
+		}
1316
+		//Registration Overview This Month Approved
1317
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1318
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1319
+		) {
1320
+			$admin_bar->add_menu(array(
1321
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1322
+				'parent' => 'espresso-toolbar-registrations-month',
1323
+				'title'  => __('Approved', 'event_espresso'),
1324
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1325
+					'action'      => 'default',
1326
+					'status'      => 'month',
1327
+					'_reg_status' => EEM_Registration::status_id_approved,
1328
+				), $reg_admin_url),
1329
+				'meta'   => array(
1330
+					'title'  => __('Approved', 'event_espresso'),
1331
+					'target' => '',
1332
+					'class'  => $menu_class,
1333
+				),
1334
+			));
1335
+		}
1336
+		//Registration Overview This Month Pending
1337
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1338
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1339
+		) {
1340
+			$admin_bar->add_menu(array(
1341
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1342
+				'parent' => 'espresso-toolbar-registrations-month',
1343
+				'title'  => __('Pending', 'event_espresso'),
1344
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1345
+					'action'      => 'default',
1346
+					'status'      => 'month',
1347
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1348
+				), $reg_admin_url),
1349
+				'meta'   => array(
1350
+					'title'  => __('Pending', 'event_espresso'),
1351
+					'target' => '',
1352
+					'class'  => $menu_class,
1353
+				),
1354
+			));
1355
+		}
1356
+		//Registration Overview This Month Not Approved
1357
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1358
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1359
+		) {
1360
+			$admin_bar->add_menu(array(
1361
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1362
+				'parent' => 'espresso-toolbar-registrations-month',
1363
+				'title'  => __('Not Approved', 'event_espresso'),
1364
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1365
+					'action'      => 'default',
1366
+					'status'      => 'month',
1367
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1368
+				), $reg_admin_url),
1369
+				'meta'   => array(
1370
+					'title'  => __('Not Approved', 'event_espresso'),
1371
+					'target' => '',
1372
+					'class'  => $menu_class,
1373
+				),
1374
+			));
1375
+		}
1376
+		//Registration Overview This Month Cancelled
1377
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1378
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1379
+		) {
1380
+			$admin_bar->add_menu(array(
1381
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1382
+				'parent' => 'espresso-toolbar-registrations-month',
1383
+				'title'  => __('Cancelled', 'event_espresso'),
1384
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1385
+					'action'      => 'default',
1386
+					'status'      => 'month',
1387
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1388
+				), $reg_admin_url),
1389
+				'meta'   => array(
1390
+					'title'  => __('Cancelled', 'event_espresso'),
1391
+					'target' => '',
1392
+					'class'  => $menu_class,
1393
+				),
1394
+			));
1395
+		}
1396
+		//Extensions & Services
1397
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1398
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1399
+		) {
1400
+			$admin_bar->add_menu(array(
1401
+				'id'     => 'espresso-toolbar-extensions-and-services',
1402
+				'parent' => 'espresso-toolbar',
1403
+				'title'  => __('Extensions & Services', 'event_espresso'),
1404
+				'href'   => $extensions_admin_url,
1405
+				'meta'   => array(
1406
+					'title'  => __('Extensions & Services', 'event_espresso'),
1407
+					'target' => '',
1408
+					'class'  => $menu_class,
1409
+				),
1410
+			));
1411
+		}
1412
+	}
1413
+
1414
+
1415
+
1416
+	/**
1417
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1418
+	 * never returned with the function.
1419
+	 *
1420
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1421
+	 * @return array
1422
+	 */
1423
+	public function remove_pages_from_wp_list_pages($exclude_array)
1424
+	{
1425
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1426
+	}
1427 1427
 
1428 1428
 
1429 1429
 
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14 14
 if (! defined('EVENT_ESPRESSO_VERSION')) {
15
-    exit('No direct script access allowed');
15
+	exit('No direct script access allowed');
16 16
 }
17 17
 
18 18
 
@@ -31,642 +31,642 @@  discard block
 block discarded – undo
31 31
 abstract class FormHandler implements FormHandlerInterface
32 32
 {
33 33
 
34
-    /**
35
-     * will add opening and closing HTML form tags as well as a submit button
36
-     */
37
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
-
39
-    /**
40
-     * will add opening and closing HTML form tags but NOT a submit button
41
-     */
42
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
-
44
-    /**
45
-     * will NOT add opening and closing HTML form tags but will add a submit button
46
-     */
47
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
-
49
-    /**
50
-     * will NOT add opening and closing HTML form tags NOR a submit button
51
-     */
52
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
-
54
-    /**
55
-     * if set to false, then this form has no displayable content,
56
-     * and will only be used for processing data sent passed via GET or POST
57
-     * defaults to true ( ie: form has displayable content )
58
-     *
59
-     * @var boolean $displayable
60
-     */
61
-    private $displayable = true;
62
-
63
-    /**
64
-     * @var string $form_name
65
-     */
66
-    private $form_name;
67
-
68
-    /**
69
-     * @var string $admin_name
70
-     */
71
-    private $admin_name;
72
-
73
-    /**
74
-     * @var string $slug
75
-     */
76
-    private $slug;
77
-
78
-    /**
79
-     * @var string $submit_btn_text
80
-     */
81
-    private $submit_btn_text;
82
-
83
-    /**
84
-     * @var string $form_action
85
-     */
86
-    private $form_action;
87
-
88
-    /**
89
-     * form params in key value pairs
90
-     * can be added to form action URL or as hidden inputs
91
-     *
92
-     * @var array $form_args
93
-     */
94
-    private $form_args = array();
95
-
96
-    /**
97
-     * value of one of the string constant above
98
-     *
99
-     * @var string $form_config
100
-     */
101
-    private $form_config;
102
-
103
-    /**
104
-     * whether or not the form was determined to be invalid
105
-     *
106
-     * @var boolean $form_has_errors
107
-     */
108
-    private $form_has_errors;
109
-
110
-    /**
111
-     * the absolute top level form section being used on the page
112
-     *
113
-     * @var \EE_Form_Section_Proper $form
114
-     */
115
-    private $form;
116
-
117
-    /**
118
-     * @var \EE_Registry $registry
119
-     */
120
-    protected $registry;
121
-
122
-
123
-
124
-    /**
125
-     * Form constructor.
126
-     *
127
-     * @param string       $form_name
128
-     * @param string       $admin_name
129
-     * @param string       $slug
130
-     * @param string       $form_action
131
-     * @param string       $form_config
132
-     * @param \EE_Registry $registry
133
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
-     * @throws \DomainException
135
-     * @throws \InvalidArgumentException
136
-     */
137
-    public function __construct(
138
-        $form_name,
139
-        $admin_name,
140
-        $slug,
141
-        $form_action = '',
142
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
-        \EE_Registry $registry
144
-    ) {
145
-        $this->setFormName($form_name);
146
-        $this->setAdminName($admin_name);
147
-        $this->setSlug($slug);
148
-        $this->setFormAction($form_action);
149
-        $this->setFormConfig($form_config);
150
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
-        $this->registry = $registry;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @return array
158
-     */
159
-    public static function getFormConfigConstants()
160
-    {
161
-        return array(
162
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
-            FormHandler::ADD_FORM_TAGS_ONLY,
164
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
165
-            FormHandler::DO_NOT_SETUP_FORM,
166
-        );
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param bool $for_display
173
-     * @return \EE_Form_Section_Proper
174
-     * @throws \EE_Error
175
-     * @throws \LogicException
176
-     */
177
-    public function form($for_display = false)
178
-    {
179
-        if (! $this->formIsValid()) {
180
-            return null;
181
-        }
182
-        if ($for_display) {
183
-            $form_config = $this->formConfig();
184
-            if (
185
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
-            ) {
188
-                $this->appendSubmitButton();
189
-                $this->clearFormButtonFloats();
190
-            }
191
-        }
192
-        return $this->form;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @return boolean
199
-     * @throws LogicException
200
-     */
201
-    public function formIsValid()
202
-    {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
204
-            static $generated = false;
205
-            if (! $generated) {
206
-                $generated = true;
207
-                $form = apply_filters(
208
-                    'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
209
-                    $this->generate(),
210
-                    $this
211
-                );
212
-                if ($form instanceof \EE_Form_Section_Proper) {
213
-                    $this->setForm($form);
214
-                }
215
-            }
216
-            return $this->verifyForm();
217
-        }
218
-        return true;
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * @return boolean
225
-     * @throws LogicException
226
-     */
227
-    public function verifyForm()
228
-    {
229
-        if ($this->form instanceof \EE_Form_Section_Proper) {
230
-            return true;
231
-        }
232
-        throw new LogicException(
233
-            sprintf(
234
-                esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
235
-                $this->form_name
236
-            )
237
-        );
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * @param \EE_Form_Section_Proper $form
244
-     */
245
-    public function setForm(\EE_Form_Section_Proper $form)
246
-    {
247
-        $this->form = $form;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @return boolean
254
-     */
255
-    public function displayable()
256
-    {
257
-        return $this->displayable;
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * @param boolean $displayable
264
-     */
265
-    public function setDisplayable($displayable = false)
266
-    {
267
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * a public name for the form that can be displayed on the frontend of a site
274
-     *
275
-     * @return string
276
-     */
277
-    public function formName()
278
-    {
279
-        return $this->form_name;
280
-    }
281
-
282
-
283
-
284
-    /**
285
-     * @param string $form_name
286
-     * @throws InvalidDataTypeException
287
-     */
288
-    public function setFormName($form_name)
289
-    {
290
-        if (! is_string($form_name)) {
291
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
292
-        }
293
-        $this->form_name = $form_name;
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * a public name for the form that can be displayed, but only in the admin
300
-     *
301
-     * @return string
302
-     */
303
-    public function adminName()
304
-    {
305
-        return $this->admin_name;
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * @param string $admin_name
312
-     * @throws InvalidDataTypeException
313
-     */
314
-    public function setAdminName($admin_name)
315
-    {
316
-        if (! is_string($admin_name)) {
317
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
318
-        }
319
-        $this->admin_name = $admin_name;
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * a URL friendly string that can be used for identifying the form
326
-     *
327
-     * @return string
328
-     */
329
-    public function slug()
330
-    {
331
-        return $this->slug;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param string $slug
338
-     * @throws InvalidDataTypeException
339
-     */
340
-    public function setSlug($slug)
341
-    {
342
-        if (! is_string($slug)) {
343
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
344
-        }
345
-        $this->slug = $slug;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * @return string
352
-     */
353
-    public function submitBtnText()
354
-    {
355
-        return $this->submit_btn_text;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * @param string $submit_btn_text
362
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
363
-     * @throws \InvalidArgumentException
364
-     */
365
-    public function setSubmitBtnText($submit_btn_text)
366
-    {
367
-        if (! is_string($submit_btn_text)) {
368
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
369
-        }
370
-        if (empty($submit_btn_text)) {
371
-            throw new InvalidArgumentException(
372
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
373
-            );
374
-        }
375
-        $this->submit_btn_text = $submit_btn_text;
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * @return string
382
-     */
383
-    public function formAction()
384
-    {
385
-        return ! empty($this->form_args)
386
-            ? add_query_arg($this->form_args, $this->form_action)
387
-            : $this->form_action;
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * @param string $form_action
394
-     * @throws InvalidDataTypeException
395
-     */
396
-    public function setFormAction($form_action)
397
-    {
398
-        if (! is_string($form_action)) {
399
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
400
-        }
401
-        $this->form_action = $form_action;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * @param array $form_args
408
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
409
-     * @throws \InvalidArgumentException
410
-     */
411
-    public function addFormActionArgs($form_args = array())
412
-    {
413
-        if (is_object($form_args)) {
414
-            throw new InvalidDataTypeException(
415
-                '$form_args',
416
-                $form_args,
417
-                'anything other than an object was expected.'
418
-            );
419
-        }
420
-        if (empty($form_args)) {
421
-            throw new InvalidArgumentException(
422
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
423
-            );
424
-        }
425
-        $this->form_args = array_merge($this->form_args, $form_args);
426
-    }
427
-
428
-
429
-
430
-    /**
431
-     * @return string
432
-     */
433
-    public function formConfig()
434
-    {
435
-        return $this->form_config;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * @param string $form_config
442
-     * @throws DomainException
443
-     */
444
-    public function setFormConfig($form_config)
445
-    {
446
-        if (
447
-        ! in_array(
448
-            $form_config,
449
-            array(
450
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
451
-                FormHandler::ADD_FORM_TAGS_ONLY,
452
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
453
-                FormHandler::DO_NOT_SETUP_FORM,
454
-            ),
455
-            true
456
-        )
457
-        ) {
458
-            throw new DomainException(
459
-                sprintf(
460
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
461
-                        'event_espresso'),
462
-                    $form_config
463
-                )
464
-            );
465
-        }
466
-        $this->form_config = $form_config;
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * called after the form is instantiated
473
-     * and used for performing any logic that needs to occur early
474
-     * before any of the other methods are called.
475
-     * returns true if everything is ok to proceed,
476
-     * and false if no further form logic should be implemented
477
-     *
478
-     * @return boolean
479
-     */
480
-    public function initialize()
481
-    {
482
-        $this->form_has_errors = \EE_Error::has_error(true);
483
-        return true;
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * used for setting up css and js
490
-     *
491
-     * @return void
492
-     * @throws LogicException
493
-     * @throws \EE_Error
494
-     */
495
-    public function enqueueStylesAndScripts()
496
-    {
497
-        $this->form(false)->enqueue_js();
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * creates and returns the actual form
504
-     *
505
-     * @return EE_Form_Section_Proper
506
-     */
507
-    abstract public function generate();
508
-
509
-
510
-
511
-    /**
512
-     * creates and returns an EE_Submit_Input labeled "Submit"
513
-     *
514
-     * @param string $text
515
-     * @return \EE_Submit_Input
516
-     */
517
-    public function generateSubmitButton($text = '')
518
-    {
519
-        $text = ! empty($text) ? $text : $this->submitBtnText();
520
-        return new EE_Submit_Input(
521
-            array(
522
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
523
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
524
-                'html_class'            => 'ee-form-submit',
525
-                'html_label'            => '&nbsp;',
526
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
527
-                'default'               => $text,
528
-            )
529
-        );
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
536
-     *
537
-     * @param string $text
538
-     * @return void
539
-     * @throws \LogicException
540
-     * @throws \EE_Error
541
-     */
542
-    public function appendSubmitButton($text = '')
543
-    {
544
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
545
-            return;
546
-        }
547
-        $this->form->add_subsections(
548
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
549
-            null,
550
-            false
551
-        );
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     * creates and returns an EE_Submit_Input labeled "Cancel"
558
-     *
559
-     * @param string $text
560
-     * @return \EE_Submit_Input
561
-     */
562
-    public function generateCancelButton($text = '')
563
-    {
564
-        $cancel_button = new EE_Submit_Input(
565
-            array(
566
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
567
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
568
-                'html_class'            => 'ee-cancel-form',
569
-                'html_label'            => '&nbsp;',
570
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
571
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
572
-            )
573
-        );
574
-        $cancel_button->set_button_css_attributes(false);
575
-        return $cancel_button;
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * appends a float clearing div onto end of form
582
-     *
583
-     * @return void
584
-     * @throws \EE_Error
585
-     */
586
-    public function clearFormButtonFloats()
587
-    {
588
-        $this->form->add_subsections(
589
-            array(
590
-                'clear-submit-btn-float' => new \EE_Form_Section_HTML(
591
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
592
-                ),
593
-            ),
594
-            null,
595
-            false
596
-        );
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
603
-     * returns a string of HTML that can be directly echoed in a template
604
-     *
605
-     * @return string
606
-     * @throws LogicException
607
-     * @throws \EE_Error
608
-     */
609
-    public function display()
610
-    {
611
-        $form_html = apply_filters(
612
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
613
-            ''
614
-        );
615
-        $form_config = $this->formConfig();
616
-        if (
617
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
618
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
619
-        ) {
620
-            $form_html .= $this->form()->form_open($this->formAction());
621
-        }
622
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
623
-        if (
624
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
625
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
626
-        ) {
627
-            $form_html .= $this->form()->form_close();
628
-        }
629
-        $form_html .= apply_filters(
630
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
631
-            ''
632
-        );
633
-        return $form_html;
634
-    }
635
-
636
-
637
-
638
-    /**
639
-     * handles processing the form submission
640
-     * returns true or false depending on whether the form was processed successfully or not
641
-     *
642
-     * @param array $submitted_form_data
643
-     * @return array
644
-     * @throws \EE_Error
645
-     * @throws \LogicException
646
-     * @throws InvalidFormSubmissionException
647
-     */
648
-    public function process($submitted_form_data = array())
649
-    {
650
-        if (! $this->form()->was_submitted($submitted_form_data)) {
651
-            throw new InvalidFormSubmissionException($this->form_name);
652
-        }
653
-        $this->form(true)->receive_form_submission($submitted_form_data);
654
-        if (! $this->form()->is_valid()) {
655
-            throw new InvalidFormSubmissionException(
656
-                $this->form_name,
657
-                sprintf(
658
-                    esc_html__(
659
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
660
-                        'event_espresso'
661
-                    ),
662
-                    $this->form_name,
663
-                    '<br />',
664
-                    $this->form()->submission_error_message()
665
-                )
666
-            );
667
-        }
668
-        return $this->form()->valid_data();
669
-    }
34
+	/**
35
+	 * will add opening and closing HTML form tags as well as a submit button
36
+	 */
37
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
+
39
+	/**
40
+	 * will add opening and closing HTML form tags but NOT a submit button
41
+	 */
42
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
+
44
+	/**
45
+	 * will NOT add opening and closing HTML form tags but will add a submit button
46
+	 */
47
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
+
49
+	/**
50
+	 * will NOT add opening and closing HTML form tags NOR a submit button
51
+	 */
52
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
+
54
+	/**
55
+	 * if set to false, then this form has no displayable content,
56
+	 * and will only be used for processing data sent passed via GET or POST
57
+	 * defaults to true ( ie: form has displayable content )
58
+	 *
59
+	 * @var boolean $displayable
60
+	 */
61
+	private $displayable = true;
62
+
63
+	/**
64
+	 * @var string $form_name
65
+	 */
66
+	private $form_name;
67
+
68
+	/**
69
+	 * @var string $admin_name
70
+	 */
71
+	private $admin_name;
72
+
73
+	/**
74
+	 * @var string $slug
75
+	 */
76
+	private $slug;
77
+
78
+	/**
79
+	 * @var string $submit_btn_text
80
+	 */
81
+	private $submit_btn_text;
82
+
83
+	/**
84
+	 * @var string $form_action
85
+	 */
86
+	private $form_action;
87
+
88
+	/**
89
+	 * form params in key value pairs
90
+	 * can be added to form action URL or as hidden inputs
91
+	 *
92
+	 * @var array $form_args
93
+	 */
94
+	private $form_args = array();
95
+
96
+	/**
97
+	 * value of one of the string constant above
98
+	 *
99
+	 * @var string $form_config
100
+	 */
101
+	private $form_config;
102
+
103
+	/**
104
+	 * whether or not the form was determined to be invalid
105
+	 *
106
+	 * @var boolean $form_has_errors
107
+	 */
108
+	private $form_has_errors;
109
+
110
+	/**
111
+	 * the absolute top level form section being used on the page
112
+	 *
113
+	 * @var \EE_Form_Section_Proper $form
114
+	 */
115
+	private $form;
116
+
117
+	/**
118
+	 * @var \EE_Registry $registry
119
+	 */
120
+	protected $registry;
121
+
122
+
123
+
124
+	/**
125
+	 * Form constructor.
126
+	 *
127
+	 * @param string       $form_name
128
+	 * @param string       $admin_name
129
+	 * @param string       $slug
130
+	 * @param string       $form_action
131
+	 * @param string       $form_config
132
+	 * @param \EE_Registry $registry
133
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
+	 * @throws \DomainException
135
+	 * @throws \InvalidArgumentException
136
+	 */
137
+	public function __construct(
138
+		$form_name,
139
+		$admin_name,
140
+		$slug,
141
+		$form_action = '',
142
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
+		\EE_Registry $registry
144
+	) {
145
+		$this->setFormName($form_name);
146
+		$this->setAdminName($admin_name);
147
+		$this->setSlug($slug);
148
+		$this->setFormAction($form_action);
149
+		$this->setFormConfig($form_config);
150
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
+		$this->registry = $registry;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @return array
158
+	 */
159
+	public static function getFormConfigConstants()
160
+	{
161
+		return array(
162
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
+			FormHandler::ADD_FORM_TAGS_ONLY,
164
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
165
+			FormHandler::DO_NOT_SETUP_FORM,
166
+		);
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param bool $for_display
173
+	 * @return \EE_Form_Section_Proper
174
+	 * @throws \EE_Error
175
+	 * @throws \LogicException
176
+	 */
177
+	public function form($for_display = false)
178
+	{
179
+		if (! $this->formIsValid()) {
180
+			return null;
181
+		}
182
+		if ($for_display) {
183
+			$form_config = $this->formConfig();
184
+			if (
185
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
+			) {
188
+				$this->appendSubmitButton();
189
+				$this->clearFormButtonFloats();
190
+			}
191
+		}
192
+		return $this->form;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @return boolean
199
+	 * @throws LogicException
200
+	 */
201
+	public function formIsValid()
202
+	{
203
+		if (! $this->form instanceof \EE_Form_Section_Proper) {
204
+			static $generated = false;
205
+			if (! $generated) {
206
+				$generated = true;
207
+				$form = apply_filters(
208
+					'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
209
+					$this->generate(),
210
+					$this
211
+				);
212
+				if ($form instanceof \EE_Form_Section_Proper) {
213
+					$this->setForm($form);
214
+				}
215
+			}
216
+			return $this->verifyForm();
217
+		}
218
+		return true;
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * @return boolean
225
+	 * @throws LogicException
226
+	 */
227
+	public function verifyForm()
228
+	{
229
+		if ($this->form instanceof \EE_Form_Section_Proper) {
230
+			return true;
231
+		}
232
+		throw new LogicException(
233
+			sprintf(
234
+				esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
235
+				$this->form_name
236
+			)
237
+		);
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * @param \EE_Form_Section_Proper $form
244
+	 */
245
+	public function setForm(\EE_Form_Section_Proper $form)
246
+	{
247
+		$this->form = $form;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @return boolean
254
+	 */
255
+	public function displayable()
256
+	{
257
+		return $this->displayable;
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * @param boolean $displayable
264
+	 */
265
+	public function setDisplayable($displayable = false)
266
+	{
267
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * a public name for the form that can be displayed on the frontend of a site
274
+	 *
275
+	 * @return string
276
+	 */
277
+	public function formName()
278
+	{
279
+		return $this->form_name;
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * @param string $form_name
286
+	 * @throws InvalidDataTypeException
287
+	 */
288
+	public function setFormName($form_name)
289
+	{
290
+		if (! is_string($form_name)) {
291
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
292
+		}
293
+		$this->form_name = $form_name;
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * a public name for the form that can be displayed, but only in the admin
300
+	 *
301
+	 * @return string
302
+	 */
303
+	public function adminName()
304
+	{
305
+		return $this->admin_name;
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * @param string $admin_name
312
+	 * @throws InvalidDataTypeException
313
+	 */
314
+	public function setAdminName($admin_name)
315
+	{
316
+		if (! is_string($admin_name)) {
317
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
318
+		}
319
+		$this->admin_name = $admin_name;
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * a URL friendly string that can be used for identifying the form
326
+	 *
327
+	 * @return string
328
+	 */
329
+	public function slug()
330
+	{
331
+		return $this->slug;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param string $slug
338
+	 * @throws InvalidDataTypeException
339
+	 */
340
+	public function setSlug($slug)
341
+	{
342
+		if (! is_string($slug)) {
343
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
344
+		}
345
+		$this->slug = $slug;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * @return string
352
+	 */
353
+	public function submitBtnText()
354
+	{
355
+		return $this->submit_btn_text;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * @param string $submit_btn_text
362
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
363
+	 * @throws \InvalidArgumentException
364
+	 */
365
+	public function setSubmitBtnText($submit_btn_text)
366
+	{
367
+		if (! is_string($submit_btn_text)) {
368
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
369
+		}
370
+		if (empty($submit_btn_text)) {
371
+			throw new InvalidArgumentException(
372
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
373
+			);
374
+		}
375
+		$this->submit_btn_text = $submit_btn_text;
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * @return string
382
+	 */
383
+	public function formAction()
384
+	{
385
+		return ! empty($this->form_args)
386
+			? add_query_arg($this->form_args, $this->form_action)
387
+			: $this->form_action;
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * @param string $form_action
394
+	 * @throws InvalidDataTypeException
395
+	 */
396
+	public function setFormAction($form_action)
397
+	{
398
+		if (! is_string($form_action)) {
399
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
400
+		}
401
+		$this->form_action = $form_action;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * @param array $form_args
408
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
409
+	 * @throws \InvalidArgumentException
410
+	 */
411
+	public function addFormActionArgs($form_args = array())
412
+	{
413
+		if (is_object($form_args)) {
414
+			throw new InvalidDataTypeException(
415
+				'$form_args',
416
+				$form_args,
417
+				'anything other than an object was expected.'
418
+			);
419
+		}
420
+		if (empty($form_args)) {
421
+			throw new InvalidArgumentException(
422
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
423
+			);
424
+		}
425
+		$this->form_args = array_merge($this->form_args, $form_args);
426
+	}
427
+
428
+
429
+
430
+	/**
431
+	 * @return string
432
+	 */
433
+	public function formConfig()
434
+	{
435
+		return $this->form_config;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * @param string $form_config
442
+	 * @throws DomainException
443
+	 */
444
+	public function setFormConfig($form_config)
445
+	{
446
+		if (
447
+		! in_array(
448
+			$form_config,
449
+			array(
450
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
451
+				FormHandler::ADD_FORM_TAGS_ONLY,
452
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
453
+				FormHandler::DO_NOT_SETUP_FORM,
454
+			),
455
+			true
456
+		)
457
+		) {
458
+			throw new DomainException(
459
+				sprintf(
460
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
461
+						'event_espresso'),
462
+					$form_config
463
+				)
464
+			);
465
+		}
466
+		$this->form_config = $form_config;
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * called after the form is instantiated
473
+	 * and used for performing any logic that needs to occur early
474
+	 * before any of the other methods are called.
475
+	 * returns true if everything is ok to proceed,
476
+	 * and false if no further form logic should be implemented
477
+	 *
478
+	 * @return boolean
479
+	 */
480
+	public function initialize()
481
+	{
482
+		$this->form_has_errors = \EE_Error::has_error(true);
483
+		return true;
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * used for setting up css and js
490
+	 *
491
+	 * @return void
492
+	 * @throws LogicException
493
+	 * @throws \EE_Error
494
+	 */
495
+	public function enqueueStylesAndScripts()
496
+	{
497
+		$this->form(false)->enqueue_js();
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * creates and returns the actual form
504
+	 *
505
+	 * @return EE_Form_Section_Proper
506
+	 */
507
+	abstract public function generate();
508
+
509
+
510
+
511
+	/**
512
+	 * creates and returns an EE_Submit_Input labeled "Submit"
513
+	 *
514
+	 * @param string $text
515
+	 * @return \EE_Submit_Input
516
+	 */
517
+	public function generateSubmitButton($text = '')
518
+	{
519
+		$text = ! empty($text) ? $text : $this->submitBtnText();
520
+		return new EE_Submit_Input(
521
+			array(
522
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
523
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
524
+				'html_class'            => 'ee-form-submit',
525
+				'html_label'            => '&nbsp;',
526
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
527
+				'default'               => $text,
528
+			)
529
+		);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
536
+	 *
537
+	 * @param string $text
538
+	 * @return void
539
+	 * @throws \LogicException
540
+	 * @throws \EE_Error
541
+	 */
542
+	public function appendSubmitButton($text = '')
543
+	{
544
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
545
+			return;
546
+		}
547
+		$this->form->add_subsections(
548
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
549
+			null,
550
+			false
551
+		);
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
558
+	 *
559
+	 * @param string $text
560
+	 * @return \EE_Submit_Input
561
+	 */
562
+	public function generateCancelButton($text = '')
563
+	{
564
+		$cancel_button = new EE_Submit_Input(
565
+			array(
566
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
567
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
568
+				'html_class'            => 'ee-cancel-form',
569
+				'html_label'            => '&nbsp;',
570
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
571
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
572
+			)
573
+		);
574
+		$cancel_button->set_button_css_attributes(false);
575
+		return $cancel_button;
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * appends a float clearing div onto end of form
582
+	 *
583
+	 * @return void
584
+	 * @throws \EE_Error
585
+	 */
586
+	public function clearFormButtonFloats()
587
+	{
588
+		$this->form->add_subsections(
589
+			array(
590
+				'clear-submit-btn-float' => new \EE_Form_Section_HTML(
591
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
592
+				),
593
+			),
594
+			null,
595
+			false
596
+		);
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
603
+	 * returns a string of HTML that can be directly echoed in a template
604
+	 *
605
+	 * @return string
606
+	 * @throws LogicException
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function display()
610
+	{
611
+		$form_html = apply_filters(
612
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
613
+			''
614
+		);
615
+		$form_config = $this->formConfig();
616
+		if (
617
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
618
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
619
+		) {
620
+			$form_html .= $this->form()->form_open($this->formAction());
621
+		}
622
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
623
+		if (
624
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
625
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
626
+		) {
627
+			$form_html .= $this->form()->form_close();
628
+		}
629
+		$form_html .= apply_filters(
630
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
631
+			''
632
+		);
633
+		return $form_html;
634
+	}
635
+
636
+
637
+
638
+	/**
639
+	 * handles processing the form submission
640
+	 * returns true or false depending on whether the form was processed successfully or not
641
+	 *
642
+	 * @param array $submitted_form_data
643
+	 * @return array
644
+	 * @throws \EE_Error
645
+	 * @throws \LogicException
646
+	 * @throws InvalidFormSubmissionException
647
+	 */
648
+	public function process($submitted_form_data = array())
649
+	{
650
+		if (! $this->form()->was_submitted($submitted_form_data)) {
651
+			throw new InvalidFormSubmissionException($this->form_name);
652
+		}
653
+		$this->form(true)->receive_form_submission($submitted_form_data);
654
+		if (! $this->form()->is_valid()) {
655
+			throw new InvalidFormSubmissionException(
656
+				$this->form_name,
657
+				sprintf(
658
+					esc_html__(
659
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
660
+						'event_espresso'
661
+					),
662
+					$this->form_name,
663
+					'<br />',
664
+					$this->form()->submission_error_message()
665
+				)
666
+			);
667
+		}
668
+		return $this->form()->valid_data();
669
+	}
670 670
 
671 671
 
672 672
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14
-if (! defined('EVENT_ESPRESSO_VERSION')) {
14
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
15 15
     exit('No direct script access allowed');
16 16
 }
17 17
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      */
177 177
     public function form($for_display = false)
178 178
     {
179
-        if (! $this->formIsValid()) {
179
+        if ( ! $this->formIsValid()) {
180 180
             return null;
181 181
         }
182 182
         if ($for_display) {
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function formIsValid()
202 202
     {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
203
+        if ( ! $this->form instanceof \EE_Form_Section_Proper) {
204 204
             static $generated = false;
205
-            if (! $generated) {
205
+            if ( ! $generated) {
206 206
                 $generated = true;
207 207
                 $form = apply_filters(
208 208
                     'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      */
288 288
     public function setFormName($form_name)
289 289
     {
290
-        if (! is_string($form_name)) {
290
+        if ( ! is_string($form_name)) {
291 291
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
292 292
         }
293 293
         $this->form_name = $form_name;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      */
314 314
     public function setAdminName($admin_name)
315 315
     {
316
-        if (! is_string($admin_name)) {
316
+        if ( ! is_string($admin_name)) {
317 317
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
318 318
         }
319 319
         $this->admin_name = $admin_name;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
      */
340 340
     public function setSlug($slug)
341 341
     {
342
-        if (! is_string($slug)) {
342
+        if ( ! is_string($slug)) {
343 343
             throw new InvalidDataTypeException('$slug', $slug, 'string');
344 344
         }
345 345
         $this->slug = $slug;
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
      */
365 365
     public function setSubmitBtnText($submit_btn_text)
366 366
     {
367
-        if (! is_string($submit_btn_text)) {
367
+        if ( ! is_string($submit_btn_text)) {
368 368
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
369 369
         }
370 370
         if (empty($submit_btn_text)) {
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      */
396 396
     public function setFormAction($form_action)
397 397
     {
398
-        if (! is_string($form_action)) {
398
+        if ( ! is_string($form_action)) {
399 399
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
400 400
         }
401 401
         $this->form_action = $form_action;
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
         $text = ! empty($text) ? $text : $this->submitBtnText();
520 520
         return new EE_Submit_Input(
521 521
             array(
522
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
523
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
522
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
523
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
524 524
                 'html_class'            => 'ee-form-submit',
525 525
                 'html_label'            => '&nbsp;',
526
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
526
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
527 527
                 'default'               => $text,
528 528
             )
529 529
         );
@@ -541,11 +541,11 @@  discard block
 block discarded – undo
541 541
      */
542 542
     public function appendSubmitButton($text = '')
543 543
     {
544
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
544
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
545 545
             return;
546 546
         }
547 547
         $this->form->add_subsections(
548
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
548
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
549 549
             null,
550 550
             false
551 551
         );
@@ -563,11 +563,11 @@  discard block
 block discarded – undo
563 563
     {
564 564
         $cancel_button = new EE_Submit_Input(
565 565
             array(
566
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
567
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
566
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
567
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
568 568
                 'html_class'            => 'ee-cancel-form',
569 569
                 'html_label'            => '&nbsp;',
570
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
570
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
571 571
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
572 572
             )
573 573
         );
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         $this->form->add_subsections(
589 589
             array(
590 590
                 'clear-submit-btn-float' => new \EE_Form_Section_HTML(
591
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
591
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
592 592
                 ),
593 593
             ),
594 594
             null,
@@ -647,11 +647,11 @@  discard block
 block discarded – undo
647 647
      */
648 648
     public function process($submitted_form_data = array())
649 649
     {
650
-        if (! $this->form()->was_submitted($submitted_form_data)) {
650
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
651 651
             throw new InvalidFormSubmissionException($this->form_name);
652 652
         }
653 653
         $this->form(true)->receive_form_submission($submitted_form_data);
654
-        if (! $this->form()->is_valid()) {
654
+        if ( ! $this->form()->is_valid()) {
655 655
             throw new InvalidFormSubmissionException(
656 656
                 $this->form_name,
657 657
                 sprintf(
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 2 patches
Indentation   +780 added lines, -780 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6
+	require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
7 7
 }
8 8
 
9 9
 
@@ -22,782 +22,782 @@  discard block
 block discarded – undo
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24 24
 
25
-    /**
26
-     * holds the data that will be processed for the table
27
-     *
28
-     * @var array $_data
29
-     */
30
-    protected $_data;
31
-
32
-
33
-    /**
34
-     * This holds the value of all the data available for the given view (for all pages).
35
-     *
36
-     * @var int $_all_data_count
37
-     */
38
-    protected $_all_data_count;
39
-
40
-
41
-    /**
42
-     * Will contain the count of trashed items for the view label.
43
-     *
44
-     * @var int $_trashed_count
45
-     */
46
-    protected $_trashed_count;
47
-
48
-
49
-    /**
50
-     * This is what will be referenced as the slug for the current screen
51
-     *
52
-     * @var string $_screen
53
-     */
54
-    protected $_screen;
55
-
56
-
57
-    /**
58
-     * this is the EE_Admin_Page object
59
-     *
60
-     * @var EE_Admin_Page $_admin_page
61
-     */
62
-    protected $_admin_page;
63
-
64
-
65
-    /**
66
-     * The current view
67
-     *
68
-     * @var string $_view
69
-     */
70
-    protected $_view;
71
-
72
-
73
-    /**
74
-     * array of possible views for this table
75
-     *
76
-     * @var array $_views
77
-     */
78
-    protected $_views;
79
-
80
-
81
-    /**
82
-     * An array of key => value pairs containing information about the current table
83
-     * array(
84
-     *        'plural' => 'plural label',
85
-     *        'singular' => 'singular label',
86
-     *        'ajax' => false, //whether to use ajax or not
87
-     *        'screen' => null, //string used to reference what screen this is
88
-     *        (WP_List_table converts to screen object)
89
-     * )
90
-     *
91
-     * @var array $_wp_list_args
92
-     */
93
-    protected $_wp_list_args;
94
-
95
-    /**
96
-     * an array of column names
97
-     * array(
98
-     *    'internal-name' => 'Title'
99
-     * )
100
-     *
101
-     * @var array $_columns
102
-     */
103
-    protected $_columns;
104
-
105
-    /**
106
-     * An array of sortable columns
107
-     * array(
108
-     *    'internal-name' => 'orderby' //or
109
-     *    'internal-name' => array( 'orderby', true )
110
-     * )
111
-     *
112
-     * @var array $_sortable_columns
113
-     */
114
-    protected $_sortable_columns;
115
-
116
-    /**
117
-     * callback method used to perform AJAX row reordering
118
-     *
119
-     * @var string $_ajax_sorting_callback
120
-     */
121
-    protected $_ajax_sorting_callback;
122
-
123
-    /**
124
-     * An array of hidden columns (if needed)
125
-     * array('internal-name', 'internal-name')
126
-     *
127
-     * @var array $_hidden_columns
128
-     */
129
-    protected $_hidden_columns;
130
-
131
-    /**
132
-     * holds the per_page value
133
-     *
134
-     * @var int $_per_page
135
-     */
136
-    protected $_per_page;
137
-
138
-    /**
139
-     * holds what page number is currently being viewed
140
-     *
141
-     * @var int $_current_page
142
-     */
143
-    protected $_current_page;
144
-
145
-    /**
146
-     * the reference string for the nonce_action
147
-     *
148
-     * @var string $_nonce_action_ref
149
-     */
150
-    protected $_nonce_action_ref;
151
-
152
-    /**
153
-     * property to hold incoming request data (as set by the admin_page_core)
154
-     *
155
-     * @var array $_req_data
156
-     */
157
-    protected $_req_data;
158
-
159
-
160
-    /**
161
-     * yes / no array for admin form fields
162
-     *
163
-     * @var array $_yes_no
164
-     */
165
-    protected $_yes_no = array();
166
-
167
-    /**
168
-     * Array describing buttons that should appear at the bottom of the page
169
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
-     * and the values are another array with the following keys
171
-     * array(
172
-     *    'route' => 'page_route',
173
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
-     * )
175
-     *
176
-     * @var array $_bottom_buttons
177
-     */
178
-    protected $_bottom_buttons = array();
179
-
180
-
181
-    /**
182
-     * Used to indicate what should be the primary column for the list table.
183
-     * If not present then falls back to what WP calculates
184
-     * as the primary column.
185
-     *
186
-     * @type string $_primary_column
187
-     */
188
-    protected $_primary_column = '';
189
-
190
-
191
-    /**
192
-     * Used to indicate whether the table has a checkbox column or not.
193
-     *
194
-     * @type bool $_has_checkbox_column
195
-     */
196
-    protected $_has_checkbox_column = false;
197
-
198
-
199
-    /**
200
-     * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
-     */
202
-    public function __construct(EE_Admin_Page $admin_page)
203
-    {
204
-        $this->_admin_page   = $admin_page;
205
-        $this->_req_data     = $this->_admin_page->get_request_data();
206
-        $this->_view         = $this->_admin_page->get_view();
207
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
-        $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
-        $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
-
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
-
214
-        $this->_setup_data();
215
-        $this->_add_view_counts();
216
-
217
-        $this->_nonce_action_ref = $this->_view;
218
-
219
-        $this->_set_properties();
220
-
221
-        //set primary column
222
-        add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
-
224
-        //set parent defaults
225
-        parent::__construct($this->_wp_list_args);
226
-
227
-        $this->prepare_items();
228
-    }
229
-
230
-
231
-    /**
232
-     * _setup_data
233
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
-     *
235
-     * @uses $this->_admin_page
236
-     * @return void
237
-     */
238
-    abstract protected function _setup_data();
239
-
240
-
241
-    /**
242
-     * set the properties that this class needs to be able to execute wp_list_table properly
243
-     * properties set:
244
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
-     * _columns = set the columns in an array.
246
-     * _sortable_columns = columns that are sortable (array).
247
-     * _hidden_columns = columns that are hidden (array)
248
-     * _default_orderby = the default orderby for sorting.
249
-     *
250
-     * @abstract
251
-     * @access protected
252
-     * @return void
253
-     */
254
-    abstract protected function _set_properties();
255
-
256
-
257
-    /**
258
-     * _get_table_filters
259
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
260
-     * get's shown in the table.
261
-     *
262
-     * @abstract
263
-     * @access protected
264
-     * @return string
265
-     */
266
-    abstract protected function _get_table_filters();
267
-
268
-
269
-    /**
270
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
271
-     * counts of the views is accurate.
272
-     *
273
-     * @abstract
274
-     * @access protected
275
-     * @return void
276
-     */
277
-    abstract protected function _add_view_counts();
278
-
279
-
280
-    /**
281
-     * _get_hidden_fields
282
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
-     *
284
-     * @return string
285
-     */
286
-    protected function _get_hidden_fields()
287
-    {
288
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
-        //if action is STILL empty, then we set it to default
291
-        $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
-
296
-        $bulk_actions = $this->_get_bulk_actions();
297
-        foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
299
-        }
300
-
301
-        return $field;
302
-    }
303
-
304
-
305
-    /**
306
-     * _set_column_info
307
-     * we're using this to set the column headers property.
308
-     *
309
-     * @access protected
310
-     * @return void
311
-     */
312
-    protected function _set_column_info()
313
-    {
314
-        $columns   = $this->get_columns();
315
-        $hidden    = $this->get_hidden_columns();
316
-        $_sortable = $this->get_sortable_columns();
317
-
318
-        /**
319
-         * Dynamic hook allowing for adding sortable columns in this list table.
320
-         * Note that $this->screen->id is in the format
321
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
322
-         * table it is: event-espresso_page_espresso_messages.
323
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
324
-         * hook prefix ("event-espresso") will be different.
325
-         *
326
-         * @var array
327
-         */
328
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
329
-
330
-        $sortable = array();
331
-        foreach ($_sortable as $id => $data) {
332
-            if (empty($data)) {
333
-                continue;
334
-            }
335
-            //fix for offset errors with WP_List_Table default get_columninfo()
336
-            if (is_array($data)) {
337
-                $_data[0] = key($data);
338
-                $_data[1] = isset($data[1]) ? $data[1] : false;
339
-            } else {
340
-                $_data[0] = $data;
341
-            }
342
-
343
-            $data = (array)$data;
344
-
345
-            if (! isset($data[1])) {
346
-                $_data[1] = false;
347
-            }
348
-
349
-            $sortable[$id] = $_data;
350
-        }
351
-        $primary               = $this->get_primary_column_name();
352
-        $this->_column_headers = array($columns, $hidden, $sortable, $primary);
353
-    }
354
-
355
-
356
-    /**
357
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
358
-     *
359
-     * @return string
360
-     */
361
-    protected function get_primary_column_name()
362
-    {
363
-        foreach (class_parents($this) as $parent) {
364
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
365
-                return parent::get_primary_column_name();
366
-            }
367
-        }
368
-        return $this->_primary_column;
369
-    }
370
-
371
-
372
-    /**
373
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
374
-     *
375
-     * @param EE_Base_Class $item
376
-     * @param string        $column_name
377
-     * @param string        $primary
378
-     * @return string
379
-     */
380
-    protected function handle_row_actions($item, $column_name, $primary)
381
-    {
382
-        foreach (class_parents($this) as $parent) {
383
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
384
-                return parent::handle_row_actions($item, $column_name, $primary);
385
-            }
386
-        }
387
-        return '';
388
-    }
389
-
390
-
391
-    /**
392
-     * _get_bulk_actions
393
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
394
-     *
395
-     * @access protected
396
-     * @return array bulk_actions
397
-     */
398
-    protected function _get_bulk_actions()
399
-    {
400
-        $actions = array();
401
-        //the _views property should have the bulk_actions, so let's go through and extract them into a properly formatted array for the wp_list_table();
402
-        foreach ($this->_views as $view => $args) {
403
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
404
-                //each bulk action will correspond with a admin page route, so we can check whatever the capability is for that page route and skip adding the bulk action if no access for the current logged in user.
405
-                foreach ($args['bulk_action'] as $route => $label) {
406
-                    if ($this->_admin_page->check_user_access($route, true)) {
407
-                        $actions[$route] = $label;
408
-                    }
409
-                }
410
-            }
411
-        }
412
-        return $actions;
413
-    }
414
-
415
-
416
-    /**
417
-     * _filters
418
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
419
-     * button.
420
-     *
421
-     * @access private
422
-     * @return string html showing filters
423
-     */
424
-    private function _filters()
425
-    {
426
-        $classname = get_class($this);
427
-        $filters   = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this,
428
-            $this->_screen);
429
-
430
-        if (empty($filters)) {
431
-            return;
432
-        }
433
-        foreach ($filters as $filter) {
434
-            echo $filter;
435
-        }
436
-        //add filter button at end
437
-        echo '<input type="submit" class="button-secondary" value="' . __('Filter',
438
-                'event_espresso') . '" id="post-query-submit" />';
439
-        //add reset filters button at end
440
-        echo '<a class="button button-secondary"  href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters',
441
-                'event_espresso') . '</a>';
442
-    }
443
-
444
-
445
-    /**
446
-     * Callback for 'list_table_primary_column' WordPress filter
447
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
448
-     * column when class is instantiated.
449
-     *
450
-     * @see WP_List_Table::get_primary_column_name
451
-     * @param string $column_name
452
-     * @return string
453
-     */
454
-    public function set_primary_column($column_name)
455
-    {
456
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
457
-    }
458
-
459
-
460
-    /**
461
-     *
462
-     */
463
-    public function prepare_items()
464
-    {
465
-
466
-        $this->_set_column_info();
467
-        //$this->_column_headers = $this->get_column_info();
468
-        $total_items = $this->_all_data_count;
469
-        $this->process_bulk_action();
470
-
471
-        $this->items = $this->_data;
472
-        $this->set_pagination_args(
473
-            array(
474
-                'total_items' => $total_items,
475
-                'per_page'    => $this->_per_page,
476
-                'total_pages' => ceil($total_items / $this->_per_page),
477
-            )
478
-        );
479
-    }
480
-
481
-
482
-    /**
483
-     * This column is the default for when there is no defined column method for a registered column.
484
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
485
-     *
486
-     * @param EE_Base_Class $item
487
-     * @param string        $column_name The column being called.
488
-     * @return string html content for the column
489
-     */
490
-    public function column_default($item, $column_name)
491
-    {
492
-        /**
493
-         * Dynamic hook allowing for adding additional column content in this list table.
494
-         * Note that $this->screen->id is in the format
495
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
496
-         * table it is: event-espresso_page_espresso_messages.
497
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
498
-         * hook prefix ("event-espresso") will be different.
499
-         */
500
-        do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item,
501
-            $this->_screen);
502
-    }
503
-
504
-
505
-    /**
506
-     * Get a list of columns. The format is:
507
-     * 'internal-name' => 'Title'
508
-     *
509
-     * @since  3.1.0
510
-     * @access public
511
-     * @abstract
512
-     * @return array
513
-     */
514
-    public function get_columns()
515
-    {
516
-        /**
517
-         * Dynamic hook allowing for adding additional columns in this list table.
518
-         * Note that $this->screen->id is in the format
519
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
520
-         * table it is: event-espresso_page_espresso_messages.
521
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
522
-         * hook prefix ("event-espresso") will be different.
523
-         *
524
-         * @var array
525
-         */
526
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
527
-        return $columns;
528
-    }
529
-
530
-
531
-    /**
532
-     * Get an associative array ( id => link ) with the list
533
-     * of views available on this table.
534
-     *
535
-     * @since  3.1.0
536
-     * @access protected
537
-     * @return array
538
-     */
539
-    public function get_views()
540
-    {
541
-        return $this->_views;
542
-    }
543
-
544
-    public function display_views()
545
-    {
546
-        $views           = $this->get_views();
547
-        $assembled_views = array();
548
-
549
-        if (empty($views)) {
550
-            return;
551
-        }
552
-        echo "<ul class='subsubsub'>\n";
553
-        foreach ($views as $view) {
554
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
555
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
556
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>';
557
-            }
558
-        }
559
-
560
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
561
-        echo "</ul>";
562
-    }
563
-
564
-
565
-    /**
566
-     * Generates content for a single row of the table
567
-     *
568
-     * @since  4.1
569
-     * @access public
570
-     * @param EE_Base_Class $item The current item
571
-     */
572
-    public function single_row($item)
573
-    {
574
-        $row_class = $this->_get_row_class($item);
575
-        echo '<tr class="' . esc_attr($row_class) . '">';
576
-        $this->single_row_columns($item);
577
-        echo '</tr>';
578
-    }
579
-
580
-
581
-    /**
582
-     * This simply sets up the row class for the table rows.
583
-     * Allows for easier overriding of child methods for setting up sorting.
584
-     *
585
-     * @param  EE_Base_Class $item the current item
586
-     * @return string
587
-     */
588
-    protected function _get_row_class($item)
589
-    {
590
-        static $row_class = '';
591
-        $row_class = ($row_class === '' ? 'alternate' : '');
592
-
593
-        $new_row_class = $row_class;
594
-
595
-        if (! empty($this->_ajax_sorting_callback)) {
596
-            $new_row_class .= ' rowsortable';
597
-        }
598
-
599
-        return $new_row_class;
600
-    }
601
-
602
-
603
-    /**
604
-     * @return array
605
-     */
606
-    public function get_sortable_columns()
607
-    {
608
-        return (array)$this->_sortable_columns;
609
-    }
610
-
611
-
612
-    /**
613
-     * @return string
614
-     */
615
-    public function get_ajax_sorting_callback()
616
-    {
617
-        return $this->_ajax_sorting_callback;
618
-    }
619
-
620
-
621
-    /**
622
-     * @return array
623
-     */
624
-    public function get_hidden_columns()
625
-    {
626
-        $user_id     = get_current_user_id();
627
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
628
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
629
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
630
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
631
-        }
632
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
633
-        return (array)get_user_option($ref, $user_id);
634
-    }
635
-
636
-
637
-    /**
638
-     * Generates the columns for a single row of the table.
639
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
640
-     * column.
641
-     *
642
-     * @since 3.1.0
643
-     * @param EE_Base_Class $item The current item
644
-     */
645
-    public function single_row_columns($item)
646
-    {
647
-        list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
648
-
649
-        global $wp_version;
650
-        $use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
651
-
652
-        foreach ($columns as $column_name => $column_display_name) {
653
-
654
-            /**
655
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns are
656
-             * hidden or not instead of using "display:none;".  This bit of code provides backward compat.
657
-             */
658
-            $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
659
-            $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
660
-
661
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
662
-            if ($primary === $column_name) {
663
-                $classes .= ' has-row-actions column-primary';
664
-            }
665
-
666
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
667
-
668
-            $class = "class='$classes'";
669
-
670
-            $attributes = "$class$style$data";
671
-
672
-            if ($column_name === 'cb') {
673
-                echo '<th scope="row" class="check-column">';
674
-                echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
675
-                    $this->column_cb($item), $item, $this);
676
-                echo '</th>';
677
-            } elseif (method_exists($this, 'column_' . $column_name)) {
678
-                echo "<td $attributes>";
679
-                echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
680
-                    call_user_func(array($this, 'column_' . $column_name), $item), $item, $this);
681
-                echo $this->handle_row_actions($item, $column_name, $primary);
682
-                echo "</td>";
683
-            } else {
684
-                echo "<td $attributes>";
685
-                echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
686
-                    $this->column_default($item, $column_name), $item, $column_name, $this);
687
-                echo $this->handle_row_actions($item, $column_name, $primary);
688
-                echo "</td>";
689
-            }
690
-        }
691
-    }
692
-
693
-
694
-    /**
695
-     * Extra controls to be displayed between bulk actions and pagination
696
-     *
697
-     * @access public
698
-     * @param string $which
699
-     * @throws \EE_Error
700
-     */
701
-    public function extra_tablenav($which)
702
-    {
703
-        if ($which === 'top') {
704
-            $this->_filters();
705
-            echo $this->_get_hidden_fields();
706
-        } else {
707
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
708
-            foreach ($this->_bottom_buttons as $type => $action) {
709
-                $route         = isset($action['route']) ? $action['route'] : '';
710
-                $extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
711
-                echo $this->_admin_page->get_action_link_or_button(
712
-                    $route,
713
-                    $type,
714
-                    $extra_request,
715
-                    'button button-secondary',
716
-                    '',
717
-                    false
718
-                );
719
-            }
720
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
721
-            echo '</div>';
722
-        }
723
-        //echo $this->_entries_per_page_dropdown;
724
-    }
725
-
726
-
727
-    /**
728
-     * Get an associative array ( option_name => option_title ) with the list
729
-     * of bulk actions available on this table.
730
-     *
731
-     * @since  3.1.0
732
-     * @access protected
733
-     * @return array
734
-     */
735
-    public function get_bulk_actions()
736
-    {
737
-        return (array)$this->_get_bulk_actions();
738
-    }
739
-
740
-    public function process_bulk_action()
741
-    {
742
-        //this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for reference in case there is a case where it gets used.
743
-    }
744
-
745
-
746
-    /**
747
-     * returns the EE admin page this list table is associated with
748
-     *
749
-     * @return EE_Admin_Page
750
-     */
751
-    public function get_admin_page()
752
-    {
753
-        return $this->_admin_page;
754
-    }
755
-
756
-
757
-    /**
758
-     * A "helper" function for all children to provide an html string of
759
-     * actions to output in their content.  It is preferable for child classes
760
-     * to use this method for generating their actions content so that it's
761
-     * filterable by plugins
762
-     *
763
-     * @param string        $action_container           what are the html container
764
-     *                                                  elements for this actions string?
765
-     * @param string        $action_class               What class is for the container
766
-     *                                                  element.
767
-     * @param string        $action_items               The contents for the action items
768
-     *                                                  container.  This is filtered before
769
-     *                                                  returned.
770
-     * @param string        $action_id                  What id (optional) is used for the
771
-     *                                                  container element.
772
-     * @param EE_Base_Class $item                       The object for the column displaying
773
-     *                                                  the actions.
774
-     * @return string The assembled action elements container.
775
-     */
776
-    protected function _action_string(
777
-        $action_items,
778
-        $item,
779
-        $action_container = 'ul',
780
-        $action_class = '',
781
-        $action_id = ''
782
-    ) {
783
-        $content      = '';
784
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
785
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
786
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
787
-        try {
788
-            $content .= apply_filters(
789
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
790
-                $action_items,
791
-                $item,
792
-                $this
793
-            );
794
-        } catch (\Exception $e) {
795
-            if (WP_DEBUG) {
796
-                \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
797
-            }
798
-            $content .= $action_items;
799
-        }
800
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
801
-        return $content;
802
-    }
25
+	/**
26
+	 * holds the data that will be processed for the table
27
+	 *
28
+	 * @var array $_data
29
+	 */
30
+	protected $_data;
31
+
32
+
33
+	/**
34
+	 * This holds the value of all the data available for the given view (for all pages).
35
+	 *
36
+	 * @var int $_all_data_count
37
+	 */
38
+	protected $_all_data_count;
39
+
40
+
41
+	/**
42
+	 * Will contain the count of trashed items for the view label.
43
+	 *
44
+	 * @var int $_trashed_count
45
+	 */
46
+	protected $_trashed_count;
47
+
48
+
49
+	/**
50
+	 * This is what will be referenced as the slug for the current screen
51
+	 *
52
+	 * @var string $_screen
53
+	 */
54
+	protected $_screen;
55
+
56
+
57
+	/**
58
+	 * this is the EE_Admin_Page object
59
+	 *
60
+	 * @var EE_Admin_Page $_admin_page
61
+	 */
62
+	protected $_admin_page;
63
+
64
+
65
+	/**
66
+	 * The current view
67
+	 *
68
+	 * @var string $_view
69
+	 */
70
+	protected $_view;
71
+
72
+
73
+	/**
74
+	 * array of possible views for this table
75
+	 *
76
+	 * @var array $_views
77
+	 */
78
+	protected $_views;
79
+
80
+
81
+	/**
82
+	 * An array of key => value pairs containing information about the current table
83
+	 * array(
84
+	 *        'plural' => 'plural label',
85
+	 *        'singular' => 'singular label',
86
+	 *        'ajax' => false, //whether to use ajax or not
87
+	 *        'screen' => null, //string used to reference what screen this is
88
+	 *        (WP_List_table converts to screen object)
89
+	 * )
90
+	 *
91
+	 * @var array $_wp_list_args
92
+	 */
93
+	protected $_wp_list_args;
94
+
95
+	/**
96
+	 * an array of column names
97
+	 * array(
98
+	 *    'internal-name' => 'Title'
99
+	 * )
100
+	 *
101
+	 * @var array $_columns
102
+	 */
103
+	protected $_columns;
104
+
105
+	/**
106
+	 * An array of sortable columns
107
+	 * array(
108
+	 *    'internal-name' => 'orderby' //or
109
+	 *    'internal-name' => array( 'orderby', true )
110
+	 * )
111
+	 *
112
+	 * @var array $_sortable_columns
113
+	 */
114
+	protected $_sortable_columns;
115
+
116
+	/**
117
+	 * callback method used to perform AJAX row reordering
118
+	 *
119
+	 * @var string $_ajax_sorting_callback
120
+	 */
121
+	protected $_ajax_sorting_callback;
122
+
123
+	/**
124
+	 * An array of hidden columns (if needed)
125
+	 * array('internal-name', 'internal-name')
126
+	 *
127
+	 * @var array $_hidden_columns
128
+	 */
129
+	protected $_hidden_columns;
130
+
131
+	/**
132
+	 * holds the per_page value
133
+	 *
134
+	 * @var int $_per_page
135
+	 */
136
+	protected $_per_page;
137
+
138
+	/**
139
+	 * holds what page number is currently being viewed
140
+	 *
141
+	 * @var int $_current_page
142
+	 */
143
+	protected $_current_page;
144
+
145
+	/**
146
+	 * the reference string for the nonce_action
147
+	 *
148
+	 * @var string $_nonce_action_ref
149
+	 */
150
+	protected $_nonce_action_ref;
151
+
152
+	/**
153
+	 * property to hold incoming request data (as set by the admin_page_core)
154
+	 *
155
+	 * @var array $_req_data
156
+	 */
157
+	protected $_req_data;
158
+
159
+
160
+	/**
161
+	 * yes / no array for admin form fields
162
+	 *
163
+	 * @var array $_yes_no
164
+	 */
165
+	protected $_yes_no = array();
166
+
167
+	/**
168
+	 * Array describing buttons that should appear at the bottom of the page
169
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
+	 * and the values are another array with the following keys
171
+	 * array(
172
+	 *    'route' => 'page_route',
173
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
+	 * )
175
+	 *
176
+	 * @var array $_bottom_buttons
177
+	 */
178
+	protected $_bottom_buttons = array();
179
+
180
+
181
+	/**
182
+	 * Used to indicate what should be the primary column for the list table.
183
+	 * If not present then falls back to what WP calculates
184
+	 * as the primary column.
185
+	 *
186
+	 * @type string $_primary_column
187
+	 */
188
+	protected $_primary_column = '';
189
+
190
+
191
+	/**
192
+	 * Used to indicate whether the table has a checkbox column or not.
193
+	 *
194
+	 * @type bool $_has_checkbox_column
195
+	 */
196
+	protected $_has_checkbox_column = false;
197
+
198
+
199
+	/**
200
+	 * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
+	 */
202
+	public function __construct(EE_Admin_Page $admin_page)
203
+	{
204
+		$this->_admin_page   = $admin_page;
205
+		$this->_req_data     = $this->_admin_page->get_request_data();
206
+		$this->_view         = $this->_admin_page->get_view();
207
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
+		$this->_current_page = $this->get_pagenum();
209
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
+		$this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
+
212
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
+
214
+		$this->_setup_data();
215
+		$this->_add_view_counts();
216
+
217
+		$this->_nonce_action_ref = $this->_view;
218
+
219
+		$this->_set_properties();
220
+
221
+		//set primary column
222
+		add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
+
224
+		//set parent defaults
225
+		parent::__construct($this->_wp_list_args);
226
+
227
+		$this->prepare_items();
228
+	}
229
+
230
+
231
+	/**
232
+	 * _setup_data
233
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
+	 *
235
+	 * @uses $this->_admin_page
236
+	 * @return void
237
+	 */
238
+	abstract protected function _setup_data();
239
+
240
+
241
+	/**
242
+	 * set the properties that this class needs to be able to execute wp_list_table properly
243
+	 * properties set:
244
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
+	 * _columns = set the columns in an array.
246
+	 * _sortable_columns = columns that are sortable (array).
247
+	 * _hidden_columns = columns that are hidden (array)
248
+	 * _default_orderby = the default orderby for sorting.
249
+	 *
250
+	 * @abstract
251
+	 * @access protected
252
+	 * @return void
253
+	 */
254
+	abstract protected function _set_properties();
255
+
256
+
257
+	/**
258
+	 * _get_table_filters
259
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
260
+	 * get's shown in the table.
261
+	 *
262
+	 * @abstract
263
+	 * @access protected
264
+	 * @return string
265
+	 */
266
+	abstract protected function _get_table_filters();
267
+
268
+
269
+	/**
270
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
271
+	 * counts of the views is accurate.
272
+	 *
273
+	 * @abstract
274
+	 * @access protected
275
+	 * @return void
276
+	 */
277
+	abstract protected function _add_view_counts();
278
+
279
+
280
+	/**
281
+	 * _get_hidden_fields
282
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
+	 *
284
+	 * @return string
285
+	 */
286
+	protected function _get_hidden_fields()
287
+	{
288
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
+		//if action is STILL empty, then we set it to default
291
+		$action = empty($action) ? 'default' : $action;
292
+		$field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
+		$field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
+		$field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
+
296
+		$bulk_actions = $this->_get_bulk_actions();
297
+		foreach ($bulk_actions as $bulk_action => $label) {
298
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
299
+		}
300
+
301
+		return $field;
302
+	}
303
+
304
+
305
+	/**
306
+	 * _set_column_info
307
+	 * we're using this to set the column headers property.
308
+	 *
309
+	 * @access protected
310
+	 * @return void
311
+	 */
312
+	protected function _set_column_info()
313
+	{
314
+		$columns   = $this->get_columns();
315
+		$hidden    = $this->get_hidden_columns();
316
+		$_sortable = $this->get_sortable_columns();
317
+
318
+		/**
319
+		 * Dynamic hook allowing for adding sortable columns in this list table.
320
+		 * Note that $this->screen->id is in the format
321
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
322
+		 * table it is: event-espresso_page_espresso_messages.
323
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
324
+		 * hook prefix ("event-espresso") will be different.
325
+		 *
326
+		 * @var array
327
+		 */
328
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
329
+
330
+		$sortable = array();
331
+		foreach ($_sortable as $id => $data) {
332
+			if (empty($data)) {
333
+				continue;
334
+			}
335
+			//fix for offset errors with WP_List_Table default get_columninfo()
336
+			if (is_array($data)) {
337
+				$_data[0] = key($data);
338
+				$_data[1] = isset($data[1]) ? $data[1] : false;
339
+			} else {
340
+				$_data[0] = $data;
341
+			}
342
+
343
+			$data = (array)$data;
344
+
345
+			if (! isset($data[1])) {
346
+				$_data[1] = false;
347
+			}
348
+
349
+			$sortable[$id] = $_data;
350
+		}
351
+		$primary               = $this->get_primary_column_name();
352
+		$this->_column_headers = array($columns, $hidden, $sortable, $primary);
353
+	}
354
+
355
+
356
+	/**
357
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
358
+	 *
359
+	 * @return string
360
+	 */
361
+	protected function get_primary_column_name()
362
+	{
363
+		foreach (class_parents($this) as $parent) {
364
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
365
+				return parent::get_primary_column_name();
366
+			}
367
+		}
368
+		return $this->_primary_column;
369
+	}
370
+
371
+
372
+	/**
373
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
374
+	 *
375
+	 * @param EE_Base_Class $item
376
+	 * @param string        $column_name
377
+	 * @param string        $primary
378
+	 * @return string
379
+	 */
380
+	protected function handle_row_actions($item, $column_name, $primary)
381
+	{
382
+		foreach (class_parents($this) as $parent) {
383
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
384
+				return parent::handle_row_actions($item, $column_name, $primary);
385
+			}
386
+		}
387
+		return '';
388
+	}
389
+
390
+
391
+	/**
392
+	 * _get_bulk_actions
393
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
394
+	 *
395
+	 * @access protected
396
+	 * @return array bulk_actions
397
+	 */
398
+	protected function _get_bulk_actions()
399
+	{
400
+		$actions = array();
401
+		//the _views property should have the bulk_actions, so let's go through and extract them into a properly formatted array for the wp_list_table();
402
+		foreach ($this->_views as $view => $args) {
403
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
404
+				//each bulk action will correspond with a admin page route, so we can check whatever the capability is for that page route and skip adding the bulk action if no access for the current logged in user.
405
+				foreach ($args['bulk_action'] as $route => $label) {
406
+					if ($this->_admin_page->check_user_access($route, true)) {
407
+						$actions[$route] = $label;
408
+					}
409
+				}
410
+			}
411
+		}
412
+		return $actions;
413
+	}
414
+
415
+
416
+	/**
417
+	 * _filters
418
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
419
+	 * button.
420
+	 *
421
+	 * @access private
422
+	 * @return string html showing filters
423
+	 */
424
+	private function _filters()
425
+	{
426
+		$classname = get_class($this);
427
+		$filters   = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this,
428
+			$this->_screen);
429
+
430
+		if (empty($filters)) {
431
+			return;
432
+		}
433
+		foreach ($filters as $filter) {
434
+			echo $filter;
435
+		}
436
+		//add filter button at end
437
+		echo '<input type="submit" class="button-secondary" value="' . __('Filter',
438
+				'event_espresso') . '" id="post-query-submit" />';
439
+		//add reset filters button at end
440
+		echo '<a class="button button-secondary"  href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters',
441
+				'event_espresso') . '</a>';
442
+	}
443
+
444
+
445
+	/**
446
+	 * Callback for 'list_table_primary_column' WordPress filter
447
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
448
+	 * column when class is instantiated.
449
+	 *
450
+	 * @see WP_List_Table::get_primary_column_name
451
+	 * @param string $column_name
452
+	 * @return string
453
+	 */
454
+	public function set_primary_column($column_name)
455
+	{
456
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
457
+	}
458
+
459
+
460
+	/**
461
+	 *
462
+	 */
463
+	public function prepare_items()
464
+	{
465
+
466
+		$this->_set_column_info();
467
+		//$this->_column_headers = $this->get_column_info();
468
+		$total_items = $this->_all_data_count;
469
+		$this->process_bulk_action();
470
+
471
+		$this->items = $this->_data;
472
+		$this->set_pagination_args(
473
+			array(
474
+				'total_items' => $total_items,
475
+				'per_page'    => $this->_per_page,
476
+				'total_pages' => ceil($total_items / $this->_per_page),
477
+			)
478
+		);
479
+	}
480
+
481
+
482
+	/**
483
+	 * This column is the default for when there is no defined column method for a registered column.
484
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
485
+	 *
486
+	 * @param EE_Base_Class $item
487
+	 * @param string        $column_name The column being called.
488
+	 * @return string html content for the column
489
+	 */
490
+	public function column_default($item, $column_name)
491
+	{
492
+		/**
493
+		 * Dynamic hook allowing for adding additional column content in this list table.
494
+		 * Note that $this->screen->id is in the format
495
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
496
+		 * table it is: event-espresso_page_espresso_messages.
497
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
498
+		 * hook prefix ("event-espresso") will be different.
499
+		 */
500
+		do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item,
501
+			$this->_screen);
502
+	}
503
+
504
+
505
+	/**
506
+	 * Get a list of columns. The format is:
507
+	 * 'internal-name' => 'Title'
508
+	 *
509
+	 * @since  3.1.0
510
+	 * @access public
511
+	 * @abstract
512
+	 * @return array
513
+	 */
514
+	public function get_columns()
515
+	{
516
+		/**
517
+		 * Dynamic hook allowing for adding additional columns in this list table.
518
+		 * Note that $this->screen->id is in the format
519
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
520
+		 * table it is: event-espresso_page_espresso_messages.
521
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
522
+		 * hook prefix ("event-espresso") will be different.
523
+		 *
524
+		 * @var array
525
+		 */
526
+		$columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
527
+		return $columns;
528
+	}
529
+
530
+
531
+	/**
532
+	 * Get an associative array ( id => link ) with the list
533
+	 * of views available on this table.
534
+	 *
535
+	 * @since  3.1.0
536
+	 * @access protected
537
+	 * @return array
538
+	 */
539
+	public function get_views()
540
+	{
541
+		return $this->_views;
542
+	}
543
+
544
+	public function display_views()
545
+	{
546
+		$views           = $this->get_views();
547
+		$assembled_views = array();
548
+
549
+		if (empty($views)) {
550
+			return;
551
+		}
552
+		echo "<ul class='subsubsub'>\n";
553
+		foreach ($views as $view) {
554
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
555
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
556
+				$assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>';
557
+			}
558
+		}
559
+
560
+		echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
561
+		echo "</ul>";
562
+	}
563
+
564
+
565
+	/**
566
+	 * Generates content for a single row of the table
567
+	 *
568
+	 * @since  4.1
569
+	 * @access public
570
+	 * @param EE_Base_Class $item The current item
571
+	 */
572
+	public function single_row($item)
573
+	{
574
+		$row_class = $this->_get_row_class($item);
575
+		echo '<tr class="' . esc_attr($row_class) . '">';
576
+		$this->single_row_columns($item);
577
+		echo '</tr>';
578
+	}
579
+
580
+
581
+	/**
582
+	 * This simply sets up the row class for the table rows.
583
+	 * Allows for easier overriding of child methods for setting up sorting.
584
+	 *
585
+	 * @param  EE_Base_Class $item the current item
586
+	 * @return string
587
+	 */
588
+	protected function _get_row_class($item)
589
+	{
590
+		static $row_class = '';
591
+		$row_class = ($row_class === '' ? 'alternate' : '');
592
+
593
+		$new_row_class = $row_class;
594
+
595
+		if (! empty($this->_ajax_sorting_callback)) {
596
+			$new_row_class .= ' rowsortable';
597
+		}
598
+
599
+		return $new_row_class;
600
+	}
601
+
602
+
603
+	/**
604
+	 * @return array
605
+	 */
606
+	public function get_sortable_columns()
607
+	{
608
+		return (array)$this->_sortable_columns;
609
+	}
610
+
611
+
612
+	/**
613
+	 * @return string
614
+	 */
615
+	public function get_ajax_sorting_callback()
616
+	{
617
+		return $this->_ajax_sorting_callback;
618
+	}
619
+
620
+
621
+	/**
622
+	 * @return array
623
+	 */
624
+	public function get_hidden_columns()
625
+	{
626
+		$user_id     = get_current_user_id();
627
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
628
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
629
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
630
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
631
+		}
632
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
633
+		return (array)get_user_option($ref, $user_id);
634
+	}
635
+
636
+
637
+	/**
638
+	 * Generates the columns for a single row of the table.
639
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
640
+	 * column.
641
+	 *
642
+	 * @since 3.1.0
643
+	 * @param EE_Base_Class $item The current item
644
+	 */
645
+	public function single_row_columns($item)
646
+	{
647
+		list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
648
+
649
+		global $wp_version;
650
+		$use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
651
+
652
+		foreach ($columns as $column_name => $column_display_name) {
653
+
654
+			/**
655
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns are
656
+			 * hidden or not instead of using "display:none;".  This bit of code provides backward compat.
657
+			 */
658
+			$hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
659
+			$style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
660
+
661
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
662
+			if ($primary === $column_name) {
663
+				$classes .= ' has-row-actions column-primary';
664
+			}
665
+
666
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
667
+
668
+			$class = "class='$classes'";
669
+
670
+			$attributes = "$class$style$data";
671
+
672
+			if ($column_name === 'cb') {
673
+				echo '<th scope="row" class="check-column">';
674
+				echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
675
+					$this->column_cb($item), $item, $this);
676
+				echo '</th>';
677
+			} elseif (method_exists($this, 'column_' . $column_name)) {
678
+				echo "<td $attributes>";
679
+				echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
680
+					call_user_func(array($this, 'column_' . $column_name), $item), $item, $this);
681
+				echo $this->handle_row_actions($item, $column_name, $primary);
682
+				echo "</td>";
683
+			} else {
684
+				echo "<td $attributes>";
685
+				echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
686
+					$this->column_default($item, $column_name), $item, $column_name, $this);
687
+				echo $this->handle_row_actions($item, $column_name, $primary);
688
+				echo "</td>";
689
+			}
690
+		}
691
+	}
692
+
693
+
694
+	/**
695
+	 * Extra controls to be displayed between bulk actions and pagination
696
+	 *
697
+	 * @access public
698
+	 * @param string $which
699
+	 * @throws \EE_Error
700
+	 */
701
+	public function extra_tablenav($which)
702
+	{
703
+		if ($which === 'top') {
704
+			$this->_filters();
705
+			echo $this->_get_hidden_fields();
706
+		} else {
707
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
708
+			foreach ($this->_bottom_buttons as $type => $action) {
709
+				$route         = isset($action['route']) ? $action['route'] : '';
710
+				$extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
711
+				echo $this->_admin_page->get_action_link_or_button(
712
+					$route,
713
+					$type,
714
+					$extra_request,
715
+					'button button-secondary',
716
+					'',
717
+					false
718
+				);
719
+			}
720
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
721
+			echo '</div>';
722
+		}
723
+		//echo $this->_entries_per_page_dropdown;
724
+	}
725
+
726
+
727
+	/**
728
+	 * Get an associative array ( option_name => option_title ) with the list
729
+	 * of bulk actions available on this table.
730
+	 *
731
+	 * @since  3.1.0
732
+	 * @access protected
733
+	 * @return array
734
+	 */
735
+	public function get_bulk_actions()
736
+	{
737
+		return (array)$this->_get_bulk_actions();
738
+	}
739
+
740
+	public function process_bulk_action()
741
+	{
742
+		//this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for reference in case there is a case where it gets used.
743
+	}
744
+
745
+
746
+	/**
747
+	 * returns the EE admin page this list table is associated with
748
+	 *
749
+	 * @return EE_Admin_Page
750
+	 */
751
+	public function get_admin_page()
752
+	{
753
+		return $this->_admin_page;
754
+	}
755
+
756
+
757
+	/**
758
+	 * A "helper" function for all children to provide an html string of
759
+	 * actions to output in their content.  It is preferable for child classes
760
+	 * to use this method for generating their actions content so that it's
761
+	 * filterable by plugins
762
+	 *
763
+	 * @param string        $action_container           what are the html container
764
+	 *                                                  elements for this actions string?
765
+	 * @param string        $action_class               What class is for the container
766
+	 *                                                  element.
767
+	 * @param string        $action_items               The contents for the action items
768
+	 *                                                  container.  This is filtered before
769
+	 *                                                  returned.
770
+	 * @param string        $action_id                  What id (optional) is used for the
771
+	 *                                                  container element.
772
+	 * @param EE_Base_Class $item                       The object for the column displaying
773
+	 *                                                  the actions.
774
+	 * @return string The assembled action elements container.
775
+	 */
776
+	protected function _action_string(
777
+		$action_items,
778
+		$item,
779
+		$action_container = 'ul',
780
+		$action_class = '',
781
+		$action_id = ''
782
+	) {
783
+		$content      = '';
784
+		$action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
785
+		$action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
786
+		$content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
787
+		try {
788
+			$content .= apply_filters(
789
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
790
+				$action_items,
791
+				$item,
792
+				$this
793
+			);
794
+		} catch (\Exception $e) {
795
+			if (WP_DEBUG) {
796
+				\EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
797
+			}
798
+			$content .= $action_items;
799
+		}
800
+		$content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
801
+		return $content;
802
+	}
803 803
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5
-if (! class_exists('WP_List_Table')) {
6
-    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
5
+if ( ! class_exists('WP_List_Table')) {
6
+    require_once(ABSPATH.'wp-admin/includes/class-wp-list-table.php');
7 7
 }
8 8
 
9 9
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
         $this->_view         = $this->_admin_page->get_view();
207 207
         $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208 208
         $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
209
+        $this->_screen       = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view();
210 210
         $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211 211
 
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
212
+        $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10);
213 213
 
214 214
         $this->_setup_data();
215 215
         $this->_add_view_counts();
@@ -289,13 +289,13 @@  discard block
 block discarded – undo
289 289
         $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290 290
         //if action is STILL empty, then we set it to default
291 291
         $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
292
+        $field  = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n";
293
+        $field  .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/
294
+        $field  .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n";
295 295
 
296 296
         $bulk_actions = $this->_get_bulk_actions();
297 297
         foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce" value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
298
+            $field .= '<input type="hidden" name="'.$bulk_action.'_nonce" value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n";
299 299
         }
300 300
 
301 301
         return $field;
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
                 $_data[0] = $data;
341 341
             }
342 342
 
343
-            $data = (array)$data;
343
+            $data = (array) $data;
344 344
 
345
-            if (! isset($data[1])) {
345
+            if ( ! isset($data[1])) {
346 346
                 $_data[1] = false;
347 347
             }
348 348
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
     private function _filters()
425 425
     {
426 426
         $classname = get_class($this);
427
-        $filters   = apply_filters("FHEE__{$classname}__filters", (array)$this->_get_table_filters(), $this,
427
+        $filters   = apply_filters("FHEE__{$classname}__filters", (array) $this->_get_table_filters(), $this,
428 428
             $this->_screen);
429 429
 
430 430
         if (empty($filters)) {
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
             echo $filter;
435 435
         }
436 436
         //add filter button at end
437
-        echo '<input type="submit" class="button-secondary" value="' . __('Filter',
438
-                'event_espresso') . '" id="post-query-submit" />';
437
+        echo '<input type="submit" class="button-secondary" value="'.__('Filter',
438
+                'event_espresso').'" id="post-query-submit" />';
439 439
         //add reset filters button at end
440
-        echo '<a class="button button-secondary"  href="' . $this->_admin_page->get_current_page_view_url() . '" style="display:inline-block">' . __('Reset Filters',
441
-                'event_espresso') . '</a>';
440
+        echo '<a class="button button-secondary"  href="'.$this->_admin_page->get_current_page_view_url().'" style="display:inline-block">'.__('Reset Filters',
441
+                'event_espresso').'</a>';
442 442
     }
443 443
 
444 444
 
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
          * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
498 498
          * hook prefix ("event-espresso") will be different.
499 499
          */
500
-        do_action('AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, $item,
500
+        do_action('AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, $item,
501 501
             $this->_screen);
502 502
     }
503 503
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
          *
524 524
          * @var array
525 525
          */
526
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
526
+        $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen);
527 527
         return $columns;
528 528
     }
529 529
 
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
         foreach ($views as $view) {
554 554
             $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
555 555
             if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
556
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>" . '<a href="' . $view['url'] . '">' . $view['label'] . '</a> <span class="count">(' . $count . ')</span>';
556
+                $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>".'<a href="'.$view['url'].'">'.$view['label'].'</a> <span class="count">('.$count.')</span>';
557 557
             }
558 558
         }
559 559
 
560
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
560
+        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : '';
561 561
         echo "</ul>";
562 562
     }
563 563
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
     public function single_row($item)
573 573
     {
574 574
         $row_class = $this->_get_row_class($item);
575
-        echo '<tr class="' . esc_attr($row_class) . '">';
575
+        echo '<tr class="'.esc_attr($row_class).'">';
576 576
         $this->single_row_columns($item);
577 577
         echo '</tr>';
578 578
     }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 
593 593
         $new_row_class = $row_class;
594 594
 
595
-        if (! empty($this->_ajax_sorting_callback)) {
595
+        if ( ! empty($this->_ajax_sorting_callback)) {
596 596
             $new_row_class .= ' rowsortable';
597 597
         }
598 598
 
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
      */
606 606
     public function get_sortable_columns()
607 607
     {
608
-        return (array)$this->_sortable_columns;
608
+        return (array) $this->_sortable_columns;
609 609
     }
610 610
 
611 611
 
@@ -624,13 +624,13 @@  discard block
 block discarded – undo
624 624
     public function get_hidden_columns()
625 625
     {
626 626
         $user_id     = get_current_user_id();
627
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
627
+        $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id);
628 628
         if (empty($has_default) && ! empty($this->_hidden_columns)) {
629
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
630
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
629
+            update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true);
630
+            update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true);
631 631
         }
632
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
633
-        return (array)get_user_option($ref, $user_id);
632
+        $ref = 'manage'.$this->screen->id.'columnshidden';
633
+        return (array) get_user_option($ref, $user_id);
634 634
     }
635 635
 
636 636
 
@@ -658,12 +658,12 @@  discard block
 block discarded – undo
658 658
             $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
659 659
             $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
660 660
 
661
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
661
+            $classes = $column_name.' column-'.$column_name.$hidden_class;
662 662
             if ($primary === $column_name) {
663 663
                 $classes .= ' has-row-actions column-primary';
664 664
             }
665 665
 
666
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
666
+            $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"';
667 667
 
668 668
             $class = "class='$classes'";
669 669
 
@@ -674,10 +674,10 @@  discard block
 block discarded – undo
674 674
                 echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
675 675
                     $this->column_cb($item), $item, $this);
676 676
                 echo '</th>';
677
-            } elseif (method_exists($this, 'column_' . $column_name)) {
677
+            } elseif (method_exists($this, 'column_'.$column_name)) {
678 678
                 echo "<td $attributes>";
679
-                echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
680
-                    call_user_func(array($this, 'column_' . $column_name), $item), $item, $this);
679
+                echo apply_filters('FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content',
680
+                    call_user_func(array($this, 'column_'.$column_name), $item), $item, $this);
681 681
                 echo $this->handle_row_actions($item, $column_name, $primary);
682 682
                 echo "</td>";
683 683
             } else {
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
      */
735 735
     public function get_bulk_actions()
736 736
     {
737
-        return (array)$this->_get_bulk_actions();
737
+        return (array) $this->_get_bulk_actions();
738 738
     }
739 739
 
740 740
     public function process_bulk_action()
@@ -781,9 +781,9 @@  discard block
 block discarded – undo
781 781
         $action_id = ''
782 782
     ) {
783 783
         $content      = '';
784
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
785
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
786
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
784
+        $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : '';
785
+        $action_id    = ! empty($action_id) ? ' id="'.$action_id.'"' : '';
786
+        $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : '';
787 787
         try {
788 788
             $content .= apply_filters(
789 789
                 'FHEE__EE_Admin_List_Table___action_string__action_items',
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
             }
798 798
             $content .= $action_items;
799 799
         }
800
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
800
+        $content .= ! empty($action_container) ? '</'.$action_container.'>' : '';
801 801
         return $content;
802 802
     }
803 803
 }
Please login to merge, or discard this patch.
espresso.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    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
-                    ); ?>
52
+					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
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            '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.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'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.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.025');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.43.rc.025');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once(EE_CORE . 'EE_Error.core.php');
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once(EE_CORE . 'EE_Error.core.php');
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once($full_path_to_file);
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once($full_path_to_file);
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once(plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE) . 'core/espresso_definitions.php');
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions.' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once(plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE) . 'core/espresso_definitions.php');
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions.' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
+    if ( ! function_exists('espresso_duplicate_plugin_error')) {
42 42
         /**
43 43
          *    espresso_duplicate_plugin_error
44 44
          *    displays if more than one version of EE is activated at the same time
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
 } else {
65 65
     define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67 67
         /**
68 68
          * espresso_minimum_php_version_error
69 69
          *
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
                 return;
128 128
             }
129 129
             // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
130
+            if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
131
+                require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php');
132 132
                 \EEH_Debug_Tools::instance();
133 133
             }
134 134
             // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once(EE_CORE . 'EE_Error.core.php');
135
+            if (is_readable(EE_CORE.'EE_Error.core.php')) {
136
+                require_once(EE_CORE.'EE_Error.core.php');
137 137
             } else {
138 138
                 wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139 139
             }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             if (is_readable($full_path_to_file)) {
154 154
                 require_once($full_path_to_file);
155 155
             } else {
156
-                throw new \EE_Error (
156
+                throw new \EE_Error(
157 157
                     sprintf(
158 158
                         esc_html__(
159 159
                             'The %s class file could not be located or is not readable due to file permissions.',
@@ -179,47 +179,47 @@  discard block
 block discarded – undo
179 179
          */
180 180
         function bootstrap_espresso()
181 181
         {
182
-            require_once(plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE) . 'core/espresso_definitions.php');
182
+            require_once(plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE).'core/espresso_definitions.php');
183 183
             try {
184 184
                 espresso_load_error_handling();
185 185
                 espresso_load_required(
186 186
                     'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+                    EE_CORE.'helpers'.DS.'EEH_Base.helper.php'
188 188
                 );
189 189
                 espresso_load_required(
190 190
                     'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+                    EE_CORE.'interfaces'.DS.'EEHI_File.interface.php'
192 192
                 );
193 193
                 espresso_load_required(
194 194
                     'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+                    EE_CORE.'helpers'.DS.'EEH_File.helper.php'
196 196
                 );
197 197
                 espresso_load_required(
198 198
                     'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+                    EE_CORE.'helpers'.DS.'EEH_Array.helper.php'
200 200
                 );
201 201
                 // instantiate and configure PSR4 autoloader
202 202
                 espresso_load_required(
203 203
                     'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
204
+                    EE_CORE.'Psr4Autoloader.php'
205 205
                 );
206 206
                 espresso_load_required(
207 207
                     'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+                    EE_CORE.'EE_Psr4AutoloaderInit.core.php'
209 209
                 );
210 210
                 $AutoloaderInit = new EE_Psr4AutoloaderInit();
211 211
                 $AutoloaderInit->initializeAutoloader();
212 212
                 espresso_load_required(
213 213
                     'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+                    EE_CORE.'request_stack'.DS.'EE_Request.core.php'
215 215
                 );
216 216
                 espresso_load_required(
217 217
                     'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+                    EE_CORE.'request_stack'.DS.'EE_Response.core.php'
219 219
                 );
220 220
                 espresso_load_required(
221 221
                     'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
+                    EE_CORE.'EE_Bootstrap.core.php'
223 223
                 );
224 224
                 // bootstrap EE and the request stack
225 225
                 new EE_Bootstrap(
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
                     new EE_Response()
228 228
                 );
229 229
             } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions.' . DS . 'ExceptionStackTraceDisplay.php';
230
+                require_once EE_CORE.'exceptions.'.DS.'ExceptionStackTraceDisplay.php';
231 231
                 new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232 232
             }
233 233
         }
234 234
         bootstrap_espresso();
235 235
     }
236 236
 }
237
-if (! function_exists('espresso_deactivate_plugin')) {
237
+if ( ! function_exists('espresso_deactivate_plugin')) {
238 238
     /**
239 239
      *    deactivate_plugin
240 240
      * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
      */
246 246
     function espresso_deactivate_plugin($plugin_basename = '')
247 247
     {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
248
+        if ( ! function_exists('deactivate_plugins')) {
249
+            require_once(ABSPATH.'wp-admin/includes/plugin.php');
250 250
         }
251 251
         unset($_GET['activate'], $_REQUEST['activate']);
252 252
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -23,220 +23,220 @@
 block discarded – undo
23 23
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
24 24
 {
25 25
 
26
-    /**
27
-     * @type LoaderInterface $loader
28
-     */
29
-    protected $loader;
26
+	/**
27
+	 * @type LoaderInterface $loader
28
+	 */
29
+	protected $loader;
30 30
 
31
-    /**
32
-     * @var EE_Request $request
33
-     */
34
-    protected $request;
31
+	/**
32
+	 * @var EE_Request $request
33
+	 */
34
+	protected $request;
35 35
 
36
-    /**
37
-     * @var EE_Response $response
38
-     */
39
-    protected $response;
36
+	/**
37
+	 * @var EE_Response $response
38
+	 */
39
+	protected $response;
40 40
 
41
-    /**
42
-     * @var EE_Dependency_Map $dependency_map
43
-     */
44
-    protected $dependency_map;
41
+	/**
42
+	 * @var EE_Dependency_Map $dependency_map
43
+	 */
44
+	protected $dependency_map;
45 45
 
46
-    /**
47
-     * @var EE_Registry $registry
48
-     */
49
-    protected $registry;
46
+	/**
47
+	 * @var EE_Registry $registry
48
+	 */
49
+	protected $registry;
50 50
 
51 51
 
52 52
 
53
-    /**
54
-     * EE_Load_Espresso_Core constructor
55
-     */
53
+	/**
54
+	 * EE_Load_Espresso_Core constructor
55
+	 */
56 56
 	public function __construct() {
57
-        // deprecated functions
58
-        espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
59
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * handle
66
-     * sets hooks for running rest of system
67
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
-     * starting EE Addons from any other point may lead to problems
69
-     *
70
-     * @param EE_Request  $request
71
-     * @param EE_Response $response
72
-     * @return EE_Response
73
-     * @throws EE_Error
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     * @throws InvalidArgumentException
77
-     */
78
-    public function handle_request(EE_Request $request, EE_Response $response)
79
-    {
80
-        $this->request = $request;
81
-        $this->response = $response;
82
-        // info about how to load classes required by other classes
83
-        $this->dependency_map = $this->_load_dependency_map();
84
-        // central repository for classes
85
-        $this->registry = $this->_load_registry();
86
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
87
-        $this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
88
-        $this->dependency_map->setLoader($this->loader);
89
-        // create and cache the CommandBus, and also add middleware
90
-        $this->registry->create(
91
-            'CommandBusInterface',
92
-            array(
93
-                null,
94
-                apply_filters(
95
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
96
-                    array(
97
-                        $this->registry->create('CapChecker'),
98
-                        $this->registry->create('AddActionHook'),
99
-                    )
100
-                ),
101
-            ),
102
-            true
103
-        );
104
-        // workarounds for PHP < 5.3
105
-        $this->_load_class_tools();
106
-        // deprecated functions
107
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
108
-        // WP cron jobs
109
-        $this->registry->load_core('Cron_Tasks');
110
-        $this->registry->load_core('EE_Request_Handler');
111
-        $this->registry->load_core('EE_System');
112
-        return $this->response;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @return EE_Request
119
-     */
120
-    public function request()
121
-    {
122
-        return $this->request;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * @return EE_Response
129
-     */
130
-    public function response()
131
-    {
132
-        return $this->response;
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * @return EE_Dependency_Map
139
-     * @throws EE_Error
140
-     */
141
-    public function dependency_map()
142
-    {
143
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
144
-            throw new EE_Error(
145
-                sprintf(
146
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
147
-                    print_r($this->dependency_map, true)
148
-                )
149
-            );
150
-        }
151
-        return $this->dependency_map;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @return EE_Registry
158
-     * @throws EE_Error
159
-     */
160
-    public function registry()
161
-    {
162
-        if (! $this->registry instanceof EE_Registry) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
166
-                    print_r($this->registry, true)
167
-                )
168
-            );
169
-        }
170
-        return $this->registry;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * @return EE_Dependency_Map
177
-     */
178
-    private function _load_dependency_map()
179
-    {
180
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
181
-            EE_Error::add_error(
182
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
183
-                __FILE__, __FUNCTION__, __LINE__
184
-            );
185
-            wp_die(EE_Error::get_notices());
186
-        }
187
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
188
-        return EE_Dependency_Map::instance($this->request, $this->response);
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @return EE_Registry
195
-     */
196
-    private function _load_registry()
197
-    {
198
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
199
-            EE_Error::add_error(
200
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
201
-                __FILE__, __FUNCTION__, __LINE__
202
-            );
203
-            wp_die(EE_Error::get_notices());
204
-        }
205
-        require_once(EE_CORE . 'EE_Registry.core.php');
206
-        return EE_Registry::instance($this->dependency_map);
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * @return void
213
-     */
214
-    private function _load_class_tools()
215
-    {
216
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
217
-            EE_Error::add_error(
218
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
219
-                __FILE__, __FUNCTION__, __LINE__
220
-            );
221
-        }
222
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * called after the request stack has been fully processed
229
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
230
-     *
231
-     * @param EE_Request  $request
232
-     * @param EE_Response $response
233
-     */
234
-    public function handle_response(EE_Request $request, EE_Response $response)
235
-    {
236
-        if ($response->plugin_deactivated()) {
237
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
238
-        }
239
-    }
57
+		// deprecated functions
58
+		espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
59
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * handle
66
+	 * sets hooks for running rest of system
67
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
68
+	 * starting EE Addons from any other point may lead to problems
69
+	 *
70
+	 * @param EE_Request  $request
71
+	 * @param EE_Response $response
72
+	 * @return EE_Response
73
+	 * @throws EE_Error
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 * @throws InvalidArgumentException
77
+	 */
78
+	public function handle_request(EE_Request $request, EE_Response $response)
79
+	{
80
+		$this->request = $request;
81
+		$this->response = $response;
82
+		// info about how to load classes required by other classes
83
+		$this->dependency_map = $this->_load_dependency_map();
84
+		// central repository for classes
85
+		$this->registry = $this->_load_registry();
86
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
87
+		$this->loader = $this->registry->create('EventEspresso\core\services\loaders\Loader');
88
+		$this->dependency_map->setLoader($this->loader);
89
+		// create and cache the CommandBus, and also add middleware
90
+		$this->registry->create(
91
+			'CommandBusInterface',
92
+			array(
93
+				null,
94
+				apply_filters(
95
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
96
+					array(
97
+						$this->registry->create('CapChecker'),
98
+						$this->registry->create('AddActionHook'),
99
+					)
100
+				),
101
+			),
102
+			true
103
+		);
104
+		// workarounds for PHP < 5.3
105
+		$this->_load_class_tools();
106
+		// deprecated functions
107
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
108
+		// WP cron jobs
109
+		$this->registry->load_core('Cron_Tasks');
110
+		$this->registry->load_core('EE_Request_Handler');
111
+		$this->registry->load_core('EE_System');
112
+		return $this->response;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @return EE_Request
119
+	 */
120
+	public function request()
121
+	{
122
+		return $this->request;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * @return EE_Response
129
+	 */
130
+	public function response()
131
+	{
132
+		return $this->response;
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * @return EE_Dependency_Map
139
+	 * @throws EE_Error
140
+	 */
141
+	public function dependency_map()
142
+	{
143
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
144
+			throw new EE_Error(
145
+				sprintf(
146
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
147
+					print_r($this->dependency_map, true)
148
+				)
149
+			);
150
+		}
151
+		return $this->dependency_map;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @return EE_Registry
158
+	 * @throws EE_Error
159
+	 */
160
+	public function registry()
161
+	{
162
+		if (! $this->registry instanceof EE_Registry) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
166
+					print_r($this->registry, true)
167
+				)
168
+			);
169
+		}
170
+		return $this->registry;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * @return EE_Dependency_Map
177
+	 */
178
+	private function _load_dependency_map()
179
+	{
180
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
181
+			EE_Error::add_error(
182
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
183
+				__FILE__, __FUNCTION__, __LINE__
184
+			);
185
+			wp_die(EE_Error::get_notices());
186
+		}
187
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
188
+		return EE_Dependency_Map::instance($this->request, $this->response);
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @return EE_Registry
195
+	 */
196
+	private function _load_registry()
197
+	{
198
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
199
+			EE_Error::add_error(
200
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
201
+				__FILE__, __FUNCTION__, __LINE__
202
+			);
203
+			wp_die(EE_Error::get_notices());
204
+		}
205
+		require_once(EE_CORE . 'EE_Registry.core.php');
206
+		return EE_Registry::instance($this->dependency_map);
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * @return void
213
+	 */
214
+	private function _load_class_tools()
215
+	{
216
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
217
+			EE_Error::add_error(
218
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
219
+				__FILE__, __FUNCTION__, __LINE__
220
+			);
221
+		}
222
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * called after the request stack has been fully processed
229
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
230
+	 *
231
+	 * @param EE_Request  $request
232
+	 * @param EE_Response $response
233
+	 */
234
+	public function handle_response(EE_Request $request, EE_Response $response)
235
+	{
236
+		if ($response->plugin_deactivated()) {
237
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
238
+		}
239
+	}
240 240
 
241 241
 
242 242
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
      */
56 56
 	public function __construct() {
57 57
         // deprecated functions
58
-        espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
59
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
58
+        espresso_load_required('EE_Base', EE_CORE.'EE_Base.core.php');
59
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
60 60
     }
61 61
 
62 62
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         // workarounds for PHP < 5.3
105 105
         $this->_load_class_tools();
106 106
         // deprecated functions
107
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
107
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
108 108
         // WP cron jobs
109 109
         $this->registry->load_core('Cron_Tasks');
110 110
         $this->registry->load_core('EE_Request_Handler');
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function dependency_map()
142 142
     {
143
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
143
+        if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
144 144
             throw new EE_Error(
145 145
                 sprintf(
146 146
                     __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function registry()
161 161
     {
162
-        if (! $this->registry instanceof EE_Registry) {
162
+        if ( ! $this->registry instanceof EE_Registry) {
163 163
             throw new EE_Error(
164 164
                 sprintf(
165 165
                     __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
      */
178 178
     private function _load_dependency_map()
179 179
     {
180
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
180
+        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
181 181
             EE_Error::add_error(
182 182
                 __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
183 183
                 __FILE__, __FUNCTION__, __LINE__
184 184
             );
185 185
             wp_die(EE_Error::get_notices());
186 186
         }
187
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
187
+        require_once(EE_CORE.'EE_Dependency_Map.core.php');
188 188
         return EE_Dependency_Map::instance($this->request, $this->response);
189 189
     }
190 190
 
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
      */
196 196
     private function _load_registry()
197 197
     {
198
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
198
+        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
199 199
             EE_Error::add_error(
200 200
                 __('The EE_Registry core class could not be loaded.', 'event_espresso'),
201 201
                 __FILE__, __FUNCTION__, __LINE__
202 202
             );
203 203
             wp_die(EE_Error::get_notices());
204 204
         }
205
-        require_once(EE_CORE . 'EE_Registry.core.php');
205
+        require_once(EE_CORE.'EE_Registry.core.php');
206 206
         return EE_Registry::instance($this->dependency_map);
207 207
     }
208 208
 
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
      */
214 214
     private function _load_class_tools()
215 215
     {
216
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
216
+        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
217 217
             EE_Error::add_error(
218 218
                 __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
219 219
                 __FILE__, __FUNCTION__, __LINE__
220 220
             );
221 221
         }
222
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
222
+        require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
223 223
     }
224 224
 
225 225
 
Please login to merge, or discard this patch.
core/EE_Bootstrap.core.php 2 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -29,191 +29,191 @@
 block discarded – undo
29 29
 class EE_Bootstrap
30 30
 {
31 31
 
32
-    /**
33
-     * @var EE_Request $request
34
-     */
35
-    protected $request;
36
-
37
-    /**
38
-     * @var EE_Response $response
39
-     */
40
-    protected $response;
41
-
42
-    /**
43
-     * @var EE_Request_Stack_Builder $request_stack_builder
44
-     */
45
-    protected $request_stack_builder;
46
-
47
-    /**
48
-     * @var EE_Request_Stack $_request_stack
49
-     */
50
-    protected $request_stack;
51
-
52
-
53
-
54
-    public function __construct(EE_Request $request, EE_Response $response)
55
-    {
56
-        $this->request = $request;
57
-        $this->response = $response;
58
-        // construct request stack and run middleware apps as soon as all WP plugins are loaded
59
-        add_action('plugins_loaded', array($this, 'run_request_stack'), 0);
60
-        // set framework for the rest of EE to hook into when loading
61
-        add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1);
62
-        add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3);
63
-        add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5);
64
-        add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7);
65
-        add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * run_request_stack
72
-     * construct request stack and run middleware apps
73
-     *
74
-     * @throws EE_Error
75
-     * @throws InvalidArgumentException
76
-     */
77
-    public function run_request_stack()
78
-    {
79
-        $this->load_autoloader();
80
-        $this->set_autoloaders_for_required_files();
81
-        $this->request_stack_builder = $this->build_request_stack();
82
-        $this->request_stack = $this->request_stack_builder->resolve(
83
-            new EE_Load_Espresso_Core()
84
-        );
85
-        $this->request_stack->handle_request($this->request, $this->response);
86
-        $this->request_stack->handle_response();
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * load_autoloader
93
-     */
94
-    protected function load_autoloader()
95
-    {
96
-        // load interfaces
97
-        espresso_load_required(
98
-            'EEH_Autoloader',
99
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
100
-        );
101
-        EEH_Autoloader::instance();
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * load_required_files
108
-     *
109
-     * @throws EE_Error
110
-     */
111
-    protected function set_autoloaders_for_required_files()
112
-    {
113
-        // load interfaces
114
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
115
-        // load helpers
116
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
117
-        // load request stack
118
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
119
-        // load middleware
120
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * build_request_stack
127
-     *
128
-     * @return EE_Request_Stack_Builder
129
-     * @throws InvalidArgumentException
130
-     */
131
-    public function build_request_stack()
132
-    {
133
-        $request_stack_builder = new EE_Request_Stack_Builder();
134
-        $stack_apps = apply_filters(
135
-            'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
136
-            array(
137
-                'EE_Detect_Login',
138
-                'EE_Recommended_Versions',
139
-                'EE_Alpha_Banner_Warning',
140
-            )
141
-        );
142
-        // load middleware onto stack : FILO (First In Last Out)
143
-        foreach ((array)$stack_apps as $stack_app) {
144
-            //$request_stack_builder->push( $stack_app );
145
-            $request_stack_builder->unshift($stack_app);
146
-        }
147
-        return apply_filters(
148
-            'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
149
-            $request_stack_builder
150
-        );
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * load_espresso_addons
157
-     * runs during the WP 'plugins_loaded' action at priority 1
158
-     * and is the initial loading phase for EE addons
159
-     * no other logic should be performed at this point
160
-     */
161
-    public static function load_espresso_addons()
162
-    {
163
-        do_action('AHEE__EE_Bootstrap__load_espresso_addons');
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * detect_activations_or_upgrades
170
-     * runs during the WP 'plugins_loaded' action at priority 3
171
-     * Now that all of the addons have been loaded,
172
-     * we can determine if anything needs activating or upgrading
173
-     */
174
-    public static function detect_activations_or_upgrades()
175
-    {
176
-        do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * load_core_configuration
183
-     * runs during the WP 'plugins_loaded' action at priority 5
184
-     * Now that the database is assumed to be at the correct version
185
-     * we can load and set all of the system configurations
186
-     */
187
-    public static function load_core_configuration()
188
-    {
189
-        do_action('AHEE__EE_Bootstrap__load_core_configuration');
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * register_shortcodes_modules_and_widgets
196
-     * runs during the WP 'plugins_loaded' action at priority 7
197
-     * and handles registering all o four shortcodes, modules and widgets
198
-     * so that they are ready to be used throughout the system
199
-     */
200
-    public static function register_shortcodes_modules_and_widgets()
201
-    {
202
-        do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * brew_espresso
209
-     * runs during the WP 'plugins_loaded' action at priority 9
210
-     * bootstrapping is considered complete at this point,
211
-     * so let the fun begin...
212
-     */
213
-    public static function brew_espresso()
214
-    {
215
-        do_action('AHEE__EE_Bootstrap__brew_espresso');
216
-    }
32
+	/**
33
+	 * @var EE_Request $request
34
+	 */
35
+	protected $request;
36
+
37
+	/**
38
+	 * @var EE_Response $response
39
+	 */
40
+	protected $response;
41
+
42
+	/**
43
+	 * @var EE_Request_Stack_Builder $request_stack_builder
44
+	 */
45
+	protected $request_stack_builder;
46
+
47
+	/**
48
+	 * @var EE_Request_Stack $_request_stack
49
+	 */
50
+	protected $request_stack;
51
+
52
+
53
+
54
+	public function __construct(EE_Request $request, EE_Response $response)
55
+	{
56
+		$this->request = $request;
57
+		$this->response = $response;
58
+		// construct request stack and run middleware apps as soon as all WP plugins are loaded
59
+		add_action('plugins_loaded', array($this, 'run_request_stack'), 0);
60
+		// set framework for the rest of EE to hook into when loading
61
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1);
62
+		add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3);
63
+		add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5);
64
+		add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7);
65
+		add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * run_request_stack
72
+	 * construct request stack and run middleware apps
73
+	 *
74
+	 * @throws EE_Error
75
+	 * @throws InvalidArgumentException
76
+	 */
77
+	public function run_request_stack()
78
+	{
79
+		$this->load_autoloader();
80
+		$this->set_autoloaders_for_required_files();
81
+		$this->request_stack_builder = $this->build_request_stack();
82
+		$this->request_stack = $this->request_stack_builder->resolve(
83
+			new EE_Load_Espresso_Core()
84
+		);
85
+		$this->request_stack->handle_request($this->request, $this->response);
86
+		$this->request_stack->handle_response();
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * load_autoloader
93
+	 */
94
+	protected function load_autoloader()
95
+	{
96
+		// load interfaces
97
+		espresso_load_required(
98
+			'EEH_Autoloader',
99
+			EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
100
+		);
101
+		EEH_Autoloader::instance();
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * load_required_files
108
+	 *
109
+	 * @throws EE_Error
110
+	 */
111
+	protected function set_autoloaders_for_required_files()
112
+	{
113
+		// load interfaces
114
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
115
+		// load helpers
116
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
117
+		// load request stack
118
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
119
+		// load middleware
120
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * build_request_stack
127
+	 *
128
+	 * @return EE_Request_Stack_Builder
129
+	 * @throws InvalidArgumentException
130
+	 */
131
+	public function build_request_stack()
132
+	{
133
+		$request_stack_builder = new EE_Request_Stack_Builder();
134
+		$stack_apps = apply_filters(
135
+			'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
136
+			array(
137
+				'EE_Detect_Login',
138
+				'EE_Recommended_Versions',
139
+				'EE_Alpha_Banner_Warning',
140
+			)
141
+		);
142
+		// load middleware onto stack : FILO (First In Last Out)
143
+		foreach ((array)$stack_apps as $stack_app) {
144
+			//$request_stack_builder->push( $stack_app );
145
+			$request_stack_builder->unshift($stack_app);
146
+		}
147
+		return apply_filters(
148
+			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
149
+			$request_stack_builder
150
+		);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * load_espresso_addons
157
+	 * runs during the WP 'plugins_loaded' action at priority 1
158
+	 * and is the initial loading phase for EE addons
159
+	 * no other logic should be performed at this point
160
+	 */
161
+	public static function load_espresso_addons()
162
+	{
163
+		do_action('AHEE__EE_Bootstrap__load_espresso_addons');
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * detect_activations_or_upgrades
170
+	 * runs during the WP 'plugins_loaded' action at priority 3
171
+	 * Now that all of the addons have been loaded,
172
+	 * we can determine if anything needs activating or upgrading
173
+	 */
174
+	public static function detect_activations_or_upgrades()
175
+	{
176
+		do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades');
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * load_core_configuration
183
+	 * runs during the WP 'plugins_loaded' action at priority 5
184
+	 * Now that the database is assumed to be at the correct version
185
+	 * we can load and set all of the system configurations
186
+	 */
187
+	public static function load_core_configuration()
188
+	{
189
+		do_action('AHEE__EE_Bootstrap__load_core_configuration');
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * register_shortcodes_modules_and_widgets
196
+	 * runs during the WP 'plugins_loaded' action at priority 7
197
+	 * and handles registering all o four shortcodes, modules and widgets
198
+	 * so that they are ready to be used throughout the system
199
+	 */
200
+	public static function register_shortcodes_modules_and_widgets()
201
+	{
202
+		do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets');
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * brew_espresso
209
+	 * runs during the WP 'plugins_loaded' action at priority 9
210
+	 * bootstrapping is considered complete at this point,
211
+	 * so let the fun begin...
212
+	 */
213
+	public static function brew_espresso()
214
+	{
215
+		do_action('AHEE__EE_Bootstrap__brew_espresso');
216
+	}
217 217
 
218 218
 
219 219
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         // load interfaces
97 97
         espresso_load_required(
98 98
             'EEH_Autoloader',
99
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
99
+            EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php'
100 100
         );
101 101
         EEH_Autoloader::instance();
102 102
     }
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
     protected function set_autoloaders_for_required_files()
112 112
     {
113 113
         // load interfaces
114
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
114
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces', true);
115 115
         // load helpers
116 116
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
117 117
         // load request stack
118
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
118
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS);
119 119
         // load middleware
120
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
120
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS);
121 121
     }
122 122
 
123 123
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             )
141 141
         );
142 142
         // load middleware onto stack : FILO (First In Last Out)
143
-        foreach ((array)$stack_apps as $stack_app) {
143
+        foreach ((array) $stack_apps as $stack_app) {
144 144
             //$request_stack_builder->push( $stack_app );
145 145
             $request_stack_builder->unshift($stack_app);
146 146
         }
Please login to merge, or discard this patch.
core/EE_Registry.core.php 2 patches
Indentation   +1415 added lines, -1415 removed lines patch added patch discarded remove patch
@@ -16,1451 +16,1451 @@
 block discarded – undo
16 16
 class EE_Registry
17 17
 {
18 18
 
19
-    /**
20
-     *    EE_Registry Object
21
-     *
22
-     * @var EE_Registry $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance = null;
26
-
27
-    /**
28
-     * @var EE_Dependency_Map $_dependency_map
29
-     * @access    protected
30
-     */
31
-    protected $_dependency_map = null;
32
-
33
-    /**
34
-     * @var array $_class_abbreviations
35
-     * @access    protected
36
-     */
37
-    protected $_class_abbreviations = array();
38
-
39
-    /**
40
-     * @access public
41
-     * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     *    EE_Cart Object
47
-     *
48
-     * @access    public
49
-     * @var    EE_Cart $CART
50
-     */
51
-    public $CART = null;
52
-
53
-    /**
54
-     *    EE_Config Object
55
-     *
56
-     * @access    public
57
-     * @var    EE_Config $CFG
58
-     */
59
-    public $CFG = null;
60
-
61
-    /**
62
-     * EE_Network_Config Object
63
-     *
64
-     * @access public
65
-     * @var EE_Network_Config $NET_CFG
66
-     */
67
-    public $NET_CFG = null;
68
-
69
-    /**
70
-     *    StdClass object for storing library classes in
71
-     *
72
-     * @public LIB
73
-     * @var StdClass $LIB
74
-     */
75
-    public $LIB = null;
76
-
77
-    /**
78
-     *    EE_Request_Handler Object
79
-     *
80
-     * @access    public
81
-     * @var    EE_Request_Handler $REQ
82
-     */
83
-    public $REQ = null;
84
-
85
-    /**
86
-     *    EE_Session Object
87
-     *
88
-     * @access    public
89
-     * @var    EE_Session $SSN
90
-     */
91
-    public $SSN = null;
92
-
93
-    /**
94
-     * holds the ee capabilities object.
95
-     *
96
-     * @since 4.5.0
97
-     * @var EE_Capabilities
98
-     */
99
-    public $CAP = null;
100
-
101
-    /**
102
-     * holds the EE_Message_Resource_Manager object.
103
-     *
104
-     * @since 4.9.0
105
-     * @var EE_Message_Resource_Manager
106
-     */
107
-    public $MRM = null;
108
-
109
-
110
-    /**
111
-     * Holds the Assets Registry instance
112
-     * @var Registry
113
-     */
114
-    public $AssetsRegistry = null;
115
-
116
-    /**
117
-     *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
-     *
119
-     * @access    public
120
-     * @var    EE_Addon[]
121
-     */
122
-    public $addons = null;
123
-
124
-    /**
125
-     *    $models
126
-     * @access    public
127
-     * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
-     */
129
-    public $models = array();
130
-
131
-    /**
132
-     *    $modules
133
-     * @access    public
134
-     * @var    EED_Module[] $modules
135
-     */
136
-    public $modules = null;
137
-
138
-    /**
139
-     *    $shortcodes
140
-     * @access    public
141
-     * @var    EES_Shortcode[] $shortcodes
142
-     */
143
-    public $shortcodes = null;
144
-
145
-    /**
146
-     *    $widgets
147
-     * @access    public
148
-     * @var    WP_Widget[] $widgets
149
-     */
150
-    public $widgets = null;
151
-
152
-    /**
153
-     * $non_abstract_db_models
154
-     * @access public
155
-     * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
-     * classnames (eg "EEM_Event")
159
-     */
160
-    public $non_abstract_db_models = array();
161
-
162
-
163
-    /**
164
-     *    $i18n_js_strings - internationalization for JS strings
165
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
-     *    in js file:  var translatedString = eei18n.string_key;
167
-     *
168
-     * @access    public
169
-     * @var    array
170
-     */
171
-    public static $i18n_js_strings = array();
172
-
173
-
174
-    /**
175
-     *    $main_file - path to espresso.php
176
-     *
177
-     * @access    public
178
-     * @var    array
179
-     */
180
-    public $main_file;
181
-
182
-    /**
183
-     * array of ReflectionClass objects where the key is the class name
184
-     *
185
-     * @access    public
186
-     * @var ReflectionClass[]
187
-     */
188
-    public $_reflectors;
189
-
190
-    /**
191
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
-     *
193
-     * @access    protected
194
-     * @var boolean $_cache_on
195
-     */
196
-    protected $_cache_on = true;
197
-
198
-
199
-
200
-    /**
201
-     * @singleton method used to instantiate class object
202
-     * @access    public
203
-     * @param  \EE_Dependency_Map $dependency_map
204
-     * @return \EE_Registry instance
205
-     */
206
-    public static function instance(\EE_Dependency_Map $dependency_map = null)
207
-    {
208
-        // check if class object is instantiated
209
-        if ( ! self::$_instance instanceof EE_Registry) {
210
-            self::$_instance = new EE_Registry($dependency_map);
211
-        }
212
-        return self::$_instance;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     *protected constructor to prevent direct creation
219
-     *
220
-     * @Constructor
221
-     * @access protected
222
-     * @param  \EE_Dependency_Map $dependency_map
223
-     */
224
-    protected function __construct(\EE_Dependency_Map $dependency_map)
225
-    {
226
-        $this->_dependency_map = $dependency_map;
227
-        $this->LIB = new stdClass();
228
-        $this->addons = new stdClass();
229
-        $this->modules = new stdClass();
230
-        $this->shortcodes = new stdClass();
231
-        $this->widgets = new stdClass();
232
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * initialize
239
-     */
240
-    public function initialize()
241
-    {
242
-        $this->_class_abbreviations = apply_filters(
243
-            'FHEE__EE_Registry____construct___class_abbreviations',
244
-            array(
245
-                'EE_Config'                                       => 'CFG',
246
-                'EE_Session'                                      => 'SSN',
247
-                'EE_Capabilities'                                 => 'CAP',
248
-                'EE_Cart'                                         => 'CART',
249
-                'EE_Network_Config'                               => 'NET_CFG',
250
-                'EE_Request_Handler'                              => 'REQ',
251
-                'EE_Message_Resource_Manager'                     => 'MRM',
252
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
253
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
254
-            )
255
-        );
256
-        $this->load_core('Base', array(), true);
257
-        // add our request and response objects to the cache
258
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
259
-        $this->_set_cached_class(
260
-            $request_loader(),
261
-            'EE_Request'
262
-        );
263
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
264
-        $this->_set_cached_class(
265
-            $response_loader(),
266
-            'EE_Response'
267
-        );
268
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
269
-    }
270
-
271
-
272
-
273
-    /**
274
-     *    init
275
-     *
276
-     * @access    public
277
-     * @return    void
278
-     */
279
-    public function init()
280
-    {
281
-        // Get current page protocol
282
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
283
-        // Output admin-ajax.php URL with same protocol as current page
284
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
285
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * localize_i18n_js_strings
292
-     *
293
-     * @return string
294
-     */
295
-    public static function localize_i18n_js_strings()
296
-    {
297
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
298
-        foreach ($i18n_js_strings as $key => $value) {
299
-            if (is_scalar($value)) {
300
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
301
-            }
302
-        }
303
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * @param mixed string | EED_Module $module
310
-     */
311
-    public function add_module($module)
312
-    {
313
-        if ($module instanceof EED_Module) {
314
-            $module_class = get_class($module);
315
-            $this->modules->{$module_class} = $module;
316
-        } else {
317
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
318
-                $this->load_core('Module_Request_Router');
319
-            }
320
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
321
-        }
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @param string $module_name
328
-     * @return mixed EED_Module | NULL
329
-     */
330
-    public function get_module($module_name = '')
331
-    {
332
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     *    loads core classes - must be singletons
339
-     *
340
-     * @access    public
341
-     * @param string $class_name - simple class name ie: session
342
-     * @param mixed  $arguments
343
-     * @param bool   $load_only
344
-     * @return mixed
345
-     */
346
-    public function load_core($class_name, $arguments = array(), $load_only = false)
347
-    {
348
-        $core_paths = apply_filters(
349
-            'FHEE__EE_Registry__load_core__core_paths',
350
-            array(
351
-                EE_CORE,
352
-                EE_ADMIN,
353
-                EE_CPTS,
354
-                EE_CORE . 'data_migration_scripts' . DS,
355
-                EE_CORE . 'request_stack' . DS,
356
-                EE_CORE . 'middleware' . DS,
357
-            )
358
-        );
359
-        // retrieve instantiated class
360
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     *    loads service classes
367
-     *
368
-     * @access    public
369
-     * @param string $class_name - simple class name ie: session
370
-     * @param mixed  $arguments
371
-     * @param bool   $load_only
372
-     * @return mixed
373
-     */
374
-    public function load_service($class_name, $arguments = array(), $load_only = false)
375
-    {
376
-        $service_paths = apply_filters(
377
-            'FHEE__EE_Registry__load_service__service_paths',
378
-            array(
379
-                EE_CORE . 'services' . DS,
380
-            )
381
-        );
382
-        // retrieve instantiated class
383
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     *    loads data_migration_scripts
390
-     *
391
-     * @access    public
392
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
393
-     * @param mixed  $arguments
394
-     * @return EE_Data_Migration_Script_Base|mixed
395
-     */
396
-    public function load_dms($class_name, $arguments = array())
397
-    {
398
-        // retrieve instantiated class
399
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     *    loads object creating classes - must be singletons
406
-     *
407
-     * @param string $class_name - simple class name ie: attendee
408
-     * @param mixed  $arguments  - an array of arguments to pass to the class
409
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
410
-     * @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)
411
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
412
-     * @return EE_Base_Class | bool
413
-     */
414
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
415
-    {
416
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
417
-            EE_CORE,
418
-            EE_CLASSES,
419
-            EE_BUSINESS,
420
-        ));
421
-        // retrieve instantiated class
422
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     *    loads helper classes - must be singletons
429
-     *
430
-     * @param string $class_name - simple class name ie: price
431
-     * @param mixed  $arguments
432
-     * @param bool   $load_only
433
-     * @return EEH_Base | bool
434
-     */
435
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
436
-    {
437
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
438
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
439
-        // retrieve instantiated class
440
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     *    loads core classes - must be singletons
447
-     *
448
-     * @access    public
449
-     * @param string $class_name - simple class name ie: session
450
-     * @param mixed  $arguments
451
-     * @param bool   $load_only
452
-     * @param bool   $cache      whether to cache the object or not.
453
-     * @return mixed
454
-     */
455
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
456
-    {
457
-        $paths = array(
458
-            EE_LIBRARIES,
459
-            EE_LIBRARIES . 'messages' . DS,
460
-            EE_LIBRARIES . 'shortcodes' . DS,
461
-            EE_LIBRARIES . 'qtips' . DS,
462
-            EE_LIBRARIES . 'payment_methods' . DS,
463
-            EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
464
-        );
465
-        // retrieve instantiated class
466
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     *    loads model classes - must be singletons
473
-     *
474
-     * @param string $class_name - simple class name ie: price
475
-     * @param mixed  $arguments
476
-     * @param bool   $load_only
477
-     * @return EEM_Base | bool
478
-     */
479
-    public function load_model($class_name, $arguments = array(), $load_only = false)
480
-    {
481
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
482
-            EE_MODELS,
483
-            EE_CORE,
484
-        ));
485
-        // retrieve instantiated class
486
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     *    loads model classes - must be singletons
493
-     *
494
-     * @param string $class_name - simple class name ie: price
495
-     * @param mixed  $arguments
496
-     * @param bool   $load_only
497
-     * @return mixed | bool
498
-     */
499
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
500
-    {
501
-        $paths = array(
502
-            EE_MODELS . 'fields' . DS,
503
-            EE_MODELS . 'helpers' . DS,
504
-            EE_MODELS . 'relations' . DS,
505
-            EE_MODELS . 'strategies' . DS,
506
-        );
507
-        // retrieve instantiated class
508
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
509
-    }
510
-
511
-
512
-
513
-    /**
514
-     * Determines if $model_name is the name of an actual EE model.
515
-     *
516
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
517
-     * @return boolean
518
-     */
519
-    public function is_model_name($model_name)
520
-    {
521
-        return isset($this->models[$model_name]) ? true : false;
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     *    generic class loader
528
-     *
529
-     * @param string $path_to_file - directory path to file location, not including filename
530
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
531
-     * @param string $type         - file type - core? class? helper? model?
532
-     * @param mixed  $arguments
533
-     * @param bool   $load_only
534
-     * @return mixed
535
-     */
536
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
537
-    {
538
-        // retrieve instantiated class
539
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     *    load_addon
546
-     *
547
-     * @param string $path_to_file - directory path to file location, not including filename
548
-     * @param string $class_name   - full class name  ie:  My_Class
549
-     * @param string $type         - file type - core? class? helper? model?
550
-     * @param mixed  $arguments
551
-     * @param bool   $load_only
552
-     * @return EE_Addon
553
-     */
554
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
555
-    {
556
-        // retrieve instantiated class
557
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
558
-    }
559
-
560
-
561
-
562
-    /**
563
-     * instantiates, caches, and automatically resolves dependencies
564
-     * for classes that use a Fully Qualified Class Name.
565
-     * if the class is not capable of being loaded using PSR-4 autoloading,
566
-     * then you need to use one of the existing load_*() methods
567
-     * which can resolve the classname and filepath from the passed arguments
568
-     *
569
-     * @param bool|string $class_name   Fully Qualified Class Name
570
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
571
-     * @param bool        $cache        whether to cache the instantiated object for reuse
572
-     * @param bool        $from_db      some classes are instantiated from the db
573
-     *                                  and thus call a different method to instantiate
574
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
575
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
576
-     * @return mixed                    null = failure to load or instantiate class object.
577
-     *                                  object = class loaded and instantiated successfully.
578
-     *                                  bool = fail or success when $load_only is true
579
-     */
580
-    public function create(
581
-        $class_name = false,
582
-        $arguments = array(),
583
-        $cache = false,
584
-        $from_db = false,
585
-        $load_only = false,
586
-        $addon = false
587
-    ) {
588
-        $class_name = ltrim($class_name, '\\');
589
-        $class_name = $this->_dependency_map->get_alias($class_name);
590
-        if ( ! class_exists($class_name)) {
591
-            // maybe the class is registered with a preceding \
592
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
593
-            // still doesn't exist ?
594
-            if ( ! class_exists($class_name)) {
595
-                return null;
596
-            }
597
-        }
598
-        // if we're only loading the class and it already exists, then let's just return true immediately
599
-        if ($load_only) {
600
-            return true;
601
-        }
602
-        $addon = $addon ? 'addon' : '';
603
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
604
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
605
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
606
-        if ($this->_cache_on && $cache && ! $load_only) {
607
-            // return object if it's already cached
608
-            $cached_class = $this->_get_cached_class($class_name, $addon);
609
-            if ($cached_class !== null) {
610
-                return $cached_class;
611
-            }
612
-        }
613
-        // instantiate the requested object
614
-        $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
615
-        if ($this->_cache_on && $cache) {
616
-            // save it for later... kinda like gum  { : $
617
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
618
-        }
619
-        $this->_cache_on = true;
620
-        return $class_obj;
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * instantiates, caches, and injects dependencies for classes
627
-     *
628
-     * @param array       $file_paths   an array of paths to folders to look in
629
-     * @param string      $class_prefix EE  or EEM or... ???
630
-     * @param bool|string $class_name   $class name
631
-     * @param string      $type         file type - core? class? helper? model?
632
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
633
-     * @param bool        $from_db      some classes are instantiated from the db
634
-     *                                  and thus call a different method to instantiate
635
-     * @param bool        $cache        whether to cache the instantiated object for reuse
636
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
637
-     * @return null|object|bool         null = failure to load or instantiate class object.
638
-     *                                  object = class loaded and instantiated successfully.
639
-     *                                  bool = fail or success when $load_only is true
640
-     */
641
-    protected function _load(
642
-        $file_paths = array(),
643
-        $class_prefix = 'EE_',
644
-        $class_name = false,
645
-        $type = 'class',
646
-        $arguments = array(),
647
-        $from_db = false,
648
-        $cache = true,
649
-        $load_only = false
650
-    ) {
651
-        $class_name = ltrim($class_name, '\\');
652
-        // strip php file extension
653
-        $class_name = str_replace('.php', '', trim($class_name));
654
-        // does the class have a prefix ?
655
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
656
-            // make sure $class_prefix is uppercase
657
-            $class_prefix = strtoupper(trim($class_prefix));
658
-            // add class prefix ONCE!!!
659
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
660
-        }
661
-        $class_name = $this->_dependency_map->get_alias($class_name);
662
-        $class_exists = class_exists($class_name, false);
663
-        // if we're only loading the class and it already exists, then let's just return true immediately
664
-        if ($load_only && $class_exists) {
665
-            return true;
666
-        }
667
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
668
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
669
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
670
-        if ($this->_cache_on && $cache && ! $load_only) {
671
-            // return object if it's already cached
672
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
673
-            if ($cached_class !== null) {
674
-                return $cached_class;
675
-            }
676
-        }
677
-        // if the class doesn't already exist.. then we need to try and find the file and load it
678
-        if ( ! $class_exists) {
679
-            // get full path to file
680
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
681
-            // load the file
682
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
683
-            // if loading failed, or we are only loading a file but NOT instantiating an object
684
-            if ( ! $loaded || $load_only) {
685
-                // return boolean if only loading, or null if an object was expected
686
-                return $load_only ? $loaded : null;
687
-            }
688
-        }
689
-        // instantiate the requested object
690
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
691
-        if ($this->_cache_on && $cache) {
692
-            // save it for later... kinda like gum  { : $
693
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
694
-        }
695
-        $this->_cache_on = true;
696
-        return $class_obj;
697
-    }
698
-
699
-
700
-
701
-
702
-    /**
703
-     * _get_cached_class
704
-     * attempts to find a cached version of the requested class
705
-     * by looking in the following places:
706
-     *        $this->{$class_abbreviation}            ie:    $this->CART
707
-     *        $this->{$class_name}                        ie:    $this->Some_Class
708
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
709
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
710
-     *
711
-     * @access protected
712
-     * @param string $class_name
713
-     * @param string $class_prefix
714
-     * @return mixed
715
-     */
716
-    protected function _get_cached_class($class_name, $class_prefix = '')
717
-    {
718
-        // have to specify something, but not anything that will conflict
719
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
720
-            ? $this->_class_abbreviations[ $class_name ]
721
-            : 'FANCY_BATMAN_PANTS';
722
-        $class_name = str_replace('\\', '_', $class_name);
723
-        // check if class has already been loaded, and return it if it has been
724
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
725
-            return $this->{$class_abbreviation};
726
-        }
727
-        if (isset ($this->{$class_name})) {
728
-            return $this->{$class_name};
729
-        }
730
-        if (isset ($this->LIB->{$class_name})) {
731
-            return $this->LIB->{$class_name};
732
-        }
733
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
734
-            return $this->addons->{$class_name};
735
-        }
736
-        return null;
737
-    }
738
-
739
-
740
-
741
-    /**
742
-     * removes a cached version of the requested class
743
-     *
744
-     * @param string $class_name
745
-     * @param boolean $addon
746
-     * @return boolean
747
-     */
748
-    public function clear_cached_class($class_name, $addon = false)
749
-    {
750
-        // have to specify something, but not anything that will conflict
751
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
752
-            ? $this->_class_abbreviations[ $class_name ]
753
-            : 'FANCY_BATMAN_PANTS';
754
-        $class_name = str_replace('\\', '_', $class_name);
755
-        // check if class has already been loaded, and return it if it has been
756
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
757
-            $this->{$class_abbreviation} = null;
758
-            return true;
759
-        }
760
-        if (isset($this->{$class_name})) {
761
-            $this->{$class_name} = null;
762
-            return true;
763
-        }
764
-        if (isset($this->LIB->{$class_name})) {
765
-            unset($this->LIB->{$class_name});
766
-            return true;
767
-        }
768
-        if ($addon && isset($this->addons->{$class_name})) {
769
-            unset($this->addons->{$class_name});
770
-            return true;
771
-        }
772
-        return false;
773
-    }
774
-
775
-
776
-    /**
777
-     * _resolve_path
778
-     * attempts to find a full valid filepath for the requested class.
779
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
780
-     * then returns that path if the target file has been found and is readable
781
-     *
782
-     * @access protected
783
-     * @param string $class_name
784
-     * @param string $type
785
-     * @param array  $file_paths
786
-     * @return string | bool
787
-     */
788
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
789
-    {
790
-        // make sure $file_paths is an array
791
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
792
-        // cycle thru paths
793
-        foreach ($file_paths as $key => $file_path) {
794
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
795
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
796
-            // prep file type
797
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
798
-            // build full file path
799
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
800
-            //does the file exist and can be read ?
801
-            if (is_readable($file_paths[$key])) {
802
-                return $file_paths[$key];
803
-            }
804
-        }
805
-        return false;
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * _require_file
812
-     * basically just performs a require_once()
813
-     * but with some error handling
814
-     *
815
-     * @access protected
816
-     * @param  string $path
817
-     * @param  string $class_name
818
-     * @param  string $type
819
-     * @param  array  $file_paths
820
-     * @return boolean
821
-     * @throws \EE_Error
822
-     */
823
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
824
-    {
825
-        $this->resolve_legacy_class_parent($class_name);
826
-        // don't give up! you gotta...
827
-        try {
828
-            //does the file exist and can it be read ?
829
-            if ( ! $path) {
830
-                // so sorry, can't find the file
831
-                throw new EE_Error (
832
-                    sprintf(
833
-                        __('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'),
834
-                        trim($type, '.'),
835
-                        $class_name,
836
-                        '<br />' . implode(',<br />', $file_paths)
837
-                    )
838
-                );
839
-            }
840
-            // get the file
841
-            require_once($path);
842
-            // if the class isn't already declared somewhere
843
-            if (class_exists($class_name, false) === false) {
844
-                // so sorry, not a class
845
-                throw new EE_Error(
846
-                    sprintf(
847
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
848
-                        $type,
849
-                        $path,
850
-                        $class_name
851
-                    )
852
-                );
853
-            }
854
-        } catch (EE_Error $e) {
855
-            $e->get_error();
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-
863
-    /**
864
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
865
-     * before their class declaration in order to ensure that the parent class was loaded.
866
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
867
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
868
-     *
869
-     * @param string $class_name
870
-     */
871
-    protected function resolve_legacy_class_parent($class_name = '')
872
-    {
873
-        try {
874
-            $legacy_parent_class_map = array(
875
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
876
-            );
877
-            if(isset($legacy_parent_class_map[$class_name])) {
878
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
879
-            }
880
-        } catch (Exception $exception) {
881
-        }
882
-    }
883
-
884
-
885
-
886
-    /**
887
-     * _create_object
888
-     * Attempts to instantiate the requested class via any of the
889
-     * commonly used instantiation methods employed throughout EE.
890
-     * The priority for instantiation is as follows:
891
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
892
-     *        - model objects via their 'new_instance_from_db' method
893
-     *        - model objects via their 'new_instance' method
894
-     *        - "singleton" classes" via their 'instance' method
895
-     *    - standard instantiable classes via their __constructor
896
-     * Prior to instantiation, if the classname exists in the dependency_map,
897
-     * then the constructor for the requested class will be examined to determine
898
-     * if any dependencies exist, and if they can be injected.
899
-     * If so, then those classes will be added to the array of arguments passed to the constructor
900
-     *
901
-     * @access protected
902
-     * @param string $class_name
903
-     * @param array  $arguments
904
-     * @param string $type
905
-     * @param bool   $from_db
906
-     * @return null | object
907
-     * @throws \EE_Error
908
-     */
909
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
910
-    {
911
-        $class_obj = null;
912
-        $instantiation_mode = '0) none';
913
-        // don't give up! you gotta...
914
-        try {
915
-            // create reflection
916
-            $reflector = $this->get_ReflectionClass($class_name);
917
-            // make sure arguments are an array
918
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
919
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
920
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
921
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
922
-                ? $arguments
923
-                : array($arguments);
924
-            // attempt to inject dependencies ?
925
-            if ($this->_dependency_map->has($class_name)) {
926
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
927
-            }
928
-            // instantiate the class if possible
929
-            if ($reflector->isAbstract()) {
930
-                // nothing to instantiate, loading file was enough
931
-                // does not throw an exception so $instantiation_mode is unused
932
-                // $instantiation_mode = "1) no constructor abstract class";
933
-                $class_obj = true;
934
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
935
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
936
-                $instantiation_mode = "2) no constructor but instantiable";
937
-                $class_obj = $reflector->newInstance();
938
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
939
-                $instantiation_mode = "3) new_instance_from_db()";
940
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
941
-            } else if (method_exists($class_name, 'new_instance')) {
942
-                $instantiation_mode = "4) new_instance()";
943
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
944
-            } else if (method_exists($class_name, 'instance')) {
945
-                $instantiation_mode = "5) instance()";
946
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
947
-            } else if ($reflector->isInstantiable()) {
948
-                $instantiation_mode = "6) constructor";
949
-                $class_obj = $reflector->newInstanceArgs($arguments);
950
-            } else {
951
-                // heh ? something's not right !
952
-                throw new EE_Error(
953
-                    sprintf(
954
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
955
-                        $type,
956
-                        $class_name
957
-                    )
958
-                );
959
-            }
960
-        } catch (Exception $e) {
961
-            if ( ! $e instanceof EE_Error) {
962
-                $e = new EE_Error(
963
-                    sprintf(
964
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
965
-                        $class_name,
966
-                        '<br />',
967
-                        $e->getMessage(),
968
-                        $instantiation_mode
969
-                    )
970
-                );
971
-            }
972
-            $e->get_error();
973
-        }
974
-        return $class_obj;
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
981
-     * @param array $array
982
-     * @return bool
983
-     */
984
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
985
-    {
986
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
987
-    }
988
-
989
-
990
-
991
-    /**
992
-     * getReflectionClass
993
-     * checks if a ReflectionClass object has already been generated for a class
994
-     * and returns that instead of creating a new one
995
-     *
996
-     * @access public
997
-     * @param string $class_name
998
-     * @return ReflectionClass
999
-     */
1000
-    public function get_ReflectionClass($class_name)
1001
-    {
1002
-        if (
1003
-            ! isset($this->_reflectors[$class_name])
1004
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1005
-        ) {
1006
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1007
-        }
1008
-        return $this->_reflectors[$class_name];
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     * _resolve_dependencies
1015
-     * examines the constructor for the requested class to determine
1016
-     * if any dependencies exist, and if they can be injected.
1017
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1018
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1019
-     * For example:
1020
-     *        if attempting to load a class "Foo" with the following constructor:
1021
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1022
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1023
-     *        but only IF they are NOT already present in the incoming arguments array,
1024
-     *        and the correct classes can be loaded
1025
-     *
1026
-     * @access protected
1027
-     * @param ReflectionClass $reflector
1028
-     * @param string          $class_name
1029
-     * @param array           $arguments
1030
-     * @return array
1031
-     * @throws \ReflectionException
1032
-     */
1033
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1034
-    {
1035
-        // let's examine the constructor
1036
-        $constructor = $reflector->getConstructor();
1037
-        // whu? huh? nothing?
1038
-        if ( ! $constructor) {
1039
-            return $arguments;
1040
-        }
1041
-        // get constructor parameters
1042
-        $params = $constructor->getParameters();
1043
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1044
-        $argument_keys = array_keys($arguments);
1045
-        // now loop thru all of the constructors expected parameters
1046
-        foreach ($params as $index => $param) {
1047
-            // is this a dependency for a specific class ?
1048
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
1049
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1050
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1051
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1052
-                : $param_class;
1053
-            if (
1054
-                // param is not even a class
1055
-                empty($param_class)
1056
-                // and something already exists in the incoming arguments for this param
1057
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1058
-            ) {
1059
-                // so let's skip this argument and move on to the next
1060
-                continue;
1061
-            }
1062
-            if (
1063
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1064
-                ! empty($param_class)
1065
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1066
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1067
-            ) {
1068
-                // skip this argument and move on to the next
1069
-                continue;
1070
-            }
1071
-            if (
1072
-                // parameter is type hinted as a class, and should be injected
1073
-                ! empty($param_class)
1074
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1075
-            ) {
1076
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1077
-            } else {
1078
-                try {
1079
-                    $arguments[$index] = $param->getDefaultValue();
1080
-                } catch (ReflectionException $e) {
1081
-                    throw new ReflectionException(
1082
-                        sprintf(
1083
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1084
-                            $e->getMessage(),
1085
-                            $param->getName()
1086
-                        )
1087
-                    );
1088
-                }
1089
-            }
1090
-        }
1091
-        return $arguments;
1092
-    }
1093
-
1094
-
1095
-
1096
-    /**
1097
-     * @access protected
1098
-     * @param string $class_name
1099
-     * @param string $param_class
1100
-     * @param array  $arguments
1101
-     * @param mixed  $index
1102
-     * @return array
1103
-     */
1104
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1105
-    {
1106
-        $dependency = null;
1107
-        // should dependency be loaded from cache ?
1108
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1109
-                    !== EE_Dependency_Map::load_new_object
1110
-            ? true
1111
-            : false;
1112
-        // we might have a dependency...
1113
-        // let's MAYBE try and find it in our cache if that's what's been requested
1114
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1115
-        // and grab it if it exists
1116
-        if ($cached_class instanceof $param_class) {
1117
-            $dependency = $cached_class;
1118
-        } else if ($param_class !== $class_name) {
1119
-            // obtain the loader method from the dependency map
1120
-            $loader = $this->_dependency_map->class_loader($param_class);
1121
-            // is loader a custom closure ?
1122
-            if ($loader instanceof Closure) {
1123
-                $dependency = $loader();
1124
-            } else {
1125
-                // set the cache on property for the recursive loading call
1126
-                $this->_cache_on = $cache_on;
1127
-                // if not, then let's try and load it via the registry
1128
-                if ($loader && method_exists($this, $loader)) {
1129
-                    $dependency = $this->{$loader}($param_class);
1130
-                } else {
1131
-                    $dependency = $this->create($param_class, array(), $cache_on);
1132
-                }
1133
-            }
1134
-        }
1135
-        // did we successfully find the correct dependency ?
1136
-        if ($dependency instanceof $param_class) {
1137
-            // then let's inject it into the incoming array of arguments at the correct location
1138
-            if (isset($argument_keys[$index])) {
1139
-                $arguments[$argument_keys[$index]] = $dependency;
1140
-            } else {
1141
-                $arguments[$index] = $dependency;
1142
-            }
1143
-        }
1144
-        return $arguments;
1145
-    }
1146
-
1147
-
1148
-
1149
-    /**
1150
-     * _set_cached_class
1151
-     * attempts to cache the instantiated class locally
1152
-     * in one of the following places, in the following order:
1153
-     *        $this->{class_abbreviation}   ie:    $this->CART
1154
-     *        $this->{$class_name}          ie:    $this->Some_Class
1155
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1156
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1157
-     *
1158
-     * @access protected
1159
-     * @param object $class_obj
1160
-     * @param string $class_name
1161
-     * @param string $class_prefix
1162
-     * @param bool   $from_db
1163
-     * @return void
1164
-     */
1165
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1166
-    {
1167
-        if (empty($class_obj)) {
1168
-            return;
1169
-        }
1170
-        // return newly instantiated class
1171
-        if (isset($this->_class_abbreviations[$class_name])) {
1172
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1173
-            $this->{$class_abbreviation} = $class_obj;
1174
-            return;
1175
-        }
1176
-        $class_name = str_replace('\\', '_', $class_name);
1177
-        if (property_exists($this, $class_name)) {
1178
-            $this->{$class_name} = $class_obj;
1179
-            return;
1180
-        }
1181
-        if ($class_prefix === 'addon') {
1182
-            $this->addons->{$class_name} = $class_obj;
1183
-            return;
1184
-        }
1185
-        if ( ! $from_db) {
1186
-            $this->LIB->{$class_name} = $class_obj;
1187
-        }
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1194
-     *
1195
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1196
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1197
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1198
-     * @param array  $arguments
1199
-     * @return object
1200
-     */
1201
-    public static function factory($classname, $arguments = array())
1202
-    {
1203
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1204
-        if ($loader instanceof Closure) {
1205
-            return $loader($arguments);
1206
-        }
1207
-        if (method_exists(EE_Registry::instance(), $loader)) {
1208
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1209
-        }
1210
-        return null;
1211
-    }
1212
-
1213
-
1214
-
1215
-    /**
1216
-     * Gets the addon by its name/slug (not classname. For that, just
1217
-     * use the classname as the property name on EE_Config::instance()->addons)
1218
-     *
1219
-     * @param string $name
1220
-     * @return EE_Addon
1221
-     */
1222
-    public function get_addon_by_name($name)
1223
-    {
1224
-        foreach ($this->addons as $addon) {
1225
-            if ($addon->name() == $name) {
1226
-                return $addon;
1227
-            }
1228
-        }
1229
-        return null;
1230
-    }
1231
-
1232
-
1233
-
1234
-    /**
1235
-     * 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
1236
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1237
-     *
1238
-     * @return EE_Addon[] where the KEYS are the addon's name()
1239
-     */
1240
-    public function get_addons_by_name()
1241
-    {
1242
-        $addons = array();
1243
-        foreach ($this->addons as $addon) {
1244
-            $addons[$addon->name()] = $addon;
1245
-        }
1246
-        return $addons;
1247
-    }
1248
-
1249
-
1250
-
1251
-    /**
1252
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1253
-     * a stale copy of it around
1254
-     *
1255
-     * @param string $model_name
1256
-     * @return \EEM_Base
1257
-     * @throws \EE_Error
1258
-     */
1259
-    public function reset_model($model_name)
1260
-    {
1261
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1262
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1263
-            return null;
1264
-        }
1265
-        //get that model reset it and make sure we nuke the old reference to it
1266
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1267
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1268
-        } else {
1269
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1270
-        }
1271
-        return $this->LIB->{$model_class_name};
1272
-    }
1273
-
1274
-
1275
-
1276
-    /**
1277
-     * Resets the registry.
1278
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1279
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1280
-     * - $_dependency_map
1281
-     * - $_class_abbreviations
1282
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1283
-     * - $REQ:  Still on the same request so no need to change.
1284
-     * - $CAP: There is no site specific state in the EE_Capability class.
1285
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1286
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1287
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1288
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1289
-     *             switch or on the restore.
1290
-     * - $modules
1291
-     * - $shortcodes
1292
-     * - $widgets
1293
-     *
1294
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1295
-     *                                  the Registry to its state at the beginning of the request
1296
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1297
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1298
-     *                                  currently reinstantiate the singletons at the moment)
1299
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1300
-     *                                  code instead can just change the model context to a different blog id if necessary
1301
-     * @return EE_Registry
1302
-     */
1303
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1304
-    {
1305
-        $instance = self::instance();
1306
-        EEH_Activation::reset();
1307
-        //properties that get reset
1308
-        $instance->_cache_on = true;
1309
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1310
-        $instance->CART = null;
1311
-        $instance->MRM = null;
1312
-        $instance->AssetsRegistry = null;
1313
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1314
-        //messages reset
1315
-        EED_Messages::reset();
1316
-        if ($reset_models) {
1317
-            foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1318
-                $instance->reset_model($model_name);
1319
-            }
1320
-        }
1321
-        $instance->LIB = new stdClass();
1322
-        return $instance;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * @override magic methods
1329
-     * @return void
1330
-     */
1331
-    public final function __destruct()
1332
-    {
1333
-    }
1334
-
1335
-
1336
-
1337
-    /**
1338
-     * @param $a
1339
-     * @param $b
1340
-     */
1341
-    public final function __call($a, $b)
1342
-    {
1343
-    }
1344
-
1345
-
1346
-
1347
-    /**
1348
-     * @param $a
1349
-     */
1350
-    public final function __get($a)
1351
-    {
1352
-    }
1353
-
1354
-
1355
-
1356
-    /**
1357
-     * @param $a
1358
-     * @param $b
1359
-     */
1360
-    public final function __set($a, $b)
1361
-    {
1362
-    }
1363
-
1364
-
1365
-
1366
-    /**
1367
-     * @param $a
1368
-     */
1369
-    public final function __isset($a)
1370
-    {
1371
-    }
19
+	/**
20
+	 *    EE_Registry Object
21
+	 *
22
+	 * @var EE_Registry $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance = null;
26
+
27
+	/**
28
+	 * @var EE_Dependency_Map $_dependency_map
29
+	 * @access    protected
30
+	 */
31
+	protected $_dependency_map = null;
32
+
33
+	/**
34
+	 * @var array $_class_abbreviations
35
+	 * @access    protected
36
+	 */
37
+	protected $_class_abbreviations = array();
38
+
39
+	/**
40
+	 * @access public
41
+	 * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 *    EE_Cart Object
47
+	 *
48
+	 * @access    public
49
+	 * @var    EE_Cart $CART
50
+	 */
51
+	public $CART = null;
52
+
53
+	/**
54
+	 *    EE_Config Object
55
+	 *
56
+	 * @access    public
57
+	 * @var    EE_Config $CFG
58
+	 */
59
+	public $CFG = null;
60
+
61
+	/**
62
+	 * EE_Network_Config Object
63
+	 *
64
+	 * @access public
65
+	 * @var EE_Network_Config $NET_CFG
66
+	 */
67
+	public $NET_CFG = null;
68
+
69
+	/**
70
+	 *    StdClass object for storing library classes in
71
+	 *
72
+	 * @public LIB
73
+	 * @var StdClass $LIB
74
+	 */
75
+	public $LIB = null;
76
+
77
+	/**
78
+	 *    EE_Request_Handler Object
79
+	 *
80
+	 * @access    public
81
+	 * @var    EE_Request_Handler $REQ
82
+	 */
83
+	public $REQ = null;
84
+
85
+	/**
86
+	 *    EE_Session Object
87
+	 *
88
+	 * @access    public
89
+	 * @var    EE_Session $SSN
90
+	 */
91
+	public $SSN = null;
92
+
93
+	/**
94
+	 * holds the ee capabilities object.
95
+	 *
96
+	 * @since 4.5.0
97
+	 * @var EE_Capabilities
98
+	 */
99
+	public $CAP = null;
100
+
101
+	/**
102
+	 * holds the EE_Message_Resource_Manager object.
103
+	 *
104
+	 * @since 4.9.0
105
+	 * @var EE_Message_Resource_Manager
106
+	 */
107
+	public $MRM = null;
108
+
109
+
110
+	/**
111
+	 * Holds the Assets Registry instance
112
+	 * @var Registry
113
+	 */
114
+	public $AssetsRegistry = null;
115
+
116
+	/**
117
+	 *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
+	 *
119
+	 * @access    public
120
+	 * @var    EE_Addon[]
121
+	 */
122
+	public $addons = null;
123
+
124
+	/**
125
+	 *    $models
126
+	 * @access    public
127
+	 * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
+	 */
129
+	public $models = array();
130
+
131
+	/**
132
+	 *    $modules
133
+	 * @access    public
134
+	 * @var    EED_Module[] $modules
135
+	 */
136
+	public $modules = null;
137
+
138
+	/**
139
+	 *    $shortcodes
140
+	 * @access    public
141
+	 * @var    EES_Shortcode[] $shortcodes
142
+	 */
143
+	public $shortcodes = null;
144
+
145
+	/**
146
+	 *    $widgets
147
+	 * @access    public
148
+	 * @var    WP_Widget[] $widgets
149
+	 */
150
+	public $widgets = null;
151
+
152
+	/**
153
+	 * $non_abstract_db_models
154
+	 * @access public
155
+	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
+	 * classnames (eg "EEM_Event")
159
+	 */
160
+	public $non_abstract_db_models = array();
161
+
162
+
163
+	/**
164
+	 *    $i18n_js_strings - internationalization for JS strings
165
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
+	 *    in js file:  var translatedString = eei18n.string_key;
167
+	 *
168
+	 * @access    public
169
+	 * @var    array
170
+	 */
171
+	public static $i18n_js_strings = array();
172
+
173
+
174
+	/**
175
+	 *    $main_file - path to espresso.php
176
+	 *
177
+	 * @access    public
178
+	 * @var    array
179
+	 */
180
+	public $main_file;
181
+
182
+	/**
183
+	 * array of ReflectionClass objects where the key is the class name
184
+	 *
185
+	 * @access    public
186
+	 * @var ReflectionClass[]
187
+	 */
188
+	public $_reflectors;
189
+
190
+	/**
191
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
+	 *
193
+	 * @access    protected
194
+	 * @var boolean $_cache_on
195
+	 */
196
+	protected $_cache_on = true;
197
+
198
+
199
+
200
+	/**
201
+	 * @singleton method used to instantiate class object
202
+	 * @access    public
203
+	 * @param  \EE_Dependency_Map $dependency_map
204
+	 * @return \EE_Registry instance
205
+	 */
206
+	public static function instance(\EE_Dependency_Map $dependency_map = null)
207
+	{
208
+		// check if class object is instantiated
209
+		if ( ! self::$_instance instanceof EE_Registry) {
210
+			self::$_instance = new EE_Registry($dependency_map);
211
+		}
212
+		return self::$_instance;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 *protected constructor to prevent direct creation
219
+	 *
220
+	 * @Constructor
221
+	 * @access protected
222
+	 * @param  \EE_Dependency_Map $dependency_map
223
+	 */
224
+	protected function __construct(\EE_Dependency_Map $dependency_map)
225
+	{
226
+		$this->_dependency_map = $dependency_map;
227
+		$this->LIB = new stdClass();
228
+		$this->addons = new stdClass();
229
+		$this->modules = new stdClass();
230
+		$this->shortcodes = new stdClass();
231
+		$this->widgets = new stdClass();
232
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * initialize
239
+	 */
240
+	public function initialize()
241
+	{
242
+		$this->_class_abbreviations = apply_filters(
243
+			'FHEE__EE_Registry____construct___class_abbreviations',
244
+			array(
245
+				'EE_Config'                                       => 'CFG',
246
+				'EE_Session'                                      => 'SSN',
247
+				'EE_Capabilities'                                 => 'CAP',
248
+				'EE_Cart'                                         => 'CART',
249
+				'EE_Network_Config'                               => 'NET_CFG',
250
+				'EE_Request_Handler'                              => 'REQ',
251
+				'EE_Message_Resource_Manager'                     => 'MRM',
252
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
253
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
254
+			)
255
+		);
256
+		$this->load_core('Base', array(), true);
257
+		// add our request and response objects to the cache
258
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
259
+		$this->_set_cached_class(
260
+			$request_loader(),
261
+			'EE_Request'
262
+		);
263
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
264
+		$this->_set_cached_class(
265
+			$response_loader(),
266
+			'EE_Response'
267
+		);
268
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
269
+	}
270
+
271
+
272
+
273
+	/**
274
+	 *    init
275
+	 *
276
+	 * @access    public
277
+	 * @return    void
278
+	 */
279
+	public function init()
280
+	{
281
+		// Get current page protocol
282
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
283
+		// Output admin-ajax.php URL with same protocol as current page
284
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
285
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * localize_i18n_js_strings
292
+	 *
293
+	 * @return string
294
+	 */
295
+	public static function localize_i18n_js_strings()
296
+	{
297
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
298
+		foreach ($i18n_js_strings as $key => $value) {
299
+			if (is_scalar($value)) {
300
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
301
+			}
302
+		}
303
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * @param mixed string | EED_Module $module
310
+	 */
311
+	public function add_module($module)
312
+	{
313
+		if ($module instanceof EED_Module) {
314
+			$module_class = get_class($module);
315
+			$this->modules->{$module_class} = $module;
316
+		} else {
317
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
318
+				$this->load_core('Module_Request_Router');
319
+			}
320
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
321
+		}
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @param string $module_name
328
+	 * @return mixed EED_Module | NULL
329
+	 */
330
+	public function get_module($module_name = '')
331
+	{
332
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 *    loads core classes - must be singletons
339
+	 *
340
+	 * @access    public
341
+	 * @param string $class_name - simple class name ie: session
342
+	 * @param mixed  $arguments
343
+	 * @param bool   $load_only
344
+	 * @return mixed
345
+	 */
346
+	public function load_core($class_name, $arguments = array(), $load_only = false)
347
+	{
348
+		$core_paths = apply_filters(
349
+			'FHEE__EE_Registry__load_core__core_paths',
350
+			array(
351
+				EE_CORE,
352
+				EE_ADMIN,
353
+				EE_CPTS,
354
+				EE_CORE . 'data_migration_scripts' . DS,
355
+				EE_CORE . 'request_stack' . DS,
356
+				EE_CORE . 'middleware' . DS,
357
+			)
358
+		);
359
+		// retrieve instantiated class
360
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 *    loads service classes
367
+	 *
368
+	 * @access    public
369
+	 * @param string $class_name - simple class name ie: session
370
+	 * @param mixed  $arguments
371
+	 * @param bool   $load_only
372
+	 * @return mixed
373
+	 */
374
+	public function load_service($class_name, $arguments = array(), $load_only = false)
375
+	{
376
+		$service_paths = apply_filters(
377
+			'FHEE__EE_Registry__load_service__service_paths',
378
+			array(
379
+				EE_CORE . 'services' . DS,
380
+			)
381
+		);
382
+		// retrieve instantiated class
383
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 *    loads data_migration_scripts
390
+	 *
391
+	 * @access    public
392
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
393
+	 * @param mixed  $arguments
394
+	 * @return EE_Data_Migration_Script_Base|mixed
395
+	 */
396
+	public function load_dms($class_name, $arguments = array())
397
+	{
398
+		// retrieve instantiated class
399
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 *    loads object creating classes - must be singletons
406
+	 *
407
+	 * @param string $class_name - simple class name ie: attendee
408
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
409
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
410
+	 * @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)
411
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
412
+	 * @return EE_Base_Class | bool
413
+	 */
414
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
415
+	{
416
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
417
+			EE_CORE,
418
+			EE_CLASSES,
419
+			EE_BUSINESS,
420
+		));
421
+		// retrieve instantiated class
422
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 *    loads helper classes - must be singletons
429
+	 *
430
+	 * @param string $class_name - simple class name ie: price
431
+	 * @param mixed  $arguments
432
+	 * @param bool   $load_only
433
+	 * @return EEH_Base | bool
434
+	 */
435
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
436
+	{
437
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
438
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
439
+		// retrieve instantiated class
440
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 *    loads core classes - must be singletons
447
+	 *
448
+	 * @access    public
449
+	 * @param string $class_name - simple class name ie: session
450
+	 * @param mixed  $arguments
451
+	 * @param bool   $load_only
452
+	 * @param bool   $cache      whether to cache the object or not.
453
+	 * @return mixed
454
+	 */
455
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
456
+	{
457
+		$paths = array(
458
+			EE_LIBRARIES,
459
+			EE_LIBRARIES . 'messages' . DS,
460
+			EE_LIBRARIES . 'shortcodes' . DS,
461
+			EE_LIBRARIES . 'qtips' . DS,
462
+			EE_LIBRARIES . 'payment_methods' . DS,
463
+			EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
464
+		);
465
+		// retrieve instantiated class
466
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 *    loads model classes - must be singletons
473
+	 *
474
+	 * @param string $class_name - simple class name ie: price
475
+	 * @param mixed  $arguments
476
+	 * @param bool   $load_only
477
+	 * @return EEM_Base | bool
478
+	 */
479
+	public function load_model($class_name, $arguments = array(), $load_only = false)
480
+	{
481
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
482
+			EE_MODELS,
483
+			EE_CORE,
484
+		));
485
+		// retrieve instantiated class
486
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 *    loads model classes - must be singletons
493
+	 *
494
+	 * @param string $class_name - simple class name ie: price
495
+	 * @param mixed  $arguments
496
+	 * @param bool   $load_only
497
+	 * @return mixed | bool
498
+	 */
499
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
500
+	{
501
+		$paths = array(
502
+			EE_MODELS . 'fields' . DS,
503
+			EE_MODELS . 'helpers' . DS,
504
+			EE_MODELS . 'relations' . DS,
505
+			EE_MODELS . 'strategies' . DS,
506
+		);
507
+		// retrieve instantiated class
508
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
509
+	}
510
+
511
+
512
+
513
+	/**
514
+	 * Determines if $model_name is the name of an actual EE model.
515
+	 *
516
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
517
+	 * @return boolean
518
+	 */
519
+	public function is_model_name($model_name)
520
+	{
521
+		return isset($this->models[$model_name]) ? true : false;
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 *    generic class loader
528
+	 *
529
+	 * @param string $path_to_file - directory path to file location, not including filename
530
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
531
+	 * @param string $type         - file type - core? class? helper? model?
532
+	 * @param mixed  $arguments
533
+	 * @param bool   $load_only
534
+	 * @return mixed
535
+	 */
536
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
537
+	{
538
+		// retrieve instantiated class
539
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 *    load_addon
546
+	 *
547
+	 * @param string $path_to_file - directory path to file location, not including filename
548
+	 * @param string $class_name   - full class name  ie:  My_Class
549
+	 * @param string $type         - file type - core? class? helper? model?
550
+	 * @param mixed  $arguments
551
+	 * @param bool   $load_only
552
+	 * @return EE_Addon
553
+	 */
554
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
555
+	{
556
+		// retrieve instantiated class
557
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
558
+	}
559
+
560
+
561
+
562
+	/**
563
+	 * instantiates, caches, and automatically resolves dependencies
564
+	 * for classes that use a Fully Qualified Class Name.
565
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
566
+	 * then you need to use one of the existing load_*() methods
567
+	 * which can resolve the classname and filepath from the passed arguments
568
+	 *
569
+	 * @param bool|string $class_name   Fully Qualified Class Name
570
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
571
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
572
+	 * @param bool        $from_db      some classes are instantiated from the db
573
+	 *                                  and thus call a different method to instantiate
574
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
575
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
576
+	 * @return mixed                    null = failure to load or instantiate class object.
577
+	 *                                  object = class loaded and instantiated successfully.
578
+	 *                                  bool = fail or success when $load_only is true
579
+	 */
580
+	public function create(
581
+		$class_name = false,
582
+		$arguments = array(),
583
+		$cache = false,
584
+		$from_db = false,
585
+		$load_only = false,
586
+		$addon = false
587
+	) {
588
+		$class_name = ltrim($class_name, '\\');
589
+		$class_name = $this->_dependency_map->get_alias($class_name);
590
+		if ( ! class_exists($class_name)) {
591
+			// maybe the class is registered with a preceding \
592
+			$class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
593
+			// still doesn't exist ?
594
+			if ( ! class_exists($class_name)) {
595
+				return null;
596
+			}
597
+		}
598
+		// if we're only loading the class and it already exists, then let's just return true immediately
599
+		if ($load_only) {
600
+			return true;
601
+		}
602
+		$addon = $addon ? 'addon' : '';
603
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
604
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
605
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
606
+		if ($this->_cache_on && $cache && ! $load_only) {
607
+			// return object if it's already cached
608
+			$cached_class = $this->_get_cached_class($class_name, $addon);
609
+			if ($cached_class !== null) {
610
+				return $cached_class;
611
+			}
612
+		}
613
+		// instantiate the requested object
614
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
615
+		if ($this->_cache_on && $cache) {
616
+			// save it for later... kinda like gum  { : $
617
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
618
+		}
619
+		$this->_cache_on = true;
620
+		return $class_obj;
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * instantiates, caches, and injects dependencies for classes
627
+	 *
628
+	 * @param array       $file_paths   an array of paths to folders to look in
629
+	 * @param string      $class_prefix EE  or EEM or... ???
630
+	 * @param bool|string $class_name   $class name
631
+	 * @param string      $type         file type - core? class? helper? model?
632
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
633
+	 * @param bool        $from_db      some classes are instantiated from the db
634
+	 *                                  and thus call a different method to instantiate
635
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
636
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
637
+	 * @return null|object|bool         null = failure to load or instantiate class object.
638
+	 *                                  object = class loaded and instantiated successfully.
639
+	 *                                  bool = fail or success when $load_only is true
640
+	 */
641
+	protected function _load(
642
+		$file_paths = array(),
643
+		$class_prefix = 'EE_',
644
+		$class_name = false,
645
+		$type = 'class',
646
+		$arguments = array(),
647
+		$from_db = false,
648
+		$cache = true,
649
+		$load_only = false
650
+	) {
651
+		$class_name = ltrim($class_name, '\\');
652
+		// strip php file extension
653
+		$class_name = str_replace('.php', '', trim($class_name));
654
+		// does the class have a prefix ?
655
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
656
+			// make sure $class_prefix is uppercase
657
+			$class_prefix = strtoupper(trim($class_prefix));
658
+			// add class prefix ONCE!!!
659
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
660
+		}
661
+		$class_name = $this->_dependency_map->get_alias($class_name);
662
+		$class_exists = class_exists($class_name, false);
663
+		// if we're only loading the class and it already exists, then let's just return true immediately
664
+		if ($load_only && $class_exists) {
665
+			return true;
666
+		}
667
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
668
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
669
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
670
+		if ($this->_cache_on && $cache && ! $load_only) {
671
+			// return object if it's already cached
672
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
673
+			if ($cached_class !== null) {
674
+				return $cached_class;
675
+			}
676
+		}
677
+		// if the class doesn't already exist.. then we need to try and find the file and load it
678
+		if ( ! $class_exists) {
679
+			// get full path to file
680
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
681
+			// load the file
682
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
683
+			// if loading failed, or we are only loading a file but NOT instantiating an object
684
+			if ( ! $loaded || $load_only) {
685
+				// return boolean if only loading, or null if an object was expected
686
+				return $load_only ? $loaded : null;
687
+			}
688
+		}
689
+		// instantiate the requested object
690
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
691
+		if ($this->_cache_on && $cache) {
692
+			// save it for later... kinda like gum  { : $
693
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
694
+		}
695
+		$this->_cache_on = true;
696
+		return $class_obj;
697
+	}
698
+
699
+
700
+
701
+
702
+	/**
703
+	 * _get_cached_class
704
+	 * attempts to find a cached version of the requested class
705
+	 * by looking in the following places:
706
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
707
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
708
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
709
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
710
+	 *
711
+	 * @access protected
712
+	 * @param string $class_name
713
+	 * @param string $class_prefix
714
+	 * @return mixed
715
+	 */
716
+	protected function _get_cached_class($class_name, $class_prefix = '')
717
+	{
718
+		// have to specify something, but not anything that will conflict
719
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
720
+			? $this->_class_abbreviations[ $class_name ]
721
+			: 'FANCY_BATMAN_PANTS';
722
+		$class_name = str_replace('\\', '_', $class_name);
723
+		// check if class has already been loaded, and return it if it has been
724
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
725
+			return $this->{$class_abbreviation};
726
+		}
727
+		if (isset ($this->{$class_name})) {
728
+			return $this->{$class_name};
729
+		}
730
+		if (isset ($this->LIB->{$class_name})) {
731
+			return $this->LIB->{$class_name};
732
+		}
733
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
734
+			return $this->addons->{$class_name};
735
+		}
736
+		return null;
737
+	}
738
+
739
+
740
+
741
+	/**
742
+	 * removes a cached version of the requested class
743
+	 *
744
+	 * @param string $class_name
745
+	 * @param boolean $addon
746
+	 * @return boolean
747
+	 */
748
+	public function clear_cached_class($class_name, $addon = false)
749
+	{
750
+		// have to specify something, but not anything that will conflict
751
+		$class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
752
+			? $this->_class_abbreviations[ $class_name ]
753
+			: 'FANCY_BATMAN_PANTS';
754
+		$class_name = str_replace('\\', '_', $class_name);
755
+		// check if class has already been loaded, and return it if it has been
756
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
757
+			$this->{$class_abbreviation} = null;
758
+			return true;
759
+		}
760
+		if (isset($this->{$class_name})) {
761
+			$this->{$class_name} = null;
762
+			return true;
763
+		}
764
+		if (isset($this->LIB->{$class_name})) {
765
+			unset($this->LIB->{$class_name});
766
+			return true;
767
+		}
768
+		if ($addon && isset($this->addons->{$class_name})) {
769
+			unset($this->addons->{$class_name});
770
+			return true;
771
+		}
772
+		return false;
773
+	}
774
+
775
+
776
+	/**
777
+	 * _resolve_path
778
+	 * attempts to find a full valid filepath for the requested class.
779
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
780
+	 * then returns that path if the target file has been found and is readable
781
+	 *
782
+	 * @access protected
783
+	 * @param string $class_name
784
+	 * @param string $type
785
+	 * @param array  $file_paths
786
+	 * @return string | bool
787
+	 */
788
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
789
+	{
790
+		// make sure $file_paths is an array
791
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
792
+		// cycle thru paths
793
+		foreach ($file_paths as $key => $file_path) {
794
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
795
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
796
+			// prep file type
797
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
798
+			// build full file path
799
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
800
+			//does the file exist and can be read ?
801
+			if (is_readable($file_paths[$key])) {
802
+				return $file_paths[$key];
803
+			}
804
+		}
805
+		return false;
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * _require_file
812
+	 * basically just performs a require_once()
813
+	 * but with some error handling
814
+	 *
815
+	 * @access protected
816
+	 * @param  string $path
817
+	 * @param  string $class_name
818
+	 * @param  string $type
819
+	 * @param  array  $file_paths
820
+	 * @return boolean
821
+	 * @throws \EE_Error
822
+	 */
823
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
824
+	{
825
+		$this->resolve_legacy_class_parent($class_name);
826
+		// don't give up! you gotta...
827
+		try {
828
+			//does the file exist and can it be read ?
829
+			if ( ! $path) {
830
+				// so sorry, can't find the file
831
+				throw new EE_Error (
832
+					sprintf(
833
+						__('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'),
834
+						trim($type, '.'),
835
+						$class_name,
836
+						'<br />' . implode(',<br />', $file_paths)
837
+					)
838
+				);
839
+			}
840
+			// get the file
841
+			require_once($path);
842
+			// if the class isn't already declared somewhere
843
+			if (class_exists($class_name, false) === false) {
844
+				// so sorry, not a class
845
+				throw new EE_Error(
846
+					sprintf(
847
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
848
+						$type,
849
+						$path,
850
+						$class_name
851
+					)
852
+				);
853
+			}
854
+		} catch (EE_Error $e) {
855
+			$e->get_error();
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+
863
+	/**
864
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
865
+	 * before their class declaration in order to ensure that the parent class was loaded.
866
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
867
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
868
+	 *
869
+	 * @param string $class_name
870
+	 */
871
+	protected function resolve_legacy_class_parent($class_name = '')
872
+	{
873
+		try {
874
+			$legacy_parent_class_map = array(
875
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
876
+			);
877
+			if(isset($legacy_parent_class_map[$class_name])) {
878
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
879
+			}
880
+		} catch (Exception $exception) {
881
+		}
882
+	}
883
+
884
+
885
+
886
+	/**
887
+	 * _create_object
888
+	 * Attempts to instantiate the requested class via any of the
889
+	 * commonly used instantiation methods employed throughout EE.
890
+	 * The priority for instantiation is as follows:
891
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
892
+	 *        - model objects via their 'new_instance_from_db' method
893
+	 *        - model objects via their 'new_instance' method
894
+	 *        - "singleton" classes" via their 'instance' method
895
+	 *    - standard instantiable classes via their __constructor
896
+	 * Prior to instantiation, if the classname exists in the dependency_map,
897
+	 * then the constructor for the requested class will be examined to determine
898
+	 * if any dependencies exist, and if they can be injected.
899
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
900
+	 *
901
+	 * @access protected
902
+	 * @param string $class_name
903
+	 * @param array  $arguments
904
+	 * @param string $type
905
+	 * @param bool   $from_db
906
+	 * @return null | object
907
+	 * @throws \EE_Error
908
+	 */
909
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
910
+	{
911
+		$class_obj = null;
912
+		$instantiation_mode = '0) none';
913
+		// don't give up! you gotta...
914
+		try {
915
+			// create reflection
916
+			$reflector = $this->get_ReflectionClass($class_name);
917
+			// make sure arguments are an array
918
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
919
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
920
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
921
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
922
+				? $arguments
923
+				: array($arguments);
924
+			// attempt to inject dependencies ?
925
+			if ($this->_dependency_map->has($class_name)) {
926
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
927
+			}
928
+			// instantiate the class if possible
929
+			if ($reflector->isAbstract()) {
930
+				// nothing to instantiate, loading file was enough
931
+				// does not throw an exception so $instantiation_mode is unused
932
+				// $instantiation_mode = "1) no constructor abstract class";
933
+				$class_obj = true;
934
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
935
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
936
+				$instantiation_mode = "2) no constructor but instantiable";
937
+				$class_obj = $reflector->newInstance();
938
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
939
+				$instantiation_mode = "3) new_instance_from_db()";
940
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
941
+			} else if (method_exists($class_name, 'new_instance')) {
942
+				$instantiation_mode = "4) new_instance()";
943
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
944
+			} else if (method_exists($class_name, 'instance')) {
945
+				$instantiation_mode = "5) instance()";
946
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
947
+			} else if ($reflector->isInstantiable()) {
948
+				$instantiation_mode = "6) constructor";
949
+				$class_obj = $reflector->newInstanceArgs($arguments);
950
+			} else {
951
+				// heh ? something's not right !
952
+				throw new EE_Error(
953
+					sprintf(
954
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
955
+						$type,
956
+						$class_name
957
+					)
958
+				);
959
+			}
960
+		} catch (Exception $e) {
961
+			if ( ! $e instanceof EE_Error) {
962
+				$e = new EE_Error(
963
+					sprintf(
964
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
965
+						$class_name,
966
+						'<br />',
967
+						$e->getMessage(),
968
+						$instantiation_mode
969
+					)
970
+				);
971
+			}
972
+			$e->get_error();
973
+		}
974
+		return $class_obj;
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
981
+	 * @param array $array
982
+	 * @return bool
983
+	 */
984
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
985
+	{
986
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
987
+	}
988
+
989
+
990
+
991
+	/**
992
+	 * getReflectionClass
993
+	 * checks if a ReflectionClass object has already been generated for a class
994
+	 * and returns that instead of creating a new one
995
+	 *
996
+	 * @access public
997
+	 * @param string $class_name
998
+	 * @return ReflectionClass
999
+	 */
1000
+	public function get_ReflectionClass($class_name)
1001
+	{
1002
+		if (
1003
+			! isset($this->_reflectors[$class_name])
1004
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1005
+		) {
1006
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1007
+		}
1008
+		return $this->_reflectors[$class_name];
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 * _resolve_dependencies
1015
+	 * examines the constructor for the requested class to determine
1016
+	 * if any dependencies exist, and if they can be injected.
1017
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1018
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1019
+	 * For example:
1020
+	 *        if attempting to load a class "Foo" with the following constructor:
1021
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1022
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1023
+	 *        but only IF they are NOT already present in the incoming arguments array,
1024
+	 *        and the correct classes can be loaded
1025
+	 *
1026
+	 * @access protected
1027
+	 * @param ReflectionClass $reflector
1028
+	 * @param string          $class_name
1029
+	 * @param array           $arguments
1030
+	 * @return array
1031
+	 * @throws \ReflectionException
1032
+	 */
1033
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1034
+	{
1035
+		// let's examine the constructor
1036
+		$constructor = $reflector->getConstructor();
1037
+		// whu? huh? nothing?
1038
+		if ( ! $constructor) {
1039
+			return $arguments;
1040
+		}
1041
+		// get constructor parameters
1042
+		$params = $constructor->getParameters();
1043
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1044
+		$argument_keys = array_keys($arguments);
1045
+		// now loop thru all of the constructors expected parameters
1046
+		foreach ($params as $index => $param) {
1047
+			// is this a dependency for a specific class ?
1048
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
1049
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1050
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1051
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1052
+				: $param_class;
1053
+			if (
1054
+				// param is not even a class
1055
+				empty($param_class)
1056
+				// and something already exists in the incoming arguments for this param
1057
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1058
+			) {
1059
+				// so let's skip this argument and move on to the next
1060
+				continue;
1061
+			}
1062
+			if (
1063
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1064
+				! empty($param_class)
1065
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1066
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1067
+			) {
1068
+				// skip this argument and move on to the next
1069
+				continue;
1070
+			}
1071
+			if (
1072
+				// parameter is type hinted as a class, and should be injected
1073
+				! empty($param_class)
1074
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1075
+			) {
1076
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1077
+			} else {
1078
+				try {
1079
+					$arguments[$index] = $param->getDefaultValue();
1080
+				} catch (ReflectionException $e) {
1081
+					throw new ReflectionException(
1082
+						sprintf(
1083
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1084
+							$e->getMessage(),
1085
+							$param->getName()
1086
+						)
1087
+					);
1088
+				}
1089
+			}
1090
+		}
1091
+		return $arguments;
1092
+	}
1093
+
1094
+
1095
+
1096
+	/**
1097
+	 * @access protected
1098
+	 * @param string $class_name
1099
+	 * @param string $param_class
1100
+	 * @param array  $arguments
1101
+	 * @param mixed  $index
1102
+	 * @return array
1103
+	 */
1104
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1105
+	{
1106
+		$dependency = null;
1107
+		// should dependency be loaded from cache ?
1108
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1109
+					!== EE_Dependency_Map::load_new_object
1110
+			? true
1111
+			: false;
1112
+		// we might have a dependency...
1113
+		// let's MAYBE try and find it in our cache if that's what's been requested
1114
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1115
+		// and grab it if it exists
1116
+		if ($cached_class instanceof $param_class) {
1117
+			$dependency = $cached_class;
1118
+		} else if ($param_class !== $class_name) {
1119
+			// obtain the loader method from the dependency map
1120
+			$loader = $this->_dependency_map->class_loader($param_class);
1121
+			// is loader a custom closure ?
1122
+			if ($loader instanceof Closure) {
1123
+				$dependency = $loader();
1124
+			} else {
1125
+				// set the cache on property for the recursive loading call
1126
+				$this->_cache_on = $cache_on;
1127
+				// if not, then let's try and load it via the registry
1128
+				if ($loader && method_exists($this, $loader)) {
1129
+					$dependency = $this->{$loader}($param_class);
1130
+				} else {
1131
+					$dependency = $this->create($param_class, array(), $cache_on);
1132
+				}
1133
+			}
1134
+		}
1135
+		// did we successfully find the correct dependency ?
1136
+		if ($dependency instanceof $param_class) {
1137
+			// then let's inject it into the incoming array of arguments at the correct location
1138
+			if (isset($argument_keys[$index])) {
1139
+				$arguments[$argument_keys[$index]] = $dependency;
1140
+			} else {
1141
+				$arguments[$index] = $dependency;
1142
+			}
1143
+		}
1144
+		return $arguments;
1145
+	}
1146
+
1147
+
1148
+
1149
+	/**
1150
+	 * _set_cached_class
1151
+	 * attempts to cache the instantiated class locally
1152
+	 * in one of the following places, in the following order:
1153
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1154
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1155
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1156
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1157
+	 *
1158
+	 * @access protected
1159
+	 * @param object $class_obj
1160
+	 * @param string $class_name
1161
+	 * @param string $class_prefix
1162
+	 * @param bool   $from_db
1163
+	 * @return void
1164
+	 */
1165
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1166
+	{
1167
+		if (empty($class_obj)) {
1168
+			return;
1169
+		}
1170
+		// return newly instantiated class
1171
+		if (isset($this->_class_abbreviations[$class_name])) {
1172
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1173
+			$this->{$class_abbreviation} = $class_obj;
1174
+			return;
1175
+		}
1176
+		$class_name = str_replace('\\', '_', $class_name);
1177
+		if (property_exists($this, $class_name)) {
1178
+			$this->{$class_name} = $class_obj;
1179
+			return;
1180
+		}
1181
+		if ($class_prefix === 'addon') {
1182
+			$this->addons->{$class_name} = $class_obj;
1183
+			return;
1184
+		}
1185
+		if ( ! $from_db) {
1186
+			$this->LIB->{$class_name} = $class_obj;
1187
+		}
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1194
+	 *
1195
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1196
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1197
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1198
+	 * @param array  $arguments
1199
+	 * @return object
1200
+	 */
1201
+	public static function factory($classname, $arguments = array())
1202
+	{
1203
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1204
+		if ($loader instanceof Closure) {
1205
+			return $loader($arguments);
1206
+		}
1207
+		if (method_exists(EE_Registry::instance(), $loader)) {
1208
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1209
+		}
1210
+		return null;
1211
+	}
1212
+
1213
+
1214
+
1215
+	/**
1216
+	 * Gets the addon by its name/slug (not classname. For that, just
1217
+	 * use the classname as the property name on EE_Config::instance()->addons)
1218
+	 *
1219
+	 * @param string $name
1220
+	 * @return EE_Addon
1221
+	 */
1222
+	public function get_addon_by_name($name)
1223
+	{
1224
+		foreach ($this->addons as $addon) {
1225
+			if ($addon->name() == $name) {
1226
+				return $addon;
1227
+			}
1228
+		}
1229
+		return null;
1230
+	}
1231
+
1232
+
1233
+
1234
+	/**
1235
+	 * 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
1236
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1237
+	 *
1238
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1239
+	 */
1240
+	public function get_addons_by_name()
1241
+	{
1242
+		$addons = array();
1243
+		foreach ($this->addons as $addon) {
1244
+			$addons[$addon->name()] = $addon;
1245
+		}
1246
+		return $addons;
1247
+	}
1248
+
1249
+
1250
+
1251
+	/**
1252
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1253
+	 * a stale copy of it around
1254
+	 *
1255
+	 * @param string $model_name
1256
+	 * @return \EEM_Base
1257
+	 * @throws \EE_Error
1258
+	 */
1259
+	public function reset_model($model_name)
1260
+	{
1261
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1262
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1263
+			return null;
1264
+		}
1265
+		//get that model reset it and make sure we nuke the old reference to it
1266
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1267
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1268
+		} else {
1269
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1270
+		}
1271
+		return $this->LIB->{$model_class_name};
1272
+	}
1273
+
1274
+
1275
+
1276
+	/**
1277
+	 * Resets the registry.
1278
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1279
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1280
+	 * - $_dependency_map
1281
+	 * - $_class_abbreviations
1282
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1283
+	 * - $REQ:  Still on the same request so no need to change.
1284
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1285
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1286
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1287
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1288
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1289
+	 *             switch or on the restore.
1290
+	 * - $modules
1291
+	 * - $shortcodes
1292
+	 * - $widgets
1293
+	 *
1294
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1295
+	 *                                  the Registry to its state at the beginning of the request
1296
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1297
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1298
+	 *                                  currently reinstantiate the singletons at the moment)
1299
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1300
+	 *                                  code instead can just change the model context to a different blog id if necessary
1301
+	 * @return EE_Registry
1302
+	 */
1303
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1304
+	{
1305
+		$instance = self::instance();
1306
+		EEH_Activation::reset();
1307
+		//properties that get reset
1308
+		$instance->_cache_on = true;
1309
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1310
+		$instance->CART = null;
1311
+		$instance->MRM = null;
1312
+		$instance->AssetsRegistry = null;
1313
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1314
+		//messages reset
1315
+		EED_Messages::reset();
1316
+		if ($reset_models) {
1317
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1318
+				$instance->reset_model($model_name);
1319
+			}
1320
+		}
1321
+		$instance->LIB = new stdClass();
1322
+		return $instance;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * @override magic methods
1329
+	 * @return void
1330
+	 */
1331
+	public final function __destruct()
1332
+	{
1333
+	}
1334
+
1335
+
1336
+
1337
+	/**
1338
+	 * @param $a
1339
+	 * @param $b
1340
+	 */
1341
+	public final function __call($a, $b)
1342
+	{
1343
+	}
1344
+
1345
+
1346
+
1347
+	/**
1348
+	 * @param $a
1349
+	 */
1350
+	public final function __get($a)
1351
+	{
1352
+	}
1353
+
1354
+
1355
+
1356
+	/**
1357
+	 * @param $a
1358
+	 * @param $b
1359
+	 */
1360
+	public final function __set($a, $b)
1361
+	{
1362
+	}
1363
+
1364
+
1365
+
1366
+	/**
1367
+	 * @param $a
1368
+	 */
1369
+	public final function __isset($a)
1370
+	{
1371
+	}
1372 1372
 
1373 1373
 
1374 1374
 
1375
-    /**
1376
-     * @param $a
1377
-     */
1378
-    public final function __unset($a)
1379
-    {
1380
-    }
1375
+	/**
1376
+	 * @param $a
1377
+	 */
1378
+	public final function __unset($a)
1379
+	{
1380
+	}
1381 1381
 
1382 1382
 
1383 1383
 
1384
-    /**
1385
-     * @return array
1386
-     */
1387
-    public final function __sleep()
1388
-    {
1389
-        return array();
1390
-    }
1384
+	/**
1385
+	 * @return array
1386
+	 */
1387
+	public final function __sleep()
1388
+	{
1389
+		return array();
1390
+	}
1391 1391
 
1392 1392
 
1393 1393
 
1394
-    public final function __wakeup()
1395
-    {
1396
-    }
1394
+	public final function __wakeup()
1395
+	{
1396
+	}
1397 1397
 
1398 1398
 
1399 1399
 
1400
-    /**
1401
-     * @return string
1402
-     */
1403
-    public final function __toString()
1404
-    {
1405
-        return '';
1406
-    }
1400
+	/**
1401
+	 * @return string
1402
+	 */
1403
+	public final function __toString()
1404
+	{
1405
+		return '';
1406
+	}
1407 1407
 
1408 1408
 
1409 1409
 
1410
-    public final function __invoke()
1411
-    {
1412
-    }
1410
+	public final function __invoke()
1411
+	{
1412
+	}
1413 1413
 
1414 1414
 
1415 1415
 
1416
-    public final static function __set_state($array = array())
1417
-    {
1418
-        return EE_Registry::instance();
1419
-    }
1416
+	public final static function __set_state($array = array())
1417
+	{
1418
+		return EE_Registry::instance();
1419
+	}
1420 1420
 
1421 1421
 
1422 1422
 
1423
-    public final function __clone()
1424
-    {
1425
-    }
1423
+	public final function __clone()
1424
+	{
1425
+	}
1426 1426
 
1427 1427
 
1428 1428
 
1429
-    /**
1430
-     * @param $a
1431
-     * @param $b
1432
-     */
1433
-    public final static function __callStatic($a, $b)
1434
-    {
1435
-    }
1429
+	/**
1430
+	 * @param $a
1431
+	 * @param $b
1432
+	 */
1433
+	public final static function __callStatic($a, $b)
1434
+	{
1435
+	}
1436 1436
 
1437 1437
 
1438 1438
 
1439
-    /**
1440
-     * Gets all the custom post type models defined
1441
-     *
1442
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1443
-     */
1444
-    public function cpt_models()
1445
-    {
1446
-        $cpt_models = array();
1447
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1448
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1449
-                $cpt_models[$short_name] = $classname;
1450
-            }
1451
-        }
1452
-        return $cpt_models;
1453
-    }
1439
+	/**
1440
+	 * Gets all the custom post type models defined
1441
+	 *
1442
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1443
+	 */
1444
+	public function cpt_models()
1445
+	{
1446
+		$cpt_models = array();
1447
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1448
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1449
+				$cpt_models[$short_name] = $classname;
1450
+			}
1451
+		}
1452
+		return $cpt_models;
1453
+	}
1454 1454
 
1455 1455
 
1456 1456
 
1457
-    /**
1458
-     * @return \EE_Config
1459
-     */
1460
-    public static function CFG()
1461
-    {
1462
-        return self::instance()->CFG;
1463
-    }
1457
+	/**
1458
+	 * @return \EE_Config
1459
+	 */
1460
+	public static function CFG()
1461
+	{
1462
+		return self::instance()->CFG;
1463
+	}
1464 1464
 
1465 1465
 
1466 1466
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public static function localize_i18n_js_strings()
296 296
     {
297
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
297
+        $i18n_js_strings = (array) EE_Registry::$i18n_js_strings;
298 298
         foreach ($i18n_js_strings as $key => $value) {
299 299
             if (is_scalar($value)) {
300
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
300
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
301 301
             }
302 302
         }
303
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
303
+        return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */';
304 304
     }
305 305
 
306 306
 
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
                 EE_CORE,
352 352
                 EE_ADMIN,
353 353
                 EE_CPTS,
354
-                EE_CORE . 'data_migration_scripts' . DS,
355
-                EE_CORE . 'request_stack' . DS,
356
-                EE_CORE . 'middleware' . DS,
354
+                EE_CORE.'data_migration_scripts'.DS,
355
+                EE_CORE.'request_stack'.DS,
356
+                EE_CORE.'middleware'.DS,
357 357
             )
358 358
         );
359 359
         // retrieve instantiated class
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         $service_paths = apply_filters(
377 377
             'FHEE__EE_Registry__load_service__service_paths',
378 378
             array(
379
-                EE_CORE . 'services' . DS,
379
+                EE_CORE.'services'.DS,
380 380
             )
381 381
         );
382 382
         // retrieve instantiated class
@@ -456,11 +456,11 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $paths = array(
458 458
             EE_LIBRARIES,
459
-            EE_LIBRARIES . 'messages' . DS,
460
-            EE_LIBRARIES . 'shortcodes' . DS,
461
-            EE_LIBRARIES . 'qtips' . DS,
462
-            EE_LIBRARIES . 'payment_methods' . DS,
463
-            EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
459
+            EE_LIBRARIES.'messages'.DS,
460
+            EE_LIBRARIES.'shortcodes'.DS,
461
+            EE_LIBRARIES.'qtips'.DS,
462
+            EE_LIBRARIES.'payment_methods'.DS,
463
+            EE_LIBRARIES.'messages'.DS.'defaults'.DS,
464 464
         );
465 465
         // retrieve instantiated class
466 466
         return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
@@ -499,10 +499,10 @@  discard block
 block discarded – undo
499 499
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
500 500
     {
501 501
         $paths = array(
502
-            EE_MODELS . 'fields' . DS,
503
-            EE_MODELS . 'helpers' . DS,
504
-            EE_MODELS . 'relations' . DS,
505
-            EE_MODELS . 'strategies' . DS,
502
+            EE_MODELS.'fields'.DS,
503
+            EE_MODELS.'helpers'.DS,
504
+            EE_MODELS.'relations'.DS,
505
+            EE_MODELS.'strategies'.DS,
506 506
         );
507 507
         // retrieve instantiated class
508 508
         return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
         $class_name = $this->_dependency_map->get_alias($class_name);
590 590
         if ( ! class_exists($class_name)) {
591 591
             // maybe the class is registered with a preceding \
592
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
592
+            $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name;
593 593
             // still doesn't exist ?
594 594
             if ( ! class_exists($class_name)) {
595 595
                 return null;
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
             // make sure $class_prefix is uppercase
657 657
             $class_prefix = strtoupper(trim($class_prefix));
658 658
             // add class prefix ONCE!!!
659
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
660 660
         }
661 661
         $class_name = $this->_dependency_map->get_alias($class_name);
662 662
         $class_exists = class_exists($class_name, false);
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
     protected function _get_cached_class($class_name, $class_prefix = '')
717 717
     {
718 718
         // have to specify something, but not anything that will conflict
719
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
720
-            ? $this->_class_abbreviations[ $class_name ]
719
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
720
+            ? $this->_class_abbreviations[$class_name]
721 721
             : 'FANCY_BATMAN_PANTS';
722 722
         $class_name = str_replace('\\', '_', $class_name);
723 723
         // check if class has already been loaded, and return it if it has been
@@ -748,8 +748,8 @@  discard block
 block discarded – undo
748 748
     public function clear_cached_class($class_name, $addon = false)
749 749
     {
750 750
         // have to specify something, but not anything that will conflict
751
-        $class_abbreviation = isset($this->_class_abbreviations[ $class_name ])
752
-            ? $this->_class_abbreviations[ $class_name ]
751
+        $class_abbreviation = isset($this->_class_abbreviations[$class_name])
752
+            ? $this->_class_abbreviations[$class_name]
753 753
             : 'FANCY_BATMAN_PANTS';
754 754
         $class_name = str_replace('\\', '_', $class_name);
755 755
         // check if class has already been loaded, and return it if it has been
@@ -794,9 +794,9 @@  discard block
 block discarded – undo
794 794
             // convert all separators to proper DS, if no filepath, then use EE_CLASSES
795 795
             $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
796 796
             // prep file type
797
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
797
+            $type = ! empty($type) ? trim($type, '.').'.' : '';
798 798
             // build full file path
799
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
799
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
800 800
             //does the file exist and can be read ?
801 801
             if (is_readable($file_paths[$key])) {
802 802
                 return $file_paths[$key];
@@ -828,12 +828,12 @@  discard block
 block discarded – undo
828 828
             //does the file exist and can it be read ?
829 829
             if ( ! $path) {
830 830
                 // so sorry, can't find the file
831
-                throw new EE_Error (
831
+                throw new EE_Error(
832 832
                     sprintf(
833 833
                         __('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'),
834 834
                         trim($type, '.'),
835 835
                         $class_name,
836
-                        '<br />' . implode(',<br />', $file_paths)
836
+                        '<br />'.implode(',<br />', $file_paths)
837 837
                     )
838 838
                 );
839 839
             }
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
             $legacy_parent_class_map = array(
875 875
                 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
876 876
             );
877
-            if(isset($legacy_parent_class_map[$class_name])) {
878
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
877
+            if (isset($legacy_parent_class_map[$class_name])) {
878
+                require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name];
879 879
             }
880 880
         } catch (Exception $exception) {
881 881
         }
Please login to merge, or discard this patch.