@@ -14,328 +14,328 @@ |
||
14 | 14 | class EEH_Sideloader extends EEH_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @since 4.1.0 |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private $_upload_to; |
|
22 | - |
|
23 | - /** |
|
24 | - * @since 4.10.5.p |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private $_download_from; |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 4.1.0 |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private $_permissions; |
|
34 | - |
|
35 | - /** |
|
36 | - * @since 4.1.0 |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $_new_file_name; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
44 | - * |
|
45 | - * @since 4.1.0 |
|
46 | - * @param array $init array fo initializing the sideloader if keys match the properties. |
|
47 | - */ |
|
48 | - public function __construct($init = array()) |
|
49 | - { |
|
50 | - $this->_init($init); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * sets the properties for class either to defaults or using incoming initialization array |
|
56 | - * |
|
57 | - * @since 4.1.0 |
|
58 | - * @param array $init array on init (keys match properties others ignored) |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - private function _init($init) |
|
62 | - { |
|
63 | - $defaults = array( |
|
64 | - '_upload_to' => $this->_get_wp_uploads_dir(), |
|
65 | - '_download_from' => '', |
|
66 | - '_permissions' => 0644, |
|
67 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
68 | - ); |
|
69 | - |
|
70 | - $props = array_merge($defaults, $init); |
|
71 | - |
|
72 | - foreach ($props as $property => $val) { |
|
73 | - $setter = 'set' . $property; |
|
74 | - if (method_exists($this, $setter)) { |
|
75 | - $this->$setter($val); |
|
76 | - } else { |
|
77 | - // No setter found. |
|
78 | - EE_Error::add_error( |
|
79 | - sprintf( |
|
80 | - esc_html__( |
|
81 | - 'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $setter, |
|
85 | - $property |
|
86 | - ), |
|
87 | - __FILE__, |
|
88 | - __FUNCTION__, |
|
89 | - __LINE__ |
|
90 | - ); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - // make sure we include the required wp file for needed functions |
|
95 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - // utilities |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @since 4.1.0 |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - private function _get_wp_uploads_dir() |
|
107 | - { |
|
108 | - } |
|
109 | - |
|
110 | - // setters |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * sets the _upload_to property to the directory to upload to. |
|
115 | - * |
|
116 | - * @since 4.1.0 |
|
117 | - * @param $upload_to_folder |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function set_upload_to($upload_to_folder) |
|
121 | - { |
|
122 | - $this->_upload_to = $upload_to_folder; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * sets the _download_from property to the location we should download the file from. |
|
128 | - * |
|
129 | - * @since 4.10.5.p |
|
130 | - * @param string $download_from The full path to the file we should sideload. |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function set_download_from($download_from) |
|
134 | - { |
|
135 | - $this->_download_from = $download_from; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * sets the _permissions property used on the sideloaded file. |
|
141 | - * |
|
142 | - * @since 4.1.0 |
|
143 | - * @param int $permissions |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function set_permissions($permissions) |
|
147 | - { |
|
148 | - $this->_permissions = $permissions; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * sets the _new_file_name property used on the sideloaded file. |
|
154 | - * |
|
155 | - * @since 4.1.0 |
|
156 | - * @param string $new_file_name |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function set_new_file_name($new_file_name) |
|
160 | - { |
|
161 | - $this->_new_file_name = $new_file_name; |
|
162 | - } |
|
163 | - |
|
164 | - // getters |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @since 4.1.0 |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_upload_to() |
|
172 | - { |
|
173 | - return $this->_upload_to; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @since 4.10.5.p |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_download_from() |
|
182 | - { |
|
183 | - return $this->_download_from; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @since 4.1.0 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_permissions() |
|
192 | - { |
|
193 | - return $this->_permissions; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @since 4.1.0 |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function get_new_file_name() |
|
202 | - { |
|
203 | - return $this->_new_file_name; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - // upload methods |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Downloads the file using the WordPress HTTP API. |
|
212 | - * |
|
213 | - * @since 4.1.0 |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function sideload() |
|
217 | - { |
|
218 | - // setup temp dir |
|
219 | - $temp_file = wp_tempnam($this->_download_from); |
|
220 | - |
|
221 | - if (!$temp_file) { |
|
222 | - EE_Error::add_error( |
|
223 | - esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
224 | - __FILE__, |
|
225 | - __FUNCTION__, |
|
226 | - __LINE__ |
|
227 | - ); |
|
228 | - return false; |
|
229 | - } |
|
230 | - |
|
231 | - do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
232 | - |
|
233 | - $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
234 | - |
|
235 | - $response = wp_safe_remote_get($this->_download_from, $wp_remote_args); |
|
236 | - |
|
237 | - if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
238 | - unlink($temp_file); |
|
239 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
240 | - EE_Error::add_error( |
|
241 | - sprintf( |
|
242 | - esc_html__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
243 | - $this->_download_from |
|
244 | - ), |
|
245 | - __FILE__, |
|
246 | - __FUNCTION__, |
|
247 | - __LINE__ |
|
248 | - ); |
|
249 | - } |
|
250 | - return false; |
|
251 | - } |
|
252 | - |
|
253 | - // possible md5 check |
|
254 | - $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
255 | - if ($content_md5) { |
|
256 | - $md5_check = verify_file_md5($temp_file, $content_md5); |
|
257 | - if (is_wp_error($md5_check)) { |
|
258 | - unlink($temp_file); |
|
259 | - EE_Error::add_error( |
|
260 | - $md5_check->get_error_message(), |
|
261 | - __FILE__, |
|
262 | - __FUNCTION__, |
|
263 | - __LINE__ |
|
264 | - ); |
|
265 | - return false; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - $file = $temp_file; |
|
270 | - |
|
271 | - // now we have the file, let's get it in the right directory with the right name. |
|
272 | - $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
273 | - |
|
274 | - // move file in |
|
275 | - if (false === @ rename($file, $path)) { |
|
276 | - unlink($temp_file); |
|
277 | - EE_Error::add_error( |
|
278 | - sprintf( |
|
279 | - esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
280 | - $path |
|
281 | - ), |
|
282 | - __FILE__, |
|
283 | - __FUNCTION__, |
|
284 | - __LINE__ |
|
285 | - ); |
|
286 | - return false; |
|
287 | - } |
|
288 | - |
|
289 | - // set permissions |
|
290 | - $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
291 | - chmod($path, $permissions); |
|
292 | - |
|
293 | - // that's it. let's allow for actions after file uploaded. |
|
294 | - do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | - |
|
296 | - // unlink tempfile |
|
297 | - @unlink($temp_file); |
|
298 | - return true; |
|
299 | - } |
|
300 | - |
|
301 | - // deprecated |
|
302 | - |
|
303 | - /** |
|
304 | - * sets the _upload_from property to the location we should download the file from. |
|
305 | - * |
|
306 | - * @param string $upload_from The full path to the file we should sideload. |
|
307 | - * @return void |
|
308 | - * @deprecated since version 4.10.5.p |
|
309 | - */ |
|
310 | - public function set_upload_from($upload_from) |
|
311 | - { |
|
312 | - EE_Error::doing_it_wrong( |
|
313 | - __CLASS__ . '::' . __FUNCTION__, |
|
314 | - __( |
|
315 | - 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from', |
|
316 | - 'event_espresso' |
|
317 | - ), |
|
318 | - '4.10.5.p' |
|
319 | - ); |
|
320 | - $this->set_download_from($upload_from); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @since 4.1.0 |
|
326 | - * @return string |
|
327 | - * @deprecated since version 4.10.5.p |
|
328 | - */ |
|
329 | - public function get_upload_from() |
|
330 | - { |
|
331 | - EE_Error::doing_it_wrong( |
|
332 | - __CLASS__ . '::' . __FUNCTION__, |
|
333 | - __( |
|
334 | - 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from', |
|
335 | - 'event_espresso' |
|
336 | - ), |
|
337 | - '4.10.5.p' |
|
338 | - ); |
|
339 | - return $this->_download_from; |
|
340 | - } |
|
17 | + /** |
|
18 | + * @since 4.1.0 |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private $_upload_to; |
|
22 | + |
|
23 | + /** |
|
24 | + * @since 4.10.5.p |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private $_download_from; |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 4.1.0 |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private $_permissions; |
|
34 | + |
|
35 | + /** |
|
36 | + * @since 4.1.0 |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $_new_file_name; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * constructor allows the user to set the properties on the sideloader on construct. However, there are also setters for doing so. |
|
44 | + * |
|
45 | + * @since 4.1.0 |
|
46 | + * @param array $init array fo initializing the sideloader if keys match the properties. |
|
47 | + */ |
|
48 | + public function __construct($init = array()) |
|
49 | + { |
|
50 | + $this->_init($init); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * sets the properties for class either to defaults or using incoming initialization array |
|
56 | + * |
|
57 | + * @since 4.1.0 |
|
58 | + * @param array $init array on init (keys match properties others ignored) |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + private function _init($init) |
|
62 | + { |
|
63 | + $defaults = array( |
|
64 | + '_upload_to' => $this->_get_wp_uploads_dir(), |
|
65 | + '_download_from' => '', |
|
66 | + '_permissions' => 0644, |
|
67 | + '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
68 | + ); |
|
69 | + |
|
70 | + $props = array_merge($defaults, $init); |
|
71 | + |
|
72 | + foreach ($props as $property => $val) { |
|
73 | + $setter = 'set' . $property; |
|
74 | + if (method_exists($this, $setter)) { |
|
75 | + $this->$setter($val); |
|
76 | + } else { |
|
77 | + // No setter found. |
|
78 | + EE_Error::add_error( |
|
79 | + sprintf( |
|
80 | + esc_html__( |
|
81 | + 'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $setter, |
|
85 | + $property |
|
86 | + ), |
|
87 | + __FILE__, |
|
88 | + __FUNCTION__, |
|
89 | + __LINE__ |
|
90 | + ); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + // make sure we include the required wp file for needed functions |
|
95 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + // utilities |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @since 4.1.0 |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + private function _get_wp_uploads_dir() |
|
107 | + { |
|
108 | + } |
|
109 | + |
|
110 | + // setters |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * sets the _upload_to property to the directory to upload to. |
|
115 | + * |
|
116 | + * @since 4.1.0 |
|
117 | + * @param $upload_to_folder |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function set_upload_to($upload_to_folder) |
|
121 | + { |
|
122 | + $this->_upload_to = $upload_to_folder; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * sets the _download_from property to the location we should download the file from. |
|
128 | + * |
|
129 | + * @since 4.10.5.p |
|
130 | + * @param string $download_from The full path to the file we should sideload. |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function set_download_from($download_from) |
|
134 | + { |
|
135 | + $this->_download_from = $download_from; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * sets the _permissions property used on the sideloaded file. |
|
141 | + * |
|
142 | + * @since 4.1.0 |
|
143 | + * @param int $permissions |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function set_permissions($permissions) |
|
147 | + { |
|
148 | + $this->_permissions = $permissions; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * sets the _new_file_name property used on the sideloaded file. |
|
154 | + * |
|
155 | + * @since 4.1.0 |
|
156 | + * @param string $new_file_name |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function set_new_file_name($new_file_name) |
|
160 | + { |
|
161 | + $this->_new_file_name = $new_file_name; |
|
162 | + } |
|
163 | + |
|
164 | + // getters |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @since 4.1.0 |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_upload_to() |
|
172 | + { |
|
173 | + return $this->_upload_to; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @since 4.10.5.p |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_download_from() |
|
182 | + { |
|
183 | + return $this->_download_from; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @since 4.1.0 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_permissions() |
|
192 | + { |
|
193 | + return $this->_permissions; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @since 4.1.0 |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function get_new_file_name() |
|
202 | + { |
|
203 | + return $this->_new_file_name; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + // upload methods |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Downloads the file using the WordPress HTTP API. |
|
212 | + * |
|
213 | + * @since 4.1.0 |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function sideload() |
|
217 | + { |
|
218 | + // setup temp dir |
|
219 | + $temp_file = wp_tempnam($this->_download_from); |
|
220 | + |
|
221 | + if (!$temp_file) { |
|
222 | + EE_Error::add_error( |
|
223 | + esc_html__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), |
|
224 | + __FILE__, |
|
225 | + __FUNCTION__, |
|
226 | + __LINE__ |
|
227 | + ); |
|
228 | + return false; |
|
229 | + } |
|
230 | + |
|
231 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
232 | + |
|
233 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file); |
|
234 | + |
|
235 | + $response = wp_safe_remote_get($this->_download_from, $wp_remote_args); |
|
236 | + |
|
237 | + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
238 | + unlink($temp_file); |
|
239 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
240 | + EE_Error::add_error( |
|
241 | + sprintf( |
|
242 | + esc_html__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'), |
|
243 | + $this->_download_from |
|
244 | + ), |
|
245 | + __FILE__, |
|
246 | + __FUNCTION__, |
|
247 | + __LINE__ |
|
248 | + ); |
|
249 | + } |
|
250 | + return false; |
|
251 | + } |
|
252 | + |
|
253 | + // possible md5 check |
|
254 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
255 | + if ($content_md5) { |
|
256 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
257 | + if (is_wp_error($md5_check)) { |
|
258 | + unlink($temp_file); |
|
259 | + EE_Error::add_error( |
|
260 | + $md5_check->get_error_message(), |
|
261 | + __FILE__, |
|
262 | + __FUNCTION__, |
|
263 | + __LINE__ |
|
264 | + ); |
|
265 | + return false; |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + $file = $temp_file; |
|
270 | + |
|
271 | + // now we have the file, let's get it in the right directory with the right name. |
|
272 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this); |
|
273 | + |
|
274 | + // move file in |
|
275 | + if (false === @ rename($file, $path)) { |
|
276 | + unlink($temp_file); |
|
277 | + EE_Error::add_error( |
|
278 | + sprintf( |
|
279 | + esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), |
|
280 | + $path |
|
281 | + ), |
|
282 | + __FILE__, |
|
283 | + __FUNCTION__, |
|
284 | + __LINE__ |
|
285 | + ); |
|
286 | + return false; |
|
287 | + } |
|
288 | + |
|
289 | + // set permissions |
|
290 | + $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
291 | + chmod($path, $permissions); |
|
292 | + |
|
293 | + // that's it. let's allow for actions after file uploaded. |
|
294 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | + |
|
296 | + // unlink tempfile |
|
297 | + @unlink($temp_file); |
|
298 | + return true; |
|
299 | + } |
|
300 | + |
|
301 | + // deprecated |
|
302 | + |
|
303 | + /** |
|
304 | + * sets the _upload_from property to the location we should download the file from. |
|
305 | + * |
|
306 | + * @param string $upload_from The full path to the file we should sideload. |
|
307 | + * @return void |
|
308 | + * @deprecated since version 4.10.5.p |
|
309 | + */ |
|
310 | + public function set_upload_from($upload_from) |
|
311 | + { |
|
312 | + EE_Error::doing_it_wrong( |
|
313 | + __CLASS__ . '::' . __FUNCTION__, |
|
314 | + __( |
|
315 | + 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from', |
|
316 | + 'event_espresso' |
|
317 | + ), |
|
318 | + '4.10.5.p' |
|
319 | + ); |
|
320 | + $this->set_download_from($upload_from); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @since 4.1.0 |
|
326 | + * @return string |
|
327 | + * @deprecated since version 4.10.5.p |
|
328 | + */ |
|
329 | + public function get_upload_from() |
|
330 | + { |
|
331 | + EE_Error::doing_it_wrong( |
|
332 | + __CLASS__ . '::' . __FUNCTION__, |
|
333 | + __( |
|
334 | + 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from', |
|
335 | + 'event_espresso' |
|
336 | + ), |
|
337 | + '4.10.5.p' |
|
338 | + ); |
|
339 | + return $this->_download_from; |
|
340 | + } |
|
341 | 341 | } //end EEH_Sideloader class |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.6.rc.000'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.6.rc.000'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |