Completed
Branch BUG-9042-ics-organizer-email (7b2e23)
by
unknown
29:24 queued 16:15
created
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1388 added lines, -1388 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -24,445 +24,445 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var object
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var object
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map = null;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  object $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (is_array($box['callback'])
259
-                        && ($box['callback'][0] instanceof EE_Admin_Page
260
-                            || $box['callback'][0] instanceof EE_Admin_Hooks)
261
-                    ) {
262
-                        $containers[] = $box['id'];
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
-        //add hidden inputs container
269
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
-    }
271
-
272
-
273
-
274
-    protected function _load_autosave_scripts_styles()
275
-    {
276
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map = null;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  object $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (is_array($box['callback'])
259
+						&& ($box['callback'][0] instanceof EE_Admin_Page
260
+							|| $box['callback'][0] instanceof EE_Admin_Hooks)
261
+					) {
262
+						$containers[] = $box['id'];
263
+					}
264
+				}
265
+			}
266
+		}
267
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
+		//add hidden inputs container
269
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
+	}
271
+
272
+
273
+
274
+	protected function _load_autosave_scripts_styles()
275
+	{
276
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
277 277
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
278 278
 
279
-        //filter _autosave_containers
280
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
-            $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
-            $containers, $this);
284
-
285
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
-
288
-        $unsaved_data_msg = array(
289
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
291
-            'inputChanged' => 0,
292
-        );
293
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
-    }
295
-
296
-
297
-
298
-    public function load_page_dependencies()
299
-    {
300
-        try {
301
-            $this->_load_page_dependencies();
302
-        } catch (EE_Error $e) {
303
-            $e->get_error();
304
-        }
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
-     *
312
-     * @access protected
313
-     * @return void
314
-     */
315
-    protected function _load_page_dependencies()
316
-    {
317
-        //we only add stuff if this is a cpt_route!
318
-        if ( ! $this->_cpt_route) {
319
-            parent::_load_page_dependencies();
320
-            return;
321
-        }
322
-        //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
-        //the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
-        //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
-        //inject our Admin page nav tabs...
327
-        //let's make sure the nav tabs are set if they aren't already
328
-        //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
-        //modify the post_updated messages array
331
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
-        //add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
-        //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
-        if ( ! empty($this->_labels['publishbox'])) {
336
-            $box_label = is_array($this->_labels['publishbox'])
337
-                         && isset($this->_labels['publishbox'][$this->_req_action])
338
-                ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
-            remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
-                'side', 'core');
341
-            add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
-                'side', 'core');
343
-        }
344
-        //let's add page_templates metabox if this cpt added support for it.
345
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
-            add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
-                array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
-        }
349
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
351
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
-        }
353
-        //add preview button
354
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
-        //insert our own post_stati dropdown
356
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
358
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
-        }
361
-        //This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
-        if (method_exists($this, 'edit_form_after_title')) {
363
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
-        }
365
-        /**
366
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
-         */
368
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
-        parent::_load_page_dependencies();
370
-        //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
-        global $pagenow;
372
-        do_action('load-' . $pagenow);
373
-        $this->modify_current_screen();
374
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
-        //we route REALLY early.
376
-        try {
377
-            $this->_route_admin_request();
378
-        } catch (EE_Error $e) {
379
-            $e->get_error();
380
-        }
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
-     * route instead.
389
-     *
390
-     * @param string $good_protocol_url The escaped url.
391
-     * @param string $original_url      The original url.
392
-     * @param string $_context          The context sendt to the esc_url method.
393
-     * @return string possibly a new url for our route.
394
-     */
395
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
-    {
397
-        $routes_to_match = array(
398
-            0 => array(
399
-                'edit.php?post_type=espresso_attendees',
400
-                'admin.php?page=espresso_registrations&action=contact_list',
401
-            ),
402
-            1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
405
-            ),
406
-        );
407
-        foreach ($routes_to_match as $route_matches) {
408
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
-            }
411
-        }
412
-        return $good_protocol_url;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Determine whether the current cpt supports page templates or not.
419
-     *
420
-     * @since %VER%
421
-     * @param string $cpt_name The cpt slug we're checking on.
422
-     * @return bool True supported, false not.
423
-     */
424
-    private function _supports_page_templates($cpt_name)
425
-    {
426
-
427
-        $cpt_args = EE_Register_CPTs::get_CPTs();
428
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
430
-
431
-        //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
-            $post_templates = wp_get_theme()->get_post_templates();
434
-            //if there are $post_templates for this cpt, then we return false for this method because
435
-            //that means we aren't going to load our page template manager and leave that up to the native
436
-            //cpt template manager.
437
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
-        }
439
-
440
-        return $cpt_has_support;
441
-    }
442
-
443
-
444
-    /**
445
-     * Callback for the page_templates metabox selector.
446
-     *
447
-     * @since %VER%
448
-     * @return string html
449
-     */
450
-    public function page_template_meta_box()
451
-    {
452
-        global $post;
453
-        $template = '';
454
-
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
-            $page_template_count = count(get_page_templates());
457
-        } else {
458
-            $page_template_count = count(get_page_templates($post));
459
-        };
460
-
461
-        if ($page_template_count) {
462
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
-            $template      = ! empty($page_template) ? $page_template : '';
464
-        }
465
-        ?>
279
+		//filter _autosave_containers
280
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
+			$this->_autosave_containers, $this);
282
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
+			$containers, $this);
284
+
285
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
+
288
+		$unsaved_data_msg = array(
289
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
291
+			'inputChanged' => 0,
292
+		);
293
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
+	}
295
+
296
+
297
+
298
+	public function load_page_dependencies()
299
+	{
300
+		try {
301
+			$this->_load_page_dependencies();
302
+		} catch (EE_Error $e) {
303
+			$e->get_error();
304
+		}
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
+	 *
312
+	 * @access protected
313
+	 * @return void
314
+	 */
315
+	protected function _load_page_dependencies()
316
+	{
317
+		//we only add stuff if this is a cpt_route!
318
+		if ( ! $this->_cpt_route) {
319
+			parent::_load_page_dependencies();
320
+			return;
321
+		}
322
+		//now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
+		//the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
+		//let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
+		//inject our Admin page nav tabs...
327
+		//let's make sure the nav tabs are set if they aren't already
328
+		//if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
+		//modify the post_updated messages array
331
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
+		//add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
+		//This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
+		if ( ! empty($this->_labels['publishbox'])) {
336
+			$box_label = is_array($this->_labels['publishbox'])
337
+						 && isset($this->_labels['publishbox'][$this->_req_action])
338
+				? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
+			remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
+				'side', 'core');
341
+			add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
+				'side', 'core');
343
+		}
344
+		//let's add page_templates metabox if this cpt added support for it.
345
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
+			add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
+				array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
+		}
349
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
351
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
+		}
353
+		//add preview button
354
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
+		//insert our own post_stati dropdown
356
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
358
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
+		}
361
+		//This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
+		if (method_exists($this, 'edit_form_after_title')) {
363
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
+		}
365
+		/**
366
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
+		 */
368
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
+		parent::_load_page_dependencies();
370
+		//notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
+		global $pagenow;
372
+		do_action('load-' . $pagenow);
373
+		$this->modify_current_screen();
374
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
+		//we route REALLY early.
376
+		try {
377
+			$this->_route_admin_request();
378
+		} catch (EE_Error $e) {
379
+			$e->get_error();
380
+		}
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
+	 * route instead.
389
+	 *
390
+	 * @param string $good_protocol_url The escaped url.
391
+	 * @param string $original_url      The original url.
392
+	 * @param string $_context          The context sendt to the esc_url method.
393
+	 * @return string possibly a new url for our route.
394
+	 */
395
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
+	{
397
+		$routes_to_match = array(
398
+			0 => array(
399
+				'edit.php?post_type=espresso_attendees',
400
+				'admin.php?page=espresso_registrations&action=contact_list',
401
+			),
402
+			1 => array(
403
+				'edit.php?post_type=' . $this->_cpt_object->name,
404
+				'admin.php?page=' . $this->_cpt_object->name,
405
+			),
406
+		);
407
+		foreach ($routes_to_match as $route_matches) {
408
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
+			}
411
+		}
412
+		return $good_protocol_url;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Determine whether the current cpt supports page templates or not.
419
+	 *
420
+	 * @since %VER%
421
+	 * @param string $cpt_name The cpt slug we're checking on.
422
+	 * @return bool True supported, false not.
423
+	 */
424
+	private function _supports_page_templates($cpt_name)
425
+	{
426
+
427
+		$cpt_args = EE_Register_CPTs::get_CPTs();
428
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
430
+
431
+		//if the installed version of WP is > 4.7 we do some additional checks.
432
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
+			$post_templates = wp_get_theme()->get_post_templates();
434
+			//if there are $post_templates for this cpt, then we return false for this method because
435
+			//that means we aren't going to load our page template manager and leave that up to the native
436
+			//cpt template manager.
437
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
+		}
439
+
440
+		return $cpt_has_support;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Callback for the page_templates metabox selector.
446
+	 *
447
+	 * @since %VER%
448
+	 * @return string html
449
+	 */
450
+	public function page_template_meta_box()
451
+	{
452
+		global $post;
453
+		$template = '';
454
+
455
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
+			$page_template_count = count(get_page_templates());
457
+		} else {
458
+			$page_template_count = count(get_page_templates($post));
459
+		};
460
+
461
+		if ($page_template_count) {
462
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
+			$template      = ! empty($page_template) ? $page_template : '';
464
+		}
465
+		?>
466 466
         <p><strong><?php _e('Template') ?></strong></p>
467 467
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
468 468
             name="page_template" id="page_template">
@@ -470,437 +470,437 @@  discard block
 block discarded – undo
470 470
         <?php page_template_dropdown($template); ?>
471 471
     </select>
