Completed
Branch FET-8394-RULES (1ae5e4)
by
unknown
50:31 queued 37:22
created
core/domain/entities/DbSafeDateTime.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
 	protected $_datetime_string = '';
33 33
 
34 34
 	/**
35
-     * where to write the error log to
36
-     *
37
-     * @type string $_error_log_dir
35
+	 * where to write the error log to
36
+	 *
37
+	 * @type string $_error_log_dir
38 38
 	 */
39 39
 	protected $_error_log_dir = '';
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @param string $error_log_dir
45
-     */
46
-    public function setErrorLogDir($error_log_dir)
47
-    {
48
-        // if the folder path is writable, then except the path + filename, else keep empty
49
-        $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
-            ?  $error_log_dir
51
-            : '';
52
-    }
43
+	/**
44
+	 * @param string $error_log_dir
45
+	 */
46
+	public function setErrorLogDir($error_log_dir)
47
+	{
48
+		// if the folder path is writable, then except the path + filename, else keep empty
49
+		$this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
+			?  $error_log_dir
51
+			: '';
52
+	}
53 53
 
54 54
 
55 55
 
@@ -61,84 +61,84 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function __sleep() {
63 63
 		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
64
-        $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
-        if ( ! $date instanceof \DateTime) {
66
-            try {
67
-                // we want a stack trace to determine where the malformed date came from, so...
68
-                throw new \DomainException();
69
-            } catch (\DomainException $e) {
70
-                $stack_trace = $e->getTraceAsString();
71
-            }
72
-            $this->writeToErrorLog(
73
-                sprintf(
74
-                    __(
75
-                        'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
-                        'event_espresso'
77
-                    ),
78
-                    $this->_datetime_string,
79
-                    '<br />',
80
-                    print_r(\DateTime::getLastErrors(), true),
81
-                    PHP_VERSION,
82
-                    $stack_trace
83
-                )
84
-            );
85
-        }
86
-        return array( '_datetime_string' );
64
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
+		if ( ! $date instanceof \DateTime) {
66
+			try {
67
+				// we want a stack trace to determine where the malformed date came from, so...
68
+				throw new \DomainException();
69
+			} catch (\DomainException $e) {
70
+				$stack_trace = $e->getTraceAsString();
71
+			}
72
+			$this->writeToErrorLog(
73
+				sprintf(
74
+					__(
75
+						'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
+						'event_espresso'
77
+					),
78
+					$this->_datetime_string,
79
+					'<br />',
80
+					print_r(\DateTime::getLastErrors(), true),
81
+					PHP_VERSION,
82
+					$stack_trace
83
+				)
84
+			);
85
+		}
86
+		return array( '_datetime_string' );
87 87
 	}
88 88
 
89 89
 
90 90
 
91 91
 	public function __wakeup() {
92
-	    // if an empty or null value got saved to the db for a datetime,
93
-        // then some servers and/or PHP itself will incorrectly convert that date string
94
-        // resulting in "-0001-11-30" for the year-month-day.
95
-        // We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
-        // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
-        // so we're no better off, but at least things won't go fatal on us.
98
-        $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
92
+		// if an empty or null value got saved to the db for a datetime,
93
+		// then some servers and/or PHP itself will incorrectly convert that date string
94
+		// resulting in "-0001-11-30" for the year-month-day.
95
+		// We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
+		// but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
+		// so we're no better off, but at least things won't go fatal on us.
98
+		$this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
99 99
 		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
100 100
 		if ( ! $date instanceof \DateTime) {
101
-            $this->writeToErrorLog(
102
-                sprintf(
103
-                    __(
104
-                        'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
-                        'event_espresso'
106
-                    ),
107
-                    $this->_datetime_string,
108
-                    '<br />',
109
-                    print_r(\DateTime::getLastErrors(), true),
110
-                    PHP_VERSION
111
-                )
112
-            );
113
-        } else {
114
-            $this->__construct(
115
-                $date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
-                new \DateTimeZone($date->format('e'))
117
-            );
118
-        }
101
+			$this->writeToErrorLog(
102
+				sprintf(
103
+					__(
104
+						'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
+						'event_espresso'
106
+					),
107
+					$this->_datetime_string,
108
+					'<br />',
109
+					print_r(\DateTime::getLastErrors(), true),
110
+					PHP_VERSION
111
+				)
112
+			);
113
+		} else {
114
+			$this->__construct(
115
+				$date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
+				new \DateTimeZone($date->format('e'))
117
+			);
118
+		}
119 119
 	}
120 120
 
121
-    /**
122
-     * Creates a DbSafeDateTime from ye old DateTime
123
-     * @param \DateTime $datetime
124
-     * @return \EventEspresso\core\domain\entities\DbSafeDateTime
125
-     */
126
-    public static function createFromDateTime(\DateTime $datetime)
127
-    {
128
-        return new DbSafeDateTime(
129
-            $datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
130
-            new \DateTimeZone($datetime->format('e'))
131
-        );
132
-    }
133
-
134
-    private function writeToErrorLog($message)
135
-    {
136
-        if ( ! empty($this->_error_log_dir)) {
137
-            error_log($message, 3, $this->_error_log_dir);
138
-        } else {
139
-            error_log($message);
140
-        }
141
-    }
121
+	/**
122
+	 * Creates a DbSafeDateTime from ye old DateTime
123
+	 * @param \DateTime $datetime
124
+	 * @return \EventEspresso\core\domain\entities\DbSafeDateTime
125
+	 */
126
+	public static function createFromDateTime(\DateTime $datetime)
127
+	{
128
+		return new DbSafeDateTime(
129
+			$datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
130
+			new \DateTimeZone($datetime->format('e'))
131
+		);
132
+	}
133
+
134
+	private function writeToErrorLog($message)
135
+	{
136
+		if ( ! empty($this->_error_log_dir)) {
137
+			error_log($message, 3, $this->_error_log_dir);
138
+		} else {
139
+			error_log($message);
140
+		}
141
+	}
142 142
 
143 143
 
144 144
 }
Please login to merge, or discard this patch.
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/libraries/batch/JobHandlers/RegistrationsReport.php 3 patches
Indentation   +395 added lines, -396 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use EventEspressoBatchRequest\Helpers\JobStepResponse;
18 18
 
19 19
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -25,424 +25,423 @@  discard block
 block discarded – undo
25 25
 class RegistrationsReport extends JobHandlerFile
26 26
 {
27 27
 
28
-    /**
29
-     * Performs any necessary setup for starting the job. This is also a good
30
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
-     * when continue_job will be called
32
-     *
33
-     * @param JobParameters $job_parameters
34
-     * @throws BatchRequestException
35
-     * @return JobStepResponse
36
-     */
37
-    public function create_job(JobParameters $job_parameters)
38
-    {
39
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
-        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
-        }
43
-        $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
-            $this->get_filename($event_id));
45
-        $job_parameters->add_extra_data('filepath', $filepath);
46
-        if ($job_parameters->request_datum('use_filters', false)) {
47
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
-        } else {
49
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
-                array(
51
-                    'OR'                 => array(
52
-                        //don't include registrations from failed or abandoned transactions...
53
-                        'Transaction.STS_ID' => array(
54
-                            'NOT IN',
55
-                            array(
56
-                                \EEM_Transaction::failed_status_code,
57
-                                \EEM_Transaction::abandoned_status_code,
58
-                            ),
59
-                        ),
60
-                        //unless the registration is approved, in which case include it regardless of transaction status
61
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
62
-                    ),
63
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
-                ),
65
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
-                'caps'       => \EEM_Base::caps_read_admin,
68
-            ), $event_id);
69
-            if ($event_id) {
70
-                $query_params[0]['EVT_ID'] = $event_id;
71
-            } else {
72
-                $query_params['force_join'][] = 'Event';
73
-            }
74
-        }
75
-        if ( ! isset($query_params['force_join'])) {
76
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
-        }
78
-        $job_parameters->add_extra_data('query_params', $query_params);
79
-        $question_labels = $this->_get_question_labels($query_params);
80
-        $job_parameters->add_extra_data('question_labels', $question_labels);
81
-        $job_parameters->set_job_size(
82
-            \EEM_Registration::instance()->count(
83
-                array_diff_key(
84
-                    $query_params,
85
-                    array_flip(
86
-                        array( 'limit' )
87
-                    )
88
-                )
89
-            )
90
-        );
91
-        //we should also set the header columns
92
-        $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
-            $job_parameters->extra_datum('query_params'));
94
-        \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
-        //if we actually processed a row there, record it
96
-        if ($job_parameters->job_size()) {
97
-            $job_parameters->mark_processed(1);
98
-        }
99
-        return new JobStepResponse($job_parameters,
100
-            __('Registrations report started successfully...', 'event_espresso'));
101
-    }
28
+	/**
29
+	 * Performs any necessary setup for starting the job. This is also a good
30
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
+	 * when continue_job will be called
32
+	 *
33
+	 * @param JobParameters $job_parameters
34
+	 * @throws BatchRequestException
35
+	 * @return JobStepResponse
36
+	 */
37
+	public function create_job(JobParameters $job_parameters)
38
+	{
39
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
+		if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
+		}
43
+		$filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
+			$this->get_filename($event_id));
45
+		$job_parameters->add_extra_data('filepath', $filepath);
46
+		if ($job_parameters->request_datum('use_filters', false)) {
47
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
+		} else {
49
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
+				array(
51
+					'OR'                 => array(
52
+						//don't include registrations from failed or abandoned transactions...
53
+						'Transaction.STS_ID' => array(
54
+							'NOT IN',
55
+							array(
56
+								\EEM_Transaction::failed_status_code,
57
+								\EEM_Transaction::abandoned_status_code,
58
+							),
59
+						),
60
+						//unless the registration is approved, in which case include it regardless of transaction status
61
+						'STS_ID'             => \EEM_Registration::status_id_approved,
62
+					),
63
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
+				),
65
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
+				'caps'       => \EEM_Base::caps_read_admin,
68
+			), $event_id);
69
+			if ($event_id) {
70
+				$query_params[0]['EVT_ID'] = $event_id;
71
+			} else {
72
+				$query_params['force_join'][] = 'Event';
73
+			}
74
+		}
75
+		if ( ! isset($query_params['force_join'])) {
76
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
+		}
78
+		$job_parameters->add_extra_data('query_params', $query_params);
79
+		$question_labels = $this->_get_question_labels($query_params);
80
+		$job_parameters->add_extra_data('question_labels', $question_labels);
81
+		$job_parameters->set_job_size(
82
+			\EEM_Registration::instance()->count(
83
+				array_diff_key(
84
+					$query_params,
85
+					array_flip(
86
+						array( 'limit' )
87
+					)
88
+				)
89
+			)
90
+		);
91
+		//we should also set the header columns
92
+		$csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
+			$job_parameters->extra_datum('query_params'));
94
+		\EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
+		//if we actually processed a row there, record it
96
+		if ($job_parameters->job_size()) {
97
+			$job_parameters->mark_processed(1);
98
+		}
99
+		return new JobStepResponse($job_parameters,
100
+			__('Registrations report started successfully...', 'event_espresso'));
101
+	}
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * Gets the filename
107
-     * @return string
108
-     */
109
-    protected function get_filename()
110
-    {
111
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
-    }
105
+	/**
106
+	 * Gets the filename
107
+	 * @return string
108
+	 */
109
+	protected function get_filename()
110
+	{
111
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
+	}
113 113
 
114 114
 
115 115
 
