@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,673 +16,673 @@ discard block |
||
16 | 16 | abstract class EE_SPCO_Reg_Step |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * $_completed - TRUE if this step has fully completed it's duties |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @type bool $_completed |
|
24 | - */ |
|
25 | - protected $_completed = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_is_current_step - TRUE if this is the current step |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @type bool $_is_current_step |
|
32 | - */ |
|
33 | - protected $_is_current_step = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * $_order - when the reg step should be run relative to other steps |
|
37 | - * |
|
38 | - * @access protected |
|
39 | - * @type int $_template |
|
40 | - */ |
|
41 | - protected $_order = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * $_slug - URL param for this step |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @type string $_slug |
|
48 | - */ |
|
49 | - protected $_slug; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_name - Step Name - translatable string |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @type string $_slug |
|
56 | - */ |
|
57 | - protected $_name; |
|
58 | - |
|
59 | - /** |
|
60 | - * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | - * |
|
62 | - * @access protected |
|
63 | - * @type string $_slug |
|
64 | - */ |
|
65 | - protected $_submit_button_text; |
|
66 | - |
|
67 | - /** |
|
68 | - * $_template - template name |
|
69 | - * |
|
70 | - * @access protected |
|
71 | - * @type string $_template |
|
72 | - */ |
|
73 | - protected $_template; |
|
74 | - |
|
75 | - /** |
|
76 | - * $_reg_form_name - the form input name and id attribute |
|
77 | - * |
|
78 | - * @access protected |
|
79 | - * @var string $_reg_form_name |
|
80 | - */ |
|
81 | - protected $_reg_form_name; |
|
82 | - |
|
83 | - /** |
|
84 | - * $_success_message - text to display upon successful form submission |
|
85 | - * |
|
86 | - * @access private |
|
87 | - * @var string $_success_message |
|
88 | - */ |
|
89 | - protected $_success_message; |
|
90 | - |
|
91 | - /** |
|
92 | - * $_instructions - a brief description of how to complete the reg step. |
|
93 | - * Usually displayed in conjunction with the previous step's success message. |
|
94 | - * |
|
95 | - * @access private |
|
96 | - * @var string $_instructions |
|
97 | - */ |
|
98 | - protected $_instructions; |
|
99 | - |
|
100 | - /** |
|
101 | - * $_valid_data - the normalized and validated data for this step |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @var array $_valid_data |
|
105 | - */ |
|
106 | - protected $_valid_data = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * $reg_form - the registration form for this step |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @var EE_Form_Section_Proper $reg_form |
|
113 | - */ |
|
114 | - public $reg_form; |
|
115 | - |
|
116 | - /** |
|
117 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Checkout $checkout |
|
121 | - */ |
|
122 | - public $checkout; |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - abstract public function translate_js_strings(); |
|
130 | - |
|
131 | - |
|
19 | + /** |
|
20 | + * $_completed - TRUE if this step has fully completed it's duties |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @type bool $_completed |
|
24 | + */ |
|
25 | + protected $_completed = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_is_current_step - TRUE if this is the current step |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @type bool $_is_current_step |
|
32 | + */ |
|
33 | + protected $_is_current_step = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * $_order - when the reg step should be run relative to other steps |
|
37 | + * |
|
38 | + * @access protected |
|
39 | + * @type int $_template |
|
40 | + */ |
|
41 | + protected $_order = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * $_slug - URL param for this step |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @type string $_slug |
|
48 | + */ |
|
49 | + protected $_slug; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_name - Step Name - translatable string |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @type string $_slug |
|
56 | + */ |
|
57 | + protected $_name; |
|
58 | + |
|
59 | + /** |
|
60 | + * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | + * |
|
62 | + * @access protected |
|
63 | + * @type string $_slug |
|
64 | + */ |
|
65 | + protected $_submit_button_text; |
|
66 | + |
|
67 | + /** |
|
68 | + * $_template - template name |
|
69 | + * |
|
70 | + * @access protected |
|
71 | + * @type string $_template |
|
72 | + */ |
|
73 | + protected $_template; |
|
74 | + |
|
75 | + /** |
|
76 | + * $_reg_form_name - the form input name and id attribute |
|
77 | + * |
|
78 | + * @access protected |
|
79 | + * @var string $_reg_form_name |
|
80 | + */ |
|
81 | + protected $_reg_form_name; |
|
82 | + |
|
83 | + /** |
|
84 | + * $_success_message - text to display upon successful form submission |
|
85 | + * |
|
86 | + * @access private |
|
87 | + * @var string $_success_message |
|
88 | + */ |
|
89 | + protected $_success_message; |
|
90 | + |
|
91 | + /** |
|
92 | + * $_instructions - a brief description of how to complete the reg step. |
|
93 | + * Usually displayed in conjunction with the previous step's success message. |
|
94 | + * |
|
95 | + * @access private |
|
96 | + * @var string $_instructions |
|
97 | + */ |
|
98 | + protected $_instructions; |
|
99 | + |
|
100 | + /** |
|
101 | + * $_valid_data - the normalized and validated data for this step |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @var array $_valid_data |
|
105 | + */ |
|
106 | + protected $_valid_data = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * $reg_form - the registration form for this step |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @var EE_Form_Section_Proper $reg_form |
|
113 | + */ |
|
114 | + public $reg_form; |
|
115 | + |
|
116 | + /** |
|
117 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Checkout $checkout |
|
121 | + */ |
|
122 | + public $checkout; |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + abstract public function translate_js_strings(); |
|
130 | + |
|
131 | + |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function enqueue_styles_and_scripts(); |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - abstract public function initialize_reg_step(); |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - abstract public function generate_reg_form(); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return boolean |
|
156 | - */ |
|
157 | - abstract public function process_reg_step(); |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return boolean |
|
163 | - */ |
|
164 | - abstract public function update_reg_step(); |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return boolean |
|
170 | - */ |
|
171 | - public function completed() |
|
172 | - { |
|
173 | - return $this->_completed; |
|
174 | - } |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function enqueue_styles_and_scripts(); |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + abstract public function initialize_reg_step(); |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + abstract public function generate_reg_form(); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return boolean |
|
156 | + */ |
|
157 | + abstract public function process_reg_step(); |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return boolean |
|
163 | + */ |
|
164 | + abstract public function update_reg_step(); |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return boolean |
|
170 | + */ |
|
171 | + public function completed() |
|
172 | + { |
|
173 | + return $this->_completed; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * set_completed - toggles $_completed to TRUE |
|
180 | - */ |
|
181 | - public function set_completed() |
|
182 | - { |
|
183 | - // DEBUG LOG |
|
184 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | - $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | - } |
|
178 | + /** |
|
179 | + * set_completed - toggles $_completed to TRUE |
|
180 | + */ |
|
181 | + public function set_completed() |
|
182 | + { |
|
183 | + // DEBUG LOG |
|
184 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | + $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * set_completed - toggles $_completed to FALSE |
|
192 | - */ |
|
193 | - public function set_not_completed() |
|
194 | - { |
|
195 | - $this->_completed = false; |
|
196 | - } |
|
190 | + /** |
|
191 | + * set_completed - toggles $_completed to FALSE |
|
192 | + */ |
|
193 | + public function set_not_completed() |
|
194 | + { |
|
195 | + $this->_completed = false; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function name() |
|
204 | - { |
|
205 | - return $this->_name; |
|
206 | - } |
|
200 | + /** |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function name() |
|
204 | + { |
|
205 | + return $this->_name; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | 209 | |
210 | - /** |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function slug() |
|
214 | - { |
|
215 | - return $this->_slug; |
|
216 | - } |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function slug() |
|
214 | + { |
|
215 | + return $this->_slug; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * submit_button_text |
|
222 | - * the text that appears on the reg step form submit button |
|
223 | - * |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function submit_button_text() |
|
227 | - { |
|
228 | - return $this->_submit_button_text; |
|
229 | - } |
|
220 | + /** |
|
221 | + * submit_button_text |
|
222 | + * the text that appears on the reg step form submit button |
|
223 | + * |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function submit_button_text() |
|
227 | + { |
|
228 | + return $this->_submit_button_text; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * set_submit_button_text |
|
235 | - * sets the text that appears on the reg step form submit button |
|
236 | - * |
|
237 | - * @param string $submit_button_text |
|
238 | - */ |
|
239 | - public function set_submit_button_text($submit_button_text = '') |
|
240 | - { |
|
241 | - if (! empty($submit_button_text)) { |
|
242 | - $this->_submit_button_text = $submit_button_text; |
|
243 | - } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | - if ($this->checkout->revisit) { |
|
245 | - $this->_submit_button_text = sprintf( |
|
246 | - __('Update %s', 'event_espresso'), |
|
247 | - $this->checkout->current_step->name() |
|
248 | - ); |
|
249 | - } else { |
|
250 | - $this->_submit_button_text = sprintf( |
|
251 | - __('Proceed to %s', 'event_espresso'), |
|
252 | - $this->checkout->next_step->name() |
|
253 | - ); |
|
254 | - } |
|
255 | - } |
|
256 | - // filters the submit button text |
|
257 | - $this->_submit_button_text = apply_filters( |
|
258 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
259 | - $this->_submit_button_text, |
|
260 | - $this->checkout |
|
261 | - ); |
|
262 | - } |
|
233 | + /** |
|
234 | + * set_submit_button_text |
|
235 | + * sets the text that appears on the reg step form submit button |
|
236 | + * |
|
237 | + * @param string $submit_button_text |
|
238 | + */ |
|
239 | + public function set_submit_button_text($submit_button_text = '') |
|
240 | + { |
|
241 | + if (! empty($submit_button_text)) { |
|
242 | + $this->_submit_button_text = $submit_button_text; |
|
243 | + } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | + if ($this->checkout->revisit) { |
|
245 | + $this->_submit_button_text = sprintf( |
|
246 | + __('Update %s', 'event_espresso'), |
|
247 | + $this->checkout->current_step->name() |
|
248 | + ); |
|
249 | + } else { |
|
250 | + $this->_submit_button_text = sprintf( |
|
251 | + __('Proceed to %s', 'event_espresso'), |
|
252 | + $this->checkout->next_step->name() |
|
253 | + ); |
|
254 | + } |
|
255 | + } |
|
256 | + // filters the submit button text |
|
257 | + $this->_submit_button_text = apply_filters( |
|
258 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
259 | + $this->_submit_button_text, |
|
260 | + $this->checkout |
|
261 | + ); |
|
262 | + } |
|
263 | 263 | |
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * @param boolean $is_current_step |
|
268 | - */ |
|
269 | - public function set_is_current_step($is_current_step) |
|
270 | - { |
|
271 | - $this->_is_current_step = $is_current_step; |
|
272 | - } |
|
266 | + /** |
|
267 | + * @param boolean $is_current_step |
|
268 | + */ |
|
269 | + public function set_is_current_step($is_current_step) |
|
270 | + { |
|
271 | + $this->_is_current_step = $is_current_step; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * @return boolean |
|
278 | - */ |
|
279 | - public function is_current_step() |
|
280 | - { |
|
281 | - return $this->_is_current_step; |
|
282 | - } |
|
276 | + /** |
|
277 | + * @return boolean |
|
278 | + */ |
|
279 | + public function is_current_step() |
|
280 | + { |
|
281 | + return $this->_is_current_step; |
|
282 | + } |
|
283 | 283 | |
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * @return boolean |
|
288 | - */ |
|
289 | - public function is_final_step() |
|
290 | - { |
|
291 | - return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
292 | - } |
|
286 | + /** |
|
287 | + * @return boolean |
|
288 | + */ |
|
289 | + public function is_final_step() |
|
290 | + { |
|
291 | + return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | 295 | |
296 | - /** |
|
297 | - * @param int $order |
|
298 | - */ |
|
299 | - public function set_order($order) |
|
300 | - { |
|
301 | - $this->_order = $order; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
296 | + /** |
|
297 | + * @param int $order |
|
298 | + */ |
|
299 | + public function set_order($order) |
|
300 | + { |
|
301 | + $this->_order = $order; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | 305 | |
306 | - /** |
|
307 | - * @return int |
|
308 | - */ |
|
309 | - public function order() |
|
310 | - { |
|
311 | - return $this->_order; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @return string |
|
318 | - */ |
|
319 | - public function template() |
|
320 | - { |
|
321 | - return $this->_template; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public function success_message() |
|
330 | - { |
|
331 | - return $this->_success_message; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * _set_success_message |
|
338 | - * |
|
339 | - * @param string $success_message |
|
340 | - */ |
|
341 | - protected function _set_success_message($success_message) |
|
342 | - { |
|
343 | - $this->_success_message = $success_message; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * _reset_success_message |
|
350 | - * |
|
351 | - * @return void |
|
352 | - */ |
|
353 | - protected function _reset_success_message() |
|
354 | - { |
|
355 | - $this->_success_message = ''; |
|
356 | - } |
|
306 | + /** |
|
307 | + * @return int |
|
308 | + */ |
|
309 | + public function order() |
|
310 | + { |
|
311 | + return $this->_order; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @return string |
|
318 | + */ |
|
319 | + public function template() |
|
320 | + { |
|
321 | + return $this->_template; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public function success_message() |
|
330 | + { |
|
331 | + return $this->_success_message; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * _set_success_message |
|
338 | + * |
|
339 | + * @param string $success_message |
|
340 | + */ |
|
341 | + protected function _set_success_message($success_message) |
|
342 | + { |
|
343 | + $this->_success_message = $success_message; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * _reset_success_message |
|
350 | + * |
|
351 | + * @return void |
|
352 | + */ |
|
353 | + protected function _reset_success_message() |
|
354 | + { |
|
355 | + $this->_success_message = ''; |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | 359 | |
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function _instructions() |
|
364 | - { |
|
365 | - return $this->_instructions; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param string $instructions |
|
372 | - */ |
|
373 | - public function set_instructions($instructions) |
|
374 | - { |
|
375 | - $this->_instructions = apply_filters( |
|
376 | - 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
377 | - $instructions, |
|
378 | - $this |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @param array $valid_data |
|
386 | - */ |
|
387 | - public function set_valid_data($valid_data) |
|
388 | - { |
|
389 | - $this->_valid_data = $valid_data; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function valid_data() |
|
398 | - { |
|
399 | - if (empty($this->_valid_data)) { |
|
400 | - $this->_valid_data = $this->reg_form->valid_data(); |
|
401 | - } |
|
402 | - return $this->_valid_data; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @return string |
|
409 | - */ |
|
410 | - public function reg_form_name() |
|
411 | - { |
|
412 | - if (empty($this->_reg_form_name)) { |
|
413 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
414 | - } |
|
415 | - return $this->_reg_form_name; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @param string $reg_form_name |
|
422 | - */ |
|
423 | - protected function set_reg_form_name($reg_form_name) |
|
424 | - { |
|
425 | - $this->_reg_form_name = $reg_form_name; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * reg_step_url |
|
432 | - * |
|
433 | - * @param string $action |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - public function reg_step_url($action = '') |
|
437 | - { |
|
438 | - $query_args = array('step' => $this->slug()); |
|
439 | - if (! empty($action)) { |
|
440 | - $query_args['action'] = $action; |
|
441 | - } |
|
442 | - // final step has no display |
|
443 | - if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
444 | - $query_args['action'] = 'process_reg_step'; |
|
445 | - } |
|
446 | - if ($this->checkout->revisit) { |
|
447 | - $query_args['revisit'] = true; |
|
448 | - } |
|
449 | - if ($this->checkout->reg_url_link) { |
|
450 | - $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
451 | - } |
|
452 | - return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * creates the default hidden inputs section |
|
459 | - * |
|
460 | - * @return EE_Form_Section_Proper |
|
461 | - * @throws \EE_Error |
|
462 | - */ |
|
463 | - public function reg_step_hidden_inputs() |
|
464 | - { |
|
465 | - // hidden inputs for admin registrations |
|
466 | - if ($this->checkout->admin_request) { |
|
467 | - return new EE_Form_Section_Proper( |
|
468 | - array( |
|
469 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
470 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
471 | - 'subsections' => array( |
|
472 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
473 | - array( |
|
474 | - 'html_name' => 'next_step', |
|
475 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
476 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
477 | - ? $this->checkout->next_step->slug() |
|
478 | - : '', |
|
479 | - ) |
|
480 | - ), |
|
481 | - ), |
|
482 | - ) |
|
483 | - ); |
|
484 | - } |
|
485 | - // hidden inputs for frontend registrations |
|
486 | - return new EE_Form_Section_Proper( |
|
487 | - array( |
|
488 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
489 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
490 | - 'subsections' => array( |
|
491 | - 'action' => new EE_Fixed_Hidden_Input( |
|
492 | - array( |
|
493 | - 'html_name' => 'action', |
|
494 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
495 | - 'default' => apply_filters( |
|
496 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
497 | - empty($this->checkout->reg_url_link) |
|
498 | - ? 'process_reg_step' |
|
499 | - : 'update_reg_step', |
|
500 | - $this |
|
501 | - ), |
|
502 | - ) |
|
503 | - ), |
|
504 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
505 | - array( |
|
506 | - 'html_name' => 'next_step', |
|
507 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
508 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
509 | - ? $this->checkout->next_step->slug() |
|
510 | - : '', |
|
511 | - ) |
|
512 | - ), |
|
513 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
514 | - array( |
|
515 | - 'html_name' => 'e_reg_url_link', |
|
516 | - 'html_id' => 'spco-reg_url_link', |
|
517 | - 'default' => $this->checkout->reg_url_link, |
|
518 | - ) |
|
519 | - ), |
|
520 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
521 | - array( |
|
522 | - 'html_name' => 'revisit', |
|
523 | - 'html_id' => 'spco-revisit', |
|
524 | - 'default' => $this->checkout->revisit, |
|
525 | - ) |
|
526 | - ), |
|
527 | - ), |
|
528 | - ) |
|
529 | - ); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * generate_reg_form_for_actions |
|
536 | - * |
|
537 | - * @param array $actions |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public function generate_reg_form_for_actions($actions = array()) |
|
541 | - { |
|
542 | - $actions = array_merge( |
|
543 | - array( |
|
544 | - 'generate_reg_form', |
|
545 | - 'display_spco_reg_step', |
|
546 | - 'process_reg_step', |
|
547 | - 'update_reg_step', |
|
548 | - ), |
|
549 | - $actions |
|
550 | - ); |
|
551 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * @return string |
|
558 | - * @throws \EE_Error |
|
559 | - */ |
|
560 | - public function display_reg_form() |
|
561 | - { |
|
562 | - $html = ''; |
|
563 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
564 | - do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
565 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
566 | - if (EE_Registry::instance()->REQ->ajax) { |
|
567 | - $this->reg_form->localize_validation_rules(); |
|
568 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
569 | - } |
|
570 | - $html .= $this->reg_form->get_html(); |
|
571 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
572 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
573 | - } |
|
574 | - return $html; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
581 | - * |
|
582 | - * @return string |
|
583 | - * @throws \EE_Error |
|
584 | - */ |
|
585 | - public function reg_step_submit_button() |
|
586 | - { |
|
587 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | - return ''; |
|
589 | - } |
|
590 | - ob_start(); |
|
591 | - do_action( |
|
592 | - 'AHEE__before_spco_whats_next_buttons', |
|
593 | - $this->slug(), |
|
594 | - $this->checkout->next_step->slug(), |
|
595 | - $this->checkout |
|
596 | - ); |
|
597 | - $html = ob_get_clean(); |
|
598 | - // generate submit button |
|
599 | - $sbmt_btn = new EE_Submit_Input( |
|
600 | - array( |
|
601 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
603 | - 'html_class' => 'spco-next-step-btn', |
|
604 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
605 | - 'default' => $this->submit_button_text(), |
|
606 | - ) |
|
607 | - ); |
|
608 | - $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
609 | - $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
610 | - $html .= EEH_HTML::div( |
|
611 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
612 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
613 | - 'spco-whats-next-buttons' |
|
614 | - ); |
|
615 | - return $html; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
622 | - * |
|
623 | - * @return string |
|
624 | - */ |
|
625 | - public function div_class() |
|
626 | - { |
|
627 | - return $this->is_current_step() ? '' : ' hidden'; |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | - * |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function edit_lnk_url() |
|
638 | - { |
|
639 | - return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
646 | - * |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function edit_link_class() |
|
650 | - { |
|
651 | - return $this->is_current_step() ? ' hidden' : ''; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * update_checkout with changes that have been made to the cart |
|
658 | - * |
|
659 | - * @return void |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - public function update_checkout() |
|
663 | - { |
|
664 | - // grab the cart grand total and reset TXN total |
|
665 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
666 | - $this->checkout->stash_transaction_and_checkout(); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * __sleep |
|
675 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
676 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
677 | - * reg form, because if needed, it will be regenerated anyways |
|
678 | - * |
|
679 | - * @return array |
|
680 | - */ |
|
681 | - public function __sleep() |
|
682 | - { |
|
683 | - // remove the reg form and the checkout |
|
684 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
685 | - } |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function _instructions() |
|
364 | + { |
|
365 | + return $this->_instructions; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param string $instructions |
|
372 | + */ |
|
373 | + public function set_instructions($instructions) |
|
374 | + { |
|
375 | + $this->_instructions = apply_filters( |
|
376 | + 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
377 | + $instructions, |
|
378 | + $this |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @param array $valid_data |
|
386 | + */ |
|
387 | + public function set_valid_data($valid_data) |
|
388 | + { |
|
389 | + $this->_valid_data = $valid_data; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function valid_data() |
|
398 | + { |
|
399 | + if (empty($this->_valid_data)) { |
|
400 | + $this->_valid_data = $this->reg_form->valid_data(); |
|
401 | + } |
|
402 | + return $this->_valid_data; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @return string |
|
409 | + */ |
|
410 | + public function reg_form_name() |
|
411 | + { |
|
412 | + if (empty($this->_reg_form_name)) { |
|
413 | + $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
414 | + } |
|
415 | + return $this->_reg_form_name; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @param string $reg_form_name |
|
422 | + */ |
|
423 | + protected function set_reg_form_name($reg_form_name) |
|
424 | + { |
|
425 | + $this->_reg_form_name = $reg_form_name; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * reg_step_url |
|
432 | + * |
|
433 | + * @param string $action |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + public function reg_step_url($action = '') |
|
437 | + { |
|
438 | + $query_args = array('step' => $this->slug()); |
|
439 | + if (! empty($action)) { |
|
440 | + $query_args['action'] = $action; |
|
441 | + } |
|
442 | + // final step has no display |
|
443 | + if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
444 | + $query_args['action'] = 'process_reg_step'; |
|
445 | + } |
|
446 | + if ($this->checkout->revisit) { |
|
447 | + $query_args['revisit'] = true; |
|
448 | + } |
|
449 | + if ($this->checkout->reg_url_link) { |
|
450 | + $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
451 | + } |
|
452 | + return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * creates the default hidden inputs section |
|
459 | + * |
|
460 | + * @return EE_Form_Section_Proper |
|
461 | + * @throws \EE_Error |
|
462 | + */ |
|
463 | + public function reg_step_hidden_inputs() |
|
464 | + { |
|
465 | + // hidden inputs for admin registrations |
|
466 | + if ($this->checkout->admin_request) { |
|
467 | + return new EE_Form_Section_Proper( |
|
468 | + array( |
|
469 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
470 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
471 | + 'subsections' => array( |
|
472 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
473 | + array( |
|
474 | + 'html_name' => 'next_step', |
|
475 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
476 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
477 | + ? $this->checkout->next_step->slug() |
|
478 | + : '', |
|
479 | + ) |
|
480 | + ), |
|
481 | + ), |
|
482 | + ) |
|
483 | + ); |
|
484 | + } |
|
485 | + // hidden inputs for frontend registrations |
|
486 | + return new EE_Form_Section_Proper( |
|
487 | + array( |
|
488 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
489 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
490 | + 'subsections' => array( |
|
491 | + 'action' => new EE_Fixed_Hidden_Input( |
|
492 | + array( |
|
493 | + 'html_name' => 'action', |
|
494 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
495 | + 'default' => apply_filters( |
|
496 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
497 | + empty($this->checkout->reg_url_link) |
|
498 | + ? 'process_reg_step' |
|
499 | + : 'update_reg_step', |
|
500 | + $this |
|
501 | + ), |
|
502 | + ) |
|
503 | + ), |
|
504 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
505 | + array( |
|
506 | + 'html_name' => 'next_step', |
|
507 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
508 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
509 | + ? $this->checkout->next_step->slug() |
|
510 | + : '', |
|
511 | + ) |
|
512 | + ), |
|
513 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
514 | + array( |
|
515 | + 'html_name' => 'e_reg_url_link', |
|
516 | + 'html_id' => 'spco-reg_url_link', |
|
517 | + 'default' => $this->checkout->reg_url_link, |
|
518 | + ) |
|
519 | + ), |
|
520 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
521 | + array( |
|
522 | + 'html_name' => 'revisit', |
|
523 | + 'html_id' => 'spco-revisit', |
|
524 | + 'default' => $this->checkout->revisit, |
|
525 | + ) |
|
526 | + ), |
|
527 | + ), |
|
528 | + ) |
|
529 | + ); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * generate_reg_form_for_actions |
|
536 | + * |
|
537 | + * @param array $actions |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public function generate_reg_form_for_actions($actions = array()) |
|
541 | + { |
|
542 | + $actions = array_merge( |
|
543 | + array( |
|
544 | + 'generate_reg_form', |
|
545 | + 'display_spco_reg_step', |
|
546 | + 'process_reg_step', |
|
547 | + 'update_reg_step', |
|
548 | + ), |
|
549 | + $actions |
|
550 | + ); |
|
551 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * @return string |
|
558 | + * @throws \EE_Error |
|
559 | + */ |
|
560 | + public function display_reg_form() |
|
561 | + { |
|
562 | + $html = ''; |
|
563 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
564 | + do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
565 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
566 | + if (EE_Registry::instance()->REQ->ajax) { |
|
567 | + $this->reg_form->localize_validation_rules(); |
|
568 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
569 | + } |
|
570 | + $html .= $this->reg_form->get_html(); |
|
571 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
572 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
573 | + } |
|
574 | + return $html; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
581 | + * |
|
582 | + * @return string |
|
583 | + * @throws \EE_Error |
|
584 | + */ |
|
585 | + public function reg_step_submit_button() |
|
586 | + { |
|
587 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | + return ''; |
|
589 | + } |
|
590 | + ob_start(); |
|
591 | + do_action( |
|
592 | + 'AHEE__before_spco_whats_next_buttons', |
|
593 | + $this->slug(), |
|
594 | + $this->checkout->next_step->slug(), |
|
595 | + $this->checkout |
|
596 | + ); |
|
597 | + $html = ob_get_clean(); |
|
598 | + // generate submit button |
|
599 | + $sbmt_btn = new EE_Submit_Input( |
|
600 | + array( |
|
601 | + 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | + 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
603 | + 'html_class' => 'spco-next-step-btn', |
|
604 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
605 | + 'default' => $this->submit_button_text(), |
|
606 | + ) |
|
607 | + ); |
|
608 | + $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
609 | + $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
610 | + $html .= EEH_HTML::div( |
|
611 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
612 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
613 | + 'spco-whats-next-buttons' |
|
614 | + ); |
|
615 | + return $html; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
622 | + * |
|
623 | + * @return string |
|
624 | + */ |
|
625 | + public function div_class() |
|
626 | + { |
|
627 | + return $this->is_current_step() ? '' : ' hidden'; |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | + * |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function edit_lnk_url() |
|
638 | + { |
|
639 | + return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
646 | + * |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function edit_link_class() |
|
650 | + { |
|
651 | + return $this->is_current_step() ? ' hidden' : ''; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * update_checkout with changes that have been made to the cart |
|
658 | + * |
|
659 | + * @return void |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + public function update_checkout() |
|
663 | + { |
|
664 | + // grab the cart grand total and reset TXN total |
|
665 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
666 | + $this->checkout->stash_transaction_and_checkout(); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * __sleep |
|
675 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
676 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
677 | + * reg form, because if needed, it will be regenerated anyways |
|
678 | + * |
|
679 | + * @return array |
|
680 | + */ |
|
681 | + public function __sleep() |
|
682 | + { |
|
683 | + // remove the reg form and the checkout |
|
684 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
685 | + } |
|
686 | 686 | |
687 | 687 | |
688 | 688 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function set_submit_button_text($submit_button_text = '') |
240 | 240 | { |
241 | - if (! empty($submit_button_text)) { |
|
241 | + if ( ! empty($submit_button_text)) { |
|
242 | 242 | $this->_submit_button_text = $submit_button_text; |
243 | 243 | } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
244 | 244 | if ($this->checkout->revisit) { |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | public function reg_form_name() |
411 | 411 | { |
412 | 412 | if (empty($this->_reg_form_name)) { |
413 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
413 | + $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form'); |
|
414 | 414 | } |
415 | 415 | return $this->_reg_form_name; |
416 | 416 | } |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | public function reg_step_url($action = '') |
437 | 437 | { |
438 | 438 | $query_args = array('step' => $this->slug()); |
439 | - if (! empty($action)) { |
|
439 | + if ( ! empty($action)) { |
|
440 | 440 | $query_args['action'] = $action; |
441 | 441 | } |
442 | 442 | // final step has no display |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | return new EE_Form_Section_Proper( |
468 | 468 | array( |
469 | 469 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
470 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
470 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
471 | 471 | 'subsections' => array( |
472 | 472 | 'next_step' => new EE_Fixed_Hidden_Input( |
473 | 473 | array( |
474 | 474 | 'html_name' => 'next_step', |
475 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
475 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
476 | 476 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
477 | 477 | ? $this->checkout->next_step->slug() |
478 | 478 | : '', |
@@ -486,12 +486,12 @@ discard block |
||
486 | 486 | return new EE_Form_Section_Proper( |
487 | 487 | array( |
488 | 488 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
489 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
489 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
490 | 490 | 'subsections' => array( |
491 | 491 | 'action' => new EE_Fixed_Hidden_Input( |
492 | 492 | array( |
493 | 493 | 'html_name' => 'action', |
494 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
494 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
495 | 495 | 'default' => apply_filters( |
496 | 496 | 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
497 | 497 | empty($this->checkout->reg_url_link) |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | 'next_step' => new EE_Fixed_Hidden_Input( |
505 | 505 | array( |
506 | 506 | 'html_name' => 'next_step', |
507 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
507 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
508 | 508 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
509 | 509 | ? $this->checkout->next_step->slug() |
510 | 510 | : '', |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | */ |
585 | 585 | public function reg_step_submit_button() |
586 | 586 | { |
587 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
587 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
588 | 588 | return ''; |
589 | 589 | } |
590 | 590 | ob_start(); |
@@ -598,10 +598,10 @@ discard block |
||
598 | 598 | // generate submit button |
599 | 599 | $sbmt_btn = new EE_Submit_Input( |
600 | 600 | array( |
601 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
602 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
601 | + 'html_name' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
602 | + 'html_id' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
603 | 603 | 'html_class' => 'spco-next-step-btn', |
604 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
604 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
605 | 605 | 'default' => $this->submit_button_text(), |
606 | 606 | ) |
607 | 607 | ); |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
610 | 610 | $html .= EEH_HTML::div( |
611 | 611 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
612 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
612 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
613 | 613 | 'spco-whats-next-buttons' |
614 | 614 | ); |
615 | 615 | return $html; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | use InvalidArgumentException; |
20 | 20 | use WP_Post; |
21 | 21 | |
22 | -defined('EVENT_ESPRESSO_VERSION')|| exit('No direct script access allowed'); |
|
22 | +defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | } |
141 | 141 | } else { |
142 | 142 | $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
143 | - $dev_msg = $user_msg . __( |
|
143 | + $dev_msg = $user_msg.__( |
|
144 | 144 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
145 | 145 | 'event_espresso' |
146 | 146 | ); |
147 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
147 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | return true; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | // reset filter for displaying submit button |
209 | 209 | remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
210 | 210 | // poke and prod incoming event till it tells us what it is |
211 | - if (! $this->setEvent($event)) { |
|
211 | + if ( ! $this->setEvent($event)) { |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | // begin gathering template arguments by getting event status |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | return $this->noTicketAvailableMessage(); |
239 | 239 | } |
240 | 240 | // redirecting to another site for registration ?? |
241 | - $external_url = (string)$this->event->external_url(); |
|
241 | + $external_url = (string) $this->event->external_url(); |
|
242 | 242 | // if redirecting to another site for registration, then we don't load the TS |
243 | 243 | $ticket_selector = $external_url |
244 | 244 | ? $this->externalEventRegistration() |
245 | 245 | : $this->loadTicketSelector($tickets, $template_args); |
246 | 246 | // now set up the form (but not for the admin) |
247 | 247 | $ticket_selector = $this->display_full_ui() |
248 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
248 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
249 | 249 | : $ticket_selector; |
250 | 250 | // submit button and form close tag |
251 | 251 | $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | */ |
296 | 296 | protected function expiredEventMessage() |
297 | 297 | { |
298 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
298 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
299 | 299 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
300 | 300 | 'event_espresso' |
301 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
301 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | return ' |
331 | 331 | <div class="ee-event-expired-notice"> |
332 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
332 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
333 | 333 | </div><!-- .ee-event-expired-notice -->'; |
334 | 334 | } |
335 | 335 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
363 | 363 | ); |
364 | 364 | } |
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
365 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | |
@@ -430,9 +430,9 @@ discard block |
||
430 | 430 | * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
431 | 431 | * @param int $EVT_ID The Event ID |
432 | 432 | */ |
433 | - $template_args['anchor_id'] = apply_filters( |
|
433 | + $template_args['anchor_id'] = apply_filters( |
|
434 | 434 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
435 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
435 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
436 | 436 | $this->event->ID() |
437 | 437 | ); |
438 | 438 | $template_args['tickets'] = $tickets; |
@@ -523,8 +523,8 @@ discard block |
||
523 | 523 | // if redirecting, we don't need any anything else |
524 | 524 | if ($external_url) { |
525 | 525 | $html = '<form method="GET" '; |
526 | - $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
527 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
526 | + $html .= 'action="'.EEH_URL::refactor_url($external_url).'" '; |
|
527 | + $html .= 'name="ticket-selector-form-'.$ID.'"'; |
|
528 | 528 | // open link in new window ? |
529 | 529 | $html .= apply_filters( |
530 | 530 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -536,17 +536,17 @@ discard block |
||
536 | 536 | $html .= '>'; |
537 | 537 | $query_args = EEH_URL::get_query_string($external_url); |
538 | 538 | foreach ((array) $query_args as $query_arg => $value) { |
539 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
539 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
540 | 540 | } |
541 | 541 | return $html; |
542 | 542 | } |
543 | 543 | // if there is no submit button, then don't start building a form |
544 | 544 | // because the "View Details" button will build its own form |
545 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
545 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
546 | 546 | return ''; |
547 | 547 | } |
548 | 548 | $checkout_url = EEH_Event_View::event_link_url($ID); |
549 | - if (! $checkout_url) { |
|
549 | + if ( ! $checkout_url) { |
|
550 | 550 | EE_Error::add_error( |
551 | 551 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
552 | 552 | __FILE__, |
@@ -557,8 +557,8 @@ discard block |
||
557 | 557 | // set no cache headers and constants |
558 | 558 | EE_System::do_not_cache(); |
559 | 559 | $html = '<form method="POST" '; |
560 | - $html .= 'action="' . $checkout_url . '" '; |
|
561 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
560 | + $html .= 'action="'.$checkout_url.'" '; |
|
561 | + $html .= 'name="ticket-selector-form-'.$ID.'"'; |
|
562 | 562 | $html .= $this->iframe ? ' target="_blank"' : ''; |
563 | 563 | $html .= '>'; |
564 | 564 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $html .= empty($external_url) |
586 | 586 | ? $this->ticketSelectorEndDiv() |
587 | 587 | : $this->clearTicketSelector(); |
588 | - $html .= '<br/>' . $this->formClose(); |
|
588 | + $html .= '<br/>'.$this->formClose(); |
|
589 | 589 | } elseif ($this->getMaxAttendees() === 1) { |
590 | 590 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
591 | 591 | if ($this->event->is_sold_out()) { |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | // no submit or view details button, and no additional content |
644 | 644 | $html .= $this->ticketSelectorEndDiv(); |
645 | 645 | } |
646 | - if (! $this->iframe && ! is_archive()) { |
|
646 | + if ( ! $this->iframe && ! is_archive()) { |
|
647 | 647 | $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
648 | 648 | } |
649 | 649 | } |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | */ |
664 | 664 | public function displayRegisterNowButton() |
665 | 665 | { |
666 | - $btn_text = apply_filters( |
|
666 | + $btn_text = apply_filters( |
|
667 | 667 | 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
668 | 668 | __('Register Now', 'event_espresso'), |
669 | 669 | $this->event |
@@ -671,14 +671,14 @@ discard block |
||
671 | 671 | $external_url = $this->event->external_url(); |
672 | 672 | $html = EEH_HTML::div( |
673 | 673 | '', |
674 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
674 | + 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', |
|
675 | 675 | 'ticket-selector-submit-btn-wrap' |
676 | 676 | ); |
677 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
677 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
678 | 678 | $html .= ' class="ticket-selector-submit-btn '; |
679 | 679 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
680 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
681 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
680 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
681 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
682 | 682 | $html .= apply_filters( |
683 | 683 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
684 | 684 | '', |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | */ |
701 | 701 | public function displayViewDetailsButton($DWMTS = false) |
702 | 702 | { |
703 | - if (! $this->event->get_permalink()) { |
|
703 | + if ( ! $this->event->get_permalink()) { |
|
704 | 704 | EE_Error::add_error( |
705 | 705 | esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
706 | 706 | __FILE__, |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | ? ' target="_blank"' |
725 | 725 | : ''; |
726 | 726 | $view_details_btn .= '>'; |
727 | - $btn_text = apply_filters( |
|
727 | + $btn_text = apply_filters( |
|
728 | 728 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
729 | 729 | esc_html__('View Details', 'event_espresso'), |
730 | 730 | $this->event |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | */ |
755 | 755 | public function ticketSelectorEndDiv() |
756 | 756 | { |
757 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
757 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
758 | 758 | } |
759 | 759 | |
760 | 760 |
@@ -36,749 +36,749 @@ |
||
36 | 36 | class DisplayTicketSelector |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * event that ticket selector is being generated for |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @var EE_Event $event |
|
44 | - */ |
|
45 | - protected $event; |
|
46 | - |
|
47 | - /** |
|
48 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
49 | - * |
|
50 | - * @var bool $iframe |
|
51 | - */ |
|
52 | - protected $iframe = false; |
|
53 | - |
|
54 | - /** |
|
55 | - * max attendees that can register for event at one time |
|
56 | - * |
|
57 | - * @var int $max_attendees |
|
58 | - */ |
|
59 | - private $max_attendees = EE_INF; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string $date_format |
|
63 | - */ |
|
64 | - private $date_format; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $time_format |
|
68 | - */ |
|
69 | - private $time_format; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var boolean $display_full_ui |
|
73 | - */ |
|
74 | - private $display_full_ui; |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * DisplayTicketSelector constructor. |
|
80 | - * |
|
81 | - * @param bool $iframe |
|
82 | - */ |
|
83 | - public function __construct($iframe = false) |
|
84 | - { |
|
85 | - $this->iframe = $iframe; |
|
86 | - $this->date_format = apply_filters( |
|
87 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
88 | - get_option('date_format') |
|
89 | - ); |
|
90 | - $this->time_format = apply_filters( |
|
91 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
92 | - get_option('time_format') |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function isIframe() |
|
101 | - { |
|
102 | - return $this->iframe; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param boolean $iframe |
|
109 | - */ |
|
110 | - public function setIframe($iframe = true) |
|
111 | - { |
|
112 | - $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * finds and sets the \EE_Event object for use throughout class |
|
118 | - * |
|
119 | - * @param mixed $event |
|
120 | - * @return bool |
|
121 | - * @throws EE_Error |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws InvalidInterfaceException |
|
124 | - * @throws InvalidArgumentException |
|
125 | - */ |
|
126 | - protected function setEvent($event = null) |
|
127 | - { |
|
128 | - if ($event === null) { |
|
129 | - global $post; |
|
130 | - $event = $post; |
|
131 | - } |
|
132 | - if ($event instanceof EE_Event) { |
|
133 | - $this->event = $event; |
|
134 | - } elseif ($event instanceof WP_Post) { |
|
135 | - if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
136 | - $this->event = $event->EE_Event; |
|
137 | - } elseif ($event->post_type === 'espresso_events') { |
|
138 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
139 | - $this->event = $event->EE_Event; |
|
140 | - } |
|
141 | - } else { |
|
142 | - $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
143 | - $dev_msg = $user_msg . __( |
|
144 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
145 | - 'event_espresso' |
|
146 | - ); |
|
147 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | - return false; |
|
149 | - } |
|
150 | - return true; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return int |
|
157 | - */ |
|
158 | - public function getMaxAttendees() |
|
159 | - { |
|
160 | - return $this->max_attendees; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param int $max_attendees |
|
167 | - */ |
|
168 | - public function setMaxAttendees($max_attendees) |
|
169 | - { |
|
170 | - $this->max_attendees = absint( |
|
171 | - apply_filters( |
|
172 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
173 | - $max_attendees |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns whether or not the full ticket selector should be shown or not. |
|
182 | - * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - private function display_full_ui() |
|
187 | - { |
|
188 | - if ($this->display_full_ui === null) { |
|
189 | - $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
190 | - } |
|
191 | - return $this->display_full_ui; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * creates buttons for selecting number of attendees for an event |
|
197 | - * |
|
198 | - * @param WP_Post|int $event |
|
199 | - * @param bool $view_details |
|
200 | - * @return string |
|
201 | - * @throws EE_Error |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws InvalidDataTypeException |
|
204 | - * @throws InvalidInterfaceException |
|
205 | - */ |
|
206 | - public function display($event = null, $view_details = false) |
|
207 | - { |
|
208 | - // reset filter for displaying submit button |
|
209 | - remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
210 | - // poke and prod incoming event till it tells us what it is |
|
211 | - if (! $this->setEvent($event)) { |
|
212 | - return false; |
|
213 | - } |
|
214 | - // begin gathering template arguments by getting event status |
|
215 | - $template_args = array('event_status' => $this->event->get_active_status()); |
|
216 | - if ( |
|
217 | - $this->activeEventAndShowTicketSelector( |
|
218 | - $event, |
|
219 | - $template_args['event_status'], |
|
220 | - $view_details |
|
221 | - ) |
|
222 | - ) { |
|
223 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
224 | - } |
|
225 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
226 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
227 | - if ($this->getMaxAttendees() < 1) { |
|
228 | - return $this->ticketSalesClosedMessage(); |
|
229 | - } |
|
230 | - // is the event expired ? |
|
231 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
232 | - if ($template_args['event_is_expired']) { |
|
233 | - return $this->expiredEventMessage(); |
|
234 | - } |
|
235 | - // get all tickets for this event ordered by the datetime |
|
236 | - $tickets = $this->getTickets(); |
|
237 | - if (count($tickets) < 1) { |
|
238 | - return $this->noTicketAvailableMessage(); |
|
239 | - } |
|
240 | - // redirecting to another site for registration ?? |
|
241 | - $external_url = (string)$this->event->external_url(); |
|
242 | - // if redirecting to another site for registration, then we don't load the TS |
|
243 | - $ticket_selector = $external_url |
|
244 | - ? $this->externalEventRegistration() |
|
245 | - : $this->loadTicketSelector($tickets, $template_args); |
|
246 | - // now set up the form (but not for the admin) |
|
247 | - $ticket_selector = $this->display_full_ui() |
|
248 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
249 | - : $ticket_selector; |
|
250 | - // submit button and form close tag |
|
251 | - $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
252 | - return $ticket_selector; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * displayTicketSelector |
|
259 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
260 | - * |
|
261 | - * @param WP_Post|int $event |
|
262 | - * @param string $_event_active_status |
|
263 | - * @param bool $view_details |
|
264 | - * @return bool |
|
265 | - * @throws EE_Error |
|
266 | - */ |
|
267 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
268 | - { |
|
269 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
270 | - return $this->display_full_ui() |
|
271 | - && ( |
|
272 | - ! $this->event->display_ticket_selector() |
|
273 | - || $view_details |
|
274 | - || post_password_required($event_post) |
|
275 | - || ( |
|
276 | - $_event_active_status !== EE_Datetime::active |
|
277 | - && $_event_active_status !== EE_Datetime::upcoming |
|
278 | - && $_event_active_status !== EE_Datetime::sold_out |
|
279 | - && ! ( |
|
280 | - $_event_active_status === EE_Datetime::inactive |
|
281 | - && is_user_logged_in() |
|
282 | - ) |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * noTicketAvailableMessage |
|
291 | - * notice displayed if event is expired |
|
292 | - * |
|
293 | - * @return string |
|
294 | - * @throws EE_Error |
|
295 | - */ |
|
296 | - protected function expiredEventMessage() |
|
297 | - { |
|
298 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
299 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
300 | - 'event_espresso' |
|
301 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * noTicketAvailableMessage |
|
308 | - * notice displayed if event has no more tickets available |
|
309 | - * |
|
310 | - * @return string |
|
311 | - * @throws EE_Error |
|
312 | - */ |
|
313 | - protected function noTicketAvailableMessage() |
|
314 | - { |
|
315 | - $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
316 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
317 | - $no_ticket_available_msg .= sprintf( |
|
318 | - esc_html__( |
|
319 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
320 | - 'event_espresso' |
|
321 | - ), |
|
322 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
323 | - '</b><br />', |
|
324 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
325 | - . get_edit_post_link($this->event->ID()) |
|
326 | - . '">', |
|
327 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
328 | - ); |
|
329 | - } |
|
330 | - return ' |
|
39 | + /** |
|
40 | + * event that ticket selector is being generated for |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @var EE_Event $event |
|
44 | + */ |
|
45 | + protected $event; |
|
46 | + |
|
47 | + /** |
|
48 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
49 | + * |
|
50 | + * @var bool $iframe |
|
51 | + */ |
|
52 | + protected $iframe = false; |
|
53 | + |
|
54 | + /** |
|
55 | + * max attendees that can register for event at one time |
|
56 | + * |
|
57 | + * @var int $max_attendees |
|
58 | + */ |
|
59 | + private $max_attendees = EE_INF; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string $date_format |
|
63 | + */ |
|
64 | + private $date_format; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $time_format |
|
68 | + */ |
|
69 | + private $time_format; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var boolean $display_full_ui |
|
73 | + */ |
|
74 | + private $display_full_ui; |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * DisplayTicketSelector constructor. |
|
80 | + * |
|
81 | + * @param bool $iframe |
|
82 | + */ |
|
83 | + public function __construct($iframe = false) |
|
84 | + { |
|
85 | + $this->iframe = $iframe; |
|
86 | + $this->date_format = apply_filters( |
|
87 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
88 | + get_option('date_format') |
|
89 | + ); |
|
90 | + $this->time_format = apply_filters( |
|
91 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
92 | + get_option('time_format') |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function isIframe() |
|
101 | + { |
|
102 | + return $this->iframe; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param boolean $iframe |
|
109 | + */ |
|
110 | + public function setIframe($iframe = true) |
|
111 | + { |
|
112 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * finds and sets the \EE_Event object for use throughout class |
|
118 | + * |
|
119 | + * @param mixed $event |
|
120 | + * @return bool |
|
121 | + * @throws EE_Error |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws InvalidInterfaceException |
|
124 | + * @throws InvalidArgumentException |
|
125 | + */ |
|
126 | + protected function setEvent($event = null) |
|
127 | + { |
|
128 | + if ($event === null) { |
|
129 | + global $post; |
|
130 | + $event = $post; |
|
131 | + } |
|
132 | + if ($event instanceof EE_Event) { |
|
133 | + $this->event = $event; |
|
134 | + } elseif ($event instanceof WP_Post) { |
|
135 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
136 | + $this->event = $event->EE_Event; |
|
137 | + } elseif ($event->post_type === 'espresso_events') { |
|
138 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
139 | + $this->event = $event->EE_Event; |
|
140 | + } |
|
141 | + } else { |
|
142 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
143 | + $dev_msg = $user_msg . __( |
|
144 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
145 | + 'event_espresso' |
|
146 | + ); |
|
147 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | + return false; |
|
149 | + } |
|
150 | + return true; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return int |
|
157 | + */ |
|
158 | + public function getMaxAttendees() |
|
159 | + { |
|
160 | + return $this->max_attendees; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param int $max_attendees |
|
167 | + */ |
|
168 | + public function setMaxAttendees($max_attendees) |
|
169 | + { |
|
170 | + $this->max_attendees = absint( |
|
171 | + apply_filters( |
|
172 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
173 | + $max_attendees |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns whether or not the full ticket selector should be shown or not. |
|
182 | + * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + private function display_full_ui() |
|
187 | + { |
|
188 | + if ($this->display_full_ui === null) { |
|
189 | + $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
190 | + } |
|
191 | + return $this->display_full_ui; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * creates buttons for selecting number of attendees for an event |
|
197 | + * |
|
198 | + * @param WP_Post|int $event |
|
199 | + * @param bool $view_details |
|
200 | + * @return string |
|
201 | + * @throws EE_Error |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws InvalidDataTypeException |
|
204 | + * @throws InvalidInterfaceException |
|
205 | + */ |
|
206 | + public function display($event = null, $view_details = false) |
|
207 | + { |
|
208 | + // reset filter for displaying submit button |
|
209 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
210 | + // poke and prod incoming event till it tells us what it is |
|
211 | + if (! $this->setEvent($event)) { |
|
212 | + return false; |
|
213 | + } |
|
214 | + // begin gathering template arguments by getting event status |
|
215 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
216 | + if ( |
|
217 | + $this->activeEventAndShowTicketSelector( |
|
218 | + $event, |
|
219 | + $template_args['event_status'], |
|
220 | + $view_details |
|
221 | + ) |
|
222 | + ) { |
|
223 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
224 | + } |
|
225 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
226 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
227 | + if ($this->getMaxAttendees() < 1) { |
|
228 | + return $this->ticketSalesClosedMessage(); |
|
229 | + } |
|
230 | + // is the event expired ? |
|
231 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
232 | + if ($template_args['event_is_expired']) { |
|
233 | + return $this->expiredEventMessage(); |
|
234 | + } |
|
235 | + // get all tickets for this event ordered by the datetime |
|
236 | + $tickets = $this->getTickets(); |
|
237 | + if (count($tickets) < 1) { |
|
238 | + return $this->noTicketAvailableMessage(); |
|
239 | + } |
|
240 | + // redirecting to another site for registration ?? |
|
241 | + $external_url = (string)$this->event->external_url(); |
|
242 | + // if redirecting to another site for registration, then we don't load the TS |
|
243 | + $ticket_selector = $external_url |
|
244 | + ? $this->externalEventRegistration() |
|
245 | + : $this->loadTicketSelector($tickets, $template_args); |
|
246 | + // now set up the form (but not for the admin) |
|
247 | + $ticket_selector = $this->display_full_ui() |
|
248 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
249 | + : $ticket_selector; |
|
250 | + // submit button and form close tag |
|
251 | + $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
252 | + return $ticket_selector; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * displayTicketSelector |
|
259 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
260 | + * |
|
261 | + * @param WP_Post|int $event |
|
262 | + * @param string $_event_active_status |
|
263 | + * @param bool $view_details |
|
264 | + * @return bool |
|
265 | + * @throws EE_Error |
|
266 | + */ |
|
267 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
268 | + { |
|
269 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
270 | + return $this->display_full_ui() |
|
271 | + && ( |
|
272 | + ! $this->event->display_ticket_selector() |
|
273 | + || $view_details |
|
274 | + || post_password_required($event_post) |
|
275 | + || ( |
|
276 | + $_event_active_status !== EE_Datetime::active |
|
277 | + && $_event_active_status !== EE_Datetime::upcoming |
|
278 | + && $_event_active_status !== EE_Datetime::sold_out |
|
279 | + && ! ( |
|
280 | + $_event_active_status === EE_Datetime::inactive |
|
281 | + && is_user_logged_in() |
|
282 | + ) |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * noTicketAvailableMessage |
|
291 | + * notice displayed if event is expired |
|
292 | + * |
|
293 | + * @return string |
|
294 | + * @throws EE_Error |
|
295 | + */ |
|
296 | + protected function expiredEventMessage() |
|
297 | + { |
|
298 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
299 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
300 | + 'event_espresso' |
|
301 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * noTicketAvailableMessage |
|
308 | + * notice displayed if event has no more tickets available |
|
309 | + * |
|
310 | + * @return string |
|
311 | + * @throws EE_Error |
|
312 | + */ |
|
313 | + protected function noTicketAvailableMessage() |
|
314 | + { |
|
315 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
316 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
317 | + $no_ticket_available_msg .= sprintf( |
|
318 | + esc_html__( |
|
319 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
320 | + 'event_espresso' |
|
321 | + ), |
|
322 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
323 | + '</b><br />', |
|
324 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
325 | + . get_edit_post_link($this->event->ID()) |
|
326 | + . '">', |
|
327 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
328 | + ); |
|
329 | + } |
|
330 | + return ' |
|
331 | 331 | <div class="ee-event-expired-notice"> |
332 | 332 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
333 | 333 | </div><!-- .ee-event-expired-notice -->'; |
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * ticketSalesClosed |
|
340 | - * notice displayed if event ticket sales are turned off |
|
341 | - * |
|
342 | - * @return string |
|
343 | - * @throws EE_Error |
|
344 | - */ |
|
345 | - protected function ticketSalesClosedMessage() |
|
346 | - { |
|
347 | - $sales_closed_msg = esc_html__( |
|
348 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
349 | - 'event_espresso' |
|
350 | - ); |
|
351 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
352 | - $sales_closed_msg .= sprintf( |
|
353 | - esc_html__( |
|
354 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
355 | - 'event_espresso' |
|
356 | - ), |
|
357 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | - '</b><br />', |
|
359 | - '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | - . get_edit_post_link($this->event->ID()) |
|
361 | - . '">', |
|
362 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
363 | - ); |
|
364 | - } |
|
365 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * getTickets |
|
372 | - * |
|
373 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
374 | - * @throws EE_Error |
|
375 | - * @throws InvalidDataTypeException |
|
376 | - * @throws InvalidInterfaceException |
|
377 | - * @throws InvalidArgumentException |
|
378 | - */ |
|
379 | - protected function getTickets() |
|
380 | - { |
|
381 | - $ticket_query_args = array( |
|
382 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
383 | - 'order_by' => array( |
|
384 | - 'TKT_order' => 'ASC', |
|
385 | - 'TKT_required' => 'DESC', |
|
386 | - 'TKT_start_date' => 'ASC', |
|
387 | - 'TKT_end_date' => 'ASC', |
|
388 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
389 | - ), |
|
390 | - ); |
|
391 | - if ( |
|
392 | - ! ( |
|
393 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
394 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
395 | - ) |
|
396 | - ) { |
|
397 | - //use the correct applicable time query depending on what version of core is being run. |
|
398 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
399 | - ? time() |
|
400 | - : current_time('timestamp'); |
|
401 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
402 | - } |
|
403 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * loadTicketSelector |
|
410 | - * begins to assemble template arguments |
|
411 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
412 | - * |
|
413 | - * @param \EE_Ticket[] $tickets |
|
414 | - * @param array $template_args |
|
415 | - * @return string |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
419 | - { |
|
420 | - $template_args['event'] = $this->event; |
|
421 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
422 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
423 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
424 | - $template_args['date_format'] = $this->date_format; |
|
425 | - $template_args['time_format'] = $this->time_format; |
|
426 | - /** |
|
427 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
428 | - * |
|
429 | - * @since 4.9.13 |
|
430 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
431 | - * @param int $EVT_ID The Event ID |
|
432 | - */ |
|
433 | - $template_args['anchor_id'] = apply_filters( |
|
434 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
435 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
436 | - $this->event->ID() |
|
437 | - ); |
|
438 | - $template_args['tickets'] = $tickets; |
|
439 | - $template_args['ticket_count'] = count($tickets); |
|
440 | - $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
441 | - return $ticket_selector instanceof TicketSelectorSimple |
|
442 | - ? $ticket_selector |
|
443 | - : new TicketSelectorStandard( |
|
444 | - $this->event, |
|
445 | - $tickets, |
|
446 | - $this->getMaxAttendees(), |
|
447 | - $template_args, |
|
448 | - $this->date_format, |
|
449 | - $this->time_format |
|
450 | - ); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * simpleTicketSelector |
|
457 | - * there's one ticket, and max attendees is set to one, |
|
458 | - * so if the event is free, then this is a "simple" ticket selector |
|
459 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
460 | - * |
|
461 | - * @param \EE_Ticket[] $tickets |
|
462 | - * @param array $template_args |
|
463 | - * @return string |
|
464 | - * @throws EE_Error |
|
465 | - */ |
|
466 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
467 | - { |
|
468 | - // if there is only ONE ticket with a max qty of ONE |
|
469 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
470 | - return ''; |
|
471 | - } |
|
472 | - /** @var \EE_Ticket $ticket */ |
|
473 | - $ticket = reset($tickets); |
|
474 | - // if the ticket is free... then not much need for the ticket selector |
|
475 | - if ( |
|
476 | - apply_filters( |
|
477 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
478 | - $ticket->is_free(), |
|
479 | - $this->event->ID() |
|
480 | - ) |
|
481 | - ) { |
|
482 | - return new TicketSelectorSimple( |
|
483 | - $this->event, |
|
484 | - $ticket, |
|
485 | - $this->getMaxAttendees(), |
|
486 | - $template_args |
|
487 | - ); |
|
488 | - } |
|
489 | - return ''; |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * externalEventRegistration |
|
496 | - * |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - public function externalEventRegistration() |
|
500 | - { |
|
501 | - // if not we still need to trigger the display of the submit button |
|
502 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
503 | - //display notice to admin that registration is external |
|
504 | - return $this->display_full_ui() |
|
505 | - ? esc_html__( |
|
506 | - 'Registration is at an external URL for this event.', |
|
507 | - 'event_espresso' |
|
508 | - ) |
|
509 | - : ''; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * formOpen |
|
516 | - * |
|
517 | - * @param int $ID |
|
518 | - * @param string $external_url |
|
519 | - * @return string |
|
520 | - */ |
|
521 | - public function formOpen($ID = 0, $external_url = '') |
|
522 | - { |
|
523 | - // if redirecting, we don't need any anything else |
|
524 | - if ($external_url) { |
|
525 | - $html = '<form method="GET" '; |
|
526 | - $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
527 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
528 | - // open link in new window ? |
|
529 | - $html .= apply_filters( |
|
530 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
531 | - $this->isIframe(), |
|
532 | - $this |
|
533 | - ) |
|
534 | - ? ' target="_blank"' |
|
535 | - : ''; |
|
536 | - $html .= '>'; |
|
537 | - $query_args = EEH_URL::get_query_string($external_url); |
|
538 | - foreach ((array) $query_args as $query_arg => $value) { |
|
539 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
540 | - } |
|
541 | - return $html; |
|
542 | - } |
|
543 | - // if there is no submit button, then don't start building a form |
|
544 | - // because the "View Details" button will build its own form |
|
545 | - if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
546 | - return ''; |
|
547 | - } |
|
548 | - $checkout_url = EEH_Event_View::event_link_url($ID); |
|
549 | - if (! $checkout_url) { |
|
550 | - EE_Error::add_error( |
|
551 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
552 | - __FILE__, |
|
553 | - __FUNCTION__, |
|
554 | - __LINE__ |
|
555 | - ); |
|
556 | - } |
|
557 | - // set no cache headers and constants |
|
558 | - EE_System::do_not_cache(); |
|
559 | - $html = '<form method="POST" '; |
|
560 | - $html .= 'action="' . $checkout_url . '" '; |
|
561 | - $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
562 | - $html .= $this->iframe ? ' target="_blank"' : ''; |
|
563 | - $html .= '>'; |
|
564 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
565 | - $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
566 | - return $html; |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * displaySubmitButton |
|
573 | - * |
|
574 | - * @param string $external_url |
|
575 | - * @return string |
|
576 | - * @throws EE_Error |
|
577 | - */ |
|
578 | - public function displaySubmitButton($external_url = '') |
|
579 | - { |
|
580 | - $html = ''; |
|
581 | - if ($this->display_full_ui()) { |
|
582 | - // standard TS displayed with submit button, ie: "Register Now" |
|
583 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
584 | - $html .= $this->displayRegisterNowButton(); |
|
585 | - $html .= empty($external_url) |
|
586 | - ? $this->ticketSelectorEndDiv() |
|
587 | - : $this->clearTicketSelector(); |
|
588 | - $html .= '<br/>' . $this->formClose(); |
|
589 | - } elseif ($this->getMaxAttendees() === 1) { |
|
590 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
591 | - if ($this->event->is_sold_out()) { |
|
592 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
593 | - $html .= apply_filters( |
|
594 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
595 | - sprintf( |
|
596 | - __( |
|
597 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
598 | - 'event_espresso' |
|
599 | - ), |
|
600 | - '<p class="no-ticket-selector-msg clear-float">', |
|
601 | - $this->event->name(), |
|
602 | - '</p>', |
|
603 | - '<br />' |
|
604 | - ), |
|
605 | - $this->event |
|
606 | - ); |
|
607 | - if ( |
|
608 | - apply_filters( |
|
609 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
610 | - false, |
|
611 | - $this->event |
|
612 | - ) |
|
613 | - ) { |
|
614 | - $html .= $this->displayRegisterNowButton(); |
|
615 | - } |
|
616 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
617 | - $html .= $this->ticketSelectorEndDiv(); |
|
618 | - } elseif ( |
|
619 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
620 | - && ! is_single() |
|
621 | - ) { |
|
622 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
623 | - // but no tickets are available, so display event's "View Details" button. |
|
624 | - // it is being viewed via somewhere other than a single post |
|
625 | - $html .= $this->displayViewDetailsButton(true); |
|
626 | - } else { |
|
627 | - $html .= $this->ticketSelectorEndDiv(); |
|
628 | - } |
|
629 | - } elseif (is_archive()) { |
|
630 | - // event list, no tickets available so display event's "View Details" button |
|
631 | - $html .= $this->ticketSelectorEndDiv(); |
|
632 | - $html .= $this->displayViewDetailsButton(); |
|
633 | - } else { |
|
634 | - if ( |
|
635 | - apply_filters( |
|
636 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
637 | - false, |
|
638 | - $this->event |
|
639 | - ) |
|
640 | - ) { |
|
641 | - $html .= $this->displayRegisterNowButton(); |
|
642 | - } |
|
643 | - // no submit or view details button, and no additional content |
|
644 | - $html .= $this->ticketSelectorEndDiv(); |
|
645 | - } |
|
646 | - if (! $this->iframe && ! is_archive()) { |
|
647 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
648 | - } |
|
649 | - } |
|
650 | - return apply_filters( |
|
651 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
652 | - $html, |
|
653 | - $this->event, |
|
654 | - $this |
|
655 | - ); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * @return string |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function displayRegisterNowButton() |
|
665 | - { |
|
666 | - $btn_text = apply_filters( |
|
667 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
668 | - __('Register Now', 'event_espresso'), |
|
669 | - $this->event |
|
670 | - ); |
|
671 | - $external_url = $this->event->external_url(); |
|
672 | - $html = EEH_HTML::div( |
|
673 | - '', |
|
674 | - 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
675 | - 'ticket-selector-submit-btn-wrap' |
|
676 | - ); |
|
677 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
678 | - $html .= ' class="ticket-selector-submit-btn '; |
|
679 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
680 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
681 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
682 | - $html .= apply_filters( |
|
683 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
684 | - '', |
|
685 | - $this->event, |
|
686 | - $this->iframe |
|
687 | - ); |
|
688 | - return $html; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * displayViewDetailsButton |
|
694 | - * |
|
695 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
696 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
697 | - * either because they are sold out, expired, or not yet on sale. |
|
698 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
699 | - * @return string |
|
700 | - * @throws EE_Error |
|
701 | - */ |
|
702 | - public function displayViewDetailsButton($DWMTS = false) |
|
703 | - { |
|
704 | - if (! $this->event->get_permalink()) { |
|
705 | - EE_Error::add_error( |
|
706 | - esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
707 | - __FILE__, |
|
708 | - __FUNCTION__, |
|
709 | - __LINE__ |
|
710 | - ); |
|
711 | - } |
|
712 | - $view_details_btn = '<form method="POST" action="'; |
|
713 | - $view_details_btn .= apply_filters( |
|
714 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
715 | - $this->event->get_permalink(), |
|
716 | - $this->event |
|
717 | - ); |
|
718 | - $view_details_btn .= '"'; |
|
719 | - // open link in new window ? |
|
720 | - $view_details_btn .= apply_filters( |
|
721 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
722 | - $this->isIframe(), |
|
723 | - $this |
|
724 | - ) |
|
725 | - ? ' target="_blank"' |
|
726 | - : ''; |
|
727 | - $view_details_btn .= '>'; |
|
728 | - $btn_text = apply_filters( |
|
729 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
730 | - esc_html__('View Details', 'event_espresso'), |
|
731 | - $this->event |
|
732 | - ); |
|
733 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
734 | - . $this->event->ID() |
|
735 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
736 | - . $btn_text |
|
737 | - . '" />'; |
|
738 | - $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
739 | - if ($DWMTS) { |
|
740 | - $view_details_btn .= $this->formClose(); |
|
741 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
742 | - $view_details_btn .= '<br/>'; |
|
743 | - } else { |
|
744 | - $view_details_btn .= $this->clearTicketSelector(); |
|
745 | - $view_details_btn .= '<br/>'; |
|
746 | - $view_details_btn .= $this->formClose(); |
|
747 | - } |
|
748 | - return $view_details_btn; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * @return string |
|
755 | - */ |
|
756 | - public function ticketSelectorEndDiv() |
|
757 | - { |
|
758 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * @return string |
|
765 | - */ |
|
766 | - public function clearTicketSelector() |
|
767 | - { |
|
768 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
769 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * @access public |
|
776 | - * @return string |
|
777 | - */ |
|
778 | - public function formClose() |
|
779 | - { |
|
780 | - return '</form>'; |
|
781 | - } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * ticketSalesClosed |
|
340 | + * notice displayed if event ticket sales are turned off |
|
341 | + * |
|
342 | + * @return string |
|
343 | + * @throws EE_Error |
|
344 | + */ |
|
345 | + protected function ticketSalesClosedMessage() |
|
346 | + { |
|
347 | + $sales_closed_msg = esc_html__( |
|
348 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
349 | + 'event_espresso' |
|
350 | + ); |
|
351 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
352 | + $sales_closed_msg .= sprintf( |
|
353 | + esc_html__( |
|
354 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
355 | + 'event_espresso' |
|
356 | + ), |
|
357 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
358 | + '</b><br />', |
|
359 | + '<span class="edit-link"><a class="post-edit-link" href="' |
|
360 | + . get_edit_post_link($this->event->ID()) |
|
361 | + . '">', |
|
362 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
363 | + ); |
|
364 | + } |
|
365 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * getTickets |
|
372 | + * |
|
373 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
374 | + * @throws EE_Error |
|
375 | + * @throws InvalidDataTypeException |
|
376 | + * @throws InvalidInterfaceException |
|
377 | + * @throws InvalidArgumentException |
|
378 | + */ |
|
379 | + protected function getTickets() |
|
380 | + { |
|
381 | + $ticket_query_args = array( |
|
382 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
383 | + 'order_by' => array( |
|
384 | + 'TKT_order' => 'ASC', |
|
385 | + 'TKT_required' => 'DESC', |
|
386 | + 'TKT_start_date' => 'ASC', |
|
387 | + 'TKT_end_date' => 'ASC', |
|
388 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
389 | + ), |
|
390 | + ); |
|
391 | + if ( |
|
392 | + ! ( |
|
393 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
394 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
395 | + ) |
|
396 | + ) { |
|
397 | + //use the correct applicable time query depending on what version of core is being run. |
|
398 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
399 | + ? time() |
|
400 | + : current_time('timestamp'); |
|
401 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
402 | + } |
|
403 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * loadTicketSelector |
|
410 | + * begins to assemble template arguments |
|
411 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
412 | + * |
|
413 | + * @param \EE_Ticket[] $tickets |
|
414 | + * @param array $template_args |
|
415 | + * @return string |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
419 | + { |
|
420 | + $template_args['event'] = $this->event; |
|
421 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
422 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
423 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
424 | + $template_args['date_format'] = $this->date_format; |
|
425 | + $template_args['time_format'] = $this->time_format; |
|
426 | + /** |
|
427 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
428 | + * |
|
429 | + * @since 4.9.13 |
|
430 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
431 | + * @param int $EVT_ID The Event ID |
|
432 | + */ |
|
433 | + $template_args['anchor_id'] = apply_filters( |
|
434 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
435 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
436 | + $this->event->ID() |
|
437 | + ); |
|
438 | + $template_args['tickets'] = $tickets; |
|
439 | + $template_args['ticket_count'] = count($tickets); |
|
440 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
441 | + return $ticket_selector instanceof TicketSelectorSimple |
|
442 | + ? $ticket_selector |
|
443 | + : new TicketSelectorStandard( |
|
444 | + $this->event, |
|
445 | + $tickets, |
|
446 | + $this->getMaxAttendees(), |
|
447 | + $template_args, |
|
448 | + $this->date_format, |
|
449 | + $this->time_format |
|
450 | + ); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * simpleTicketSelector |
|
457 | + * there's one ticket, and max attendees is set to one, |
|
458 | + * so if the event is free, then this is a "simple" ticket selector |
|
459 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
460 | + * |
|
461 | + * @param \EE_Ticket[] $tickets |
|
462 | + * @param array $template_args |
|
463 | + * @return string |
|
464 | + * @throws EE_Error |
|
465 | + */ |
|
466 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
467 | + { |
|
468 | + // if there is only ONE ticket with a max qty of ONE |
|
469 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
470 | + return ''; |
|
471 | + } |
|
472 | + /** @var \EE_Ticket $ticket */ |
|
473 | + $ticket = reset($tickets); |
|
474 | + // if the ticket is free... then not much need for the ticket selector |
|
475 | + if ( |
|
476 | + apply_filters( |
|
477 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
478 | + $ticket->is_free(), |
|
479 | + $this->event->ID() |
|
480 | + ) |
|
481 | + ) { |
|
482 | + return new TicketSelectorSimple( |
|
483 | + $this->event, |
|
484 | + $ticket, |
|
485 | + $this->getMaxAttendees(), |
|
486 | + $template_args |
|
487 | + ); |
|
488 | + } |
|
489 | + return ''; |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * externalEventRegistration |
|
496 | + * |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + public function externalEventRegistration() |
|
500 | + { |
|
501 | + // if not we still need to trigger the display of the submit button |
|
502 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
503 | + //display notice to admin that registration is external |
|
504 | + return $this->display_full_ui() |
|
505 | + ? esc_html__( |
|
506 | + 'Registration is at an external URL for this event.', |
|
507 | + 'event_espresso' |
|
508 | + ) |
|
509 | + : ''; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * formOpen |
|
516 | + * |
|
517 | + * @param int $ID |
|
518 | + * @param string $external_url |
|
519 | + * @return string |
|
520 | + */ |
|
521 | + public function formOpen($ID = 0, $external_url = '') |
|
522 | + { |
|
523 | + // if redirecting, we don't need any anything else |
|
524 | + if ($external_url) { |
|
525 | + $html = '<form method="GET" '; |
|
526 | + $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" '; |
|
527 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
528 | + // open link in new window ? |
|
529 | + $html .= apply_filters( |
|
530 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
531 | + $this->isIframe(), |
|
532 | + $this |
|
533 | + ) |
|
534 | + ? ' target="_blank"' |
|
535 | + : ''; |
|
536 | + $html .= '>'; |
|
537 | + $query_args = EEH_URL::get_query_string($external_url); |
|
538 | + foreach ((array) $query_args as $query_arg => $value) { |
|
539 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
540 | + } |
|
541 | + return $html; |
|
542 | + } |
|
543 | + // if there is no submit button, then don't start building a form |
|
544 | + // because the "View Details" button will build its own form |
|
545 | + if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
546 | + return ''; |
|
547 | + } |
|
548 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
549 | + if (! $checkout_url) { |
|
550 | + EE_Error::add_error( |
|
551 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
552 | + __FILE__, |
|
553 | + __FUNCTION__, |
|
554 | + __LINE__ |
|
555 | + ); |
|
556 | + } |
|
557 | + // set no cache headers and constants |
|
558 | + EE_System::do_not_cache(); |
|
559 | + $html = '<form method="POST" '; |
|
560 | + $html .= 'action="' . $checkout_url . '" '; |
|
561 | + $html .= 'name="ticket-selector-form-' . $ID . '"'; |
|
562 | + $html .= $this->iframe ? ' target="_blank"' : ''; |
|
563 | + $html .= '>'; |
|
564 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
565 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
566 | + return $html; |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * displaySubmitButton |
|
573 | + * |
|
574 | + * @param string $external_url |
|
575 | + * @return string |
|
576 | + * @throws EE_Error |
|
577 | + */ |
|
578 | + public function displaySubmitButton($external_url = '') |
|
579 | + { |
|
580 | + $html = ''; |
|
581 | + if ($this->display_full_ui()) { |
|
582 | + // standard TS displayed with submit button, ie: "Register Now" |
|
583 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
584 | + $html .= $this->displayRegisterNowButton(); |
|
585 | + $html .= empty($external_url) |
|
586 | + ? $this->ticketSelectorEndDiv() |
|
587 | + : $this->clearTicketSelector(); |
|
588 | + $html .= '<br/>' . $this->formClose(); |
|
589 | + } elseif ($this->getMaxAttendees() === 1) { |
|
590 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
591 | + if ($this->event->is_sold_out()) { |
|
592 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
593 | + $html .= apply_filters( |
|
594 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
595 | + sprintf( |
|
596 | + __( |
|
597 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
598 | + 'event_espresso' |
|
599 | + ), |
|
600 | + '<p class="no-ticket-selector-msg clear-float">', |
|
601 | + $this->event->name(), |
|
602 | + '</p>', |
|
603 | + '<br />' |
|
604 | + ), |
|
605 | + $this->event |
|
606 | + ); |
|
607 | + if ( |
|
608 | + apply_filters( |
|
609 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
610 | + false, |
|
611 | + $this->event |
|
612 | + ) |
|
613 | + ) { |
|
614 | + $html .= $this->displayRegisterNowButton(); |
|
615 | + } |
|
616 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
617 | + $html .= $this->ticketSelectorEndDiv(); |
|
618 | + } elseif ( |
|
619 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
620 | + && ! is_single() |
|
621 | + ) { |
|
622 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
623 | + // but no tickets are available, so display event's "View Details" button. |
|
624 | + // it is being viewed via somewhere other than a single post |
|
625 | + $html .= $this->displayViewDetailsButton(true); |
|
626 | + } else { |
|
627 | + $html .= $this->ticketSelectorEndDiv(); |
|
628 | + } |
|
629 | + } elseif (is_archive()) { |
|
630 | + // event list, no tickets available so display event's "View Details" button |
|
631 | + $html .= $this->ticketSelectorEndDiv(); |
|
632 | + $html .= $this->displayViewDetailsButton(); |
|
633 | + } else { |
|
634 | + if ( |
|
635 | + apply_filters( |
|
636 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
637 | + false, |
|
638 | + $this->event |
|
639 | + ) |
|
640 | + ) { |
|
641 | + $html .= $this->displayRegisterNowButton(); |
|
642 | + } |
|
643 | + // no submit or view details button, and no additional content |
|
644 | + $html .= $this->ticketSelectorEndDiv(); |
|
645 | + } |
|
646 | + if (! $this->iframe && ! is_archive()) { |
|
647 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
648 | + } |
|
649 | + } |
|
650 | + return apply_filters( |
|
651 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
652 | + $html, |
|
653 | + $this->event, |
|
654 | + $this |
|
655 | + ); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * @return string |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function displayRegisterNowButton() |
|
665 | + { |
|
666 | + $btn_text = apply_filters( |
|
667 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
668 | + __('Register Now', 'event_espresso'), |
|
669 | + $this->event |
|
670 | + ); |
|
671 | + $external_url = $this->event->external_url(); |
|
672 | + $html = EEH_HTML::div( |
|
673 | + '', |
|
674 | + 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', |
|
675 | + 'ticket-selector-submit-btn-wrap' |
|
676 | + ); |
|
677 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
678 | + $html .= ' class="ticket-selector-submit-btn '; |
|
679 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
680 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
681 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
682 | + $html .= apply_filters( |
|
683 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
684 | + '', |
|
685 | + $this->event, |
|
686 | + $this->iframe |
|
687 | + ); |
|
688 | + return $html; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * displayViewDetailsButton |
|
694 | + * |
|
695 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
696 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
697 | + * either because they are sold out, expired, or not yet on sale. |
|
698 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
699 | + * @return string |
|
700 | + * @throws EE_Error |
|
701 | + */ |
|
702 | + public function displayViewDetailsButton($DWMTS = false) |
|
703 | + { |
|
704 | + if (! $this->event->get_permalink()) { |
|
705 | + EE_Error::add_error( |
|
706 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
707 | + __FILE__, |
|
708 | + __FUNCTION__, |
|
709 | + __LINE__ |
|
710 | + ); |
|
711 | + } |
|
712 | + $view_details_btn = '<form method="POST" action="'; |
|
713 | + $view_details_btn .= apply_filters( |
|
714 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
715 | + $this->event->get_permalink(), |
|
716 | + $this->event |
|
717 | + ); |
|
718 | + $view_details_btn .= '"'; |
|
719 | + // open link in new window ? |
|
720 | + $view_details_btn .= apply_filters( |
|
721 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
722 | + $this->isIframe(), |
|
723 | + $this |
|
724 | + ) |
|
725 | + ? ' target="_blank"' |
|
726 | + : ''; |
|
727 | + $view_details_btn .= '>'; |
|
728 | + $btn_text = apply_filters( |
|
729 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
730 | + esc_html__('View Details', 'event_espresso'), |
|
731 | + $this->event |
|
732 | + ); |
|
733 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
734 | + . $this->event->ID() |
|
735 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
736 | + . $btn_text |
|
737 | + . '" />'; |
|
738 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
739 | + if ($DWMTS) { |
|
740 | + $view_details_btn .= $this->formClose(); |
|
741 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
742 | + $view_details_btn .= '<br/>'; |
|
743 | + } else { |
|
744 | + $view_details_btn .= $this->clearTicketSelector(); |
|
745 | + $view_details_btn .= '<br/>'; |
|
746 | + $view_details_btn .= $this->formClose(); |
|
747 | + } |
|
748 | + return $view_details_btn; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * @return string |
|
755 | + */ |
|
756 | + public function ticketSelectorEndDiv() |
|
757 | + { |
|
758 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * @return string |
|
765 | + */ |
|
766 | + public function clearTicketSelector() |
|
767 | + { |
|
768 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
769 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * @access public |
|
776 | + * @return string |
|
777 | + */ |
|
778 | + public function formClose() |
|
779 | + { |
|
780 | + return '</form>'; |
|
781 | + } |
|
782 | 782 | |
783 | 783 | |
784 | 784 |
@@ -14,262 +14,262 @@ |
||
14 | 14 | class EEH_URL |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * _add_query_arg |
|
19 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
20 | - * |
|
21 | - * @access public |
|
22 | - * @param array $args |
|
23 | - * @param string $url |
|
24 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
28 | - { |
|
29 | - if (empty($url)) { |
|
30 | - $user_msg = esc_html__( |
|
31 | - 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
32 | - 'event_espresso' |
|
33 | - ); |
|
34 | - $dev_msg = $user_msg . "\n" |
|
35 | - . sprintf( |
|
36 | - esc_html__( |
|
37 | - 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
38 | - 'event_espresso' |
|
39 | - ), |
|
40 | - __CLASS__ . '::add_query_args_and_nonce' |
|
41 | - ); |
|
42 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
43 | - } |
|
44 | - // check that an action exists and add nonce |
|
45 | - if (! $exclude_nonce) { |
|
46 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
47 | - $args = array_merge( |
|
48 | - $args, |
|
49 | - array( |
|
50 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
51 | - ) |
|
52 | - ); |
|
53 | - } else { |
|
54 | - $args = array_merge( |
|
55 | - $args, |
|
56 | - array( |
|
57 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
61 | - } |
|
17 | + /** |
|
18 | + * _add_query_arg |
|
19 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
20 | + * |
|
21 | + * @access public |
|
22 | + * @param array $args |
|
23 | + * @param string $url |
|
24 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
28 | + { |
|
29 | + if (empty($url)) { |
|
30 | + $user_msg = esc_html__( |
|
31 | + 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
32 | + 'event_espresso' |
|
33 | + ); |
|
34 | + $dev_msg = $user_msg . "\n" |
|
35 | + . sprintf( |
|
36 | + esc_html__( |
|
37 | + 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
38 | + 'event_espresso' |
|
39 | + ), |
|
40 | + __CLASS__ . '::add_query_args_and_nonce' |
|
41 | + ); |
|
42 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
43 | + } |
|
44 | + // check that an action exists and add nonce |
|
45 | + if (! $exclude_nonce) { |
|
46 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
47 | + $args = array_merge( |
|
48 | + $args, |
|
49 | + array( |
|
50 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
51 | + ) |
|
52 | + ); |
|
53 | + } else { |
|
54 | + $args = array_merge( |
|
55 | + $args, |
|
56 | + array( |
|
57 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - //finally, let's always add a return address (if present) :) |
|
64 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
65 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
66 | - : $args; |
|
63 | + //finally, let's always add a return address (if present) :) |
|
64 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
65 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
66 | + : $args; |
|
67 | 67 | |
68 | - return add_query_arg($args, $url); |
|
69 | - } |
|
68 | + return add_query_arg($args, $url); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Returns whether not the remote file exists. |
|
74 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
75 | - * |
|
76 | - * @param string $url |
|
77 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
78 | - * @return boolean |
|
79 | - */ |
|
80 | - public static function remote_file_exists($url, $args = array()) |
|
81 | - { |
|
82 | - $results = wp_remote_request( |
|
83 | - $url, |
|
84 | - array_merge( |
|
85 | - array( |
|
86 | - 'method' => 'GET', |
|
87 | - 'redirection' => 1, |
|
88 | - ), |
|
89 | - $args |
|
90 | - ) |
|
91 | - ); |
|
92 | - if (! $results instanceof WP_Error && |
|
93 | - isset($results['response']) && |
|
94 | - isset($results['response']['code']) && |
|
95 | - $results['response']['code'] == '200') { |
|
96 | - return true; |
|
97 | - } else { |
|
98 | - return false; |
|
99 | - } |
|
100 | - } |
|
72 | + /** |
|
73 | + * Returns whether not the remote file exists. |
|
74 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
75 | + * |
|
76 | + * @param string $url |
|
77 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
78 | + * @return boolean |
|
79 | + */ |
|
80 | + public static function remote_file_exists($url, $args = array()) |
|
81 | + { |
|
82 | + $results = wp_remote_request( |
|
83 | + $url, |
|
84 | + array_merge( |
|
85 | + array( |
|
86 | + 'method' => 'GET', |
|
87 | + 'redirection' => 1, |
|
88 | + ), |
|
89 | + $args |
|
90 | + ) |
|
91 | + ); |
|
92 | + if (! $results instanceof WP_Error && |
|
93 | + isset($results['response']) && |
|
94 | + isset($results['response']['code']) && |
|
95 | + $results['response']['code'] == '200') { |
|
96 | + return true; |
|
97 | + } else { |
|
98 | + return false; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * refactor_url |
|
105 | - * primarily used for removing the query string from a URL |
|
106 | - * |
|
107 | - * @param string $url |
|
108 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
109 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
113 | - { |
|
114 | - // break apart incoming URL |
|
115 | - $url_bits = parse_url($url); |
|
116 | - // HTTP or HTTPS ? |
|
117 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
118 | - // domain |
|
119 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
120 | - // if only the base URL is requested, then return that now |
|
121 | - if ($base_url_only) { |
|
122 | - return $scheme . $host; |
|
123 | - } |
|
124 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
125 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
126 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
127 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
128 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
129 | - // if the query string is not required, then return what we have so far |
|
130 | - if ($remove_query) { |
|
131 | - return $scheme . $user . $pass . $host . $port . $path; |
|
132 | - } |
|
133 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
134 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
135 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
136 | - } |
|
103 | + /** |
|
104 | + * refactor_url |
|
105 | + * primarily used for removing the query string from a URL |
|
106 | + * |
|
107 | + * @param string $url |
|
108 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
109 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
113 | + { |
|
114 | + // break apart incoming URL |
|
115 | + $url_bits = parse_url($url); |
|
116 | + // HTTP or HTTPS ? |
|
117 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
118 | + // domain |
|
119 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
120 | + // if only the base URL is requested, then return that now |
|
121 | + if ($base_url_only) { |
|
122 | + return $scheme . $host; |
|
123 | + } |
|
124 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
125 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
126 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
127 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
128 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
129 | + // if the query string is not required, then return what we have so far |
|
130 | + if ($remove_query) { |
|
131 | + return $scheme . $user . $pass . $host . $port . $path; |
|
132 | + } |
|
133 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
134 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
135 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * get_query_string |
|
141 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
142 | - * |
|
143 | - * @param string $url |
|
144 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
145 | - * simply return the query string |
|
146 | - * @return string|array |
|
147 | - */ |
|
148 | - public static function get_query_string($url = '', $as_array = true) |
|
149 | - { |
|
150 | - // decode, then break apart incoming URL |
|
151 | - $url_bits = parse_url(html_entity_decode($url)); |
|
152 | - // grab query string from URL |
|
153 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
154 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
155 | - if (! $as_array) { |
|
156 | - return $query; |
|
157 | - } |
|
158 | - // if no query string exists then just return an empty array now |
|
159 | - if (empty($query)) { |
|
160 | - return array(); |
|
161 | - } |
|
162 | - // empty array to hold results |
|
163 | - $query_params = array(); |
|
164 | - // now break apart the query string into separate params |
|
165 | - $query = explode('&', $query); |
|
166 | - // loop thru our query params |
|
167 | - foreach ($query as $query_args) { |
|
168 | - // break apart the key value pairs |
|
169 | - $query_args = explode('=', $query_args); |
|
170 | - // and add to our results array |
|
171 | - $query_params[$query_args[0]] = $query_args[1]; |
|
172 | - } |
|
173 | - return $query_params; |
|
174 | - } |
|
139 | + /** |
|
140 | + * get_query_string |
|
141 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
142 | + * |
|
143 | + * @param string $url |
|
144 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
145 | + * simply return the query string |
|
146 | + * @return string|array |
|
147 | + */ |
|
148 | + public static function get_query_string($url = '', $as_array = true) |
|
149 | + { |
|
150 | + // decode, then break apart incoming URL |
|
151 | + $url_bits = parse_url(html_entity_decode($url)); |
|
152 | + // grab query string from URL |
|
153 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
154 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
155 | + if (! $as_array) { |
|
156 | + return $query; |
|
157 | + } |
|
158 | + // if no query string exists then just return an empty array now |
|
159 | + if (empty($query)) { |
|
160 | + return array(); |
|
161 | + } |
|
162 | + // empty array to hold results |
|
163 | + $query_params = array(); |
|
164 | + // now break apart the query string into separate params |
|
165 | + $query = explode('&', $query); |
|
166 | + // loop thru our query params |
|
167 | + foreach ($query as $query_args) { |
|
168 | + // break apart the key value pairs |
|
169 | + $query_args = explode('=', $query_args); |
|
170 | + // and add to our results array |
|
171 | + $query_params[$query_args[0]] = $query_args[1]; |
|
172 | + } |
|
173 | + return $query_params; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * prevent_prefetching |
|
179 | - * |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public static function prevent_prefetching() |
|
183 | - { |
|
184 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
185 | - // with the registration process |
|
186 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
187 | - } |
|
177 | + /** |
|
178 | + * prevent_prefetching |
|
179 | + * |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public static function prevent_prefetching() |
|
183 | + { |
|
184 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
185 | + // with the registration process |
|
186 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * This generates a unique site-specific string. |
|
192 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
193 | - * urls. |
|
194 | - * |
|
195 | - * @param string $prefix Use this to prefix the string with something. |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public static function generate_unique_token($prefix = '') |
|
199 | - { |
|
200 | - $token = md5(uniqid() . mt_rand()); |
|
201 | - return $prefix ? $prefix . '_' . $token : $token; |
|
202 | - } |
|
190 | + /** |
|
191 | + * This generates a unique site-specific string. |
|
192 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
193 | + * urls. |
|
194 | + * |
|
195 | + * @param string $prefix Use this to prefix the string with something. |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public static function generate_unique_token($prefix = '') |
|
199 | + { |
|
200 | + $token = md5(uniqid() . mt_rand()); |
|
201 | + return $prefix ? $prefix . '_' . $token : $token; |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - /** |
|
206 | - * filter_input_server_url |
|
207 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
208 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
209 | - * |
|
210 | - * @param string $server_variable |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
214 | - { |
|
215 | - $URL = ''; |
|
216 | - $server_variables = array( |
|
217 | - 'REQUEST_URI' => 1, |
|
218 | - 'HTTP_HOST' => 1, |
|
219 | - 'PHP_SELF' => 1, |
|
220 | - ); |
|
221 | - $server_variable = strtoupper($server_variable); |
|
222 | - // whitelist INPUT_SERVER var |
|
223 | - if (isset($server_variables[$server_variable])) { |
|
224 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
225 | - if (empty($URL)) { |
|
226 | - // fallback sanitization if the above fails |
|
227 | - $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
228 | - } |
|
229 | - } |
|
230 | - return $URL; |
|
231 | - } |
|
205 | + /** |
|
206 | + * filter_input_server_url |
|
207 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
208 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
209 | + * |
|
210 | + * @param string $server_variable |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
214 | + { |
|
215 | + $URL = ''; |
|
216 | + $server_variables = array( |
|
217 | + 'REQUEST_URI' => 1, |
|
218 | + 'HTTP_HOST' => 1, |
|
219 | + 'PHP_SELF' => 1, |
|
220 | + ); |
|
221 | + $server_variable = strtoupper($server_variable); |
|
222 | + // whitelist INPUT_SERVER var |
|
223 | + if (isset($server_variables[$server_variable])) { |
|
224 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
225 | + if (empty($URL)) { |
|
226 | + // fallback sanitization if the above fails |
|
227 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
228 | + } |
|
229 | + } |
|
230 | + return $URL; |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Gets the current page's full URL. |
|
236 | - * |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public static function current_url() |
|
240 | - { |
|
241 | - $url = ''; |
|
242 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
243 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
244 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
245 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
246 | - } |
|
247 | - return $url; |
|
248 | - } |
|
234 | + /** |
|
235 | + * Gets the current page's full URL. |
|
236 | + * |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public static function current_url() |
|
240 | + { |
|
241 | + $url = ''; |
|
242 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
243 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
244 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
245 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
246 | + } |
|
247 | + return $url; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
253 | - * |
|
254 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
255 | - * @since 4.9.46.rc.029 |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
259 | - { |
|
260 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
261 | - } |
|
251 | + /** |
|
252 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
253 | + * |
|
254 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
255 | + * @since 4.9.46.rc.029 |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
259 | + { |
|
260 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * @param string $location |
|
266 | - * @param int $status |
|
267 | - * @param string $exit_notice |
|
268 | - */ |
|
269 | - public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
270 | - { |
|
271 | - EE_Error::get_notices(false, true); |
|
272 | - wp_safe_redirect($location, $status); |
|
273 | - exit($exit_notice); |
|
274 | - } |
|
264 | + /** |
|
265 | + * @param string $location |
|
266 | + * @param int $status |
|
267 | + * @param string $exit_notice |
|
268 | + */ |
|
269 | + public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
270 | + { |
|
271 | + EE_Error::get_notices(false, true); |
|
272 | + wp_safe_redirect($location, $status); |
|
273 | + exit($exit_notice); |
|
274 | + } |
|
275 | 275 | } |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | class EE_Invisible_Recaptcha_Display_Strategy extends EE_Display_Strategy_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @return EE_Form_Input_Base|EE_Invisible_Recaptcha_Input |
|
23 | - */ |
|
24 | - public function input() |
|
25 | - { |
|
26 | - return $this->_input; |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * returns HTML and javascript related to the displaying of this input |
|
32 | - * |
|
33 | - * @return string |
|
34 | - * @throws InvalidInterfaceException |
|
35 | - * @throws InvalidDataTypeException |
|
36 | - * @throws InvalidArgumentException |
|
37 | - */ |
|
38 | - public function display() |
|
39 | - { |
|
40 | - wp_enqueue_script(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA); |
|
41 | - return <<<EOD |
|
21 | + /** |
|
22 | + * @return EE_Form_Input_Base|EE_Invisible_Recaptcha_Input |
|
23 | + */ |
|
24 | + public function input() |
|
25 | + { |
|
26 | + return $this->_input; |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * returns HTML and javascript related to the displaying of this input |
|
32 | + * |
|
33 | + * @return string |
|
34 | + * @throws InvalidInterfaceException |
|
35 | + * @throws InvalidDataTypeException |
|
36 | + * @throws InvalidArgumentException |
|
37 | + */ |
|
38 | + public function display() |
|
39 | + { |
|
40 | + wp_enqueue_script(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA); |
|
41 | + return <<<EOD |
|
42 | 42 | <div id="g-recaptcha-{$this->input()->recaptchaId()}" |
43 | 43 | class="g-recaptcha" |
44 | 44 | data-sitekey="{$this->input()->siteKey()}" |
@@ -48,5 +48,5 @@ discard block |
||
48 | 48 | > |
49 | 49 | </div> |
50 | 50 | EOD; |
51 | - } |
|
51 | + } |
|
52 | 52 | } |
@@ -14,138 +14,138 @@ |
||
14 | 14 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * opening div tag for a form |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function layout_form_begin() |
|
23 | - { |
|
24 | - return EEH_HTML::div( |
|
25 | - '', |
|
26 | - $this->_form_section->html_id(), |
|
27 | - $this->_form_section->html_class(), |
|
28 | - $this->_form_section->html_style() |
|
29 | - ); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Lays out the row for the input, including label and errors |
|
36 | - * |
|
37 | - * @param EE_Form_Input_Base $input |
|
38 | - * @return string |
|
39 | - * @throws \EE_Error |
|
40 | - */ |
|
41 | - public function layout_input($input) |
|
42 | - { |
|
43 | - $html = ''; |
|
44 | - // set something unique for the id |
|
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
47 | - : spl_object_hash($input); |
|
48 | - // and add a generic input type class |
|
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | - if ($input instanceof EE_Hidden_Input) { |
|
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | - } else if ($input instanceof EE_Submit_Input) { |
|
53 | - $html .= EEH_HTML::div( |
|
54 | - $input->get_html_for_input(), |
|
55 | - $html_id . '-submit-dv', |
|
56 | - "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | - ); |
|
58 | - } else if ($input instanceof EE_Select_Input) { |
|
59 | - $html .= EEH_HTML::div( |
|
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
65 | - "{$input->html_class()}-input-dv {$html_class}" |
|
66 | - ); |
|
67 | - } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | - $html .= EEH_HTML::div( |
|
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
74 | - "{$input->html_class()}-input-dv {$html_class}" |
|
75 | - ); |
|
76 | - } else { |
|
77 | - $html .= EEH_HTML::div( |
|
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
83 | - "{$input->html_class()}-input-dv {$html_class}" |
|
84 | - ); |
|
85 | - } |
|
86 | - return $html; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * |
|
93 | - * _display_label_for_option_type_question |
|
94 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | - * should be for each input) |
|
96 | - * |
|
97 | - * @param EE_Form_Input_With_Options_Base $input |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | - { |
|
102 | - if ($input->display_html_label_text()) { |
|
103 | - $html_label_text = $input->html_label_text(); |
|
104 | - $label_html = EEH_HTML::div( |
|
105 | - $input->required() |
|
106 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
107 | - : $html_label_text, |
|
108 | - $input->html_label_id(), |
|
109 | - $input->required() |
|
110 | - ? 'ee-required-label ' . $input->html_label_class() |
|
111 | - : $input->html_label_class(), |
|
112 | - $input->html_label_style(), |
|
113 | - $input->html_other_attributes() |
|
114 | - ); |
|
115 | - // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
116 | - // then we need to close the div manually |
|
117 | - if(empty($html_label_text)){ |
|
118 | - $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
119 | - } |
|
120 | - return $label_html; |
|
121 | - } |
|
122 | - return ''; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Lays out a row for the subsection |
|
129 | - * |
|
130 | - * @param EE_Form_Section_Proper $form_section |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function layout_subsection($form_section) |
|
134 | - { |
|
135 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * closing div tag for a form |
|
142 | - * |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function layout_form_end() |
|
146 | - { |
|
147 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
148 | - } |
|
17 | + /** |
|
18 | + * opening div tag for a form |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function layout_form_begin() |
|
23 | + { |
|
24 | + return EEH_HTML::div( |
|
25 | + '', |
|
26 | + $this->_form_section->html_id(), |
|
27 | + $this->_form_section->html_class(), |
|
28 | + $this->_form_section->html_style() |
|
29 | + ); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Lays out the row for the input, including label and errors |
|
36 | + * |
|
37 | + * @param EE_Form_Input_Base $input |
|
38 | + * @return string |
|
39 | + * @throws \EE_Error |
|
40 | + */ |
|
41 | + public function layout_input($input) |
|
42 | + { |
|
43 | + $html = ''; |
|
44 | + // set something unique for the id |
|
45 | + $html_id = (string)$input->html_id() !== '' |
|
46 | + ? (string)$input->html_id() |
|
47 | + : spl_object_hash($input); |
|
48 | + // and add a generic input type class |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | + if ($input instanceof EE_Hidden_Input) { |
|
51 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | + } else if ($input instanceof EE_Submit_Input) { |
|
53 | + $html .= EEH_HTML::div( |
|
54 | + $input->get_html_for_input(), |
|
55 | + $html_id . '-submit-dv', |
|
56 | + "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | + ); |
|
58 | + } else if ($input instanceof EE_Select_Input) { |
|
59 | + $html .= EEH_HTML::div( |
|
60 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | + $html_id . '-input-dv', |
|
65 | + "{$input->html_class()}-input-dv {$html_class}" |
|
66 | + ); |
|
67 | + } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | + $html .= EEH_HTML::div( |
|
69 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | + $html_id . '-input-dv', |
|
74 | + "{$input->html_class()}-input-dv {$html_class}" |
|
75 | + ); |
|
76 | + } else { |
|
77 | + $html .= EEH_HTML::div( |
|
78 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | + $html_id . '-input-dv', |
|
83 | + "{$input->html_class()}-input-dv {$html_class}" |
|
84 | + ); |
|
85 | + } |
|
86 | + return $html; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * |
|
93 | + * _display_label_for_option_type_question |
|
94 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | + * should be for each input) |
|
96 | + * |
|
97 | + * @param EE_Form_Input_With_Options_Base $input |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | + { |
|
102 | + if ($input->display_html_label_text()) { |
|
103 | + $html_label_text = $input->html_label_text(); |
|
104 | + $label_html = EEH_HTML::div( |
|
105 | + $input->required() |
|
106 | + ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
107 | + : $html_label_text, |
|
108 | + $input->html_label_id(), |
|
109 | + $input->required() |
|
110 | + ? 'ee-required-label ' . $input->html_label_class() |
|
111 | + : $input->html_label_class(), |
|
112 | + $input->html_label_style(), |
|
113 | + $input->html_other_attributes() |
|
114 | + ); |
|
115 | + // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
116 | + // then we need to close the div manually |
|
117 | + if(empty($html_label_text)){ |
|
118 | + $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
119 | + } |
|
120 | + return $label_html; |
|
121 | + } |
|
122 | + return ''; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Lays out a row for the subsection |
|
129 | + * |
|
130 | + * @param EE_Form_Section_Proper $form_section |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function layout_subsection($form_section) |
|
134 | + { |
|
135 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * closing div tag for a form |
|
142 | + * |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function layout_form_end() |
|
146 | + { |
|
147 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
148 | + } |
|
149 | 149 | |
150 | 150 | |
151 | 151 |
@@ -42,44 +42,44 @@ discard block |
||
42 | 42 | { |
43 | 43 | $html = ''; |
44 | 44 | // set something unique for the id |
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
45 | + $html_id = (string) $input->html_id() !== '' |
|
46 | + ? (string) $input->html_id() |
|
47 | 47 | : spl_object_hash($input); |
48 | 48 | // and add a generic input type class |
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv'; |
|
50 | 50 | if ($input instanceof EE_Hidden_Input) { |
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
51 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
52 | 52 | } else if ($input instanceof EE_Submit_Input) { |
53 | 53 | $html .= EEH_HTML::div( |
54 | 54 | $input->get_html_for_input(), |
55 | - $html_id . '-submit-dv', |
|
55 | + $html_id.'-submit-dv', |
|
56 | 56 | "{$input->html_class()}-submit-dv {$html_class}" |
57 | 57 | ); |
58 | 58 | } else if ($input instanceof EE_Select_Input) { |
59 | 59 | $html .= EEH_HTML::div( |
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
60 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
61 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
62 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
63 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
64 | + $html_id.'-input-dv', |
|
65 | 65 | "{$input->html_class()}-input-dv {$html_class}" |
66 | 66 | ); |
67 | 67 | } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
68 | 68 | $html .= EEH_HTML::div( |
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
69 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
70 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
71 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
72 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
73 | + $html_id.'-input-dv', |
|
74 | 74 | "{$input->html_class()}-input-dv {$html_class}" |
75 | 75 | ); |
76 | 76 | } else { |
77 | 77 | $html .= EEH_HTML::div( |
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
78 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
79 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
80 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
81 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
82 | + $html_id.'-input-dv', |
|
83 | 83 | "{$input->html_class()}-input-dv {$html_class}" |
84 | 84 | ); |
85 | 85 | } |
@@ -103,18 +103,18 @@ discard block |
||
103 | 103 | $html_label_text = $input->html_label_text(); |
104 | 104 | $label_html = EEH_HTML::div( |
105 | 105 | $input->required() |
106 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | + ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk') |
|
107 | 107 | : $html_label_text, |
108 | 108 | $input->html_label_id(), |
109 | 109 | $input->required() |
110 | - ? 'ee-required-label ' . $input->html_label_class() |
|
110 | + ? 'ee-required-label '.$input->html_label_class() |
|
111 | 111 | : $input->html_label_class(), |
112 | 112 | $input->html_label_style(), |
113 | 113 | $input->html_other_attributes() |
114 | 114 | ); |
115 | 115 | // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
116 | 116 | // then we need to close the div manually |
117 | - if(empty($html_label_text)){ |
|
117 | + if (empty($html_label_text)) { |
|
118 | 118 | $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
119 | 119 | } |
120 | 120 | return $label_html; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function layout_subsection($form_section) |
134 | 134 | { |
135 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
135 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -21,485 +21,485 @@ discard block |
||
21 | 21 | abstract class EE_Form_Section_Base |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * the URL the form is submitted to |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $_action; |
|
30 | - |
|
31 | - /** |
|
32 | - * POST (default) or GET |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_method; |
|
37 | - |
|
38 | - /** |
|
39 | - * html_id and html_name are derived from this by default |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $_name; |
|
44 | - |
|
45 | - /** |
|
46 | - * $_html_id |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_html_id; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_html_class |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - protected $_html_class; |
|
56 | - |
|
57 | - /** |
|
58 | - * $_html_style |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $_html_style; |
|
62 | - |
|
63 | - /** |
|
64 | - * $_other_html_attributes |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $_other_html_attributes; |
|
68 | - |
|
69 | - /** |
|
70 | - * The form section of which this form section is a part |
|
71 | - * |
|
72 | - * @var EE_Form_Section_Proper |
|
73 | - */ |
|
74 | - protected $_parent_section; |
|
75 | - |
|
76 | - /** |
|
77 | - * flag indicating that _construct_finalize has been called. |
|
78 | - * If it has not been called and we try to use functions which require it, we call it |
|
79 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
80 | - * |
|
81 | - * @var boolean |
|
82 | - */ |
|
83 | - protected $_construction_finalized; |
|
84 | - |
|
85 | - /** |
|
86 | - * Strategy for parsing the form HTML upon display |
|
87 | - * |
|
88 | - * @var FormHtmlFilter |
|
89 | - */ |
|
90 | - protected $_form_html_filter; |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param array $options_array { |
|
95 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
96 | - * } |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - */ |
|
99 | - public function __construct($options_array = array()) |
|
100 | - { |
|
101 | - // used by display strategies |
|
102 | - // assign incoming values to properties |
|
103 | - foreach ($options_array as $key => $value) { |
|
104 | - $key = '_' . $key; |
|
105 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
106 | - $this->{$key} = $value; |
|
107 | - if($key === '_subsections' && ! is_array($value)) { |
|
108 | - throw new InvalidDataTypeException($key, $value, 'array'); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - // set parser which allows the form section's rendered HTML to be filtered |
|
113 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
114 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param $parent_form_section |
|
122 | - * @param $name |
|
123 | - * @throws \EE_Error |
|
124 | - */ |
|
125 | - protected function _construct_finalize($parent_form_section, $name) |
|
126 | - { |
|
127 | - $this->_construction_finalized = true; |
|
128 | - $this->_parent_section = $parent_form_section; |
|
129 | - if ($name !== null) { |
|
130 | - $this->_name = $name; |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * make sure construction finalized was called, otherwise children might not be ready |
|
138 | - * |
|
139 | - * @return void |
|
140 | - * @throws \EE_Error |
|
141 | - */ |
|
142 | - public function ensure_construct_finalized_called() |
|
143 | - { |
|
144 | - if (! $this->_construction_finalized) { |
|
145 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function action() |
|
155 | - { |
|
156 | - return $this->_action; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param string $action |
|
163 | - */ |
|
164 | - public function set_action($action) |
|
165 | - { |
|
166 | - $this->_action = $action; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function method() |
|
175 | - { |
|
176 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $method |
|
183 | - */ |
|
184 | - public function set_method($method) |
|
185 | - { |
|
186 | - switch ($method) { |
|
187 | - case 'get' : |
|
188 | - case 'GET' : |
|
189 | - $this->_method = 'GET'; |
|
190 | - break; |
|
191 | - default : |
|
192 | - $this->_method = 'POST'; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
200 | - * Calculation involves using the name and the parent's html id |
|
201 | - * return void |
|
202 | - * |
|
203 | - * @throws \EE_Error |
|
204 | - */ |
|
205 | - protected function _set_default_html_id_if_empty() |
|
206 | - { |
|
207 | - if (! $this->_html_id) { |
|
208 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
209 | - $this->_html_id = $this->_parent_section->html_id() |
|
210 | - . '-' |
|
211 | - . $this->_prep_name_for_html_id($this->name()); |
|
212 | - } else { |
|
213 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * _prep_name_for_html_id |
|
222 | - * |
|
223 | - * @param $name |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - private function _prep_name_for_html_id($name) |
|
227 | - { |
|
228 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
229 | - } |
|
24 | + /** |
|
25 | + * the URL the form is submitted to |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $_action; |
|
30 | + |
|
31 | + /** |
|
32 | + * POST (default) or GET |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_method; |
|
37 | + |
|
38 | + /** |
|
39 | + * html_id and html_name are derived from this by default |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $_name; |
|
44 | + |
|
45 | + /** |
|
46 | + * $_html_id |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_html_id; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_html_class |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + protected $_html_class; |
|
56 | + |
|
57 | + /** |
|
58 | + * $_html_style |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $_html_style; |
|
62 | + |
|
63 | + /** |
|
64 | + * $_other_html_attributes |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $_other_html_attributes; |
|
68 | + |
|
69 | + /** |
|
70 | + * The form section of which this form section is a part |
|
71 | + * |
|
72 | + * @var EE_Form_Section_Proper |
|
73 | + */ |
|
74 | + protected $_parent_section; |
|
75 | + |
|
76 | + /** |
|
77 | + * flag indicating that _construct_finalize has been called. |
|
78 | + * If it has not been called and we try to use functions which require it, we call it |
|
79 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
80 | + * |
|
81 | + * @var boolean |
|
82 | + */ |
|
83 | + protected $_construction_finalized; |
|
84 | + |
|
85 | + /** |
|
86 | + * Strategy for parsing the form HTML upon display |
|
87 | + * |
|
88 | + * @var FormHtmlFilter |
|
89 | + */ |
|
90 | + protected $_form_html_filter; |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param array $options_array { |
|
95 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
96 | + * } |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + */ |
|
99 | + public function __construct($options_array = array()) |
|
100 | + { |
|
101 | + // used by display strategies |
|
102 | + // assign incoming values to properties |
|
103 | + foreach ($options_array as $key => $value) { |
|
104 | + $key = '_' . $key; |
|
105 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
106 | + $this->{$key} = $value; |
|
107 | + if($key === '_subsections' && ! is_array($value)) { |
|
108 | + throw new InvalidDataTypeException($key, $value, 'array'); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + // set parser which allows the form section's rendered HTML to be filtered |
|
113 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
114 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param $parent_form_section |
|
122 | + * @param $name |
|
123 | + * @throws \EE_Error |
|
124 | + */ |
|
125 | + protected function _construct_finalize($parent_form_section, $name) |
|
126 | + { |
|
127 | + $this->_construction_finalized = true; |
|
128 | + $this->_parent_section = $parent_form_section; |
|
129 | + if ($name !== null) { |
|
130 | + $this->_name = $name; |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * make sure construction finalized was called, otherwise children might not be ready |
|
138 | + * |
|
139 | + * @return void |
|
140 | + * @throws \EE_Error |
|
141 | + */ |
|
142 | + public function ensure_construct_finalized_called() |
|
143 | + { |
|
144 | + if (! $this->_construction_finalized) { |
|
145 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function action() |
|
155 | + { |
|
156 | + return $this->_action; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param string $action |
|
163 | + */ |
|
164 | + public function set_action($action) |
|
165 | + { |
|
166 | + $this->_action = $action; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function method() |
|
175 | + { |
|
176 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $method |
|
183 | + */ |
|
184 | + public function set_method($method) |
|
185 | + { |
|
186 | + switch ($method) { |
|
187 | + case 'get' : |
|
188 | + case 'GET' : |
|
189 | + $this->_method = 'GET'; |
|
190 | + break; |
|
191 | + default : |
|
192 | + $this->_method = 'POST'; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
200 | + * Calculation involves using the name and the parent's html id |
|
201 | + * return void |
|
202 | + * |
|
203 | + * @throws \EE_Error |
|
204 | + */ |
|
205 | + protected function _set_default_html_id_if_empty() |
|
206 | + { |
|
207 | + if (! $this->_html_id) { |
|
208 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
209 | + $this->_html_id = $this->_parent_section->html_id() |
|
210 | + . '-' |
|
211 | + . $this->_prep_name_for_html_id($this->name()); |
|
212 | + } else { |
|
213 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * _prep_name_for_html_id |
|
222 | + * |
|
223 | + * @param $name |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + private function _prep_name_for_html_id($name) |
|
227 | + { |
|
228 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
235 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
236 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
237 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
238 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
239 | - * and so might stop working anytime. |
|
240 | - * |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public function get_html_and_js() |
|
244 | - { |
|
245 | - return $this->get_html(); |
|
246 | - } |
|
233 | + /** |
|
234 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
235 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
236 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
237 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
238 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
239 | + * and so might stop working anytime. |
|
240 | + * |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public function get_html_and_js() |
|
244 | + { |
|
245 | + return $this->get_html(); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * Gets the HTML for displaying this form section |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - abstract public function get_html(); |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @param bool $add_pound_sign |
|
260 | - * @return string |
|
261 | - * @throws EE_Error |
|
262 | - */ |
|
263 | - public function html_id($add_pound_sign = false) |
|
264 | - { |
|
265 | - $this->_set_default_html_id_if_empty(); |
|
266 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public function html_class() |
|
275 | - { |
|
276 | - return $this->_html_class; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function html_style() |
|
285 | - { |
|
286 | - return $this->_html_style; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * @param mixed $html_class |
|
293 | - */ |
|
294 | - public function set_html_class($html_class) |
|
295 | - { |
|
296 | - $this->_html_class = $html_class; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * @param mixed $html_id |
|
303 | - */ |
|
304 | - public function set_html_id($html_id) |
|
305 | - { |
|
306 | - $this->_html_id = $html_id; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @param mixed $html_style |
|
313 | - */ |
|
314 | - public function set_html_style($html_style) |
|
315 | - { |
|
316 | - $this->_html_style = $html_style; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @param string $other_html_attributes |
|
323 | - */ |
|
324 | - public function set_other_html_attributes($other_html_attributes) |
|
325 | - { |
|
326 | - $this->_other_html_attributes = $other_html_attributes; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function other_html_attributes() |
|
335 | - { |
|
336 | - return $this->_other_html_attributes; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
343 | - * |
|
344 | - * @throws EE_Error |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - public function name() |
|
348 | - { |
|
349 | - if (! $this->_construction_finalized) { |
|
350 | - throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
351 | - 'event_espresso'), get_class($this))); |
|
352 | - } |
|
353 | - return $this->_name; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * Gets the parent section |
|
360 | - * |
|
361 | - * @return EE_Form_Section_Proper |
|
362 | - */ |
|
363 | - public function parent_section() |
|
364 | - { |
|
365 | - return $this->_parent_section; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
371 | - * |
|
372 | - * @param string $action the URL the form is submitted to |
|
373 | - * @param string $method POST (default) or GET |
|
374 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
375 | - * @return string |
|
376 | - * @throws EE_Error |
|
377 | - */ |
|
378 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
379 | - { |
|
380 | - if (! empty($action)) { |
|
381 | - $this->set_action($action); |
|
382 | - } |
|
383 | - if (! empty($method)) { |
|
384 | - $this->set_method($method); |
|
385 | - } |
|
386 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
387 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
388 | - $html .= ' action="' . $this->action() . '"'; |
|
389 | - $html .= ' method="' . $this->method() . '"'; |
|
390 | - $html .= ' name="' . $this->name() . '"'; |
|
391 | - $html .= $other_attributes . '>'; |
|
392 | - return $html; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
399 | - * so that id doesn't conflict/collide with other elements |
|
400 | - * |
|
401 | - * @param string $html_id |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - protected function get_html_id_for_form($html_id) |
|
405 | - { |
|
406 | - $strlen = strlen($html_id); |
|
407 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
408 | - ? $html_id |
|
409 | - : $html_id . '-frm'; |
|
410 | - return $html_id; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
416 | - * |
|
417 | - * @return string |
|
418 | - * @throws EE_Error |
|
419 | - */ |
|
420 | - public function form_close() |
|
421 | - { |
|
422 | - return EEH_HTML::nl(-1, 'form') |
|
423 | - . '</form>' |
|
424 | - . EEH_HTML::nl() |
|
425 | - . '<!-- end of ee-' |
|
426 | - . $this->html_id() |
|
427 | - . '-form -->' |
|
428 | - . EEH_HTML::nl(); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
435 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
436 | - * Default does nothing, but child classes can override |
|
437 | - * |
|
438 | - * @return void |
|
439 | - */ |
|
440 | - public function enqueue_js() |
|
441 | - { |
|
442 | - //defaults to enqueue NO js or css |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
449 | - * with it, and it will be on each form section's 'other_data' property. |
|
450 | - * By default nothing is added, but child classes can extend this method to add something. |
|
451 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
452 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
453 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
454 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
455 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
456 | - * |
|
457 | - * @param array $form_other_js_data |
|
458 | - * @return array |
|
459 | - */ |
|
460 | - public function get_other_js_data($form_other_js_data = array()) |
|
461 | - { |
|
462 | - return $form_other_js_data; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
469 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
470 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
471 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
472 | - * which will be returned. |
|
473 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
474 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
475 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
476 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
477 | - * Etc |
|
478 | - * |
|
479 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
480 | - * @return EE_Form_Section_Base |
|
481 | - */ |
|
482 | - public function find_section_from_path($form_section_path) |
|
483 | - { |
|
484 | - if (strpos($form_section_path, '/') === 0) { |
|
485 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
486 | - } |
|
487 | - if (empty($form_section_path)) { |
|
488 | - return $this; |
|
489 | - } |
|
490 | - if (strpos($form_section_path, '../') === 0) { |
|
491 | - $parent = $this->parent_section(); |
|
492 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
493 | - if ($parent instanceof EE_Form_Section_Base) { |
|
494 | - return $parent->find_section_from_path($form_section_path); |
|
495 | - } |
|
496 | - if (empty($form_section_path)) { |
|
497 | - return $this; |
|
498 | - } |
|
499 | - } |
|
500 | - //couldn't find it using simple parent following |
|
501 | - return null; |
|
502 | - } |
|
250 | + /** |
|
251 | + * Gets the HTML for displaying this form section |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + abstract public function get_html(); |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @param bool $add_pound_sign |
|
260 | + * @return string |
|
261 | + * @throws EE_Error |
|
262 | + */ |
|
263 | + public function html_id($add_pound_sign = false) |
|
264 | + { |
|
265 | + $this->_set_default_html_id_if_empty(); |
|
266 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public function html_class() |
|
275 | + { |
|
276 | + return $this->_html_class; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function html_style() |
|
285 | + { |
|
286 | + return $this->_html_style; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * @param mixed $html_class |
|
293 | + */ |
|
294 | + public function set_html_class($html_class) |
|
295 | + { |
|
296 | + $this->_html_class = $html_class; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * @param mixed $html_id |
|
303 | + */ |
|
304 | + public function set_html_id($html_id) |
|
305 | + { |
|
306 | + $this->_html_id = $html_id; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @param mixed $html_style |
|
313 | + */ |
|
314 | + public function set_html_style($html_style) |
|
315 | + { |
|
316 | + $this->_html_style = $html_style; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @param string $other_html_attributes |
|
323 | + */ |
|
324 | + public function set_other_html_attributes($other_html_attributes) |
|
325 | + { |
|
326 | + $this->_other_html_attributes = $other_html_attributes; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function other_html_attributes() |
|
335 | + { |
|
336 | + return $this->_other_html_attributes; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
343 | + * |
|
344 | + * @throws EE_Error |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + public function name() |
|
348 | + { |
|
349 | + if (! $this->_construction_finalized) { |
|
350 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
351 | + 'event_espresso'), get_class($this))); |
|
352 | + } |
|
353 | + return $this->_name; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * Gets the parent section |
|
360 | + * |
|
361 | + * @return EE_Form_Section_Proper |
|
362 | + */ |
|
363 | + public function parent_section() |
|
364 | + { |
|
365 | + return $this->_parent_section; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
371 | + * |
|
372 | + * @param string $action the URL the form is submitted to |
|
373 | + * @param string $method POST (default) or GET |
|
374 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
375 | + * @return string |
|
376 | + * @throws EE_Error |
|
377 | + */ |
|
378 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
379 | + { |
|
380 | + if (! empty($action)) { |
|
381 | + $this->set_action($action); |
|
382 | + } |
|
383 | + if (! empty($method)) { |
|
384 | + $this->set_method($method); |
|
385 | + } |
|
386 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
387 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
388 | + $html .= ' action="' . $this->action() . '"'; |
|
389 | + $html .= ' method="' . $this->method() . '"'; |
|
390 | + $html .= ' name="' . $this->name() . '"'; |
|
391 | + $html .= $other_attributes . '>'; |
|
392 | + return $html; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
399 | + * so that id doesn't conflict/collide with other elements |
|
400 | + * |
|
401 | + * @param string $html_id |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + protected function get_html_id_for_form($html_id) |
|
405 | + { |
|
406 | + $strlen = strlen($html_id); |
|
407 | + $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
408 | + ? $html_id |
|
409 | + : $html_id . '-frm'; |
|
410 | + return $html_id; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
416 | + * |
|
417 | + * @return string |
|
418 | + * @throws EE_Error |
|
419 | + */ |
|
420 | + public function form_close() |
|
421 | + { |
|
422 | + return EEH_HTML::nl(-1, 'form') |
|
423 | + . '</form>' |
|
424 | + . EEH_HTML::nl() |
|
425 | + . '<!-- end of ee-' |
|
426 | + . $this->html_id() |
|
427 | + . '-form -->' |
|
428 | + . EEH_HTML::nl(); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
435 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
436 | + * Default does nothing, but child classes can override |
|
437 | + * |
|
438 | + * @return void |
|
439 | + */ |
|
440 | + public function enqueue_js() |
|
441 | + { |
|
442 | + //defaults to enqueue NO js or css |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
449 | + * with it, and it will be on each form section's 'other_data' property. |
|
450 | + * By default nothing is added, but child classes can extend this method to add something. |
|
451 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
452 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
453 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
454 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
455 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
456 | + * |
|
457 | + * @param array $form_other_js_data |
|
458 | + * @return array |
|
459 | + */ |
|
460 | + public function get_other_js_data($form_other_js_data = array()) |
|
461 | + { |
|
462 | + return $form_other_js_data; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
469 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
470 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
471 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
472 | + * which will be returned. |
|
473 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
474 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
475 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
476 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
477 | + * Etc |
|
478 | + * |
|
479 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
480 | + * @return EE_Form_Section_Base |
|
481 | + */ |
|
482 | + public function find_section_from_path($form_section_path) |
|
483 | + { |
|
484 | + if (strpos($form_section_path, '/') === 0) { |
|
485 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
486 | + } |
|
487 | + if (empty($form_section_path)) { |
|
488 | + return $this; |
|
489 | + } |
|
490 | + if (strpos($form_section_path, '../') === 0) { |
|
491 | + $parent = $this->parent_section(); |
|
492 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
493 | + if ($parent instanceof EE_Form_Section_Base) { |
|
494 | + return $parent->find_section_from_path($form_section_path); |
|
495 | + } |
|
496 | + if (empty($form_section_path)) { |
|
497 | + return $this; |
|
498 | + } |
|
499 | + } |
|
500 | + //couldn't find it using simple parent following |
|
501 | + return null; |
|
502 | + } |
|
503 | 503 | |
504 | 504 | |
505 | 505 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | // used by display strategies |
102 | 102 | // assign incoming values to properties |
103 | 103 | foreach ($options_array as $key => $value) { |
104 | - $key = '_' . $key; |
|
104 | + $key = '_'.$key; |
|
105 | 105 | if (property_exists($this, $key) && empty($this->{$key})) { |
106 | 106 | $this->{$key} = $value; |
107 | - if($key === '_subsections' && ! is_array($value)) { |
|
107 | + if ($key === '_subsections' && ! is_array($value)) { |
|
108 | 108 | throw new InvalidDataTypeException($key, $value, 'array'); |
109 | 109 | } |
110 | 110 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function ensure_construct_finalized_called() |
143 | 143 | { |
144 | - if (! $this->_construction_finalized) { |
|
144 | + if ( ! $this->_construction_finalized) { |
|
145 | 145 | $this->_construct_finalize($this->_parent_section, $this->_name); |
146 | 146 | } |
147 | 147 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function _set_default_html_id_if_empty() |
206 | 206 | { |
207 | - if (! $this->_html_id) { |
|
207 | + if ( ! $this->_html_id) { |
|
208 | 208 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
209 | 209 | $this->_html_id = $this->_parent_section->html_id() |
210 | 210 | . '-' |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | public function html_id($add_pound_sign = false) |
264 | 264 | { |
265 | 265 | $this->_set_default_html_id_if_empty(); |
266 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
266 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function name() |
348 | 348 | { |
349 | - if (! $this->_construction_finalized) { |
|
349 | + if ( ! $this->_construction_finalized) { |
|
350 | 350 | throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
351 | 351 | 'event_espresso'), get_class($this))); |
352 | 352 | } |
@@ -377,18 +377,18 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function form_open($action = '', $method = '', $other_attributes = '') |
379 | 379 | { |
380 | - if (! empty($action)) { |
|
380 | + if ( ! empty($action)) { |
|
381 | 381 | $this->set_action($action); |
382 | 382 | } |
383 | - if (! empty($method)) { |
|
383 | + if ( ! empty($method)) { |
|
384 | 384 | $this->set_method($method); |
385 | 385 | } |
386 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
387 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
388 | - $html .= ' action="' . $this->action() . '"'; |
|
389 | - $html .= ' method="' . $this->method() . '"'; |
|
390 | - $html .= ' name="' . $this->name() . '"'; |
|
391 | - $html .= $other_attributes . '>'; |
|
386 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
387 | + $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : ''; |
|
388 | + $html .= ' action="'.$this->action().'"'; |
|
389 | + $html .= ' method="'.$this->method().'"'; |
|
390 | + $html .= ' name="'.$this->name().'"'; |
|
391 | + $html .= $other_attributes.'>'; |
|
392 | 392 | return $html; |
393 | 393 | } |
394 | 394 | |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | protected function get_html_id_for_form($html_id) |
405 | 405 | { |
406 | 406 | $strlen = strlen($html_id); |
407 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
407 | + $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4 |
|
408 | 408 | ? $html_id |
409 | - : $html_id . '-frm'; |
|
409 | + : $html_id.'-frm'; |
|
410 | 410 | return $html_id; |
411 | 411 | } |
412 | 412 |
@@ -17,256 +17,256 @@ |
||
17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Request $request |
|
22 | - */ |
|
23 | - private $request; |
|
20 | + /** |
|
21 | + * @var EE_Request $request |
|
22 | + */ |
|
23 | + private $request; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array $_previous_routes |
|
27 | - */ |
|
28 | - private static $_previous_routes = array(); |
|
25 | + /** |
|
26 | + * @var array $_previous_routes |
|
27 | + */ |
|
28 | + private static $_previous_routes = array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var WP_Query $WP_Query |
|
32 | - */ |
|
33 | - public $WP_Query; |
|
30 | + /** |
|
31 | + * @var WP_Query $WP_Query |
|
32 | + */ |
|
33 | + public $WP_Query; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * EE_Module_Request_Router constructor. |
|
39 | - * |
|
40 | - * @param EE_Request $request |
|
41 | - */ |
|
42 | - public function __construct(EE_Request $request) |
|
43 | - { |
|
44 | - $this->request = $request; |
|
45 | - } |
|
37 | + /** |
|
38 | + * EE_Module_Request_Router constructor. |
|
39 | + * |
|
40 | + * @param EE_Request $request |
|
41 | + */ |
|
42 | + public function __construct(EE_Request $request) |
|
43 | + { |
|
44 | + $this->request = $request; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
51 | - * on subsequent calls to this method, |
|
52 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
53 | - * and checks if the last called route has any forwarding routes registered for it |
|
54 | - * |
|
55 | - * @param WP_Query $WP_Query |
|
56 | - * @return NULL|string |
|
57 | - * @throws EE_Error |
|
58 | - * @throws ReflectionException |
|
59 | - */ |
|
60 | - public function get_route(WP_Query $WP_Query) |
|
61 | - { |
|
62 | - $this->WP_Query = $WP_Query; |
|
63 | - // assume this if first route being called |
|
64 | - $previous_route = false; |
|
65 | - // but is it really ??? |
|
66 | - if (! empty(self::$_previous_routes)) { |
|
67 | - // get last run route |
|
68 | - $previous_routes = array_values(self::$_previous_routes); |
|
69 | - $previous_route = array_pop($previous_routes); |
|
70 | - } |
|
71 | - // has another route already been run ? |
|
72 | - if ($previous_route) { |
|
73 | - // check if forwarding has been set |
|
74 | - $current_route = $this->get_forward($previous_route); |
|
75 | - try { |
|
76 | - //check for recursive forwarding |
|
77 | - if (isset(self::$_previous_routes[$current_route])) { |
|
78 | - throw new EE_Error( |
|
79 | - sprintf( |
|
80 | - __( |
|
81 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $current_route |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
88 | - } catch (EE_Error $e) { |
|
89 | - $e->get_error(); |
|
90 | - return null; |
|
91 | - } |
|
92 | - } else { |
|
93 | - // first route called |
|
94 | - $current_route = null; |
|
95 | - // grab all routes |
|
96 | - $routes = EE_Config::get_routes(); |
|
97 | - foreach ($routes as $key => $route) { |
|
98 | - // first determine if route key uses w?ldc*rds |
|
99 | - $uses_wildcards = strpos($key, '?') !== false |
|
100 | - || strpos($key, '*') !== false; |
|
101 | - // check request for module route |
|
102 | - $route_found = $uses_wildcards |
|
103 | - ? $this->request->matches($key) |
|
104 | - : $this->request->is_set($key); |
|
105 | - if ($route_found) { |
|
106 | - $current_route = $uses_wildcards |
|
107 | - ? $this->request->getMatch($key) |
|
108 | - : $this->request->get($key); |
|
109 | - $current_route = sanitize_text_field($current_route); |
|
110 | - if ($current_route) { |
|
111 | - $current_route = array($key, $current_route); |
|
112 | - break; |
|
113 | - } |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - // sorry, but I can't read what you route ! |
|
118 | - if (empty($current_route)) { |
|
119 | - return null; |
|
120 | - } |
|
121 | - //add route to previous routes array |
|
122 | - self::$_previous_routes[] = $current_route; |
|
123 | - return $current_route; |
|
124 | - } |
|
49 | + /** |
|
50 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
51 | + * on subsequent calls to this method, |
|
52 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
53 | + * and checks if the last called route has any forwarding routes registered for it |
|
54 | + * |
|
55 | + * @param WP_Query $WP_Query |
|
56 | + * @return NULL|string |
|
57 | + * @throws EE_Error |
|
58 | + * @throws ReflectionException |
|
59 | + */ |
|
60 | + public function get_route(WP_Query $WP_Query) |
|
61 | + { |
|
62 | + $this->WP_Query = $WP_Query; |
|
63 | + // assume this if first route being called |
|
64 | + $previous_route = false; |
|
65 | + // but is it really ??? |
|
66 | + if (! empty(self::$_previous_routes)) { |
|
67 | + // get last run route |
|
68 | + $previous_routes = array_values(self::$_previous_routes); |
|
69 | + $previous_route = array_pop($previous_routes); |
|
70 | + } |
|
71 | + // has another route already been run ? |
|
72 | + if ($previous_route) { |
|
73 | + // check if forwarding has been set |
|
74 | + $current_route = $this->get_forward($previous_route); |
|
75 | + try { |
|
76 | + //check for recursive forwarding |
|
77 | + if (isset(self::$_previous_routes[$current_route])) { |
|
78 | + throw new EE_Error( |
|
79 | + sprintf( |
|
80 | + __( |
|
81 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $current_route |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | + } catch (EE_Error $e) { |
|
89 | + $e->get_error(); |
|
90 | + return null; |
|
91 | + } |
|
92 | + } else { |
|
93 | + // first route called |
|
94 | + $current_route = null; |
|
95 | + // grab all routes |
|
96 | + $routes = EE_Config::get_routes(); |
|
97 | + foreach ($routes as $key => $route) { |
|
98 | + // first determine if route key uses w?ldc*rds |
|
99 | + $uses_wildcards = strpos($key, '?') !== false |
|
100 | + || strpos($key, '*') !== false; |
|
101 | + // check request for module route |
|
102 | + $route_found = $uses_wildcards |
|
103 | + ? $this->request->matches($key) |
|
104 | + : $this->request->is_set($key); |
|
105 | + if ($route_found) { |
|
106 | + $current_route = $uses_wildcards |
|
107 | + ? $this->request->getMatch($key) |
|
108 | + : $this->request->get($key); |
|
109 | + $current_route = sanitize_text_field($current_route); |
|
110 | + if ($current_route) { |
|
111 | + $current_route = array($key, $current_route); |
|
112 | + break; |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + // sorry, but I can't read what you route ! |
|
118 | + if (empty($current_route)) { |
|
119 | + return null; |
|
120 | + } |
|
121 | + //add route to previous routes array |
|
122 | + self::$_previous_routes[] = $current_route; |
|
123 | + return $current_route; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
130 | - * |
|
131 | - * @param string $key |
|
132 | - * @param string $current_route |
|
133 | - * @return mixed EED_Module | boolean |
|
134 | - * @throws EE_Error |
|
135 | - * @throws ReflectionException |
|
136 | - */ |
|
137 | - public function resolve_route($key, $current_route) |
|
138 | - { |
|
139 | - // get module method that route has been mapped to |
|
140 | - $module_method = EE_Config::get_route($current_route, $key); |
|
141 | - // verify result was returned |
|
142 | - if (empty($module_method)) { |
|
143 | - $msg = sprintf( |
|
144 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
145 | - $current_route |
|
146 | - ); |
|
147 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | - return false; |
|
149 | - } |
|
150 | - // verify that result is an array |
|
151 | - if (! is_array($module_method)) { |
|
152 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
153 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | - return false; |
|
155 | - } |
|
156 | - // grab module name |
|
157 | - $module_name = $module_method[0]; |
|
158 | - // verify that a class method was registered properly |
|
159 | - if (! isset($module_method[1])) { |
|
160 | - $msg = sprintf( |
|
161 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
162 | - $current_route |
|
163 | - ); |
|
164 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - return false; |
|
166 | - } |
|
167 | - // grab method |
|
168 | - $method = $module_method[1]; |
|
169 | - // verify that class exists |
|
170 | - if (! class_exists($module_name)) { |
|
171 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
172 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | - return false; |
|
174 | - } |
|
175 | - // verify that method exists |
|
176 | - if (! method_exists($module_name, $method)) { |
|
177 | - $msg = sprintf( |
|
178 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
179 | - ); |
|
180 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
181 | - return false; |
|
182 | - } |
|
183 | - // instantiate module and call route method |
|
184 | - return $this->_module_router($module_name, $method); |
|
185 | - } |
|
128 | + /** |
|
129 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
130 | + * |
|
131 | + * @param string $key |
|
132 | + * @param string $current_route |
|
133 | + * @return mixed EED_Module | boolean |
|
134 | + * @throws EE_Error |
|
135 | + * @throws ReflectionException |
|
136 | + */ |
|
137 | + public function resolve_route($key, $current_route) |
|
138 | + { |
|
139 | + // get module method that route has been mapped to |
|
140 | + $module_method = EE_Config::get_route($current_route, $key); |
|
141 | + // verify result was returned |
|
142 | + if (empty($module_method)) { |
|
143 | + $msg = sprintf( |
|
144 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
145 | + $current_route |
|
146 | + ); |
|
147 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | + return false; |
|
149 | + } |
|
150 | + // verify that result is an array |
|
151 | + if (! is_array($module_method)) { |
|
152 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
153 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
154 | + return false; |
|
155 | + } |
|
156 | + // grab module name |
|
157 | + $module_name = $module_method[0]; |
|
158 | + // verify that a class method was registered properly |
|
159 | + if (! isset($module_method[1])) { |
|
160 | + $msg = sprintf( |
|
161 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
162 | + $current_route |
|
163 | + ); |
|
164 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + return false; |
|
166 | + } |
|
167 | + // grab method |
|
168 | + $method = $module_method[1]; |
|
169 | + // verify that class exists |
|
170 | + if (! class_exists($module_name)) { |
|
171 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
172 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | + return false; |
|
174 | + } |
|
175 | + // verify that method exists |
|
176 | + if (! method_exists($module_name, $method)) { |
|
177 | + $msg = sprintf( |
|
178 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
179 | + ); |
|
180 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
181 | + return false; |
|
182 | + } |
|
183 | + // instantiate module and call route method |
|
184 | + return $this->_module_router($module_name, $method); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
191 | - * |
|
192 | - * @param string $module_name |
|
193 | - * @return EED_Module|object|null |
|
194 | - * @throws ReflectionException |
|
195 | - */ |
|
196 | - public static function module_factory($module_name) |
|
197 | - { |
|
198 | - if ($module_name === 'EED_Module') { |
|
199 | - EE_Error::add_error( |
|
200 | - sprintf( |
|
201 | - __( |
|
202 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
203 | - 'event_espresso' |
|
204 | - ), $module_name |
|
205 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
206 | - ); |
|
207 | - return null; |
|
208 | - } |
|
209 | - // instantiate module class |
|
210 | - $module = new $module_name(); |
|
211 | - // ensure that class is actually a module |
|
212 | - if (! $module instanceof EED_Module) { |
|
213 | - EE_Error::add_error( |
|
214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | - __FILE__, __FUNCTION__, __LINE__ |
|
216 | - ); |
|
217 | - return null; |
|
218 | - } |
|
219 | - return $module; |
|
220 | - } |
|
189 | + /** |
|
190 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
191 | + * |
|
192 | + * @param string $module_name |
|
193 | + * @return EED_Module|object|null |
|
194 | + * @throws ReflectionException |
|
195 | + */ |
|
196 | + public static function module_factory($module_name) |
|
197 | + { |
|
198 | + if ($module_name === 'EED_Module') { |
|
199 | + EE_Error::add_error( |
|
200 | + sprintf( |
|
201 | + __( |
|
202 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
203 | + 'event_espresso' |
|
204 | + ), $module_name |
|
205 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
206 | + ); |
|
207 | + return null; |
|
208 | + } |
|
209 | + // instantiate module class |
|
210 | + $module = new $module_name(); |
|
211 | + // ensure that class is actually a module |
|
212 | + if (! $module instanceof EED_Module) { |
|
213 | + EE_Error::add_error( |
|
214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | + __FILE__, __FUNCTION__, __LINE__ |
|
216 | + ); |
|
217 | + return null; |
|
218 | + } |
|
219 | + return $module; |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | 223 | |
224 | - /** |
|
225 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
226 | - * |
|
227 | - * @param string $module_name |
|
228 | - * @param string $method |
|
229 | - * @return EED_Module|null |
|
230 | - * @throws EE_Error |
|
231 | - * @throws ReflectionException |
|
232 | - */ |
|
233 | - private function _module_router($module_name, $method) |
|
234 | - { |
|
235 | - // instantiate module class |
|
236 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
237 | - if ($module instanceof EED_Module) { |
|
238 | - // and call whatever action the route was for |
|
239 | - try { |
|
240 | - call_user_func(array($module, $method), $this->WP_Query); |
|
241 | - } catch (EE_Error $e) { |
|
242 | - $e->get_error(); |
|
243 | - return null; |
|
244 | - } |
|
245 | - } |
|
246 | - return $module; |
|
247 | - } |
|
224 | + /** |
|
225 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
226 | + * |
|
227 | + * @param string $module_name |
|
228 | + * @param string $method |
|
229 | + * @return EED_Module|null |
|
230 | + * @throws EE_Error |
|
231 | + * @throws ReflectionException |
|
232 | + */ |
|
233 | + private function _module_router($module_name, $method) |
|
234 | + { |
|
235 | + // instantiate module class |
|
236 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
237 | + if ($module instanceof EED_Module) { |
|
238 | + // and call whatever action the route was for |
|
239 | + try { |
|
240 | + call_user_func(array($module, $method), $this->WP_Query); |
|
241 | + } catch (EE_Error $e) { |
|
242 | + $e->get_error(); |
|
243 | + return null; |
|
244 | + } |
|
245 | + } |
|
246 | + return $module; |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param $current_route |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_forward($current_route) |
|
256 | - { |
|
257 | - return EE_Config::get_forward($current_route); |
|
258 | - } |
|
251 | + /** |
|
252 | + * @param $current_route |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_forward($current_route) |
|
256 | + { |
|
257 | + return EE_Config::get_forward($current_route); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * @param $current_route |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public function get_view($current_route) |
|
267 | - { |
|
268 | - return EE_Config::get_view($current_route); |
|
269 | - } |
|
262 | + /** |
|
263 | + * @param $current_route |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public function get_view($current_route) |
|
267 | + { |
|
268 | + return EE_Config::get_view($current_route); |
|
269 | + } |
|
270 | 270 | |
271 | 271 | |
272 | 272 | } |
@@ -3,7 +3,6 @@ |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | 5 | use EventEspresso\core\interfaces\ResettableInterface; |
6 | - |
|
7 | 6 | use EventEspresso\core\services\database\TableManager; |
8 | 7 | use EventEspresso\core\services\database\TableAnalysis; |
9 | 8 |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | protected $script_migration_versions; |
137 | 137 | |
138 | 138 | /** |
139 | - * @var EE_Data_Migration_Manager $_instance |
|
139 | + * @var EE_Data_Migration_Manager $_instance |
|
140 | 140 | * @access private |
141 | - */ |
|
141 | + */ |
|
142 | 142 | private static $_instance = NULL; |
143 | 143 | |
144 | 144 | |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function get_data_migration_script_folders(){ |
324 | 324 | return apply_filters( |
325 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
326 | - array('Core' => EE_CORE.'data_migration_scripts') |
|
327 | - ); |
|
325 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
326 | + array('Core' => EE_CORE.'data_migration_scripts') |
|
327 | + ); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -337,15 +337,15 @@ discard block |
||
337 | 337 | * @throws EE_Error |
338 | 338 | */ |
339 | 339 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
342 | - } |
|
340 | + if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
341 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
342 | + } |
|
343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
344 | + $this->script_migration_versions[ $migration_script_name ] = array( |
|
345 | 345 | 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
346 | 346 | 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
347 | - ); |
|
348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
347 | + ); |
|
348 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -736,60 +736,60 @@ discard block |
||
736 | 736 | } |
737 | 737 | |
738 | 738 | |
739 | - /** |
|
740 | - * Gets all the data migration scripts available in the core folder and folders |
|
741 | - * in addons. Has the side effect of adding them for autoloading |
|
742 | - * |
|
743 | - * @return array keys are expected classnames, values are their filepaths |
|
744 | - * @throws InvalidInterfaceException |
|
745 | - * @throws InvalidDataTypeException |
|
746 | - * @throws EE_Error |
|
747 | - * @throws InvalidArgumentException |
|
748 | - */ |
|
749 | - public function get_all_data_migration_scripts_available() |
|
750 | - { |
|
751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
752 | - $this->_data_migration_class_to_filepath_map = array(); |
|
753 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
754 | - // strip any placeholders added to classname to make it a unique array key |
|
755 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
756 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
757 | - ? $eeAddonClass |
|
758 | - : ''; |
|
759 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
760 | - $files = glob($folder_path . '*.dms.php'); |
|
761 | - if (empty($files)) { |
|
762 | - continue; |
|
763 | - } |
|
764 | - foreach ($files as $file) { |
|
765 | - $pos_of_last_slash = strrpos($file, DS); |
|
766 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
767 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
768 | - $slug = $migrates_to['slug']; |
|
769 | - //check that the slug as contained in the DMS is associated with |
|
770 | - //the slug of an addon or core |
|
771 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
772 | - EE_Error::doing_it_wrong( |
|
773 | - __FUNCTION__, |
|
774 | - sprintf( |
|
775 | - esc_html__( |
|
776 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
777 | - 'event_espresso' |
|
778 | - ), |
|
779 | - $classname, |
|
780 | - $slug, |
|
781 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
782 | - ), |
|
783 | - '4.3.0.alpha.019' |
|
784 | - ); |
|
785 | - } |
|
786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
787 | - } |
|
788 | - } |
|
789 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
790 | - } |
|
791 | - return $this->_data_migration_class_to_filepath_map; |
|
792 | - } |
|
739 | + /** |
|
740 | + * Gets all the data migration scripts available in the core folder and folders |
|
741 | + * in addons. Has the side effect of adding them for autoloading |
|
742 | + * |
|
743 | + * @return array keys are expected classnames, values are their filepaths |
|
744 | + * @throws InvalidInterfaceException |
|
745 | + * @throws InvalidDataTypeException |
|
746 | + * @throws EE_Error |
|
747 | + * @throws InvalidArgumentException |
|
748 | + */ |
|
749 | + public function get_all_data_migration_scripts_available() |
|
750 | + { |
|
751 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
752 | + $this->_data_migration_class_to_filepath_map = array(); |
|
753 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
754 | + // strip any placeholders added to classname to make it a unique array key |
|
755 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
756 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
757 | + ? $eeAddonClass |
|
758 | + : ''; |
|
759 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
760 | + $files = glob($folder_path . '*.dms.php'); |
|
761 | + if (empty($files)) { |
|
762 | + continue; |
|
763 | + } |
|
764 | + foreach ($files as $file) { |
|
765 | + $pos_of_last_slash = strrpos($file, DS); |
|
766 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
767 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
768 | + $slug = $migrates_to['slug']; |
|
769 | + //check that the slug as contained in the DMS is associated with |
|
770 | + //the slug of an addon or core |
|
771 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
772 | + EE_Error::doing_it_wrong( |
|
773 | + __FUNCTION__, |
|
774 | + sprintf( |
|
775 | + esc_html__( |
|
776 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
777 | + 'event_espresso' |
|
778 | + ), |
|
779 | + $classname, |
|
780 | + $slug, |
|
781 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
782 | + ), |
|
783 | + '4.3.0.alpha.019' |
|
784 | + ); |
|
785 | + } |
|
786 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
787 | + } |
|
788 | + } |
|
789 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
790 | + } |
|
791 | + return $this->_data_migration_class_to_filepath_map; |
|
792 | + } |
|
793 | 793 | |
794 | 794 | |
795 | 795 | |
@@ -961,12 +961,12 @@ discard block |
||
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
964 | - * Resets the borked data migration scripts so they're no longer borked |
|
965 | - * so we can again attempt to migrate |
|
966 | - * |
|
967 | - * @return bool |
|
968 | - * @throws EE_Error |
|
969 | - */ |
|
964 | + * Resets the borked data migration scripts so they're no longer borked |
|
965 | + * so we can again attempt to migrate |
|
966 | + * |
|
967 | + * @return bool |
|
968 | + * @throws EE_Error |
|
969 | + */ |
|
970 | 970 | public function reattempt(){ |
971 | 971 | //find if the last-ran script was borked |
972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * of this EE installation. Keys should be the name of the version the script upgraded to |
86 | 86 | * @var EE_Data_Migration_Script_Base[] |
87 | 87 | */ |
88 | - private $_data_migrations_ran =null; |
|
88 | + private $_data_migrations_ran = null; |
|
89 | 89 | /** |
90 | 90 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
91 | 91 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public static function instance() { |
152 | 152 | // check if class object is instantiated |
153 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
153 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
154 | 154 | self::$_instance = new self(); |
155 | 155 | } |
156 | 156 | return self::$_instance; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
161 | 161 | * @return EE_Data_Migration_Manager |
162 | 162 | */ |
163 | - public static function reset(){ |
|
163 | + public static function reset() { |
|
164 | 164 | self::$_instance = NULL; |
165 | 165 | return self::instance(); |
166 | 166 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | /** |
171 | 171 | * constructor |
172 | 172 | */ |
173 | - private function __construct(){ |
|
173 | + private function __construct() { |
|
174 | 174 | $this->stati_that_indicate_to_continue_migrations = array( |
175 | 175 | self::status_continue, |
176 | 176 | self::status_completed |
@@ -189,13 +189,13 @@ discard block |
||
189 | 189 | ); |
190 | 190 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
191 | 191 | //to be defined, because right now it doesn't get autoloaded on its own |
192 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
193 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
194 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
195 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
196 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
197 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
198 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
192 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
193 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
194 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
195 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
196 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
197 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
198 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -208,21 +208,21 @@ discard block |
||
208 | 208 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
209 | 209 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
210 | 210 | */ |
211 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
211 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
212 | 212 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
213 | 213 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
214 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
214 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
215 | 215 | |
216 | - if(count($parts) == 4){ |
|
216 | + if (count($parts) == 4) { |
|
217 | 217 | //it's 4.2-style.eg Core.4.1.0 |
218 | - $plugin_slug = $parts[0];//eg Core |
|
218 | + $plugin_slug = $parts[0]; //eg Core |
|
219 | 219 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
220 | - }else{ |
|
220 | + } else { |
|
221 | 221 | //it's 4.1-style: eg 4.1.0 |
222 | 222 | $plugin_slug = 'Core'; |
223 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
223 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
224 | 224 | } |
225 | - return array($plugin_slug,$version_string); |
|
225 | + return array($plugin_slug, $version_string); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -233,21 +233,21 @@ discard block |
||
233 | 233 | * @return EE_Data_Migration_Script_Base |
234 | 234 | * @throws EE_Error |
235 | 235 | */ |
236 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
236 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
237 | 237 | $data_migration_data = maybe_unserialize($dms_option_value); |
238 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
238 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
239 | 239 | $class = new $data_migration_data['class']; |
240 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
240 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
241 | 241 | $class->instantiate_from_array_of_properties($data_migration_data); |
242 | 242 | return $class; |
243 | - }else{ |
|
243 | + } else { |
|
244 | 244 | //huh, so its an object but not a data migration script?? that shouldn't happen |
245 | 245 | //just leave it as an array (which will probably just get ignored) |
246 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
246 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
247 | 247 | } |
248 | - }else{ |
|
248 | + } else { |
|
249 | 249 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
250 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
250 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | /** |
@@ -255,34 +255,34 @@ discard block |
||
255 | 255 | * the last ran which hasn't finished yet |
256 | 256 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
257 | 257 | */ |
258 | - public function get_data_migrations_ran(){ |
|
259 | - if( ! $this->_data_migrations_ran ){ |
|
258 | + public function get_data_migrations_ran() { |
|
259 | + if ( ! $this->_data_migrations_ran) { |
|
260 | 260 | //setup autoloaders for each of the scripts in there |
261 | 261 | $this->get_all_data_migration_scripts_available(); |
262 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
262 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
263 | 263 | |
264 | 264 | $data_migrations_ran = array(); |
265 | 265 | //convert into data migration script classes where possible |
266 | - foreach($data_migrations_options as $data_migration_option){ |
|
267 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
266 | + foreach ($data_migrations_options as $data_migration_option) { |
|
267 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
268 | 268 | |
269 | - try{ |
|
270 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
269 | + try { |
|
270 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
272 | 272 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
273 | 273 | $this->_last_ran_script = $class; |
274 | - if( ! $class->is_completed()){ |
|
274 | + if ( ! $class->is_completed()) { |
|
275 | 275 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
276 | 276 | $this->_last_ran_incomplete_script = $class; |
277 | 277 | } |
278 | - }catch(EE_Error $e){ |
|
278 | + } catch (EE_Error $e) { |
|
279 | 279 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
280 | 280 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
281 | 281 | } |
282 | 282 | } |
283 | 283 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
284 | 284 | $this->_data_migrations_ran = $data_migrations_ran; |
285 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
285 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
286 | 286 | $this->_data_migrations_ran = array(); |
287 | 287 | } |
288 | 288 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param $new_table |
300 | 300 | * @return mixed string or int |
301 | 301 | */ |
302 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
302 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
303 | 303 | $script = EE_Registry::instance()->load_dms($script_name); |
304 | 304 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
305 | 305 | return $mapping; |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | * option returned in this array is the most-recently ran DMS option |
311 | 311 | * @return array |
312 | 312 | */ |
313 | - public function get_all_migration_script_options(){ |
|
313 | + public function get_all_migration_script_options() { |
|
314 | 314 | global $wpdb; |
315 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
315 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
321 | 321 | * folder name. |
322 | 322 | */ |
323 | - public function get_data_migration_script_folders(){ |
|
323 | + public function get_data_migration_script_folders() { |
|
324 | 324 | return apply_filters( |
325 | 325 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
326 | 326 | array('Core' => EE_CORE.'data_migration_scripts') |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | * } |
337 | 337 | * @throws EE_Error |
338 | 338 | */ |
339 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
|
340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
339 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') { |
|
340 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
341 | + return $this->script_migration_versions[$migration_script_name]; |
|
342 | 342 | } |
343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
345 | - 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
|
346 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
|
344 | + $this->script_migration_versions[$migration_script_name] = array( |
|
345 | + 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
346 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] |
|
347 | 347 | ); |
348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
348 | + return $this->script_migration_versions[$migration_script_name]; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
355 | 355 | * @throws EE_Error |
356 | 356 | */ |
357 | - public function parse_dms_classname($classname){ |
|
357 | + public function parse_dms_classname($classname) { |
|
358 | 358 | $matches = array(); |
359 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
360 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
361 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
359 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
360 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
361 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
362 | 362 | } |
363 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
363 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
364 | 364 | } |
365 | 365 | /** |
366 | 366 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -369,33 +369,33 @@ discard block |
||
369 | 369 | * to 4.1.x. |
370 | 370 | * @return string of current db state |
371 | 371 | */ |
372 | - public function ensure_current_database_state_is_set(){ |
|
373 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
372 | + public function ensure_current_database_state_is_set() { |
|
373 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
374 | 374 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
375 | - if( ! $db_state ){ |
|
375 | + if ( ! $db_state) { |
|
376 | 376 | //mark the DB as being in the state as the last version in there. |
377 | 377 | //this is done to trigger maintenance mode and do data migration scripts |
378 | 378 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
379 | 379 | //otherwise, the normal maintenance mode code is fine |
380 | 380 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
381 | 381 | $previous_version_installed = end($previous_versions_installed); |
382 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
382 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
383 | 383 | //last installed version was less than 4.1 |
384 | 384 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
385 | 385 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
386 | 386 | $db_state = array('Core'=>$previous_version_installed); |
387 | - }else{ |
|
387 | + } else { |
|
388 | 388 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
389 | 389 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
390 | 390 | } |
391 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
391 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
392 | 392 | } |
393 | 393 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
394 | 394 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
395 | 395 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
396 | - if( ! is_array($db_state)){ |
|
396 | + if ( ! is_array($db_state)) { |
|
397 | 397 | $db_state = array('Core'=>$db_state); |
398 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
398 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
399 | 399 | } |
400 | 400 | return $db_state; |
401 | 401 | } |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * or they don't apply), returns an empty array |
407 | 407 | * @return EE_Data_Migration_Script_Base[] |
408 | 408 | */ |
409 | - public function check_for_applicable_data_migration_scripts(){ |
|
409 | + public function check_for_applicable_data_migration_scripts() { |
|
410 | 410 | //get the option describing what options have already run |
411 | 411 | $scripts_ran = $this->get_data_migrations_ran(); |
412 | 412 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -419,62 +419,62 @@ discard block |
||
419 | 419 | $iteration = 0; |
420 | 420 | $next_database_state_to_consider = $current_database_state; |
421 | 421 | $theoretical_database_state = NULL; |
422 | - do{ |
|
422 | + do { |
|
423 | 423 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
424 | 424 | $theoretical_database_state = $next_database_state_to_consider; |
425 | 425 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
426 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
426 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
427 | 427 | |
428 | 428 | $migrates_to_version = $this->script_migrates_to_version($classname); |
429 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
430 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
429 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
430 | + $script_converts_to_version = $migrates_to_version['version']; |
|
431 | 431 | //check if this version script is DONE or not; or if it's never been ran |
432 | - if( ! $scripts_ran || |
|
432 | + if ( ! $scripts_ran || |
|
433 | 433 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
434 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
434 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
435 | 435 | //we haven't ran this conversion script before |
436 | 436 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
437 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
437 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
438 | 438 | /* @var $script EE_Data_Migration_Script_Base */ |
439 | 439 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
440 | - if($can_migrate){ |
|
440 | + if ($can_migrate) { |
|
441 | 441 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
442 | 442 | $migrates_to_version = $script->migrates_to_version(); |
443 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
443 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
444 | 444 | unset($script_class_and_filepaths_available[$classname]); |
445 | 445 | } |
446 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
446 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
447 | 447 | //this script has been ran, or at least started |
448 | 448 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
449 | - if( $script->get_status() != self::status_completed){ |
|
449 | + if ($script->get_status() != self::status_completed) { |
|
450 | 450 | //this script is already underway... keep going with it |
451 | 451 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
452 | 452 | $migrates_to_version = $script->migrates_to_version(); |
453 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
453 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
454 | 454 | unset($script_class_and_filepaths_available[$classname]); |
455 | - }else{ |
|
455 | + } else { |
|
456 | 456 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
457 | 457 | } |
458 | - }else{ |
|
458 | + } else { |
|
459 | 459 | //it exists but it's not a proper data migration script |
460 | 460 | //maybe the script got renamed? or was simply removed from EE? |
461 | 461 | //either way, its certainly not runnable! |
462 | 462 | } |
463 | 463 | } |
464 | 464 | $iteration++; |
465 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
465 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
466 | 466 | //ok we have all the scripts that should run, now let's make them into flat array |
467 | 467 | $scripts_that_should_run = array(); |
468 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
468 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
469 | 469 | ksort($scripts_at_priority); |
470 | - foreach($scripts_at_priority as $scripts){ |
|
471 | - foreach($scripts as $script){ |
|
470 | + foreach ($scripts_at_priority as $scripts) { |
|
471 | + foreach ($scripts as $script) { |
|
472 | 472 | $scripts_that_should_run[get_class($script)] = $script; |
473 | 473 | } |
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
477 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
478 | 478 | return $scripts_that_should_run; |
479 | 479 | } |
480 | 480 | |
@@ -488,14 +488,14 @@ discard block |
||
488 | 488 | * @param bool $include_completed_scripts |
489 | 489 | * @return EE_Data_Migration_Script_Base |
490 | 490 | */ |
491 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
491 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
492 | 492 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
493 | - if( ! $this->_data_migrations_ran){ |
|
493 | + if ( ! $this->_data_migrations_ran) { |
|
494 | 494 | $this->get_data_migrations_ran(); |
495 | 495 | } |
496 | - if($include_completed_scripts){ |
|
496 | + if ($include_completed_scripts) { |
|
497 | 497 | return $this->_last_ran_script; |
498 | - }else{ |
|
498 | + } else { |
|
499 | 499 | return $this->_last_ran_incomplete_script; |
500 | 500 | } |
501 | 501 | } |
@@ -518,19 +518,19 @@ discard block |
||
518 | 518 | * @type string $message string describing what was done during this step |
519 | 519 | * } |
520 | 520 | */ |
521 | - public function migration_step( $step_size = 0 ){ |
|
521 | + public function migration_step($step_size = 0) { |
|
522 | 522 | |
523 | 523 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
524 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
525 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
524 | + if (class_exists('EE_CPT_Strategy')) { |
|
525 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
526 | 526 | } |
527 | 527 | |
528 | - try{ |
|
528 | + try { |
|
529 | 529 | $currently_executing_script = $this->get_last_ran_script(); |
530 | - if( ! $currently_executing_script){ |
|
530 | + if ( ! $currently_executing_script) { |
|
531 | 531 | //Find the next script that needs to execute |
532 | 532 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
533 | - if( ! $scripts ){ |
|
533 | + if ( ! $scripts) { |
|
534 | 534 | //huh, no more scripts to run... apparently we're done! |
535 | 535 | //but dont forget to make sure initial data is there |
536 | 536 | //we should be good to allow them to exit maintenance mode now |
@@ -551,18 +551,18 @@ discard block |
||
551 | 551 | //and add to the array/wp option showing the scripts ran |
552 | 552 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
553 | 553 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
554 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
555 | - $version = $migrates_to[ 'version' ]; |
|
554 | + $plugin_slug = $migrates_to['slug']; |
|
555 | + $version = $migrates_to['version']; |
|
556 | 556 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
557 | 557 | } |
558 | 558 | $current_script_name = get_class($currently_executing_script); |
559 | - }catch(Exception $e){ |
|
559 | + } catch (Exception $e) { |
|
560 | 560 | //an exception occurred while trying to get migration scripts |
561 | 561 | |
562 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
562 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
563 | 563 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
564 | 564 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
565 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
565 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
566 | 566 | return array( |
567 | 567 | 'records_to_migrate'=>1, |
568 | 568 | 'records_migrated'=>0, |
@@ -572,16 +572,16 @@ discard block |
||
572 | 572 | ); |
573 | 573 | } |
574 | 574 | //ok so we definitely have a data migration script |
575 | - try{ |
|
575 | + try { |
|
576 | 576 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
577 | - if( ! absint( $step_size ) > 0 ){ |
|
578 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
577 | + if ( ! absint($step_size) > 0) { |
|
578 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
579 | 579 | } |
580 | 580 | //do what we came to do! |
581 | 581 | $currently_executing_script->migration_step($step_size); |
582 | 582 | //can we wrap it up and verify default data? |
583 | 583 | $init_dbs = false; |
584 | - switch($currently_executing_script->get_status()){ |
|
584 | + switch ($currently_executing_script->get_status()) { |
|
585 | 585 | case EE_Data_Migration_Manager::status_continue: |
586 | 586 | $response_array = array( |
587 | 587 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -593,16 +593,16 @@ discard block |
||
593 | 593 | case EE_Data_Migration_Manager::status_completed: |
594 | 594 | //ok so THAT script has completed |
595 | 595 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
596 | - $response_array = array( |
|
596 | + $response_array = array( |
|
597 | 597 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
598 | 598 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
599 | 599 | 'status'=> EE_Data_Migration_Manager::status_completed, |
600 | 600 | 'message'=>$currently_executing_script->get_feedback_message(), |
601 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
601 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
602 | 602 | ); |
603 | 603 | //check if there are any more after this one. |
604 | 604 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
605 | - if( ! $scripts_remaining ){ |
|
605 | + if ( ! $scripts_remaining) { |
|
606 | 606 | //we should be good to allow them to exit maintenance mode now |
607 | 607 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
608 | 608 | ////huh, no more scripts to run... apparently we're done! |
@@ -616,39 +616,39 @@ discard block |
||
616 | 616 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
617 | 617 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
618 | 618 | 'status'=> $currently_executing_script->get_status(), |
619 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
619 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
620 | 620 | 'script'=>$currently_executing_script->pretty_name() |
621 | 621 | ); |
622 | 622 | break; |
623 | 623 | } |
624 | - }catch(Exception $e){ |
|
624 | + } catch (Exception $e) { |
|
625 | 625 | //ok so some exception was thrown which killed the data migration script |
626 | 626 | //double-check we have a real script |
627 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
627 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
628 | 628 | $script_name = $currently_executing_script->pretty_name(); |
629 | 629 | $currently_executing_script->set_broken(); |
630 | 630 | $currently_executing_script->add_error($e->getMessage()); |
631 | - }else{ |
|
631 | + } else { |
|
632 | 632 | $script_name = __("Error getting Migration Script", "event_espresso"); |
633 | 633 | } |
634 | 634 | $response_array = array( |
635 | 635 | 'records_to_migrate'=>1, |
636 | 636 | 'records_migrated'=>0, |
637 | 637 | 'status'=>self::status_fatal_error, |
638 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
638 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
639 | 639 | 'script'=>$script_name |
640 | 640 | ); |
641 | 641 | } |
642 | 642 | $successful_save = $this->_save_migrations_ran(); |
643 | - if($successful_save !== TRUE){ |
|
643 | + if ($successful_save !== TRUE) { |
|
644 | 644 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
645 | 645 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
646 | 646 | //however, if we throw an exception, and return that, then the next request |
647 | 647 | //won't have as much info in it, and it may be able to save |
648 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
648 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
649 | 649 | } |
650 | 650 | //if we're all done, initialize EE plugins' default data etc. |
651 | - if( $init_dbs ) { |
|
651 | + if ($init_dbs) { |
|
652 | 652 | $this->initialize_db_for_enqueued_ee_plugins(); |
653 | 653 | } |
654 | 654 | return $response_array; |
@@ -666,23 +666,23 @@ discard block |
||
666 | 666 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
667 | 667 | * 'script'=>a pretty name of the script currently running |
668 | 668 | */ |
669 | - public function response_to_migration_ajax_request(){ |
|
669 | + public function response_to_migration_ajax_request() { |
|
670 | 670 | // //start output buffer just to make sure we don't mess up the json |
671 | 671 | ob_start(); |
672 | - try{ |
|
672 | + try { |
|
673 | 673 | $response = $this->migration_step(); |
674 | - }catch(Exception $e){ |
|
674 | + } catch (Exception $e) { |
|
675 | 675 | $response = array( |
676 | 676 | 'records_to_migrate'=>0, |
677 | 677 | 'records_migrated'=>0, |
678 | 678 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
679 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
679 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
680 | 680 | 'script'=>'Unknown'); |
681 | 681 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
682 | 682 | } |
683 | 683 | $warnings_etc = @ob_get_contents(); |
684 | 684 | ob_end_clean(); |
685 | - $response['message'] .=$warnings_etc; |
|
685 | + $response['message'] .= $warnings_etc; |
|
686 | 686 | return $response; |
687 | 687 | } |
688 | 688 | |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | * } |
696 | 696 | * @return void |
697 | 697 | */ |
698 | - public function update_current_database_state_to($slug_and_version = null){ |
|
699 | - if( ! $slug_and_version ){ |
|
698 | + public function update_current_database_state_to($slug_and_version = null) { |
|
699 | + if ( ! $slug_and_version) { |
|
700 | 700 | //no version was provided, assume it should be at the current code version |
701 | 701 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
702 | 702 | } |
703 | 703 | $current_database_state = get_option(self::current_database_state); |
704 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
705 | - update_option(self::current_database_state,$current_database_state); |
|
704 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
705 | + update_option(self::current_database_state, $current_database_state); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -713,20 +713,20 @@ discard block |
||
713 | 713 | * } |
714 | 714 | * @return boolean |
715 | 715 | */ |
716 | - public function database_needs_updating_to( $slug_and_version ) { |
|
716 | + public function database_needs_updating_to($slug_and_version) { |
|
717 | 717 | |
718 | - $slug = $slug_and_version[ 'slug' ]; |
|
719 | - $version = $slug_and_version[ 'version' ]; |
|
718 | + $slug = $slug_and_version['slug']; |
|
719 | + $version = $slug_and_version['version']; |
|
720 | 720 | $current_database_state = get_option(self::current_database_state); |
721 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
721 | + if ( ! isset($current_database_state[$slug])) { |
|
722 | 722 | return true; |
723 | - }else{ |
|
723 | + } else { |
|
724 | 724 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
725 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
726 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
725 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
726 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
727 | 727 | $needs_updating = false; |
728 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
729 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
728 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
729 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
730 | 730 | $needs_updating = true; |
731 | 731 | break; |
732 | 732 | } |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | */ |
749 | 749 | public function get_all_data_migration_scripts_available() |
750 | 750 | { |
751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
751 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
752 | 752 | $this->_data_migration_class_to_filepath_map = array(); |
753 | 753 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
754 | 754 | // strip any placeholders added to classname to make it a unique array key |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | ? $eeAddonClass |
758 | 758 | : ''; |
759 | 759 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
760 | - $files = glob($folder_path . '*.dms.php'); |
|
760 | + $files = glob($folder_path.'*.dms.php'); |
|
761 | 761 | if (empty($files)) { |
762 | 762 | continue; |
763 | 763 | } |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | '4.3.0.alpha.019' |
784 | 784 | ); |
785 | 785 | } |
786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
786 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
787 | 787 | } |
788 | 788 | } |
789 | 789 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | * from each addon, and check if they need updating, |
799 | 799 | * @return boolean |
800 | 800 | */ |
801 | - public function addons_need_updating(){ |
|
801 | + public function addons_need_updating() { |
|
802 | 802 | return false; |
803 | 803 | } |
804 | 804 | /** |
@@ -807,25 +807,25 @@ discard block |
||
807 | 807 | * @param string $error_message |
808 | 808 | * @throws EE_Error |
809 | 809 | */ |
810 | - public function add_error_to_migrations_ran($error_message){ |
|
810 | + public function add_error_to_migrations_ran($error_message) { |
|
811 | 811 | //get last-ran migration script |
812 | 812 | global $wpdb; |
813 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
813 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
814 | 814 | |
815 | 815 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
816 | 816 | //now, tread lightly because we're here because a FATAL non-catchable error |
817 | 817 | //was thrown last time when we were trying to run a data migration script |
818 | 818 | //so the fatal error could have happened while getting the migration script |
819 | 819 | //or doing running it... |
820 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
820 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
821 | 821 | |
822 | 822 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
823 | 823 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
824 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
824 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
825 | 825 | //ok then just add this error to its list of errors |
826 | 826 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
827 | 827 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
828 | - }else{ |
|
828 | + } else { |
|
829 | 829 | //so we don't even know which script was last running |
830 | 830 | //use the data migration error stub, which is designed specifically for this type of thing |
831 | 831 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -835,39 +835,39 @@ discard block |
||
835 | 835 | $versions_migrated_to = 'Unknown.1.0.0'; |
836 | 836 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
837 | 837 | //delete the old one |
838 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
838 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
839 | 839 | } |
840 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
840 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
841 | 841 | |
842 | 842 | } |
843 | 843 | /** |
844 | 844 | * saves what data migrations have ran to the database |
845 | 845 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
846 | 846 | */ |
847 | - protected function _save_migrations_ran(){ |
|
848 | - if($this->_data_migrations_ran == null){ |
|
847 | + protected function _save_migrations_ran() { |
|
848 | + if ($this->_data_migrations_ran == null) { |
|
849 | 849 | $this->get_data_migrations_ran(); |
850 | 850 | } |
851 | 851 | //now, we don't want to save actual classes to the DB because that's messy |
852 | 852 | $successful_updates = true; |
853 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
854 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
853 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
854 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
855 | 855 | // echo "saving migration script to $version_string<br>"; |
856 | 856 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
857 | 857 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
858 | 858 | $old_option_value = get_option($option_name); |
859 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
859 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
860 | 860 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
861 | - if( $old_option_value != $script_array_for_saving){ |
|
862 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
861 | + if ($old_option_value != $script_array_for_saving) { |
|
862 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
863 | 863 | } |
864 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
864 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
865 | 865 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
866 | - if($old_option_value != $array_or_migration_obj){ |
|
867 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
866 | + if ($old_option_value != $array_or_migration_obj) { |
|
867 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
868 | 868 | } |
869 | 869 | } |
870 | - if( ! $successful_updates ){ |
|
870 | + if ( ! $successful_updates) { |
|
871 | 871 | global $wpdb; |
872 | 872 | return $wpdb->last_error; |
873 | 873 | } |
@@ -891,17 +891,17 @@ discard block |
||
891 | 891 | * @return EE_Data_Migration_Script_Base |
892 | 892 | * @throws EE_Error |
893 | 893 | */ |
894 | - function _instantiate_script_from_properties_array($properties_array){ |
|
895 | - if( ! isset($properties_array['class'])){ |
|
896 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
894 | + function _instantiate_script_from_properties_array($properties_array) { |
|
895 | + if ( ! isset($properties_array['class'])) { |
|
896 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
897 | 897 | } |
898 | 898 | $class_name = $properties_array['class']; |
899 | - if( ! class_exists($class_name)){ |
|
900 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
899 | + if ( ! class_exists($class_name)) { |
|
900 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
901 | 901 | } |
902 | 902 | $class = new $class_name; |
903 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
904 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
903 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
904 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
905 | 905 | } |
906 | 906 | $class->instantiate_from_array_of_properties($properties_array); |
907 | 907 | return $class; |
@@ -913,25 +913,25 @@ discard block |
||
913 | 913 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
914 | 914 | * @return string |
915 | 915 | */ |
916 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
916 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
917 | 917 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
918 | 918 | $most_up_to_date_dms_classname = NULL; |
919 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
920 | - if($most_up_to_date_dms_classname === NULL){ |
|
919 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
920 | + if ($most_up_to_date_dms_classname === NULL) { |
|
921 | 921 | $migrates_to = $this->script_migrates_to_version($classname); |
922 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
922 | + $this_plugin_slug = $migrates_to['slug']; |
|
923 | 923 | // $version_string = $migrates_to[ 'version' ]; |
924 | 924 | // $details = $this->parse_dms_classname($classname); |
925 | - if($this_plugin_slug == $plugin_slug){ |
|
925 | + if ($this_plugin_slug == $plugin_slug) { |
|
926 | 926 | //if it's for core, it wins |
927 | 927 | $most_up_to_date_dms_classname = $classname; |
928 | 928 | } |
929 | 929 | //if it wasn't for core, we must keep searching for one that is! |
930 | 930 | continue; |
931 | - }else{ |
|
932 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
931 | + } else { |
|
932 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
933 | 933 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
934 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
934 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
935 | 935 | //so the contenders version is higher and its for Core |
936 | 936 | $most_up_to_date_dms_classname = $classname; |
937 | 937 | } |
@@ -951,11 +951,11 @@ discard block |
||
951 | 951 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
952 | 952 | * @return EE_Data_Migration_Script_Base |
953 | 953 | */ |
954 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
954 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
955 | 955 | $migrations_ran = $this->get_data_migrations_ran(); |
956 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
957 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
958 | - }else{ |
|
956 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
957 | + return $migrations_ran[$plugin_slug][$version]; |
|
958 | + } else { |
|
959 | 959 | return NULL; |
960 | 960 | } |
961 | 961 | } |
@@ -967,20 +967,20 @@ discard block |
||
967 | 967 | * @return bool |
968 | 968 | * @throws EE_Error |
969 | 969 | */ |
970 | - public function reattempt(){ |
|
970 | + public function reattempt() { |
|
971 | 971 | //find if the last-ran script was borked |
972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
973 | 973 | //add an 'error' saying that we attempted to reset |
974 | 974 | //does it have a stage that was borked too? if so make it no longer borked |
975 | 975 | //add an 'error' saying we attempted to reset |
976 | 976 | $last_ran_script = $this->get_last_ran_script(); |
977 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
977 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
978 | 978 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
979 | 979 | $last_ran_script->set_completed(); |
980 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
980 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
981 | 981 | $last_ran_script->reattempt(); |
982 | - }else{ |
|
983 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
982 | + } else { |
|
983 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
984 | 984 | } |
985 | 985 | return $this->_save_migrations_ran(); |
986 | 986 | } |
@@ -990,19 +990,19 @@ discard block |
||
990 | 990 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
991 | 991 | * @return boolean |
992 | 992 | */ |
993 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
994 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
993 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
994 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
995 | 995 | } |
996 | 996 | /** |
997 | 997 | * Enqueues this ee plugin to have its data initialized |
998 | 998 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
999 | 999 | */ |
1000 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
1000 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
1001 | 1001 | $queue = $this->get_db_initialization_queue(); |
1002 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
1002 | + if ( ! in_array($plugin_slug, $queue)) { |
|
1003 | 1003 | $queue[] = $plugin_slug; |
1004 | 1004 | } |
1005 | - update_option( self::db_init_queue_option_name, $queue ); |
|
1005 | + update_option(self::db_init_queue_option_name, $queue); |
|
1006 | 1006 | } |
1007 | 1007 | /** |
1008 | 1008 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -1012,26 +1012,26 @@ discard block |
||
1012 | 1012 | public function initialize_db_for_enqueued_ee_plugins() { |
1013 | 1013 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
1014 | 1014 | $queue = $this->get_db_initialization_queue(); |
1015 | - foreach( $queue as $plugin_slug ) { |
|
1016 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
1017 | - if( ! $most_up_to_date_dms ) { |
|
1015 | + foreach ($queue as $plugin_slug) { |
|
1016 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
1017 | + if ( ! $most_up_to_date_dms) { |
|
1018 | 1018 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
1019 | 1019 | $verify_db = false; |
1020 | - }else{ |
|
1021 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
1022 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
1020 | + } else { |
|
1021 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1022 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1023 | 1023 | } |
1024 | - if( $plugin_slug == 'Core' ){ |
|
1024 | + if ($plugin_slug == 'Core') { |
|
1025 | 1025 | EE_System::instance()->initialize_db_if_no_migrations_required( |
1026 | 1026 | false, |
1027 | 1027 | $verify_db |
1028 | 1028 | ); |
1029 | - }else{ |
|
1029 | + } else { |
|
1030 | 1030 | //just loop through the addons to make sure their database is setup |
1031 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
1032 | - if( $addon->name() == $plugin_slug ) { |
|
1031 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
1032 | + if ($addon->name() == $plugin_slug) { |
|
1033 | 1033 | |
1034 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
1034 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1035 | 1035 | break; |
1036 | 1036 | } |
1037 | 1037 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | // EEH_Debug_Tools::instance()->show_times(); |
1042 | 1042 | //because we just initialized the DBs for the enqueued ee plugins |
1043 | 1043 | //we don't need to keep remembering which ones needed to be initialized |
1044 | - delete_option( self::db_init_queue_option_name ); |
|
1044 | + delete_option(self::db_init_queue_option_name); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | /** |
@@ -1050,8 +1050,8 @@ discard block |
||
1050 | 1050 | * 'Core', or the return value of EE_Addon::name() for an addon |
1051 | 1051 | * @return array |
1052 | 1052 | */ |
1053 | - public function get_db_initialization_queue(){ |
|
1054 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
1053 | + public function get_db_initialization_queue() { |
|
1054 | + return get_option(self::db_init_queue_option_name, array()); |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | /** |
@@ -1061,13 +1061,13 @@ discard block |
||
1061 | 1061 | * @throws EE_Error |
1062 | 1062 | */ |
1063 | 1063 | protected function _get_table_analysis() { |
1064 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
1064 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
1065 | 1065 | return $this->_table_analysis; |
1066 | 1066 | } else { |
1067 | 1067 | throw new EE_Error( |
1068 | 1068 | sprintf( |
1069 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1070 | - get_class( $this ) |
|
1069 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1070 | + get_class($this) |
|
1071 | 1071 | ) |
1072 | 1072 | ); |
1073 | 1073 | } |
@@ -1080,13 +1080,13 @@ discard block |
||
1080 | 1080 | * @throws EE_Error |
1081 | 1081 | */ |
1082 | 1082 | protected function _get_table_manager() { |
1083 | - if( $this->_table_manager instanceof TableManager ) { |
|
1083 | + if ($this->_table_manager instanceof TableManager) { |
|
1084 | 1084 | return $this->_table_manager; |
1085 | 1085 | } else { |
1086 | 1086 | throw new EE_Error( |
1087 | 1087 | sprintf( |
1088 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1089 | - get_class( $this ) |
|
1088 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1089 | + get_class($this) |
|
1090 | 1090 | ) |
1091 | 1091 | ); |
1092 | 1092 | } |
@@ -25,1152 +25,1152 @@ |
||
25 | 25 | class EE_Register_Addon implements EEI_Plugin_API |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * possibly truncated version of the EE core version string |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected static $_core_version = ''; |
|
28 | + /** |
|
29 | + * possibly truncated version of the EE core version string |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected static $_core_version = ''; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Holds values for registered addons |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected static $_settings = array(); |
|
35 | + /** |
|
36 | + * Holds values for registered addons |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected static $_settings = array(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | - * EE core with knowledge of ALL the addons out there. |
|
48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | - * minimum plugin version. |
|
52 | - * @access protected |
|
53 | - */ |
|
54 | - protected static $_incompatible_addons = array( |
|
55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | - 'Promotions' => '1.0.0.rc.084', |
|
57 | - ); |
|
42 | + /** |
|
43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | + * EE core with knowledge of ALL the addons out there. |
|
48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | + * minimum plugin version. |
|
52 | + * @access protected |
|
53 | + */ |
|
54 | + protected static $_incompatible_addons = array( |
|
55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | + 'Promotions' => '1.0.0.rc.084', |
|
57 | + ); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | - * not just '4.3.0'. |
|
63 | - * So if the addon developer doesn't provide that full version string, |
|
64 | - * fill in the blanks for them |
|
65 | - * |
|
66 | - * @param string $min_core_version |
|
67 | - * @return string always like '4.3.0.rc.000' |
|
68 | - */ |
|
69 | - protected static function _effective_version($min_core_version) |
|
70 | - { |
|
71 | - // versions: 4 . 3 . 1 . p . 123 |
|
72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | - $version_parts = explode('.', $min_core_version); |
|
74 | - //check they specified the micro version (after 2nd period) |
|
75 | - if (! isset($version_parts[2])) { |
|
76 | - $version_parts[2] = '0'; |
|
77 | - } |
|
78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | - if (! isset($version_parts[3])) { |
|
81 | - $version_parts[3] = 'dev'; |
|
82 | - } |
|
83 | - if (! isset($version_parts[4])) { |
|
84 | - $version_parts[4] = '000'; |
|
85 | - } |
|
86 | - return implode('.', $version_parts); |
|
87 | - } |
|
60 | + /** |
|
61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | + * not just '4.3.0'. |
|
63 | + * So if the addon developer doesn't provide that full version string, |
|
64 | + * fill in the blanks for them |
|
65 | + * |
|
66 | + * @param string $min_core_version |
|
67 | + * @return string always like '4.3.0.rc.000' |
|
68 | + */ |
|
69 | + protected static function _effective_version($min_core_version) |
|
70 | + { |
|
71 | + // versions: 4 . 3 . 1 . p . 123 |
|
72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | + $version_parts = explode('.', $min_core_version); |
|
74 | + //check they specified the micro version (after 2nd period) |
|
75 | + if (! isset($version_parts[2])) { |
|
76 | + $version_parts[2] = '0'; |
|
77 | + } |
|
78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | + if (! isset($version_parts[3])) { |
|
81 | + $version_parts[3] = 'dev'; |
|
82 | + } |
|
83 | + if (! isset($version_parts[4])) { |
|
84 | + $version_parts[4] = '000'; |
|
85 | + } |
|
86 | + return implode('.', $version_parts); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Returns whether or not the min core version requirement of the addon is met |
|
92 | - * |
|
93 | - * @param string $min_core_version the minimum core version required by the addon |
|
94 | - * @param string $actual_core_version the actual core version, optional |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public static function _meets_min_core_version_requirement( |
|
98 | - $min_core_version, |
|
99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | - ) { |
|
101 | - return version_compare( |
|
102 | - self::_effective_version($actual_core_version), |
|
103 | - self::_effective_version($min_core_version), |
|
104 | - '>=' |
|
105 | - ); |
|
106 | - } |
|
90 | + /** |
|
91 | + * Returns whether or not the min core version requirement of the addon is met |
|
92 | + * |
|
93 | + * @param string $min_core_version the minimum core version required by the addon |
|
94 | + * @param string $actual_core_version the actual core version, optional |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public static function _meets_min_core_version_requirement( |
|
98 | + $min_core_version, |
|
99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | + ) { |
|
101 | + return version_compare( |
|
102 | + self::_effective_version($actual_core_version), |
|
103 | + self::_effective_version($min_core_version), |
|
104 | + '>=' |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Method for registering new EE_Addons. |
|
111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | - * |
|
120 | - * @since 4.3.0 |
|
121 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
122 | - * @param array $setup_args { |
|
123 | - * An array of arguments provided for registering |
|
124 | - * the message type. |
|
125 | - * @type string $class_name the addon's main file name. |
|
126 | - * If left blank, generated from the addon name, |
|
127 | - * changes something like "calendar" to |
|
128 | - * "EE_Calendar" |
|
129 | - * @type string $min_core_version the minimum version of EE Core that the |
|
130 | - * addon will work with. eg "4.8.1.rc.084" |
|
131 | - * @type string $version the "software" version for the addon. eg |
|
132 | - * "1.0.0.p" for a first stable release, or |
|
133 | - * "1.0.0.rc.043" for a version in progress |
|
134 | - * @type string $main_file_path the full server path to the main file |
|
135 | - * loaded directly by WP |
|
136 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
137 | - * for the addon's Domain class |
|
138 | - * (see EventEspresso\core\domain\Domain) |
|
139 | - * @type string $admin_path full server path to the folder where the |
|
140 | - * addon\'s admin files reside |
|
141 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
142 | - * first invoked, can be used for hooking into |
|
143 | - * any admin page |
|
144 | - * @type string $config_section the section name for this addon's |
|
145 | - * configuration settings section |
|
146 | - * (defaults to "addons") |
|
147 | - * @type string $config_class the class name for this addon's |
|
148 | - * configuration settings object |
|
149 | - * @type string $config_name the class name for this addon's |
|
150 | - * configuration settings object |
|
151 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
152 | - * server paths to those files. |
|
153 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
154 | - * folders containing classes that might be |
|
155 | - * invoked by the addon |
|
156 | - * @type string $dms_paths [Required] an array of full server paths to |
|
157 | - * folders that contain data migration scripts. |
|
158 | - * The key should be the EE_Addon class name that |
|
159 | - * this set of data migration scripts belongs to. |
|
160 | - * If the EE_Addon class is namespaced, then this |
|
161 | - * needs to be the Fully Qualified Class Name |
|
162 | - * @type string $module_paths an array of full server paths to any |
|
163 | - * EED_Modules used by the addon |
|
164 | - * @type string $shortcode_paths an array of full server paths to folders |
|
165 | - * that contain EES_Shortcodes |
|
166 | - * @type string $widget_paths an array of full server paths to folders |
|
167 | - * that contain WP_Widgets |
|
168 | - * @type string $pue_options |
|
169 | - * @type array $capabilities an array indexed by role name |
|
170 | - * (i.e administrator,author ) and the values |
|
171 | - * are an array of caps to add to the role. |
|
172 | - * 'administrator' => array( |
|
173 | - * 'read_addon', |
|
174 | - * 'edit_addon', |
|
175 | - * etc. |
|
176 | - * ). |
|
177 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
178 | - * for any addons that need to register any |
|
179 | - * special meta mapped capabilities. Should |
|
180 | - * be indexed where the key is the |
|
181 | - * EE_Meta_Capability_Map class name and the |
|
182 | - * values are the arguments sent to the class. |
|
183 | - * @type array $model_paths array of folders containing DB models |
|
184 | - * @see EE_Register_Model |
|
185 | - * @type array $class_paths array of folders containing DB classes |
|
186 | - * @see EE_Register_Model |
|
187 | - * @type array $model_extension_paths array of folders containing DB model |
|
188 | - * extensions |
|
189 | - * @see EE_Register_Model_Extension |
|
190 | - * @type array $class_extension_paths array of folders containing DB class |
|
191 | - * extensions |
|
192 | - * @see EE_Register_Model_Extension |
|
193 | - * @type array message_types { |
|
194 | - * An array of message types with the key as |
|
195 | - * the message type name and the values as |
|
196 | - * below: |
|
197 | - * @type string $mtfilename [Required] The filename of the message type |
|
198 | - * being registered. This will be the main |
|
199 | - * EE_{Message Type Name}_message_type class. |
|
200 | - * for example: |
|
201 | - * EE_Declined_Registration_message_type.class.php |
|
202 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
203 | - * messages autoloader for the new message type. |
|
204 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
205 | - * type should activate with. Each value in |
|
206 | - * the |
|
207 | - * array |
|
208 | - * should match the name property of a |
|
209 | - * EE_messenger. Optional. |
|
210 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
211 | - * type should validate with. Each value in |
|
212 | - * the |
|
213 | - * array |
|
214 | - * should match the name property of an |
|
215 | - * EE_messenger. |
|
216 | - * Optional. |
|
217 | - * } |
|
218 | - * @type array $custom_post_types |
|
219 | - * @type array $custom_taxonomies |
|
220 | - * @type array $payment_method_paths each element is the folder containing the |
|
221 | - * EE_PMT_Base child class |
|
222 | - * (eg, |
|
223 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
224 | - * which contains the files |
|
225 | - * EE_PMT_Payomatic.pm.php) |
|
226 | - * @type array $default_terms |
|
227 | - * @type array $namespace { |
|
228 | - * An array with two items for registering the |
|
229 | - * addon's namespace. (If, for some reason, you |
|
230 | - * require additional namespaces, |
|
231 | - * use |
|
232 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
233 | - * directly) |
|
234 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
235 | - * @type string $FQNS the namespace prefix |
|
236 | - * @type string $DIR a base directory for class files in the |
|
237 | - * namespace. |
|
238 | - * } |
|
239 | - * } |
|
240 | - * @return void |
|
241 | - * @throws DomainException |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws ReflectionException |
|
245 | - * @throws InvalidDataTypeException |
|
246 | - * @throws InvalidInterfaceException |
|
247 | - */ |
|
248 | - public static function register($addon_name = '', $setup_args = array()) |
|
249 | - { |
|
250 | - // required fields MUST be present, so let's make sure they are. |
|
251 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
252 | - // get class name for addon |
|
253 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
254 | - //setup $_settings array from incoming values. |
|
255 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
256 | - // setup PUE |
|
257 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
258 | - // does this addon work with this version of core or WordPress ? |
|
259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
260 | - return; |
|
261 | - } |
|
262 | - // register namespaces |
|
263 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
264 | - // check if this is an activation request |
|
265 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
266 | - // dont bother setting up the rest of the addon atm |
|
267 | - return; |
|
268 | - } |
|
269 | - // we need cars |
|
270 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
271 | - // register new models and extensions |
|
272 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
273 | - // setup DMS |
|
274 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
275 | - // if config_class is present let's register config. |
|
276 | - EE_Register_Addon::_register_config($addon_name); |
|
277 | - // register admin pages |
|
278 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
279 | - // add to list of modules to be registered |
|
280 | - EE_Register_Addon::_register_modules($addon_name); |
|
281 | - // add to list of shortcodes to be registered |
|
282 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
283 | - // add to list of widgets to be registered |
|
284 | - EE_Register_Addon::_register_widgets($addon_name); |
|
285 | - // register capability related stuff. |
|
286 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
287 | - // any message type to register? |
|
288 | - EE_Register_Addon::_register_message_types($addon_name); |
|
289 | - // any custom post type/ custom capabilities or default terms to register |
|
290 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
291 | - // and any payment methods |
|
292 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
293 | - // load and instantiate main addon class |
|
294 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
295 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
296 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
297 | - } |
|
109 | + /** |
|
110 | + * Method for registering new EE_Addons. |
|
111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | + * |
|
120 | + * @since 4.3.0 |
|
121 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
122 | + * @param array $setup_args { |
|
123 | + * An array of arguments provided for registering |
|
124 | + * the message type. |
|
125 | + * @type string $class_name the addon's main file name. |
|
126 | + * If left blank, generated from the addon name, |
|
127 | + * changes something like "calendar" to |
|
128 | + * "EE_Calendar" |
|
129 | + * @type string $min_core_version the minimum version of EE Core that the |
|
130 | + * addon will work with. eg "4.8.1.rc.084" |
|
131 | + * @type string $version the "software" version for the addon. eg |
|
132 | + * "1.0.0.p" for a first stable release, or |
|
133 | + * "1.0.0.rc.043" for a version in progress |
|
134 | + * @type string $main_file_path the full server path to the main file |
|
135 | + * loaded directly by WP |
|
136 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
137 | + * for the addon's Domain class |
|
138 | + * (see EventEspresso\core\domain\Domain) |
|
139 | + * @type string $admin_path full server path to the folder where the |
|
140 | + * addon\'s admin files reside |
|
141 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
142 | + * first invoked, can be used for hooking into |
|
143 | + * any admin page |
|
144 | + * @type string $config_section the section name for this addon's |
|
145 | + * configuration settings section |
|
146 | + * (defaults to "addons") |
|
147 | + * @type string $config_class the class name for this addon's |
|
148 | + * configuration settings object |
|
149 | + * @type string $config_name the class name for this addon's |
|
150 | + * configuration settings object |
|
151 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
152 | + * server paths to those files. |
|
153 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
154 | + * folders containing classes that might be |
|
155 | + * invoked by the addon |
|
156 | + * @type string $dms_paths [Required] an array of full server paths to |
|
157 | + * folders that contain data migration scripts. |
|
158 | + * The key should be the EE_Addon class name that |
|
159 | + * this set of data migration scripts belongs to. |
|
160 | + * If the EE_Addon class is namespaced, then this |
|
161 | + * needs to be the Fully Qualified Class Name |
|
162 | + * @type string $module_paths an array of full server paths to any |
|
163 | + * EED_Modules used by the addon |
|
164 | + * @type string $shortcode_paths an array of full server paths to folders |
|
165 | + * that contain EES_Shortcodes |
|
166 | + * @type string $widget_paths an array of full server paths to folders |
|
167 | + * that contain WP_Widgets |
|
168 | + * @type string $pue_options |
|
169 | + * @type array $capabilities an array indexed by role name |
|
170 | + * (i.e administrator,author ) and the values |
|
171 | + * are an array of caps to add to the role. |
|
172 | + * 'administrator' => array( |
|
173 | + * 'read_addon', |
|
174 | + * 'edit_addon', |
|
175 | + * etc. |
|
176 | + * ). |
|
177 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
178 | + * for any addons that need to register any |
|
179 | + * special meta mapped capabilities. Should |
|
180 | + * be indexed where the key is the |
|
181 | + * EE_Meta_Capability_Map class name and the |
|
182 | + * values are the arguments sent to the class. |
|
183 | + * @type array $model_paths array of folders containing DB models |
|
184 | + * @see EE_Register_Model |
|
185 | + * @type array $class_paths array of folders containing DB classes |
|
186 | + * @see EE_Register_Model |
|
187 | + * @type array $model_extension_paths array of folders containing DB model |
|
188 | + * extensions |
|
189 | + * @see EE_Register_Model_Extension |
|
190 | + * @type array $class_extension_paths array of folders containing DB class |
|
191 | + * extensions |
|
192 | + * @see EE_Register_Model_Extension |
|
193 | + * @type array message_types { |
|
194 | + * An array of message types with the key as |
|
195 | + * the message type name and the values as |
|
196 | + * below: |
|
197 | + * @type string $mtfilename [Required] The filename of the message type |
|
198 | + * being registered. This will be the main |
|
199 | + * EE_{Message Type Name}_message_type class. |
|
200 | + * for example: |
|
201 | + * EE_Declined_Registration_message_type.class.php |
|
202 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
203 | + * messages autoloader for the new message type. |
|
204 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
205 | + * type should activate with. Each value in |
|
206 | + * the |
|
207 | + * array |
|
208 | + * should match the name property of a |
|
209 | + * EE_messenger. Optional. |
|
210 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
211 | + * type should validate with. Each value in |
|
212 | + * the |
|
213 | + * array |
|
214 | + * should match the name property of an |
|
215 | + * EE_messenger. |
|
216 | + * Optional. |
|
217 | + * } |
|
218 | + * @type array $custom_post_types |
|
219 | + * @type array $custom_taxonomies |
|
220 | + * @type array $payment_method_paths each element is the folder containing the |
|
221 | + * EE_PMT_Base child class |
|
222 | + * (eg, |
|
223 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
224 | + * which contains the files |
|
225 | + * EE_PMT_Payomatic.pm.php) |
|
226 | + * @type array $default_terms |
|
227 | + * @type array $namespace { |
|
228 | + * An array with two items for registering the |
|
229 | + * addon's namespace. (If, for some reason, you |
|
230 | + * require additional namespaces, |
|
231 | + * use |
|
232 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
233 | + * directly) |
|
234 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
235 | + * @type string $FQNS the namespace prefix |
|
236 | + * @type string $DIR a base directory for class files in the |
|
237 | + * namespace. |
|
238 | + * } |
|
239 | + * } |
|
240 | + * @return void |
|
241 | + * @throws DomainException |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws ReflectionException |
|
245 | + * @throws InvalidDataTypeException |
|
246 | + * @throws InvalidInterfaceException |
|
247 | + */ |
|
248 | + public static function register($addon_name = '', $setup_args = array()) |
|
249 | + { |
|
250 | + // required fields MUST be present, so let's make sure they are. |
|
251 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
252 | + // get class name for addon |
|
253 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
254 | + //setup $_settings array from incoming values. |
|
255 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
256 | + // setup PUE |
|
257 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
258 | + // does this addon work with this version of core or WordPress ? |
|
259 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
260 | + return; |
|
261 | + } |
|
262 | + // register namespaces |
|
263 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
264 | + // check if this is an activation request |
|
265 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
266 | + // dont bother setting up the rest of the addon atm |
|
267 | + return; |
|
268 | + } |
|
269 | + // we need cars |
|
270 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
271 | + // register new models and extensions |
|
272 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
273 | + // setup DMS |
|
274 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
275 | + // if config_class is present let's register config. |
|
276 | + EE_Register_Addon::_register_config($addon_name); |
|
277 | + // register admin pages |
|
278 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
279 | + // add to list of modules to be registered |
|
280 | + EE_Register_Addon::_register_modules($addon_name); |
|
281 | + // add to list of shortcodes to be registered |
|
282 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
283 | + // add to list of widgets to be registered |
|
284 | + EE_Register_Addon::_register_widgets($addon_name); |
|
285 | + // register capability related stuff. |
|
286 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
287 | + // any message type to register? |
|
288 | + EE_Register_Addon::_register_message_types($addon_name); |
|
289 | + // any custom post type/ custom capabilities or default terms to register |
|
290 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
291 | + // and any payment methods |
|
292 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
293 | + // load and instantiate main addon class |
|
294 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
295 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
296 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
297 | + } |
|
298 | 298 | |
299 | 299 | |
300 | - /** |
|
301 | - * @param string $addon_name |
|
302 | - * @param array $setup_args |
|
303 | - * @return void |
|
304 | - * @throws EE_Error |
|
305 | - */ |
|
306 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
307 | - { |
|
308 | - // required fields MUST be present, so let's make sure they are. |
|
309 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
310 | - throw new EE_Error( |
|
311 | - __( |
|
312 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
313 | - 'event_espresso' |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
318 | - throw new EE_Error( |
|
319 | - sprintf( |
|
320 | - __( |
|
321 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
322 | - 'event_espresso' |
|
323 | - ), |
|
324 | - implode(',', array_keys($setup_args)) |
|
325 | - ) |
|
326 | - ); |
|
327 | - } |
|
328 | - // check that addon has not already been registered with that name |
|
329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
330 | - throw new EE_Error( |
|
331 | - sprintf( |
|
332 | - __( |
|
333 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
334 | - 'event_espresso' |
|
335 | - ), |
|
336 | - $addon_name |
|
337 | - ) |
|
338 | - ); |
|
339 | - } |
|
340 | - } |
|
300 | + /** |
|
301 | + * @param string $addon_name |
|
302 | + * @param array $setup_args |
|
303 | + * @return void |
|
304 | + * @throws EE_Error |
|
305 | + */ |
|
306 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
307 | + { |
|
308 | + // required fields MUST be present, so let's make sure they are. |
|
309 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
310 | + throw new EE_Error( |
|
311 | + __( |
|
312 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
313 | + 'event_espresso' |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
318 | + throw new EE_Error( |
|
319 | + sprintf( |
|
320 | + __( |
|
321 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
322 | + 'event_espresso' |
|
323 | + ), |
|
324 | + implode(',', array_keys($setup_args)) |
|
325 | + ) |
|
326 | + ); |
|
327 | + } |
|
328 | + // check that addon has not already been registered with that name |
|
329 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
330 | + throw new EE_Error( |
|
331 | + sprintf( |
|
332 | + __( |
|
333 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
334 | + 'event_espresso' |
|
335 | + ), |
|
336 | + $addon_name |
|
337 | + ) |
|
338 | + ); |
|
339 | + } |
|
340 | + } |
|
341 | 341 | |
342 | 342 | |
343 | - /** |
|
344 | - * @param string $addon_name |
|
345 | - * @param array $setup_args |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
349 | - { |
|
350 | - if (empty($setup_args['class_name'])) { |
|
351 | - // generate one by first separating name with spaces |
|
352 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
353 | - //capitalize, then replace spaces with underscores |
|
354 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
355 | - } else { |
|
356 | - $class_name = $setup_args['class_name']; |
|
357 | - } |
|
358 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
359 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
360 | - ? $class_name |
|
361 | - : 'EE_' . $class_name; |
|
362 | - } |
|
343 | + /** |
|
344 | + * @param string $addon_name |
|
345 | + * @param array $setup_args |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
349 | + { |
|
350 | + if (empty($setup_args['class_name'])) { |
|
351 | + // generate one by first separating name with spaces |
|
352 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
353 | + //capitalize, then replace spaces with underscores |
|
354 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
355 | + } else { |
|
356 | + $class_name = $setup_args['class_name']; |
|
357 | + } |
|
358 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
359 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
360 | + ? $class_name |
|
361 | + : 'EE_' . $class_name; |
|
362 | + } |
|
363 | 363 | |
364 | 364 | |
365 | - /** |
|
366 | - * @param string $class_name |
|
367 | - * @param array $setup_args |
|
368 | - * @return array |
|
369 | - */ |
|
370 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
371 | - { |
|
372 | - //setup $_settings array from incoming values. |
|
373 | - $addon_settings = array( |
|
374 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
375 | - 'class_name' => $class_name, |
|
376 | - // the addon slug for use in URLs, etc |
|
377 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
378 | - ? (string) $setup_args['plugin_slug'] |
|
379 | - : '', |
|
380 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
381 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
382 | - ? (string) $setup_args['plugin_action_slug'] |
|
383 | - : '', |
|
384 | - // the "software" version for the addon |
|
385 | - 'version' => isset($setup_args['version']) |
|
386 | - ? (string) $setup_args['version'] |
|
387 | - : '', |
|
388 | - // the minimum version of EE Core that the addon will work with |
|
389 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
390 | - ? (string) $setup_args['min_core_version'] |
|
391 | - : '', |
|
392 | - // the minimum version of WordPress that the addon will work with |
|
393 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
394 | - ? (string) $setup_args['min_wp_version'] |
|
395 | - : EE_MIN_WP_VER_REQUIRED, |
|
396 | - // full server path to main file (file loaded directly by WP) |
|
397 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
398 | - ? (string) $setup_args['main_file_path'] |
|
399 | - : '', |
|
400 | - // Fully Qualified Class Name for the addon's Domain class |
|
401 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
402 | - ? (string) $setup_args['domain_fqcn'] |
|
403 | - : '', |
|
404 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
405 | - 'admin_path' => isset($setup_args['admin_path']) |
|
406 | - ? (string) $setup_args['admin_path'] : '', |
|
407 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
408 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
409 | - ? (string) $setup_args['admin_callback'] |
|
410 | - : '', |
|
411 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
412 | - 'config_section' => isset($setup_args['config_section']) |
|
413 | - ? (string) $setup_args['config_section'] |
|
414 | - : 'addons', |
|
415 | - // the class name for this addon's configuration settings object |
|
416 | - 'config_class' => isset($setup_args['config_class']) |
|
417 | - ? (string) $setup_args['config_class'] : '', |
|
418 | - //the name given to the config for this addons' configuration settings object (optional) |
|
419 | - 'config_name' => isset($setup_args['config_name']) |
|
420 | - ? (string) $setup_args['config_name'] : '', |
|
421 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
422 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
423 | - ? (array) $setup_args['autoloader_paths'] |
|
424 | - : array(), |
|
425 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
426 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
427 | - ? (array) $setup_args['autoloader_folders'] |
|
428 | - : array(), |
|
429 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
430 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
431 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
432 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
433 | - ? (array) $setup_args['dms_paths'] |
|
434 | - : array(), |
|
435 | - // array of full server paths to any EED_Modules used by the addon |
|
436 | - 'module_paths' => isset($setup_args['module_paths']) |
|
437 | - ? (array) $setup_args['module_paths'] |
|
438 | - : array(), |
|
439 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
440 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
441 | - ? (array) $setup_args['shortcode_paths'] |
|
442 | - : array(), |
|
443 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
444 | - ? (array) $setup_args['shortcode_fqcns'] |
|
445 | - : array(), |
|
446 | - // array of full server paths to any WP_Widgets used by the addon |
|
447 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
448 | - ? (array) $setup_args['widget_paths'] |
|
449 | - : array(), |
|
450 | - // array of PUE options used by the addon |
|
451 | - 'pue_options' => isset($setup_args['pue_options']) |
|
452 | - ? (array) $setup_args['pue_options'] |
|
453 | - : array(), |
|
454 | - 'message_types' => isset($setup_args['message_types']) |
|
455 | - ? (array) $setup_args['message_types'] |
|
456 | - : array(), |
|
457 | - 'capabilities' => isset($setup_args['capabilities']) |
|
458 | - ? (array) $setup_args['capabilities'] |
|
459 | - : array(), |
|
460 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
461 | - ? (array) $setup_args['capability_maps'] |
|
462 | - : array(), |
|
463 | - 'model_paths' => isset($setup_args['model_paths']) |
|
464 | - ? (array) $setup_args['model_paths'] |
|
465 | - : array(), |
|
466 | - 'class_paths' => isset($setup_args['class_paths']) |
|
467 | - ? (array) $setup_args['class_paths'] |
|
468 | - : array(), |
|
469 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
470 | - ? (array) $setup_args['model_extension_paths'] |
|
471 | - : array(), |
|
472 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
473 | - ? (array) $setup_args['class_extension_paths'] |
|
474 | - : array(), |
|
475 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
476 | - ? (array) $setup_args['custom_post_types'] |
|
477 | - : array(), |
|
478 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
479 | - ? (array) $setup_args['custom_taxonomies'] |
|
480 | - : array(), |
|
481 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
482 | - ? (array) $setup_args['payment_method_paths'] |
|
483 | - : array(), |
|
484 | - 'default_terms' => isset($setup_args['default_terms']) |
|
485 | - ? (array) $setup_args['default_terms'] |
|
486 | - : array(), |
|
487 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
488 | - // that can be used for adding upgrading/marketing info |
|
489 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
490 | - ? $setup_args['plugins_page_row'] |
|
491 | - : '', |
|
492 | - 'namespace' => isset( |
|
493 | - $setup_args['namespace']['FQNS'], |
|
494 | - $setup_args['namespace']['DIR'] |
|
495 | - ) |
|
496 | - ? (array) $setup_args['namespace'] |
|
497 | - : array(), |
|
498 | - ); |
|
499 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
500 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
501 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
502 | - && ! empty($addon_settings['admin_path']) |
|
503 | - ? $addon_settings['plugin_slug'] |
|
504 | - : $addon_settings['plugin_action_slug']; |
|
505 | - // full server path to main file (file loaded directly by WP) |
|
506 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
507 | - return $addon_settings; |
|
508 | - } |
|
365 | + /** |
|
366 | + * @param string $class_name |
|
367 | + * @param array $setup_args |
|
368 | + * @return array |
|
369 | + */ |
|
370 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
371 | + { |
|
372 | + //setup $_settings array from incoming values. |
|
373 | + $addon_settings = array( |
|
374 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
375 | + 'class_name' => $class_name, |
|
376 | + // the addon slug for use in URLs, etc |
|
377 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
378 | + ? (string) $setup_args['plugin_slug'] |
|
379 | + : '', |
|
380 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
381 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
382 | + ? (string) $setup_args['plugin_action_slug'] |
|
383 | + : '', |
|
384 | + // the "software" version for the addon |
|
385 | + 'version' => isset($setup_args['version']) |
|
386 | + ? (string) $setup_args['version'] |
|
387 | + : '', |
|
388 | + // the minimum version of EE Core that the addon will work with |
|
389 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
390 | + ? (string) $setup_args['min_core_version'] |
|
391 | + : '', |
|
392 | + // the minimum version of WordPress that the addon will work with |
|
393 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
394 | + ? (string) $setup_args['min_wp_version'] |
|
395 | + : EE_MIN_WP_VER_REQUIRED, |
|
396 | + // full server path to main file (file loaded directly by WP) |
|
397 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
398 | + ? (string) $setup_args['main_file_path'] |
|
399 | + : '', |
|
400 | + // Fully Qualified Class Name for the addon's Domain class |
|
401 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
402 | + ? (string) $setup_args['domain_fqcn'] |
|
403 | + : '', |
|
404 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
405 | + 'admin_path' => isset($setup_args['admin_path']) |
|
406 | + ? (string) $setup_args['admin_path'] : '', |
|
407 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
408 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
409 | + ? (string) $setup_args['admin_callback'] |
|
410 | + : '', |
|
411 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
412 | + 'config_section' => isset($setup_args['config_section']) |
|
413 | + ? (string) $setup_args['config_section'] |
|
414 | + : 'addons', |
|
415 | + // the class name for this addon's configuration settings object |
|
416 | + 'config_class' => isset($setup_args['config_class']) |
|
417 | + ? (string) $setup_args['config_class'] : '', |
|
418 | + //the name given to the config for this addons' configuration settings object (optional) |
|
419 | + 'config_name' => isset($setup_args['config_name']) |
|
420 | + ? (string) $setup_args['config_name'] : '', |
|
421 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
422 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
423 | + ? (array) $setup_args['autoloader_paths'] |
|
424 | + : array(), |
|
425 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
426 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
427 | + ? (array) $setup_args['autoloader_folders'] |
|
428 | + : array(), |
|
429 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
430 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
431 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
432 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
433 | + ? (array) $setup_args['dms_paths'] |
|
434 | + : array(), |
|
435 | + // array of full server paths to any EED_Modules used by the addon |
|
436 | + 'module_paths' => isset($setup_args['module_paths']) |
|
437 | + ? (array) $setup_args['module_paths'] |
|
438 | + : array(), |
|
439 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
440 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
441 | + ? (array) $setup_args['shortcode_paths'] |
|
442 | + : array(), |
|
443 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
444 | + ? (array) $setup_args['shortcode_fqcns'] |
|
445 | + : array(), |
|
446 | + // array of full server paths to any WP_Widgets used by the addon |
|
447 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
448 | + ? (array) $setup_args['widget_paths'] |
|
449 | + : array(), |
|
450 | + // array of PUE options used by the addon |
|
451 | + 'pue_options' => isset($setup_args['pue_options']) |
|
452 | + ? (array) $setup_args['pue_options'] |
|
453 | + : array(), |
|
454 | + 'message_types' => isset($setup_args['message_types']) |
|
455 | + ? (array) $setup_args['message_types'] |
|
456 | + : array(), |
|
457 | + 'capabilities' => isset($setup_args['capabilities']) |
|
458 | + ? (array) $setup_args['capabilities'] |
|
459 | + : array(), |
|
460 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
461 | + ? (array) $setup_args['capability_maps'] |
|
462 | + : array(), |
|
463 | + 'model_paths' => isset($setup_args['model_paths']) |
|
464 | + ? (array) $setup_args['model_paths'] |
|
465 | + : array(), |
|
466 | + 'class_paths' => isset($setup_args['class_paths']) |
|
467 | + ? (array) $setup_args['class_paths'] |
|
468 | + : array(), |
|
469 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
470 | + ? (array) $setup_args['model_extension_paths'] |
|
471 | + : array(), |
|
472 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
473 | + ? (array) $setup_args['class_extension_paths'] |
|
474 | + : array(), |
|
475 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
476 | + ? (array) $setup_args['custom_post_types'] |
|
477 | + : array(), |
|
478 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
479 | + ? (array) $setup_args['custom_taxonomies'] |
|
480 | + : array(), |
|
481 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
482 | + ? (array) $setup_args['payment_method_paths'] |
|
483 | + : array(), |
|
484 | + 'default_terms' => isset($setup_args['default_terms']) |
|
485 | + ? (array) $setup_args['default_terms'] |
|
486 | + : array(), |
|
487 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
488 | + // that can be used for adding upgrading/marketing info |
|
489 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
490 | + ? $setup_args['plugins_page_row'] |
|
491 | + : '', |
|
492 | + 'namespace' => isset( |
|
493 | + $setup_args['namespace']['FQNS'], |
|
494 | + $setup_args['namespace']['DIR'] |
|
495 | + ) |
|
496 | + ? (array) $setup_args['namespace'] |
|
497 | + : array(), |
|
498 | + ); |
|
499 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
500 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
501 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
502 | + && ! empty($addon_settings['admin_path']) |
|
503 | + ? $addon_settings['plugin_slug'] |
|
504 | + : $addon_settings['plugin_action_slug']; |
|
505 | + // full server path to main file (file loaded directly by WP) |
|
506 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
507 | + return $addon_settings; |
|
508 | + } |
|
509 | 509 | |
510 | 510 | |
511 | - /** |
|
512 | - * @param string $addon_name |
|
513 | - * @param array $addon_settings |
|
514 | - * @return boolean |
|
515 | - */ |
|
516 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
517 | - { |
|
518 | - global $wp_version; |
|
519 | - $incompatibility_message = ''; |
|
520 | - //check whether this addon version is compatible with EE core |
|
521 | - if ( |
|
522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
523 | - && ! self::_meets_min_core_version_requirement( |
|
524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
525 | - $addon_settings['version'] |
|
526 | - ) |
|
527 | - ) { |
|
528 | - $incompatibility_message = sprintf( |
|
529 | - __( |
|
530 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
531 | - ), |
|
532 | - $addon_name, |
|
533 | - '<br />', |
|
534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
535 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
536 | - '</span><br />' |
|
537 | - ); |
|
538 | - } elseif ( |
|
539 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
540 | - ) { |
|
541 | - $incompatibility_message = sprintf( |
|
542 | - __( |
|
543 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
544 | - 'event_espresso' |
|
545 | - ), |
|
546 | - $addon_name, |
|
547 | - self::_effective_version($addon_settings['min_core_version']), |
|
548 | - self::_effective_version(espresso_version()), |
|
549 | - '<br />', |
|
550 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
551 | - '</span><br />' |
|
552 | - ); |
|
553 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
554 | - $incompatibility_message = sprintf( |
|
555 | - __( |
|
556 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
557 | - 'event_espresso' |
|
558 | - ), |
|
559 | - $addon_name, |
|
560 | - $addon_settings['min_wp_version'], |
|
561 | - '<br />', |
|
562 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
563 | - '</span><br />' |
|
564 | - ); |
|
565 | - } |
|
566 | - if (! empty($incompatibility_message)) { |
|
567 | - // remove 'activate' from the REQUEST |
|
568 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
569 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
570 | - if (current_user_can('activate_plugins')) { |
|
571 | - // show an error message indicating the plugin didn't activate properly |
|
572 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
573 | - } |
|
574 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
575 | - return false; |
|
576 | - } |
|
577 | - // addon IS compatible |
|
578 | - return true; |
|
579 | - } |
|
511 | + /** |
|
512 | + * @param string $addon_name |
|
513 | + * @param array $addon_settings |
|
514 | + * @return boolean |
|
515 | + */ |
|
516 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
517 | + { |
|
518 | + global $wp_version; |
|
519 | + $incompatibility_message = ''; |
|
520 | + //check whether this addon version is compatible with EE core |
|
521 | + if ( |
|
522 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
523 | + && ! self::_meets_min_core_version_requirement( |
|
524 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
525 | + $addon_settings['version'] |
|
526 | + ) |
|
527 | + ) { |
|
528 | + $incompatibility_message = sprintf( |
|
529 | + __( |
|
530 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
531 | + ), |
|
532 | + $addon_name, |
|
533 | + '<br />', |
|
534 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
535 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
536 | + '</span><br />' |
|
537 | + ); |
|
538 | + } elseif ( |
|
539 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
540 | + ) { |
|
541 | + $incompatibility_message = sprintf( |
|
542 | + __( |
|
543 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
544 | + 'event_espresso' |
|
545 | + ), |
|
546 | + $addon_name, |
|
547 | + self::_effective_version($addon_settings['min_core_version']), |
|
548 | + self::_effective_version(espresso_version()), |
|
549 | + '<br />', |
|
550 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
551 | + '</span><br />' |
|
552 | + ); |
|
553 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
554 | + $incompatibility_message = sprintf( |
|
555 | + __( |
|
556 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
557 | + 'event_espresso' |
|
558 | + ), |
|
559 | + $addon_name, |
|
560 | + $addon_settings['min_wp_version'], |
|
561 | + '<br />', |
|
562 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
563 | + '</span><br />' |
|
564 | + ); |
|
565 | + } |
|
566 | + if (! empty($incompatibility_message)) { |
|
567 | + // remove 'activate' from the REQUEST |
|
568 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
569 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
570 | + if (current_user_can('activate_plugins')) { |
|
571 | + // show an error message indicating the plugin didn't activate properly |
|
572 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
573 | + } |
|
574 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
575 | + return false; |
|
576 | + } |
|
577 | + // addon IS compatible |
|
578 | + return true; |
|
579 | + } |
|
580 | 580 | |
581 | 581 | |
582 | - /** |
|
583 | - * if plugin update engine is being used for auto-updates, |
|
584 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
585 | - * (not needed if PUE is not being used) |
|
586 | - * |
|
587 | - * @param string $addon_name |
|
588 | - * @param string $class_name |
|
589 | - * @param array $setup_args |
|
590 | - * @return void |
|
591 | - */ |
|
592 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
593 | - { |
|
594 | - if (! empty($setup_args['pue_options'])) { |
|
595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
596 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
597 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
598 | - : 'espresso_' . strtolower($class_name), |
|
599 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
600 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
601 | - : plugin_basename($setup_args['main_file_path']), |
|
602 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
603 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
604 | - : '24', |
|
605 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
606 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
607 | - : false, |
|
608 | - ); |
|
609 | - add_action( |
|
610 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
611 | - array('EE_Register_Addon', 'load_pue_update') |
|
612 | - ); |
|
613 | - } |
|
614 | - } |
|
582 | + /** |
|
583 | + * if plugin update engine is being used for auto-updates, |
|
584 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
585 | + * (not needed if PUE is not being used) |
|
586 | + * |
|
587 | + * @param string $addon_name |
|
588 | + * @param string $class_name |
|
589 | + * @param array $setup_args |
|
590 | + * @return void |
|
591 | + */ |
|
592 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
593 | + { |
|
594 | + if (! empty($setup_args['pue_options'])) { |
|
595 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
596 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
597 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
598 | + : 'espresso_' . strtolower($class_name), |
|
599 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
600 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
601 | + : plugin_basename($setup_args['main_file_path']), |
|
602 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
603 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
604 | + : '24', |
|
605 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
606 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
607 | + : false, |
|
608 | + ); |
|
609 | + add_action( |
|
610 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
611 | + array('EE_Register_Addon', 'load_pue_update') |
|
612 | + ); |
|
613 | + } |
|
614 | + } |
|
615 | 615 | |
616 | 616 | |
617 | - /** |
|
618 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
619 | - * |
|
620 | - * @param array $addon_settings |
|
621 | - * @return void |
|
622 | - */ |
|
623 | - private static function _setup_namespaces(array $addon_settings) |
|
624 | - { |
|
625 | - // |
|
626 | - if ( |
|
627 | - isset( |
|
628 | - $addon_settings['namespace']['FQNS'], |
|
629 | - $addon_settings['namespace']['DIR'] |
|
630 | - ) |
|
631 | - ) { |
|
632 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
633 | - $addon_settings['namespace']['FQNS'], |
|
634 | - $addon_settings['namespace']['DIR'] |
|
635 | - ); |
|
636 | - } |
|
637 | - } |
|
617 | + /** |
|
618 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
619 | + * |
|
620 | + * @param array $addon_settings |
|
621 | + * @return void |
|
622 | + */ |
|
623 | + private static function _setup_namespaces(array $addon_settings) |
|
624 | + { |
|
625 | + // |
|
626 | + if ( |
|
627 | + isset( |
|
628 | + $addon_settings['namespace']['FQNS'], |
|
629 | + $addon_settings['namespace']['DIR'] |
|
630 | + ) |
|
631 | + ) { |
|
632 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
633 | + $addon_settings['namespace']['FQNS'], |
|
634 | + $addon_settings['namespace']['DIR'] |
|
635 | + ); |
|
636 | + } |
|
637 | + } |
|
638 | 638 | |
639 | 639 | |
640 | - /** |
|
641 | - * @param string $addon_name |
|
642 | - * @param array $addon_settings |
|
643 | - * @return bool |
|
644 | - * @throws EE_Error |
|
645 | - * @throws InvalidArgumentException |
|
646 | - * @throws ReflectionException |
|
647 | - * @throws InvalidDataTypeException |
|
648 | - * @throws InvalidInterfaceException |
|
649 | - */ |
|
650 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
651 | - { |
|
652 | - // this is an activation request |
|
653 | - if (did_action('activate_plugin')) { |
|
654 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
655 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
656 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
657 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
659 | - || (isset(self::$_settings[ $addon_name ]) |
|
660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
661 | - ) |
|
662 | - ) { |
|
663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
664 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
665 | - $addon->set_activation_indicator_option(); |
|
666 | - // dont bother setting up the rest of the addon. |
|
667 | - // we know it was just activated and the request will end soon |
|
668 | - } |
|
669 | - return true; |
|
670 | - } |
|
671 | - // make sure this was called in the right place! |
|
672 | - if ( |
|
673 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
674 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
675 | - ) { |
|
676 | - EE_Error::doing_it_wrong( |
|
677 | - __METHOD__, |
|
678 | - sprintf( |
|
679 | - __( |
|
680 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
681 | - 'event_espresso' |
|
682 | - ), |
|
683 | - $addon_name |
|
684 | - ), |
|
685 | - '4.3.0' |
|
686 | - ); |
|
687 | - } |
|
688 | - // make sure addon settings are set correctly without overwriting anything existing |
|
689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
691 | - } else { |
|
692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
693 | - } |
|
694 | - return false; |
|
695 | - } |
|
640 | + /** |
|
641 | + * @param string $addon_name |
|
642 | + * @param array $addon_settings |
|
643 | + * @return bool |
|
644 | + * @throws EE_Error |
|
645 | + * @throws InvalidArgumentException |
|
646 | + * @throws ReflectionException |
|
647 | + * @throws InvalidDataTypeException |
|
648 | + * @throws InvalidInterfaceException |
|
649 | + */ |
|
650 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
651 | + { |
|
652 | + // this is an activation request |
|
653 | + if (did_action('activate_plugin')) { |
|
654 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
655 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
656 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
657 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
658 | + if (! isset(self::$_settings[ $addon_name ]) |
|
659 | + || (isset(self::$_settings[ $addon_name ]) |
|
660 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
661 | + ) |
|
662 | + ) { |
|
663 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
664 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
665 | + $addon->set_activation_indicator_option(); |
|
666 | + // dont bother setting up the rest of the addon. |
|
667 | + // we know it was just activated and the request will end soon |
|
668 | + } |
|
669 | + return true; |
|
670 | + } |
|
671 | + // make sure this was called in the right place! |
|
672 | + if ( |
|
673 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
674 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
675 | + ) { |
|
676 | + EE_Error::doing_it_wrong( |
|
677 | + __METHOD__, |
|
678 | + sprintf( |
|
679 | + __( |
|
680 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
681 | + 'event_espresso' |
|
682 | + ), |
|
683 | + $addon_name |
|
684 | + ), |
|
685 | + '4.3.0' |
|
686 | + ); |
|
687 | + } |
|
688 | + // make sure addon settings are set correctly without overwriting anything existing |
|
689 | + if (isset(self::$_settings[ $addon_name ])) { |
|
690 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
691 | + } else { |
|
692 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
693 | + } |
|
694 | + return false; |
|
695 | + } |
|
696 | 696 | |
697 | 697 | |
698 | - /** |
|
699 | - * @param string $addon_name |
|
700 | - * @return void |
|
701 | - * @throws EE_Error |
|
702 | - */ |
|
703 | - private static function _setup_autoloaders($addon_name) |
|
704 | - { |
|
705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
706 | - // setup autoloader for single file |
|
707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
708 | - } |
|
709 | - // setup autoloaders for folders |
|
710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
712 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
713 | - } |
|
714 | - } |
|
715 | - } |
|
698 | + /** |
|
699 | + * @param string $addon_name |
|
700 | + * @return void |
|
701 | + * @throws EE_Error |
|
702 | + */ |
|
703 | + private static function _setup_autoloaders($addon_name) |
|
704 | + { |
|
705 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
706 | + // setup autoloader for single file |
|
707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
708 | + } |
|
709 | + // setup autoloaders for folders |
|
710 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
711 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
712 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
713 | + } |
|
714 | + } |
|
715 | + } |
|
716 | 716 | |
717 | 717 | |
718 | - /** |
|
719 | - * register new models and extensions |
|
720 | - * |
|
721 | - * @param string $addon_name |
|
722 | - * @return void |
|
723 | - * @throws EE_Error |
|
724 | - */ |
|
725 | - private static function _register_models_and_extensions($addon_name) |
|
726 | - { |
|
727 | - // register new models |
|
728 | - if ( |
|
729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
731 | - ) { |
|
732 | - EE_Register_Model::register( |
|
733 | - $addon_name, |
|
734 | - array( |
|
735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
737 | - ) |
|
738 | - ); |
|
739 | - } |
|
740 | - // register model extensions |
|
741 | - if ( |
|
742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
744 | - ) { |
|
745 | - EE_Register_Model_Extensions::register( |
|
746 | - $addon_name, |
|
747 | - array( |
|
748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
750 | - ) |
|
751 | - ); |
|
752 | - } |
|
753 | - } |
|
718 | + /** |
|
719 | + * register new models and extensions |
|
720 | + * |
|
721 | + * @param string $addon_name |
|
722 | + * @return void |
|
723 | + * @throws EE_Error |
|
724 | + */ |
|
725 | + private static function _register_models_and_extensions($addon_name) |
|
726 | + { |
|
727 | + // register new models |
|
728 | + if ( |
|
729 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
730 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
731 | + ) { |
|
732 | + EE_Register_Model::register( |
|
733 | + $addon_name, |
|
734 | + array( |
|
735 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
736 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
737 | + ) |
|
738 | + ); |
|
739 | + } |
|
740 | + // register model extensions |
|
741 | + if ( |
|
742 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
743 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
744 | + ) { |
|
745 | + EE_Register_Model_Extensions::register( |
|
746 | + $addon_name, |
|
747 | + array( |
|
748 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
749 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
750 | + ) |
|
751 | + ); |
|
752 | + } |
|
753 | + } |
|
754 | 754 | |
755 | 755 | |
756 | - /** |
|
757 | - * @param string $addon_name |
|
758 | - * @return void |
|
759 | - * @throws EE_Error |
|
760 | - */ |
|
761 | - private static function _register_data_migration_scripts($addon_name) |
|
762 | - { |
|
763 | - // setup DMS |
|
764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
765 | - EE_Register_Data_Migration_Scripts::register( |
|
766 | - $addon_name, |
|
767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
768 | - ); |
|
769 | - } |
|
770 | - } |
|
756 | + /** |
|
757 | + * @param string $addon_name |
|
758 | + * @return void |
|
759 | + * @throws EE_Error |
|
760 | + */ |
|
761 | + private static function _register_data_migration_scripts($addon_name) |
|
762 | + { |
|
763 | + // setup DMS |
|
764 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
765 | + EE_Register_Data_Migration_Scripts::register( |
|
766 | + $addon_name, |
|
767 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
768 | + ); |
|
769 | + } |
|
770 | + } |
|
771 | 771 | |
772 | 772 | |
773 | - /** |
|
774 | - * @param string $addon_name |
|
775 | - * @return void |
|
776 | - * @throws EE_Error |
|
777 | - */ |
|
778 | - private static function _register_config($addon_name) |
|
779 | - { |
|
780 | - // if config_class is present let's register config. |
|
781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
782 | - EE_Register_Config::register( |
|
783 | - self::$_settings[ $addon_name ]['config_class'], |
|
784 | - array( |
|
785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
787 | - ) |
|
788 | - ); |
|
789 | - } |
|
790 | - } |
|
773 | + /** |
|
774 | + * @param string $addon_name |
|
775 | + * @return void |
|
776 | + * @throws EE_Error |
|
777 | + */ |
|
778 | + private static function _register_config($addon_name) |
|
779 | + { |
|
780 | + // if config_class is present let's register config. |
|
781 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
782 | + EE_Register_Config::register( |
|
783 | + self::$_settings[ $addon_name ]['config_class'], |
|
784 | + array( |
|
785 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
786 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
787 | + ) |
|
788 | + ); |
|
789 | + } |
|
790 | + } |
|
791 | 791 | |
792 | 792 | |
793 | - /** |
|
794 | - * @param string $addon_name |
|
795 | - * @return void |
|
796 | - * @throws EE_Error |
|
797 | - */ |
|
798 | - private static function _register_admin_pages($addon_name) |
|
799 | - { |
|
800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
801 | - EE_Register_Admin_Page::register( |
|
802 | - $addon_name, |
|
803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
804 | - ); |
|
805 | - } |
|
806 | - } |
|
793 | + /** |
|
794 | + * @param string $addon_name |
|
795 | + * @return void |
|
796 | + * @throws EE_Error |
|
797 | + */ |
|
798 | + private static function _register_admin_pages($addon_name) |
|
799 | + { |
|
800 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
801 | + EE_Register_Admin_Page::register( |
|
802 | + $addon_name, |
|
803 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
804 | + ); |
|
805 | + } |
|
806 | + } |
|
807 | 807 | |
808 | 808 | |
809 | - /** |
|
810 | - * @param string $addon_name |
|
811 | - * @return void |
|
812 | - * @throws EE_Error |
|
813 | - */ |
|
814 | - private static function _register_modules($addon_name) |
|
815 | - { |
|
816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
817 | - EE_Register_Module::register( |
|
818 | - $addon_name, |
|
819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
820 | - ); |
|
821 | - } |
|
822 | - } |
|
809 | + /** |
|
810 | + * @param string $addon_name |
|
811 | + * @return void |
|
812 | + * @throws EE_Error |
|
813 | + */ |
|
814 | + private static function _register_modules($addon_name) |
|
815 | + { |
|
816 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
817 | + EE_Register_Module::register( |
|
818 | + $addon_name, |
|
819 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
820 | + ); |
|
821 | + } |
|
822 | + } |
|
823 | 823 | |
824 | 824 | |
825 | - /** |
|
826 | - * @param string $addon_name |
|
827 | - * @return void |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - private static function _register_shortcodes($addon_name) |
|
831 | - { |
|
832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
834 | - ) { |
|
835 | - EE_Register_Shortcode::register( |
|
836 | - $addon_name, |
|
837 | - array( |
|
838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
840 | - : array(), |
|
841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
843 | - : array(), |
|
844 | - ) |
|
845 | - ); |
|
846 | - } |
|
847 | - } |
|
825 | + /** |
|
826 | + * @param string $addon_name |
|
827 | + * @return void |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + private static function _register_shortcodes($addon_name) |
|
831 | + { |
|
832 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
833 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
834 | + ) { |
|
835 | + EE_Register_Shortcode::register( |
|
836 | + $addon_name, |
|
837 | + array( |
|
838 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
839 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
840 | + : array(), |
|
841 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
842 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
843 | + : array(), |
|
844 | + ) |
|
845 | + ); |
|
846 | + } |
|
847 | + } |
|
848 | 848 | |
849 | 849 | |
850 | - /** |
|
851 | - * @param string $addon_name |
|
852 | - * @return void |
|
853 | - * @throws EE_Error |
|
854 | - */ |
|
855 | - private static function _register_widgets($addon_name) |
|
856 | - { |
|
857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
858 | - EE_Register_Widget::register( |
|
859 | - $addon_name, |
|
860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
861 | - ); |
|
862 | - } |
|
863 | - } |
|
850 | + /** |
|
851 | + * @param string $addon_name |
|
852 | + * @return void |
|
853 | + * @throws EE_Error |
|
854 | + */ |
|
855 | + private static function _register_widgets($addon_name) |
|
856 | + { |
|
857 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
858 | + EE_Register_Widget::register( |
|
859 | + $addon_name, |
|
860 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
861 | + ); |
|
862 | + } |
|
863 | + } |
|
864 | 864 | |
865 | 865 | |
866 | - /** |
|
867 | - * @param string $addon_name |
|
868 | - * @return void |
|
869 | - * @throws EE_Error |
|
870 | - */ |
|
871 | - private static function _register_capabilities($addon_name) |
|
872 | - { |
|
873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
874 | - EE_Register_Capabilities::register( |
|
875 | - $addon_name, |
|
876 | - array( |
|
877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
879 | - ) |
|
880 | - ); |
|
881 | - } |
|
882 | - } |
|
866 | + /** |
|
867 | + * @param string $addon_name |
|
868 | + * @return void |
|
869 | + * @throws EE_Error |
|
870 | + */ |
|
871 | + private static function _register_capabilities($addon_name) |
|
872 | + { |
|
873 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
874 | + EE_Register_Capabilities::register( |
|
875 | + $addon_name, |
|
876 | + array( |
|
877 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
878 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
879 | + ) |
|
880 | + ); |
|
881 | + } |
|
882 | + } |
|
883 | 883 | |
884 | 884 | |
885 | - /** |
|
886 | - * @param string $addon_name |
|
887 | - * @return void |
|
888 | - * @throws EE_Error |
|
889 | - */ |
|
890 | - private static function _register_message_types($addon_name) |
|
891 | - { |
|
892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
893 | - add_action( |
|
894 | - 'EE_Brewing_Regular___messages_caf', |
|
895 | - array('EE_Register_Addon', 'register_message_types') |
|
896 | - ); |
|
897 | - } |
|
898 | - } |
|
885 | + /** |
|
886 | + * @param string $addon_name |
|
887 | + * @return void |
|
888 | + * @throws EE_Error |
|
889 | + */ |
|
890 | + private static function _register_message_types($addon_name) |
|
891 | + { |
|
892 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
893 | + add_action( |
|
894 | + 'EE_Brewing_Regular___messages_caf', |
|
895 | + array('EE_Register_Addon', 'register_message_types') |
|
896 | + ); |
|
897 | + } |
|
898 | + } |
|
899 | 899 | |
900 | 900 | |
901 | - /** |
|
902 | - * @param string $addon_name |
|
903 | - * @return void |
|
904 | - * @throws EE_Error |
|
905 | - */ |
|
906 | - private static function _register_custom_post_types($addon_name) |
|
907 | - { |
|
908 | - if ( |
|
909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
911 | - ) { |
|
912 | - EE_Register_CPT::register( |
|
913 | - $addon_name, |
|
914 | - array( |
|
915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
918 | - ) |
|
919 | - ); |
|
920 | - } |
|
921 | - } |
|
901 | + /** |
|
902 | + * @param string $addon_name |
|
903 | + * @return void |
|
904 | + * @throws EE_Error |
|
905 | + */ |
|
906 | + private static function _register_custom_post_types($addon_name) |
|
907 | + { |
|
908 | + if ( |
|
909 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
910 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
911 | + ) { |
|
912 | + EE_Register_CPT::register( |
|
913 | + $addon_name, |
|
914 | + array( |
|
915 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
916 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
917 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
918 | + ) |
|
919 | + ); |
|
920 | + } |
|
921 | + } |
|
922 | 922 | |
923 | 923 | |
924 | - /** |
|
925 | - * @param string $addon_name |
|
926 | - * @return void |
|
927 | - * @throws InvalidArgumentException |
|
928 | - * @throws InvalidInterfaceException |
|
929 | - * @throws InvalidDataTypeException |
|
930 | - * @throws DomainException |
|
931 | - * @throws EE_Error |
|
932 | - */ |
|
933 | - private static function _register_payment_methods($addon_name) |
|
934 | - { |
|
935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
936 | - EE_Register_Payment_Method::register( |
|
937 | - $addon_name, |
|
938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
939 | - ); |
|
940 | - } |
|
941 | - } |
|
924 | + /** |
|
925 | + * @param string $addon_name |
|
926 | + * @return void |
|
927 | + * @throws InvalidArgumentException |
|
928 | + * @throws InvalidInterfaceException |
|
929 | + * @throws InvalidDataTypeException |
|
930 | + * @throws DomainException |
|
931 | + * @throws EE_Error |
|
932 | + */ |
|
933 | + private static function _register_payment_methods($addon_name) |
|
934 | + { |
|
935 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
936 | + EE_Register_Payment_Method::register( |
|
937 | + $addon_name, |
|
938 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
939 | + ); |
|
940 | + } |
|
941 | + } |
|
942 | 942 | |
943 | 943 | |
944 | - /** |
|
945 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
946 | - * |
|
947 | - * @param string $addon_name |
|
948 | - * @return EE_Addon |
|
949 | - * @throws InvalidArgumentException |
|
950 | - * @throws InvalidInterfaceException |
|
951 | - * @throws InvalidDataTypeException |
|
952 | - * @throws ReflectionException |
|
953 | - * @throws EE_Error |
|
954 | - */ |
|
955 | - private static function _load_and_init_addon_class($addon_name) |
|
956 | - { |
|
957 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
958 | - $addon = $loader->getShared( |
|
959 | - self::$_settings[ $addon_name ]['class_name'], |
|
960 | - array('EE_Registry::create(addon)' => true) |
|
961 | - ); |
|
962 | - // setter inject dep map if required |
|
963 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
964 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
965 | - } |
|
966 | - // setter inject domain if required |
|
967 | - if ( |
|
968 | - $addon instanceof RequiresDomainInterface |
|
969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
970 | - && $addon->domain() === null |
|
971 | - ) { |
|
972 | - $addon->setDomain( |
|
973 | - $loader->getShared( |
|
974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
975 | - array( |
|
976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
977 | - self::$_settings[ $addon_name ]['version'], |
|
978 | - ) |
|
979 | - ) |
|
980 | - ); |
|
981 | - } |
|
982 | - $addon->set_name($addon_name); |
|
983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
993 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
994 | - //the plugin mainfile's path upon construction. |
|
995 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
996 | - // call any additional admin_callback functions during load_admin_controller hook |
|
997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
998 | - add_action( |
|
999 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1001 | - ); |
|
1002 | - } |
|
1003 | - return $addon; |
|
1004 | - } |
|
944 | + /** |
|
945 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
946 | + * |
|
947 | + * @param string $addon_name |
|
948 | + * @return EE_Addon |
|
949 | + * @throws InvalidArgumentException |
|
950 | + * @throws InvalidInterfaceException |
|
951 | + * @throws InvalidDataTypeException |
|
952 | + * @throws ReflectionException |
|
953 | + * @throws EE_Error |
|
954 | + */ |
|
955 | + private static function _load_and_init_addon_class($addon_name) |
|
956 | + { |
|
957 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
958 | + $addon = $loader->getShared( |
|
959 | + self::$_settings[ $addon_name ]['class_name'], |
|
960 | + array('EE_Registry::create(addon)' => true) |
|
961 | + ); |
|
962 | + // setter inject dep map if required |
|
963 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
964 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
965 | + } |
|
966 | + // setter inject domain if required |
|
967 | + if ( |
|
968 | + $addon instanceof RequiresDomainInterface |
|
969 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
970 | + && $addon->domain() === null |
|
971 | + ) { |
|
972 | + $addon->setDomain( |
|
973 | + $loader->getShared( |
|
974 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
975 | + array( |
|
976 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
977 | + self::$_settings[ $addon_name ]['version'], |
|
978 | + ) |
|
979 | + ) |
|
980 | + ); |
|
981 | + } |
|
982 | + $addon->set_name($addon_name); |
|
983 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
984 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
985 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
986 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
987 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
988 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
990 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
991 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
992 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
993 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
994 | + //the plugin mainfile's path upon construction. |
|
995 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
996 | + // call any additional admin_callback functions during load_admin_controller hook |
|
997 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
998 | + add_action( |
|
999 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1000 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1001 | + ); |
|
1002 | + } |
|
1003 | + return $addon; |
|
1004 | + } |
|
1005 | 1005 | |
1006 | 1006 | |
1007 | - /** |
|
1008 | - * load_pue_update - Update notifications |
|
1009 | - * |
|
1010 | - * @return void |
|
1011 | - * @throws InvalidArgumentException |
|
1012 | - * @throws InvalidDataTypeException |
|
1013 | - * @throws InvalidInterfaceException |
|
1014 | - */ |
|
1015 | - public static function load_pue_update() |
|
1016 | - { |
|
1017 | - // load PUE client |
|
1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1019 | - // cycle thru settings |
|
1020 | - foreach (self::$_settings as $settings) { |
|
1021 | - if (! empty($settings['pue_options'])) { |
|
1022 | - // initiate the class and start the plugin update engine! |
|
1023 | - new PluginUpdateEngineChecker( |
|
1024 | - // host file URL |
|
1025 | - 'https://eventespresso.com', |
|
1026 | - // plugin slug(s) |
|
1027 | - array( |
|
1028 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1030 | - ), |
|
1031 | - // options |
|
1032 | - array( |
|
1033 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1034 | - 'lang_domain' => 'event_espresso', |
|
1035 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1036 | - 'option_key' => 'site_license_key', |
|
1037 | - 'options_page_slug' => 'event_espresso', |
|
1038 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1039 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1040 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1041 | - ) |
|
1042 | - ); |
|
1043 | - } |
|
1044 | - } |
|
1045 | - } |
|
1007 | + /** |
|
1008 | + * load_pue_update - Update notifications |
|
1009 | + * |
|
1010 | + * @return void |
|
1011 | + * @throws InvalidArgumentException |
|
1012 | + * @throws InvalidDataTypeException |
|
1013 | + * @throws InvalidInterfaceException |
|
1014 | + */ |
|
1015 | + public static function load_pue_update() |
|
1016 | + { |
|
1017 | + // load PUE client |
|
1018 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1019 | + // cycle thru settings |
|
1020 | + foreach (self::$_settings as $settings) { |
|
1021 | + if (! empty($settings['pue_options'])) { |
|
1022 | + // initiate the class and start the plugin update engine! |
|
1023 | + new PluginUpdateEngineChecker( |
|
1024 | + // host file URL |
|
1025 | + 'https://eventespresso.com', |
|
1026 | + // plugin slug(s) |
|
1027 | + array( |
|
1028 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1030 | + ), |
|
1031 | + // options |
|
1032 | + array( |
|
1033 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1034 | + 'lang_domain' => 'event_espresso', |
|
1035 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1036 | + 'option_key' => 'site_license_key', |
|
1037 | + 'options_page_slug' => 'event_espresso', |
|
1038 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1039 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1040 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1041 | + ) |
|
1042 | + ); |
|
1043 | + } |
|
1044 | + } |
|
1045 | + } |
|
1046 | 1046 | |
1047 | 1047 | |
1048 | - /** |
|
1049 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1050 | - * |
|
1051 | - * @since 4.4.0 |
|
1052 | - * @return void |
|
1053 | - * @throws EE_Error |
|
1054 | - */ |
|
1055 | - public static function register_message_types() |
|
1056 | - { |
|
1057 | - foreach (self::$_settings as $addon_name => $settings) { |
|
1058 | - if (! empty($settings['message_types'])) { |
|
1059 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1060 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1061 | - } |
|
1062 | - } |
|
1063 | - } |
|
1064 | - } |
|
1048 | + /** |
|
1049 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1050 | + * |
|
1051 | + * @since 4.4.0 |
|
1052 | + * @return void |
|
1053 | + * @throws EE_Error |
|
1054 | + */ |
|
1055 | + public static function register_message_types() |
|
1056 | + { |
|
1057 | + foreach (self::$_settings as $addon_name => $settings) { |
|
1058 | + if (! empty($settings['message_types'])) { |
|
1059 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1060 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1061 | + } |
|
1062 | + } |
|
1063 | + } |
|
1064 | + } |
|
1065 | 1065 | |
1066 | 1066 | |
1067 | - /** |
|
1068 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1069 | - * |
|
1070 | - * @since 4.3.0 |
|
1071 | - * @param string $addon_name the name for the addon that was previously registered |
|
1072 | - * @throws DomainException |
|
1073 | - * @throws EE_Error |
|
1074 | - * @throws InvalidArgumentException |
|
1075 | - * @throws InvalidDataTypeException |
|
1076 | - * @throws InvalidInterfaceException |
|
1077 | - */ |
|
1078 | - public static function deregister($addon_name = null) |
|
1079 | - { |
|
1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1081 | - try { |
|
1082 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1085 | - // setup DMS |
|
1086 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1087 | - } |
|
1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1089 | - // register admin page |
|
1090 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1091 | - } |
|
1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1093 | - // add to list of modules to be registered |
|
1094 | - EE_Register_Module::deregister($addon_name); |
|
1095 | - } |
|
1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1098 | - ) { |
|
1099 | - // add to list of shortcodes to be registered |
|
1100 | - EE_Register_Shortcode::deregister($addon_name); |
|
1101 | - } |
|
1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1103 | - // if config_class present let's register config. |
|
1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1105 | - } |
|
1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1107 | - // add to list of widgets to be registered |
|
1108 | - EE_Register_Widget::deregister($addon_name); |
|
1109 | - } |
|
1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1112 | - ) { |
|
1113 | - // add to list of shortcodes to be registered |
|
1114 | - EE_Register_Model::deregister($addon_name); |
|
1115 | - } |
|
1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1118 | - ) { |
|
1119 | - // add to list of shortcodes to be registered |
|
1120 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1121 | - } |
|
1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1123 | - foreach ( |
|
1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
1125 | - $message_type_settings |
|
1126 | - ) { |
|
1127 | - EE_Register_Message_Type::deregister($message_type); |
|
1128 | - } |
|
1129 | - } |
|
1130 | - //deregister capabilities for addon |
|
1131 | - if ( |
|
1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1134 | - ) { |
|
1135 | - EE_Register_Capabilities::deregister($addon_name); |
|
1136 | - } |
|
1137 | - //deregister custom_post_types for addon |
|
1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1139 | - EE_Register_CPT::deregister($addon_name); |
|
1140 | - } |
|
1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1142 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1143 | - } |
|
1144 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1145 | - if ($addon instanceof EE_Addon) { |
|
1146 | - remove_action( |
|
1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1148 | - array($addon, 'deactivation') |
|
1149 | - ); |
|
1150 | - remove_action( |
|
1151 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1152 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1153 | - ); |
|
1154 | - //remove `after_registration` call |
|
1155 | - remove_action( |
|
1156 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1157 | - array($addon, 'after_registration'), |
|
1158 | - 999 |
|
1159 | - ); |
|
1160 | - } |
|
1161 | - EE_Registry::instance()->removeAddon($class_name); |
|
1162 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1163 | - // the add-on was not yet registered in the registry, |
|
1164 | - // so RegistryContainer::__get() throws this exception. |
|
1165 | - // also no need to worry about this or log it, |
|
1166 | - // it's ok to deregister an add-on before its registered in the registry |
|
1167 | - } catch (Exception $e) { |
|
1168 | - new ExceptionLogger($e); |
|
1169 | - } |
|
1170 | - unset(self::$_settings[ $addon_name ]); |
|
1171 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1172 | - } |
|
1173 | - } |
|
1067 | + /** |
|
1068 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1069 | + * |
|
1070 | + * @since 4.3.0 |
|
1071 | + * @param string $addon_name the name for the addon that was previously registered |
|
1072 | + * @throws DomainException |
|
1073 | + * @throws EE_Error |
|
1074 | + * @throws InvalidArgumentException |
|
1075 | + * @throws InvalidDataTypeException |
|
1076 | + * @throws InvalidInterfaceException |
|
1077 | + */ |
|
1078 | + public static function deregister($addon_name = null) |
|
1079 | + { |
|
1080 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1081 | + try { |
|
1082 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1083 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1084 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1085 | + // setup DMS |
|
1086 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1087 | + } |
|
1088 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1089 | + // register admin page |
|
1090 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1091 | + } |
|
1092 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1093 | + // add to list of modules to be registered |
|
1094 | + EE_Register_Module::deregister($addon_name); |
|
1095 | + } |
|
1096 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1097 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1098 | + ) { |
|
1099 | + // add to list of shortcodes to be registered |
|
1100 | + EE_Register_Shortcode::deregister($addon_name); |
|
1101 | + } |
|
1102 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1103 | + // if config_class present let's register config. |
|
1104 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1105 | + } |
|
1106 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1107 | + // add to list of widgets to be registered |
|
1108 | + EE_Register_Widget::deregister($addon_name); |
|
1109 | + } |
|
1110 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1111 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1112 | + ) { |
|
1113 | + // add to list of shortcodes to be registered |
|
1114 | + EE_Register_Model::deregister($addon_name); |
|
1115 | + } |
|
1116 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1117 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1118 | + ) { |
|
1119 | + // add to list of shortcodes to be registered |
|
1120 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1121 | + } |
|
1122 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1123 | + foreach ( |
|
1124 | + (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
1125 | + $message_type_settings |
|
1126 | + ) { |
|
1127 | + EE_Register_Message_Type::deregister($message_type); |
|
1128 | + } |
|
1129 | + } |
|
1130 | + //deregister capabilities for addon |
|
1131 | + if ( |
|
1132 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1133 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1134 | + ) { |
|
1135 | + EE_Register_Capabilities::deregister($addon_name); |
|
1136 | + } |
|
1137 | + //deregister custom_post_types for addon |
|
1138 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1139 | + EE_Register_CPT::deregister($addon_name); |
|
1140 | + } |
|
1141 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1142 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1143 | + } |
|
1144 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1145 | + if ($addon instanceof EE_Addon) { |
|
1146 | + remove_action( |
|
1147 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1148 | + array($addon, 'deactivation') |
|
1149 | + ); |
|
1150 | + remove_action( |
|
1151 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1152 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1153 | + ); |
|
1154 | + //remove `after_registration` call |
|
1155 | + remove_action( |
|
1156 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1157 | + array($addon, 'after_registration'), |
|
1158 | + 999 |
|
1159 | + ); |
|
1160 | + } |
|
1161 | + EE_Registry::instance()->removeAddon($class_name); |
|
1162 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1163 | + // the add-on was not yet registered in the registry, |
|
1164 | + // so RegistryContainer::__get() throws this exception. |
|
1165 | + // also no need to worry about this or log it, |
|
1166 | + // it's ok to deregister an add-on before its registered in the registry |
|
1167 | + } catch (Exception $e) { |
|
1168 | + new ExceptionLogger($e); |
|
1169 | + } |
|
1170 | + unset(self::$_settings[ $addon_name ]); |
|
1171 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1172 | + } |
|
1173 | + } |
|
1174 | 1174 | } |
1175 | 1175 | // End of file EE_Register_Addon.lib.php |
1176 | 1176 | // Location: /core/libraries/plugin_api/EE_Register_Addon.lib.php |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
73 | 73 | $version_parts = explode('.', $min_core_version); |
74 | 74 | //check they specified the micro version (after 2nd period) |
75 | - if (! isset($version_parts[2])) { |
|
75 | + if ( ! isset($version_parts[2])) { |
|
76 | 76 | $version_parts[2] = '0'; |
77 | 77 | } |
78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
80 | - if (! isset($version_parts[3])) { |
|
80 | + if ( ! isset($version_parts[3])) { |
|
81 | 81 | $version_parts[3] = 'dev'; |
82 | 82 | } |
83 | - if (! isset($version_parts[4])) { |
|
83 | + if ( ! isset($version_parts[4])) { |
|
84 | 84 | $version_parts[4] = '000'; |
85 | 85 | } |
86 | 86 | return implode('.', $version_parts); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | // setup PUE |
257 | 257 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
258 | 258 | // does this addon work with this version of core or WordPress ? |
259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
259 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | // register namespaces |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | ) |
315 | 315 | ); |
316 | 316 | } |
317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
317 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
318 | 318 | throw new EE_Error( |
319 | 319 | sprintf( |
320 | 320 | __( |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ); |
327 | 327 | } |
328 | 328 | // check that addon has not already been registered with that name |
329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
329 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
330 | 330 | throw new EE_Error( |
331 | 331 | sprintf( |
332 | 332 | __( |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
359 | 359 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
360 | 360 | ? $class_name |
361 | - : 'EE_' . $class_name; |
|
361 | + : 'EE_'.$class_name; |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | |
@@ -519,9 +519,9 @@ discard block |
||
519 | 519 | $incompatibility_message = ''; |
520 | 520 | //check whether this addon version is compatible with EE core |
521 | 521 | if ( |
522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
522 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
523 | 523 | && ! self::_meets_min_core_version_requirement( |
524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
524 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
525 | 525 | $addon_settings['version'] |
526 | 526 | ) |
527 | 527 | ) { |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | ), |
532 | 532 | $addon_name, |
533 | 533 | '<br />', |
534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
534 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
535 | 535 | '<span style="font-weight: bold; color: #D54E21;">', |
536 | 536 | '</span><br />' |
537 | 537 | ); |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | '</span><br />' |
564 | 564 | ); |
565 | 565 | } |
566 | - if (! empty($incompatibility_message)) { |
|
566 | + if ( ! empty($incompatibility_message)) { |
|
567 | 567 | // remove 'activate' from the REQUEST |
568 | 568 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
569 | 569 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -591,11 +591,11 @@ discard block |
||
591 | 591 | */ |
592 | 592 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
593 | 593 | { |
594 | - if (! empty($setup_args['pue_options'])) { |
|
595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
594 | + if ( ! empty($setup_args['pue_options'])) { |
|
595 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
596 | 596 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
597 | 597 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
598 | - : 'espresso_' . strtolower($class_name), |
|
598 | + : 'espresso_'.strtolower($class_name), |
|
599 | 599 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
600 | 600 | ? (string) $setup_args['pue_options']['plugin_basename'] |
601 | 601 | : plugin_basename($setup_args['main_file_path']), |
@@ -655,12 +655,12 @@ discard block |
||
655 | 655 | //(as the newly-activated addon wasn't around the first time addons were registered). |
656 | 656 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
657 | 657 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
659 | - || (isset(self::$_settings[ $addon_name ]) |
|
660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
658 | + if ( ! isset(self::$_settings[$addon_name]) |
|
659 | + || (isset(self::$_settings[$addon_name]) |
|
660 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
661 | 661 | ) |
662 | 662 | ) { |
663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
663 | + self::$_settings[$addon_name] = $addon_settings; |
|
664 | 664 | $addon = self::_load_and_init_addon_class($addon_name); |
665 | 665 | $addon->set_activation_indicator_option(); |
666 | 666 | // dont bother setting up the rest of the addon. |
@@ -686,10 +686,10 @@ discard block |
||
686 | 686 | ); |
687 | 687 | } |
688 | 688 | // make sure addon settings are set correctly without overwriting anything existing |
689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
689 | + if (isset(self::$_settings[$addon_name])) { |
|
690 | + self::$_settings[$addon_name] += $addon_settings; |
|
691 | 691 | } else { |
692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
692 | + self::$_settings[$addon_name] = $addon_settings; |
|
693 | 693 | } |
694 | 694 | return false; |
695 | 695 | } |
@@ -702,13 +702,13 @@ discard block |
||
702 | 702 | */ |
703 | 703 | private static function _setup_autoloaders($addon_name) |
704 | 704 | { |
705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
705 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
706 | 706 | // setup autoloader for single file |
707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
708 | 708 | } |
709 | 709 | // setup autoloaders for folders |
710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
710 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
711 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
712 | 712 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
713 | 713 | } |
714 | 714 | } |
@@ -726,27 +726,27 @@ discard block |
||
726 | 726 | { |
727 | 727 | // register new models |
728 | 728 | if ( |
729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
729 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
730 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
731 | 731 | ) { |
732 | 732 | EE_Register_Model::register( |
733 | 733 | $addon_name, |
734 | 734 | array( |
735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
735 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
736 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
737 | 737 | ) |
738 | 738 | ); |
739 | 739 | } |
740 | 740 | // register model extensions |
741 | 741 | if ( |
742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
742 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
743 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
744 | 744 | ) { |
745 | 745 | EE_Register_Model_Extensions::register( |
746 | 746 | $addon_name, |
747 | 747 | array( |
748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
748 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
749 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
750 | 750 | ) |
751 | 751 | ); |
752 | 752 | } |
@@ -761,10 +761,10 @@ discard block |
||
761 | 761 | private static function _register_data_migration_scripts($addon_name) |
762 | 762 | { |
763 | 763 | // setup DMS |
764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
764 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
765 | 765 | EE_Register_Data_Migration_Scripts::register( |
766 | 766 | $addon_name, |
767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
767 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
768 | 768 | ); |
769 | 769 | } |
770 | 770 | } |
@@ -778,12 +778,12 @@ discard block |
||
778 | 778 | private static function _register_config($addon_name) |
779 | 779 | { |
780 | 780 | // if config_class is present let's register config. |
781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
781 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
782 | 782 | EE_Register_Config::register( |
783 | - self::$_settings[ $addon_name ]['config_class'], |
|
783 | + self::$_settings[$addon_name]['config_class'], |
|
784 | 784 | array( |
785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
785 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
786 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
787 | 787 | ) |
788 | 788 | ); |
789 | 789 | } |
@@ -797,10 +797,10 @@ discard block |
||
797 | 797 | */ |
798 | 798 | private static function _register_admin_pages($addon_name) |
799 | 799 | { |
800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
800 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
801 | 801 | EE_Register_Admin_Page::register( |
802 | 802 | $addon_name, |
803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
803 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
804 | 804 | ); |
805 | 805 | } |
806 | 806 | } |
@@ -813,10 +813,10 @@ discard block |
||
813 | 813 | */ |
814 | 814 | private static function _register_modules($addon_name) |
815 | 815 | { |
816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
816 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
817 | 817 | EE_Register_Module::register( |
818 | 818 | $addon_name, |
819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
819 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
820 | 820 | ); |
821 | 821 | } |
822 | 822 | } |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | */ |
830 | 830 | private static function _register_shortcodes($addon_name) |
831 | 831 | { |
832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
832 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
833 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
834 | 834 | ) { |
835 | 835 | EE_Register_Shortcode::register( |
836 | 836 | $addon_name, |
837 | 837 | array( |
838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
838 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
839 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
840 | 840 | : array(), |
841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
841 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
842 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
843 | 843 | : array(), |
844 | 844 | ) |
845 | 845 | ); |
@@ -854,10 +854,10 @@ discard block |
||
854 | 854 | */ |
855 | 855 | private static function _register_widgets($addon_name) |
856 | 856 | { |
857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
857 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
858 | 858 | EE_Register_Widget::register( |
859 | 859 | $addon_name, |
860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
860 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
861 | 861 | ); |
862 | 862 | } |
863 | 863 | } |
@@ -870,12 +870,12 @@ discard block |
||
870 | 870 | */ |
871 | 871 | private static function _register_capabilities($addon_name) |
872 | 872 | { |
873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
873 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
874 | 874 | EE_Register_Capabilities::register( |
875 | 875 | $addon_name, |
876 | 876 | array( |
877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
877 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
878 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
879 | 879 | ) |
880 | 880 | ); |
881 | 881 | } |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | */ |
890 | 890 | private static function _register_message_types($addon_name) |
891 | 891 | { |
892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
892 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
893 | 893 | add_action( |
894 | 894 | 'EE_Brewing_Regular___messages_caf', |
895 | 895 | array('EE_Register_Addon', 'register_message_types') |
@@ -906,15 +906,15 @@ discard block |
||
906 | 906 | private static function _register_custom_post_types($addon_name) |
907 | 907 | { |
908 | 908 | if ( |
909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
909 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
910 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
911 | 911 | ) { |
912 | 912 | EE_Register_CPT::register( |
913 | 913 | $addon_name, |
914 | 914 | array( |
915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
915 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
916 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
917 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
918 | 918 | ) |
919 | 919 | ); |
920 | 920 | } |
@@ -932,10 +932,10 @@ discard block |
||
932 | 932 | */ |
933 | 933 | private static function _register_payment_methods($addon_name) |
934 | 934 | { |
935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
935 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
936 | 936 | EE_Register_Payment_Method::register( |
937 | 937 | $addon_name, |
938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
938 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
939 | 939 | ); |
940 | 940 | } |
941 | 941 | } |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | { |
957 | 957 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
958 | 958 | $addon = $loader->getShared( |
959 | - self::$_settings[ $addon_name ]['class_name'], |
|
959 | + self::$_settings[$addon_name]['class_name'], |
|
960 | 960 | array('EE_Registry::create(addon)' => true) |
961 | 961 | ); |
962 | 962 | // setter inject dep map if required |
@@ -966,38 +966,38 @@ discard block |
||
966 | 966 | // setter inject domain if required |
967 | 967 | if ( |
968 | 968 | $addon instanceof RequiresDomainInterface |
969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
969 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
970 | 970 | && $addon->domain() === null |
971 | 971 | ) { |
972 | 972 | $addon->setDomain( |
973 | 973 | $loader->getShared( |
974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
974 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
975 | 975 | array( |
976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
977 | - self::$_settings[ $addon_name ]['version'], |
|
976 | + self::$_settings[$addon_name]['main_file_path'], |
|
977 | + self::$_settings[$addon_name]['version'], |
|
978 | 978 | ) |
979 | 979 | ) |
980 | 980 | ); |
981 | 981 | } |
982 | 982 | $addon->set_name($addon_name); |
983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
983 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
984 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
985 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
986 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
987 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
988 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
990 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
991 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
992 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
993 | 993 | //unfortunately this can't be hooked in upon construction, because we don't have |
994 | 994 | //the plugin mainfile's path upon construction. |
995 | 995 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
996 | 996 | // call any additional admin_callback functions during load_admin_controller hook |
997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
997 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
998 | 998 | add_action( |
999 | 999 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1000 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
1001 | 1001 | ); |
1002 | 1002 | } |
1003 | 1003 | return $addon; |
@@ -1015,10 +1015,10 @@ discard block |
||
1015 | 1015 | public static function load_pue_update() |
1016 | 1016 | { |
1017 | 1017 | // load PUE client |
1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1018 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
1019 | 1019 | // cycle thru settings |
1020 | 1020 | foreach (self::$_settings as $settings) { |
1021 | - if (! empty($settings['pue_options'])) { |
|
1021 | + if ( ! empty($settings['pue_options'])) { |
|
1022 | 1022 | // initiate the class and start the plugin update engine! |
1023 | 1023 | new PluginUpdateEngineChecker( |
1024 | 1024 | // host file URL |
@@ -1026,7 +1026,7 @@ discard block |
||
1026 | 1026 | // plugin slug(s) |
1027 | 1027 | array( |
1028 | 1028 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
1030 | 1030 | ), |
1031 | 1031 | // options |
1032 | 1032 | array( |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | public static function register_message_types() |
1056 | 1056 | { |
1057 | 1057 | foreach (self::$_settings as $addon_name => $settings) { |
1058 | - if (! empty($settings['message_types'])) { |
|
1058 | + if ( ! empty($settings['message_types'])) { |
|
1059 | 1059 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1060 | 1060 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1061 | 1061 | } |
@@ -1077,51 +1077,51 @@ discard block |
||
1077 | 1077 | */ |
1078 | 1078 | public static function deregister($addon_name = null) |
1079 | 1079 | { |
1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1080 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1081 | 1081 | try { |
1082 | 1082 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1083 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1084 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1085 | 1085 | // setup DMS |
1086 | 1086 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1087 | 1087 | } |
1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1088 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1089 | 1089 | // register admin page |
1090 | 1090 | EE_Register_Admin_Page::deregister($addon_name); |
1091 | 1091 | } |
1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1092 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1093 | 1093 | // add to list of modules to be registered |
1094 | 1094 | EE_Register_Module::deregister($addon_name); |
1095 | 1095 | } |
1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1096 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1097 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1098 | 1098 | ) { |
1099 | 1099 | // add to list of shortcodes to be registered |
1100 | 1100 | EE_Register_Shortcode::deregister($addon_name); |
1101 | 1101 | } |
1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1102 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1103 | 1103 | // if config_class present let's register config. |
1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1104 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1105 | 1105 | } |
1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1106 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1107 | 1107 | // add to list of widgets to be registered |
1108 | 1108 | EE_Register_Widget::deregister($addon_name); |
1109 | 1109 | } |
1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1110 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1111 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1112 | 1112 | ) { |
1113 | 1113 | // add to list of shortcodes to be registered |
1114 | 1114 | EE_Register_Model::deregister($addon_name); |
1115 | 1115 | } |
1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1116 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1117 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1118 | 1118 | ) { |
1119 | 1119 | // add to list of shortcodes to be registered |
1120 | 1120 | EE_Register_Model_Extensions::deregister($addon_name); |
1121 | 1121 | } |
1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1122 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1123 | 1123 | foreach ( |
1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
1124 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1125 | 1125 | $message_type_settings |
1126 | 1126 | ) { |
1127 | 1127 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,22 +1129,22 @@ discard block |
||
1129 | 1129 | } |
1130 | 1130 | //deregister capabilities for addon |
1131 | 1131 | if ( |
1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1132 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1133 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1134 | 1134 | ) { |
1135 | 1135 | EE_Register_Capabilities::deregister($addon_name); |
1136 | 1136 | } |
1137 | 1137 | //deregister custom_post_types for addon |
1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1138 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1139 | 1139 | EE_Register_CPT::deregister($addon_name); |
1140 | 1140 | } |
1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1141 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1142 | 1142 | EE_Register_Payment_Method::deregister($addon_name); |
1143 | 1143 | } |
1144 | 1144 | $addon = EE_Registry::instance()->getAddon($class_name); |
1145 | 1145 | if ($addon instanceof EE_Addon) { |
1146 | 1146 | remove_action( |
1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1147 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1148 | 1148 | array($addon, 'deactivation') |
1149 | 1149 | ); |
1150 | 1150 | remove_action( |
@@ -1167,7 +1167,7 @@ discard block |
||
1167 | 1167 | } catch (Exception $e) { |
1168 | 1168 | new ExceptionLogger($e); |
1169 | 1169 | } |
1170 | - unset(self::$_settings[ $addon_name ]); |
|
1170 | + unset(self::$_settings[$addon_name]); |
|
1171 | 1171 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1172 | 1172 | } |
1173 | 1173 | } |