472 472
         <?php
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
479
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
-     *
481
-     * @param  string $return    the current html
482
-     * @param  int    $id        the post id for the page
483
-     * @param  string $new_title What the title is
484
-     * @param  string $new_slug  what the slug is
485
-     * @return string            The new html string for the permalink area
486
-     */
487
-    public function preview_button_html($return, $id, $new_title, $new_slug)
488
-    {
489
-        $post = get_post($id);
490
-        if ('publish' != get_post_status($post)) {
491
-            //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
493
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
-                       . get_preview_post_link($id)
495
-                       . '" class="button button-small">'
496
-                       . __('Preview', 'event_espresso')
497
-                       . '</a></span>'
498
-                       . "\n";
499
-        }
500
-        return $return;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * add our custom post stati dropdown on the wp post page for this cpt
507
-     *
508
-     * @return string html for dropdown
509
-     */
510
-    public function custom_post_stati_dropdown()
511
-    {
512
-
513
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
-            ? $statuses[$this->_cpt_model_obj->status()]
516
-            : '';
517
-        $template_args    = array(
518
-            'cur_status'            => $this->_cpt_model_obj->status(),
519
-            'statuses'              => $statuses,
520
-            'cur_status_label'      => $cur_status_label,
521
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
-        );
523
-        //we'll add a trash post status (WP doesn't add one for some reason)
524
-        if ($this->_cpt_model_obj->status() == 'trash') {
525
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
527
-            $template_args['statuses']         = $statuses;
528
-        }
529
-
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
-        EEH_Template::display_template($template, $template_args);
532
-    }
533
-
534
-
535
-
536
-    public function setup_autosave_hooks()
537
-    {
538
-        $this->_set_autosave_containers();
539
-        $this->_load_autosave_scripts_styles();
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
-     * for the nonce in here, but then this method looks for two things:
548
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
-     * template args.
553
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
-     *    $this->_template_args['data']['items'] = array(
557
-     *        'event-datetime-ids' => '1,2,3';
558
-     *    );
559
-     *    Keep in mind the following things:
560
-     *    - "where" index is for the input with the id as that string.
561
-     *    - "what" index is what will be used for the value of that input.
562
-     *
563
-     * @return void
564
-     */
565
-    public function do_extra_autosave_stuff()
566
-    {
567
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
568
-        $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
-        $this->_verify_nonce($nonce, 'autosave');
570
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
-        if ( ! defined('DOING_AUTOSAVE')) {
572
-            define('DOING_AUTOSAVE', true);
573
-        }
574
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
-        } else {
578
-            $this->_template_args['success'] = true;
579
-        }
580
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
-        //now let's return json
583
-        $this->_return_json();
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
-     *
593
-     * @access protected
594
-     * @throws EE_Error
595
-     * @return void
596
-     */
597
-    protected function _extend_page_config_for_cpt()
598
-    {
599
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
-        if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
-            return;
602
-        }
603
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
-        if ( ! empty($this->_cpt_object)) {
605
-            $this->_page_routes = array_merge(array(
606
-                'create_new' => '_create_new_cpt_item',
607
-                'edit'       => '_edit_cpt_item',
608
-            ), $this->_page_routes);
609
-            $this->_page_config = array_merge(array(
610
-                'create_new' => array(
611
-                    'nav'           => array(
612
-                        'label' => $this->_cpt_object->labels->add_new_item,
613
-                        'order' => 5,
614
-                    ),
615
-                    'require_nonce' => false,
616
-                ),
617
-                'edit'       => array(
618
-                    'nav'           => array(
619
-                        'label'      => $this->_cpt_object->labels->edit_item,
620
-                        'order'      => 5,
621
-                        'persistent' => false,
622
-                        'url'        => '',
623
-                    ),
624
-                    'require_nonce' => false,
625
-                ),
626
-            ),
627
-                $this->_page_config
628
-            );
629
-        }
630
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
631
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
-            return;
633
-        }
634
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
-        if (empty($this->_cpt_object)) {
637
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
-                $this->page_slug, $this->_req_action, get_class($this));
639
-            throw new EE_Error($msg);
640
-        }
641
-        if ($this->_cpt_route) {
642
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
-            $this->_set_model_object($id);
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
-     *
652
-     * @access protected
653
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
-     * @param bool $ignore_route_check
655
-     */
656
-    protected function _set_model_object($id = null, $ignore_route_check = false)
657
-    {
658
-        $model = null;
659
-        if (
660
-            empty($this->_cpt_model_names)
661
-            || (
662
-                ! $ignore_route_check
663
-                && ! isset($this->_cpt_routes[$this->_req_action])
664
-            ) || (
665
-                $this->_cpt_model_obj instanceof EE_CPT_Base
666
-                && $this->_cpt_model_obj->ID() === $id
667
-            )
668
-        ) {
669
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
-            return;
671
-        }
672
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
-        if ($ignore_route_check) {
674
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
675
-            $post_type   = get_post_type($id);
676
-            if (isset($model_names[$post_type])) {
677
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
-            }
679
-        } else {
680
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
-        }
682
-        if ($model instanceof EEM_Base) {
683
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
-        }
685
-        do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * admin_init_global
692
-     * This runs all the code that we want executed within the WP admin_init hook.
693
-     * This method executes for ALL EE Admin pages.
694
-     *
695
-     * @access public
696
-     * @return void
697
-     */
698
-    public function admin_init_global()
699
-    {
700
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
-        //its possible this is a new save so let's catch that instead
702
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
-        $post_type = $post ? $post->post_type : false;
704
-        $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
-            : 'shouldneverwork';
706
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
-            : '';
708
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
-        if ($post_type === $route_to_check) {
711
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
-            //catch trashed wp redirect
713
-            add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
714
-        }
715
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
716
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
717
-        if ( ! empty($revision)) {
718
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
719
-            //doing a restore?
720
-            if ( ! empty($action) && $action == 'restore') {
721
-                //get post for revision
722
-                $rev_post = get_post($revision);
723
-                $rev_parent = get_post($rev_post->post_parent);
724
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
725
-                if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
726
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
727
-                    //restores of revisions
728
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
729
-                }
730
-            }
731
-        }
732
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
733
-        if ($post_type && $post_type === $route_to_check) {
734
-            //$post_id, $post
735
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
736
-            //$post_id
737
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
738
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
739
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
740
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * Callback for the WordPress trashed_post hook.
748
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
749
-     *
750
-     * @param int $post_id
751
-     */
752
-    public function before_trash_cpt_item($post_id)
753
-    {
754
-        $this->_set_model_object($post_id, true);
755
-        //if our cpt object isn't existent then get out immediately.
756
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
757
-            return;
758
-        }
759
-        $this->trash_cpt_item($post_id);
760
-    }
761
-
762
-
763
-
764
-    /**
765
-     * Callback for the WordPress untrashed_post hook.
766
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
767
-     *
768
-     * @param $post_id
769
-     */
770
-    public function before_restore_cpt_item($post_id)
771
-    {
772
-        $this->_set_model_object($post_id, true);
773
-        //if our cpt object isn't existent then get out immediately.
774
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
775
-            return;
776
-        }
777
-        $this->restore_cpt_item($post_id);
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     * Callback for the WordPress after_delete_post hook.
784
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
785
-     *
786
-     * @param $post_id
787
-     */
788
-    public function before_delete_cpt_item($post_id)
789
-    {
790
-        $this->_set_model_object($post_id, true);
791
-        //if our cpt object isn't existent then get out immediately.
792
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
793
-            return;
794
-        }
795
-        $this->delete_cpt_item($post_id);
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
802
-     * accordingly.
803
-     *
804
-     * @access public
805
-     * @throws EE_Error
806
-     * @return void
807
-     */
808
-    public function verify_cpt_object()
809
-    {
810
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
811
-        // verify event object
812
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
813
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
814
-                'event_espresso'), $label));
815
-        }
816
-        //if auto-draft then throw an error
817
-        if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
818
-            EE_Error::overwrite_errors();
819
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
820
-                $label), __FILE__, __FUNCTION__, __LINE__);
821
-        }
822
-    }
823
-
824
-
825
-
826
-    /**
827
-     * admin_footer_scripts_global
828
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
829
-     * will apply on ALL EE_Admin pages.
830
-     *
831
-     * @access public
832
-     * @return void
833
-     */
834
-    public function admin_footer_scripts_global()
835
-    {
836
-        $this->_add_admin_page_ajax_loading_img();
837
-        $this->_add_admin_page_overlay();
838
-    }
839
-
840
-
841
-
842
-    /**
843
-     * add in any global scripts for cpt routes
844
-     *
845
-     * @return void
846
-     */
847
-    public function load_global_scripts_styles()
848
-    {
849
-        parent::load_global_scripts_styles();
850
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
851
-            //setup custom post status object for localize script but only if we've got a cpt object
852
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
853
-            if ( ! empty($statuses)) {
854
-                //get ALL statuses!
855
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
856
-                //setup object
857
-                $ee_cpt_statuses = array();
858
-                foreach ($statuses as $status => $label) {
859
-                    $ee_cpt_statuses[$status] = array(
860
-                        'label'      => $label,
861
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
862
-                    );
863
-                }
864
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
865
-            }
866
-        }
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
873
-     * insert/updates
874
-     *
875
-     * @param  int     $post_id ID of post being updated
876
-     * @param  WP_Post $post    Post object from WP
877
-     * @param  bool    $update  Whether this is an update or a new save.
878
-     * @return void
879
-     */
880
-    public function insert_update($post_id, $post, $update)
881
-    {
882
-        //make sure that if this is a revision OR trash action that we don't do any updates!
883
-        if (
884
-            isset($this->_req_data['action'])
885
-            && (
886
-                $this->_req_data['action'] == 'restore'
887
-                || $this->_req_data['action'] == 'trash'
888
-            )
889
-        ) {
890
-            return;
891
-        }
892
-        $this->_set_model_object($post_id, true);
893
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
894
-        if ($update
895
-            && (
896
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
897
-                || $this->_cpt_model_obj->ID() !== $post_id
898
-            )
899
-        ) {
900
-            return;
901
-        }
902
-        //check for autosave and update our req_data property accordingly.
903
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
479
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
+	 *
481
+	 * @param  string $return    the current html
482
+	 * @param  int    $id        the post id for the page
483
+	 * @param  string $new_title What the title is
484
+	 * @param  string $new_slug  what the slug is
485
+	 * @return string            The new html string for the permalink area
486
+	 */
487
+	public function preview_button_html($return, $id, $new_title, $new_slug)
488
+	{
489
+		$post = get_post($id);
490
+		if ('publish' != get_post_status($post)) {
491
+			//include shims for the `get_preview_post_link` function
492
+			require_once( EE_CORE . 'wordpress-shims.php' );
493
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
+					   . get_preview_post_link($id)
495
+					   . '" class="button button-small">'
496
+					   . __('Preview', 'event_espresso')
497
+					   . '</a></span>'
498
+					   . "\n";
499
+		}
500
+		return $return;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * add our custom post stati dropdown on the wp post page for this cpt
507
+	 *
508
+	 * @return string html for dropdown
509
+	 */
510
+	public function custom_post_stati_dropdown()
511
+	{
512
+
513
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
+			? $statuses[$this->_cpt_model_obj->status()]
516
+			: '';
517
+		$template_args    = array(
518
+			'cur_status'            => $this->_cpt_model_obj->status(),
519
+			'statuses'              => $statuses,
520
+			'cur_status_label'      => $cur_status_label,
521
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
+		);
523
+		//we'll add a trash post status (WP doesn't add one for some reason)
524
+		if ($this->_cpt_model_obj->status() == 'trash') {
525
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
527
+			$template_args['statuses']         = $statuses;
528
+		}
529
+
530
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
+		EEH_Template::display_template($template, $template_args);
532
+	}
533
+
534
+
535
+
536
+	public function setup_autosave_hooks()
537
+	{
538
+		$this->_set_autosave_containers();
539
+		$this->_load_autosave_scripts_styles();
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
+	 * for the nonce in here, but then this method looks for two things:
548
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
+	 * template args.
553
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
+	 *    $this->_template_args['data']['items'] = array(
557
+	 *        'event-datetime-ids' => '1,2,3';
558
+	 *    );
559
+	 *    Keep in mind the following things:
560
+	 *    - "where" index is for the input with the id as that string.
561
+	 *    - "what" index is what will be used for the value of that input.
562
+	 *
563
+	 * @return void
564
+	 */
565
+	public function do_extra_autosave_stuff()
566
+	{
567
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
568
+		$nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
+		$this->_verify_nonce($nonce, 'autosave');
570
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
+		if ( ! defined('DOING_AUTOSAVE')) {
572
+			define('DOING_AUTOSAVE', true);
573
+		}
574
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
575
+		if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
+			call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
+		} else {
578
+			$this->_template_args['success'] = true;
579
+		}
580
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
+		//now let's return json
583
+		$this->_return_json();
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
+	 *
593
+	 * @access protected
594
+	 * @throws EE_Error
595
+	 * @return void
596
+	 */
597
+	protected function _extend_page_config_for_cpt()
598
+	{
599
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
+		if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
+			return;
602
+		}
603
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
+		if ( ! empty($this->_cpt_object)) {
605
+			$this->_page_routes = array_merge(array(
606
+				'create_new' => '_create_new_cpt_item',
607
+				'edit'       => '_edit_cpt_item',
608
+			), $this->_page_routes);
609
+			$this->_page_config = array_merge(array(
610
+				'create_new' => array(
611
+					'nav'           => array(
612
+						'label' => $this->_cpt_object->labels->add_new_item,
613
+						'order' => 5,
614
+					),
615
+					'require_nonce' => false,
616
+				),
617
+				'edit'       => array(
618
+					'nav'           => array(
619
+						'label'      => $this->_cpt_object->labels->edit_item,
620
+						'order'      => 5,
621
+						'persistent' => false,
622
+						'url'        => '',
623
+					),
624
+					'require_nonce' => false,
625
+				),
626
+			),
627
+				$this->_page_config
628
+			);
629
+		}
630
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
631
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
+			return;
633
+		}
634
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
+		if (empty($this->_cpt_object)) {
637
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
+				$this->page_slug, $this->_req_action, get_class($this));
639
+			throw new EE_Error($msg);
640
+		}
641
+		if ($this->_cpt_route) {
642
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
+			$this->_set_model_object($id);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
+	 *
652
+	 * @access protected
653
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
+	 * @param bool $ignore_route_check
655
+	 */
656
+	protected function _set_model_object($id = null, $ignore_route_check = false)
657
+	{
658
+		$model = null;
659
+		if (
660
+			empty($this->_cpt_model_names)
661
+			|| (
662
+				! $ignore_route_check
663
+				&& ! isset($this->_cpt_routes[$this->_req_action])
664
+			) || (
665
+				$this->_cpt_model_obj instanceof EE_CPT_Base
666
+				&& $this->_cpt_model_obj->ID() === $id
667
+			)
668
+		) {
669
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
+			return;
671
+		}
672
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
+		if ($ignore_route_check) {
674
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
675
+			$post_type   = get_post_type($id);
676
+			if (isset($model_names[$post_type])) {
677
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
+			}
679
+		} else {
680
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
+		}
682
+		if ($model instanceof EEM_Base) {
683
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
+		}
685
+		do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * admin_init_global
692
+	 * This runs all the code that we want executed within the WP admin_init hook.
693
+	 * This method executes for ALL EE Admin pages.
694
+	 *
695
+	 * @access public
696
+	 * @return void
697
+	 */
698
+	public function admin_init_global()
699
+	{
700
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
+		//its possible this is a new save so let's catch that instead
702
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
+		$post_type = $post ? $post->post_type : false;
704
+		$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
+			: 'shouldneverwork';
706
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
+			: '';
708
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
+		if ($post_type === $route_to_check) {
711
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
+			//catch trashed wp redirect
713
+			add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
714
+		}
715
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
716
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
717
+		if ( ! empty($revision)) {
718
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
719
+			//doing a restore?
720
+			if ( ! empty($action) && $action == 'restore') {
721
+				//get post for revision
722
+				$rev_post = get_post($revision);
723
+				$rev_parent = get_post($rev_post->post_parent);
724
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
725
+				if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
726
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
727
+					//restores of revisions
728
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
729
+				}
730
+			}
731
+		}
732
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
733
+		if ($post_type && $post_type === $route_to_check) {
734
+			//$post_id, $post
735
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
736
+			//$post_id
737
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
738
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
739
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
740
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * Callback for the WordPress trashed_post hook.
748
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
749
+	 *
750
+	 * @param int $post_id
751
+	 */
752
+	public function before_trash_cpt_item($post_id)
753
+	{
754
+		$this->_set_model_object($post_id, true);
755
+		//if our cpt object isn't existent then get out immediately.
756
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
757
+			return;
758
+		}
759
+		$this->trash_cpt_item($post_id);
760
+	}
761
+
762
+
763
+
764
+	/**
765
+	 * Callback for the WordPress untrashed_post hook.
766
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
767
+	 *
768
+	 * @param $post_id
769
+	 */
770
+	public function before_restore_cpt_item($post_id)
771
+	{
772
+		$this->_set_model_object($post_id, true);
773
+		//if our cpt object isn't existent then get out immediately.
774
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
775
+			return;
776
+		}
777
+		$this->restore_cpt_item($post_id);
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 * Callback for the WordPress after_delete_post hook.
784
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
785
+	 *
786
+	 * @param $post_id
787
+	 */
788
+	public function before_delete_cpt_item($post_id)
789
+	{
790
+		$this->_set_model_object($post_id, true);
791
+		//if our cpt object isn't existent then get out immediately.
792
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
793
+			return;
794
+		}
795
+		$this->delete_cpt_item($post_id);
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
802
+	 * accordingly.
803
+	 *
804
+	 * @access public
805
+	 * @throws EE_Error
806
+	 * @return void
807
+	 */
808
+	public function verify_cpt_object()
809
+	{
810
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
811
+		// verify event object
812
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
813
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
814
+				'event_espresso'), $label));
815
+		}
816
+		//if auto-draft then throw an error
817
+		if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
818
+			EE_Error::overwrite_errors();
819
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
820
+				$label), __FILE__, __FUNCTION__, __LINE__);
821
+		}
822
+	}
823
+
824
+
825
+
826
+	/**
827
+	 * admin_footer_scripts_global
828
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
829
+	 * will apply on ALL EE_Admin pages.
830
+	 *
831
+	 * @access public
832
+	 * @return void
833
+	 */
834
+	public function admin_footer_scripts_global()
835
+	{
836
+		$this->_add_admin_page_ajax_loading_img();
837
+		$this->_add_admin_page_overlay();
838
+	}
839
+
840
+
841
+
842
+	/**
843
+	 * add in any global scripts for cpt routes
844
+	 *
845
+	 * @return void
846
+	 */
847
+	public function load_global_scripts_styles()
848
+	{
849
+		parent::load_global_scripts_styles();
850
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
851
+			//setup custom post status object for localize script but only if we've got a cpt object
852
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
853
+			if ( ! empty($statuses)) {
854
+				//get ALL statuses!
855
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
856
+				//setup object
857
+				$ee_cpt_statuses = array();
858
+				foreach ($statuses as $status => $label) {
859
+					$ee_cpt_statuses[$status] = array(
860
+						'label'      => $label,
861
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
862
+					);
863
+				}
864
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
865
+			}
866
+		}
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
873
+	 * insert/updates
874
+	 *
875
+	 * @param  int     $post_id ID of post being updated
876
+	 * @param  WP_Post $post    Post object from WP
877
+	 * @param  bool    $update  Whether this is an update or a new save.
878
+	 * @return void
879
+	 */
880
+	public function insert_update($post_id, $post, $update)
881
+	{
882
+		//make sure that if this is a revision OR trash action that we don't do any updates!
883
+		if (
884
+			isset($this->_req_data['action'])
885
+			&& (
886
+				$this->_req_data['action'] == 'restore'
887
+				|| $this->_req_data['action'] == 'trash'
888
+			)
889
+		) {
890
+			return;
891
+		}
892
+		$this->_set_model_object($post_id, true);
893
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
894
+		if ($update
895
+			&& (
896
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
897
+				|| $this->_cpt_model_obj->ID() !== $post_id
898
+			)
899
+		) {
900
+			return;
901
+		}
902
+		//check for autosave and update our req_data property accordingly.
903
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
904 904
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
905 905
 
906 906
                 foreach ( (array) $values as $key => $value ) {
@@ -910,536 +910,536 @@  discard block
 block discarded – undo
910 910
 
911 911
         }/**/ //TODO reactivate after autosave is implemented in 4.2
912 912
 
913
-        //take care of updating any selected page_template IF this cpt supports it.
914
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
915
-            //wp version aware.
916
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
917
-                $page_templates = wp_get_theme()->get_page_templates();
918
-            } else {
919
-                $post->page_template = $this->_req_data['page_template'];
920
-                $page_templates      = wp_get_theme()->get_page_templates($post);
921
-            }
922
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
923
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
924
-            } else {
925
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
926
-            }
927
-        }
928
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
929
-            return;
930
-        } //TODO we'll remove this after reimplementing autosave in 4.2
931
-        $this->_insert_update_cpt_item($post_id, $post);
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
938
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
939
-     * so we don't have to check for our CPT.
940
-     *
941
-     * @param  int $post_id ID of the post
942
-     * @return void
943
-     */
944
-    public function dont_permanently_delete_ee_cpts($post_id)
945
-    {
946
-        //only do this if we're actually processing one of our CPTs
947
-        //if our cpt object isn't existent then get out immediately.
948
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
949
-            return;
950
-        }
951
-        delete_post_meta($post_id, '_wp_trash_meta_status');
952
-        delete_post_meta($post_id, '_wp_trash_meta_time');
953
-        //our cpts may have comments so let's take care of that too
954
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
955
-    }
956
-
957
-
958
-
959
-    /**
960
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
961
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
962
-     * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
963
-     *
964
-     * @param  int $post_id     ID of cpt item
965
-     * @param  int $revision_id ID of revision being restored
966
-     * @return void
967
-     */
968
-    public function restore_revision($post_id, $revision_id)
969
-    {
970
-        $this->_restore_cpt_item($post_id, $revision_id);
971
-        //global action
972
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973
-        //class specific action so you can limit hooking into a specific page.
974
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * @see restore_revision() for details
981
-     * @param  int $post_id     ID of cpt item
982
-     * @param  int $revision_id ID of revision for item
983
-     * @return void
984
-     */
985
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
986
-
987
-
988
-
989
-    /**
990
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
991
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
992
-     * To fix we have to reset the current_screen using the page_slug
993
-     * (which is identical - or should be - to our registered_post_type id.)
994
-     * Also, since the core WP file loads the admin_header.php for WP
995
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
996
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
997
-     *
998
-     * @return void
999
-     */
1000
-    public function modify_current_screen()
1001
-    {
1002
-        //ONLY do this if the current page_route IS a cpt route
1003
-        if ( ! $this->_cpt_route) {
1004
-            return;
1005
-        }
1006
-        //routing things REALLY early b/c this is a cpt admin page
1007
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1008
-        $this->_current_screen       = get_current_screen();
1009
-        $this->_current_screen->base = 'event-espresso';
1010
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1011
-        /*try {
913
+		//take care of updating any selected page_template IF this cpt supports it.
914
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
915
+			//wp version aware.
916
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
917
+				$page_templates = wp_get_theme()->get_page_templates();
918
+			} else {
919
+				$post->page_template = $this->_req_data['page_template'];
920
+				$page_templates      = wp_get_theme()->get_page_templates($post);
921
+			}
922
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
923
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
924
+			} else {
925
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
926
+			}
927
+		}
928
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
929
+			return;
930
+		} //TODO we'll remove this after reimplementing autosave in 4.2
931
+		$this->_insert_update_cpt_item($post_id, $post);
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
938
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
939
+	 * so we don't have to check for our CPT.
940
+	 *
941
+	 * @param  int $post_id ID of the post
942
+	 * @return void
943
+	 */
944
+	public function dont_permanently_delete_ee_cpts($post_id)
945
+	{
946
+		//only do this if we're actually processing one of our CPTs
947
+		//if our cpt object isn't existent then get out immediately.
948
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
949
+			return;
950
+		}
951
+		delete_post_meta($post_id, '_wp_trash_meta_status');
952
+		delete_post_meta($post_id, '_wp_trash_meta_time');
953
+		//our cpts may have comments so let's take care of that too
954
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
955
+	}
956
+
957
+
958
+
959
+	/**
960
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
961
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
962
+	 * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
963
+	 *
964
+	 * @param  int $post_id     ID of cpt item
965
+	 * @param  int $revision_id ID of revision being restored
966
+	 * @return void
967
+	 */
968
+	public function restore_revision($post_id, $revision_id)
969
+	{
970
+		$this->_restore_cpt_item($post_id, $revision_id);
971
+		//global action
972
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973
+		//class specific action so you can limit hooking into a specific page.
974
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * @see restore_revision() for details
981
+	 * @param  int $post_id     ID of cpt item
982
+	 * @param  int $revision_id ID of revision for item
983
+	 * @return void
984
+	 */
985
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
986
+
987
+
988
+
989
+	/**
990
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
991
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
992
+	 * To fix we have to reset the current_screen using the page_slug
993
+	 * (which is identical - or should be - to our registered_post_type id.)
994
+	 * Also, since the core WP file loads the admin_header.php for WP
995
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
996
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
997
+	 *
998
+	 * @return void
999
+	 */
1000
+	public function modify_current_screen()
1001
+	{
1002
+		//ONLY do this if the current page_route IS a cpt route
1003
+		if ( ! $this->_cpt_route) {
1004
+			return;
1005
+		}
1006
+		//routing things REALLY early b/c this is a cpt admin page
1007
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1008
+		$this->_current_screen       = get_current_screen();
1009
+		$this->_current_screen->base = 'event-espresso';
1010
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1011
+		/*try {
1012 1012
             $this->_route_admin_request();
1013 1013
         } catch ( EE_Error $e ) {
1014 1014
             $e->get_error();
1015 1015
         }/**/
1016
-    }
1017
-
1018
-
1019
-
1020
-    /**
1021
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1022
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1023
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1024
-     * default to be.
1025
-     *
1026
-     * @param string $title The new title (or existing if there is no editor_title defined)
1027
-     * @return string
1028
-     */
1029
-    public function add_custom_editor_default_title($title)
1030
-    {
1031
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1032
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1033
-            : $title;
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1040
-     *
1041
-     * @param string $shortlink   The already generated shortlink
1042
-     * @param int    $id          Post ID for this item
1043
-     * @param string $context     The context for the link
1044
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1045
-     * @return string
1046
-     */
1047
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1048
-    {
1049
-        if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050
-            $post = get_post($id);
1051
-            if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
-                $shortlink = home_url('?p=' . $post->ID);
1053
-            }
1054
-        }
1055
-        return $shortlink;
1056
-    }
1057
-
1058
-
1059
-
1060
-    /**
1061
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1062
-     * already run in modify_current_screen())
1063
-     *
1064
-     * @return void
1065
-     */
1066
-    public function route_admin_request()
1067
-    {
1068
-        if ($this->_cpt_route) {
1069
-            return;
1070
-        }
1071
-        try {
1072
-            $this->_route_admin_request();
1073
-        } catch (EE_Error $e) {
1074
-            $e->get_error();
1075
-        }
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1082
-     *
1083
-     * @return string html
1084
-     */
1085
-    public function cpt_post_form_hidden_input()
1086
-    {
1087
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1088
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089
-        echo '<div id="ee-cpt-hidden-inputs">';
1090
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1092
-        echo '</div>';
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1099
-     *
1100
-     * @param  string $location Original location url
1101
-     * @param  int    $status   Status for http header
1102
-     * @return string           new (or original) url to redirect to.
1103
-     */
1104
-    public function revision_redirect($location, $status)
1105
-    {
1106
-        //get revision
1107
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1108
-        //can't do anything without revision so let's get out if not present
1109
-        if (empty($rev_id)) {
1110
-            return $location;
1111
-        }
1112
-        //get rev_post_data
1113
-        $rev = get_post($rev_id);
1114
-        $admin_url = $this->_admin_base_url;
1115
-        $query_args = array(
1116
-            'action'   => 'edit',
1117
-            'post'     => $rev->post_parent,
1118
-            'revision' => $rev_id,
1119
-            'message'  => 5,
1120
-        );
1121
-        $this->_process_notices($query_args, true);
1122
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1129
-     *
1130
-     * @param  string $link    the original generated link
1131
-     * @param  int    $id      post id
1132
-     * @param  string $context optional, defaults to display.  How to write the '&'
1133
-     * @return string          the link
1134
-     */
1135
-    public function modify_edit_post_link($link, $id, $context)
1136
-    {
1137
-        $post = get_post($id);
1138
-        if ( ! isset($this->_req_data['action'])
1139
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1140
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1141
-        ) {
1142
-            return $link;
1143
-        }
1144
-        $query_args = array(
1145
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1146
-                ? $this->_cpt_edit_routes[$post->post_type]
1147
-                : 'edit',
1148
-            'post'   => $id,
1149
-        );
1150
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1157
-     * our routes.
1158
-     *
1159
-     * @param  string $delete_link  original delete link
1160
-     * @param  int    $post_id      id of cpt object
1161
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1162
-     * @return string               new delete link
1163
-     */
1164
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1165
-    {
1166
-        $post = get_post($post_id);
1167
-        if ( ! isset($this->_req_data['action'])
1168
-             || (isset($this->_cpt_routes[$this->_req_data['action']])
1169
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
-        ) {
1171
-            return $delete_link;
1172
-        }
1173
-        return add_query_arg(array('current_route' => 'trash'), $delete_link);
1174
-    }
1175
-
1176
-
1177
-
1178
-    /**
1179
-     * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1180
-     * route
1181
-     *
1182
-     * @param  string $location url
1183
-     * @param  string $status   status
1184
-     * @return string           url to redirect to
1185
-     */
1186
-    public function cpt_trash_post_location_redirect($location, $status)
1187
-    {
1188
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1189
-            return $location;
1190
-        }
1191
-
1192
-        $post              = get_post($this->_req_data['post']);
1193
-        $query_args        = array('action' => 'default');
1194
-        $this->_cpt_object = get_post_type_object($post->post_type);
1195
-        EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1196
-        $this->_process_notices($query_args, true);
1197
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1198
-    }
1199
-
1200
-
1201
-
1202
-    /**
1203
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1204
-     * so that we can hijack the default redirect locations for wp custom post types
1205
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1206
-     *
1207
-     * @param  string $location This is the incoming currently set redirect location
1208
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1209
-     * @return string           the new location to redirect to
1210
-     */
1211
-    public function cpt_post_location_redirect($location, $post_id)
1212
-    {
1213
-        //we DO have a match so let's setup the url
1214
-        //we have to get the post to determine our route
1215
-        $post       = get_post($post_id);
1216
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1217
-        //shared query_args
1218
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1219
-        $admin_url  = $this->_admin_base_url;
1220
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1221
-            $status = get_post_status($post_id);
1222
-            if (isset($this->_req_data['publish'])) {
1223
-                switch ($status) {
1224
-                    case 'pending':
1225
-                        $message = 8;
1226
-                        break;
1227
-                    case 'future':
1228
-                        $message = 9;
1229
-                        break;
1230
-                    default:
1231
-                        $message = 6;
1232
-                }
1233
-            } else {
1234
-                $message = 'draft' == $status ? 10 : 1;
1235
-            }
1236
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1237
-            $message = 2;
1238
-            //			$append = '#postcustom';
1239
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1240
-            $message = 3;
1241
-            //			$append = '#postcustom';
1242
-        } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1243
-            $message = 7;
1244
-        } else {
1245
-            $message = 4;
1246
-        }
1247
-        //change the message if the post type is not viewable on the frontend
1248
-        $this->_cpt_object = get_post_type_object($post->post_type);
1249
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1250
-        $query_args = array_merge(array('message' => $message), $query_args);
1251
-        $this->_process_notices($query_args, true);
1252
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1253
-    }
1254
-
1255
-
1256
-
1257
-    /**
1258
-     * This method is called to inject nav tabs on core WP cpt pages
1259
-     *
1260
-     * @access public
1261
-     * @return string html
1262
-     */
1263
-    public function inject_nav_tabs()
1264
-    {
1265
-        //can we hijack and insert the nav_tabs?
1266
-        $nav_tabs = $this->_get_main_nav_tabs();
1267
-        //first close off existing form tag
1268
-        $html = '>';
1269
-        $html .= $nav_tabs;
1270
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1271
-        $html .= '<span></span';
1272
-        echo $html;
1273
-    }
1274
-
1275
-
1276
-
1277
-    /**
1278
-     * This just sets up the post update messages when an update form is loaded
1279
-     *
1280
-     * @access public
1281
-     * @param  array $messages the original messages array
1282
-     * @return array           the new messages array
1283
-     */
1284
-    public function post_update_messages($messages)
1285
-    {
1286
-        global $post;
1287
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1288
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1289
-        //		$post_type = $post ? $post->post_type : false;
1290
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1016
+	}
1017
+
1018
+
1019
+
1020
+	/**
1021
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1022
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1023
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1024
+	 * default to be.
1025
+	 *
1026
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1027
+	 * @return string
1028
+	 */
1029
+	public function add_custom_editor_default_title($title)
1030
+	{
1031
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1032
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1033
+			: $title;
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1040
+	 *
1041
+	 * @param string $shortlink   The already generated shortlink
1042
+	 * @param int    $id          Post ID for this item
1043
+	 * @param string $context     The context for the link
1044
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1045
+	 * @return string
1046
+	 */
1047
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1048
+	{
1049
+		if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050
+			$post = get_post($id);
1051
+			if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
+				$shortlink = home_url('?p=' . $post->ID);
1053
+			}
1054
+		}
1055
+		return $shortlink;
1056
+	}
1057
+
1058
+
1059
+
1060
+	/**
1061
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1062
+	 * already run in modify_current_screen())
1063
+	 *
1064
+	 * @return void
1065
+	 */
1066
+	public function route_admin_request()
1067
+	{
1068
+		if ($this->_cpt_route) {
1069
+			return;
1070
+		}
1071
+		try {
1072
+			$this->_route_admin_request();
1073
+		} catch (EE_Error $e) {
1074
+			$e->get_error();
1075
+		}
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1082
+	 *
1083
+	 * @return string html
1084
+	 */
1085
+	public function cpt_post_form_hidden_input()
1086
+	{
1087
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1088
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089
+		echo '<div id="ee-cpt-hidden-inputs">';
1090
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1092
+		echo '</div>';
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1099
+	 *
1100
+	 * @param  string $location Original location url
1101
+	 * @param  int    $status   Status for http header
1102
+	 * @return string           new (or original) url to redirect to.
1103
+	 */
1104
+	public function revision_redirect($location, $status)
1105
+	{
1106
+		//get revision
1107
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1108
+		//can't do anything without revision so let's get out if not present
1109
+		if (empty($rev_id)) {
1110
+			return $location;
1111
+		}
1112
+		//get rev_post_data
1113
+		$rev = get_post($rev_id);
1114
+		$admin_url = $this->_admin_base_url;
1115
+		$query_args = array(
1116
+			'action'   => 'edit',
1117
+			'post'     => $rev->post_parent,
1118
+			'revision' => $rev_id,
1119
+			'message'  => 5,
1120
+		);
1121
+		$this->_process_notices($query_args, true);
1122
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1129
+	 *
1130
+	 * @param  string $link    the original generated link
1131
+	 * @param  int    $id      post id
1132
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1133
+	 * @return string          the link
1134
+	 */
1135
+	public function modify_edit_post_link($link, $id, $context)
1136
+	{
1137
+		$post = get_post($id);
1138
+		if ( ! isset($this->_req_data['action'])
1139
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1140
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1141
+		) {
1142
+			return $link;
1143
+		}
1144
+		$query_args = array(
1145
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1146
+				? $this->_cpt_edit_routes[$post->post_type]
1147
+				: 'edit',
1148
+			'post'   => $id,
1149
+		);
1150
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1157
+	 * our routes.
1158
+	 *
1159
+	 * @param  string $delete_link  original delete link
1160
+	 * @param  int    $post_id      id of cpt object
1161
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1162
+	 * @return string               new delete link
1163
+	 */
1164
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1165
+	{
1166
+		$post = get_post($post_id);
1167
+		if ( ! isset($this->_req_data['action'])
1168
+			 || (isset($this->_cpt_routes[$this->_req_data['action']])
1169
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
+		) {
1171
+			return $delete_link;
1172
+		}
1173
+		return add_query_arg(array('current_route' => 'trash'), $delete_link);
1174
+	}
1175
+
1176
+
1177
+
1178
+	/**
1179
+	 * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1180
+	 * route
1181
+	 *
1182
+	 * @param  string $location url
1183
+	 * @param  string $status   status
1184
+	 * @return string           url to redirect to
1185
+	 */
1186
+	public function cpt_trash_post_location_redirect($location, $status)
1187
+	{
1188
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1189
+			return $location;
1190
+		}
1191
+
1192
+		$post              = get_post($this->_req_data['post']);
1193
+		$query_args        = array('action' => 'default');
1194
+		$this->_cpt_object = get_post_type_object($post->post_type);
1195
+		EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1196
+		$this->_process_notices($query_args, true);
1197
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1198
+	}
1199
+
1200
+
1201
+
1202
+	/**
1203
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1204
+	 * so that we can hijack the default redirect locations for wp custom post types
1205
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1206
+	 *
1207
+	 * @param  string $location This is the incoming currently set redirect location
1208
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1209
+	 * @return string           the new location to redirect to
1210
+	 */
1211
+	public function cpt_post_location_redirect($location, $post_id)
1212
+	{
1213
+		//we DO have a match so let's setup the url
1214
+		//we have to get the post to determine our route
1215
+		$post       = get_post($post_id);
1216
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1217
+		//shared query_args
1218
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1219
+		$admin_url  = $this->_admin_base_url;
1220
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1221
+			$status = get_post_status($post_id);
1222
+			if (isset($this->_req_data['publish'])) {
1223
+				switch ($status) {
1224
+					case 'pending':
1225
+						$message = 8;
1226
+						break;
1227
+					case 'future':
1228
+						$message = 9;
1229
+						break;
1230
+					default:
1231
+						$message = 6;
1232
+				}
1233
+			} else {
1234
+				$message = 'draft' == $status ? 10 : 1;
1235
+			}
1236
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1237
+			$message = 2;
1238
+			//			$append = '#postcustom';
1239
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1240
+			$message = 3;
1241
+			//			$append = '#postcustom';
1242
+		} elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1243
+			$message = 7;
1244
+		} else {
1245
+			$message = 4;
1246
+		}
1247
+		//change the message if the post type is not viewable on the frontend
1248
+		$this->_cpt_object = get_post_type_object($post->post_type);
1249
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1250
+		$query_args = array_merge(array('message' => $message), $query_args);
1251
+		$this->_process_notices($query_args, true);
1252
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1253
+	}
1254
+
1255
+
1256
+
1257
+	/**
1258
+	 * This method is called to inject nav tabs on core WP cpt pages
1259
+	 *
1260
+	 * @access public
1261
+	 * @return string html
1262
+	 */
1263
+	public function inject_nav_tabs()
1264
+	{
1265
+		//can we hijack and insert the nav_tabs?
1266
+		$nav_tabs = $this->_get_main_nav_tabs();
1267
+		//first close off existing form tag
1268
+		$html = '>';
1269
+		$html .= $nav_tabs;
1270
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1271
+		$html .= '<span></span';
1272
+		echo $html;
1273
+	}
1274
+
1275
+
1276
+
1277
+	/**
1278
+	 * This just sets up the post update messages when an update form is loaded
1279
+	 *
1280
+	 * @access public
1281
+	 * @param  array $messages the original messages array
1282
+	 * @return array           the new messages array
1283
+	 */
1284
+	public function post_update_messages($messages)
1285
+	{
1286
+		global $post;
1287
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1288
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1289
+		//		$post_type = $post ? $post->post_type : false;
1290
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1291 1291
 
1292 1292
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1293
-        $messages[$post->post_type] = array(
1294
-            0 => '', //Unused. Messages start at index 1.
1295
-            1 => sprintf(
1296
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297
-                $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1299
-                '</a>'
1300
-            ),
1301
-            2 => __('Custom field updated'),
1302
-            3 => __('Custom field deleted.'),
1303
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1306
-                : false,
1307
-            6 => sprintf(
1308
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309
-                $this->_cpt_object->labels->singular_name,
1310
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1311
-                '</a>'
1312
-            ),
1313
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314
-            8 => sprintf(
1315
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316
-                $this->_cpt_object->labels->singular_name,
1317
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1318
-                '</a>'
1319
-            ),
1320
-            9 => sprintf(
1321
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322
-                $this->_cpt_object->labels->singular_name,
1323
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1325
-                '</a>'
1326
-            ),
1327
-            10 => sprintf(
1328
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329
-                $this->_cpt_object->labels->singular_name,
1330
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331
-                '</a>'
1332
-            ),
1333
-        );
1334
-        return $messages;
1335
-    }
1336
-
1337
-
1338
-
1339
-    /**
1340
-     * default method for the 'create_new' route for cpt admin pages.
1341
-     * For reference what to include in here, see wp-admin/post-new.php
1342
-     *
1343
-     * @access  protected
1344
-     * @return string template for add new cpt form
1345
-     */
1346
-    protected function _create_new_cpt_item()
1347
-    {
1348
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1349
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1350
-        $post_type_object = $this->_cpt_object;
1351
-        $title            = $post_type_object->labels->add_new_item;
1352
-        $editing          = true;
1353
-        wp_enqueue_script('autosave');
1354
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1355
-        $post_ID = $post->ID;
1356
-        $is_IE   = $is_IE;
1357
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358
-        //modify the default editor title field with default title.
1359
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1361
-    }
1362
-
1363
-
1364
-
1365
-    public function add_new_admin_page_global()
1366
-    {
1367
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1368
-        ?>
1293
+		$messages[$post->post_type] = array(
1294
+			0 => '', //Unused. Messages start at index 1.
1295
+			1 => sprintf(
1296
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297
+				$this->_cpt_object->labels->singular_name,
1298
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1299
+				'</a>'
1300
+			),
1301
+			2 => __('Custom field updated'),
1302
+			3 => __('Custom field deleted.'),
1303
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1306
+				: false,
1307
+			6 => sprintf(
1308
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309
+				$this->_cpt_object->labels->singular_name,
1310
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1311
+				'</a>'
1312
+			),
1313
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314
+			8 => sprintf(
1315
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316
+				$this->_cpt_object->labels->singular_name,
1317
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1318
+				'</a>'
1319
+			),
1320
+			9 => sprintf(
1321
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322
+				$this->_cpt_object->labels->singular_name,
1323
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1325
+				'</a>'
1326
+			),
1327
+			10 => sprintf(
1328
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329
+				$this->_cpt_object->labels->singular_name,
1330
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331
+				'</a>'
1332
+			),
1333
+		);
1334
+		return $messages;
1335
+	}
1336
+
1337
+
1338
+
1339
+	/**
1340
+	 * default method for the 'create_new' route for cpt admin pages.
1341
+	 * For reference what to include in here, see wp-admin/post-new.php
1342
+	 *
1343
+	 * @access  protected
1344
+	 * @return string template for add new cpt form
1345
+	 */
1346
+	protected function _create_new_cpt_item()
1347
+	{
1348
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1349
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1350
+		$post_type_object = $this->_cpt_object;
1351
+		$title            = $post_type_object->labels->add_new_item;
1352
+		$editing          = true;
1353
+		wp_enqueue_script('autosave');
1354
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1355
+		$post_ID = $post->ID;
1356
+		$is_IE   = $is_IE;
1357
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358
+		//modify the default editor title field with default title.
1359
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1361
+	}
1362
+
1363
+
1364
+
1365
+	public function add_new_admin_page_global()
1366
+	{
1367
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1368
+		?>
1369 1369
         <script type="text/javascript">
1370 1370
             adminpage = '<?php echo $admin_page; ?>';
1371 1371
         </script>
1372 1372
         <?php
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * default method for the 'edit' route for cpt admin pages
1379
-     * For reference on what to put in here, refer to wp-admin/post.php
1380
-     *
1381
-     * @access protected
1382
-     * @return string   template for edit cpt form
1383
-     */
1384
-    protected function _edit_cpt_item()
1385
-    {
1386
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1387
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1388
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1389
-        if (empty ($post)) {
1390
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1391
-        }
1392
-        if ( ! empty($_GET['get-post-lock'])) {
1393
-            wp_set_post_lock($post_id);
1394
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1395
-            exit();
1396
-        }
1397
-
1398
-        // template vars
1399
-        $editing          = true;
1400
-        $post_ID          = $post_id;
1401
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1402
-        $post_type_object = $this->_cpt_object;
1403
-
1404
-        if ( ! wp_check_post_lock($post->ID)) {
1405
-            $active_post_lock = wp_set_post_lock($post->ID);
1406
-            //wp_enqueue_script('autosave');
1407
-        }
1408
-        $title = $this->_cpt_object->labels->edit_item;
1409
-        add_action('admin_footer', '_admin_notice_post_locked');
1410
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1411
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1412
-        ) {
1413
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1414
-                'create_new', $this);
1415
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1416
-                'action' => $create_new_action,
1417
-                'page'   => $this->page_slug,
1418
-            ), 'admin.php');
1419
-        }
1420
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1421
-            wp_enqueue_script('admin-comments');
1422
-            enqueue_comment_hotkeys_js();
1423
-        }
1424
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425
-        //modify the default editor title field with default title.
1426
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1428
-    }
1429
-
1430
-
1431
-
1432
-    /**
1433
-     * some getters
1434
-     */
1435
-    /**
1436
-     * This returns the protected _cpt_model_obj property
1437
-     *
1438
-     * @return EE_CPT_Base
1439
-     */
1440
-    public function get_cpt_model_obj()
1441
-    {
1442
-        return $this->_cpt_model_obj;
1443
-    }
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * default method for the 'edit' route for cpt admin pages
1379
+	 * For reference on what to put in here, refer to wp-admin/post.php
1380
+	 *
1381
+	 * @access protected
1382
+	 * @return string   template for edit cpt form
1383
+	 */
1384
+	protected function _edit_cpt_item()
1385
+	{
1386
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1387
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1388
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1389
+		if (empty ($post)) {
1390
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1391
+		}
1392
+		if ( ! empty($_GET['get-post-lock'])) {
1393
+			wp_set_post_lock($post_id);
1394
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1395
+			exit();
1396
+		}
1397
+
1398
+		// template vars
1399
+		$editing          = true;
1400
+		$post_ID          = $post_id;
1401
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1402
+		$post_type_object = $this->_cpt_object;
1403
+
1404
+		if ( ! wp_check_post_lock($post->ID)) {
1405
+			$active_post_lock = wp_set_post_lock($post->ID);
1406
+			//wp_enqueue_script('autosave');
1407
+		}
1408
+		$title = $this->_cpt_object->labels->edit_item;
1409
+		add_action('admin_footer', '_admin_notice_post_locked');
1410
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1411
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1412
+		) {
1413
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1414
+				'create_new', $this);
1415
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1416
+				'action' => $create_new_action,
1417
+				'page'   => $this->page_slug,
1418
+			), 'admin.php');
1419
+		}
1420
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1421
+			wp_enqueue_script('admin-comments');
1422
+			enqueue_comment_hotkeys_js();
1423
+		}
1424
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425
+		//modify the default editor title field with default title.
1426
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1428
+	}
1429
+
1430
+
1431
+
1432
+	/**
1433
+	 * some getters
1434
+	 */
1435
+	/**
1436
+	 * This returns the protected _cpt_model_obj property
1437
+	 *
1438
+	 * @return EE_CPT_Base
1439
+	 */
1440
+	public function get_cpt_model_obj()
1441
+	{
1442
+		return $this->_cpt_model_obj;
1443
+	}
1444 1444
 
1445 1445
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         //filter _autosave_containers
280 280
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281 281
             $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
282
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
283 283
             $containers, $this);
284 284
 
285 285
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         parent::_load_page_dependencies();
370 370
         //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371 371
         global $pagenow;
372
-        do_action('load-' . $pagenow);
372
+        do_action('load-'.$pagenow);
373 373
         $this->modify_current_screen();
374 374
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375 375
         //we route REALLY early.
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
                 'admin.php?page=espresso_registrations&action=contact_list',
401 401
             ),
402 402
             1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
403
+                'edit.php?post_type='.$this->_cpt_object->name,
404
+                'admin.php?page='.$this->_cpt_object->name,
405 405
             ),
406 406
         );
407 407
         foreach ($routes_to_match as $route_matches) {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $cpt_has_support = ! empty($cpt_args['page_templates']);
430 430
 
431 431
         //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
432
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
433 433
             $post_templates = wp_get_theme()->get_post_templates();
434 434
             //if there are $post_templates for this cpt, then we return false for this method because
435 435
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         global $post;
453 453
         $template = '';
454 454
 
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
455
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
456 456
             $page_template_count = count(get_page_templates());
457 457
         } else {
458 458
             $page_template_count = count(get_page_templates($post));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $post = get_post($id);
490 490
         if ('publish' != get_post_status($post)) {
491 491
             //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
492
+            require_once(EE_CORE.'wordpress-shims.php');
493 493
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494 494
                        . get_preview_post_link($id)
495 495
                        . '" class="button button-small">'
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $template_args['statuses']         = $statuses;
528 528
         }
529 529
 
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
530
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
531 531
         EEH_Template::display_template($template, $template_args);
532 532
     }
533 533
 
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
             define('DOING_AUTOSAVE', true);
573 573
         }
574 574
         //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
575
+        if (method_exists($this, '_ee_autosave_'.$this->_current_view)) {
576
+            call_user_func(array($this, '_ee_autosave_'.$this->_current_view));
577 577
         } else {
578 578
             $this->_template_args['success'] = true;
579 579
         }
580 580
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
581
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
582 582
         //now let's return json
583 583
         $this->_return_json();
584 584
     }
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
         //global action
972 972
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973 973
         //class specific action so you can limit hooking into a specific page.
974
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
974
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
975 975
     }
976 976
 
977 977
 
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
         if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050 1050
             $post = get_post($id);
1051 1051
             if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
-                $shortlink = home_url('?p=' . $post->ID);
1052
+                $shortlink = home_url('?p='.$post->ID);
1053 1053
             }
1054 1054
         }
1055 1055
         return $shortlink;
@@ -1084,11 +1084,11 @@  discard block
 block discarded – undo
1084 1084
      */
1085 1085
     public function cpt_post_form_hidden_input()
1086 1086
     {
1087
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1087
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1088 1088
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089 1089
         echo '<div id="ee-cpt-hidden-inputs">';
1090
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1091
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1092 1092
         echo '</div>';
1093 1093
     }
1094 1094
 
@@ -1295,39 +1295,39 @@  discard block
 block discarded – undo
1295 1295
             1 => sprintf(
1296 1296
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297 1297
                 $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1298
+                '<a href="'.esc_url(get_permalink($id)).'">',
1299 1299
                 '</a>'
1300 1300
             ),
1301 1301
             2 => __('Custom field updated'),
1302 1302
             3 => __('Custom field deleted.'),
1303 1303
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304 1304
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1305
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1306 1306
                 : false,
1307 1307
             6 => sprintf(
1308 1308
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309 1309
                 $this->_cpt_object->labels->singular_name,
1310
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1310
+                '<a href="'.esc_url(get_permalink($id)).'">',
1311 1311
                 '</a>'
1312 1312
             ),
1313 1313
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314 1314
             8 => sprintf(
1315 1315
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316 1316
                 $this->_cpt_object->labels->singular_name,
1317
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1317
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1318 1318
                 '</a>'
1319 1319
             ),
1320 1320
             9 => sprintf(
1321 1321
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322 1322
                 $this->_cpt_object->labels->singular_name,
1323
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1323
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1324
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1325 1325
                 '</a>'
1326 1326
             ),
1327 1327
             10 => sprintf(
1328 1328
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329 1329
                 $this->_cpt_object->labels->singular_name,
1330
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1330
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331 1331
                 '</a>'
1332 1332
             ),
1333 1333
         );
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358 1358
         //modify the default editor title field with default title.
1359 1359
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1360
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1361 1361
     }
1362 1362
 
1363 1363
 
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425 1425
         //modify the default editor title field with default title.
1426 1426
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1427
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1428 1428
     }
1429 1429
 
1430 1430
 
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1423 added lines, -1423 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,1428 +16,1428 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
21
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
22
-     */
23
-    const req_type_normal = 0;
24
-
25
-    /**
26
-     * Indicates this is a brand new installation of EE so we should install
27
-     * tables and default data etc
28
-     */
29
-    const req_type_new_activation = 1;
30
-
31
-    /**
32
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
33
-     * and we just exited maintenance mode). We MUST check the database is setup properly
34
-     * and that default data is setup too
35
-     */
36
-    const req_type_reactivation = 2;
37
-
38
-    /**
39
-     * indicates that EE has been upgraded since its previous request.
40
-     * We may have data migration scripts to call and will want to trigger maintenance mode
41
-     */
42
-    const req_type_upgrade = 3;
43
-
44
-    /**
45
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
46
-     */
47
-    const req_type_downgrade = 4;
48
-
49
-    /**
50
-     * @deprecated since version 4.6.0.dev.006
51
-     * Now whenever a new_activation is detected the request type is still just
52
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
53
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
54
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
55
-     * (Specifically, when the migration manager indicates migrations are finished
56
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
57
-     */
58
-    const req_type_activation_but_not_installed = 5;
59
-
60
-    /**
61
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
62
-     */
63
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
64
-
65
-
66
-    /**
67
-     *    instance of the EE_System object
68
-     *
69
-     * @var    $_instance
70
-     * @access    private
71
-     */
72
-    private static $_instance = null;
73
-
74
-    /**
75
-     * @type  EE_Registry $Registry
76
-     * @access    protected
77
-     */
78
-    protected $registry;
79
-
80
-    /**
81
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
82
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
83
-     *
84
-     * @var int
85
-     */
86
-    private $_req_type;
87
-
88
-    /**
89
-     * Whether or not there was a non-micro version change in EE core version during this request
90
-     *
91
-     * @var boolean
92
-     */
93
-    private $_major_version_change = false;
94
-
95
-
96
-
97
-    /**
98
-     * @singleton method used to instantiate class object
99
-     * @access    public
100
-     * @param  \EE_Registry $Registry
101
-     * @return \EE_System
102
-     */
103
-    public static function instance(EE_Registry $Registry = null)
104
-    {
105
-        // check if class object is instantiated
106
-        if ( ! self::$_instance instanceof EE_System) {
107
-            self::$_instance = new self($Registry);
108
-        }
109
-        return self::$_instance;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * resets the instance and returns it
116
-     *
117
-     * @return EE_System
118
-     */
119
-    public static function reset()
120
-    {
121
-        self::$_instance->_req_type = null;
122
-        //make sure none of the old hooks are left hanging around
123
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
124
-        //we need to reset the migration manager in order for it to detect DMSs properly
125
-        EE_Data_Migration_Manager::reset();
126
-        self::instance()->detect_activations_or_upgrades();
127
-        self::instance()->perform_activations_upgrades_and_migrations();
128
-        return self::instance();
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     *    sets hooks for running rest of system
135
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
136
-     *    starting EE Addons from any other point may lead to problems
137
-     *
138
-     * @access private
139
-     * @param  \EE_Registry $Registry
140
-     */
141
-    private function __construct(EE_Registry $Registry)
142
-    {
143
-        $this->registry = $Registry;
144
-        do_action('AHEE__EE_System__construct__begin', $this);
145
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
146
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
147
-        // when an ee addon is activated, we want to call the core hook(s) again
148
-        // because the newly-activated addon didn't get a chance to run at all
149
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
150
-        // detect whether install or upgrade
151
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
152
-            3);
153
-        // load EE_Config, EE_Textdomain, etc
154
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
155
-        // load EE_Config, EE_Textdomain, etc
156
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
157
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
158
-        // you wanna get going? I wanna get going... let's get going!
159
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
160
-        //other housekeeping
161
-        //exclude EE critical pages from wp_list_pages
162
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
163
-        // ALL EE Addons should use the following hook point to attach their initial setup too
164
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
165
-        do_action('AHEE__EE_System__construct__complete', $this);
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * load_espresso_addons
172
-     * allow addons to load first so that they can set hooks for running DMS's, etc
173
-     * this is hooked into both:
174
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
175
-     *        which runs during the WP 'plugins_loaded' action at priority 5
176
-     *    and the WP 'activate_plugin' hookpoint
177
-     *
178
-     * @access public
179
-     * @return void
180
-     */
181
-    public function load_espresso_addons()
182
-    {
183
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
184
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
185
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
186
-        //load and setup EE_Capabilities
187
-        $this->registry->load_core('Capabilities');
188
-        //caps need to be initialized on every request so that capability maps are set.
189
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
190
-        $this->registry->CAP->init_caps();
191
-        do_action('AHEE__EE_System__load_espresso_addons');
192
-        //if the WP API basic auth plugin isn't already loaded, load it now.
193
-        //We want it for mobile apps. Just include the entire plugin
194
-        //also, don't load the basic auth when a plugin is getting activated, because
195
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
196
-        //and causes a fatal error
197
-        if ( ! function_exists('json_basic_auth_handler')
198
-             && ! function_exists('json_basic_auth_error')
199
-             && ! (
200
-                isset($_GET['action'])
201
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
202
-            )
203
-             && ! (
204
-                isset($_GET['activate'])
205
-                && $_GET['activate'] === 'true'
206
-            )
207
-        ) {
208
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
209
-        }
210
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * detect_activations_or_upgrades
217
-     * Checks for activation or upgrade of core first;
218
-     * then also checks if any registered addons have been activated or upgraded
219
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
220
-     * which runs during the WP 'plugins_loaded' action at priority 3
221
-     *
222
-     * @access public
223
-     * @return void
224
-     */
225
-    public function detect_activations_or_upgrades()
226
-    {
227
-        //first off: let's make sure to handle core
228
-        $this->detect_if_activation_or_upgrade();
229
-        foreach ($this->registry->addons as $addon) {
230
-            //detect teh request type for that addon
231
-            $addon->detect_activation_or_upgrade();
232
-        }
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * detect_if_activation_or_upgrade
239
-     * Takes care of detecting whether this is a brand new install or code upgrade,
240
-     * and either setting up the DB or setting up maintenance mode etc.
241
-     *
242
-     * @access public
243
-     * @return void
244
-     */
245
-    public function detect_if_activation_or_upgrade()
246
-    {
247
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
248
-        // load M-Mode class
249
-        $this->registry->load_core('Maintenance_Mode');
250
-        // check if db has been updated, or if its a brand-new installation
251
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
252
-        $request_type = $this->detect_req_type($espresso_db_update);
253
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
254
-        switch ($request_type) {
255
-            case EE_System::req_type_new_activation:
256
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
257
-                $this->_handle_core_version_change($espresso_db_update);
258
-                break;
259
-            case EE_System::req_type_reactivation:
260
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
261
-                $this->_handle_core_version_change($espresso_db_update);
262
-                break;
263
-            case EE_System::req_type_upgrade:
264
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
265
-                //migrations may be required now that we've upgraded
266
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
267
-                $this->_handle_core_version_change($espresso_db_update);
268
-                //				echo "done upgrade";die;
269
-                break;
270
-            case EE_System::req_type_downgrade:
271
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
272
-                //its possible migrations are no longer required
273
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
274
-                $this->_handle_core_version_change($espresso_db_update);
275
-                break;
276
-            case EE_System::req_type_normal:
277
-            default:
278
-                //				$this->_maybe_redirect_to_ee_about();
279
-                break;
280
-        }
281
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * Updates the list of installed versions and sets hooks for
288
-     * initializing the database later during the request
289
-     *
290
-     * @param array $espresso_db_update
291
-     */
292
-    protected function _handle_core_version_change($espresso_db_update)
293
-    {
294
-        $this->update_list_of_installed_versions($espresso_db_update);
295
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
296
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
297
-            array($this, 'initialize_db_if_no_migrations_required'));
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
304
-     * information about what versions of EE have been installed and activated,
305
-     * NOT necessarily the state of the database
306
-     *
307
-     * @param null $espresso_db_update
308
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
309
-     *           from the options table
310
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
311
-     */
312
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
313
-    {
314
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
315
-        if ( ! $espresso_db_update) {
316
-            $espresso_db_update = get_option('espresso_db_update');
317
-        }
318
-        // check that option is an array
319
-        if ( ! is_array($espresso_db_update)) {
320
-            // if option is FALSE, then it never existed
321
-            if ($espresso_db_update === false) {
322
-                // make $espresso_db_update an array and save option with autoload OFF
323
-                $espresso_db_update = array();
324
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
325
-            } else {
326
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
327
-                $espresso_db_update = array($espresso_db_update => array());
328
-                update_option('espresso_db_update', $espresso_db_update);
329
-            }
330
-        } else {
331
-            $corrected_db_update = array();
332
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
333
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
334
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
335
-                    //the key is an int, and the value IS NOT an array
336
-                    //so it must be numerically-indexed, where values are versions installed...
337
-                    //fix it!
338
-                    $version_string = $should_be_array;
339
-                    $corrected_db_update[$version_string] = array('unknown-date');
340
-                } else {
341
-                    //ok it checks out
342
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
343
-                }
344
-            }
345
-            $espresso_db_update = $corrected_db_update;
346
-            update_option('espresso_db_update', $espresso_db_update);
347
-        }
348
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
349
-        return $espresso_db_update;
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Does the traditional work of setting up the plugin's database and adding default data.
356
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
357
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
358
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
359
-     * so that it will be done when migrations are finished
360
-     *
361
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
362
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
363
-     *                                       This is a resource-intensive job
364
-     *                                       so we prefer to only do it when necessary
365
-     * @return void
366
-     */
367
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
368
-    {
369
-        $request_type = $this->detect_req_type();
370
-        //only initialize system if we're not in maintenance mode.
371
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
372
-            update_option('ee_flush_rewrite_rules', true);
373
-            if ($verify_schema) {
374
-                EEH_Activation::initialize_db_and_folders();
375
-            }
376
-            EEH_Activation::initialize_db_content();
377
-            EEH_Activation::system_initialization();
378
-            if ($initialize_addons_too) {
379
-                $this->initialize_addons();
380
-            }
381
-        } else {
382
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
383
-        }
384
-        if ($request_type === EE_System::req_type_new_activation
385
-            || $request_type === EE_System::req_type_reactivation
386
-            || (
387
-                $request_type === EE_System::req_type_upgrade
388
-                && $this->is_major_version_change()
389
-            )
390
-        ) {
391
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
392
-        }
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * Initializes the db for all registered addons
399
-     */
400
-    public function initialize_addons()
401
-    {
402
-        //foreach registered addon, make sure its db is up-to-date too
403
-        foreach ($this->registry->addons as $addon) {
404
-            $addon->initialize_db_if_no_migrations_required();
405
-        }
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
412
-     *
413
-     * @param    array  $version_history
414
-     * @param    string $current_version_to_add version to be added to the version history
415
-     * @return    boolean success as to whether or not this option was changed
416
-     */
417
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
418
-    {
419
-        if ( ! $version_history) {
420
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
421
-        }
422
-        if ($current_version_to_add == null) {
423
-            $current_version_to_add = espresso_version();
424
-        }
425
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
426
-        // re-save
427
-        return update_option('espresso_db_update', $version_history);
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * Detects if the current version indicated in the has existed in the list of
434
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
435
-     *
436
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
437
-     *                                  If not supplied, fetches it from the options table.
438
-     *                                  Also, caches its result so later parts of the code can also know whether
439
-     *                                  there's been an update or not. This way we can add the current version to
440
-     *                                  espresso_db_update, but still know if this is a new install or not
441
-     * @return int one of the constants on EE_System::req_type_
442
-     */
443
-    public function detect_req_type($espresso_db_update = null)
444
-    {
445
-        if ($this->_req_type === null) {
446
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
447
-                : $this->fix_espresso_db_upgrade_option();
448
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
449
-                'ee_espresso_activation', espresso_version());
450
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
451
-        }
452
-        return $this->_req_type;
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     * Returns whether or not there was a non-micro version change (ie, change in either
459
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
460
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
461
-     *
462
-     * @param $activation_history
463
-     * @return bool
464
-     */
465
-    protected function _detect_major_version_change($activation_history)
466
-    {
467
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
468
-        $previous_version_parts = explode('.', $previous_version);
469
-        $current_version_parts = explode('.', espresso_version());
470
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
471
-               && ($previous_version_parts[0] !== $current_version_parts[0]
472
-                   || $previous_version_parts[1] !== $current_version_parts[1]
473
-               );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * Returns true if either the major or minor version of EE changed during this request.
480
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
481
-     *
482
-     * @return bool
483
-     */
484
-    public function is_major_version_change()
485
-    {
486
-        return $this->_major_version_change;
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
493
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
494
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
495
-     * just activated to (for core that will always be espresso_version())
496
-     *
497
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
498
-     *                                                 ee plugin. for core that's 'espresso_db_update'
499
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
500
-     *                                                 indicate that this plugin was just activated
501
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
502
-     *                                                 espresso_version())
503
-     * @return int one of the constants on EE_System::req_type_*
504
-     */
505
-    public static function detect_req_type_given_activation_history(
506
-        $activation_history_for_addon,
507
-        $activation_indicator_option_name,
508
-        $version_to_upgrade_to
509
-    ) {
510
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
511
-        if ($activation_history_for_addon) {
512
-            //it exists, so this isn't a completely new install
513
-            //check if this version already in that list of previously installed versions
514
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
515
-                //it a version we haven't seen before
516
-                if ($version_is_higher === 1) {
517
-                    $req_type = EE_System::req_type_upgrade;
518
-                } else {
519
-                    $req_type = EE_System::req_type_downgrade;
520
-                }
521
-                delete_option($activation_indicator_option_name);
522
-            } else {
523
-                // its not an update. maybe a reactivation?
524
-                if (get_option($activation_indicator_option_name, false)) {
525
-                    if ($version_is_higher === -1) {
526
-                        $req_type = EE_System::req_type_downgrade;
527
-                    } elseif ($version_is_higher === 0) {
528
-                        //we've seen this version before, but it's an activation. must be a reactivation
529
-                        $req_type = EE_System::req_type_reactivation;
530
-                    } else {//$version_is_higher === 1
531
-                        $req_type = EE_System::req_type_upgrade;
532
-                    }
533
-                    delete_option($activation_indicator_option_name);
534
-                } else {
535
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
536
-                    if ($version_is_higher === -1) {
537
-                        $req_type = EE_System::req_type_downgrade;
538
-                    } elseif ($version_is_higher === 0) {
539
-                        //we've seen this version before and it's not an activation. its normal request
540
-                        $req_type = EE_System::req_type_normal;
541
-                    } else {//$version_is_higher === 1
542
-                        $req_type = EE_System::req_type_upgrade;
543
-                    }
544
-                }
545
-            }
546
-        } else {
547
-            //brand new install
548
-            $req_type = EE_System::req_type_new_activation;
549
-            delete_option($activation_indicator_option_name);
550
-        }
551
-        return $req_type;
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
558
-     * the $activation_history_for_addon
559
-     *
560
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
561
-     *                                             sometimes containing 'unknown-date'
562
-     * @param string $version_to_upgrade_to        (current version)
563
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
564
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
565
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
566
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
567
-     */
568
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
569
-    {
570
-        //find the most recently-activated version
571
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
572
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Gets the most recently active version listed in the activation history,
579
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
580
-     *
581
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
582
-     *                                   sometimes containing 'unknown-date'
583
-     * @return string
584
-     */
585
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
586
-    {
587
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
588
-        $most_recently_active_version = '0.0.0.dev.000';
589
-        if (is_array($activation_history)) {
590
-            foreach ($activation_history as $version => $times_activated) {
591
-                //check there is a record of when this version was activated. Otherwise,
592
-                //mark it as unknown
593
-                if ( ! $times_activated) {
594
-                    $times_activated = array('unknown-date');
595
-                }
596
-                if (is_string($times_activated)) {
597
-                    $times_activated = array($times_activated);
598
-                }
599
-                foreach ($times_activated as $an_activation) {
600
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
601
-                        $most_recently_active_version = $version;
602
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
603
-                            ? '1970-01-01 00:00:00' : $an_activation;
604
-                    }
605
-                }
606
-            }
607
-        }
608
-        return $most_recently_active_version;
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * This redirects to the about EE page after activation
615
-     *
616
-     * @return void
617
-     */
618
-    public function redirect_to_about_ee()
619
-    {
620
-        $notices = EE_Error::get_notices(false);
621
-        //if current user is an admin and it's not an ajax or rest request
622
-        if (
623
-            ! (defined('DOING_AJAX') && DOING_AJAX)
624
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
625
-            && ! isset($notices['errors'])
626
-            && apply_filters(
627
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
628
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
629
-            )
630
-        ) {
631
-            $query_params = array('page' => 'espresso_about');
632
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
633
-                $query_params['new_activation'] = true;
634
-            }
635
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
636
-                $query_params['reactivation'] = true;
637
-            }
638
-            $url = add_query_arg($query_params, admin_url('admin.php'));
639
-            wp_safe_redirect($url);
640
-            exit();
641
-        }
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * load_core_configuration
648
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
649
-     * which runs during the WP 'plugins_loaded' action at priority 5
650
-     *
651
-     * @return void
652
-     */
653
-    public function load_core_configuration()
654
-    {
655
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
656
-        $this->registry->load_core('EE_Load_Textdomain');
657
-        //load textdomain
658
-        EE_Load_Textdomain::load_textdomain();
659
-        // load and setup EE_Config and EE_Network_Config
660
-        $this->registry->load_core('Config');
661
-        $this->registry->load_core('Network_Config');
662
-        // setup autoloaders
663
-        // enable logging?
664
-        if ($this->registry->CFG->admin->use_full_logging) {
665
-            $this->registry->load_core('Log');
666
-        }
667
-        // check for activation errors
668
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
669
-        if ($activation_errors) {
670
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
671
-            update_option('ee_plugin_activation_errors', false);
672
-        }
673
-        // get model names
674
-        $this->_parse_model_names();
675
-        //load caf stuff a chance to play during the activation process too.
676
-        $this->_maybe_brew_regular();
677
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
684
-     *
685
-     * @return void
686
-     */
687
-    private function _parse_model_names()
688
-    {
689
-        //get all the files in the EE_MODELS folder that end in .model.php
690
-        $models = glob(EE_MODELS . '*.model.php');
691
-        $model_names = array();
692
-        $non_abstract_db_models = array();
693
-        foreach ($models as $model) {
694
-            // get model classname
695
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
696
-            $short_name = str_replace('EEM_', '', $classname);
697
-            $reflectionClass = new ReflectionClass($classname);
698
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
699
-                $non_abstract_db_models[$short_name] = $classname;
700
-            }
701
-            $model_names[$short_name] = $classname;
702
-        }
703
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
704
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
705
-            $non_abstract_db_models);
706
-    }
707
-
708
-
709
-
710
-    /**
711
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
712
-     * that need to be setup before our EE_System launches.
713
-     *
714
-     * @return void
715
-     */
716
-    private function _maybe_brew_regular()
717
-    {
718
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
719
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
720
-        }
721
-    }
722
-
723
-
724
-
725
-    /**
726
-     * register_shortcodes_modules_and_widgets
727
-     * generate lists of shortcodes and modules, then verify paths and classes
728
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
729
-     * which runs during the WP 'plugins_loaded' action at priority 7
730
-     *
731
-     * @access public
732
-     * @return void
733
-     */
734
-    public function register_shortcodes_modules_and_widgets()
735
-    {
736
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
737
-        // check for addons using old hookpoint
738
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
739
-            $this->_incompatible_addon_error();
740
-        }
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     * _incompatible_addon_error
747
-     *
748
-     * @access public
749
-     * @return void
750
-     */
751
-    private function _incompatible_addon_error()
752
-    {
753
-        // get array of classes hooking into here
754
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
755
-        if ( ! empty($class_names)) {
756
-            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
757
-                'event_espresso');
758
-            $msg .= '<ul>';
759
-            foreach ($class_names as $class_name) {
760
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
761
-                        $class_name) . '</b></li>';
762
-            }
763
-            $msg .= '</ul>';
764
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
765
-                'event_espresso');
766
-            // save list of incompatible addons to wp-options for later use
767
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
768
-            if (is_admin()) {
769
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
770
-            }
771
-        }
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * brew_espresso
778
-     * begins the process of setting hooks for initializing EE in the correct order
779
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
780
-     * which runs during the WP 'plugins_loaded' action at priority 9
781
-     *
782
-     * @return void
783
-     */
784
-    public function brew_espresso()
785
-    {
786
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
787
-        // load some final core systems
788
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
789
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
790
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
791
-        add_action('init', array($this, 'load_controllers'), 7);
792
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
793
-        add_action('init', array($this, 'initialize'), 10);
794
-        add_action('init', array($this, 'initialize_last'), 100);
795
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
796
-        add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
797
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
798
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
799
-            // pew pew pew
800
-            $this->registry->load_core('PUE');
801
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
802
-        }
803
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
804
-    }
805
-
806
-
807
-
808
-    /**
809
-     *    set_hooks_for_core
810
-     *
811
-     * @access public
812
-     * @return    void
813
-     */
814
-    public function set_hooks_for_core()
815
-    {
816
-        $this->_deactivate_incompatible_addons();
817
-        do_action('AHEE__EE_System__set_hooks_for_core');
818
-    }
819
-
820
-
821
-
822
-    /**
823
-     * Using the information gathered in EE_System::_incompatible_addon_error,
824
-     * deactivates any addons considered incompatible with the current version of EE
825
-     */
826
-    private function _deactivate_incompatible_addons()
827
-    {
828
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
829
-        if ( ! empty($incompatible_addons)) {
830
-            $active_plugins = get_option('active_plugins', array());
831
-            foreach ($active_plugins as $active_plugin) {
832
-                foreach ($incompatible_addons as $incompatible_addon) {
833
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
834
-                        unset($_GET['activate']);
835
-                        espresso_deactivate_plugin($active_plugin);
836
-                    }
837
-                }
838
-            }
839
-        }
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     *    perform_activations_upgrades_and_migrations
846
-     *
847
-     * @access public
848
-     * @return    void
849
-     */
850
-    public function perform_activations_upgrades_and_migrations()
851
-    {
852
-        //first check if we had previously attempted to setup EE's directories but failed
853
-        if (EEH_Activation::upload_directories_incomplete()) {
854
-            EEH_Activation::create_upload_directories();
855
-        }
856
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
857
-    }
858
-
859
-
860
-
861
-    /**
862
-     *    load_CPTs_and_session
863
-     *
864
-     * @access public
865
-     * @return    void
866
-     */
867
-    public function load_CPTs_and_session()
868
-    {
869
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
870
-        // register Custom Post Types
871
-        $this->registry->load_core('Register_CPTs');
872
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
873
-    }
874
-
875
-
876
-
877
-    /**
878
-     * load_controllers
879
-     * this is the best place to load any additional controllers that needs access to EE core.
880
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
881
-     * time
882
-     *
883
-     * @access public
884
-     * @return void
885
-     */
886
-    public function load_controllers()
887
-    {
888
-        do_action('AHEE__EE_System__load_controllers__start');
889
-        // let's get it started
890
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
891
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
892
-            $this->registry->load_core('Front_Controller', array(), false, true);
893
-        } else if ( ! EE_FRONT_AJAX) {
894
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
895
-            EE_Registry::instance()->load_core('Admin');
896
-        }
897
-        do_action('AHEE__EE_System__load_controllers__complete');
898
-    }
899
-
900
-
901
-
902
-    /**
903
-     * core_loaded_and_ready
904
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
905
-     *
906
-     * @access public
907
-     * @return void
908
-     */
909
-    public function core_loaded_and_ready()
910
-    {
911
-        do_action('AHEE__EE_System__core_loaded_and_ready');
912
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
913
-        $this->registry->load_core('Session');
914
-        //		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
915
-    }
916
-
917
-
918
-
919
-    /**
920
-     * initialize
921
-     * this is the best place to begin initializing client code
922
-     *
923
-     * @access public
924
-     * @return void
925
-     */
926
-    public function initialize()
927
-    {
928
-        do_action('AHEE__EE_System__initialize');
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * initialize_last
935
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
936
-     * initialize has done so
937
-     *
938
-     * @access public
939
-     * @return void
940
-     */
941
-    public function initialize_last()
942
-    {
943
-        do_action('AHEE__EE_System__initialize_last');
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * set_hooks_for_shortcodes_modules_and_addons
950
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
951
-     * this happens at the very beginning of the wp_loaded hookpoint
952
-     *
953
-     * @access public
954
-     * @return void
955
-     */
956
-    public function set_hooks_for_shortcodes_modules_and_addons()
957
-    {
958
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * do_not_cache
965
-     * sets no cache headers and defines no cache constants for WP plugins
966
-     *
967
-     * @access public
968
-     * @return void
969
-     */
970
-    public static function do_not_cache()
971
-    {
972
-        // set no cache constants
973
-        if ( ! defined('DONOTCACHEPAGE')) {
974
-            define('DONOTCACHEPAGE', true);
975
-        }
976
-        if ( ! defined('DONOTCACHCEOBJECT')) {
977
-            define('DONOTCACHCEOBJECT', true);
978
-        }
979
-        if ( ! defined('DONOTCACHEDB')) {
980
-            define('DONOTCACHEDB', true);
981
-        }
982
-        // add no cache headers
983
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
984
-        // plus a little extra for nginx and Google Chrome
985
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
986
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
987
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     *    extra_nocache_headers
994
-     *
995
-     * @access    public
996
-     * @param $headers
997
-     * @return    array
998
-     */
999
-    public static function extra_nocache_headers($headers)
1000
-    {
1001
-        // for NGINX
1002
-        $headers['X-Accel-Expires'] = 0;
1003
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1004
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1005
-        return $headers;
1006
-    }
1007
-
1008
-
1009
-
1010
-    /**
1011
-     *    nocache_headers
1012
-     *
1013
-     * @access    public
1014
-     * @return    void
1015
-     */
1016
-    public static function nocache_headers()
1017
-    {
1018
-        nocache_headers();
1019
-    }
1020
-
1021
-
1022
-
1023
-    /**
1024
-     *    espresso_toolbar_items
1025
-     *
1026
-     * @access public
1027
-     * @param  WP_Admin_Bar $admin_bar
1028
-     * @return void
1029
-     */
1030
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1031
-    {
1032
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1033
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1034
-            || defined('DOING_AJAX')
1035
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1036
-        ) {
1037
-            return;
1038
-        }
1039
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1040
-        $menu_class = 'espresso_menu_item_class';
1041
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1042
-        //because they're only defined in each of their respective constructors
1043
-        //and this might be a frontend request, in which case they aren't available
1044
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1045
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1046
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1047
-        //Top Level
1048
-        $admin_bar->add_menu(array(
1049
-            'id'    => 'espresso-toolbar',
1050
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1051
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1052
-                       . '</span>',
1053
-            'href'  => $events_admin_url,
1054
-            'meta'  => array(
1055
-                'title' => __('Event Espresso', 'event_espresso'),
1056
-                'class' => $menu_class . 'first',
1057
-            ),
1058
-        ));
1059
-        //Events
1060
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1061
-            $admin_bar->add_menu(array(
1062
-                'id'     => 'espresso-toolbar-events',
1063
-                'parent' => 'espresso-toolbar',
1064
-                'title'  => __('Events', 'event_espresso'),
1065
-                'href'   => $events_admin_url,
1066
-                'meta'   => array(
1067
-                    'title'  => __('Events', 'event_espresso'),
1068
-                    'target' => '',
1069
-                    'class'  => $menu_class,
1070
-                ),
1071
-            ));
1072
-        }
1073
-        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1074
-            //Events Add New
1075
-            $admin_bar->add_menu(array(
1076
-                'id'     => 'espresso-toolbar-events-new',
1077
-                'parent' => 'espresso-toolbar-events',
1078
-                'title'  => __('Add New', 'event_espresso'),
1079
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1080
-                'meta'   => array(
1081
-                    'title'  => __('Add New', 'event_espresso'),
1082
-                    'target' => '',
1083
-                    'class'  => $menu_class,
1084
-                ),
1085
-            ));
1086
-        }
1087
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1088
-            //Current post
1089
-            global $post;
1090
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1091
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1092
-            ) {
1093
-                //Events Edit Current Event
1094
-                $admin_bar->add_menu(array(
1095
-                    'id'     => 'espresso-toolbar-events-edit',
1096
-                    'parent' => 'espresso-toolbar-events',
1097
-                    'title'  => __('Edit Event', 'event_espresso'),
1098
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1099
-                        $events_admin_url),
1100
-                    'meta'   => array(
1101
-                        'title'  => __('Edit Event', 'event_espresso'),
1102
-                        'target' => '',
1103
-                        'class'  => $menu_class,
1104
-                    ),
1105
-                ));
1106
-            }
1107
-        }
1108
-        //Events View
1109
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1110
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1111
-        ) {
1112
-            $admin_bar->add_menu(array(
1113
-                'id'     => 'espresso-toolbar-events-view',
1114
-                'parent' => 'espresso-toolbar-events',
1115
-                'title'  => __('View', 'event_espresso'),
1116
-                'href'   => $events_admin_url,
1117
-                'meta'   => array(
1118
-                    'title'  => __('View', 'event_espresso'),
1119
-                    'target' => '',
1120
-                    'class'  => $menu_class,
1121
-                ),
1122
-            ));
1123
-        }
1124
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1125
-            //Events View All
1126
-            $admin_bar->add_menu(array(
1127
-                'id'     => 'espresso-toolbar-events-all',
1128
-                'parent' => 'espresso-toolbar-events-view',
1129
-                'title'  => __('All', 'event_espresso'),
1130
-                'href'   => $events_admin_url,
1131
-                'meta'   => array(
1132
-                    'title'  => __('All', 'event_espresso'),
1133
-                    'target' => '',
1134
-                    'class'  => $menu_class,
1135
-                ),
1136
-            ));
1137
-        }
1138
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1139
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1140
-        ) {
1141
-            //Events View Today
1142
-            $admin_bar->add_menu(array(
1143
-                'id'     => 'espresso-toolbar-events-today',
1144
-                'parent' => 'espresso-toolbar-events-view',
1145
-                'title'  => __('Today', 'event_espresso'),
1146
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1147
-                    $events_admin_url),
1148
-                'meta'   => array(
1149
-                    'title'  => __('Today', 'event_espresso'),
1150
-                    'target' => '',
1151
-                    'class'  => $menu_class,
1152
-                ),
1153
-            ));
1154
-        }
1155
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1156
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1157
-        ) {
1158
-            //Events View This Month
1159
-            $admin_bar->add_menu(array(
1160
-                'id'     => 'espresso-toolbar-events-month',
1161
-                'parent' => 'espresso-toolbar-events-view',
1162
-                'title'  => __('This Month', 'event_espresso'),
1163
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1164
-                    $events_admin_url),
1165
-                'meta'   => array(
1166
-                    'title'  => __('This Month', 'event_espresso'),
1167
-                    'target' => '',
1168
-                    'class'  => $menu_class,
1169
-                ),
1170
-            ));
1171
-        }
1172
-        //Registration Overview
1173
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1174
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1175
-        ) {
1176
-            $admin_bar->add_menu(array(
1177
-                'id'     => 'espresso-toolbar-registrations',
1178
-                'parent' => 'espresso-toolbar',
1179
-                'title'  => __('Registrations', 'event_espresso'),
1180
-                'href'   => $reg_admin_url,
1181
-                'meta'   => array(
1182
-                    'title'  => __('Registrations', 'event_espresso'),
1183
-                    'target' => '',
1184
-                    'class'  => $menu_class,
1185
-                ),
1186
-            ));
1187
-        }
1188
-        //Registration Overview Today
1189
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1190
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1191
-        ) {
1192
-            $admin_bar->add_menu(array(
1193
-                'id'     => 'espresso-toolbar-registrations-today',
1194
-                'parent' => 'espresso-toolbar-registrations',
1195
-                'title'  => __('Today', 'event_espresso'),
1196
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1197
-                    $reg_admin_url),
1198
-                'meta'   => array(
1199
-                    'title'  => __('Today', 'event_espresso'),
1200
-                    'target' => '',
1201
-                    'class'  => $menu_class,
1202
-                ),
1203
-            ));
1204
-        }
1205
-        //Registration Overview Today Completed
1206
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1207
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1208
-        ) {
1209
-            $admin_bar->add_menu(array(
1210
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1211
-                'parent' => 'espresso-toolbar-registrations-today',
1212
-                'title'  => __('Approved', 'event_espresso'),
1213
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1214
-                    'action'      => 'default',
1215
-                    'status'      => 'today',
1216
-                    '_reg_status' => EEM_Registration::status_id_approved,
1217
-                ), $reg_admin_url),
1218
-                'meta'   => array(
1219
-                    'title'  => __('Approved', 'event_espresso'),
1220
-                    'target' => '',
1221
-                    'class'  => $menu_class,
1222
-                ),
1223
-            ));
1224
-        }
1225
-        //Registration Overview Today Pending\
1226
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1227
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1228
-        ) {
1229
-            $admin_bar->add_menu(array(
1230
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1231
-                'parent' => 'espresso-toolbar-registrations-today',
1232
-                'title'  => __('Pending', 'event_espresso'),
1233
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1234
-                    'action'     => 'default',
1235
-                    'status'     => 'today',
1236
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1237
-                ), $reg_admin_url),
1238
-                'meta'   => array(
1239
-                    'title'  => __('Pending Payment', 'event_espresso'),
1240
-                    'target' => '',
1241
-                    'class'  => $menu_class,
1242
-                ),
1243
-            ));
1244
-        }
1245
-        //Registration Overview Today Incomplete
1246
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1247
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1248
-        ) {
1249
-            $admin_bar->add_menu(array(
1250
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1251
-                'parent' => 'espresso-toolbar-registrations-today',
1252
-                'title'  => __('Not Approved', 'event_espresso'),
1253
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1254
-                    'action'      => 'default',
1255
-                    'status'      => 'today',
1256
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1257
-                ), $reg_admin_url),
1258
-                'meta'   => array(
1259
-                    'title'  => __('Not Approved', 'event_espresso'),
1260
-                    'target' => '',
1261
-                    'class'  => $menu_class,
1262
-                ),
1263
-            ));
1264
-        }
1265
-        //Registration Overview Today Incomplete
1266
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1267
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1268
-        ) {
1269
-            $admin_bar->add_menu(array(
1270
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1271
-                'parent' => 'espresso-toolbar-registrations-today',
1272
-                'title'  => __('Cancelled', 'event_espresso'),
1273
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1274
-                    'action'      => 'default',
1275
-                    'status'      => 'today',
1276
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1277
-                ), $reg_admin_url),
1278
-                'meta'   => array(
1279
-                    'title'  => __('Cancelled', 'event_espresso'),
1280
-                    'target' => '',
1281
-                    'class'  => $menu_class,
1282
-                ),
1283
-            ));
1284
-        }
1285
-        //Registration Overview This Month
1286
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1287
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1288
-        ) {
1289
-            $admin_bar->add_menu(array(
1290
-                'id'     => 'espresso-toolbar-registrations-month',
1291
-                'parent' => 'espresso-toolbar-registrations',
1292
-                'title'  => __('This Month', 'event_espresso'),
1293
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1294
-                    $reg_admin_url),
1295
-                'meta'   => array(
1296
-                    'title'  => __('This Month', 'event_espresso'),
1297
-                    'target' => '',
1298
-                    'class'  => $menu_class,
1299
-                ),
1300
-            ));
1301
-        }
1302
-        //Registration Overview This Month Approved
1303
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1304
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1305
-        ) {
1306
-            $admin_bar->add_menu(array(
1307
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1308
-                'parent' => 'espresso-toolbar-registrations-month',
1309
-                'title'  => __('Approved', 'event_espresso'),
1310
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1311
-                    'action'      => 'default',
1312
-                    'status'      => 'month',
1313
-                    '_reg_status' => EEM_Registration::status_id_approved,
1314
-                ), $reg_admin_url),
1315
-                'meta'   => array(
1316
-                    'title'  => __('Approved', 'event_espresso'),
1317
-                    'target' => '',
1318
-                    'class'  => $menu_class,
1319
-                ),
1320
-            ));
1321
-        }
1322
-        //Registration Overview This Month Pending
1323
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1324
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1325
-        ) {
1326
-            $admin_bar->add_menu(array(
1327
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1328
-                'parent' => 'espresso-toolbar-registrations-month',
1329
-                'title'  => __('Pending', 'event_espresso'),
1330
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1331
-                    'action'      => 'default',
1332
-                    'status'      => 'month',
1333
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1334
-                ), $reg_admin_url),
1335
-                'meta'   => array(
1336
-                    'title'  => __('Pending', 'event_espresso'),
1337
-                    'target' => '',
1338
-                    'class'  => $menu_class,
1339
-                ),
1340
-            ));
1341
-        }
1342
-        //Registration Overview This Month Not Approved
1343
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1344
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1345
-        ) {
1346
-            $admin_bar->add_menu(array(
1347
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1348
-                'parent' => 'espresso-toolbar-registrations-month',
1349
-                'title'  => __('Not Approved', 'event_espresso'),
1350
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1351
-                    'action'      => 'default',
1352
-                    'status'      => 'month',
1353
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1354
-                ), $reg_admin_url),
1355
-                'meta'   => array(
1356
-                    'title'  => __('Not Approved', 'event_espresso'),
1357
-                    'target' => '',
1358
-                    'class'  => $menu_class,
1359
-                ),
1360
-            ));
1361
-        }
1362
-        //Registration Overview This Month Cancelled
1363
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1364
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1365
-        ) {
1366
-            $admin_bar->add_menu(array(
1367
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1368
-                'parent' => 'espresso-toolbar-registrations-month',
1369
-                'title'  => __('Cancelled', 'event_espresso'),
1370
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1371
-                    'action'      => 'default',
1372
-                    'status'      => 'month',
1373
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1374
-                ), $reg_admin_url),
1375
-                'meta'   => array(
1376
-                    'title'  => __('Cancelled', 'event_espresso'),
1377
-                    'target' => '',
1378
-                    'class'  => $menu_class,
1379
-                ),
1380
-            ));
1381
-        }
1382
-        //Extensions & Services
1383
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1384
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1385
-        ) {
1386
-            $admin_bar->add_menu(array(
1387
-                'id'     => 'espresso-toolbar-extensions-and-services',
1388
-                'parent' => 'espresso-toolbar',
1389
-                'title'  => __('Extensions & Services', 'event_espresso'),
1390
-                'href'   => $extensions_admin_url,
1391
-                'meta'   => array(
1392
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1393
-                    'target' => '',
1394
-                    'class'  => $menu_class,
1395
-                ),
1396
-            ));
1397
-        }
1398
-    }
1399
-
1400
-
1401
-
1402
-    /**
1403
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1404
-     * never returned with the function.
1405
-     *
1406
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1407
-     * @return array
1408
-     */
1409
-    public function remove_pages_from_wp_list_pages($exclude_array)
1410
-    {
1411
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1412
-    }
1413
-
1414
-
1415
-
1416
-
1417
-
1418
-
1419
-    /***********************************************        WP_ENQUEUE_SCRIPTS HOOK         ***********************************************/
1420
-    /**
1421
-     *    wp_enqueue_scripts
1422
-     *
1423
-     * @access    public
1424
-     * @return    void
1425
-     */
1426
-    public function wp_enqueue_scripts()
1427
-    {
1428
-        // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1429
-        if (apply_filters('FHEE_load_EE_System_scripts', true)) {
1430
-            // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1431
-            if (apply_filters('FHEE_load_jquery_validate', false)) {
1432
-                // register jQuery Validate and additional methods
1433
-                wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1434
-                    array('jquery'), '1.15.0', true);
1435
-                wp_register_script('jquery-validate-extra-methods',
1436
-                    EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1437
-                    array('jquery', 'jquery-validate'), '1.15.0', true);
1438
-            }
1439
-        }
1440
-    }
19
+	/**
20
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
21
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
22
+	 */
23
+	const req_type_normal = 0;
24
+
25
+	/**
26
+	 * Indicates this is a brand new installation of EE so we should install
27
+	 * tables and default data etc
28
+	 */
29
+	const req_type_new_activation = 1;
30
+
31
+	/**
32
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
33
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
34
+	 * and that default data is setup too
35
+	 */
36
+	const req_type_reactivation = 2;
37
+
38
+	/**
39
+	 * indicates that EE has been upgraded since its previous request.
40
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
41
+	 */
42
+	const req_type_upgrade = 3;
43
+
44
+	/**
45
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
46
+	 */
47
+	const req_type_downgrade = 4;
48
+
49
+	/**
50
+	 * @deprecated since version 4.6.0.dev.006
51
+	 * Now whenever a new_activation is detected the request type is still just
52
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
53
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
54
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
55
+	 * (Specifically, when the migration manager indicates migrations are finished
56
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
57
+	 */
58
+	const req_type_activation_but_not_installed = 5;
59
+
60
+	/**
61
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
62
+	 */
63
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
64
+
65
+
66
+	/**
67
+	 *    instance of the EE_System object
68
+	 *
69
+	 * @var    $_instance
70
+	 * @access    private
71
+	 */
72
+	private static $_instance = null;
73
+
74
+	/**
75
+	 * @type  EE_Registry $Registry
76
+	 * @access    protected
77
+	 */
78
+	protected $registry;
79
+
80
+	/**
81
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
82
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
83
+	 *
84
+	 * @var int
85
+	 */
86
+	private $_req_type;
87
+
88
+	/**
89
+	 * Whether or not there was a non-micro version change in EE core version during this request
90
+	 *
91
+	 * @var boolean
92
+	 */
93
+	private $_major_version_change = false;
94
+
95
+
96
+
97
+	/**
98
+	 * @singleton method used to instantiate class object
99
+	 * @access    public
100
+	 * @param  \EE_Registry $Registry
101
+	 * @return \EE_System
102
+	 */
103
+	public static function instance(EE_Registry $Registry = null)
104
+	{
105
+		// check if class object is instantiated
106
+		if ( ! self::$_instance instanceof EE_System) {
107
+			self::$_instance = new self($Registry);
108
+		}
109
+		return self::$_instance;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * resets the instance and returns it
116
+	 *
117
+	 * @return EE_System
118
+	 */
119
+	public static function reset()
120
+	{
121
+		self::$_instance->_req_type = null;
122
+		//make sure none of the old hooks are left hanging around
123
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
124
+		//we need to reset the migration manager in order for it to detect DMSs properly
125
+		EE_Data_Migration_Manager::reset();
126
+		self::instance()->detect_activations_or_upgrades();
127
+		self::instance()->perform_activations_upgrades_and_migrations();
128
+		return self::instance();
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 *    sets hooks for running rest of system
135
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
136
+	 *    starting EE Addons from any other point may lead to problems
137
+	 *
138
+	 * @access private
139
+	 * @param  \EE_Registry $Registry
140
+	 */
141
+	private function __construct(EE_Registry $Registry)
142
+	{
143
+		$this->registry = $Registry;
144
+		do_action('AHEE__EE_System__construct__begin', $this);
145
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
146
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
147
+		// when an ee addon is activated, we want to call the core hook(s) again
148
+		// because the newly-activated addon didn't get a chance to run at all
149
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
150
+		// detect whether install or upgrade
151
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
152
+			3);
153
+		// load EE_Config, EE_Textdomain, etc
154
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
155
+		// load EE_Config, EE_Textdomain, etc
156
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
157
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
158
+		// you wanna get going? I wanna get going... let's get going!
159
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
160
+		//other housekeeping
161
+		//exclude EE critical pages from wp_list_pages
162
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
163
+		// ALL EE Addons should use the following hook point to attach their initial setup too
164
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
165
+		do_action('AHEE__EE_System__construct__complete', $this);
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * load_espresso_addons
172
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
173
+	 * this is hooked into both:
174
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
175
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
176
+	 *    and the WP 'activate_plugin' hookpoint
177
+	 *
178
+	 * @access public
179
+	 * @return void
180
+	 */
181
+	public function load_espresso_addons()
182
+	{
183
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
184
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
185
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
186
+		//load and setup EE_Capabilities
187
+		$this->registry->load_core('Capabilities');
188
+		//caps need to be initialized on every request so that capability maps are set.
189
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
190
+		$this->registry->CAP->init_caps();
191
+		do_action('AHEE__EE_System__load_espresso_addons');
192
+		//if the WP API basic auth plugin isn't already loaded, load it now.
193
+		//We want it for mobile apps. Just include the entire plugin
194
+		//also, don't load the basic auth when a plugin is getting activated, because
195
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
196
+		//and causes a fatal error
197
+		if ( ! function_exists('json_basic_auth_handler')
198
+			 && ! function_exists('json_basic_auth_error')
199
+			 && ! (
200
+				isset($_GET['action'])
201
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
202
+			)
203
+			 && ! (
204
+				isset($_GET['activate'])
205
+				&& $_GET['activate'] === 'true'
206
+			)
207
+		) {
208
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
209
+		}
210
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * detect_activations_or_upgrades
217
+	 * Checks for activation or upgrade of core first;
218
+	 * then also checks if any registered addons have been activated or upgraded
219
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
220
+	 * which runs during the WP 'plugins_loaded' action at priority 3
221
+	 *
222
+	 * @access public
223
+	 * @return void
224
+	 */
225
+	public function detect_activations_or_upgrades()
226
+	{
227
+		//first off: let's make sure to handle core
228
+		$this->detect_if_activation_or_upgrade();
229
+		foreach ($this->registry->addons as $addon) {
230
+			//detect teh request type for that addon
231
+			$addon->detect_activation_or_upgrade();
232
+		}
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * detect_if_activation_or_upgrade
239
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
240
+	 * and either setting up the DB or setting up maintenance mode etc.
241
+	 *
242
+	 * @access public
243
+	 * @return void
244
+	 */
245
+	public function detect_if_activation_or_upgrade()
246
+	{
247
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
248
+		// load M-Mode class
249
+		$this->registry->load_core('Maintenance_Mode');
250
+		// check if db has been updated, or if its a brand-new installation
251
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
252
+		$request_type = $this->detect_req_type($espresso_db_update);
253
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
254
+		switch ($request_type) {
255
+			case EE_System::req_type_new_activation:
256
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
257
+				$this->_handle_core_version_change($espresso_db_update);
258
+				break;
259
+			case EE_System::req_type_reactivation:
260
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
261
+				$this->_handle_core_version_change($espresso_db_update);
262
+				break;
263
+			case EE_System::req_type_upgrade:
264
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
265
+				//migrations may be required now that we've upgraded
266
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
267
+				$this->_handle_core_version_change($espresso_db_update);
268
+				//				echo "done upgrade";die;
269
+				break;
270
+			case EE_System::req_type_downgrade:
271
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
272
+				//its possible migrations are no longer required
273
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
274
+				$this->_handle_core_version_change($espresso_db_update);
275
+				break;
276
+			case EE_System::req_type_normal:
277
+			default:
278
+				//				$this->_maybe_redirect_to_ee_about();
279
+				break;
280
+		}
281
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * Updates the list of installed versions and sets hooks for
288
+	 * initializing the database later during the request
289
+	 *
290
+	 * @param array $espresso_db_update
291
+	 */
292
+	protected function _handle_core_version_change($espresso_db_update)
293
+	{
294
+		$this->update_list_of_installed_versions($espresso_db_update);
295
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
296
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
297
+			array($this, 'initialize_db_if_no_migrations_required'));
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
304
+	 * information about what versions of EE have been installed and activated,
305
+	 * NOT necessarily the state of the database
306
+	 *
307
+	 * @param null $espresso_db_update
308
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
309
+	 *           from the options table
310
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
311
+	 */
312
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
313
+	{
314
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
315
+		if ( ! $espresso_db_update) {
316
+			$espresso_db_update = get_option('espresso_db_update');
317
+		}
318
+		// check that option is an array
319
+		if ( ! is_array($espresso_db_update)) {
320
+			// if option is FALSE, then it never existed
321
+			if ($espresso_db_update === false) {
322
+				// make $espresso_db_update an array and save option with autoload OFF
323
+				$espresso_db_update = array();
324
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
325
+			} else {
326
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
327
+				$espresso_db_update = array($espresso_db_update => array());
328
+				update_option('espresso_db_update', $espresso_db_update);
329
+			}
330
+		} else {
331
+			$corrected_db_update = array();
332
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
333
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
334
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
335
+					//the key is an int, and the value IS NOT an array
336
+					//so it must be numerically-indexed, where values are versions installed...
337
+					//fix it!
338
+					$version_string = $should_be_array;
339
+					$corrected_db_update[$version_string] = array('unknown-date');
340
+				} else {
341
+					//ok it checks out
342
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
343
+				}
344
+			}
345
+			$espresso_db_update = $corrected_db_update;
346
+			update_option('espresso_db_update', $espresso_db_update);
347
+		}
348
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
349
+		return $espresso_db_update;
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Does the traditional work of setting up the plugin's database and adding default data.
356
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
357
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
358
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
359
+	 * so that it will be done when migrations are finished
360
+	 *
361
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
362
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
363
+	 *                                       This is a resource-intensive job
364
+	 *                                       so we prefer to only do it when necessary
365
+	 * @return void
366
+	 */
367
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
368
+	{
369
+		$request_type = $this->detect_req_type();
370
+		//only initialize system if we're not in maintenance mode.
371
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
372
+			update_option('ee_flush_rewrite_rules', true);
373
+			if ($verify_schema) {
374
+				EEH_Activation::initialize_db_and_folders();
375
+			}
376
+			EEH_Activation::initialize_db_content();
377
+			EEH_Activation::system_initialization();
378
+			if ($initialize_addons_too) {
379
+				$this->initialize_addons();
380
+			}
381
+		} else {
382
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
383
+		}
384
+		if ($request_type === EE_System::req_type_new_activation
385
+			|| $request_type === EE_System::req_type_reactivation
386
+			|| (
387
+				$request_type === EE_System::req_type_upgrade
388
+				&& $this->is_major_version_change()
389
+			)
390
+		) {
391
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
392
+		}
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * Initializes the db for all registered addons
399
+	 */
400
+	public function initialize_addons()
401
+	{
402
+		//foreach registered addon, make sure its db is up-to-date too
403
+		foreach ($this->registry->addons as $addon) {
404
+			$addon->initialize_db_if_no_migrations_required();
405
+		}
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
412
+	 *
413
+	 * @param    array  $version_history
414
+	 * @param    string $current_version_to_add version to be added to the version history
415
+	 * @return    boolean success as to whether or not this option was changed
416
+	 */
417
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
418
+	{
419
+		if ( ! $version_history) {
420
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
421
+		}
422
+		if ($current_version_to_add == null) {
423
+			$current_version_to_add = espresso_version();
424
+		}
425
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
426
+		// re-save
427
+		return update_option('espresso_db_update', $version_history);
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * Detects if the current version indicated in the has existed in the list of
434
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
435
+	 *
436
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
437
+	 *                                  If not supplied, fetches it from the options table.
438
+	 *                                  Also, caches its result so later parts of the code can also know whether
439
+	 *                                  there's been an update or not. This way we can add the current version to
440
+	 *                                  espresso_db_update, but still know if this is a new install or not
441
+	 * @return int one of the constants on EE_System::req_type_
442
+	 */
443
+	public function detect_req_type($espresso_db_update = null)
444
+	{
445
+		if ($this->_req_type === null) {
446
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
447
+				: $this->fix_espresso_db_upgrade_option();
448
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
449
+				'ee_espresso_activation', espresso_version());
450
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
451
+		}
452
+		return $this->_req_type;
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 * Returns whether or not there was a non-micro version change (ie, change in either
459
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
460
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
461
+	 *
462
+	 * @param $activation_history
463
+	 * @return bool
464
+	 */
465
+	protected function _detect_major_version_change($activation_history)
466
+	{
467
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
468
+		$previous_version_parts = explode('.', $previous_version);
469
+		$current_version_parts = explode('.', espresso_version());
470
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
471
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
472
+				   || $previous_version_parts[1] !== $current_version_parts[1]
473
+			   );
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * Returns true if either the major or minor version of EE changed during this request.
480
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
481
+	 *
482
+	 * @return bool
483
+	 */
484
+	public function is_major_version_change()
485
+	{
486
+		return $this->_major_version_change;
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
493
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
494
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
495
+	 * just activated to (for core that will always be espresso_version())
496
+	 *
497
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
498
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
499
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
500
+	 *                                                 indicate that this plugin was just activated
501
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
502
+	 *                                                 espresso_version())
503
+	 * @return int one of the constants on EE_System::req_type_*
504
+	 */
505
+	public static function detect_req_type_given_activation_history(
506
+		$activation_history_for_addon,
507
+		$activation_indicator_option_name,
508
+		$version_to_upgrade_to
509
+	) {
510
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
511
+		if ($activation_history_for_addon) {
512
+			//it exists, so this isn't a completely new install
513
+			//check if this version already in that list of previously installed versions
514
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
515
+				//it a version we haven't seen before
516
+				if ($version_is_higher === 1) {
517
+					$req_type = EE_System::req_type_upgrade;
518
+				} else {
519
+					$req_type = EE_System::req_type_downgrade;
520
+				}
521
+				delete_option($activation_indicator_option_name);
522
+			} else {
523
+				// its not an update. maybe a reactivation?
524
+				if (get_option($activation_indicator_option_name, false)) {
525
+					if ($version_is_higher === -1) {
526
+						$req_type = EE_System::req_type_downgrade;
527
+					} elseif ($version_is_higher === 0) {
528
+						//we've seen this version before, but it's an activation. must be a reactivation
529
+						$req_type = EE_System::req_type_reactivation;
530
+					} else {//$version_is_higher === 1
531
+						$req_type = EE_System::req_type_upgrade;
532
+					}
533
+					delete_option($activation_indicator_option_name);
534
+				} else {
535
+					//we've seen this version before and the activation indicate doesn't show it was just activated
536
+					if ($version_is_higher === -1) {
537
+						$req_type = EE_System::req_type_downgrade;
538
+					} elseif ($version_is_higher === 0) {
539
+						//we've seen this version before and it's not an activation. its normal request
540
+						$req_type = EE_System::req_type_normal;
541
+					} else {//$version_is_higher === 1
542
+						$req_type = EE_System::req_type_upgrade;
543
+					}
544
+				}
545
+			}
546
+		} else {
547
+			//brand new install
548
+			$req_type = EE_System::req_type_new_activation;
549
+			delete_option($activation_indicator_option_name);
550
+		}
551
+		return $req_type;
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
558
+	 * the $activation_history_for_addon
559
+	 *
560
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
561
+	 *                                             sometimes containing 'unknown-date'
562
+	 * @param string $version_to_upgrade_to        (current version)
563
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
564
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
565
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
566
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
567
+	 */
568
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
569
+	{
570
+		//find the most recently-activated version
571
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
572
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Gets the most recently active version listed in the activation history,
579
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
580
+	 *
581
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
582
+	 *                                   sometimes containing 'unknown-date'
583
+	 * @return string
584
+	 */
585
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
586
+	{
587
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
588
+		$most_recently_active_version = '0.0.0.dev.000';
589
+		if (is_array($activation_history)) {
590
+			foreach ($activation_history as $version => $times_activated) {
591
+				//check there is a record of when this version was activated. Otherwise,
592
+				//mark it as unknown
593
+				if ( ! $times_activated) {
594
+					$times_activated = array('unknown-date');
595
+				}
596
+				if (is_string($times_activated)) {
597
+					$times_activated = array($times_activated);
598
+				}
599
+				foreach ($times_activated as $an_activation) {
600
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
601
+						$most_recently_active_version = $version;
602
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
603
+							? '1970-01-01 00:00:00' : $an_activation;
604
+					}
605
+				}
606
+			}
607
+		}
608
+		return $most_recently_active_version;
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * This redirects to the about EE page after activation
615
+	 *
616
+	 * @return void
617
+	 */
618
+	public function redirect_to_about_ee()
619
+	{
620
+		$notices = EE_Error::get_notices(false);
621
+		//if current user is an admin and it's not an ajax or rest request
622
+		if (
623
+			! (defined('DOING_AJAX') && DOING_AJAX)
624
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
625
+			&& ! isset($notices['errors'])
626
+			&& apply_filters(
627
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
628
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
629
+			)
630
+		) {
631
+			$query_params = array('page' => 'espresso_about');
632
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
633
+				$query_params['new_activation'] = true;
634
+			}
635
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
636
+				$query_params['reactivation'] = true;
637
+			}
638
+			$url = add_query_arg($query_params, admin_url('admin.php'));
639
+			wp_safe_redirect($url);
640
+			exit();
641
+		}
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * load_core_configuration
648
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
649
+	 * which runs during the WP 'plugins_loaded' action at priority 5
650
+	 *
651
+	 * @return void
652
+	 */
653
+	public function load_core_configuration()
654
+	{
655
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
656
+		$this->registry->load_core('EE_Load_Textdomain');
657
+		//load textdomain
658
+		EE_Load_Textdomain::load_textdomain();
659
+		// load and setup EE_Config and EE_Network_Config
660
+		$this->registry->load_core('Config');
661
+		$this->registry->load_core('Network_Config');
662
+		// setup autoloaders
663
+		// enable logging?
664
+		if ($this->registry->CFG->admin->use_full_logging) {
665
+			$this->registry->load_core('Log');
666
+		}
667
+		// check for activation errors
668
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
669
+		if ($activation_errors) {
670
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
671
+			update_option('ee_plugin_activation_errors', false);
672
+		}
673
+		// get model names
674
+		$this->_parse_model_names();
675
+		//load caf stuff a chance to play during the activation process too.
676
+		$this->_maybe_brew_regular();
677
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
684
+	 *
685
+	 * @return void
686
+	 */
687
+	private function _parse_model_names()
688
+	{
689
+		//get all the files in the EE_MODELS folder that end in .model.php
690
+		$models = glob(EE_MODELS . '*.model.php');
691
+		$model_names = array();
692
+		$non_abstract_db_models = array();
693
+		foreach ($models as $model) {
694
+			// get model classname
695
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
696
+			$short_name = str_replace('EEM_', '', $classname);
697
+			$reflectionClass = new ReflectionClass($classname);
698
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
699
+				$non_abstract_db_models[$short_name] = $classname;
700
+			}
701
+			$model_names[$short_name] = $classname;
702
+		}
703
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
704
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
705
+			$non_abstract_db_models);
706
+	}
707
+
708
+
709
+
710
+	/**
711
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
712
+	 * that need to be setup before our EE_System launches.
713
+	 *
714
+	 * @return void
715
+	 */
716
+	private function _maybe_brew_regular()
717
+	{
718
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
719
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
720
+		}
721
+	}
722
+
723
+
724
+
725
+	/**
726
+	 * register_shortcodes_modules_and_widgets
727
+	 * generate lists of shortcodes and modules, then verify paths and classes
728
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
729
+	 * which runs during the WP 'plugins_loaded' action at priority 7
730
+	 *
731
+	 * @access public
732
+	 * @return void
733
+	 */
734
+	public function register_shortcodes_modules_and_widgets()
735
+	{
736
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
737
+		// check for addons using old hookpoint
738
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
739
+			$this->_incompatible_addon_error();
740
+		}
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 * _incompatible_addon_error
747
+	 *
748
+	 * @access public
749
+	 * @return void
750
+	 */
751
+	private function _incompatible_addon_error()
752
+	{
753
+		// get array of classes hooking into here
754
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
755
+		if ( ! empty($class_names)) {
756
+			$msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
757
+				'event_espresso');
758
+			$msg .= '<ul>';
759
+			foreach ($class_names as $class_name) {
760
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
761
+						$class_name) . '</b></li>';
762
+			}
763
+			$msg .= '</ul>';
764
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
765
+				'event_espresso');
766
+			// save list of incompatible addons to wp-options for later use
767
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
768
+			if (is_admin()) {
769
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
770
+			}
771
+		}
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * brew_espresso
778
+	 * begins the process of setting hooks for initializing EE in the correct order
779
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
780
+	 * which runs during the WP 'plugins_loaded' action at priority 9
781
+	 *
782
+	 * @return void
783
+	 */
784
+	public function brew_espresso()
785
+	{
786
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
787
+		// load some final core systems
788
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
789
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
790
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
791
+		add_action('init', array($this, 'load_controllers'), 7);
792
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
793
+		add_action('init', array($this, 'initialize'), 10);
794
+		add_action('init', array($this, 'initialize_last'), 100);
795
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
796
+		add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100);
797
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
798
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
799
+			// pew pew pew
800
+			$this->registry->load_core('PUE');
801
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
802
+		}
803
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
804
+	}
805
+
806
+
807
+
808
+	/**
809
+	 *    set_hooks_for_core
810
+	 *
811
+	 * @access public
812
+	 * @return    void
813
+	 */
814
+	public function set_hooks_for_core()
815
+	{
816
+		$this->_deactivate_incompatible_addons();
817
+		do_action('AHEE__EE_System__set_hooks_for_core');
818
+	}
819
+
820
+
821
+
822
+	/**
823
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
824
+	 * deactivates any addons considered incompatible with the current version of EE
825
+	 */
826
+	private function _deactivate_incompatible_addons()
827
+	{
828
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
829
+		if ( ! empty($incompatible_addons)) {
830
+			$active_plugins = get_option('active_plugins', array());
831
+			foreach ($active_plugins as $active_plugin) {
832
+				foreach ($incompatible_addons as $incompatible_addon) {
833
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
834
+						unset($_GET['activate']);
835
+						espresso_deactivate_plugin($active_plugin);
836
+					}
837
+				}
838
+			}
839
+		}
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 *    perform_activations_upgrades_and_migrations
846
+	 *
847
+	 * @access public
848
+	 * @return    void
849
+	 */
850
+	public function perform_activations_upgrades_and_migrations()
851
+	{
852
+		//first check if we had previously attempted to setup EE's directories but failed
853
+		if (EEH_Activation::upload_directories_incomplete()) {
854
+			EEH_Activation::create_upload_directories();
855
+		}
856
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
857
+	}
858
+
859
+
860
+
861
+	/**
862
+	 *    load_CPTs_and_session
863
+	 *
864
+	 * @access public
865
+	 * @return    void
866
+	 */
867
+	public function load_CPTs_and_session()
868
+	{
869
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
870
+		// register Custom Post Types
871
+		$this->registry->load_core('Register_CPTs');
872
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
873
+	}
874
+
875
+
876
+
877
+	/**
878
+	 * load_controllers
879
+	 * this is the best place to load any additional controllers that needs access to EE core.
880
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
881
+	 * time
882
+	 *
883
+	 * @access public
884
+	 * @return void
885
+	 */
886
+	public function load_controllers()
887
+	{
888
+		do_action('AHEE__EE_System__load_controllers__start');
889
+		// let's get it started
890
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
891
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
892
+			$this->registry->load_core('Front_Controller', array(), false, true);
893
+		} else if ( ! EE_FRONT_AJAX) {
894
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
895
+			EE_Registry::instance()->load_core('Admin');
896
+		}
897
+		do_action('AHEE__EE_System__load_controllers__complete');
898
+	}
899
+
900
+
901
+
902
+	/**
903
+	 * core_loaded_and_ready
904
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
905
+	 *
906
+	 * @access public
907
+	 * @return void
908
+	 */
909
+	public function core_loaded_and_ready()
910
+	{
911
+		do_action('AHEE__EE_System__core_loaded_and_ready');
912
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
913
+		$this->registry->load_core('Session');
914
+		//		add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 );
915
+	}
916
+
917
+
918
+
919
+	/**
920
+	 * initialize
921
+	 * this is the best place to begin initializing client code
922
+	 *
923
+	 * @access public
924
+	 * @return void
925
+	 */
926
+	public function initialize()
927
+	{
928
+		do_action('AHEE__EE_System__initialize');
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * initialize_last
935
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
936
+	 * initialize has done so
937
+	 *
938
+	 * @access public
939
+	 * @return void
940
+	 */
941
+	public function initialize_last()
942
+	{
943
+		do_action('AHEE__EE_System__initialize_last');
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * set_hooks_for_shortcodes_modules_and_addons
950
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
951
+	 * this happens at the very beginning of the wp_loaded hookpoint
952
+	 *
953
+	 * @access public
954
+	 * @return void
955
+	 */
956
+	public function set_hooks_for_shortcodes_modules_and_addons()
957
+	{
958
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * do_not_cache
965
+	 * sets no cache headers and defines no cache constants for WP plugins
966
+	 *
967
+	 * @access public
968
+	 * @return void
969
+	 */
970
+	public static function do_not_cache()
971
+	{
972
+		// set no cache constants
973
+		if ( ! defined('DONOTCACHEPAGE')) {
974
+			define('DONOTCACHEPAGE', true);
975
+		}
976
+		if ( ! defined('DONOTCACHCEOBJECT')) {
977
+			define('DONOTCACHCEOBJECT', true);
978
+		}
979
+		if ( ! defined('DONOTCACHEDB')) {
980
+			define('DONOTCACHEDB', true);
981
+		}
982
+		// add no cache headers
983
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
984
+		// plus a little extra for nginx and Google Chrome
985
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
986
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
987
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 *    extra_nocache_headers
994
+	 *
995
+	 * @access    public
996
+	 * @param $headers
997
+	 * @return    array
998
+	 */
999
+	public static function extra_nocache_headers($headers)
1000
+	{
1001
+		// for NGINX
1002
+		$headers['X-Accel-Expires'] = 0;
1003
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1004
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1005
+		return $headers;
1006
+	}
1007
+
1008
+
1009
+
1010
+	/**
1011
+	 *    nocache_headers
1012
+	 *
1013
+	 * @access    public
1014
+	 * @return    void
1015
+	 */
1016
+	public static function nocache_headers()
1017
+	{
1018
+		nocache_headers();
1019
+	}
1020
+
1021
+
1022
+
1023
+	/**
1024
+	 *    espresso_toolbar_items
1025
+	 *
1026
+	 * @access public
1027
+	 * @param  WP_Admin_Bar $admin_bar
1028
+	 * @return void
1029
+	 */
1030
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1031
+	{
1032
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1033
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1034
+			|| defined('DOING_AJAX')
1035
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1036
+		) {
1037
+			return;
1038
+		}
1039
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1040
+		$menu_class = 'espresso_menu_item_class';
1041
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1042
+		//because they're only defined in each of their respective constructors
1043
+		//and this might be a frontend request, in which case they aren't available
1044
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1045
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1046
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1047
+		//Top Level
1048
+		$admin_bar->add_menu(array(
1049
+			'id'    => 'espresso-toolbar',
1050
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1051
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1052
+					   . '</span>',
1053
+			'href'  => $events_admin_url,
1054
+			'meta'  => array(
1055
+				'title' => __('Event Espresso', 'event_espresso'),
1056
+				'class' => $menu_class . 'first',
1057
+			),
1058
+		));
1059
+		//Events
1060
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1061
+			$admin_bar->add_menu(array(
1062
+				'id'     => 'espresso-toolbar-events',
1063
+				'parent' => 'espresso-toolbar',
1064
+				'title'  => __('Events', 'event_espresso'),
1065
+				'href'   => $events_admin_url,
1066
+				'meta'   => array(
1067
+					'title'  => __('Events', 'event_espresso'),
1068
+					'target' => '',
1069
+					'class'  => $menu_class,
1070
+				),
1071
+			));
1072
+		}
1073
+		if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1074
+			//Events Add New
1075
+			$admin_bar->add_menu(array(
1076
+				'id'     => 'espresso-toolbar-events-new',
1077
+				'parent' => 'espresso-toolbar-events',
1078
+				'title'  => __('Add New', 'event_espresso'),
1079
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1080
+				'meta'   => array(
1081
+					'title'  => __('Add New', 'event_espresso'),
1082
+					'target' => '',
1083
+					'class'  => $menu_class,
1084
+				),
1085
+			));
1086
+		}
1087
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1088
+			//Current post
1089
+			global $post;
1090
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1091
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1092
+			) {
1093
+				//Events Edit Current Event
1094
+				$admin_bar->add_menu(array(
1095
+					'id'     => 'espresso-toolbar-events-edit',
1096
+					'parent' => 'espresso-toolbar-events',
1097
+					'title'  => __('Edit Event', 'event_espresso'),
1098
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1099
+						$events_admin_url),
1100
+					'meta'   => array(
1101
+						'title'  => __('Edit Event', 'event_espresso'),
1102
+						'target' => '',
1103
+						'class'  => $menu_class,
1104
+					),
1105
+				));
1106
+			}
1107
+		}
1108
+		//Events View
1109
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1110
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1111
+		) {
1112
+			$admin_bar->add_menu(array(
1113
+				'id'     => 'espresso-toolbar-events-view',
1114
+				'parent' => 'espresso-toolbar-events',
1115
+				'title'  => __('View', 'event_espresso'),
1116
+				'href'   => $events_admin_url,
1117
+				'meta'   => array(
1118
+					'title'  => __('View', 'event_espresso'),
1119
+					'target' => '',
1120
+					'class'  => $menu_class,
1121
+				),
1122
+			));
1123
+		}
1124
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1125
+			//Events View All
1126
+			$admin_bar->add_menu(array(
1127
+				'id'     => 'espresso-toolbar-events-all',
1128
+				'parent' => 'espresso-toolbar-events-view',
1129
+				'title'  => __('All', 'event_espresso'),
1130
+				'href'   => $events_admin_url,
1131
+				'meta'   => array(
1132
+					'title'  => __('All', 'event_espresso'),
1133
+					'target' => '',
1134
+					'class'  => $menu_class,
1135
+				),
1136
+			));
1137
+		}
1138
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1139
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1140
+		) {
1141
+			//Events View Today
1142
+			$admin_bar->add_menu(array(
1143
+				'id'     => 'espresso-toolbar-events-today',
1144
+				'parent' => 'espresso-toolbar-events-view',
1145
+				'title'  => __('Today', 'event_espresso'),
1146
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1147
+					$events_admin_url),
1148
+				'meta'   => array(
1149
+					'title'  => __('Today', 'event_espresso'),
1150
+					'target' => '',
1151
+					'class'  => $menu_class,
1152
+				),
1153
+			));
1154
+		}
1155
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1156
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1157
+		) {
1158
+			//Events View This Month
1159
+			$admin_bar->add_menu(array(
1160
+				'id'     => 'espresso-toolbar-events-month',
1161
+				'parent' => 'espresso-toolbar-events-view',
1162
+				'title'  => __('This Month', 'event_espresso'),
1163
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1164
+					$events_admin_url),
1165
+				'meta'   => array(
1166
+					'title'  => __('This Month', 'event_espresso'),
1167
+					'target' => '',
1168
+					'class'  => $menu_class,
1169
+				),
1170
+			));
1171
+		}
1172
+		//Registration Overview
1173
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1174
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1175
+		) {
1176
+			$admin_bar->add_menu(array(
1177
+				'id'     => 'espresso-toolbar-registrations',
1178
+				'parent' => 'espresso-toolbar',
1179
+				'title'  => __('Registrations', 'event_espresso'),
1180
+				'href'   => $reg_admin_url,
1181
+				'meta'   => array(
1182
+					'title'  => __('Registrations', 'event_espresso'),
1183
+					'target' => '',
1184
+					'class'  => $menu_class,
1185
+				),
1186
+			));
1187
+		}
1188
+		//Registration Overview Today
1189
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1190
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1191
+		) {
1192
+			$admin_bar->add_menu(array(
1193
+				'id'     => 'espresso-toolbar-registrations-today',
1194
+				'parent' => 'espresso-toolbar-registrations',
1195
+				'title'  => __('Today', 'event_espresso'),
1196
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1197
+					$reg_admin_url),
1198
+				'meta'   => array(
1199
+					'title'  => __('Today', 'event_espresso'),
1200
+					'target' => '',
1201
+					'class'  => $menu_class,
1202
+				),
1203
+			));
1204
+		}
1205
+		//Registration Overview Today Completed
1206
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1207
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1208
+		) {
1209
+			$admin_bar->add_menu(array(
1210
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1211
+				'parent' => 'espresso-toolbar-registrations-today',
1212
+				'title'  => __('Approved', 'event_espresso'),
1213
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1214
+					'action'      => 'default',
1215
+					'status'      => 'today',
1216
+					'_reg_status' => EEM_Registration::status_id_approved,
1217
+				), $reg_admin_url),
1218
+				'meta'   => array(
1219
+					'title'  => __('Approved', 'event_espresso'),
1220
+					'target' => '',
1221
+					'class'  => $menu_class,
1222
+				),
1223
+			));
1224
+		}
1225
+		//Registration Overview Today Pending\
1226
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1227
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1228
+		) {
1229
+			$admin_bar->add_menu(array(
1230
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1231
+				'parent' => 'espresso-toolbar-registrations-today',
1232
+				'title'  => __('Pending', 'event_espresso'),
1233
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1234
+					'action'     => 'default',
1235
+					'status'     => 'today',
1236
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1237
+				), $reg_admin_url),
1238
+				'meta'   => array(
1239
+					'title'  => __('Pending Payment', 'event_espresso'),
1240
+					'target' => '',
1241
+					'class'  => $menu_class,
1242
+				),
1243
+			));
1244
+		}
1245
+		//Registration Overview Today Incomplete
1246
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1247
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1248
+		) {
1249
+			$admin_bar->add_menu(array(
1250
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1251
+				'parent' => 'espresso-toolbar-registrations-today',
1252
+				'title'  => __('Not Approved', 'event_espresso'),
1253
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1254
+					'action'      => 'default',
1255
+					'status'      => 'today',
1256
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1257
+				), $reg_admin_url),
1258
+				'meta'   => array(
1259
+					'title'  => __('Not Approved', 'event_espresso'),
1260
+					'target' => '',
1261
+					'class'  => $menu_class,
1262
+				),
1263
+			));
1264
+		}
1265
+		//Registration Overview Today Incomplete
1266
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1267
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1268
+		) {
1269
+			$admin_bar->add_menu(array(
1270
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1271
+				'parent' => 'espresso-toolbar-registrations-today',
1272
+				'title'  => __('Cancelled', 'event_espresso'),
1273
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1274
+					'action'      => 'default',
1275
+					'status'      => 'today',
1276
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1277
+				), $reg_admin_url),
1278
+				'meta'   => array(
1279
+					'title'  => __('Cancelled', 'event_espresso'),
1280
+					'target' => '',
1281
+					'class'  => $menu_class,
1282
+				),
1283
+			));
1284
+		}
1285
+		//Registration Overview This Month
1286
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1287
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1288
+		) {
1289
+			$admin_bar->add_menu(array(
1290
+				'id'     => 'espresso-toolbar-registrations-month',
1291
+				'parent' => 'espresso-toolbar-registrations',
1292
+				'title'  => __('This Month', 'event_espresso'),
1293
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1294
+					$reg_admin_url),
1295
+				'meta'   => array(
1296
+					'title'  => __('This Month', 'event_espresso'),
1297
+					'target' => '',
1298
+					'class'  => $menu_class,
1299
+				),
1300
+			));
1301
+		}
1302
+		//Registration Overview This Month Approved
1303
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1304
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1305
+		) {
1306
+			$admin_bar->add_menu(array(
1307
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1308
+				'parent' => 'espresso-toolbar-registrations-month',
1309
+				'title'  => __('Approved', 'event_espresso'),
1310
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1311
+					'action'      => 'default',
1312
+					'status'      => 'month',
1313
+					'_reg_status' => EEM_Registration::status_id_approved,
1314
+				), $reg_admin_url),
1315
+				'meta'   => array(
1316
+					'title'  => __('Approved', 'event_espresso'),
1317
+					'target' => '',
1318
+					'class'  => $menu_class,
1319
+				),
1320
+			));
1321
+		}
1322
+		//Registration Overview This Month Pending
1323
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1324
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1325
+		) {
1326
+			$admin_bar->add_menu(array(
1327
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1328
+				'parent' => 'espresso-toolbar-registrations-month',
1329
+				'title'  => __('Pending', 'event_espresso'),
1330
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1331
+					'action'      => 'default',
1332
+					'status'      => 'month',
1333
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1334
+				), $reg_admin_url),
1335
+				'meta'   => array(
1336
+					'title'  => __('Pending', 'event_espresso'),
1337
+					'target' => '',
1338
+					'class'  => $menu_class,
1339
+				),
1340
+			));
1341
+		}
1342
+		//Registration Overview This Month Not Approved
1343
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1344
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1345
+		) {
1346
+			$admin_bar->add_menu(array(
1347
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1348
+				'parent' => 'espresso-toolbar-registrations-month',
1349
+				'title'  => __('Not Approved', 'event_espresso'),
1350
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1351
+					'action'      => 'default',
1352
+					'status'      => 'month',
1353
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1354
+				), $reg_admin_url),
1355
+				'meta'   => array(
1356
+					'title'  => __('Not Approved', 'event_espresso'),
1357
+					'target' => '',
1358
+					'class'  => $menu_class,
1359
+				),
1360
+			));
1361
+		}
1362
+		//Registration Overview This Month Cancelled
1363
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1364
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1365
+		) {
1366
+			$admin_bar->add_menu(array(
1367
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1368
+				'parent' => 'espresso-toolbar-registrations-month',
1369
+				'title'  => __('Cancelled', 'event_espresso'),
1370
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1371
+					'action'      => 'default',
1372
+					'status'      => 'month',
1373
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1374
+				), $reg_admin_url),
1375
+				'meta'   => array(
1376
+					'title'  => __('Cancelled', 'event_espresso'),
1377
+					'target' => '',
1378
+					'class'  => $menu_class,
1379
+				),
1380
+			));
1381
+		}
1382
+		//Extensions & Services
1383
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1384
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1385
+		) {
1386
+			$admin_bar->add_menu(array(
1387
+				'id'     => 'espresso-toolbar-extensions-and-services',
1388
+				'parent' => 'espresso-toolbar',
1389
+				'title'  => __('Extensions & Services', 'event_espresso'),
1390
+				'href'   => $extensions_admin_url,
1391
+				'meta'   => array(
1392
+					'title'  => __('Extensions & Services', 'event_espresso'),
1393
+					'target' => '',
1394
+					'class'  => $menu_class,
1395
+				),
1396
+			));
1397
+		}
1398
+	}
1399
+
1400
+
1401
+
1402
+	/**
1403
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1404
+	 * never returned with the function.
1405
+	 *
1406
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1407
+	 * @return array
1408
+	 */
1409
+	public function remove_pages_from_wp_list_pages($exclude_array)
1410
+	{
1411
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1412
+	}
1413
+
1414
+
1415
+
1416
+
1417
+
1418
+
1419
+	/***********************************************        WP_ENQUEUE_SCRIPTS HOOK         ***********************************************/
1420
+	/**
1421
+	 *    wp_enqueue_scripts
1422
+	 *
1423
+	 * @access    public
1424
+	 * @return    void
1425
+	 */
1426
+	public function wp_enqueue_scripts()
1427
+	{
1428
+		// unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' );
1429
+		if (apply_filters('FHEE_load_EE_System_scripts', true)) {
1430
+			// jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1431
+			if (apply_filters('FHEE_load_jquery_validate', false)) {
1432
+				// register jQuery Validate and additional methods
1433
+				wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1434
+					array('jquery'), '1.15.0', true);
1435
+				wp_register_script('jquery-validate-extra-methods',
1436
+					EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1437
+					array('jquery', 'jquery-validate'), '1.15.0', true);
1438
+			}
1439
+		}
1440
+	}
1441 1441
 
1442 1442
 
1443 1443
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     {
183 183
         // set autoloaders for all of the classes implementing EEI_Plugin_API
184 184
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
185
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
185
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
186 186
         //load and setup EE_Capabilities
187 187
         $this->registry->load_core('Capabilities');
188 188
         //caps need to be initialized on every request so that capability maps are set.
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
                 && $_GET['activate'] === 'true'
206 206
             )
207 207
         ) {
208
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
208
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
209 209
         }
210 210
         do_action('AHEE__EE_System__load_espresso_addons__complete');
211 211
     }
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
     private function _parse_model_names()
688 688
     {
689 689
         //get all the files in the EE_MODELS folder that end in .model.php
690
-        $models = glob(EE_MODELS . '*.model.php');
690
+        $models = glob(EE_MODELS.'*.model.php');
691 691
         $model_names = array();
692 692
         $non_abstract_db_models = array();
693 693
         foreach ($models as $model) {
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
      */
716 716
     private function _maybe_brew_regular()
717 717
     {
718
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
719
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
718
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
719
+            require_once EE_CAFF_PATH.'brewing_regular.php';
720 720
         }
721 721
     }
722 722
 
@@ -757,8 +757,8 @@  discard block
 block discarded – undo
757 757
                 'event_espresso');
758 758
             $msg .= '<ul>';
759 759
             foreach ($class_names as $class_name) {
760
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
761
-                        $class_name) . '</b></li>';
760
+                $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
761
+                        $class_name).'</b></li>';
762 762
             }
763 763
             $msg .= '</ul>';
764 764
             $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
             'href'  => $events_admin_url,
1054 1054
             'meta'  => array(
1055 1055
                 'title' => __('Event Espresso', 'event_espresso'),
1056
-                'class' => $menu_class . 'first',
1056
+                'class' => $menu_class.'first',
1057 1057
             ),
1058 1058
         ));
1059 1059
         //Events
@@ -1430,10 +1430,10 @@  discard block
 block discarded – undo
1430 1430
             // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
1431 1431
             if (apply_filters('FHEE_load_jquery_validate', false)) {
1432 1432
                 // register jQuery Validate and additional methods
1433
-                wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
1433
+                wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
1434 1434
                     array('jquery'), '1.15.0', true);
1435 1435
                 wp_register_script('jquery-validate-extra-methods',
1436
-                    EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
1436
+                    EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
1437 1437
                     array('jquery', 'jquery-validate'), '1.15.0', true);
1438 1438
             }
1439 1439
         }
Please login to merge, or discard this patch.
core/EE_Registry.core.php 1 patch
Indentation   +1336 added lines, -1336 removed lines patch added patch discarded remove patch
@@ -16,1372 +16,1372 @@
 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
-     * @return \EE_Registry
224
-     */
225
-    protected function __construct(\EE_Dependency_Map $dependency_map)
226
-    {
227
-        $this->_dependency_map = $dependency_map;
228
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * initialize
235
-     */
236
-    public function initialize()
237
-    {
238
-        $this->_class_abbreviations = apply_filters(
239
-            'FHEE__EE_Registry____construct___class_abbreviations',
240
-            array(
241
-                'EE_Config'                                       => 'CFG',
242
-                'EE_Session'                                      => 'SSN',
243
-                'EE_Capabilities'                                 => 'CAP',
244
-                'EE_Cart'                                         => 'CART',
245
-                'EE_Network_Config'                               => 'NET_CFG',
246
-                'EE_Request_Handler'                              => 'REQ',
247
-                'EE_Message_Resource_Manager'                     => 'MRM',
248
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
-            )
250
-        );
251
-        // class library
252
-        $this->LIB = new stdClass();
253
-        $this->addons = new stdClass();
254
-        $this->modules = new stdClass();
255
-        $this->shortcodes = new stdClass();
256
-        $this->widgets = new stdClass();
257
-        $this->load_core('Base', array(), true);
258
-        // add our request and response objects to the cache
259
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
260
-        $this->_set_cached_class(
261
-            $request_loader(),
262
-            'EE_Request'
263
-        );
264
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
265
-        $this->_set_cached_class(
266
-            $response_loader(),
267
-            'EE_Response'
268
-        );
269
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     *    init
276
-     *
277
-     * @access    public
278
-     * @return    void
279
-     */
280
-    public function init()
281
-    {
282
-        $this->AssetsRegistry = new Registry();
283
-        // Get current page protocol
284
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
-        // Output admin-ajax.php URL with same protocol as current page
286
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * localize_i18n_js_strings
294
-     *
295
-     * @return string
296
-     */
297
-    public static function localize_i18n_js_strings()
298
-    {
299
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
-        foreach ($i18n_js_strings as $key => $value) {
301
-            if (is_scalar($value)) {
302
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
-            }
304
-        }
305
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * @param mixed string | EED_Module $module
312
-     */
313
-    public function add_module($module)
314
-    {
315
-        if ($module instanceof EED_Module) {
316
-            $module_class = get_class($module);
317
-            $this->modules->{$module_class} = $module;
318
-        } else {
319
-            if ( ! class_exists('EE_Module_Request_Router')) {
320
-                $this->load_core('Module_Request_Router');
321
-            }
322
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
-        }
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * @param string $module_name
330
-     * @return mixed EED_Module | NULL
331
-     */
332
-    public function get_module($module_name = '')
333
-    {
334
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     *    loads core classes - must be singletons
341
-     *
342
-     * @access    public
343
-     * @param string $class_name - simple class name ie: session
344
-     * @param mixed  $arguments
345
-     * @param bool   $load_only
346
-     * @return mixed
347
-     */
348
-    public function load_core($class_name, $arguments = array(), $load_only = false)
349
-    {
350
-        $core_paths = apply_filters(
351
-            'FHEE__EE_Registry__load_core__core_paths',
352
-            array(
353
-                EE_CORE,
354
-                EE_ADMIN,
355
-                EE_CPTS,
356
-                EE_CORE . 'data_migration_scripts' . DS,
357
-                EE_CORE . 'request_stack' . DS,
358
-                EE_CORE . 'middleware' . DS,
359
-            )
360
-        );
361
-        // retrieve instantiated class
362
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     *    loads service classes
369
-     *
370
-     * @access    public
371
-     * @param string $class_name - simple class name ie: session
372
-     * @param mixed  $arguments
373
-     * @param bool   $load_only
374
-     * @return mixed
375
-     */
376
-    public function load_service($class_name, $arguments = array(), $load_only = false)
377
-    {
378
-        $service_paths = apply_filters(
379
-            'FHEE__EE_Registry__load_service__service_paths',
380
-            array(
381
-                EE_CORE . 'services' . DS,
382
-            )
383
-        );
384
-        // retrieve instantiated class
385
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     *    loads data_migration_scripts
392
-     *
393
-     * @access    public
394
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
-     * @param mixed  $arguments
396
-     * @return EE_Data_Migration_Script_Base|mixed
397
-     */
398
-    public function load_dms($class_name, $arguments = array())
399
-    {
400
-        // retrieve instantiated class
401
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     *    loads object creating classes - must be singletons
408
-     *
409
-     * @param string $class_name - simple class name ie: attendee
410
-     * @param mixed  $arguments  - an array of arguments to pass to the class
411
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
-     * @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)
413
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
-     * @return EE_Base_Class | bool
415
-     */
416
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
-    {
418
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
-            EE_CORE,
420
-            EE_CLASSES,
421
-            EE_BUSINESS,
422
-        ));
423
-        // retrieve instantiated class
424
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     *    loads helper classes - must be singletons
431
-     *
432
-     * @param string $class_name - simple class name ie: price
433
-     * @param mixed  $arguments
434
-     * @param bool   $load_only
435
-     * @return EEH_Base | bool
436
-     */
437
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
438
-    {
439
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
-        // retrieve instantiated class
442
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     *    loads core classes - must be singletons
449
-     *
450
-     * @access    public
451
-     * @param string $class_name - simple class name ie: session
452
-     * @param mixed  $arguments
453
-     * @param bool   $load_only
454
-     * @param bool   $cache      whether to cache the object or not.
455
-     * @return mixed
456
-     */
457
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
-    {
459
-        $paths = array(
460
-            EE_LIBRARIES,
461
-            EE_LIBRARIES . 'messages' . DS,
462
-            EE_LIBRARIES . 'shortcodes' . DS,
463
-            EE_LIBRARIES . 'qtips' . DS,
464
-            EE_LIBRARIES . 'payment_methods' . DS,
465
-        );
466
-        // retrieve instantiated class
467
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     *    loads model classes - must be singletons
474
-     *
475
-     * @param string $class_name - simple class name ie: price
476
-     * @param mixed  $arguments
477
-     * @param bool   $load_only
478
-     * @return EEM_Base | bool
479
-     */
480
-    public function load_model($class_name, $arguments = array(), $load_only = false)
481
-    {
482
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
-            EE_MODELS,
484
-            EE_CORE,
485
-        ));
486
-        // retrieve instantiated class
487
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     *    loads model classes - must be singletons
494
-     *
495
-     * @param string $class_name - simple class name ie: price
496
-     * @param mixed  $arguments
497
-     * @param bool   $load_only
498
-     * @return mixed | bool
499
-     */
500
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
-    {
502
-        $paths = array(
503
-            EE_MODELS . 'fields' . DS,
504
-            EE_MODELS . 'helpers' . DS,
505
-            EE_MODELS . 'relations' . DS,
506
-            EE_MODELS . 'strategies' . DS,
507
-        );
508
-        // retrieve instantiated class
509
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Determines if $model_name is the name of an actual EE model.
516
-     *
517
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
-     * @return boolean
519
-     */
520
-    public function is_model_name($model_name)
521
-    {
522
-        return isset($this->models[$model_name]) ? true : false;
523
-    }
524
-
525
-
526
-
527
-    /**
528
-     *    generic class loader
529
-     *
530
-     * @param string $path_to_file - directory path to file location, not including filename
531
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
532
-     * @param string $type         - file type - core? class? helper? model?
533
-     * @param mixed  $arguments
534
-     * @param bool   $load_only
535
-     * @return mixed
536
-     */
537
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
-    {
539
-        // retrieve instantiated class
540
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     *    load_addon
547
-     *
548
-     * @param string $path_to_file - directory path to file location, not including filename
549
-     * @param string $class_name   - full class name  ie:  My_Class
550
-     * @param string $type         - file type - core? class? helper? model?
551
-     * @param mixed  $arguments
552
-     * @param bool   $load_only
553
-     * @return EE_Addon
554
-     */
555
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
-    {
557
-        // retrieve instantiated class
558
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
-    }
560
-
561
-
562
-
563
-    /**
564
-     * instantiates, caches, and automatically resolves dependencies
565
-     * for classes that use a Fully Qualified Class Name.
566
-     * if the class is not capable of being loaded using PSR-4 autoloading,
567
-     * then you need to use one of the existing load_*() methods
568
-     * which can resolve the classname and filepath from the passed arguments
569
-     *
570
-     * @param bool|string $class_name   Fully Qualified Class Name
571
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
-     * @param bool        $cache        whether to cache the instantiated object for reuse
573
-     * @param bool        $from_db      some classes are instantiated from the db
574
-     *                                  and thus call a different method to instantiate
575
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
-     * @return mixed                    null = failure to load or instantiate class object.
578
-     *                                  object = class loaded and instantiated successfully.
579
-     *                                  bool = fail or success when $load_only is true
580
-     */
581
-    public function create(
582
-        $class_name = false,
583
-        $arguments = array(),
584
-        $cache = false,
585
-        $from_db = false,
586
-        $load_only = false,
587
-        $addon = false
588
-    ) {
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
-        // strip php file extension
652
-        $class_name = str_replace('.php', '', trim($class_name));
653
-        // does the class have a prefix ?
654
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
-            // make sure $class_prefix is uppercase
656
-            $class_prefix = strtoupper(trim($class_prefix));
657
-            // add class prefix ONCE!!!
658
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
-        }
660
-        $class_name = $this->_dependency_map->get_alias($class_name);
661
-        $class_exists = class_exists($class_name);
662
-        // if we're only loading the class and it already exists, then let's just return true immediately
663
-        if ($load_only && $class_exists) {
664
-            return true;
665
-        }
666
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
-        if ($this->_cache_on && $cache && ! $load_only) {
670
-            // return object if it's already cached
671
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
-            if ($cached_class !== null) {
673
-                return $cached_class;
674
-            }
675
-        }
676
-        // if the class doesn't already exist.. then we need to try and find the file and load it
677
-        if ( ! $class_exists) {
678
-            // get full path to file
679
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
680
-            // load the file
681
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
-            // if loading failed, or we are only loading a file but NOT instantiating an object
683
-            if ( ! $loaded || $load_only) {
684
-                // return boolean if only loading, or null if an object was expected
685
-                return $load_only ? $loaded : null;
686
-            }
687
-        }
688
-        // instantiate the requested object
689
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
-        if ($this->_cache_on && $cache) {
691
-            // save it for later... kinda like gum  { : $
692
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
-        }
694
-        $this->_cache_on = true;
695
-        return $class_obj;
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * _get_cached_class
702
-     * attempts to find a cached version of the requested class
703
-     * by looking in the following places:
704
-     *        $this->{$class_abbreviation}            ie:    $this->CART
705
-     *        $this->{$class_name}                        ie:    $this->Some_Class
706
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
707
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
708
-     *
709
-     * @access protected
710
-     * @param string $class_name
711
-     * @param string $class_prefix
712
-     * @return mixed
713
-     */
714
-    protected function _get_cached_class($class_name, $class_prefix = '')
715
-    {
716
-        if (isset($this->_class_abbreviations[$class_name])) {
717
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
718
-        } else {
719
-            // have to specify something, but not anything that will conflict
720
-            $class_abbreviation = 'FANCY_BATMAN_PANTS';
721
-        }
722
-        // check if class has already been loaded, and return it if it has been
723
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
-            return $this->{$class_abbreviation};
725
-        } else if (isset ($this->{$class_name})) {
726
-            return $this->{$class_name};
727
-        } else if (isset ($this->LIB->{$class_name})) {
728
-            return $this->LIB->{$class_name};
729
-        } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
730
-            return $this->addons->{$class_name};
731
-        }
732
-        return null;
733
-    }
734
-
735
-
736
-
737
-    /**
738
-     * _resolve_path
739
-     * attempts to find a full valid filepath for the requested class.
740
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
741
-     * then returns that path if the target file has been found and is readable
742
-     *
743
-     * @access protected
744
-     * @param string $class_name
745
-     * @param string $type
746
-     * @param array  $file_paths
747
-     * @return string | bool
748
-     */
749
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
750
-    {
751
-        // make sure $file_paths is an array
752
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
753
-        // cycle thru paths
754
-        foreach ($file_paths as $key => $file_path) {
755
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
756
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
757
-            // prep file type
758
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
759
-            // build full file path
760
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
761
-            //does the file exist and can be read ?
762
-            if (is_readable($file_paths[$key])) {
763
-                return $file_paths[$key];
764
-            }
765
-        }
766
-        return false;
767
-    }
768
-
769
-
770
-
771
-    /**
772
-     * _require_file
773
-     * basically just performs a require_once()
774
-     * but with some error handling
775
-     *
776
-     * @access protected
777
-     * @param  string $path
778
-     * @param  string $class_name
779
-     * @param  string $type
780
-     * @param  array  $file_paths
781
-     * @return boolean
782
-     * @throws \EE_Error
783
-     */
784
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
785
-    {
786
-        // don't give up! you gotta...
787
-        try {
788
-            //does the file exist and can it be read ?
789
-            if ( ! $path) {
790
-                // so sorry, can't find the file
791
-                throw new EE_Error (
792
-                    sprintf(
793
-                        __('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'),
794
-                        trim($type, '.'),
795
-                        $class_name,
796
-                        '<br />' . implode(',<br />', $file_paths)
797
-                    )
798
-                );
799
-            }
800
-            // get the file
801
-            require_once($path);
802
-            // if the class isn't already declared somewhere
803
-            if (class_exists($class_name, false) === false) {
804
-                // so sorry, not a class
805
-                throw new EE_Error(
806
-                    sprintf(
807
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
808
-                        $type,
809
-                        $path,
810
-                        $class_name
811
-                    )
812
-                );
813
-            }
814
-        } catch (EE_Error $e) {
815
-            $e->get_error();
816
-            return false;
817
-        }
818
-        return true;
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * _create_object
825
-     * Attempts to instantiate the requested class via any of the
826
-     * commonly used instantiation methods employed throughout EE.
827
-     * The priority for instantiation is as follows:
828
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
829
-     *        - model objects via their 'new_instance_from_db' method
830
-     *        - model objects via their 'new_instance' method
831
-     *        - "singleton" classes" via their 'instance' method
832
-     *    - standard instantiable classes via their __constructor
833
-     * Prior to instantiation, if the classname exists in the dependency_map,
834
-     * then the constructor for the requested class will be examined to determine
835
-     * if any dependencies exist, and if they can be injected.
836
-     * If so, then those classes will be added to the array of arguments passed to the constructor
837
-     *
838
-     * @access protected
839
-     * @param string $class_name
840
-     * @param array  $arguments
841
-     * @param string $type
842
-     * @param bool   $from_db
843
-     * @return null | object
844
-     * @throws \EE_Error
845
-     */
846
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
847
-    {
848
-        $class_obj = null;
849
-        $instantiation_mode = '0) none';
850
-        // don't give up! you gotta...
851
-        try {
852
-            // create reflection
853
-            $reflector = $this->get_ReflectionClass($class_name);
854
-            // make sure arguments are an array
855
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
856
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
857
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
858
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
859
-                ? $arguments
860
-                : array($arguments);
861
-            // attempt to inject dependencies ?
862
-            if ($this->_dependency_map->has($class_name)) {
863
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
864
-            }
865
-            // instantiate the class if possible
866
-            if ($reflector->isAbstract()) {
867
-                // nothing to instantiate, loading file was enough
868
-                // does not throw an exception so $instantiation_mode is unused
869
-                // $instantiation_mode = "1) no constructor abstract class";
870
-                $class_obj = true;
871
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
872
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
873
-                $instantiation_mode = "2) no constructor but instantiable";
874
-                $class_obj = $reflector->newInstance();
875
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
876
-                $instantiation_mode = "3) new_instance_from_db()";
877
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
878
-            } else if (method_exists($class_name, 'new_instance')) {
879
-                $instantiation_mode = "4) new_instance()";
880
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
881
-            } else if (method_exists($class_name, 'instance')) {
882
-                $instantiation_mode = "5) instance()";
883
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
884
-            } else if ($reflector->isInstantiable()) {
885
-                $instantiation_mode = "6) constructor";
886
-                $class_obj = $reflector->newInstanceArgs($arguments);
887
-            } else {
888
-                // heh ? something's not right !
889
-                throw new EE_Error(
890
-                    sprintf(
891
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
892
-                        $type,
893
-                        $class_name
894
-                    )
895
-                );
896
-            }
897
-        } catch (Exception $e) {
898
-            if ( ! $e instanceof EE_Error) {
899
-                $e = new EE_Error(
900
-                    sprintf(
901
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
902
-                        $class_name,
903
-                        '<br />',
904
-                        $e->getMessage(),
905
-                        $instantiation_mode
906
-                    )
907
-                );
908
-            }
909
-            $e->get_error();
910
-        }
911
-        return $class_obj;
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
918
-     * @param array $array
919
-     * @return bool
920
-     */
921
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
922
-    {
923
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * getReflectionClass
930
-     * checks if a ReflectionClass object has already been generated for a class
931
-     * and returns that instead of creating a new one
932
-     *
933
-     * @access public
934
-     * @param string $class_name
935
-     * @return ReflectionClass
936
-     */
937
-    public function get_ReflectionClass($class_name)
938
-    {
939
-        if (
940
-            ! isset($this->_reflectors[$class_name])
941
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
942
-        ) {
943
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
944
-        }
945
-        return $this->_reflectors[$class_name];
946
-    }
947
-
948
-
949
-
950
-    /**
951
-     * _resolve_dependencies
952
-     * examines the constructor for the requested class to determine
953
-     * if any dependencies exist, and if they can be injected.
954
-     * If so, then those classes will be added to the array of arguments passed to the constructor
955
-     * PLZ NOTE: this is achieved by type hinting the constructor params
956
-     * For example:
957
-     *        if attempting to load a class "Foo" with the following constructor:
958
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
959
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
960
-     *        but only IF they are NOT already present in the incoming arguments array,
961
-     *        and the correct classes can be loaded
962
-     *
963
-     * @access protected
964
-     * @param ReflectionClass $reflector
965
-     * @param string          $class_name
966
-     * @param array           $arguments
967
-     * @return array
968
-     * @throws \ReflectionException
969
-     */
970
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
971
-    {
972
-        // let's examine the constructor
973
-        $constructor = $reflector->getConstructor();
974
-        // whu? huh? nothing?
975
-        if ( ! $constructor) {
976
-            return $arguments;
977
-        }
978
-        // get constructor parameters
979
-        $params = $constructor->getParameters();
980
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
981
-        $argument_keys = array_keys($arguments);
982
-        // now loop thru all of the constructors expected parameters
983
-        foreach ($params as $index => $param) {
984
-            // is this a dependency for a specific class ?
985
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
986
-            if (
987
-                // param is not even a class
988
-                empty($param_class)
989
-                // and something already exists in the incoming arguments for this param
990
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
991
-            ) {
992
-                // so let's skip this argument and move on to the next
993
-                continue;
994
-            } else if (
995
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
996
-                ! empty($param_class)
997
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
998
-                && $arguments[$argument_keys[$index]] instanceof $param_class
999
-            ) {
1000
-                // skip this argument and move on to the next
1001
-                continue;
1002
-            } else if (
1003
-                // parameter is type hinted as a class, and should be injected
1004
-                ! empty($param_class)
1005
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1006
-            ) {
1007
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1008
-            } else {
1009
-                try {
1010
-                    $arguments[$index] = $param->getDefaultValue();
1011
-                } catch (ReflectionException $e) {
1012
-                    throw new ReflectionException(
1013
-                        sprintf(
1014
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1015
-                            $e->getMessage(),
1016
-                            $param->getName()
1017
-                        )
1018
-                    );
1019
-                }
1020
-            }
1021
-        }
1022
-        return $arguments;
1023
-    }
1024
-
1025
-
1026
-
1027
-    /**
1028
-     * @access protected
1029
-     * @param string $class_name
1030
-     * @param string $param_class
1031
-     * @param array  $arguments
1032
-     * @param mixed  $index
1033
-     * @return array
1034
-     */
1035
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1036
-    {
1037
-        $dependency = null;
1038
-        // should dependency be loaded from cache ?
1039
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1040
-                    !== EE_Dependency_Map::load_new_object
1041
-            ? true
1042
-            : false;
1043
-        // we might have a dependency...
1044
-        // let's MAYBE try and find it in our cache if that's what's been requested
1045
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1046
-        // and grab it if it exists
1047
-        if ($cached_class instanceof $param_class) {
1048
-            $dependency = $cached_class;
1049
-        } else if ($param_class != $class_name) {
1050
-            // obtain the loader method from the dependency map
1051
-            $loader = $this->_dependency_map->class_loader($param_class);
1052
-            // is loader a custom closure ?
1053
-            if ($loader instanceof Closure) {
1054
-                $dependency = $loader();
1055
-            } else {
1056
-                // set the cache on property for the recursive loading call
1057
-                $this->_cache_on = $cache_on;
1058
-                // if not, then let's try and load it via the registry
1059
-                if (method_exists($this, $loader)) {
1060
-                    $dependency = $this->{$loader}($param_class);
1061
-                } else {
1062
-                    $dependency = $this->create($param_class, array(), $cache_on);
1063
-                }
1064
-            }
1065
-        }
1066
-        // did we successfully find the correct dependency ?
1067
-        if ($dependency instanceof $param_class) {
1068
-            // then let's inject it into the incoming array of arguments at the correct location
1069
-            if (isset($argument_keys[$index])) {
1070
-                $arguments[$argument_keys[$index]] = $dependency;
1071
-            } else {
1072
-                $arguments[$index] = $dependency;
1073
-            }
1074
-        }
1075
-        return $arguments;
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * _set_cached_class
1082
-     * attempts to cache the instantiated class locally
1083
-     * in one of the following places, in the following order:
1084
-     *        $this->{class_abbreviation}   ie:    $this->CART
1085
-     *        $this->{$class_name}          ie:    $this->Some_Class
1086
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1087
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1088
-     *
1089
-     * @access protected
1090
-     * @param object $class_obj
1091
-     * @param string $class_name
1092
-     * @param string $class_prefix
1093
-     * @param bool   $from_db
1094
-     * @return void
1095
-     */
1096
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1097
-    {
1098
-        if (empty($class_obj)) {
1099
-            return;
1100
-        }
1101
-        // return newly instantiated class
1102
-        if (isset($this->_class_abbreviations[$class_name])) {
1103
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1104
-            $this->{$class_abbreviation} = $class_obj;
1105
-        } else if (property_exists($this, $class_name)) {
1106
-            $this->{$class_name} = $class_obj;
1107
-        } else if ($class_prefix == 'addon') {
1108
-            $this->addons->{$class_name} = $class_obj;
1109
-        } else if ( ! $from_db) {
1110
-            $this->LIB->{$class_name} = $class_obj;
1111
-        }
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1118
-     *
1119
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1120
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1121
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1122
-     * @param array  $arguments
1123
-     * @return object
1124
-     */
1125
-    public static function factory($classname, $arguments = array())
1126
-    {
1127
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1128
-        if ($loader instanceof Closure) {
1129
-            return $loader($arguments);
1130
-        } else if (method_exists(EE_Registry::instance(), $loader)) {
1131
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1132
-        }
1133
-        return null;
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * Gets the addon by its name/slug (not classname. For that, just
1140
-     * use the classname as the property name on EE_Config::instance()->addons)
1141
-     *
1142
-     * @param string $name
1143
-     * @return EE_Addon
1144
-     */
1145
-    public function get_addon_by_name($name)
1146
-    {
1147
-        foreach ($this->addons as $addon) {
1148
-            if ($addon->name() == $name) {
1149
-                return $addon;
1150
-            }
1151
-        }
1152
-        return null;
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * 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
1159
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1160
-     *
1161
-     * @return EE_Addon[] where the KEYS are the addon's name()
1162
-     */
1163
-    public function get_addons_by_name()
1164
-    {
1165
-        $addons = array();
1166
-        foreach ($this->addons as $addon) {
1167
-            $addons[$addon->name()] = $addon;
1168
-        }
1169
-        return $addons;
1170
-    }
1171
-
1172
-
1173
-
1174
-    /**
1175
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1176
-     * a stale copy of it around
1177
-     *
1178
-     * @param string $model_name
1179
-     * @return \EEM_Base
1180
-     * @throws \EE_Error
1181
-     */
1182
-    public function reset_model($model_name)
1183
-    {
1184
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1185
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1186
-            return null;
1187
-        }
1188
-        //get that model reset it and make sure we nuke the old reference to it
1189
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1190
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1191
-        } else {
1192
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1193
-        }
1194
-        return $this->LIB->{$model_class_name};
1195
-    }
1196
-
1197
-
1198
-
1199
-    /**
1200
-     * Resets the registry.
1201
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1202
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1203
-     * - $_dependency_map
1204
-     * - $_class_abbreviations
1205
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1206
-     * - $REQ:  Still on the same request so no need to change.
1207
-     * - $CAP: There is no site specific state in the EE_Capability class.
1208
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1209
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1210
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1211
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1212
-     *             switch or on the restore.
1213
-     * - $modules
1214
-     * - $shortcodes
1215
-     * - $widgets
1216
-     *
1217
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1218
-     *                                  the Registry to its state at the beginning of the request
1219
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1220
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1221
-     *                                  currently reinstantiate the singletons at the moment)
1222
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1223
-     *                                  code instead can just change the model context to a different blog id if necessary
1224
-     * @return EE_Registry
1225
-     */
1226
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1227
-    {
1228
-        $instance = self::instance();
1229
-        EEH_Activation::reset();
1230
-        //properties that get reset
1231
-        $instance->_cache_on = true;
1232
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1233
-        $instance->CART = null;
1234
-        $instance->MRM = null;
1235
-        $instance->AssetsRegistry = new Registry();
1236
-        //messages reset
1237
-        EED_Messages::reset();
1238
-        if ($reset_models) {
1239
-            foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1240
-                $instance->reset_model($model_name);
1241
-            }
1242
-        }
1243
-        $instance->LIB = new stdClass();
1244
-        return $instance;
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * @override magic methods
1251
-     * @return void
1252
-     */
1253
-    final function __destruct()
1254
-    {
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * @param $a
1261
-     * @param $b
1262
-     */
1263
-    final function __call($a, $b)
1264
-    {
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     * @param $a
1271
-     */
1272
-    final function __get($a)
1273
-    {
1274
-    }
1275
-
1276
-
1277
-
1278
-    /**
1279
-     * @param $a
1280
-     * @param $b
1281
-     */
1282
-    final function __set($a, $b)
1283
-    {
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * @param $a
1290
-     */
1291
-    final function __isset($a)
1292
-    {
1293
-    }
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
+	 * @return \EE_Registry
224
+	 */
225
+	protected function __construct(\EE_Dependency_Map $dependency_map)
226
+	{
227
+		$this->_dependency_map = $dependency_map;
228
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * initialize
235
+	 */
236
+	public function initialize()
237
+	{
238
+		$this->_class_abbreviations = apply_filters(
239
+			'FHEE__EE_Registry____construct___class_abbreviations',
240
+			array(
241
+				'EE_Config'                                       => 'CFG',
242
+				'EE_Session'                                      => 'SSN',
243
+				'EE_Capabilities'                                 => 'CAP',
244
+				'EE_Cart'                                         => 'CART',
245
+				'EE_Network_Config'                               => 'NET_CFG',
246
+				'EE_Request_Handler'                              => 'REQ',
247
+				'EE_Message_Resource_Manager'                     => 'MRM',
248
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
+			)
250
+		);
251
+		// class library
252
+		$this->LIB = new stdClass();
253
+		$this->addons = new stdClass();
254
+		$this->modules = new stdClass();
255
+		$this->shortcodes = new stdClass();
256
+		$this->widgets = new stdClass();
257
+		$this->load_core('Base', array(), true);
258
+		// add our request and response objects to the cache
259
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
260
+		$this->_set_cached_class(
261
+			$request_loader(),
262
+			'EE_Request'
263
+		);
264
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
265
+		$this->_set_cached_class(
266
+			$response_loader(),
267
+			'EE_Response'
268
+		);
269
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 *    init
276
+	 *
277
+	 * @access    public
278
+	 * @return    void
279
+	 */
280
+	public function init()
281
+	{
282
+		$this->AssetsRegistry = new Registry();
283
+		// Get current page protocol
284
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
+		// Output admin-ajax.php URL with same protocol as current page
286
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * localize_i18n_js_strings
294
+	 *
295
+	 * @return string
296
+	 */
297
+	public static function localize_i18n_js_strings()
298
+	{
299
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
+		foreach ($i18n_js_strings as $key => $value) {
301
+			if (is_scalar($value)) {
302
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
+			}
304
+		}
305
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * @param mixed string | EED_Module $module
312
+	 */
313
+	public function add_module($module)
314
+	{
315
+		if ($module instanceof EED_Module) {
316
+			$module_class = get_class($module);
317
+			$this->modules->{$module_class} = $module;
318
+		} else {
319
+			if ( ! class_exists('EE_Module_Request_Router')) {
320
+				$this->load_core('Module_Request_Router');
321
+			}
322
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
+		}
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * @param string $module_name
330
+	 * @return mixed EED_Module | NULL
331
+	 */
332
+	public function get_module($module_name = '')
333
+	{
334
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 *    loads core classes - must be singletons
341
+	 *
342
+	 * @access    public
343
+	 * @param string $class_name - simple class name ie: session
344
+	 * @param mixed  $arguments
345
+	 * @param bool   $load_only
346
+	 * @return mixed
347
+	 */
348
+	public function load_core($class_name, $arguments = array(), $load_only = false)
349
+	{
350
+		$core_paths = apply_filters(
351
+			'FHEE__EE_Registry__load_core__core_paths',
352
+			array(
353
+				EE_CORE,
354
+				EE_ADMIN,
355
+				EE_CPTS,
356
+				EE_CORE . 'data_migration_scripts' . DS,
357
+				EE_CORE . 'request_stack' . DS,
358
+				EE_CORE . 'middleware' . DS,
359
+			)
360
+		);
361
+		// retrieve instantiated class
362
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 *    loads service classes
369
+	 *
370
+	 * @access    public
371
+	 * @param string $class_name - simple class name ie: session
372
+	 * @param mixed  $arguments
373
+	 * @param bool   $load_only
374
+	 * @return mixed
375
+	 */
376
+	public function load_service($class_name, $arguments = array(), $load_only = false)
377
+	{
378
+		$service_paths = apply_filters(
379
+			'FHEE__EE_Registry__load_service__service_paths',
380
+			array(
381
+				EE_CORE . 'services' . DS,
382
+			)
383
+		);
384
+		// retrieve instantiated class
385
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 *    loads data_migration_scripts
392
+	 *
393
+	 * @access    public
394
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
+	 * @param mixed  $arguments
396
+	 * @return EE_Data_Migration_Script_Base|mixed
397
+	 */
398
+	public function load_dms($class_name, $arguments = array())
399
+	{
400
+		// retrieve instantiated class
401
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 *    loads object creating classes - must be singletons
408
+	 *
409
+	 * @param string $class_name - simple class name ie: attendee
410
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
411
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
+	 * @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)
413
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
+	 * @return EE_Base_Class | bool
415
+	 */
416
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
+	{
418
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
+			EE_CORE,
420
+			EE_CLASSES,
421
+			EE_BUSINESS,
422
+		));
423
+		// retrieve instantiated class
424
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 *    loads helper classes - must be singletons
431
+	 *
432
+	 * @param string $class_name - simple class name ie: price
433
+	 * @param mixed  $arguments
434
+	 * @param bool   $load_only
435
+	 * @return EEH_Base | bool
436
+	 */
437
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
438
+	{
439
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
+		// retrieve instantiated class
442
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 *    loads core classes - must be singletons
449
+	 *
450
+	 * @access    public
451
+	 * @param string $class_name - simple class name ie: session
452
+	 * @param mixed  $arguments
453
+	 * @param bool   $load_only
454
+	 * @param bool   $cache      whether to cache the object or not.
455
+	 * @return mixed
456
+	 */
457
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
+	{
459
+		$paths = array(
460
+			EE_LIBRARIES,
461
+			EE_LIBRARIES . 'messages' . DS,
462
+			EE_LIBRARIES . 'shortcodes' . DS,
463
+			EE_LIBRARIES . 'qtips' . DS,
464
+			EE_LIBRARIES . 'payment_methods' . DS,
465
+		);
466
+		// retrieve instantiated class
467
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 *    loads model classes - must be singletons
474
+	 *
475
+	 * @param string $class_name - simple class name ie: price
476
+	 * @param mixed  $arguments
477
+	 * @param bool   $load_only
478
+	 * @return EEM_Base | bool
479
+	 */
480
+	public function load_model($class_name, $arguments = array(), $load_only = false)
481
+	{
482
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
+			EE_MODELS,
484
+			EE_CORE,
485
+		));
486
+		// retrieve instantiated class
487
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 *    loads model classes - must be singletons
494
+	 *
495
+	 * @param string $class_name - simple class name ie: price
496
+	 * @param mixed  $arguments
497
+	 * @param bool   $load_only
498
+	 * @return mixed | bool
499
+	 */
500
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
+	{
502
+		$paths = array(
503
+			EE_MODELS . 'fields' . DS,
504
+			EE_MODELS . 'helpers' . DS,
505
+			EE_MODELS . 'relations' . DS,
506
+			EE_MODELS . 'strategies' . DS,
507
+		);
508
+		// retrieve instantiated class
509
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Determines if $model_name is the name of an actual EE model.
516
+	 *
517
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
+	 * @return boolean
519
+	 */
520
+	public function is_model_name($model_name)
521
+	{
522
+		return isset($this->models[$model_name]) ? true : false;
523
+	}
524
+
525
+
526
+
527
+	/**
528
+	 *    generic class loader
529
+	 *
530
+	 * @param string $path_to_file - directory path to file location, not including filename
531
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
532
+	 * @param string $type         - file type - core? class? helper? model?
533
+	 * @param mixed  $arguments
534
+	 * @param bool   $load_only
535
+	 * @return mixed
536
+	 */
537
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
+	{
539
+		// retrieve instantiated class
540
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 *    load_addon
547
+	 *
548
+	 * @param string $path_to_file - directory path to file location, not including filename
549
+	 * @param string $class_name   - full class name  ie:  My_Class
550
+	 * @param string $type         - file type - core? class? helper? model?
551
+	 * @param mixed  $arguments
552
+	 * @param bool   $load_only
553
+	 * @return EE_Addon
554
+	 */
555
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
+	{
557
+		// retrieve instantiated class
558
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
+	}
560
+
561
+
562
+
563
+	/**
564
+	 * instantiates, caches, and automatically resolves dependencies
565
+	 * for classes that use a Fully Qualified Class Name.
566
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
567
+	 * then you need to use one of the existing load_*() methods
568
+	 * which can resolve the classname and filepath from the passed arguments
569
+	 *
570
+	 * @param bool|string $class_name   Fully Qualified Class Name
571
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
573
+	 * @param bool        $from_db      some classes are instantiated from the db
574
+	 *                                  and thus call a different method to instantiate
575
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
+	 * @return mixed                    null = failure to load or instantiate class object.
578
+	 *                                  object = class loaded and instantiated successfully.
579
+	 *                                  bool = fail or success when $load_only is true
580
+	 */
581
+	public function create(
582
+		$class_name = false,
583
+		$arguments = array(),
584
+		$cache = false,
585
+		$from_db = false,
586
+		$load_only = false,
587
+		$addon = false
588
+	) {
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
+		// strip php file extension
652
+		$class_name = str_replace('.php', '', trim($class_name));
653
+		// does the class have a prefix ?
654
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
+			// make sure $class_prefix is uppercase
656
+			$class_prefix = strtoupper(trim($class_prefix));
657
+			// add class prefix ONCE!!!
658
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
+		}
660
+		$class_name = $this->_dependency_map->get_alias($class_name);
661
+		$class_exists = class_exists($class_name);
662
+		// if we're only loading the class and it already exists, then let's just return true immediately
663
+		if ($load_only && $class_exists) {
664
+			return true;
665
+		}
666
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
+		if ($this->_cache_on && $cache && ! $load_only) {
670
+			// return object if it's already cached
671
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
+			if ($cached_class !== null) {
673
+				return $cached_class;
674
+			}
675
+		}
676
+		// if the class doesn't already exist.. then we need to try and find the file and load it
677
+		if ( ! $class_exists) {
678
+			// get full path to file
679
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
680
+			// load the file
681
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
+			// if loading failed, or we are only loading a file but NOT instantiating an object
683
+			if ( ! $loaded || $load_only) {
684
+				// return boolean if only loading, or null if an object was expected
685
+				return $load_only ? $loaded : null;
686
+			}
687
+		}
688
+		// instantiate the requested object
689
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
+		if ($this->_cache_on && $cache) {
691
+			// save it for later... kinda like gum  { : $
692
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
+		}
694
+		$this->_cache_on = true;
695
+		return $class_obj;
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * _get_cached_class
702
+	 * attempts to find a cached version of the requested class
703
+	 * by looking in the following places:
704
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
705
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
706
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
707
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
708
+	 *
709
+	 * @access protected
710
+	 * @param string $class_name
711
+	 * @param string $class_prefix
712
+	 * @return mixed
713
+	 */
714
+	protected function _get_cached_class($class_name, $class_prefix = '')
715
+	{
716
+		if (isset($this->_class_abbreviations[$class_name])) {
717
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
718
+		} else {
719
+			// have to specify something, but not anything that will conflict
720
+			$class_abbreviation = 'FANCY_BATMAN_PANTS';
721
+		}
722
+		// check if class has already been loaded, and return it if it has been
723
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
+			return $this->{$class_abbreviation};
725
+		} else if (isset ($this->{$class_name})) {
726
+			return $this->{$class_name};
727
+		} else if (isset ($this->LIB->{$class_name})) {
728
+			return $this->LIB->{$class_name};
729
+		} else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
730
+			return $this->addons->{$class_name};
731
+		}
732
+		return null;
733
+	}
734
+
735
+
736
+
737
+	/**
738
+	 * _resolve_path
739
+	 * attempts to find a full valid filepath for the requested class.
740
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
741
+	 * then returns that path if the target file has been found and is readable
742
+	 *
743
+	 * @access protected
744
+	 * @param string $class_name
745
+	 * @param string $type
746
+	 * @param array  $file_paths
747
+	 * @return string | bool
748
+	 */
749
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
750
+	{
751
+		// make sure $file_paths is an array
752
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
753
+		// cycle thru paths
754
+		foreach ($file_paths as $key => $file_path) {
755
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
756
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
757
+			// prep file type
758
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
759
+			// build full file path
760
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
761
+			//does the file exist and can be read ?
762
+			if (is_readable($file_paths[$key])) {
763
+				return $file_paths[$key];
764
+			}
765
+		}
766
+		return false;
767
+	}
768
+
769
+
770
+
771
+	/**
772
+	 * _require_file
773
+	 * basically just performs a require_once()
774
+	 * but with some error handling
775
+	 *
776
+	 * @access protected
777
+	 * @param  string $path
778
+	 * @param  string $class_name
779
+	 * @param  string $type
780
+	 * @param  array  $file_paths
781
+	 * @return boolean
782
+	 * @throws \EE_Error
783
+	 */
784
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
785
+	{
786
+		// don't give up! you gotta...
787
+		try {
788
+			//does the file exist and can it be read ?
789
+			if ( ! $path) {
790
+				// so sorry, can't find the file
791
+				throw new EE_Error (
792
+					sprintf(
793
+						__('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'),
794
+						trim($type, '.'),
795
+						$class_name,
796
+						'<br />' . implode(',<br />', $file_paths)
797
+					)
798
+				);
799
+			}
800
+			// get the file
801
+			require_once($path);
802
+			// if the class isn't already declared somewhere
803
+			if (class_exists($class_name, false) === false) {
804
+				// so sorry, not a class
805
+				throw new EE_Error(
806
+					sprintf(
807
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
808
+						$type,
809
+						$path,
810
+						$class_name
811
+					)
812
+				);
813
+			}
814
+		} catch (EE_Error $e) {
815
+			$e->get_error();
816
+			return false;
817
+		}
818
+		return true;
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * _create_object
825
+	 * Attempts to instantiate the requested class via any of the
826
+	 * commonly used instantiation methods employed throughout EE.
827
+	 * The priority for instantiation is as follows:
828
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
829
+	 *        - model objects via their 'new_instance_from_db' method
830
+	 *        - model objects via their 'new_instance' method
831
+	 *        - "singleton" classes" via their 'instance' method
832
+	 *    - standard instantiable classes via their __constructor
833
+	 * Prior to instantiation, if the classname exists in the dependency_map,
834
+	 * then the constructor for the requested class will be examined to determine
835
+	 * if any dependencies exist, and if they can be injected.
836
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
837
+	 *
838
+	 * @access protected
839
+	 * @param string $class_name
840
+	 * @param array  $arguments
841
+	 * @param string $type
842
+	 * @param bool   $from_db
843
+	 * @return null | object
844
+	 * @throws \EE_Error
845
+	 */
846
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
847
+	{
848
+		$class_obj = null;
849
+		$instantiation_mode = '0) none';
850
+		// don't give up! you gotta...
851
+		try {
852
+			// create reflection
853
+			$reflector = $this->get_ReflectionClass($class_name);
854
+			// make sure arguments are an array
855
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
856
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
857
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
858
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
859
+				? $arguments
860
+				: array($arguments);
861
+			// attempt to inject dependencies ?
862
+			if ($this->_dependency_map->has($class_name)) {
863
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
864
+			}
865
+			// instantiate the class if possible
866
+			if ($reflector->isAbstract()) {
867
+				// nothing to instantiate, loading file was enough
868
+				// does not throw an exception so $instantiation_mode is unused
869
+				// $instantiation_mode = "1) no constructor abstract class";
870
+				$class_obj = true;
871
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
872
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
873
+				$instantiation_mode = "2) no constructor but instantiable";
874
+				$class_obj = $reflector->newInstance();
875
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
876
+				$instantiation_mode = "3) new_instance_from_db()";
877
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
878
+			} else if (method_exists($class_name, 'new_instance')) {
879
+				$instantiation_mode = "4) new_instance()";
880
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
881
+			} else if (method_exists($class_name, 'instance')) {
882
+				$instantiation_mode = "5) instance()";
883
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
884
+			} else if ($reflector->isInstantiable()) {
885
+				$instantiation_mode = "6) constructor";
886
+				$class_obj = $reflector->newInstanceArgs($arguments);
887
+			} else {
888
+				// heh ? something's not right !
889
+				throw new EE_Error(
890
+					sprintf(
891
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
892
+						$type,
893
+						$class_name
894
+					)
895
+				);
896
+			}
897
+		} catch (Exception $e) {
898
+			if ( ! $e instanceof EE_Error) {
899
+				$e = new EE_Error(
900
+					sprintf(
901
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
902
+						$class_name,
903
+						'<br />',
904
+						$e->getMessage(),
905
+						$instantiation_mode
906
+					)
907
+				);
908
+			}
909
+			$e->get_error();
910
+		}
911
+		return $class_obj;
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
918
+	 * @param array $array
919
+	 * @return bool
920
+	 */
921
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
922
+	{
923
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * getReflectionClass
930
+	 * checks if a ReflectionClass object has already been generated for a class
931
+	 * and returns that instead of creating a new one
932
+	 *
933
+	 * @access public
934
+	 * @param string $class_name
935
+	 * @return ReflectionClass
936
+	 */
937
+	public function get_ReflectionClass($class_name)
938
+	{
939
+		if (
940
+			! isset($this->_reflectors[$class_name])
941
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
942
+		) {
943
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
944
+		}
945
+		return $this->_reflectors[$class_name];
946
+	}
947
+
948
+
949
+
950
+	/**
951
+	 * _resolve_dependencies
952
+	 * examines the constructor for the requested class to determine
953
+	 * if any dependencies exist, and if they can be injected.
954
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
955
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
956
+	 * For example:
957
+	 *        if attempting to load a class "Foo" with the following constructor:
958
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
959
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
960
+	 *        but only IF they are NOT already present in the incoming arguments array,
961
+	 *        and the correct classes can be loaded
962
+	 *
963
+	 * @access protected
964
+	 * @param ReflectionClass $reflector
965
+	 * @param string          $class_name
966
+	 * @param array           $arguments
967
+	 * @return array
968
+	 * @throws \ReflectionException
969
+	 */
970
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
971
+	{
972
+		// let's examine the constructor
973
+		$constructor = $reflector->getConstructor();
974
+		// whu? huh? nothing?
975
+		if ( ! $constructor) {
976
+			return $arguments;
977
+		}
978
+		// get constructor parameters
979
+		$params = $constructor->getParameters();
980
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
981
+		$argument_keys = array_keys($arguments);
982
+		// now loop thru all of the constructors expected parameters
983
+		foreach ($params as $index => $param) {
984
+			// is this a dependency for a specific class ?
985
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
986
+			if (
987
+				// param is not even a class
988
+				empty($param_class)
989
+				// and something already exists in the incoming arguments for this param
990
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
991
+			) {
992
+				// so let's skip this argument and move on to the next
993
+				continue;
994
+			} else if (
995
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
996
+				! empty($param_class)
997
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
998
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
999
+			) {
1000
+				// skip this argument and move on to the next
1001
+				continue;
1002
+			} else if (
1003
+				// parameter is type hinted as a class, and should be injected
1004
+				! empty($param_class)
1005
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1006
+			) {
1007
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1008
+			} else {
1009
+				try {
1010
+					$arguments[$index] = $param->getDefaultValue();
1011
+				} catch (ReflectionException $e) {
1012
+					throw new ReflectionException(
1013
+						sprintf(
1014
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1015
+							$e->getMessage(),
1016
+							$param->getName()
1017
+						)
1018
+					);
1019
+				}
1020
+			}
1021
+		}
1022
+		return $arguments;
1023
+	}
1024
+
1025
+
1026
+
1027
+	/**
1028
+	 * @access protected
1029
+	 * @param string $class_name
1030
+	 * @param string $param_class
1031
+	 * @param array  $arguments
1032
+	 * @param mixed  $index
1033
+	 * @return array
1034
+	 */
1035
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1036
+	{
1037
+		$dependency = null;
1038
+		// should dependency be loaded from cache ?
1039
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1040
+					!== EE_Dependency_Map::load_new_object
1041
+			? true
1042
+			: false;
1043
+		// we might have a dependency...
1044
+		// let's MAYBE try and find it in our cache if that's what's been requested
1045
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1046
+		// and grab it if it exists
1047
+		if ($cached_class instanceof $param_class) {
1048
+			$dependency = $cached_class;
1049
+		} else if ($param_class != $class_name) {
1050
+			// obtain the loader method from the dependency map
1051
+			$loader = $this->_dependency_map->class_loader($param_class);
1052
+			// is loader a custom closure ?
1053
+			if ($loader instanceof Closure) {
1054
+				$dependency = $loader();
1055
+			} else {
1056
+				// set the cache on property for the recursive loading call
1057
+				$this->_cache_on = $cache_on;
1058
+				// if not, then let's try and load it via the registry
1059
+				if (method_exists($this, $loader)) {
1060
+					$dependency = $this->{$loader}($param_class);
1061
+				} else {
1062
+					$dependency = $this->create($param_class, array(), $cache_on);
1063
+				}
1064
+			}
1065
+		}
1066
+		// did we successfully find the correct dependency ?
1067
+		if ($dependency instanceof $param_class) {
1068
+			// then let's inject it into the incoming array of arguments at the correct location
1069
+			if (isset($argument_keys[$index])) {
1070
+				$arguments[$argument_keys[$index]] = $dependency;
1071
+			} else {
1072
+				$arguments[$index] = $dependency;
1073
+			}
1074
+		}
1075
+		return $arguments;
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * _set_cached_class
1082
+	 * attempts to cache the instantiated class locally
1083
+	 * in one of the following places, in the following order:
1084
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1085
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1086
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1087
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1088
+	 *
1089
+	 * @access protected
1090
+	 * @param object $class_obj
1091
+	 * @param string $class_name
1092
+	 * @param string $class_prefix
1093
+	 * @param bool   $from_db
1094
+	 * @return void
1095
+	 */
1096
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1097
+	{
1098
+		if (empty($class_obj)) {
1099
+			return;
1100
+		}
1101
+		// return newly instantiated class
1102
+		if (isset($this->_class_abbreviations[$class_name])) {
1103
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1104
+			$this->{$class_abbreviation} = $class_obj;
1105
+		} else if (property_exists($this, $class_name)) {
1106
+			$this->{$class_name} = $class_obj;
1107
+		} else if ($class_prefix == 'addon') {
1108
+			$this->addons->{$class_name} = $class_obj;
1109
+		} else if ( ! $from_db) {
1110
+			$this->LIB->{$class_name} = $class_obj;
1111
+		}
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1118
+	 *
1119
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1120
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1121
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1122
+	 * @param array  $arguments
1123
+	 * @return object
1124
+	 */
1125
+	public static function factory($classname, $arguments = array())
1126
+	{
1127
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1128
+		if ($loader instanceof Closure) {
1129
+			return $loader($arguments);
1130
+		} else if (method_exists(EE_Registry::instance(), $loader)) {
1131
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1132
+		}
1133
+		return null;
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * Gets the addon by its name/slug (not classname. For that, just
1140
+	 * use the classname as the property name on EE_Config::instance()->addons)
1141
+	 *
1142
+	 * @param string $name
1143
+	 * @return EE_Addon
1144
+	 */
1145
+	public function get_addon_by_name($name)
1146
+	{
1147
+		foreach ($this->addons as $addon) {
1148
+			if ($addon->name() == $name) {
1149
+				return $addon;
1150
+			}
1151
+		}
1152
+		return null;
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * 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
1159
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1160
+	 *
1161
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1162
+	 */
1163
+	public function get_addons_by_name()
1164
+	{
1165
+		$addons = array();
1166
+		foreach ($this->addons as $addon) {
1167
+			$addons[$addon->name()] = $addon;
1168
+		}
1169
+		return $addons;
1170
+	}
1171
+
1172
+
1173
+
1174
+	/**
1175
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1176
+	 * a stale copy of it around
1177
+	 *
1178
+	 * @param string $model_name
1179
+	 * @return \EEM_Base
1180
+	 * @throws \EE_Error
1181
+	 */
1182
+	public function reset_model($model_name)
1183
+	{
1184
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1185
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1186
+			return null;
1187
+		}
1188
+		//get that model reset it and make sure we nuke the old reference to it
1189
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1190
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1191
+		} else {
1192
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1193
+		}
1194
+		return $this->LIB->{$model_class_name};
1195
+	}
1196
+
1197
+
1198
+
1199
+	/**
1200
+	 * Resets the registry.
1201
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1202
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1203
+	 * - $_dependency_map
1204
+	 * - $_class_abbreviations
1205
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1206
+	 * - $REQ:  Still on the same request so no need to change.
1207
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1208
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1209
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1210
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1211
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1212
+	 *             switch or on the restore.
1213
+	 * - $modules
1214
+	 * - $shortcodes
1215
+	 * - $widgets
1216
+	 *
1217
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1218
+	 *                                  the Registry to its state at the beginning of the request
1219
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1220
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1221
+	 *                                  currently reinstantiate the singletons at the moment)
1222
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1223
+	 *                                  code instead can just change the model context to a different blog id if necessary
1224
+	 * @return EE_Registry
1225
+	 */
1226
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1227
+	{
1228
+		$instance = self::instance();
1229
+		EEH_Activation::reset();
1230
+		//properties that get reset
1231
+		$instance->_cache_on = true;
1232
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1233
+		$instance->CART = null;
1234
+		$instance->MRM = null;
1235
+		$instance->AssetsRegistry = new Registry();
1236
+		//messages reset
1237
+		EED_Messages::reset();
1238
+		if ($reset_models) {
1239
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1240
+				$instance->reset_model($model_name);
1241
+			}
1242
+		}
1243
+		$instance->LIB = new stdClass();
1244
+		return $instance;
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * @override magic methods
1251
+	 * @return void
1252
+	 */
1253
+	final function __destruct()
1254
+	{
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * @param $a
1261
+	 * @param $b
1262
+	 */
1263
+	final function __call($a, $b)
1264
+	{
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 * @param $a
1271
+	 */
1272
+	final function __get($a)
1273
+	{
1274
+	}
1275
+
1276
+
1277
+
1278
+	/**
1279
+	 * @param $a
1280
+	 * @param $b
1281
+	 */
1282
+	final function __set($a, $b)
1283
+	{
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * @param $a
1290
+	 */
1291
+	final function __isset($a)
1292
+	{
1293
+	}
1294 1294
 
1295 1295
 
1296 1296
 
1297
-    /**
1298
-     * @param $a
1299
-     */
1300
-    final function __unset($a)
1301
-    {
1302
-    }
1297
+	/**
1298
+	 * @param $a
1299
+	 */
1300
+	final function __unset($a)
1301
+	{
1302
+	}
1303 1303
 
1304 1304
 
1305 1305
 
1306
-    /**
1307
-     * @return array
1308
-     */
1309
-    final function __sleep()
1310
-    {
1311
-        return array();
1312
-    }
1306
+	/**
1307
+	 * @return array
1308
+	 */
1309
+	final function __sleep()
1310
+	{
1311
+		return array();
1312
+	}
1313 1313
 
1314 1314
 
1315 1315
 
1316
-    final function __wakeup()
1317
-    {
1318
-    }
1316
+	final function __wakeup()
1317
+	{
1318
+	}
1319 1319
 
1320 1320
 
1321 1321
 
1322
-    /**
1323
-     * @return string
1324
-     */
1325
-    final function __toString()
1326
-    {
1327
-        return '';
1328
-    }
1322
+	/**
1323
+	 * @return string
1324
+	 */
1325
+	final function __toString()
1326
+	{
1327
+		return '';
1328
+	}
1329 1329
 
1330 1330
 
1331 1331
 
1332
-    final function __invoke()
1333
-    {
1334
-    }
1332
+	final function __invoke()
1333
+	{
1334
+	}
1335 1335
 
1336 1336
 
1337 1337
 
1338
-    final function __set_state()
1339
-    {
1340
-    }
1338
+	final function __set_state()
1339
+	{
1340
+	}
1341 1341
 
1342 1342
 
1343 1343
 
1344
-    final function __clone()
1345
-    {
1346
-    }
1344
+	final function __clone()
1345
+	{
1346
+	}
1347 1347
 
1348 1348
 
1349 1349
 
1350
-    /**
1351
-     * @param $a
1352
-     * @param $b
1353
-     */
1354
-    final static function __callStatic($a, $b)
1355
-    {
1356
-    }
1350
+	/**
1351
+	 * @param $a
1352
+	 * @param $b
1353
+	 */
1354
+	final static function __callStatic($a, $b)
1355
+	{
1356
+	}
1357 1357
 
1358 1358
 
1359 1359
 
1360
-    /**
1361
-     * Gets all the custom post type models defined
1362
-     *
1363
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1364
-     */
1365
-    public function cpt_models()
1366
-    {
1367
-        $cpt_models = array();
1368
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1369
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1370
-                $cpt_models[$short_name] = $classname;
1371
-            }
1372
-        }
1373
-        return $cpt_models;
1374
-    }
1360
+	/**
1361
+	 * Gets all the custom post type models defined
1362
+	 *
1363
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1364
+	 */
1365
+	public function cpt_models()
1366
+	{
1367
+		$cpt_models = array();
1368
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1369
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1370
+				$cpt_models[$short_name] = $classname;
1371
+			}
1372
+		}
1373
+		return $cpt_models;
1374
+	}
1375 1375
 
1376 1376
 
1377 1377
 
1378
-    /**
1379
-     * @return \EE_Config
1380
-     */
1381
-    public static function CFG()
1382
-    {
1383
-        return self::instance()->CFG;
1384
-    }
1378
+	/**
1379
+	 * @return \EE_Config
1380
+	 */
1381
+	public static function CFG()
1382
+	{
1383
+		return self::instance()->CFG;
1384
+	}
1385 1385
 
1386 1386
 
1387 1387
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Foreign_Key_String_Field.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_Foreign_Key_Field_Base.php');
2
+require_once(EE_MODELS.'fields/EE_Foreign_Key_Field_Base.php');
3 3
 
4 4
 class EE_Foreign_Key_String_Field extends EE_Foreign_Key_Field_Base
5 5
 {
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@
 block discarded – undo
4 4
 class EE_Foreign_Key_String_Field extends EE_Foreign_Key_Field_Base
5 5
 {
6 6
 
7
-    /**
8
-     * removes all tags when setting
9
-     *
10
-     * @param string $value_inputted_for_field_on_model_object
11
-     * @return string
12
-     */
13
-    function prepare_for_set($value_inputted_for_field_on_model_object)
14
-    {
15
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
-        }
18
-        return strtoupper(wp_strip_all_tags($value_inputted_for_field_on_model_object));
19
-    }
7
+	/**
8
+	 * removes all tags when setting
9
+	 *
10
+	 * @param string $value_inputted_for_field_on_model_object
11
+	 * @return string
12
+	 */
13
+	function prepare_for_set($value_inputted_for_field_on_model_object)
14
+	{
15
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
+		}
18
+		return strtoupper(wp_strip_all_tags($value_inputted_for_field_on_model_object));
19
+	}
20 20
 }
21 21
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Any_Foreign_Model_Name_Field.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php');
2
+require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php');
3 3
 
4 4
 /**
5 5
  * Used by EE_Belongs_To_Any_Relations and EE_Has_Many_Any_Relations to identify the model the foreign key points to.
Please login to merge, or discard this patch.
core/db_models/fields/EE_DB_Only_Text_Field.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php');
2
+require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php');
3 3
 
4 4
 class EE_DB_Only_Text_Field extends EE_DB_Only_Field_Base
5 5
 {
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Relation.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -13,93 +13,93 @@
 block discarded – undo
13 13
 class EE_Has_Many_Relation extends EE_Model_Relation_Base
14 14
 {
15 15
 
16
-    /**
17
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
18
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
19
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
20
-     * related models across the relation, and add-and-remove the relationships.
21
-     *
22
-     * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
23
-     *                                               related models across this relation, block (prevent and add an
24
-     *                                               error) the deletion of this model
25
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
26
-     *                                               default
27
-     */
28
-    public function __construct($block_deletes = true, $blocking_delete_error_message = null)
29
-    {
30
-        parent::__construct($block_deletes, $blocking_delete_error_message);
31
-    }
16
+	/**
17
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
18
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
19
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
20
+	 * related models across the relation, and add-and-remove the relationships.
21
+	 *
22
+	 * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
23
+	 *                                               related models across this relation, block (prevent and add an
24
+	 *                                               error) the deletion of this model
25
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
26
+	 *                                               default
27
+	 */
28
+	public function __construct($block_deletes = true, $blocking_delete_error_message = null)
29
+	{
30
+		parent::__construct($block_deletes, $blocking_delete_error_message);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * Gets the SQL string for performing the join between this model and the other model.
36
-     *
37
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
38
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
39
-     *                other_model_primary_table.fk" etc
40
-     * @throws \EE_Error
41
-     */
42
-    public function get_join_statement($model_relation_chain)
43
-    {
44
-        //create the sql string like
45
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
46
-        $this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
47
-        $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
48
-        $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
-                $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
50
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
51
-                $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias();
52
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
34
+	/**
35
+	 * Gets the SQL string for performing the join between this model and the other model.
36
+	 *
37
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
38
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
39
+	 *                other_model_primary_table.fk" etc
40
+	 * @throws \EE_Error
41
+	 */
42
+	public function get_join_statement($model_relation_chain)
43
+	{
44
+		//create the sql string like
45
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
46
+		$this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
47
+		$other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
48
+		$pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
+				$this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias();
50
+		$fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
51
+				$this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias();
52
+		$fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
53 53
 
54
-        return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias,
55
-                $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
56
-    }
54
+		return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias,
55
+				$this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
61
-     * you like.
62
-     *
63
-     * @param EE_Base_Class|int $this_obj_or_id
64
-     * @param EE_Base_Class|int $other_obj_or_id
65
-     * @param array             $extra_join_model_fields_n_values
66
-     * @return \EE_Base_Class
67
-     * @throws \EE_Error
68
-     */
69
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
70
-    {
71
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
72
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
59
+	/**
60
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
61
+	 * you like.
62
+	 *
63
+	 * @param EE_Base_Class|int $this_obj_or_id
64
+	 * @param EE_Base_Class|int $other_obj_or_id
65
+	 * @param array             $extra_join_model_fields_n_values
66
+	 * @return \EE_Base_Class
67
+	 * @throws \EE_Error
68
+	 */
69
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
70
+	{
71
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
72
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
73 73
 
74
-        //find the field on the other model which is a foreign key to this model
75
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
76
-        if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
77
-            //set that field on the other model to this model's ID
78
-            $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
79
-            $other_model_obj->save();
80
-        }
81
-        return $other_model_obj;
82
-    }
74
+		//find the field on the other model which is a foreign key to this model
75
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
76
+		if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
77
+			//set that field on the other model to this model's ID
78
+			$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
79
+			$other_model_obj->save();
80
+		}
81
+		return $other_model_obj;
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
87
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
88
-     *
89
-     * @param EE_Base_Class|int $this_obj_or_id
90
-     * @param EE_Base_Class|int $other_obj_or_id
91
-     * @param array             $where_query
92
-     * @return \EE_Base_Class
93
-     * @throws \EE_Error
94
-     */
95
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
96
-    {
97
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
98
-        //find the field on the other model which is a foreign key to this model
99
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
100
-        //set that field on the other model to this model's ID
101
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
102
-        $other_model_obj->save();
103
-        return $other_model_obj;
104
-    }
85
+	/**
86
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
87
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
88
+	 *
89
+	 * @param EE_Base_Class|int $this_obj_or_id
90
+	 * @param EE_Base_Class|int $other_obj_or_id
91
+	 * @param array             $where_query
92
+	 * @return \EE_Base_Class
93
+	 * @throws \EE_Error
94
+	 */
95
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
96
+	{
97
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
98
+		//find the field on the other model which is a foreign key to this model
99
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
100
+		//set that field on the other model to this model's ID
101
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
102
+		$other_model_obj->save();
103
+		return $other_model_obj;
104
+	}
105 105
 }
Please login to merge, or discard this patch.
core/interfaces/EEI_Interfaces.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 interface EEI_Attendee {
191 191
 	public function fname();
192 192
 	public function lname();
193
-    public function full_name();
193
+	public function full_name();
194 194
 	public function email();
195 195
 	public function phone();
196 196
 	public function address();
@@ -311,23 +311,23 @@  discard block
 block discarded – undo
311 311
 	 * @param float $amount
312 312
 	 * @param string $name
313 313
 	 * @param string $description
314
-         * @param string $code
315
-         * @param boolean $add_to_existing_line_item if true and a duplicate line item with
316
-         *  the same code is found, $amount will be added onto it; otherwise will simply
317
-         *  set the taxes to match $amount
314
+	 * @param string $code
315
+	 * @param boolean $add_to_existing_line_item if true and a duplicate line item with
316
+	 *  the same code is found, $amount will be added onto it; otherwise will simply
317
+	 *  set the taxes to match $amount
318 318
 	 * @return EE_Line_Item the new tax created
319 319
 	 */
320 320
 	public function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name  = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false );
321 321
 
322
-         /**
323
-         * Makes all the line items which are children of $line_item taxable (or not).
324
-         * Does NOT save the line items
325
-         * @param EE_Line_Item $line_item
326
-         * @param boolean $taxable
327
-         * @param string $code_substring_for_whitelist if this string is part of the line item's code
328
-         *  it will be whitelisted (ie, except from becoming taxable)
329
-         */
330
-        public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null );
322
+		 /**
323
+		  * Makes all the line items which are children of $line_item taxable (or not).
324
+		  * Does NOT save the line items
325
+		  * @param EE_Line_Item $line_item
326
+		  * @param boolean $taxable
327
+		  * @param string $code_substring_for_whitelist if this string is part of the line item's code
328
+		  *  it will be whitelisted (ie, except from becoming taxable)
329
+		  */
330
+		public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null );
331 331
 
332 332
 	/**
333 333
 	 * Adds a simple item ( unrelated to any other model object) to the total line item,
@@ -357,15 +357,15 @@  discard block
 block discarded – undo
357 357
  */
358 358
 interface EEHI_Money{
359 359
 		/**
360
-	 * For comparing floats. Default operator is '=', but see the $operator below for all options.
361
-	 * This should be used to compare floats instead of normal '==' because floats
362
-	 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
363
-	 * but actually differ by 0.00000001.
364
-	 * @param float $float1
365
-	 * @param float $float2
366
-	 * @param string $operator  The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
367
-	 * @return boolean whether the equation is true or false
368
-	 */
360
+		 * For comparing floats. Default operator is '=', but see the $operator below for all options.
361
+		 * This should be used to compare floats instead of normal '==' because floats
362
+		 * are inherently imprecise, and so you can sometimes have two floats that appear to be identical
363
+		 * but actually differ by 0.00000001.
364
+		 * @param float $float1
365
+		 * @param float $float2
366
+		 * @param string $operator  The operator. Valid options are =, <=, <, >=, >, <>, eq, lt, lte, gt, gte, ne
367
+		 * @return boolean whether the equation is true or false
368
+		 */
369 369
 	public function compare_floats( $float1, $float2, $operator='=' );
370 370
 }
371 371
 
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 3 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -90,19 +90,19 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function do_direct_payment($payment,$billing_info = null){
92 92
 		$transaction = $payment->transaction();
93
-        if (! $transaction instanceof EEI_Transaction) {
94
-            throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
95
-        }
96
-        $primary_registrant = $transaction->primary_registration();
97
-        if (! $primary_registrant instanceof EEI_Registration) {
98
-            throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
99
-                'event_espresso'));
100
-        }
101
-        $attendee = $primary_registrant->attendee();
102
-        if (! $attendee instanceof EEI_Attendee) {
103
-            throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
104
-                'event_espresso'));
105
-        }
93
+		if (! $transaction instanceof EEI_Transaction) {
94
+			throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
95
+		}
96
+		$primary_registrant = $transaction->primary_registration();
97
+		if (! $primary_registrant instanceof EEI_Registration) {
98
+			throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
99
+				'event_espresso'));
100
+		}
101
+		$attendee = $primary_registrant->attendee();
102
+		if (! $attendee instanceof EEI_Attendee) {
103
+			throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
104
+				'event_espresso'));
105
+		}
106 106
 		$order_description  = $this->_format_order_description( $payment );
107 107
 		//charge for the full amount. Show itemized list
108 108
 		if( $this->_can_easily_itemize_transaction_for( $payment ) ){
@@ -232,23 +232,23 @@  discard block
 block discarded – undo
232 232
 			'zip' => $billing_info['zip'],
233 233
 		);
234 234
 
235
-        //check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
236
-        if($attendee->address() && $attendee->city() && $attendee->country_ID()){
237
-            $use_registration_address_info = true;
238
-        } else {
239
-            $use_registration_address_info = false;
240
-        }
241
-        //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
242
-        $ShippingAddress = array(
243
-            'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
244
-            'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
245
-            'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'],0,100),
246
-            'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'],0,40),
247
-            'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'],0,40),
248
-            'shiptocountry' => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'],
249
-            'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'],0,20),
250
-            'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'],0,20),
251
-        );
235
+		//check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
236
+		if($attendee->address() && $attendee->city() && $attendee->country_ID()){
237
+			$use_registration_address_info = true;
238
+		} else {
239
+			$use_registration_address_info = false;
240
+		}
241
+		//so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
242
+		$ShippingAddress = array(
243
+			'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
244
+			'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
245
+			'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'],0,100),
246
+			'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'],0,40),
247
+			'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'],0,40),
248
+			'shiptocountry' => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'],
249
+			'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'],0,20),
250
+			'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'],0,20),
251
+		);
252 252
 
253 253
 		$PaymentDetails = array(
254 254
 			// Required.  Total amount of order, including shipping, handling, and tax.
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 				'PayerInfo' => $PayerInfo,
281 281
 				'PayerName' => $PayerName,
282 282
 				'BillingAddress' => $BillingAddress,
283
-                'ShippingAddress' => $ShippingAddress,
283
+				'ShippingAddress' => $ShippingAddress,
284 284
 				'PaymentDetails' => $PaymentDetails,
285 285
 				'OrderItems' => $order_items,
286 286
 		);
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION'))
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('No direct script access allowed');
5 5
 
6 6
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EEG_Paypal_Pro extends EE_Onsite_Gateway{
28
+class EEG_Paypal_Pro extends EE_Onsite_Gateway {
29 29
 	/**
30 30
 	 *
31 31
 	 * @var $_paypal_api_username string
@@ -88,42 +88,42 @@  discard block
 block discarded – undo
88 88
 	 * } @see parent::do_direct_payment for more info
89 89
 	 * @return \EE_Payment|\EEI_Payment
90 90
 	 */
91
-	public function do_direct_payment($payment,$billing_info = null){
91
+	public function do_direct_payment($payment, $billing_info = null) {
92 92
 		$transaction = $payment->transaction();
93
-        if (! $transaction instanceof EEI_Transaction) {
93
+        if ( ! $transaction instanceof EEI_Transaction) {
94 94
             throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
95 95
         }
96 96
         $primary_registrant = $transaction->primary_registration();
97
-        if (! $primary_registrant instanceof EEI_Registration) {
97
+        if ( ! $primary_registrant instanceof EEI_Registration) {
98 98
             throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
99 99
                 'event_espresso'));
100 100
         }
101 101
         $attendee = $primary_registrant->attendee();
102
-        if (! $attendee instanceof EEI_Attendee) {
102
+        if ( ! $attendee instanceof EEI_Attendee) {
103 103
             throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
104 104
                 'event_espresso'));
105 105
         }
106
-		$order_description  = $this->_format_order_description( $payment );
106
+		$order_description = $this->_format_order_description($payment);
107 107
 		//charge for the full amount. Show itemized list
108
-		if( $this->_can_easily_itemize_transaction_for( $payment ) ){
108
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
109 109
 			$item_num = 1;
110 110
 			$total_line_item = $transaction->total_line_item();
111 111
 			$order_items = array();
112 112
 			foreach ($total_line_item->get_items() as $line_item) {
113 113
 				//ignore line items with a quantity of 0
114
-				if( $line_item->quantity() == 0 ) {
114
+				if ($line_item->quantity() == 0) {
115 115
 					continue;
116 116
 				}
117 117
 				$item = array(
118 118
 						// Item Name.  127 char max.
119 119
 						'l_name' => substr(
120
-							$this->_format_line_item_name( $line_item, $payment ),
120
+							$this->_format_line_item_name($line_item, $payment),
121 121
 							0,
122 122
 							127
123 123
 						),
124 124
 						// Item description.  127 char max.
125 125
 						'l_desc' => substr( 
126
-							$this->_format_line_item_desc( $line_item, $payment ),
126
+							$this->_format_line_item_desc($line_item, $payment),
127 127
 							0,
128 128
 							127
129 129
 						),
@@ -147,20 +147,20 @@  discard block
 block discarded – undo
147 147
 			}
148 148
 			$item_amount = $total_line_item->get_items_total();
149 149
 			$tax_amount = $total_line_item->get_total_tax();
150
-		}else{
150
+		} else {
151 151
 			$order_items = array();
152 152
 			$item_amount = $payment->amount();
153 153
 			$tax_amount = 0;
154
-			array_push($order_items,array(
154
+			array_push($order_items, array(
155 155
 				// Item Name.  127 char max.
156 156
 				'l_name' => substr(
157
-					$this->_format_partial_payment_line_item_name( $payment ),
157
+					$this->_format_partial_payment_line_item_name($payment),
158 158
 					0,
159 159
 					127
160 160
 				),
161 161
 				// Item description.  127 char max.
162 162
 				'l_desc' => substr( 
163
-					$this->_format_partial_payment_line_item_desc( $payment ),
163
+					$this->_format_partial_payment_line_item_desc($payment),
164 164
 					0,
165 165
 					127
166 166
 				),
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 			// Payer's salutation.  20 char max.
209 209
 			'salutation' => '',
210 210
 			// Payer's first name.  25 char max.
211
-			'firstname' => substr($billing_info['first_name'],0,25),
211
+			'firstname' => substr($billing_info['first_name'], 0, 25),
212 212
 			// Payer's middle name.  25 char max.
213 213
 			'middlename' => '',
214 214
 			// Payer's last name.  25 char max.
215
-			'lastname' => substr($billing_info['last_name'],0,25),
215
+			'lastname' => substr($billing_info['last_name'], 0, 25),
216 216
 			// Payer's suffix.  12 char max.
217 217
 			'suffix' => ''
218 218
 		);
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			// Required.  Name of City.
226 226
 			'city' => $billing_info['city'],
227 227
 			// Required. Name of State or Province.
228
-			'state' => substr( $billing_info['state'], 0, 40 ),
228
+			'state' => substr($billing_info['state'], 0, 40),
229 229
 			// Required.  Country code.
230 230
 			'countrycode' => $billing_info['country'],
231 231
 			// Required.  Postal code of payer.
@@ -233,21 +233,21 @@  discard block
 block discarded – undo
233 233
 		);
234 234
 
235 235
         //check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
236
-        if($attendee->address() && $attendee->city() && $attendee->country_ID()){
236
+        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
237 237
             $use_registration_address_info = true;
238 238
         } else {
239 239
             $use_registration_address_info = false;
240 240
         }
241 241
         //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
242 242
         $ShippingAddress = array(
243
-            'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
243
+            'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32),
244 244
             'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
245
-            'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'],0,100),
246
-            'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'],0,40),
247
-            'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'],0,40),
245
+            'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100),
246
+            'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40),
247
+            'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'], 0, 40),
248 248
             'shiptocountry' => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'],
249
-            'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'],0,20),
250
-            'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'],0,20),
249
+            'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'], 0, 20),
250
+            'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'], 0, 20),
251 251
         );