116
-    /**
117
-     * Gets the questions which are to be used for this report, so they
118
-     * can be remembered for later
119
-     *
120
-     * @param array $registration_query_params
121
-     * @return array question admin labels to be used for this report
122
-     */
123
-    protected function _get_question_labels($registration_query_params)
124
-    {
125
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
-        $question_query_params = array();
127
-        if ($where !== null) {
128
-            $question_query_params = array(
129
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
-            );
131
-        }
132
-        $question_query_params[0]['Answer.ANS_ID'] = array( 'IS_NOT_NULL' );
133
-        $question_query_params['group_by'] = array( 'QST_ID' );
134
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
135
-    }
116
+	/**
117
+	 * Gets the questions which are to be used for this report, so they
118
+	 * can be remembered for later
119
+	 *
120
+	 * @param array $registration_query_params
121
+	 * @return array question admin labels to be used for this report
122
+	 */
123
+	protected function _get_question_labels($registration_query_params)
124
+	{
125
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
+		$question_query_params = array();
127
+		if ($where !== null) {
128
+			$question_query_params = array(
129
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
+			);
131
+		}
132
+		$question_query_params[0]['Answer.ANS_ID'] = array( 'IS_NOT_NULL' );
133
+		$question_query_params['group_by'] = array( 'QST_ID' );
134
+		return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
135
+	}
136 136
 
137 137
 
138 138
 
139
-    /**
140
-     * Takes where params meant for registrations and changes them to work for questions
141
-     *
142
-     * @param array $reg_where_params
143
-     * @return array
144
-     */
145
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
146
-    {
147
-        $question_where_params = array();
148
-        foreach ($reg_where_params as $key => $val) {
149
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
150
-                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
151
-            } else {
152
-                //it's a normal where condition
153
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
154
-            }
155
-        }
156
-        return $question_where_params;
157
-    }
139
+	/**
140
+	 * Takes where params meant for registrations and changes them to work for questions
141
+	 *
142
+	 * @param array $reg_where_params
143
+	 * @return array
144
+	 */
145
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
146
+	{
147
+		$question_where_params = array();
148
+		foreach ($reg_where_params as $key => $val) {
149
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
150
+				$question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
151
+			} else {
152
+				//it's a normal where condition
153
+				$question_where_params['Question_Group.Event.Registration.' . $key] = $val;
154
+			}
155
+		}
156
+		return $question_where_params;
157
+	}
158 158
 
159 159
 
160 160
 
161
-    /**
162
-     * Performs another step of the job
163
-     *
164
-     * @param JobParameters $job_parameters
165
-     * @param int           $batch_size
166
-     * @return JobStepResponse
167
-     * @throws \EE_Error
168
-     */
169
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
170
-    {
171
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
172
-            $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
173
-                $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
174
-                $job_parameters->extra_datum('query_params'));
175
-            \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
176
-            $units_processed = count($csv_data);
177
-        }else{
178
-            $units_processed = 0;
179
-        }
180
-        $job_parameters->mark_processed($units_processed);
181
-        $extra_response_data = array(
182
-            'file_url' => '',
183
-        );
184
-        if ($units_processed < $batch_size) {
185
-            $job_parameters->set_status(JobParameters::status_complete);
186
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
187
-        }
161
+	/**
162
+	 * Performs another step of the job
163
+	 *
164
+	 * @param JobParameters $job_parameters
165
+	 * @param int           $batch_size
166
+	 * @return JobStepResponse
167
+	 * @throws \EE_Error
168
+	 */
169
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
170
+	{
171
+		if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
172
+			$csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
173
+				$job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
174
+				$job_parameters->extra_datum('query_params'));
175
+			\EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
176
+			$units_processed = count($csv_data);
177
+		}else{
178
+			$units_processed = 0;
179
+		}
180
+		$job_parameters->mark_processed($units_processed);
181
+		$extra_response_data = array(
182
+			'file_url' => '',
183
+		);
184
+		if ($units_processed < $batch_size) {
185
+			$job_parameters->set_status(JobParameters::status_complete);
186
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
187
+		}
188 188
 
189
-        return new JobStepResponse($job_parameters,
190
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
191
-            $extra_response_data);
192
-    }
189
+		return new JobStepResponse($job_parameters,
190
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
191
+			$extra_response_data);
192
+	}
193 193
 
194 194
 
195 195
 
196
-    /**
197
-     * Gets the csv data for a batch of registrations
198
-
199
-     *
196
+	/**
197
+	 * Gets the csv data for a batch of registrations
198
+	 *
200 199
 *@param int|null    $event_id
201
-     * @param int   $offset
202
-     * @param int   $limit
203
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
204
-     * @param array $query_params    for using where querying the model
205
-     * @return array top-level keys are numeric, next-level keys are column headers
206
-     */
207
-    function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
208
-    {
209
-        $reg_fields_to_include = array(
210
-            'TXN_ID',
211
-            'ATT_ID',
212
-            'REG_ID',
213
-            'REG_date',
214
-            'REG_code',
215
-            'REG_count',
216
-            'REG_final_price',
217
-        );
218
-        $att_fields_to_include = array(
219
-            'ATT_fname',
220
-            'ATT_lname',
221
-            'ATT_email',
222
-            'ATT_address',
223
-            'ATT_address2',
224
-            'ATT_city',
225
-            'STA_ID',
226
-            'CNT_ISO',
227
-            'ATT_zip',
228
-            'ATT_phone',
229
-        );
230
-        $registrations_csv_ready_array = array();
231
-        $reg_model = \EE_Registry::instance()->load_model('Registration');
232
-        $query_params['limit'] = array($offset, $limit);
233
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
234
-        $registration_ids = array();
235
-        foreach ($registration_rows as $reg_row) {
236
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
237
-        }
238
-        foreach ($registration_rows as $reg_row) {
239
-            if (is_array($reg_row)) {
240
-                $reg_csv_array = array();
241
-                if ( ! $event_id) {
242
-                    //get the event's name and Id
243
-                    $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
244
-                        \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
245
-                            $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
246
-                }
247
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
248
-                /*@var $reg_row EE_Registration */
249
-                foreach ($reg_fields_to_include as $field_name) {
250
-                    $field = $reg_model->field_settings_for($field_name);
251
-                    if ($field_name == 'REG_final_price') {
252
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
253
-                            $reg_row['Registration.REG_final_price'], 'localized_float');
254
-                    } elseif ($field_name == 'REG_count') {
255
-                        $value = sprintf(__('%s of %s', 'event_espresso'),
256
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
257
-                                $reg_row['Registration.REG_count']),
258
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
259
-                                $reg_row['Registration.REG_group_size']));
260
-                    } elseif ($field_name == 'REG_date') {
261
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
262
-                            $reg_row['Registration.REG_date'], 'no_html');
263
-                    } else {
264
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
265
-                            $reg_row[$field->get_qualified_column()]);
266
-                    }
267
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
268
-                    if ($field_name == 'REG_final_price') {
269
-                        //add a column named Currency after the final price
270
-                        $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
271
-                    }
272
-                }
273
-                //get pretty status
274
-                $stati = \EEM_Status::instance()->localized_status(array(
275
-                    $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
276
-                    $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
277
-                ), false, 'sentence');
278
-                $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
279
-                //get pretty transaction status
280
-                $reg_csv_array[__("Transaction Status",
281
-                    'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
282
-                $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
283
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
284
-                        $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
285
-                $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
286
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
287
-                        $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
288
-                $payment_methods = array();
289
-                $gateway_txn_ids_etc = array();
290
-                $payment_times = array();
291
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
292
-                    $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
293
-                        array(
294
-                            'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
295
-                            'STS_ID' => \EEM_Payment::status_id_approved,
296
-                        ),
297
-                        'force_join' => array('Payment_Method'),
298
-                    ), ARRAY_A,
299
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
300
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
301
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
302
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
303
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
304
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
305
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
306
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
307
-                    }
308
-                }
309
-                $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
310
-                $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
311
-                $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
312
-                //get whether or not the user has checked in
313
-                $reg_csv_array[__("Check-Ins",
314
-                    "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
315
-                //get ticket of registration and its price
316
-                $ticket_model = \EE_Registry::instance()->load_model('Ticket');
317
-                if ($reg_row['Ticket.TKT_ID']) {
318
-                    $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
319
-                        $reg_row['Ticket.TKT_name']);
320
-                    $datetimes_strings = array();
321
-                    foreach (
322
-                        \EEM_Datetime::instance()->get_all_wpdb_results(array(
323
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
324
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
325
-                            'default_where_conditions' => 'none',
326
-                        )) as $datetime
327
-                    ) {
328
-                        $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
329
-                            'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
330
-                    }
331
-                } else {
332
-                    $ticket_name = __('Unknown', 'event_espresso');
333
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
334
-                }
335
-                $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
336
-                $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
337
-                //get datetime(s) of registration
338
-                //add attendee columns
339
-                foreach ($att_fields_to_include as $att_field_name) {
340
-                    $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
341
-                    if ($reg_row['Attendee_CPT.ID']) {
342
-                        if ($att_field_name == 'STA_ID') {
343
-                            $value = \EEM_State::instance()
344
-                                               ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
345
-                                                   'STA_name');
346
-                        } elseif ($att_field_name == 'CNT_ISO') {
347
-                            $value = \EEM_Country::instance()
348
-                                                 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
349
-                                                     'CNT_name');
350
-                        } else {
351
-                            $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
352
-                                $att_field_name, $reg_row[$field_obj->get_qualified_column()]);
353
-                        }
354
-                    } else {
355
-                        $value = '';
356
-                    }
357
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
358
-                }
359
-                //make sure each registration has the same questions in the same order
360
-                foreach ($question_labels as $question_label) {
361
-                    if ( ! isset($reg_csv_array[$question_label])) {
362
-                        $reg_csv_array[$question_label] = null;
363
-                    }
364
-                }
365
-                $answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
366
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
367
-                    'force_join' => array('Question'),
368
-                ));
369
-                //now fill out the questions THEY answered
370
-                foreach ($answers as $answer_row) {
371
-                    if ($answer_row['Question.QST_ID']) {
372
-                        $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
373
-                            'QST_admin_label', $answer_row['Question.QST_admin_label']);
374
-                    } else {
375
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
376
-                    }
377
-                    if (isset($answer_row['Question.QST_type'])
378
-                        && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
379
-                    ) {
380
-                        $reg_csv_array[$question_label] = \EEM_State::instance()
381
-                                                                    ->get_state_name_by_ID($answer_row['Answer.ANS_value']);
382
-                    } else {
383
-                        //this isn't for html, so don't show html entities
384
-                        $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
385
-                            'ANS_value', $answer_row['Answer.ANS_value']));
386
-                    }
387
-                }
388
-                $registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array',
389
-                    $reg_csv_array, $reg_row);
390
-            }
391
-        }
392
-        //if we couldn't export anything, we want to at least show the column headers
393
-        if (empty($registrations_csv_ready_array)) {
394
-            $reg_csv_array = array();
395
-            $model_and_fields_to_include = array(
396
-                'Registration' => $reg_fields_to_include,
397
-                'Attendee'     => $att_fields_to_include,
398
-            );
399
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
400
-                $model = \EE_Registry::instance()->load_model($model_name);
401
-                foreach ($field_list as $field_name) {
402
-                    $field = $model->field_settings_for($field_name);
403
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
404
-                }
405
-            }
406
-            $registrations_csv_ready_array[] = $reg_csv_array;
407
-        }
408
-        return $registrations_csv_ready_array;
409
-    }
200
+	 * @param int   $offset
201
+	 * @param int   $limit
202
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
203
+	 * @param array $query_params    for using where querying the model
204
+	 * @return array top-level keys are numeric, next-level keys are column headers
205
+	 */
206
+	function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
207
+	{
208
+		$reg_fields_to_include = array(
209
+			'TXN_ID',
210
+			'ATT_ID',
211
+			'REG_ID',
212
+			'REG_date',
213
+			'REG_code',
214
+			'REG_count',
215
+			'REG_final_price',
216
+		);
217
+		$att_fields_to_include = array(
218
+			'ATT_fname',
219
+			'ATT_lname',
220
+			'ATT_email',
221
+			'ATT_address',
222
+			'ATT_address2',
223
+			'ATT_city',
224
+			'STA_ID',
225
+			'CNT_ISO',
226
+			'ATT_zip',
227
+			'ATT_phone',
228
+		);
229
+		$registrations_csv_ready_array = array();
230
+		$reg_model = \EE_Registry::instance()->load_model('Registration');
231
+		$query_params['limit'] = array($offset, $limit);
232
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
233
+		$registration_ids = array();
234
+		foreach ($registration_rows as $reg_row) {
235
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
236
+		}
237
+		foreach ($registration_rows as $reg_row) {
238
+			if (is_array($reg_row)) {
239
+				$reg_csv_array = array();
240
+				if ( ! $event_id) {
241
+					//get the event's name and Id
242
+					$reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
243
+						\EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
244
+							$reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
245
+				}
246
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
247
+				/*@var $reg_row EE_Registration */
248
+				foreach ($reg_fields_to_include as $field_name) {
249
+					$field = $reg_model->field_settings_for($field_name);
250
+					if ($field_name == 'REG_final_price') {
251
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
252
+							$reg_row['Registration.REG_final_price'], 'localized_float');
253
+					} elseif ($field_name == 'REG_count') {
254
+						$value = sprintf(__('%s of %s', 'event_espresso'),
255
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
256
+								$reg_row['Registration.REG_count']),
257
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
258
+								$reg_row['Registration.REG_group_size']));
259
+					} elseif ($field_name == 'REG_date') {
260
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
261
+							$reg_row['Registration.REG_date'], 'no_html');
262
+					} else {
263
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
264
+							$reg_row[$field->get_qualified_column()]);
265
+					}
266
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
267
+					if ($field_name == 'REG_final_price') {
268
+						//add a column named Currency after the final price
269
+						$reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
270
+					}
271
+				}
272
+				//get pretty status
273
+				$stati = \EEM_Status::instance()->localized_status(array(
274
+					$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
275
+					$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
276
+				), false, 'sentence');
277
+				$reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
278
+				//get pretty transaction status
279
+				$reg_csv_array[__("Transaction Status",
280
+					'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
281
+				$reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
282
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
283
+						$reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
284
+				$reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
285
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
286
+						$reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
287
+				$payment_methods = array();
288
+				$gateway_txn_ids_etc = array();
289
+				$payment_times = array();
290
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
291
+					$payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
292
+						array(
293
+							'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
294
+							'STS_ID' => \EEM_Payment::status_id_approved,
295
+						),
296
+						'force_join' => array('Payment_Method'),
297
+					), ARRAY_A,
298
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
299
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
300
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
301
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
302
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
303
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
304
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
305
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
306
+					}
307
+				}
308
+				$reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
309
+				$reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
310
+				$reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
311
+				//get whether or not the user has checked in
312
+				$reg_csv_array[__("Check-Ins",
313
+					"event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
314
+				//get ticket of registration and its price
315
+				$ticket_model = \EE_Registry::instance()->load_model('Ticket');
316
+				if ($reg_row['Ticket.TKT_ID']) {
317
+					$ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
318
+						$reg_row['Ticket.TKT_name']);
319
+					$datetimes_strings = array();
320
+					foreach (
321
+						\EEM_Datetime::instance()->get_all_wpdb_results(array(
322
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
323
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
324
+							'default_where_conditions' => 'none',
325
+						)) as $datetime
326
+					) {
327
+						$datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
328
+							'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
329
+					}
330
+				} else {
331
+					$ticket_name = __('Unknown', 'event_espresso');
332
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
333
+				}
334
+				$reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
335
+				$reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
336
+				//get datetime(s) of registration
337
+				//add attendee columns
338
+				foreach ($att_fields_to_include as $att_field_name) {
339
+					$field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
340
+					if ($reg_row['Attendee_CPT.ID']) {
341
+						if ($att_field_name == 'STA_ID') {
342
+							$value = \EEM_State::instance()
343
+											   ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
344
+												   'STA_name');
345
+						} elseif ($att_field_name == 'CNT_ISO') {
346
+							$value = \EEM_Country::instance()
347
+												 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
348
+													 'CNT_name');
349
+						} else {
350
+							$value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
351
+								$att_field_name, $reg_row[$field_obj->get_qualified_column()]);
352
+						}
353
+					} else {
354
+						$value = '';
355
+					}
356
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
357
+				}
358
+				//make sure each registration has the same questions in the same order
359
+				foreach ($question_labels as $question_label) {
360
+					if ( ! isset($reg_csv_array[$question_label])) {
361
+						$reg_csv_array[$question_label] = null;
362
+					}
363
+				}
364
+				$answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
365
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
366
+					'force_join' => array('Question'),
367
+				));
368
+				//now fill out the questions THEY answered
369
+				foreach ($answers as $answer_row) {
370
+					if ($answer_row['Question.QST_ID']) {
371
+						$question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
372
+							'QST_admin_label', $answer_row['Question.QST_admin_label']);
373
+					} else {
374
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
375
+					}
376
+					if (isset($answer_row['Question.QST_type'])
377
+						&& $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
378
+					) {
379
+						$reg_csv_array[$question_label] = \EEM_State::instance()
380
+																	->get_state_name_by_ID($answer_row['Answer.ANS_value']);
381
+					} else {
382
+						//this isn't for html, so don't show html entities
383
+						$reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
384
+							'ANS_value', $answer_row['Answer.ANS_value']));
385
+					}
386
+				}
387
+				$registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array',
388
+					$reg_csv_array, $reg_row);
389
+			}
390
+		}
391
+		//if we couldn't export anything, we want to at least show the column headers
392
+		if (empty($registrations_csv_ready_array)) {
393
+			$reg_csv_array = array();
394
+			$model_and_fields_to_include = array(
395
+				'Registration' => $reg_fields_to_include,
396
+				'Attendee'     => $att_fields_to_include,
397
+			);
398
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
399
+				$model = \EE_Registry::instance()->load_model($model_name);
400
+				foreach ($field_list as $field_name) {
401
+					$field = $model->field_settings_for($field_name);
402
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
403
+				}
404
+			}
405
+			$registrations_csv_ready_array[] = $reg_csv_array;
406
+		}
407
+		return $registrations_csv_ready_array;
408
+	}
410 409
 
411 410
 
412 411
 
413
-    /**
414
-     * Counts total unit to process
415
-     *
416
-     * @deprecated since 4.9.19
417
-     * @param int|array $event_id
418
-     * @return int
419
-     */
420
-    public function count_units_to_process($event_id)
421
-    {
422
-        //use the legacy filter
423
-        if ($event_id) {
424
-            $query_params[0]['EVT_ID'] = $event_id;
425
-        } else {
426
-            $query_params['force_join'][] = 'Event';
427
-        }
428
-        return \EEM_Registration::instance()->count($query_params);
429
-    }
412
+	/**
413
+	 * Counts total unit to process
414
+	 *
415
+	 * @deprecated since 4.9.19
416
+	 * @param int|array $event_id
417
+	 * @return int
418
+	 */
419
+	public function count_units_to_process($event_id)
420
+	{
421
+		//use the legacy filter
422
+		if ($event_id) {
423
+			$query_params[0]['EVT_ID'] = $event_id;
424
+		} else {
425
+			$query_params['force_join'][] = 'Event';
426
+		}
427
+		return \EEM_Registration::instance()->count($query_params);
428
+	}
430 429
 
431 430
 
432 431
 
433
-    /**
434
-     * Performs any clean-up logic when we know the job is completed.
435
-     * In this case, we delete the temporary file
436
-     *
437
-     * @param JobParameters $job_parameters
438
-     * @return boolean
439
-     */
440
-    public function cleanup_job(JobParameters $job_parameters)
441
-    {
442
-        $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
443
-            true, 'd');
444
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
445
-    }
432
+	/**
433
+	 * Performs any clean-up logic when we know the job is completed.
434
+	 * In this case, we delete the temporary file
435
+	 *
436
+	 * @param JobParameters $job_parameters
437
+	 * @return boolean
438
+	 */
439
+	public function cleanup_job(JobParameters $job_parameters)
440
+	{
441
+		$this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
442
+			true, 'd');
443
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
444
+	}
446 445
 }
447 446
 
448 447
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 array_diff_key(
84 84
                     $query_params,
85 85
                     array_flip(
86
-                        array( 'limit' )
86
+                        array('limit')
87 87
                     )
88 88
                 )
89 89
             )
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
                 $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130 130
             );
131 131
         }
132
-        $question_query_params[0]['Answer.ANS_ID'] = array( 'IS_NOT_NULL' );
133
-        $question_query_params['group_by'] = array( 'QST_ID' );
134
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
132
+        $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
133
+        $question_query_params['group_by'] = array('QST_ID');
134
+        return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
135 135
     }
136 136
 
137 137
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                 $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
151 151
             } else {
152 152
                 //it's a normal where condition
153
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
153
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
154 154
             }
155 155
         }
156 156
         return $question_where_params;
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function continue_job(JobParameters $job_parameters, $batch_size = 50)
170 170
     {
171
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
171
+        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
172 172
             $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
173 173
                 $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
174 174
                 $job_parameters->extra_datum('query_params'));
175 175
             \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
176 176
             $units_processed = count($csv_data);
177
-        }else{
177
+        } else {
178 178
             $units_processed = 0;
179 179
         }
180 180
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@
 block discarded – undo
174 174
                 $job_parameters->extra_datum('query_params'));
175 175
             \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
176 176
             $units_processed = count($csv_data);
177
-        }else{
177
+        } else{
178 178
             $units_processed = 0;
179 179
         }
180 180
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 4 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -325,8 +325,8 @@
 block discarded – undo
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
327 327
 		$ds = strlen($file_or_folder_path) > 1
328
-            ? strrpos($file_or_folder_path, DS, -2)
329
-            : strlen($file_or_folder_path);
328
+			? strrpos($file_or_folder_path, DS, -2)
329
+			: strlen($file_or_folder_path);
330 330
 		return substr($file_or_folder_path, 0, $ds + 1);
331 331
 	}
332 332
 
Please login to merge, or discard this patch.
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @ version		 	4.0
13 13
  *
14 14
  */
15
-require_once( EE_HELPERS . 'EEH_Base.helper.php' );
16
-require_once( EE_INTERFACES . 'EEI_Interfaces.php' );
15
+require_once(EE_HELPERS.'EEH_Base.helper.php');
16
+require_once(EE_INTERFACES.'EEI_Interfaces.php');
17 17
 /**
18 18
  *
19 19
  * Class EEH_File
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 	 * @throws EE_Error if filesystem credentials are required
53 53
 	 * @return WP_Filesystem_Base
54 54
 	 */
55
-	private static function _get_wp_filesystem( $filepath = null) {
56
-		if( apply_filters(
55
+	private static function _get_wp_filesystem($filepath = null) {
56
+		if (apply_filters(
57 57
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
58
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ),
59
-				$filepath ) ) {
60
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
61
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
58
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
59
+				$filepath )) {
60
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
61
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
62 62
 				$method = 'direct';
63
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
63
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
64 64
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
65
-				if ( ! defined('FS_CHMOD_DIR') ) {
66
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
65
+				if ( ! defined('FS_CHMOD_DIR')) {
66
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
67 67
 				}
68
-				if ( ! defined('FS_CHMOD_FILE') ) {
69
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
68
+				if ( ! defined('FS_CHMOD_FILE')) {
69
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
70 70
 				}
71
-				require_once( $wp_filesystem_direct_file );
72
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
71
+				require_once($wp_filesystem_direct_file);
72
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
73 73
 			}
74 74
 			return EEH_File::$_wp_filesystem_direct;
75 75
 		}
76 76
 		global $wp_filesystem;
77 77
 		// no filesystem setup ???
78
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
78
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
79 79
 			// if some eager beaver's just trying to get in there too early...
80 80
 			// let them do it, because we are one of those eager beavers! :P
81 81
 			/**
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 			 * and there may be troubles if the WP files are owned by a different user
89 89
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
90 90
 			 */
91
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
91
+			if (FALSE && ! did_action('wp_loaded')) {
92 92
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
93
-				if ( WP_DEBUG ) {
94
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
93
+				if (WP_DEBUG) {
94
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
95 95
 				}
96
-				throw new EE_Error( $msg );
96
+				throw new EE_Error($msg);
97 97
 			} else {
98 98
 				// should be loaded if we are past the wp_loaded hook...
99
-				if ( ! function_exists( 'WP_Filesystem' )) {
100
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
101
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
99
+				if ( ! function_exists('WP_Filesystem')) {
100
+					require_once(ABSPATH.'wp-admin/includes/file.php');
101
+					require_once(ABSPATH.'wp-admin/includes/template.php');
102 102
 				}
103 103
 				// turn on output buffering so that we can capture the credentials form
104 104
 				ob_start();
105
-				$credentials = request_filesystem_credentials( '' );
105
+				$credentials = request_filesystem_credentials('');
106 106
 				// store credentials form for the time being
107 107
 				EEH_File::$_credentials_form = ob_get_clean();
108 108
 				// basically check for direct or previously configured access
109
-				if ( ! WP_Filesystem( $credentials ) ) {
109
+				if ( ! WP_Filesystem($credentials)) {
110 110
 					// if credentials do NOT exist
111
-					if ( $credentials === FALSE ) {
112
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
113
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
115
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
111
+					if ($credentials === FALSE) {
112
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
113
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
115
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
116 116
 						throw new EE_Error(
117 117
 								sprintf(
118
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
118
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
119 119
 										$wp_filesystem->errors->get_error_message() ) );
120 120
 					}
121 121
 				}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * display_request_filesystem_credentials_form
129 129
 	 */
130 130
 	public static function display_request_filesystem_credentials_form() {
131
-		if ( ! empty( EEH_File::$_credentials_form )) {
132
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
131
+		if ( ! empty(EEH_File::$_credentials_form)) {
132
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
133 133
 		}
134 134
 	}
135 135
 
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
 	 * @throws EE_Error if filesystem credentials are required
148 148
 	 * @return bool
149 149
 	 */
150
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
150
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
151 151
 		// load WP_Filesystem and set file permissions
152
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
153
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
154
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
155
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
156
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
152
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
153
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
154
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
155
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
156
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
157 157
 			$msg = sprintf(
158
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
158
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
159 159
 				$file_name,
160 160
 				'<br />'
161 161
 			);
162
-			if ( EEH_File::exists( $full_file_path )) {
163
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
162
+			if (EEH_File::exists($full_file_path)) {
163
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
164 164
 			} else {
165 165
 				// no file permissions means the file was not found
166 166
 				$msg .= sprintf(
167
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
167
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
168 168
 					$full_file_path
169 169
 				);
170 170
 			}
171
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
172
-				throw new EE_Error( $msg . '||' . $msg );
171
+			if (defined('WP_DEBUG') && WP_DEBUG) {
172
+				throw new EE_Error($msg.'||'.$msg);
173 173
 			}
174 174
 			return FALSE;
175 175
 		}
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 * @throws EE_Error if filesystem credentials are required
188 188
 	 * @return string
189 189
 	 */
190
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
190
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
191 191
 		// load WP_Filesystem and set file permissions
192
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
192
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
193 193
 		// check file permissions
194
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
195
-		if ( $perms ) {
194
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
195
+		if ($perms) {
196 196
 			// file permissions exist, but way be set incorrectly
197
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
198
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
197
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
198
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
199 199
 			return sprintf(
200
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
200
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
201 201
 				$type_of_file,
202 202
 				$perms
203 203
 			);
204 204
 		} else {
205 205
 			// file exists but file permissions could not be read ?!?!
206 206
 			return sprintf(
207
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
207
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
208 208
 				$full_file_path
209 209
 			);
210 210
 		}
@@ -222,35 +222,35 @@  discard block
 block discarded – undo
222 222
 	 * can't write to it
223 223
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
224 224
 	 */
225
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
226
-		if ( empty( $folder )) {
225
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
226
+		if (empty($folder)) {
227 227
 			return false;
228 228
 		}
229 229
 		// remove ending DS
230
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
231
-		$parent_folder = EEH_File::get_parent_folder( $folder );
230
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
231
+		$parent_folder = EEH_File::get_parent_folder($folder);
232 232
 		// add DS to folder
233
-		$folder = EEH_File::end_with_directory_separator( $folder );
234
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
235
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
233
+		$folder = EEH_File::end_with_directory_separator($folder);
234
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
235
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
236 236
 			//ok so it doesn't exist. Does its parent? Can we write to it?
237
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
237
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
238 238
 				return false;
239 239
 			}
240
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
240
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
241 241
 				return false;
242 242
 			} else {
243
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
244
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
245
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
246
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
247
-						throw new EE_Error( $msg );
243
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
244
+					if (defined('WP_DEBUG') && WP_DEBUG) {
245
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
246
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
247
+						throw new EE_Error($msg);
248 248
 					}
249 249
 					return false;
250 250
 				}
251
-				EEH_File::add_index_file( $folder );
251
+				EEH_File::add_index_file($folder);
252 252
 			}
253
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
253
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
254 254
 			return false;
255 255
 		}
256 256
 		return true;
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
 	 * @throws EE_Error if filesystem credentials are required
266 266
 	 * @return bool
267 267
 	 */
268
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
268
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
269 269
 		// load WP_Filesystem and set file permissions
270
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
271
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
272
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
273
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
274
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
275
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
276
-				throw new EE_Error( $msg );
270
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
271
+		$full_path = EEH_File::standardise_directory_separators($full_path);
272
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
273
+			if (defined('WP_DEBUG') && WP_DEBUG) {
274
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
275
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
276
+				throw new EE_Error($msg);
277 277
 			}
278 278
 			return FALSE;
279 279
 		}
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 * @throws EE_Error if filesystem credentials are required
291 291
 	 * @return bool
292 292
 	 */
293
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
293
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
294 294
 		// load WP_Filesystem and set file permissions
295
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
296
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
297
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
298
-		if ( ! EEH_File::exists( $full_file_path )) {
299
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
295
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
296
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
297
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
298
+		if ( ! EEH_File::exists($full_file_path)) {
299
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
300 300
 				return false;
301 301
 			}
302
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
303
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
304
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
305
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
306
-					throw new EE_Error( $msg );
302
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
303
+				if (defined('WP_DEBUG') && WP_DEBUG) {
304
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
305
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
306
+					throw new EE_Error($msg);
307 307
 				}
308 308
 				return false;
309 309
 			}
310 310
 		}
311
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
311
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
312 312
 			return false;
313 313
 		}
314 314
 		return true;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * @param string $file_or_folder_path
321 321
 	 * @return string parent folder, ENDING with a directory separator
322 322
 	 */
323
-	public static function get_parent_folder( $file_or_folder_path ) {
323
+	public static function get_parent_folder($file_or_folder_path) {
324 324
 		//find the last DS, ignoring a DS on the very end
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 	 * @throws EE_Error if filesystem credentials are required
343 343
 	 * @return string
344 344
 	 */
345
-	public static function get_file_contents( $full_file_path = '' ){
346
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
347
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
345
+	public static function get_file_contents($full_file_path = '') {
346
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
347
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
348 348
 			// load WP_Filesystem and set file permissions
349
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
350
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
349
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
350
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
351 351
 		}
352 352
 		return '';
353 353
 	}
@@ -362,26 +362,26 @@  discard block
 block discarded – undo
362 362
 	 * @throws EE_Error if filesystem credentials are required
363 363
 	 * @return bool
364 364
 	 */
365
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
366
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
367
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
368
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
369
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
370
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
371
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
372
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
373
-				throw new EE_Error( $msg );
365
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
366
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
367
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
368
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
369
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
370
+			if (defined('WP_DEBUG') && WP_DEBUG) {
371
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
372
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
373
+				throw new EE_Error($msg);
374 374
 			}
375 375
 			return FALSE;
376 376
 		}
377 377
 		// load WP_Filesystem and set file permissions
378
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
378
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
379 379
 		// write the file
380
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
381
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
382
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
383
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
384
-				throw new EE_Error( $msg );
380
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
381
+			if (defined('WP_DEBUG') && WP_DEBUG) {
382
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
383
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
384
+				throw new EE_Error($msg);
385 385
 			}
386 386
 			return FALSE;
387 387
 		}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 * @throws EE_Error if filesystem credentials are required
398 398
 	 * @return boolean
399 399
 	 */
400
-	public static function delete( $filepath, $recursive = false, $type = false ) {
400
+	public static function delete($filepath, $recursive = false, $type = false) {
401 401
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
402
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
402
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
403 403
 	}
404 404
 
405 405
 
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
 	 * @throws EE_Error if filesystem credentials are required
412 412
 	 * @return bool
413 413
 	 */
414
-	public static function exists( $full_file_path = '' ) {
415
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
416
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
414
+	public static function exists($full_file_path = '') {
415
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
416
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
417 417
 	}
418 418
 
419 419
 
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 	 * @throws EE_Error if filesystem credentials are required
427 427
 	 * @return bool
428 428
 	 */
429
-	public static function is_readable( $full_file_path = '' ) {
430
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
431
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
429
+	public static function is_readable($full_file_path = '') {
430
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
431
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
432 432
 			return true;
433 433
 		} else {
434 434
 			return false;
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 * @param string $full_file_path
445 445
 	 * @return string
446 446
 	 */
447
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
448
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
447
+	public static function remove_filename_from_filepath($full_file_path = '') {
448
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
449 449
 	}
450 450
 
451 451
 
@@ -455,8 +455,8 @@  discard block
 block discarded – undo
455 455
 	 * @param string $full_file_path
456 456
 	 * @return string
457 457
 	 */
458
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
459
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
458
+	public static function get_filename_from_filepath($full_file_path = '') {
459
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
460 460
 	}
461 461
 
462 462
 
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
 	 * @param string $full_file_path
467 467
 	 * @return string
468 468
 	 */
469
-	public static function get_file_extension( $full_file_path = '' ) {
470
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
469
+	public static function get_file_extension($full_file_path = '') {
470
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
471 471
 	}
472 472
 
473 473
 
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 	 * @throws EE_Error if filesystem credentials are required
479 479
 	 * @return bool
480 480
 	 */
481
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
482
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
483
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
484
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
481
+	public static function add_htaccess_deny_from_all($folder = '') {
482
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
483
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
484
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
485 485
 				return FALSE;
486 486
 			}
487 487
 		}
@@ -495,10 +495,10 @@  discard block
 block discarded – undo
495 495
 	 * @throws EE_Error if filesystem credentials are required
496 496
 	 * @return boolean
497 497
 	 */
498
-	public static function add_index_file( $folder ) {
499
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
500
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
501
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
498
+	public static function add_index_file($folder) {
499
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
500
+		if ( ! EEH_File::exists($folder.'index.php')) {
501
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
502 502
 				return false;
503 503
 			}
504 504
 		}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 	 * @param string $file_path
514 514
 	 * @return string
515 515
 	 */
516
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
516
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
517 517
 		//extract file from path
518
-		$filename = basename( $file_path );
518
+		$filename = basename($file_path);
519 519
 		//now remove the first period and everything after
520
-		$pos_of_first_period = strpos( $filename,'.' );
520
+		$pos_of_first_period = strpos($filename, '.');
521 521
 		return substr($filename, 0, $pos_of_first_period);
522 522
 	}
523 523
 
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @param string $file_path
530 530
 	 * @return string
531 531
 	 */
532
-	public static function standardise_directory_separators( $file_path ){
533
-		return str_replace( array( '\\', '/' ), DS, $file_path );
532
+	public static function standardise_directory_separators($file_path) {
533
+		return str_replace(array('\\', '/'), DS, $file_path);
534 534
 	}
535 535
 
536 536
 
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 	 * @param string $file_path
542 542
 	 * @return string
543 543
 	 */
544
-	public static function end_with_directory_separator( $file_path ){
545
-		return rtrim( $file_path, '/\\' ) . DS;
544
+	public static function end_with_directory_separator($file_path) {
545
+		return rtrim($file_path, '/\\').DS;
546 546
 	}
547 547
 
548 548
 
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
 	 * @param $file_path
553 553
 	 * @return string
554 554
 	 */
555
-	public static function standardise_and_end_with_directory_separator( $file_path ){
556
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
555
+	public static function standardise_and_end_with_directory_separator($file_path) {
556
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
557 557
 	}
558 558
 
559 559
 
@@ -570,21 +570,21 @@  discard block
 block discarded – undo
570 570
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
571 571
 	 *		 and values are their filepaths
572 572
 	 */
573
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
573
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
574 574
 		$class_to_folder_path = array();
575
-		foreach( $folder_paths as $folder_path ){
576
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
575
+		foreach ($folder_paths as $folder_path) {
576
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
577 577
 			// load WP_Filesystem and set file permissions
578
-			$files_in_folder = glob( $folder_path . '*' );
578
+			$files_in_folder = glob($folder_path.'*');
579 579
 			$class_to_folder_path = array();
580
-			if ( $files_in_folder ) {
581
-				foreach( $files_in_folder as $file_path ){
580
+			if ($files_in_folder) {
581
+				foreach ($files_in_folder as $file_path) {
582 582
 					//only add files, not folders
583
-					if ( ! is_dir( $file_path )) {
584
-						if ( $index_numerically ) {
583
+					if ( ! is_dir($file_path)) {
584
+						if ($index_numerically) {
585 585
 							$class_to_folder_path[] = $file_path;
586 586
 						} else {
587
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
587
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
588 588
 							$class_to_folder_path[$classname] = $file_path;
589 589
 						}
590 590
 					}
@@ -604,39 +604,39 @@  discard block
 block discarded – undo
604 604
 	 * @throws EE_Error if filesystem credentials are required
605 605
 	 * @return boolean success
606 606
 	 */
607
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
608
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
609
-		if( ! EEH_File::exists( $full_source_path ) ){
610
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
611
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
612
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
613
-				throw new EE_Error( $msg );
607
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
608
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
609
+		if ( ! EEH_File::exists($full_source_path)) {
610
+			if (defined('WP_DEBUG') && WP_DEBUG) {
611
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
612
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
613
+				throw new EE_Error($msg);
614 614
 			}
615 615
 			return FALSE;
616 616
 		}
617 617
 
618
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
619
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
620
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
621
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
622
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
623
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
624
-				throw new EE_Error( $msg );
618
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
619
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
620
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
621
+			if (defined('WP_DEBUG') && WP_DEBUG) {
622
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
623
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
624
+				throw new EE_Error($msg);
625 625
 			}
626 626
 			return FALSE;
627 627
 		}
628 628
 
629 629
 		// load WP_Filesystem and set file permissions
630
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
630
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
631 631
 		// write the file
632 632
 		if ( ! $wp_filesystem->copy(
633
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ),
634
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ),
633
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
634
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
635 635
 						$overwrite )) {
636
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
637
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
638
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
639
-				throw new EE_Error( $msg );
636
+			if (defined('WP_DEBUG') && WP_DEBUG) {
637
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
638
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
639
+				throw new EE_Error($msg);
640 640
 			}
641 641
 			return FALSE;
642 642
 		}
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
 	 * @param string $filepath
649 649
 	 * @return boolean
650 650
 	 */
651
-	public static function is_in_uploads_folder( $filepath ) {
651
+	public static function is_in_uploads_folder($filepath) {
652 652
 		$uploads = wp_upload_dir();
653
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
653
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
654 654
 	}
655 655
 
656 656
 	/**
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
666 666
 	 * ftp or ssh, will use to access the folder
667 667
 	 */
668
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
669
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
670
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
668
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
669
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
670
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
671 671
 	}
672 672
 }
673 673
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -658,8 +658,6 @@
 block discarded – undo
658 658
 	 * converts it into a "remote" filepath (the filepath the currently-in-use
659 659
 	 * $wp_filesystem needs to use access the folder or file).
660 660
 	 * See http://wordpress.stackexchange.com/questions/124900/using-wp-filesystem-in-plugins
661
-	 * @param WP_Filesystem_Base $wp_filesystem we aren't initially sure which one
662
-	 * is in use, so you need to provide it
663 661
 	 * @param string $local_filepath the filepath to the folder/file locally
664 662
 	 * @throws EE_Error if filesystem credentials are required
665 663
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
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/libraries/rest_api/Model_Data_Translator.php 2 patches
Indentation   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\rest_api;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -26,485 +26,485 @@  discard block
 block discarded – undo
26 26
 class Model_Data_Translator
27 27
 {
28 28
 
29
-    /**
30
-     * We used to use -1 for infinity in the rest api, but that's ambiguous for
31
-     * fields that COULD contain -1; so we use null
32
-     */
33
-    const ee_inf_in_rest = null;
34
-
35
-
36
-
37
-    /**
38
-     * Prepares a possible array of input values from JSON for use by the models
39
-     *
40
-     * @param \EE_Model_Field_Base $field_obj
41
-     * @param mixed                $original_value_maybe_array
42
-     * @param string               $requested_version
43
-     * @param string               $timezone_string treat values as being in this timezone
44
-     * @return mixed
45
-     * @throws \DomainException
46
-     */
47
-    public static function prepare_field_values_from_json(
48
-        $field_obj,
49
-        $original_value_maybe_array,
50
-        $requested_version,
51
-        $timezone_string = 'UTC'
52
-    ) {
53
-        if (is_array($original_value_maybe_array)) {
54
-            $new_value_maybe_array = array();
55
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
56
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
57
-                    $field_obj,
58
-                    $array_item,
59
-                    $requested_version,
60
-                    $timezone_string
61
-                );
62
-            }
63
-        } else {
64
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
65
-                $field_obj,
66
-                $original_value_maybe_array,
67
-                $requested_version,
68
-                $timezone_string
69
-            );
70
-        }
71
-        return $new_value_maybe_array;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Prepares an array of field values FOR use in JSON/REST API
78
-     *
79
-     * @param \EE_Model_Field_Base $field_obj
80
-     * @param mixed                $original_value_maybe_array
81
-     * @param string               $request_version (eg 4.8.36)
82
-     * @return array
83
-     */
84
-    public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
85
-    {
86
-        if (is_array($original_value_maybe_array)) {
87
-            $new_value_maybe_array = array();
88
-            foreach ($original_value_maybe_array as $array_key => $array_item) {
89
-                $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
90
-                    $field_obj,
91
-                    $array_item,
92
-                    $request_version
93
-                );
94
-            }
95
-        } else {
96
-            $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
97
-                $field_obj,
98
-                $original_value_maybe_array,
99
-                $request_version
100
-            );
101
-        }
102
-        return $new_value_maybe_array;
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * Prepares incoming data from the json or $_REQUEST parameters for the models'
109
-     * "$query_params".
110
-     *
111
-     * @param \EE_Model_Field_Base $field_obj
112
-     * @param mixed                $original_value
113
-     * @param string               $requested_version
114
-     * @param string               $timezone_string treat values as being in this timezone
115
-     * @return mixed
116
-     * @throws \DomainException
117
-     */
118
-    public static function prepare_field_value_from_json(
119
-        $field_obj,
120
-        $original_value,
121
-        $requested_version,
122
-        $timezone_string = 'UTC' // UTC
123
-    )
124
-    {
125
-        $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
126
-        $new_value = null;
127
-        if ($field_obj instanceof \EE_Infinite_Integer_Field
128
-            && in_array($original_value, array(null, ''), true)
129
-        ) {
130
-            $new_value = EE_INF;
131
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
132
-            list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
133
-                $field_obj->get_timezone_offset(
134
-                    new \DateTimeZone($timezone_string)
135
-                )
136
-            );
137
-            $offset_string =
138
-                str_pad(
139
-                    floor($offset_secs / HOUR_IN_SECONDS),
140
-                    2,
141
-                    '0',
142
-                    STR_PAD_LEFT
143
-                )
144
-                . ':'
145
-                . str_pad(
146
-                    ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
147
-                    2,
148
-                    '0',
149
-                    STR_PAD_LEFT
150
-                );
151
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
152
-        } else {
153
-            $new_value = $original_value;
154
-        }
155
-        return $new_value;
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * determines what's going on with them timezone strings
162
-     *
163
-     * @param int $timezone_offset
164
-     * @return array
165
-     */
166
-    private static function parse_timezone_offset($timezone_offset)
167
-    {
168
-        $first_char = substr((string)$timezone_offset, 0, 1);
169
-        if ($first_char === '+' || $first_char === '-') {
170
-            $offset_sign = $first_char;
171
-            $offset_secs = substr((string)$timezone_offset, 1);
172
-        } else {
173
-            $offset_sign = '+';
174
-            $offset_secs = $timezone_offset;
175
-        }
176
-        return array($offset_sign, $offset_secs);
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * Prepares a field's value for display in the API
183
-     *
184
-     * @param \EE_Model_Field_Base $field_obj
185
-     * @param mixed                $original_value
186
-     * @param string               $requested_version
187
-     * @return mixed
188
-     */
189
-    public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
190
-    {
191
-        if ($original_value === EE_INF) {
192
-            $new_value = Model_Data_Translator::ee_inf_in_rest;
193
-        } elseif ($field_obj instanceof \EE_Datetime_Field) {
194
-            if ($original_value instanceof \DateTime) {
195
-                $new_value = $original_value->format('Y-m-d H:i:s');
196
-            } elseif (is_int($original_value)) {
197
-                $new_value = date('Y-m-d H:i:s', $original_value);
198
-            } else {
199
-                $new_value = $original_value;
200
-            }
201
-            $new_value = mysql_to_rfc3339($new_value);
202
-        } else {
203
-            $new_value = $original_value;
204
-        }
205
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
206
-            $new_value,
207
-            $field_obj,
208
-            $original_value,
209
-            $requested_version
210
-        );
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * Prepares condition-query-parameters (like what's in where and having) from
217
-     * the format expected in the API to use in the models
218
-     *
219
-     * @param array     $inputted_query_params_of_this_type
220
-     * @param \EEM_Base $model
221
-     * @param string    $requested_version
222
-     * @return array
223
-     * @throws \DomainException
224
-     * @throws \EE_Error
225
-     */
226
-    public static function prepare_conditions_query_params_for_models(
227
-        $inputted_query_params_of_this_type,
228
-        \EEM_Base $model,
229
-        $requested_version
230
-    ) {
231
-        $query_param_for_models = array();
232
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
233
-            $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
234
-            $field = Model_Data_Translator::deduce_field_from_query_param(
235
-                $query_param_sans_stars,
236
-                $model
237
-            );
238
-            //double-check is it a *_gmt field?
239
-            if ( ! $field instanceof \EE_Model_Field_Base
240
-                 && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
241
-            ) {
242
-                //yep, take off '_gmt', and find the field
243
-                $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
244
-                $field = Model_Data_Translator::deduce_field_from_query_param(
245
-                    $query_param_key,
246
-                    $model
247
-                );
248
-                $timezone = 'UTC';
249
-            } else {
250
-                //so it's not a GMT field. Set the timezone on the model to the default
251
-                $timezone = \EEH_DTT_Helper::get_valid_timezone_string();
252
-            }
253
-            if ($field instanceof \EE_Model_Field_Base) {
254
-                //did they specify an operator?
255
-                if (is_array($query_param_value)) {
256
-                    $op = $query_param_value[0];
257
-                    $translated_value = array($op);
258
-                    if (isset($query_param_value[1])) {
259
-                        $value = $query_param_value[1];
260
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
261
-                            $requested_version, $timezone);
262
-                    }
263
-                } else {
264
-                    $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
265
-                        $requested_version, $timezone);
266
-                }
267
-                $query_param_for_models[$query_param_key] = $translated_value;
268
-            } else {
269
-                //so it's not for a field, assume it's a logic query param key
270
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
271
-                    $model, $requested_version);
272
-            }
273
-        }
274
-        return $query_param_for_models;
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * Mostly checks if the last 4 characters are "_gmt", indicating its a
281
-     * gmt date field name
282
-     *
283
-     * @param string $field_name
284
-     * @return boolean
285
-     */
286
-    public static function is_gmt_date_field_name($field_name)
287
-    {
288
-        return substr(
289
-                   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
290
-                   -4,
291
-                   4
292
-               ) === '_gmt';
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
299
-     *
300
-     * @param string $field_name
301
-     * @return string
302
-     */
303
-    public static function remove_gmt_from_field_name($field_name)
304
-    {
305
-        if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
306
-            return $field_name;
307
-        }
308
-        $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
309
-        $query_param_sans_gmt_and_sans_stars = substr(
310
-            $query_param_sans_stars,
311
-            0,
312
-            strrpos(
313
-                $field_name,
314
-                '_gmt'
315
-            )
316
-        );
317
-        return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * Takes a field name from the REST API and prepares it for the model querying
324
-     *
325
-     * @param string $field_name
326
-     * @return string
327
-     */
328
-    public static function prepare_field_name_from_json($field_name)
329
-    {
330
-        if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
331
-            return Model_Data_Translator::remove_gmt_from_field_name($field_name);
332
-        }
333
-        return $field_name;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * Takes array of field names from REST API and prepares for models
340
-     *
341
-     * @param array $field_names
342
-     * @return array of field names (possibly include model prefixes)
343
-     */
344
-    public static function prepare_field_names_from_json(array $field_names)
345
-    {
346
-        $new_array = array();
347
-        foreach ($field_names as $key => $field_name) {
348
-            $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
349
-        }
350
-        return $new_array;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * Takes array where array keys are field names (possibly with model path prefixes)
357
-     * from the REST API and prepares them for model querying
358
-     *
359
-     * @param array $field_names_as_keys
360
-     * @return array
361
-     */
362
-    public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
363
-    {
364
-        $new_array = array();
365
-        foreach ($field_names_as_keys as $field_name => $value) {
366
-            $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
367
-        }
368
-        return $new_array;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Prepares an array of model query params for use in the REST API
375
-     *
376
-     * @param array     $model_query_params
377
-     * @param \EEM_Base $model
378
-     * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
379
-     *                                     REST API
380
-     * @return array which can be passed into the EE4 REST API when querying a model resource
381
-     * @throws \EE_Error
382
-     */
383
-    public static function prepare_query_params_for_rest_api(
384
-        array $model_query_params,
385
-        \EEM_Base $model,
386
-        $requested_version = null
387
-    ) {
388
-        if ($requested_version === null) {
389
-            $requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
390
-        }
391
-        $rest_query_params = $model_query_params;
392
-        if (isset($model_query_params[0])) {
393
-            $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
394
-                $model_query_params[0],
395
-                $model,
396
-                $requested_version
397
-            );
398
-            unset($rest_query_params[0]);
399
-        }
400
-        if (isset($model_query_params['having'])) {
401
-            $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
402
-                $model_query_params['having'],
403
-                $model,
404
-                $requested_version
405
-            );
406
-        }
407
-        return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
408
-            $rest_query_params, $model_query_params, $model, $requested_version);
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
415
-     *
416
-     * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
417
-     *                                                      passed into EEM_Base::get_all()
418
-     * @param \EEM_Base $model
419
-     * @param string    $requested_version                  eg "4.8.36"
420
-     * @return array ready for use in the rest api query params
421
-     * @throws \EE_Error
422
-     */
423
-    public static function prepare_conditions_query_params_for_rest_api(
424
-        $inputted_query_params_of_this_type,
425
-        \EEM_Base $model,
426
-        $requested_version
427
-    ) {
428
-        $query_param_for_models = array();
429
-        foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
430
-            $field = Model_Data_Translator::deduce_field_from_query_param(
431
-                Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
432
-                $model
433
-            );
434
-            if ($field instanceof \EE_Model_Field_Base) {
435
-                //did they specify an operator?
436
-                if (is_array($query_param_value)) {
437
-                    $op = $query_param_value[0];
438
-                    $translated_value = array($op);
439
-                    if (isset($query_param_value[1])) {
440
-                        $value = $query_param_value[1];
441
-                        $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
442
-                            $requested_version);
443
-                    }
444
-                } else {
445
-                    $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
446
-                        $requested_version);
447
-                }
448
-                $query_param_for_models[$query_param_key] = $translated_value;
449
-            } else {
450
-                //so it's not for a field, assume it's a logic query param key
451
-                $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
452
-                    $model, $requested_version);
453
-            }
454
-        }
455
-        return $query_param_for_models;
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * @param $condition_query_param_key
462
-     * @return string
463
-     */
464
-    public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
465
-    {
466
-        $pos_of_star = strpos($condition_query_param_key, '*');
467
-        if ($pos_of_star === false) {
468
-            return $condition_query_param_key;
469
-        } else {
470
-            $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
471
-            return $condition_query_param_sans_star;
472
-        }
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * Takes the input parameter and finds the model field that it indicates.
479
-     *
480
-     * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
481
-     * @param \EEM_Base $model
482
-     * @return \EE_Model_Field_Base
483
-     * @throws \EE_Error
484
-     */
485
-    public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
486
-    {
487
-        //ok, now proceed with deducing which part is the model's name, and which is the field's name
488
-        //which will help us find the database table and column
489
-        $query_param_parts = explode('.', $query_param_name);
490
-        if (empty($query_param_parts)) {
491
-            throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
492
-                'event_espresso'), $query_param_name));
493
-        }
494
-        $number_of_parts = count($query_param_parts);
495
-        $last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
496
-        if ($number_of_parts === 1) {
497
-            $field_name = $last_query_param_part;
498
-        } else {// $number_of_parts >= 2
499
-            //the last part is the column name, and there are only 2parts. therefore...
500
-            $field_name = $last_query_param_part;
501
-            $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
502
-        }
503
-        try {
504
-            return $model->field_settings_for($field_name);
505
-        } catch (\EE_Error $e) {
506
-            return null;
507
-        }
508
-    }
29
+	/**
30
+	 * We used to use -1 for infinity in the rest api, but that's ambiguous for
31
+	 * fields that COULD contain -1; so we use null
32
+	 */
33
+	const ee_inf_in_rest = null;
34
+
35
+
36
+
37
+	/**
38
+	 * Prepares a possible array of input values from JSON for use by the models
39
+	 *
40
+	 * @param \EE_Model_Field_Base $field_obj
41
+	 * @param mixed                $original_value_maybe_array
42
+	 * @param string               $requested_version
43
+	 * @param string               $timezone_string treat values as being in this timezone
44
+	 * @return mixed
45
+	 * @throws \DomainException
46
+	 */
47
+	public static function prepare_field_values_from_json(
48
+		$field_obj,
49
+		$original_value_maybe_array,
50
+		$requested_version,
51
+		$timezone_string = 'UTC'
52
+	) {
53
+		if (is_array($original_value_maybe_array)) {
54
+			$new_value_maybe_array = array();
55
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
56
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json(
57
+					$field_obj,
58
+					$array_item,
59
+					$requested_version,
60
+					$timezone_string
61
+				);
62
+			}
63
+		} else {
64
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json(
65
+				$field_obj,
66
+				$original_value_maybe_array,
67
+				$requested_version,
68
+				$timezone_string
69
+			);
70
+		}
71
+		return $new_value_maybe_array;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Prepares an array of field values FOR use in JSON/REST API
78
+	 *
79
+	 * @param \EE_Model_Field_Base $field_obj
80
+	 * @param mixed                $original_value_maybe_array
81
+	 * @param string               $request_version (eg 4.8.36)
82
+	 * @return array
83
+	 */
84
+	public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version)
85
+	{
86
+		if (is_array($original_value_maybe_array)) {
87
+			$new_value_maybe_array = array();
88
+			foreach ($original_value_maybe_array as $array_key => $array_item) {
89
+				$new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json(
90
+					$field_obj,
91
+					$array_item,
92
+					$request_version
93
+				);
94
+			}
95
+		} else {
96
+			$new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json(
97
+				$field_obj,
98
+				$original_value_maybe_array,
99
+				$request_version
100
+			);
101
+		}
102
+		return $new_value_maybe_array;
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * Prepares incoming data from the json or $_REQUEST parameters for the models'
109
+	 * "$query_params".
110
+	 *
111
+	 * @param \EE_Model_Field_Base $field_obj
112
+	 * @param mixed                $original_value
113
+	 * @param string               $requested_version
114
+	 * @param string               $timezone_string treat values as being in this timezone
115
+	 * @return mixed
116
+	 * @throws \DomainException
117
+	 */
118
+	public static function prepare_field_value_from_json(
119
+		$field_obj,
120
+		$original_value,
121
+		$requested_version,
122
+		$timezone_string = 'UTC' // UTC
123
+	)
124
+	{
125
+		$timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', '');
126
+		$new_value = null;
127
+		if ($field_obj instanceof \EE_Infinite_Integer_Field
128
+			&& in_array($original_value, array(null, ''), true)
129
+		) {
130
+			$new_value = EE_INF;
131
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
132
+			list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset(
133
+				$field_obj->get_timezone_offset(
134
+					new \DateTimeZone($timezone_string)
135
+				)
136
+			);
137
+			$offset_string =
138
+				str_pad(
139
+					floor($offset_secs / HOUR_IN_SECONDS),
140
+					2,
141
+					'0',
142
+					STR_PAD_LEFT
143
+				)
144
+				. ':'
145
+				. str_pad(
146
+					($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS,
147
+					2,
148
+					'0',
149
+					STR_PAD_LEFT
150
+				);
151
+			$new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
152
+		} else {
153
+			$new_value = $original_value;
154
+		}
155
+		return $new_value;
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * determines what's going on with them timezone strings
162
+	 *
163
+	 * @param int $timezone_offset
164
+	 * @return array
165
+	 */
166
+	private static function parse_timezone_offset($timezone_offset)
167
+	{
168
+		$first_char = substr((string)$timezone_offset, 0, 1);
169
+		if ($first_char === '+' || $first_char === '-') {
170
+			$offset_sign = $first_char;
171
+			$offset_secs = substr((string)$timezone_offset, 1);
172
+		} else {
173
+			$offset_sign = '+';
174
+			$offset_secs = $timezone_offset;
175
+		}
176
+		return array($offset_sign, $offset_secs);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * Prepares a field's value for display in the API
183
+	 *
184
+	 * @param \EE_Model_Field_Base $field_obj
185
+	 * @param mixed                $original_value
186
+	 * @param string               $requested_version
187
+	 * @return mixed
188
+	 */
189
+	public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version)
190
+	{
191
+		if ($original_value === EE_INF) {
192
+			$new_value = Model_Data_Translator::ee_inf_in_rest;
193
+		} elseif ($field_obj instanceof \EE_Datetime_Field) {
194
+			if ($original_value instanceof \DateTime) {
195
+				$new_value = $original_value->format('Y-m-d H:i:s');
196
+			} elseif (is_int($original_value)) {
197
+				$new_value = date('Y-m-d H:i:s', $original_value);
198
+			} else {
199
+				$new_value = $original_value;
200
+			}
201
+			$new_value = mysql_to_rfc3339($new_value);
202
+		} else {
203
+			$new_value = $original_value;
204
+		}
205
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
206
+			$new_value,
207
+			$field_obj,
208
+			$original_value,
209
+			$requested_version
210
+		);
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * Prepares condition-query-parameters (like what's in where and having) from
217
+	 * the format expected in the API to use in the models
218
+	 *
219
+	 * @param array     $inputted_query_params_of_this_type
220
+	 * @param \EEM_Base $model
221
+	 * @param string    $requested_version
222
+	 * @return array
223
+	 * @throws \DomainException
224
+	 * @throws \EE_Error
225
+	 */
226
+	public static function prepare_conditions_query_params_for_models(
227
+		$inputted_query_params_of_this_type,
228
+		\EEM_Base $model,
229
+		$requested_version
230
+	) {
231
+		$query_param_for_models = array();
232
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
233
+			$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key);
234
+			$field = Model_Data_Translator::deduce_field_from_query_param(
235
+				$query_param_sans_stars,
236
+				$model
237
+			);
238
+			//double-check is it a *_gmt field?
239
+			if ( ! $field instanceof \EE_Model_Field_Base
240
+				 && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars)
241
+			) {
242
+				//yep, take off '_gmt', and find the field
243
+				$query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars);
244
+				$field = Model_Data_Translator::deduce_field_from_query_param(
245
+					$query_param_key,
246
+					$model
247
+				);
248
+				$timezone = 'UTC';
249
+			} else {
250
+				//so it's not a GMT field. Set the timezone on the model to the default
251
+				$timezone = \EEH_DTT_Helper::get_valid_timezone_string();
252
+			}
253
+			if ($field instanceof \EE_Model_Field_Base) {
254
+				//did they specify an operator?
255
+				if (is_array($query_param_value)) {
256
+					$op = $query_param_value[0];
257
+					$translated_value = array($op);
258
+					if (isset($query_param_value[1])) {
259
+						$value = $query_param_value[1];
260
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value,
261
+							$requested_version, $timezone);
262
+					}
263
+				} else {
264
+					$translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value,
265
+						$requested_version, $timezone);
266
+				}
267
+				$query_param_for_models[$query_param_key] = $translated_value;
268
+			} else {
269
+				//so it's not for a field, assume it's a logic query param key
270
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value,
271
+					$model, $requested_version);
272
+			}
273
+		}
274
+		return $query_param_for_models;
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * Mostly checks if the last 4 characters are "_gmt", indicating its a
281
+	 * gmt date field name
282
+	 *
283
+	 * @param string $field_name
284
+	 * @return boolean
285
+	 */
286
+	public static function is_gmt_date_field_name($field_name)
287
+	{
288
+		return substr(
289
+				   Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name),
290
+				   -4,
291
+				   4
292
+			   ) === '_gmt';
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone)
299
+	 *
300
+	 * @param string $field_name
301
+	 * @return string
302
+	 */
303
+	public static function remove_gmt_from_field_name($field_name)
304
+	{
305
+		if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) {
306
+			return $field_name;
307
+		}
308
+		$query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name);
309
+		$query_param_sans_gmt_and_sans_stars = substr(
310
+			$query_param_sans_stars,
311
+			0,
312
+			strrpos(
313
+				$field_name,
314
+				'_gmt'
315
+			)
316
+		);
317
+		return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name);
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * Takes a field name from the REST API and prepares it for the model querying
324
+	 *
325
+	 * @param string $field_name
326
+	 * @return string
327
+	 */
328
+	public static function prepare_field_name_from_json($field_name)
329
+	{
330
+		if (Model_Data_Translator::is_gmt_date_field_name($field_name)) {
331
+			return Model_Data_Translator::remove_gmt_from_field_name($field_name);
332
+		}
333
+		return $field_name;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * Takes array of field names from REST API and prepares for models
340
+	 *
341
+	 * @param array $field_names
342
+	 * @return array of field names (possibly include model prefixes)
343
+	 */
344
+	public static function prepare_field_names_from_json(array $field_names)
345
+	{
346
+		$new_array = array();
347
+		foreach ($field_names as $key => $field_name) {
348
+			$new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name);
349
+		}
350
+		return $new_array;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * Takes array where array keys are field names (possibly with model path prefixes)
357
+	 * from the REST API and prepares them for model querying
358
+	 *
359
+	 * @param array $field_names_as_keys
360
+	 * @return array
361
+	 */
362
+	public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys)
363
+	{
364
+		$new_array = array();
365
+		foreach ($field_names_as_keys as $field_name => $value) {
366
+			$new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value;
367
+		}
368
+		return $new_array;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Prepares an array of model query params for use in the REST API
375
+	 *
376
+	 * @param array     $model_query_params
377
+	 * @param \EEM_Base $model
378
+	 * @param string    $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4
379
+	 *                                     REST API
380
+	 * @return array which can be passed into the EE4 REST API when querying a model resource
381
+	 * @throws \EE_Error
382
+	 */
383
+	public static function prepare_query_params_for_rest_api(
384
+		array $model_query_params,
385
+		\EEM_Base $model,
386
+		$requested_version = null
387
+	) {
388
+		if ($requested_version === null) {
389
+			$requested_version = \EED_Core_Rest_Api::latest_rest_api_version();
390
+		}
391
+		$rest_query_params = $model_query_params;
392
+		if (isset($model_query_params[0])) {
393
+			$rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
394
+				$model_query_params[0],
395
+				$model,
396
+				$requested_version
397
+			);
398
+			unset($rest_query_params[0]);
399
+		}
400
+		if (isset($model_query_params['having'])) {
401
+			$rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api(
402
+				$model_query_params['having'],
403
+				$model,
404
+				$requested_version
405
+			);
406
+		}
407
+		return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api',
408
+			$rest_query_params, $model_query_params, $model, $requested_version);
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api
415
+	 *
416
+	 * @param array     $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params
417
+	 *                                                      passed into EEM_Base::get_all()
418
+	 * @param \EEM_Base $model
419
+	 * @param string    $requested_version                  eg "4.8.36"
420
+	 * @return array ready for use in the rest api query params
421
+	 * @throws \EE_Error
422
+	 */
423
+	public static function prepare_conditions_query_params_for_rest_api(
424
+		$inputted_query_params_of_this_type,
425
+		\EEM_Base $model,
426
+		$requested_version
427
+	) {
428
+		$query_param_for_models = array();
429
+		foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) {
430
+			$field = Model_Data_Translator::deduce_field_from_query_param(
431
+				Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key),
432
+				$model
433
+			);
434
+			if ($field instanceof \EE_Model_Field_Base) {
435
+				//did they specify an operator?
436
+				if (is_array($query_param_value)) {
437
+					$op = $query_param_value[0];
438
+					$translated_value = array($op);
439
+					if (isset($query_param_value[1])) {
440
+						$value = $query_param_value[1];
441
+						$translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value,
442
+							$requested_version);
443
+					}
444
+				} else {
445
+					$translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value,
446
+						$requested_version);
447
+				}
448
+				$query_param_for_models[$query_param_key] = $translated_value;
449
+			} else {
450
+				//so it's not for a field, assume it's a logic query param key
451
+				$query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value,
452
+					$model, $requested_version);
453
+			}
454
+		}
455
+		return $query_param_for_models;
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * @param $condition_query_param_key
462
+	 * @return string
463
+	 */
464
+	public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key)
465
+	{
466
+		$pos_of_star = strpos($condition_query_param_key, '*');
467
+		if ($pos_of_star === false) {
468
+			return $condition_query_param_key;
469
+		} else {
470
+			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
471
+			return $condition_query_param_sans_star;
472
+		}
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * Takes the input parameter and finds the model field that it indicates.
479
+	 *
480
+	 * @param string    $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID
481
+	 * @param \EEM_Base $model
482
+	 * @return \EE_Model_Field_Base
483
+	 * @throws \EE_Error
484
+	 */
485
+	public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model)
486
+	{
487
+		//ok, now proceed with deducing which part is the model's name, and which is the field's name
488
+		//which will help us find the database table and column
489
+		$query_param_parts = explode('.', $query_param_name);
490
+		if (empty($query_param_parts)) {
491
+			throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s',
492
+				'event_espresso'), $query_param_name));
493
+		}
494
+		$number_of_parts = count($query_param_parts);
495
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
496
+		if ($number_of_parts === 1) {
497
+			$field_name = $last_query_param_part;
498
+		} else {// $number_of_parts >= 2
499
+			//the last part is the column name, and there are only 2parts. therefore...
500
+			$field_name = $last_query_param_part;
501
+			$model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]);
502
+		}
503
+		try {
504
+			return $model->field_settings_for($field_name);
505
+		} catch (\EE_Error $e) {
506
+			return null;
507
+		}
508
+	}
509 509
 