252 252
 
253 253
 		$PaymentDetails = array(
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 			// Required.  Three-letter currency code.  Default is USD.
257 257
 			'currencycode' => $payment->currency_code(),
258 258
 			// Required if you include itemized cart details. (L_AMTn, etc.)  Subtotal of items not including S&H, or tax.
259
-			'itemamt' => $this->format_currency($item_amount),//
259
+			'itemamt' => $this->format_currency($item_amount), //
260 260
 			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
261 261
 			'shippingamt' => '',
262 262
 			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 			// Free-form field for your own use.  256 char max.
269 269
 			'custom' => $primary_registrant ? $primary_registrant->ID() : '',
270 270
 			// Your own invoice or tracking number
271
-			'invnum' => wp_generate_password(12,false),//$transaction->ID(),
271
+			'invnum' => wp_generate_password(12, false), //$transaction->ID(),
272 272
 			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
273 273
 			'notifyurl' => '',
274
-			'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
274
+			'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this
275 275
 		);
276 276
 		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
277 277
 		$PayPalRequestData = array(
@@ -285,32 +285,32 @@  discard block
 block discarded – undo
285 285
 				'OrderItems' => $order_items,
286 286
 		);
287 287
 		$this->_log_clean_request($PayPalRequestData, $payment);
288
-		try{
288
+		try {
289 289
 			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
290 290
 			//remove PCI-sensitive data so it doesn't get stored
291
-			$PayPalResult = $this->_log_clean_response($PayPalResult,$payment);
291
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
292 292
 
293 293
 			$message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
294
-			if( empty($PayPalResult[ 'RAWRESPONSE' ] ) ) {
295
-				$payment->set_status( $this->_pay_model->failed_status() ) ;
296
-				$payment->set_gateway_response( __( 'No response received from Paypal Pro', 'event_espresso' ) );
294
+			if (empty($PayPalResult['RAWRESPONSE'])) {
295
+				$payment->set_status($this->_pay_model->failed_status());
296
+				$payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
297 297
 				$payment->set_details($PayPalResult);
298
-			}else{
299
-				if($this->_APICallSuccessful($PayPalResult)){
298
+			} else {
299
+				if ($this->_APICallSuccessful($PayPalResult)) {
300 300
 					$payment->set_status($this->_pay_model->approved_status());
301
-				}else{
301
+				} else {
302 302
 					$payment->set_status($this->_pay_model->declined_status());
303 303
 				}
304 304
 				//make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
305
-				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval( $PayPalResult['AMT'] ) : 0);
305
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
306 306
 				$payment->set_gateway_response($message);
307
-				$payment->set_txn_id_chq_nmbr(isset( $PayPalResult['TRANSACTIONID'] )? $PayPalResult['TRANSACTIONID'] : null);
307
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null);
308 308
 
309 309
 				$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
310 310
 				$payment->set_extra_accntng($primary_registration_code);
311 311
 				$payment->set_details($PayPalResult);
312 312
 			}
313
-		}catch(Exception $e){
313
+		} catch (Exception $e) {
314 314
 			$payment->set_status($this->_pay_model->failed_status());
315 315
 			$payment->set_gateway_response($e->getMessage());
316 316
 		}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 * @param EEI_Payment $payment
328 328
 	 * @return array
329 329
 	 */
330
-	private function _log_clean_request($request,$payment){
330
+	private function _log_clean_request($request, $payment) {
331 331
 		$cleaned_request_data = $request;
332 332
 		unset($cleaned_request_data['CCDetails']['acct']);
333 333
 		unset($cleaned_request_data['CCDetails']['cvv2']);
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
 	 * @param EEI_Payment $payment
344 344
 	 * @return array cleaned
345 345
 	 */
346
-	private function _log_clean_response($response,$payment){
346
+	private function _log_clean_response($response, $payment) {
347 347
 		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
348 348
 		unset($response['REQUESTDATA']['ACCT']);
349 349
 		unset($response['REQUESTDATA']['EXPDATE']);
350 350
 		unset($response['REQUESTDATA']['CVV2']);
351 351
 		unset($response['RAWREQUEST']);
352
-		$this->log(array('Paypal Response'=>$response),$payment);
352
+		$this->log(array('Paypal Response'=>$response), $payment);
353 353
 		return $response;
354 354
 	}
355 355
 
@@ -374,32 +374,32 @@  discard block
 block discarded – undo
374 374
 		// DP Fields
375 375
 		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
376 376
 		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal)
377
-			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
377
+			$DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal);
378 378
 
379 379
 		// CC Details Fields
380 380
 		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
381 381
 		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal)
382
-			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
382
+			$CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal);
383 383
 
384 384
 		// PayerInfo Type Fields
385 385
 		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
386 386
 		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal)
387
-			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
387
+			$PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal);
388 388
 
389 389
 		// Payer Name Fields
390 390
 		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
391 391
 		foreach ($PayerName as $PayerNameVar => $PayerNameVal)
392
-			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
392
+			$PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal);
393 393
 
394 394
 		// Address Fields (Billing)
395 395
 		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
396 396
 		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal)
397
-			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
397
+			$BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal);
398 398
 
399 399
 		// Payment Details Type Fields
400 400
 		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
401 401
 		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal)
402
-			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
402
+			$PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal);
403 403
 
404 404
 		// Payment Details Item Type Fields
405 405
 		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
@@ -407,22 +407,22 @@  discard block
 block discarded – undo
407 407
 		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
408 408
 			$CurrentItem = $OrderItems[$OrderItemsVar];
409 409
 			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal)
410
-				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
410
+				$OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal);
411 411
 			$n++;
412 412
 		}
413 413
 
414 414
 		// Ship To Address Fields
415 415
 		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
416 416
 		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal)
417
-			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
417
+			$ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal);
418 418
 
419 419
 		// 3D Secure Fields
420 420
 		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
421 421
 		foreach ($Secure3D as $Secure3DVar => $Secure3DVal)
422
-			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
422
+			$Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal);
423 423
 
424 424
 		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
425
-		$NVPRequest = 'USER=' . $this->_username . '&PWD=' . $this->_password . '&VERSION=64.0' . '&SIGNATURE=' . $this->_signature . $DPFieldsNVP . $CCDetailsNVP . $PayerInfoNVP . $PayerNameNVP . $BillingAddressNVP . $PaymentDetailsNVP . $OrderItemsNVP . $ShippingAddressNVP . $Secure3DNVP;
425
+		$NVPRequest = 'USER='.$this->_username.'&PWD='.$this->_password.'&VERSION=64.0'.'&SIGNATURE='.$this->_signature.$DPFieldsNVP.$CCDetailsNVP.$PayerInfoNVP.$PayerNameNVP.$BillingAddressNVP.$PaymentDetailsNVP.$OrderItemsNVP.$ShippingAddressNVP.$Secure3DNVP;
426 426
 		$NVPResponse = $this->_CURLRequest($NVPRequest);
427 427
 		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
428 428
 		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	private function _CURLRequest($Request) {
447 447
 		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
448 448
 		$curl = curl_init();
449
-		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', TRUE ) );
449
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', TRUE));
450 450
 		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
451 451
 		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
452 452
 		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
@@ -496,9 +496,9 @@  discard block
 block discarded – undo
496 496
 	private function _APICallSuccessful($PayPalResult) {
497 497
 		$approved = false;
498 498
 		// check main response message from PayPal
499
-		if (isset($PayPalResult['ACK']) && !empty($PayPalResult['ACK'])) {
499
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
500 500
 			$ack = strtoupper($PayPalResult['ACK']);
501
-			$approved = ( $ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS' ) ? true : false;
501
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
502 502
 		}
503 503
 
504 504
 		return $approved;
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 
515 515
 		$Errors = array();
516 516
 		$n = 0;
517
-		while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
518
-			$LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
519
-			$LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : '';
520
-			$LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : '';
521
-			$LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : '';
517
+		while (isset($DataArray['L_ERRORCODE'.$n.''])) {
518
+			$LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : '';
519
+			$LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) ? $DataArray['L_SHORTMESSAGE'.$n.''] : '';
520
+			$LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) ? $DataArray['L_LONGMESSAGE'.$n.''] : '';
521
+			$LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) ? $DataArray['L_SEVERITYCODE'.$n.''] : '';
522 522
 
523 523
 			$CurrentItem = array(
524 524
 					'L_ERRORCODE' => $LErrorCode,
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 				elseif ($CurrentErrorVar == 'L_SEVERITYCODE')
559 559
 					$CurrentVarName = 'Severity Code';
560 560
 
561
-				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
561
+				$error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal;
562 562
 			}
563 563
 		}
564 564
 		return $error;
Please login to merge, or discard this patch.
Braces   +42 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION'))
3
+if (!defined('EVENT_ESPRESSO_VERSION')) {
4 4
 	exit('No direct script access allowed');
5
+}
5 6
 
6 7
 /**
7 8
  * Event Espresso
@@ -147,7 +148,7 @@  discard block
 block discarded – undo
147 148
 			}
148 149
 			$item_amount = $total_line_item->get_items_total();
149 150
 			$tax_amount = $total_line_item->get_total_tax();
150
-		}else{
151
+		} else{
151 152
 			$order_items = array();
152 153
 			$item_amount = $payment->amount();
153 154
 			$tax_amount = 0;
@@ -295,10 +296,10 @@  discard block
 block discarded – undo
295 296
 				$payment->set_status( $this->_pay_model->failed_status() ) ;
296 297
 				$payment->set_gateway_response( __( 'No response received from Paypal Pro', 'event_espresso' ) );
297 298
 				$payment->set_details($PayPalResult);
298
-			}else{
299
+			} else{
299 300
 				if($this->_APICallSuccessful($PayPalResult)){
300 301
 					$payment->set_status($this->_pay_model->approved_status());
301
-				}else{
302
+				} else{
302 303
 					$payment->set_status($this->_pay_model->declined_status());
303 304
 				}
304 305
 				//make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
@@ -310,7 +311,7 @@  discard block
 block discarded – undo
310 311
 				$payment->set_extra_accntng($primary_registration_code);
311 312
 				$payment->set_details($PayPalResult);
312 313
 			}
313
-		}catch(Exception $e){
314
+		} catch(Exception $e){
314 315
 			$payment->set_status($this->_pay_model->failed_status());
315 316
 			$payment->set_gateway_response($e->getMessage());
316 317
 		}
@@ -373,53 +374,62 @@  discard block
 block discarded – undo
373 374
 
374 375
 		// DP Fields
375 376
 		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
376
-		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal)
377
-			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
377
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
378
+					$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
379
+		}
378 380
 
379 381
 		// CC Details Fields
380 382
 		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
381
-		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal)
382
-			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
383
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
384
+					$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
385
+		}
383 386
 
384 387
 		// PayerInfo Type Fields
385 388
 		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
386
-		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal)
387
-			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
389
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
390
+					$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
391
+		}
388 392
 
389 393
 		// Payer Name Fields
390 394
 		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
391
-		foreach ($PayerName as $PayerNameVar => $PayerNameVal)
392
-			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
395
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
396
+					$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
397
+		}
393 398
 
394 399
 		// Address Fields (Billing)
395 400
 		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
396
-		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal)
397
-			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
401
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
402
+					$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
403
+		}
398 404
 
399 405
 		// Payment Details Type Fields
400 406
 		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
401
-		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal)
402
-			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
407
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
408
+					$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
409
+		}
403 410
 
404 411
 		// Payment Details Item Type Fields
405 412
 		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
406 413
 		$n = 0;
407 414
 		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
408 415
 			$CurrentItem = $OrderItems[$OrderItemsVar];
409
-			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal)
410
-				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
416
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
417
+							$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
418
+			}
411 419
 			$n++;
412 420
 		}
413 421
 
414 422
 		// Ship To Address Fields
415 423
 		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
416
-		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal)
417
-			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
424
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
425
+					$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
426
+		}
418 427
 
419 428
 		// 3D Secure Fields
420 429
 		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
421
-		foreach ($Secure3D as $Secure3DVar => $Secure3DVal)
422
-			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
430
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
431
+					$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
432
+		}
423 433
 
424 434
 		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
425 435
 		$NVPRequest = 'USER=' . $this->_username . '&PWD=' . $this->_password . '&VERSION=64.0' . '&SIGNATURE=' . $this->_signature . $DPFieldsNVP . $CCDetailsNVP . $PayerInfoNVP . $PayerNameNVP . $BillingAddressNVP . $PaymentDetailsNVP . $OrderItemsNVP . $ShippingAddressNVP . $Secure3DNVP;
@@ -549,14 +559,15 @@  discard block
 block discarded – undo
549 559
 			$CurrentError = $Errors[$ErrorVar];
550 560
 			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
551 561
 				$CurrentVarName = '';
552
-				if ($CurrentErrorVar == 'L_ERRORCODE')
553
-					$CurrentVarName = 'Error Code';
554
-				elseif ($CurrentErrorVar == 'L_SHORTMESSAGE')
555
-					$CurrentVarName = 'Short Message';
556
-				elseif ($CurrentErrorVar == 'L_LONGMESSAGE')
557
-					$CurrentVarName = 'Long Message';
558
-				elseif ($CurrentErrorVar == 'L_SEVERITYCODE')
559
-					$CurrentVarName = 'Severity Code';
562
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
563
+									$CurrentVarName = 'Error Code';
564
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
565
+									$CurrentVarName = 'Short Message';
566
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
567
+									$CurrentVarName = 'Long Message';
568
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
569
+									$CurrentVarName = 'Severity Code';
570
+				}
560 571
 
561 572
 				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
562 573
 			}
Please login to merge, or discard this patch.