510 510
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
                     '0',
149 149
                     STR_PAD_LEFT
150 150
                 );
151
-            $new_value = rest_parse_date($original_value . $offset_sign . $offset_string);
151
+            $new_value = rest_parse_date($original_value.$offset_sign.$offset_string);
152 152
         } else {
153 153
             $new_value = $original_value;
154 154
         }
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private static function parse_timezone_offset($timezone_offset)
167 167
     {
168
-        $first_char = substr((string)$timezone_offset, 0, 1);
168
+        $first_char = substr((string) $timezone_offset, 0, 1);
169 169
         if ($first_char === '+' || $first_char === '-') {
170 170
             $offset_sign = $first_char;
171
-            $offset_secs = substr((string)$timezone_offset, 1);
171
+            $offset_secs = substr((string) $timezone_offset, 1);
172 172
         } else {
173 173
             $offset_sign = '+';
174 174
             $offset_secs = $timezone_offset;
Please login to merge, or discard this patch.
core/db_models/fields/EE_Field_With_Model_Name.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
      * Returns the name of the model(s) pointed to
36 36
      *
37 37
      * @deprecated since version 4.6.7
38
-     * @return mixed string or array of strings
38
+     * @return string string or array of strings
39 39
      */
40 40
     function get_model_name_pointed_to()
41 41
     {
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -8,83 +8,83 @@
 block discarded – undo
8 8
  */
9 9
 abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base
10 10
 {
11
-    /**
12
-     * Usually the name of a single model. However, as in the case for custom post types,
13
-     * it can actually be an array of models
14
-     *
15
-     * @var string or array
16
-     */
17
-    protected $_model_name_pointed_to;
11
+	/**
12
+	 * Usually the name of a single model. However, as in the case for custom post types,
13
+	 * it can actually be an array of models
14
+	 *
15
+	 * @var string or array
16
+	 */
17
+	protected $_model_name_pointed_to;
18 18
 
19
-    /**
20
-     * @param string  $table_column  name fo column for field
21
-     * @param string  $nicename      should eb internationalized with __('blah','event_espresso')
22
-     * @param boolean $nullable
23
-     * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
24
-     *                               dbe a string
25
-     * @param string  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
26
-     *                               "EEM_"
27
-     */
28
-    function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
-    {
30
-        $this->_model_name_pointed_to = $model_name;
31
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
32
-    }
19
+	/**
20
+	 * @param string  $table_column  name fo column for field
21
+	 * @param string  $nicename      should eb internationalized with __('blah','event_espresso')
22
+	 * @param boolean $nullable
23
+	 * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
24
+	 *                               dbe a string
25
+	 * @param string  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
26
+	 *                               "EEM_"
27
+	 */
28
+	function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
+	{
30
+		$this->_model_name_pointed_to = $model_name;
31
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
32
+	}
33 33
 
34
-    /**
35
-     * Returns the name of the model(s) pointed to
36
-     *
37
-     * @deprecated since version 4.6.7
38
-     * @return mixed string or array of strings
39
-     */
40
-    function get_model_name_pointed_to()
41
-    {
42
-        EE_Error::doing_it_wrong('get_model_name_pointed_to',
43
-            __('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
44
-                'event_espresso'), '4.6.7');
45
-        return $this->_model_name_pointed_to;
46
-    }
34
+	/**
35
+	 * Returns the name of the model(s) pointed to
36
+	 *
37
+	 * @deprecated since version 4.6.7
38
+	 * @return mixed string or array of strings
39
+	 */
40
+	function get_model_name_pointed_to()
41
+	{
42
+		EE_Error::doing_it_wrong('get_model_name_pointed_to',
43
+			__('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
44
+				'event_espresso'), '4.6.7');
45
+		return $this->_model_name_pointed_to;
46
+	}
47 47
 
48
-    /**
49
-     * Gets the model names pointed to by this field, always as an array
50
-     * (even if there's only one)
51
-     *
52
-     * @return array of model names pointed to by this field
53
-     */
54
-    function get_model_names_pointed_to()
55
-    {
56
-        if (is_array($this->_model_name_pointed_to)) {
57
-            return $this->_model_name_pointed_to;
58
-        } else {
59
-            return array($this->_model_name_pointed_to);
60
-        }
61
-    }
48
+	/**
49
+	 * Gets the model names pointed to by this field, always as an array
50
+	 * (even if there's only one)
51
+	 *
52
+	 * @return array of model names pointed to by this field
53
+	 */
54
+	function get_model_names_pointed_to()
55
+	{
56
+		if (is_array($this->_model_name_pointed_to)) {
57
+			return $this->_model_name_pointed_to;
58
+		} else {
59
+			return array($this->_model_name_pointed_to);
60
+		}
61
+	}
62 62
 
63
-    /**
64
-     * Returns the model's classname (eg EE_Event instead of just Event)
65
-     *
66
-     * @return array
67
-     */
68
-    function get_model_class_names_pointed_to()
69
-    {
70
-        $model_names = array();
71
-        if (is_array($this->_model_name_pointed_to)) {
72
-            foreach ($this->_model_name_pointed_to as $model_name) {
73
-                $model_names[] = "EE_" . $model_name;
74
-            }
75
-        } else {
76
-            $model_names = array("EE_" . $this->_model_name_pointed_to);
77
-        }
78
-        return $model_names;
79
-    }
63
+	/**
64
+	 * Returns the model's classname (eg EE_Event instead of just Event)
65
+	 *
66
+	 * @return array
67
+	 */
68
+	function get_model_class_names_pointed_to()
69
+	{
70
+		$model_names = array();
71
+		if (is_array($this->_model_name_pointed_to)) {
72
+			foreach ($this->_model_name_pointed_to as $model_name) {
73
+				$model_names[] = "EE_" . $model_name;
74
+			}
75
+		} else {
76
+			$model_names = array("EE_" . $this->_model_name_pointed_to);
77
+		}
78
+		return $model_names;
79
+	}
80 80
 
81
-    function is_model_obj_of_type_pointed_to($model_obj_or_ID)
82
-    {
83
-        foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
84
-            if ($model_obj_or_ID instanceof $model_obj_classname) {
85
-                return true;
86
-            }
87
-        }
88
-        return false;
89
-    }
81
+	function is_model_obj_of_type_pointed_to($model_obj_or_ID)
82
+	{
83
+		foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
84
+			if ($model_obj_or_ID instanceof $model_obj_classname) {
85
+				return true;
86
+			}
87
+		}
88
+		return false;
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,10 +70,10 @@
 block discarded – undo
70 70
         $model_names = array();
71 71
         if (is_array($this->_model_name_pointed_to)) {
72 72
             foreach ($this->_model_name_pointed_to as $model_name) {
73
-                $model_names[] = "EE_" . $model_name;
73
+                $model_names[] = "EE_".$model_name;
74 74
             }
75 75
         } else {
76
-            $model_names = array("EE_" . $this->_model_name_pointed_to);
76
+            $model_names = array("EE_".$this->_model_name_pointed_to);
77 77
         }
78 78
         return $model_names;
79 79
     }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_Field_Base.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -7,6 +7,7 @@
 block discarded – undo
7 7
      *
8 8
      * @param string $table_column
9 9
      * @param string $nicename
10
+     * @param integer|null $default
10 11
      */
11 12
     public function __construct($table_column, $nicename, $default)
12 13
     {
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -2,24 +2,24 @@
 block discarded – undo
2 2
 
3 3
 abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name
4 4
 {
5
-    /**
6
-     * Overrides parent so it doesn't need to provide so many non-applicable fields
7
-     *
8
-     * @param string $table_column
9
-     * @param string $nicename
10
-     */
11
-    public function __construct($table_column, $nicename, $default)
12
-    {
13
-        parent::__construct($table_column, $nicename, false, $default, null);
14
-    }
5
+	/**
6
+	 * Overrides parent so it doesn't need to provide so many non-applicable fields
7
+	 *
8
+	 * @param string $table_column
9
+	 * @param string $nicename
10
+	 */
11
+	public function __construct($table_column, $nicename, $default)
12
+	{
13
+		parent::__construct($table_column, $nicename, false, $default, null);
14
+	}
15 15
 
16
-    /**
17
-     * @param $table_alias
18
-     * @param $name
19
-     */
20
-    function _construct_finalize($table_alias, $name, $model_name)
21
-    {
22
-        $this->_model_name_pointed_to = $model_name;
23
-        parent::_construct_finalize($table_alias, $name, $model_name);
24
-    }
16
+	/**
17
+	 * @param $table_alias
18
+	 * @param $name
19
+	 */
20
+	function _construct_finalize($table_alias, $name, $model_name)
21
+	{
22
+		$this->_model_name_pointed_to = $model_name;
23
+		parent::_construct_finalize($table_alias, $name, $model_name);
24
+	}
25 25
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,6 @@
 block discarded – undo
33 33
      *                                    )
34 34
      *                                    )
35 35
      * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
-     *                                    set to true, it will be stored as an INT
38 36
      */
39 37
     function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40 38
     {
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -4,116 +4,116 @@
 block discarded – undo
4 4
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
5 5
 {
6 6
 
7
-    protected $_wp_post_stati;
8
-
9
-
10
-    /**
11
-     * constructor
12
-     *
13
-     * @param string  $table_column       column on table
14
-     * @param string  $nicename           nice name for column(field)
15
-     * @param bool    $nullable           is this field nullable
16
-     * @param string  $default_value      default status
17
-     * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
18
-     *                                    they can be registered via this property.  The format of the array should be
19
-     *                                    as follows: array(
20
-     *                                    'status_reference' => array(
21
-     *                                    'label' => __('Status Reference Label', 'event_espresso')
22
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
23
-     *                                    frontend of the site'
24
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
25
-     *                                    excluded from wp searches'
26
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
27
-     *                                    in queries for the admin "all" view in list table views.
28
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
29
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
30
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
31
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
32
-     *                                    on the admin screen( or you won't see your status count ).
33
-     *                                    )
34
-     *                                    )
35
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
-     *                                    set to true, it will be stored as an INT
38
-     */
39
-    function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40
-    {
41
-        $this->_register_new_stati($new_stati);
42
-        $this->_set_allowed_enum_values();
43
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
44
-    }
45
-
46
-
47
-    /**
48
-     * This registers any new statuses sent via the $new_stati array on construct
49
-     *
50
-     * @access protected
51
-     * @param  array $new_stati statuses
52
-     * @return void
53
-     */
54
-    protected function _register_new_stati($new_stati)
55
-    {
56
-
57
-        foreach ((array)$new_stati as $status_key => $status_args) {
58
-            $args = array(
59
-                'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60
-                'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
61
-                'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
62
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
63
-                'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
64
-                'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
65
-            );
66
-            register_post_status($status_key, $status_args);
67
-        }
68
-
69
-    }
70
-
71
-
72
-    /**
73
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
74
-     *
75
-     * @access protected
76
-     * @regurn void
77
-     */
78
-    protected function _set_allowed_enum_values()
79
-    {
80
-        //first let's get the post_statuses
81
-        global $wp_post_statuses;
82
-        $this->_wp_post_stati = $wp_post_statuses;
83
-
84
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
85
-            $this->_allowed_enum_values[$post_status] = $args_object->label;
86
-        }
87
-
88
-    }
89
-
90
-    /**
91
-     * Before calling parent, first double-checks our list of acceptable post
92
-     * types is up-to-date
93
-     *
94
-     * @param string $value_inputted_for_field_on_model_object
95
-     * @return string
96
-     */
97
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
98
-    {
99
-        $this->_set_allowed_enum_values();
100
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
101
-    }
102
-
103
-
104
-
105
-    //helper methods for getting various $wp_post_statuses stuff.
106
-
107
-    /**
108
-     * This just returns the status object for the given status
109
-     *
110
-     * @access public
111
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
112
-     * @param  string $status What status object you want
113
-     * @return std_object         the status object or FALSE if it doesn't exist.
114
-     */
115
-    public function get_status_object($status)
116
-    {
117
-        return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
118
-    }
7
+	protected $_wp_post_stati;
8
+
9
+
10
+	/**
11
+	 * constructor
12
+	 *
13
+	 * @param string  $table_column       column on table
14
+	 * @param string  $nicename           nice name for column(field)
15
+	 * @param bool    $nullable           is this field nullable
16
+	 * @param string  $default_value      default status
17
+	 * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
18
+	 *                                    they can be registered via this property.  The format of the array should be
19
+	 *                                    as follows: array(
20
+	 *                                    'status_reference' => array(
21
+	 *                                    'label' => __('Status Reference Label', 'event_espresso')
22
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
23
+	 *                                    frontend of the site'
24
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
25
+	 *                                    excluded from wp searches'
26
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
27
+	 *                                    in queries for the admin "all" view in list table views.
28
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
29
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
30
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
31
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
32
+	 *                                    on the admin screen( or you won't see your status count ).
33
+	 *                                    )
34
+	 *                                    )
35
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
36
+	 * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
37
+	 *                                    set to true, it will be stored as an INT
38
+	 */
39
+	function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
40
+	{
41
+		$this->_register_new_stati($new_stati);
42
+		$this->_set_allowed_enum_values();
43
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
44
+	}
45
+
46
+
47
+	/**
48
+	 * This registers any new statuses sent via the $new_stati array on construct
49
+	 *
50
+	 * @access protected
51
+	 * @param  array $new_stati statuses
52
+	 * @return void
53
+	 */
54
+	protected function _register_new_stati($new_stati)
55
+	{
56
+
57
+		foreach ((array)$new_stati as $status_key => $status_args) {
58
+			$args = array(
59
+				'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60
+				'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
61
+				'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
62
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
63
+				'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
64
+				'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
65
+			);
66
+			register_post_status($status_key, $status_args);
67
+		}
68
+
69
+	}
70
+
71
+
72
+	/**
73
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
74
+	 *
75
+	 * @access protected
76
+	 * @regurn void
77
+	 */
78
+	protected function _set_allowed_enum_values()
79
+	{
80
+		//first let's get the post_statuses
81
+		global $wp_post_statuses;
82
+		$this->_wp_post_stati = $wp_post_statuses;
83
+
84
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
85
+			$this->_allowed_enum_values[$post_status] = $args_object->label;
86
+		}
87
+
88
+	}
89
+
90
+	/**
91
+	 * Before calling parent, first double-checks our list of acceptable post
92
+	 * types is up-to-date
93
+	 *
94
+	 * @param string $value_inputted_for_field_on_model_object
95
+	 * @return string
96
+	 */
97
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
98
+	{
99
+		$this->_set_allowed_enum_values();
100
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
101
+	}
102
+
103
+
104
+
105
+	//helper methods for getting various $wp_post_statuses stuff.
106
+
107
+	/**
108
+	 * This just returns the status object for the given status
109
+	 *
110
+	 * @access public
111
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
112
+	 * @param  string $status What status object you want
113
+	 * @return std_object         the status object or FALSE if it doesn't exist.
114
+	 */
115
+	public function get_status_object($status)
116
+	{
117
+		return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
118
+	}
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_Enum_Text_Field.php');
2
+require_once(EE_MODELS.'fields/EE_Enum_Text_Field.php');
3 3
 
4 4
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
5 5
 {
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     protected function _register_new_stati($new_stati)
55 55
     {
56 56
 
57
-        foreach ((array)$new_stati as $status_key => $status_args) {
57
+        foreach ((array) $new_stati as $status_key => $status_args) {
58 58
             $args = array(
59 59
                 'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
60 60
                 'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
Please login to merge, or discard this patch.