@@ -68,7 +68,7 @@ |
||
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | 70 | 'event_espresso'); ?> <a |
71 | - href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
71 | + href="<?php echo $data_reset_page; ?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
72 | 72 | 'event_espresso'); ?></a></p> |
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | <tr> |
26 | 26 | <td> |
27 | 27 | <?php |
28 | - echo apply_filters( |
|
29 | - 'FHEE__ee_migration_page__option_1_main', |
|
30 | - esc_html__('Before updating your database, you should first create a database backup', |
|
31 | - "event_espresso"), |
|
32 | - $current_db_state, |
|
33 | - $next_db_state |
|
34 | - ); |
|
35 | - ?> |
|
28 | + echo apply_filters( |
|
29 | + 'FHEE__ee_migration_page__option_1_main', |
|
30 | + esc_html__('Before updating your database, you should first create a database backup', |
|
31 | + "event_espresso"), |
|
32 | + $current_db_state, |
|
33 | + $next_db_state |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | <a id="display-migration-details" |
37 | 37 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" |
38 | 38 | rel="migration-details"><?php esc_html_e('How Do I Make a Database Backup?', "event_espresso"); ?> |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | <td> |
42 | 42 | <a id="db-backed-up" |
43 | 43 | class="toggle-migration-monitor button-primary"><?php echo apply_filters('FHEE__ee_migration_page__option_1_button_text', |
44 | - sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | - $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
44 | + sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | + $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
46 | 46 | </td> |
47 | 47 | </tr> |
48 | 48 | <tr> |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | <div id="migration-details-dv" style="display: none; padding: 1em;"> |
51 | 51 | <p> |
52 | 52 | <?php |
53 | - printf( |
|
54 | - esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | - "event_espresso"), |
|
56 | - '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | - "</a>", |
|
58 | - "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | - ); |
|
60 | - ?> |
|
53 | + printf( |
|
54 | + esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | + "event_espresso"), |
|
56 | + '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | + "</a>", |
|
58 | + "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | </p> |
62 | 62 | <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?> |
63 | 63 | </div> |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | </table> |
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | - 'event_espresso'); ?> <a |
|
70 | + 'event_espresso'); ?> <a |
|
71 | 71 | href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
72 | - 'event_espresso'); ?></a></p> |
|
72 | + 'event_espresso'); ?></a></p> |
|
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @access public |
261 | 261 | * @param EE_Ticket $ticket |
262 | 262 | * @param int $qty |
263 | - * @return TRUE on success, FALSE on fail |
|
263 | + * @return boolean on success, FALSE on fail |
|
264 | 264 | * @throws \EE_Error |
265 | 265 | */ |
266 | 266 | public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @save cart to session |
386 | 386 | * @access public |
387 | 387 | * @param bool $apply_taxes |
388 | - * @return TRUE on success, FALSE on fail |
|
388 | + * @return boolean on success, FALSE on fail |
|
389 | 389 | * @throws \EE_Error |
390 | 390 | */ |
391 | 391 | public function save_cart($apply_taxes = true) |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | |
420 | 420 | |
421 | 421 | /** |
422 | - * @return array |
|
422 | + * @return string[] |
|
423 | 423 | */ |
424 | 424 | public function __sleep() |
425 | 425 | { |
@@ -203,7 +203,7 @@ |
||
203 | 203 | */ |
204 | 204 | public function get_tickets() |
205 | 205 | { |
206 | - if ($this->_grand_total === null ) { |
|
206 | + if ($this->_grand_total === null) { |
|
207 | 207 | return array(); |
208 | 208 | } |
209 | 209 | return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
8 | 8 | |
@@ -23,418 +23,418 @@ discard block |
||
23 | 23 | class EE_Cart implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * instance of the EE_Cart object |
|
28 | - * |
|
29 | - * @access private |
|
30 | - * @var EE_Cart $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * instance of the EE_Session object |
|
36 | - * |
|
37 | - * @access protected |
|
38 | - * @var EE_Session $_session |
|
39 | - */ |
|
40 | - protected $_session; |
|
41 | - |
|
42 | - /** |
|
43 | - * The total Line item which comprises all the children line-item subtotals, |
|
44 | - * which in turn each have their line items. |
|
45 | - * Typically, the line item structure will look like: |
|
46 | - * grand total |
|
47 | - * -tickets-sub-total |
|
48 | - * --ticket1 |
|
49 | - * --ticket2 |
|
50 | - * --... |
|
51 | - * -taxes-sub-total |
|
52 | - * --tax1 |
|
53 | - * --tax2 |
|
54 | - * |
|
55 | - * @var EE_Line_Item |
|
56 | - */ |
|
57 | - private $_grand_total; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @singleton method used to instantiate class object |
|
63 | - * @access public |
|
64 | - * @param EE_Line_Item $grand_total |
|
65 | - * @param EE_Session $session |
|
66 | - * @return \EE_Cart |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | - { |
|
71 | - if ( ! empty($grand_total)) { |
|
72 | - self::$_instance = new self($grand_total, $session); |
|
73 | - } |
|
74 | - // or maybe retrieve an existing one ? |
|
75 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | - // try getting the cart out of the session |
|
77 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | - unset($saved_cart); |
|
80 | - } |
|
81 | - // verify that cart is ok and grand total line item exists |
|
82 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | - self::$_instance = new self($grand_total, $session); |
|
84 | - } |
|
85 | - self::$_instance->get_grand_total(); |
|
86 | - // once everything is all said and done, save the cart to the EE_Session |
|
87 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | - return self::$_instance; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * private constructor to prevent direct creation |
|
95 | - * |
|
96 | - * @Constructor |
|
97 | - * @access private |
|
98 | - * @param EE_Line_Item $grand_total |
|
99 | - * @param EE_Session $session |
|
100 | - */ |
|
101 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | - { |
|
103 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | - $this->set_session($session); |
|
105 | - if ($grand_total instanceof EE_Line_Item) { |
|
106 | - $this->set_grand_total_line_item($grand_total); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Resets the cart completely (whereas empty_cart |
|
114 | - * |
|
115 | - * @param EE_Line_Item $grand_total |
|
116 | - * @param EE_Session $session |
|
117 | - * @return EE_Cart |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | - { |
|
122 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | - if ($session instanceof EE_Session) { |
|
124 | - $session->reset_cart(); |
|
125 | - } |
|
126 | - self::$_instance = null; |
|
127 | - return self::instance($grand_total, $session); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return \EE_Session |
|
134 | - */ |
|
135 | - public function session() |
|
136 | - { |
|
137 | - if ( ! $this->_session instanceof EE_Session) { |
|
138 | - $this->set_session(); |
|
139 | - } |
|
140 | - return $this->_session; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Session $session |
|
147 | - */ |
|
148 | - public function set_session(EE_Session $session = null) |
|
149 | - { |
|
150 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | - * know the grand total line item on it |
|
158 | - * |
|
159 | - * @param EE_Line_Item $line_item |
|
160 | - */ |
|
161 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | - { |
|
163 | - $this->_grand_total = $line_item; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * get_cart_from_reg_url_link |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @param EE_Transaction $transaction |
|
173 | - * @param EE_Session $session |
|
174 | - * @return \EE_Cart |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | - { |
|
179 | - $grand_total = $transaction->total_line_item(); |
|
180 | - $grand_total->get_items(); |
|
181 | - $grand_total->tax_descendants(); |
|
182 | - return EE_Cart::instance($grand_total, $session); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | - * |
|
190 | - * @return EE_Line_Item |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - private function _create_grand_total() |
|
194 | - { |
|
195 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | - return $this->_grand_total; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets all the line items of object type Ticket |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return \EE_Line_Item[] |
|
206 | - */ |
|
207 | - public function get_tickets() |
|
208 | - { |
|
209 | - if ($this->_grand_total === null ) { |
|
210 | - return array(); |
|
211 | - } |
|
212 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * returns the total quantity of tickets in the cart |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return int |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function all_ticket_quantity_count() |
|
225 | - { |
|
226 | - $tickets = $this->get_tickets(); |
|
227 | - if (empty($tickets)) { |
|
228 | - return 0; |
|
229 | - } |
|
230 | - $count = 0; |
|
231 | - foreach ($tickets as $ticket) { |
|
232 | - $count += $ticket->get('LIN_quantity'); |
|
233 | - } |
|
234 | - return $count; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the tax line items |
|
241 | - * |
|
242 | - * @return \EE_Line_Item[] |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function get_taxes() |
|
246 | - { |
|
247 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | - * |
|
255 | - * @return EE_Line_Item |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function get_grand_total() |
|
259 | - { |
|
260 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @process items for adding to cart |
|
267 | - * @access public |
|
268 | - * @param EE_Ticket $ticket |
|
269 | - * @param int $qty |
|
270 | - * @return TRUE on success, FALSE on fail |
|
271 | - * @throws \EE_Error |
|
272 | - */ |
|
273 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | - return $this->save_cart() ? true : false; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * get_cart_total_before_tax |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return float |
|
286 | - * @throws \EE_Error |
|
287 | - */ |
|
288 | - public function get_cart_total_before_tax() |
|
289 | - { |
|
290 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * gets the total amount of tax paid for items in this cart |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return float |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function get_applied_taxes() |
|
303 | - { |
|
304 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | - * |
|
312 | - * @access public |
|
313 | - * @return float |
|
314 | - * @throws \EE_Error |
|
315 | - */ |
|
316 | - public function get_cart_grand_total() |
|
317 | - { |
|
318 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | - return $this->get_grand_total()->total(); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return float |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - public function recalculate_all_cart_totals() |
|
332 | - { |
|
333 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | - return $this->get_grand_total()->total(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * deletes an item from the cart |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @param array|bool|string $line_item_codes |
|
347 | - * @return int on success, FALSE on fail |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function delete_items($line_item_codes = false) |
|
351 | - { |
|
352 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @remove ALL items from cart and zero ALL totals |
|
360 | - * @access public |
|
361 | - * @return bool |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
364 | - public function empty_cart() |
|
365 | - { |
|
366 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | - $this->_grand_total = $this->_create_grand_total(); |
|
368 | - return $this->save_cart(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @remove ALL items from cart and delete total as well |
|
375 | - * @access public |
|
376 | - * @return bool |
|
377 | - * @throws \EE_Error |
|
378 | - */ |
|
379 | - public function delete_cart() |
|
380 | - { |
|
381 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
382 | - if ($deleted) { |
|
383 | - $deleted += $this->_grand_total->delete(); |
|
384 | - $this->_grand_total = null; |
|
385 | - } |
|
386 | - return $deleted; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * @save cart to session |
|
393 | - * @access public |
|
394 | - * @param bool $apply_taxes |
|
395 | - * @return TRUE on success, FALSE on fail |
|
396 | - * @throws \EE_Error |
|
397 | - */ |
|
398 | - public function save_cart($apply_taxes = true) |
|
399 | - { |
|
400 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
401 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
402 | - //make sure we don't cache the transaction because it can get stale |
|
403 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
404 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
405 | - ) { |
|
406 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
407 | - } |
|
408 | - } |
|
409 | - if ($this->session() instanceof EE_Session) { |
|
410 | - return $this->session()->set_cart($this); |
|
411 | - } else { |
|
412 | - return false; |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - |
|
418 | - public function __wakeup() |
|
419 | - { |
|
420 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
421 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
422 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @return array |
|
430 | - */ |
|
431 | - public function __sleep() |
|
432 | - { |
|
433 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
434 | - $this->_grand_total = $this->_grand_total->ID(); |
|
435 | - } |
|
436 | - return array('_grand_total'); |
|
437 | - } |
|
26 | + /** |
|
27 | + * instance of the EE_Cart object |
|
28 | + * |
|
29 | + * @access private |
|
30 | + * @var EE_Cart $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * instance of the EE_Session object |
|
36 | + * |
|
37 | + * @access protected |
|
38 | + * @var EE_Session $_session |
|
39 | + */ |
|
40 | + protected $_session; |
|
41 | + |
|
42 | + /** |
|
43 | + * The total Line item which comprises all the children line-item subtotals, |
|
44 | + * which in turn each have their line items. |
|
45 | + * Typically, the line item structure will look like: |
|
46 | + * grand total |
|
47 | + * -tickets-sub-total |
|
48 | + * --ticket1 |
|
49 | + * --ticket2 |
|
50 | + * --... |
|
51 | + * -taxes-sub-total |
|
52 | + * --tax1 |
|
53 | + * --tax2 |
|
54 | + * |
|
55 | + * @var EE_Line_Item |
|
56 | + */ |
|
57 | + private $_grand_total; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @singleton method used to instantiate class object |
|
63 | + * @access public |
|
64 | + * @param EE_Line_Item $grand_total |
|
65 | + * @param EE_Session $session |
|
66 | + * @return \EE_Cart |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | + { |
|
71 | + if ( ! empty($grand_total)) { |
|
72 | + self::$_instance = new self($grand_total, $session); |
|
73 | + } |
|
74 | + // or maybe retrieve an existing one ? |
|
75 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | + // try getting the cart out of the session |
|
77 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | + unset($saved_cart); |
|
80 | + } |
|
81 | + // verify that cart is ok and grand total line item exists |
|
82 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | + self::$_instance = new self($grand_total, $session); |
|
84 | + } |
|
85 | + self::$_instance->get_grand_total(); |
|
86 | + // once everything is all said and done, save the cart to the EE_Session |
|
87 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | + return self::$_instance; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * private constructor to prevent direct creation |
|
95 | + * |
|
96 | + * @Constructor |
|
97 | + * @access private |
|
98 | + * @param EE_Line_Item $grand_total |
|
99 | + * @param EE_Session $session |
|
100 | + */ |
|
101 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | + { |
|
103 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | + $this->set_session($session); |
|
105 | + if ($grand_total instanceof EE_Line_Item) { |
|
106 | + $this->set_grand_total_line_item($grand_total); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Resets the cart completely (whereas empty_cart |
|
114 | + * |
|
115 | + * @param EE_Line_Item $grand_total |
|
116 | + * @param EE_Session $session |
|
117 | + * @return EE_Cart |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | + { |
|
122 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | + if ($session instanceof EE_Session) { |
|
124 | + $session->reset_cart(); |
|
125 | + } |
|
126 | + self::$_instance = null; |
|
127 | + return self::instance($grand_total, $session); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return \EE_Session |
|
134 | + */ |
|
135 | + public function session() |
|
136 | + { |
|
137 | + if ( ! $this->_session instanceof EE_Session) { |
|
138 | + $this->set_session(); |
|
139 | + } |
|
140 | + return $this->_session; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Session $session |
|
147 | + */ |
|
148 | + public function set_session(EE_Session $session = null) |
|
149 | + { |
|
150 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | + * know the grand total line item on it |
|
158 | + * |
|
159 | + * @param EE_Line_Item $line_item |
|
160 | + */ |
|
161 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | + { |
|
163 | + $this->_grand_total = $line_item; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * get_cart_from_reg_url_link |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @param EE_Transaction $transaction |
|
173 | + * @param EE_Session $session |
|
174 | + * @return \EE_Cart |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | + { |
|
179 | + $grand_total = $transaction->total_line_item(); |
|
180 | + $grand_total->get_items(); |
|
181 | + $grand_total->tax_descendants(); |
|
182 | + return EE_Cart::instance($grand_total, $session); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | + * |
|
190 | + * @return EE_Line_Item |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + private function _create_grand_total() |
|
194 | + { |
|
195 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | + return $this->_grand_total; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets all the line items of object type Ticket |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return \EE_Line_Item[] |
|
206 | + */ |
|
207 | + public function get_tickets() |
|
208 | + { |
|
209 | + if ($this->_grand_total === null ) { |
|
210 | + return array(); |
|
211 | + } |
|
212 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * returns the total quantity of tickets in the cart |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return int |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function all_ticket_quantity_count() |
|
225 | + { |
|
226 | + $tickets = $this->get_tickets(); |
|
227 | + if (empty($tickets)) { |
|
228 | + return 0; |
|
229 | + } |
|
230 | + $count = 0; |
|
231 | + foreach ($tickets as $ticket) { |
|
232 | + $count += $ticket->get('LIN_quantity'); |
|
233 | + } |
|
234 | + return $count; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the tax line items |
|
241 | + * |
|
242 | + * @return \EE_Line_Item[] |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function get_taxes() |
|
246 | + { |
|
247 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | + * |
|
255 | + * @return EE_Line_Item |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function get_grand_total() |
|
259 | + { |
|
260 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @process items for adding to cart |
|
267 | + * @access public |
|
268 | + * @param EE_Ticket $ticket |
|
269 | + * @param int $qty |
|
270 | + * @return TRUE on success, FALSE on fail |
|
271 | + * @throws \EE_Error |
|
272 | + */ |
|
273 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | + return $this->save_cart() ? true : false; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * get_cart_total_before_tax |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return float |
|
286 | + * @throws \EE_Error |
|
287 | + */ |
|
288 | + public function get_cart_total_before_tax() |
|
289 | + { |
|
290 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * gets the total amount of tax paid for items in this cart |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return float |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function get_applied_taxes() |
|
303 | + { |
|
304 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | + * |
|
312 | + * @access public |
|
313 | + * @return float |
|
314 | + * @throws \EE_Error |
|
315 | + */ |
|
316 | + public function get_cart_grand_total() |
|
317 | + { |
|
318 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | + return $this->get_grand_total()->total(); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return float |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + public function recalculate_all_cart_totals() |
|
332 | + { |
|
333 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | + return $this->get_grand_total()->total(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * deletes an item from the cart |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @param array|bool|string $line_item_codes |
|
347 | + * @return int on success, FALSE on fail |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function delete_items($line_item_codes = false) |
|
351 | + { |
|
352 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @remove ALL items from cart and zero ALL totals |
|
360 | + * @access public |
|
361 | + * @return bool |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | + public function empty_cart() |
|
365 | + { |
|
366 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | + $this->_grand_total = $this->_create_grand_total(); |
|
368 | + return $this->save_cart(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @remove ALL items from cart and delete total as well |
|
375 | + * @access public |
|
376 | + * @return bool |
|
377 | + * @throws \EE_Error |
|
378 | + */ |
|
379 | + public function delete_cart() |
|
380 | + { |
|
381 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
382 | + if ($deleted) { |
|
383 | + $deleted += $this->_grand_total->delete(); |
|
384 | + $this->_grand_total = null; |
|
385 | + } |
|
386 | + return $deleted; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * @save cart to session |
|
393 | + * @access public |
|
394 | + * @param bool $apply_taxes |
|
395 | + * @return TRUE on success, FALSE on fail |
|
396 | + * @throws \EE_Error |
|
397 | + */ |
|
398 | + public function save_cart($apply_taxes = true) |
|
399 | + { |
|
400 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
401 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
402 | + //make sure we don't cache the transaction because it can get stale |
|
403 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
404 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
405 | + ) { |
|
406 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
407 | + } |
|
408 | + } |
|
409 | + if ($this->session() instanceof EE_Session) { |
|
410 | + return $this->session()->set_cart($this); |
|
411 | + } else { |
|
412 | + return false; |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + |
|
418 | + public function __wakeup() |
|
419 | + { |
|
420 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
421 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
422 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @return array |
|
430 | + */ |
|
431 | + public function __sleep() |
|
432 | + { |
|
433 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
434 | + $this->_grand_total = $this->_grand_total->ID(); |
|
435 | + } |
|
436 | + return array('_grand_total'); |
|
437 | + } |
|
438 | 438 | |
439 | 439 | |
440 | 440 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @since 4.6.0 |
615 | 615 | * @global WPDB $wpdb |
616 | - * @return mixed null|int WP_user ID or NULL |
|
616 | + * @return integer|null null|int WP_user ID or NULL |
|
617 | 617 | */ |
618 | 618 | public static function get_default_creator_id() |
619 | 619 | { |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @static |
775 | 775 | * @deprecated instead use TableManager::dropTable() |
776 | 776 | * @param string $table_name |
777 | - * @return bool | int |
|
777 | + * @return integer | int |
|
778 | 778 | */ |
779 | 779 | public static function delete_unused_db_table($table_name) |
780 | 780 | { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @deprecated instead use TableManager::dropIndex() |
792 | 792 | * @param string $table_name |
793 | 793 | * @param string $index_name |
794 | - * @return bool | int |
|
794 | + * @return integer | int |
|
795 | 795 | */ |
796 | 796 | public static function drop_index($table_name, $index_name) |
797 | 797 | { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public static function getTableAnalysis() |
63 | 63 | { |
64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
64 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
65 | 65 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
66 | 66 | } |
67 | 67 | return self::$table_analysis; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public static function getTableManager() |
75 | 75 | { |
76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
76 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
77 | 77 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
78 | 78 | } |
79 | 79 | return self::$table_manager; |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | if ($which_to_include === 'old') { |
190 | 190 | $cron_tasks = array_filter( |
191 | 191 | $cron_tasks, |
192 | - function ($value) { |
|
192 | + function($value) { |
|
193 | 193 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
194 | 194 | } |
195 | 195 | ); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | { |
220 | 220 | |
221 | 221 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
222 | - if (! wp_next_scheduled($hook_name)) { |
|
222 | + if ( ! wp_next_scheduled($hook_name)) { |
|
223 | 223 | /** |
224 | 224 | * This allows client code to define the initial start timestamp for this schedule. |
225 | 225 | */ |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | 3 |
325 | 325 | ); |
326 | 326 | //EE_Config::reset(); |
327 | - if (! EE_Config::logging_enabled()) { |
|
327 | + if ( ! EE_Config::logging_enabled()) { |
|
328 | 328 | delete_option(EE_Config::LOG_NAME); |
329 | 329 | } |
330 | 330 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | public static function load_calendar_config() |
340 | 340 | { |
341 | 341 | // grab array of all plugin folders and loop thru it |
342 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
342 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
343 | 343 | if (empty($plugins)) { |
344 | 344 | return; |
345 | 345 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | || strpos($plugin, 'calendar') !== false |
357 | 357 | ) { |
358 | 358 | // this is what we are looking for |
359 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
359 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
360 | 360 | // does it exist in this folder ? |
361 | 361 | if (is_readable($calendar_config)) { |
362 | 362 | // YEAH! let's load it |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | ) { |
490 | 490 | //update Config with post ID |
491 | 491 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
492 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
493 | 493 | $msg = __( |
494 | 494 | 'The Event Espresso critical page configuration settings could not be updated.', |
495 | 495 | 'event_espresso' |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | public static function get_page_by_ee_shortcode($ee_shortcode) |
539 | 539 | { |
540 | 540 | global $wpdb; |
541 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
542 | 542 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
543 | 543 | if ($post_id) { |
544 | 544 | return get_post($post_id); |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | 'post_status' => 'publish', |
565 | 565 | 'post_type' => 'page', |
566 | 566 | 'comment_status' => 'closed', |
567 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | + 'post_content' => '['.$critical_page['code'].']', |
|
568 | 568 | ); |
569 | 569 | |
570 | 570 | $post_id = wp_insert_post($post_args); |
571 | - if (! $post_id) { |
|
571 | + if ( ! $post_id) { |
|
572 | 572 | $msg = sprintf( |
573 | 573 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
574 | 574 | $critical_page['name'] |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | return $critical_page; |
578 | 578 | } |
579 | 579 | // get newly created post's details |
580 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
581 | 581 | $msg = sprintf( |
582 | 582 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
583 | 583 | $critical_page['name'] |
@@ -664,17 +664,17 @@ discard block |
||
664 | 664 | $role_to_check |
665 | 665 | ); |
666 | 666 | if ($pre_filtered_id !== false) { |
667 | - return (int)$pre_filtered_id; |
|
667 | + return (int) $pre_filtered_id; |
|
668 | 668 | } |
669 | 669 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
670 | 670 | $query = $wpdb->prepare( |
671 | 671 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
672 | - '%' . $role_to_check . '%' |
|
672 | + '%'.$role_to_check.'%' |
|
673 | 673 | ); |
674 | 674 | $user_id = $wpdb->get_var($query); |
675 | 675 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
676 | - if ($user_id && (int)$user_id) { |
|
677 | - self::$_default_creator_id = (int)$user_id; |
|
676 | + if ($user_id && (int) $user_id) { |
|
677 | + self::$_default_creator_id = (int) $user_id; |
|
678 | 678 | return self::$_default_creator_id; |
679 | 679 | } else { |
680 | 680 | return null; |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | } |
710 | 710 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
711 | 711 | if ( ! function_exists('dbDelta')) { |
712 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
712 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
713 | 713 | } |
714 | 714 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
715 | 715 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -920,13 +920,13 @@ discard block |
||
920 | 920 | // reset values array |
921 | 921 | $QSG_values = array(); |
922 | 922 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
923 | - if (! in_array("$QSG_system", $question_groups)) { |
|
923 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
924 | 924 | // add it |
925 | 925 | switch ($QSG_system) { |
926 | 926 | case 1: |
927 | 927 | $QSG_values = array( |
928 | 928 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
929 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
929 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
930 | 930 | 'QSG_desc' => '', |
931 | 931 | 'QSG_order' => 1, |
932 | 932 | 'QSG_show_group_name' => 1, |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | case 2: |
939 | 939 | $QSG_values = array( |
940 | 940 | 'QSG_name' => __('Address Information', 'event_espresso'), |
941 | - 'QSG_identifier' => 'address-information-' . time(), |
|
941 | + 'QSG_identifier' => 'address-information-'.time(), |
|
942 | 942 | 'QSG_desc' => '', |
943 | 943 | 'QSG_order' => 2, |
944 | 944 | 'QSG_show_group_name' => 1, |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | break; |
950 | 950 | } |
951 | 951 | // make sure we have some values before inserting them |
952 | - if (! empty($QSG_values)) { |
|
952 | + if ( ! empty($QSG_values)) { |
|
953 | 953 | // insert system question |
954 | 954 | $wpdb->insert( |
955 | 955 | $table_name, |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | // reset values array |
987 | 987 | $QST_values = array(); |
988 | 988 | // if we don't have what we should have |
989 | - if (! in_array($QST_system, $questions)) { |
|
989 | + if ( ! in_array($QST_system, $questions)) { |
|
990 | 990 | // add it |
991 | 991 | switch ($QST_system) { |
992 | 992 | case 'fname': |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | ); |
1139 | 1139 | break; |
1140 | 1140 | } |
1141 | - if (! empty($QST_values)) { |
|
1141 | + if ( ! empty($QST_values)) { |
|
1142 | 1142 | // insert system question |
1143 | 1143 | $wpdb->insert( |
1144 | 1144 | $table_name, |
@@ -1199,7 +1199,7 @@ discard block |
||
1199 | 1199 | */ |
1200 | 1200 | public static function insert_default_payment_methods() |
1201 | 1201 | { |
1202 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1202 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1203 | 1203 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1204 | 1204 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1205 | 1205 | } else { |
@@ -1287,9 +1287,9 @@ discard block |
||
1287 | 1287 | $folders = array( |
1288 | 1288 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1289 | 1289 | EVENT_ESPRESSO_GATEWAY_DIR, |
1290 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1291 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1292 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1290 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1291 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1292 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/', |
|
1293 | 1293 | ); |
1294 | 1294 | foreach ($folders as $folder) { |
1295 | 1295 | try { |
@@ -1300,7 +1300,7 @@ discard block |
||
1300 | 1300 | sprintf( |
1301 | 1301 | __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
1302 | 1302 | $folder, |
1303 | - '<br />' . $e->getMessage() |
|
1303 | + '<br />'.$e->getMessage() |
|
1304 | 1304 | ), |
1305 | 1305 | __FILE__, __FUNCTION__, __LINE__ |
1306 | 1306 | ); |
@@ -1311,7 +1311,7 @@ discard block |
||
1311 | 1311 | } |
1312 | 1312 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1313 | 1313 | //is disabled, there might be activation errors recorded in there |
1314 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1314 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1315 | 1315 | //remember EE's folders are all good |
1316 | 1316 | delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
1317 | 1317 | return true; |
@@ -1547,7 +1547,7 @@ discard block |
||
1547 | 1547 | // this creates an array for tracking events that have no active ticket prices created |
1548 | 1548 | // this allows us to warn admins of the situation so that it can be corrected |
1549 | 1549 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1550 | - if (! $espresso_no_ticket_prices) { |
|
1550 | + if ( ! $espresso_no_ticket_prices) { |
|
1551 | 1551 | add_option('ee_no_ticket_prices', array(), '', false); |
1552 | 1552 | } |
1553 | 1553 | } |
@@ -1586,7 +1586,7 @@ discard block |
||
1586 | 1586 | } |
1587 | 1587 | } |
1588 | 1588 | //get all our CPTs |
1589 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1589 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1590 | 1590 | $cpt_ids = $wpdb->get_col($query); |
1591 | 1591 | //delete each post meta and term relations too |
1592 | 1592 | foreach ($cpt_ids as $post_id) { |
@@ -1726,7 +1726,7 @@ discard block |
||
1726 | 1726 | if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
1727 | 1727 | $db_update_sans_ee4 = array(); |
1728 | 1728 | foreach ($espresso_db_update as $version => $times_activated) { |
1729 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1729 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
1730 | 1730 | $db_update_sans_ee4[$version] = $times_activated; |
1731 | 1731 | } |
1732 | 1732 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -17,243 +17,243 @@ discard block |
||
17 | 17 | class EEH_Activation implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * constant used to indicate a cron task is no longer in use |
|
22 | - */ |
|
23 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
24 | - |
|
25 | - /** |
|
26 | - * option name that will indicate whether or not we still |
|
27 | - * need to create EE's folders in the uploads directory |
|
28 | - * (because if EE was installed without file system access, |
|
29 | - * we need to request credentials before we can create them) |
|
30 | - */ |
|
31 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
32 | - |
|
33 | - /** |
|
34 | - * WP_User->ID |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - private static $_default_creator_id; |
|
39 | - |
|
40 | - /** |
|
41 | - * indicates whether or not we've already verified core's default data during this request, |
|
42 | - * because after migrations are done, any addons activated while in maintenance mode |
|
43 | - * will want to setup their own default data, and they might hook into core's default data |
|
44 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
45 | - * This prevents doing that for EVERY single addon. |
|
46 | - * |
|
47 | - * @var boolean |
|
48 | - */ |
|
49 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
53 | - */ |
|
54 | - private static $table_analysis; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
58 | - */ |
|
59 | - private static $table_manager; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
64 | - */ |
|
65 | - public static function getTableAnalysis() |
|
66 | - { |
|
67 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
68 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
69 | - } |
|
70 | - return self::$table_analysis; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @return \EventEspresso\core\services\database\TableManager |
|
76 | - */ |
|
77 | - public static function getTableManager() |
|
78 | - { |
|
79 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
80 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
81 | - } |
|
82 | - return self::$table_manager; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * _ensure_table_name_has_prefix |
|
88 | - * |
|
89 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
90 | - * @access public |
|
91 | - * @static |
|
92 | - * @param $table_name |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public static function ensure_table_name_has_prefix($table_name) |
|
96 | - { |
|
97 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * system_initialization |
|
103 | - * ensures the EE configuration settings are loaded with at least default options set |
|
104 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @static |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public static function system_initialization() |
|
111 | - { |
|
112 | - EEH_Activation::reset_and_update_config(); |
|
113 | - //which is fired BEFORE activation of plugin anyways |
|
114 | - EEH_Activation::verify_default_pages_exist(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Sets the database schema and creates folders. This should |
|
120 | - * be called on plugin activation and reactivation |
|
121 | - * |
|
122 | - * @return boolean success, whether the database and folders are setup properly |
|
123 | - * @throws \EE_Error |
|
124 | - */ |
|
125 | - public static function initialize_db_and_folders() |
|
126 | - { |
|
127 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
128 | - $good_db = EEH_Activation::create_database_tables(); |
|
129 | - return $good_filesystem && $good_db; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * assuming we have an up-to-date database schema, this will populate it |
|
135 | - * with default and initial data. This should be called |
|
136 | - * upon activation of a new plugin, reactivation, and at the end |
|
137 | - * of running migration scripts |
|
138 | - * |
|
139 | - * @throws \EE_Error |
|
140 | - */ |
|
141 | - public static function initialize_db_content() |
|
142 | - { |
|
143 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
144 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
145 | - return; |
|
146 | - } |
|
147 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
148 | - |
|
149 | - EEH_Activation::initialize_system_questions(); |
|
150 | - EEH_Activation::insert_default_status_codes(); |
|
151 | - EEH_Activation::generate_default_message_templates(); |
|
152 | - EEH_Activation::create_no_ticket_prices_array(); |
|
153 | - |
|
154 | - EEH_Activation::validate_messages_system(); |
|
155 | - EEH_Activation::insert_default_payment_methods(); |
|
156 | - //in case we've |
|
157 | - EEH_Activation::remove_cron_tasks(); |
|
158 | - EEH_Activation::create_cron_tasks(); |
|
159 | - // remove all TXN locks since that is being done via extra meta now |
|
160 | - delete_option('ee_locked_transactions'); |
|
161 | - //also, check for CAF default db content |
|
162 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
163 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
164 | - //which users really won't care about on initial activation |
|
165 | - EE_Error::overwrite_success(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
171 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
172 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
173 | - * (null) |
|
174 | - * |
|
175 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
176 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
177 | - * @return array |
|
178 | - * @throws \EE_Error |
|
179 | - */ |
|
180 | - public static function get_cron_tasks($which_to_include) |
|
181 | - { |
|
182 | - $cron_tasks = apply_filters( |
|
183 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
184 | - array( |
|
185 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
20 | + /** |
|
21 | + * constant used to indicate a cron task is no longer in use |
|
22 | + */ |
|
23 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
24 | + |
|
25 | + /** |
|
26 | + * option name that will indicate whether or not we still |
|
27 | + * need to create EE's folders in the uploads directory |
|
28 | + * (because if EE was installed without file system access, |
|
29 | + * we need to request credentials before we can create them) |
|
30 | + */ |
|
31 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
32 | + |
|
33 | + /** |
|
34 | + * WP_User->ID |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + private static $_default_creator_id; |
|
39 | + |
|
40 | + /** |
|
41 | + * indicates whether or not we've already verified core's default data during this request, |
|
42 | + * because after migrations are done, any addons activated while in maintenance mode |
|
43 | + * will want to setup their own default data, and they might hook into core's default data |
|
44 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
45 | + * This prevents doing that for EVERY single addon. |
|
46 | + * |
|
47 | + * @var boolean |
|
48 | + */ |
|
49 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
53 | + */ |
|
54 | + private static $table_analysis; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
58 | + */ |
|
59 | + private static $table_manager; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
64 | + */ |
|
65 | + public static function getTableAnalysis() |
|
66 | + { |
|
67 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
68 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
69 | + } |
|
70 | + return self::$table_analysis; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @return \EventEspresso\core\services\database\TableManager |
|
76 | + */ |
|
77 | + public static function getTableManager() |
|
78 | + { |
|
79 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
80 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
81 | + } |
|
82 | + return self::$table_manager; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * _ensure_table_name_has_prefix |
|
88 | + * |
|
89 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
90 | + * @access public |
|
91 | + * @static |
|
92 | + * @param $table_name |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public static function ensure_table_name_has_prefix($table_name) |
|
96 | + { |
|
97 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * system_initialization |
|
103 | + * ensures the EE configuration settings are loaded with at least default options set |
|
104 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @static |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public static function system_initialization() |
|
111 | + { |
|
112 | + EEH_Activation::reset_and_update_config(); |
|
113 | + //which is fired BEFORE activation of plugin anyways |
|
114 | + EEH_Activation::verify_default_pages_exist(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Sets the database schema and creates folders. This should |
|
120 | + * be called on plugin activation and reactivation |
|
121 | + * |
|
122 | + * @return boolean success, whether the database and folders are setup properly |
|
123 | + * @throws \EE_Error |
|
124 | + */ |
|
125 | + public static function initialize_db_and_folders() |
|
126 | + { |
|
127 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
128 | + $good_db = EEH_Activation::create_database_tables(); |
|
129 | + return $good_filesystem && $good_db; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * assuming we have an up-to-date database schema, this will populate it |
|
135 | + * with default and initial data. This should be called |
|
136 | + * upon activation of a new plugin, reactivation, and at the end |
|
137 | + * of running migration scripts |
|
138 | + * |
|
139 | + * @throws \EE_Error |
|
140 | + */ |
|
141 | + public static function initialize_db_content() |
|
142 | + { |
|
143 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
144 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
145 | + return; |
|
146 | + } |
|
147 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
148 | + |
|
149 | + EEH_Activation::initialize_system_questions(); |
|
150 | + EEH_Activation::insert_default_status_codes(); |
|
151 | + EEH_Activation::generate_default_message_templates(); |
|
152 | + EEH_Activation::create_no_ticket_prices_array(); |
|
153 | + |
|
154 | + EEH_Activation::validate_messages_system(); |
|
155 | + EEH_Activation::insert_default_payment_methods(); |
|
156 | + //in case we've |
|
157 | + EEH_Activation::remove_cron_tasks(); |
|
158 | + EEH_Activation::create_cron_tasks(); |
|
159 | + // remove all TXN locks since that is being done via extra meta now |
|
160 | + delete_option('ee_locked_transactions'); |
|
161 | + //also, check for CAF default db content |
|
162 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
163 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
164 | + //which users really won't care about on initial activation |
|
165 | + EE_Error::overwrite_success(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
171 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
172 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
173 | + * (null) |
|
174 | + * |
|
175 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
176 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
177 | + * @return array |
|
178 | + * @throws \EE_Error |
|
179 | + */ |
|
180 | + public static function get_cron_tasks($which_to_include) |
|
181 | + { |
|
182 | + $cron_tasks = apply_filters( |
|
183 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
184 | + array( |
|
185 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
186 | 186 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
187 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
188 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
189 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
190 | - ) |
|
191 | - ); |
|
192 | - if ($which_to_include === 'old') { |
|
193 | - $cron_tasks = array_filter( |
|
194 | - $cron_tasks, |
|
195 | - function ($value) { |
|
196 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
197 | - } |
|
198 | - ); |
|
199 | - } elseif ($which_to_include === 'current') { |
|
200 | - $cron_tasks = array_filter($cron_tasks); |
|
201 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
202 | - throw new EE_Error( |
|
203 | - sprintf( |
|
204 | - __( |
|
205 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - $which_to_include |
|
209 | - ) |
|
210 | - ); |
|
211 | - } |
|
212 | - return $cron_tasks; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
218 | - * |
|
219 | - * @throws \EE_Error |
|
220 | - */ |
|
221 | - public static function create_cron_tasks() |
|
222 | - { |
|
223 | - |
|
224 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
225 | - if (! wp_next_scheduled($hook_name)) { |
|
226 | - /** |
|
227 | - * This allows client code to define the initial start timestamp for this schedule. |
|
228 | - */ |
|
229 | - if (is_array($frequency) |
|
230 | - && count($frequency) === 2 |
|
231 | - && isset($frequency[0], $frequency[1]) |
|
232 | - ) { |
|
233 | - $start_timestamp = $frequency[0]; |
|
234 | - $frequency = $frequency[1]; |
|
235 | - } else { |
|
236 | - $start_timestamp = time(); |
|
237 | - } |
|
238 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Remove the currently-existing and now-removed cron tasks. |
|
247 | - * |
|
248 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public static function remove_cron_tasks($remove_all = true) |
|
252 | - { |
|
253 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
254 | - $crons = _get_cron_array(); |
|
255 | - $crons = is_array($crons) ? $crons : array(); |
|
256 | - /* reminder of what $crons look like: |
|
187 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
188 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
189 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
190 | + ) |
|
191 | + ); |
|
192 | + if ($which_to_include === 'old') { |
|
193 | + $cron_tasks = array_filter( |
|
194 | + $cron_tasks, |
|
195 | + function ($value) { |
|
196 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
197 | + } |
|
198 | + ); |
|
199 | + } elseif ($which_to_include === 'current') { |
|
200 | + $cron_tasks = array_filter($cron_tasks); |
|
201 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
202 | + throw new EE_Error( |
|
203 | + sprintf( |
|
204 | + __( |
|
205 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + $which_to_include |
|
209 | + ) |
|
210 | + ); |
|
211 | + } |
|
212 | + return $cron_tasks; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
218 | + * |
|
219 | + * @throws \EE_Error |
|
220 | + */ |
|
221 | + public static function create_cron_tasks() |
|
222 | + { |
|
223 | + |
|
224 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
225 | + if (! wp_next_scheduled($hook_name)) { |
|
226 | + /** |
|
227 | + * This allows client code to define the initial start timestamp for this schedule. |
|
228 | + */ |
|
229 | + if (is_array($frequency) |
|
230 | + && count($frequency) === 2 |
|
231 | + && isset($frequency[0], $frequency[1]) |
|
232 | + ) { |
|
233 | + $start_timestamp = $frequency[0]; |
|
234 | + $frequency = $frequency[1]; |
|
235 | + } else { |
|
236 | + $start_timestamp = time(); |
|
237 | + } |
|
238 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Remove the currently-existing and now-removed cron tasks. |
|
247 | + * |
|
248 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public static function remove_cron_tasks($remove_all = true) |
|
252 | + { |
|
253 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
254 | + $crons = _get_cron_array(); |
|
255 | + $crons = is_array($crons) ? $crons : array(); |
|
256 | + /* reminder of what $crons look like: |
|
257 | 257 | * Top-level keys are timestamps, and their values are arrays. |
258 | 258 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
259 | 259 | * and their values are arrays. |
@@ -270,912 +270,912 @@ discard block |
||
270 | 270 | * ... |
271 | 271 | * ... |
272 | 272 | */ |
273 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
274 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
275 | - if (is_array($hooks_to_fire_at_time)) { |
|
276 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
277 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
278 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | - ) { |
|
280 | - unset($crons[$timestamp][$hook_name]); |
|
281 | - } |
|
282 | - } |
|
283 | - //also take care of any empty cron timestamps. |
|
284 | - if (empty($hooks_to_fire_at_time)) { |
|
285 | - unset($crons[$timestamp]); |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - _set_cron_array($crons); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * CPT_initialization |
|
295 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @static |
|
299 | - * @return void |
|
300 | - */ |
|
301 | - public static function CPT_initialization() |
|
302 | - { |
|
303 | - // register Custom Post Types |
|
304 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
305 | - flush_rewrite_rules(); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * reset_and_update_config |
|
312 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
313 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
314 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
315 | - * |
|
316 | - * @access public |
|
317 | - * @static |
|
318 | - * @return void |
|
319 | - */ |
|
320 | - public static function reset_and_update_config() |
|
321 | - { |
|
322 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
323 | - add_filter( |
|
324 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
325 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
326 | - 10, |
|
327 | - 3 |
|
328 | - ); |
|
329 | - //EE_Config::reset(); |
|
330 | - if (! EE_Config::logging_enabled()) { |
|
331 | - delete_option(EE_Config::LOG_NAME); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * load_calendar_config |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @return void |
|
341 | - */ |
|
342 | - public static function load_calendar_config() |
|
343 | - { |
|
344 | - // grab array of all plugin folders and loop thru it |
|
345 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
346 | - if (empty($plugins)) { |
|
347 | - return; |
|
348 | - } |
|
349 | - foreach ($plugins as $plugin_path) { |
|
350 | - // grab plugin folder name from path |
|
351 | - $plugin = basename($plugin_path); |
|
352 | - // drill down to Espresso plugins |
|
353 | - // then to calendar related plugins |
|
354 | - if ( |
|
355 | - strpos($plugin, 'espresso') !== false |
|
356 | - || strpos($plugin, 'Espresso') !== false |
|
357 | - || strpos($plugin, 'ee4') !== false |
|
358 | - || strpos($plugin, 'EE4') !== false |
|
359 | - || strpos($plugin, 'calendar') !== false |
|
360 | - ) { |
|
361 | - // this is what we are looking for |
|
362 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
363 | - // does it exist in this folder ? |
|
364 | - if (is_readable($calendar_config)) { |
|
365 | - // YEAH! let's load it |
|
366 | - require_once($calendar_config); |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * _migrate_old_config_data |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @param array|stdClass $settings |
|
379 | - * @param string $config |
|
380 | - * @param \EE_Config $EE_Config |
|
381 | - * @return \stdClass |
|
382 | - */ |
|
383 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
384 | - { |
|
385 | - $convert_from_array = array('addons'); |
|
386 | - // in case old settings were saved as an array |
|
387 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
388 | - // convert existing settings to an object |
|
389 | - $config_array = $settings; |
|
390 | - $settings = new stdClass(); |
|
391 | - foreach ($config_array as $key => $value) { |
|
392 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
393 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
394 | - } else { |
|
395 | - $settings->{$key} = $value; |
|
396 | - } |
|
397 | - } |
|
398 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
399 | - } |
|
400 | - return $settings; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * deactivate_event_espresso |
|
406 | - * |
|
407 | - * @access public |
|
408 | - * @static |
|
409 | - * @return void |
|
410 | - */ |
|
411 | - public static function deactivate_event_espresso() |
|
412 | - { |
|
413 | - // check permissions |
|
414 | - if (current_user_can('activate_plugins')) { |
|
415 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * verify_default_pages_exist |
|
425 | - * |
|
426 | - * @access public |
|
427 | - * @static |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - public static function verify_default_pages_exist() |
|
431 | - { |
|
432 | - $critical_page_problem = false; |
|
433 | - $critical_pages = array( |
|
434 | - array( |
|
435 | - 'id' => 'reg_page_id', |
|
436 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | - 'post' => null, |
|
438 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | - ), |
|
440 | - array( |
|
441 | - 'id' => 'txn_page_id', |
|
442 | - 'name' => __('Transactions', 'event_espresso'), |
|
443 | - 'post' => null, |
|
444 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | - ), |
|
446 | - array( |
|
447 | - 'id' => 'thank_you_page_id', |
|
448 | - 'name' => __('Thank You', 'event_espresso'), |
|
449 | - 'post' => null, |
|
450 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | - ), |
|
452 | - array( |
|
453 | - 'id' => 'cancel_page_id', |
|
454 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | - 'post' => null, |
|
456 | - 'code' => 'ESPRESSO_CANCELLED', |
|
457 | - ), |
|
458 | - ); |
|
459 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | - foreach ($critical_pages as $critical_page) { |
|
461 | - // is critical page ID set in config ? |
|
462 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | - // attempt to find post by ID |
|
464 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | - } |
|
466 | - // no dice? |
|
467 | - if ($critical_page['post'] === null) { |
|
468 | - // attempt to find post by title |
|
469 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | - // still nothing? |
|
471 | - if ($critical_page['post'] === null) { |
|
472 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | - // REALLY? Still nothing ??!?!? |
|
474 | - if ($critical_page['post'] === null) { |
|
475 | - $msg = __( |
|
476 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | - 'event_espresso' |
|
478 | - ); |
|
479 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | - break; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // check that Post ID matches critical page ID in config |
|
485 | - if ( |
|
486 | - isset($critical_page['post']->ID) |
|
487 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | - ) { |
|
489 | - //update Config with post ID |
|
490 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | - $msg = __( |
|
493 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | - 'event_espresso' |
|
495 | - ); |
|
496 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | - } |
|
498 | - } |
|
499 | - $critical_page_problem = |
|
500 | - ! isset($critical_page['post']->post_status) |
|
501 | - || $critical_page['post']->post_status !== 'publish' |
|
502 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | - ? true |
|
504 | - : $critical_page_problem; |
|
505 | - } |
|
506 | - if ($critical_page_problem) { |
|
507 | - $msg = sprintf( |
|
508 | - __( |
|
509 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
510 | - 'event_espresso' |
|
511 | - ), |
|
512 | - '<a href="' |
|
513 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
514 | - . '">' |
|
515 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | - . '</a>' |
|
517 | - ); |
|
518 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
519 | - } |
|
520 | - if (EE_Error::has_notices()) { |
|
521 | - EE_Error::get_notices(false, true, true); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Returns the first post which uses the specified shortcode |
|
529 | - * |
|
530 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | - * "[ESPRESSO_THANK_YOU" |
|
533 | - * (we don't search for the closing shortcode bracket because they might have added |
|
534 | - * parameter to the shortcode |
|
535 | - * @return WP_Post or NULl |
|
536 | - */ |
|
537 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | - { |
|
539 | - global $wpdb; |
|
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | - if ($post_id) { |
|
543 | - return get_post($post_id); |
|
544 | - } else { |
|
545 | - return null; |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * This function generates a post for critical espresso pages |
|
552 | - * |
|
553 | - * @access public |
|
554 | - * @static |
|
555 | - * @param array $critical_page |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public static function create_critical_page($critical_page) |
|
559 | - { |
|
560 | - |
|
561 | - $post_args = array( |
|
562 | - 'post_title' => $critical_page['name'], |
|
563 | - 'post_status' => 'publish', |
|
564 | - 'post_type' => 'page', |
|
565 | - 'comment_status' => 'closed', |
|
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | - ); |
|
568 | - |
|
569 | - $post_id = wp_insert_post($post_args); |
|
570 | - if (! $post_id) { |
|
571 | - $msg = sprintf( |
|
572 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | - $critical_page['name'] |
|
574 | - ); |
|
575 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | - return $critical_page; |
|
577 | - } |
|
578 | - // get newly created post's details |
|
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | - $msg = sprintf( |
|
581 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | - $critical_page['name'] |
|
583 | - ); |
|
584 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | - } |
|
586 | - |
|
587 | - return $critical_page; |
|
588 | - |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | - * The role being used to check is filterable. |
|
597 | - * |
|
598 | - * @since 4.6.0 |
|
599 | - * @global WPDB $wpdb |
|
600 | - * @return mixed null|int WP_user ID or NULL |
|
601 | - */ |
|
602 | - public static function get_default_creator_id() |
|
603 | - { |
|
604 | - global $wpdb; |
|
605 | - if ( ! empty(self::$_default_creator_id)) { |
|
606 | - return self::$_default_creator_id; |
|
607 | - }/**/ |
|
608 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | - $pre_filtered_id = apply_filters( |
|
611 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | - false, |
|
613 | - $role_to_check |
|
614 | - ); |
|
615 | - if ($pre_filtered_id !== false) { |
|
616 | - return (int)$pre_filtered_id; |
|
617 | - } |
|
618 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | - $query = $wpdb->prepare( |
|
620 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | - '%' . $role_to_check . '%' |
|
622 | - ); |
|
623 | - $user_id = $wpdb->get_var($query); |
|
624 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
627 | - return self::$_default_creator_id; |
|
628 | - } else { |
|
629 | - return null; |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * used by EE and EE addons during plugin activation to create tables. |
|
637 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | - * but includes extra logic regarding activations. |
|
639 | - * |
|
640 | - * @access public |
|
641 | - * @static |
|
642 | - * @param string $table_name without the $wpdb->prefix |
|
643 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | - * table query) |
|
645 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | - * and new once this function is done (ie, you really do want to CREATE a |
|
648 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | - * you just want to verify the table exists and matches this definition |
|
650 | - * (and if it HAS data in it you want to leave it be) |
|
651 | - * @return void |
|
652 | - * @throws EE_Error if there are database errors |
|
653 | - */ |
|
654 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | - { |
|
656 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | - return; |
|
658 | - } |
|
659 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | - if ( ! function_exists('dbDelta')) { |
|
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | - } |
|
663 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | - // do we need to first delete an existing version of this table ? |
|
666 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | - // ok, delete the table... but ONLY if it's empty |
|
668 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | - } else if ( ! $deleted_safely) { |
|
673 | - // so we should be more cautious rather than just dropping tables so easily |
|
674 | - error_log( |
|
675 | - sprintf( |
|
676 | - __( |
|
677 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | - 'event_espresso' |
|
679 | - ), |
|
680 | - $wp_table_name, |
|
681 | - '<br/>', |
|
682 | - 'espresso_db_update' |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - } |
|
687 | - $engine = str_replace('ENGINE=', '', $engine); |
|
688 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * add_column_if_it_doesn't_exist |
|
695 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @static |
|
699 | - * @deprecated instead use TableManager::addColumn() |
|
700 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | - * @param string $column_name |
|
702 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | - * 'VARCHAR(10)' |
|
704 | - * @return bool|int |
|
705 | - */ |
|
706 | - public static function add_column_if_it_doesnt_exist( |
|
707 | - $table_name, |
|
708 | - $column_name, |
|
709 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | - ) { |
|
711 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * get_fields_on_table |
|
717 | - * Gets all the fields on the database table. |
|
718 | - * |
|
719 | - * @access public |
|
720 | - * @deprecated instead use TableManager::getTableColumns() |
|
721 | - * @static |
|
722 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | - * @return array of database column names |
|
724 | - */ |
|
725 | - public static function get_fields_on_table($table_name = null) |
|
726 | - { |
|
727 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * db_table_is_empty |
|
733 | - * |
|
734 | - * @access public\ |
|
735 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | - * @static |
|
737 | - * @param string $table_name |
|
738 | - * @return bool |
|
739 | - */ |
|
740 | - public static function db_table_is_empty($table_name) |
|
741 | - { |
|
742 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_db_table_if_empty |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @param string $table_name |
|
752 | - * @return bool | int |
|
753 | - */ |
|
754 | - public static function delete_db_table_if_empty($table_name) |
|
755 | - { |
|
756 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - return false; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * delete_unused_db_table |
|
765 | - * |
|
766 | - * @access public |
|
767 | - * @static |
|
768 | - * @deprecated instead use TableManager::dropTable() |
|
769 | - * @param string $table_name |
|
770 | - * @return bool | int |
|
771 | - */ |
|
772 | - public static function delete_unused_db_table($table_name) |
|
773 | - { |
|
774 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * drop_index |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @deprecated instead use TableManager::dropIndex() |
|
784 | - * @param string $table_name |
|
785 | - * @param string $index_name |
|
786 | - * @return bool | int |
|
787 | - */ |
|
788 | - public static function drop_index($table_name, $index_name) |
|
789 | - { |
|
790 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * create_database_tables |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @static |
|
800 | - * @throws EE_Error |
|
801 | - * @return boolean success (whether database is setup properly or not) |
|
802 | - */ |
|
803 | - public static function create_database_tables() |
|
804 | - { |
|
805 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | - //find the migration script that sets the database to be compatible with the code |
|
807 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | - if ($dms_name) { |
|
809 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | - $current_data_migration_script->set_migrating(false); |
|
811 | - $current_data_migration_script->schema_changes_before_migration(); |
|
812 | - $current_data_migration_script->schema_changes_after_migration(); |
|
813 | - if ($current_data_migration_script->get_errors()) { |
|
814 | - if (WP_DEBUG) { |
|
815 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | - } |
|
818 | - } else { |
|
819 | - EE_Error::add_error( |
|
820 | - __( |
|
821 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
273 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
274 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
275 | + if (is_array($hooks_to_fire_at_time)) { |
|
276 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
277 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
278 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | + ) { |
|
280 | + unset($crons[$timestamp][$hook_name]); |
|
281 | + } |
|
282 | + } |
|
283 | + //also take care of any empty cron timestamps. |
|
284 | + if (empty($hooks_to_fire_at_time)) { |
|
285 | + unset($crons[$timestamp]); |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + _set_cron_array($crons); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * CPT_initialization |
|
295 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @static |
|
299 | + * @return void |
|
300 | + */ |
|
301 | + public static function CPT_initialization() |
|
302 | + { |
|
303 | + // register Custom Post Types |
|
304 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
305 | + flush_rewrite_rules(); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * reset_and_update_config |
|
312 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
313 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
314 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
315 | + * |
|
316 | + * @access public |
|
317 | + * @static |
|
318 | + * @return void |
|
319 | + */ |
|
320 | + public static function reset_and_update_config() |
|
321 | + { |
|
322 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
323 | + add_filter( |
|
324 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
325 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
326 | + 10, |
|
327 | + 3 |
|
328 | + ); |
|
329 | + //EE_Config::reset(); |
|
330 | + if (! EE_Config::logging_enabled()) { |
|
331 | + delete_option(EE_Config::LOG_NAME); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * load_calendar_config |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @return void |
|
341 | + */ |
|
342 | + public static function load_calendar_config() |
|
343 | + { |
|
344 | + // grab array of all plugin folders and loop thru it |
|
345 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
346 | + if (empty($plugins)) { |
|
347 | + return; |
|
348 | + } |
|
349 | + foreach ($plugins as $plugin_path) { |
|
350 | + // grab plugin folder name from path |
|
351 | + $plugin = basename($plugin_path); |
|
352 | + // drill down to Espresso plugins |
|
353 | + // then to calendar related plugins |
|
354 | + if ( |
|
355 | + strpos($plugin, 'espresso') !== false |
|
356 | + || strpos($plugin, 'Espresso') !== false |
|
357 | + || strpos($plugin, 'ee4') !== false |
|
358 | + || strpos($plugin, 'EE4') !== false |
|
359 | + || strpos($plugin, 'calendar') !== false |
|
360 | + ) { |
|
361 | + // this is what we are looking for |
|
362 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
363 | + // does it exist in this folder ? |
|
364 | + if (is_readable($calendar_config)) { |
|
365 | + // YEAH! let's load it |
|
366 | + require_once($calendar_config); |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * _migrate_old_config_data |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @param array|stdClass $settings |
|
379 | + * @param string $config |
|
380 | + * @param \EE_Config $EE_Config |
|
381 | + * @return \stdClass |
|
382 | + */ |
|
383 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
384 | + { |
|
385 | + $convert_from_array = array('addons'); |
|
386 | + // in case old settings were saved as an array |
|
387 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
388 | + // convert existing settings to an object |
|
389 | + $config_array = $settings; |
|
390 | + $settings = new stdClass(); |
|
391 | + foreach ($config_array as $key => $value) { |
|
392 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
393 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
394 | + } else { |
|
395 | + $settings->{$key} = $value; |
|
396 | + } |
|
397 | + } |
|
398 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
399 | + } |
|
400 | + return $settings; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * deactivate_event_espresso |
|
406 | + * |
|
407 | + * @access public |
|
408 | + * @static |
|
409 | + * @return void |
|
410 | + */ |
|
411 | + public static function deactivate_event_espresso() |
|
412 | + { |
|
413 | + // check permissions |
|
414 | + if (current_user_can('activate_plugins')) { |
|
415 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * verify_default_pages_exist |
|
425 | + * |
|
426 | + * @access public |
|
427 | + * @static |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + public static function verify_default_pages_exist() |
|
431 | + { |
|
432 | + $critical_page_problem = false; |
|
433 | + $critical_pages = array( |
|
434 | + array( |
|
435 | + 'id' => 'reg_page_id', |
|
436 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | + 'post' => null, |
|
438 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | + ), |
|
440 | + array( |
|
441 | + 'id' => 'txn_page_id', |
|
442 | + 'name' => __('Transactions', 'event_espresso'), |
|
443 | + 'post' => null, |
|
444 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | + ), |
|
446 | + array( |
|
447 | + 'id' => 'thank_you_page_id', |
|
448 | + 'name' => __('Thank You', 'event_espresso'), |
|
449 | + 'post' => null, |
|
450 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | + ), |
|
452 | + array( |
|
453 | + 'id' => 'cancel_page_id', |
|
454 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | + 'post' => null, |
|
456 | + 'code' => 'ESPRESSO_CANCELLED', |
|
457 | + ), |
|
458 | + ); |
|
459 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | + foreach ($critical_pages as $critical_page) { |
|
461 | + // is critical page ID set in config ? |
|
462 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | + // attempt to find post by ID |
|
464 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | + } |
|
466 | + // no dice? |
|
467 | + if ($critical_page['post'] === null) { |
|
468 | + // attempt to find post by title |
|
469 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | + // still nothing? |
|
471 | + if ($critical_page['post'] === null) { |
|
472 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | + // REALLY? Still nothing ??!?!? |
|
474 | + if ($critical_page['post'] === null) { |
|
475 | + $msg = __( |
|
476 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | + 'event_espresso' |
|
478 | + ); |
|
479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | + break; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // check that Post ID matches critical page ID in config |
|
485 | + if ( |
|
486 | + isset($critical_page['post']->ID) |
|
487 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | + ) { |
|
489 | + //update Config with post ID |
|
490 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | + $msg = __( |
|
493 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | + 'event_espresso' |
|
495 | + ); |
|
496 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | + } |
|
498 | + } |
|
499 | + $critical_page_problem = |
|
500 | + ! isset($critical_page['post']->post_status) |
|
501 | + || $critical_page['post']->post_status !== 'publish' |
|
502 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | + ? true |
|
504 | + : $critical_page_problem; |
|
505 | + } |
|
506 | + if ($critical_page_problem) { |
|
507 | + $msg = sprintf( |
|
508 | + __( |
|
509 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
510 | + 'event_espresso' |
|
511 | + ), |
|
512 | + '<a href="' |
|
513 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
514 | + . '">' |
|
515 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | + . '</a>' |
|
517 | + ); |
|
518 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
519 | + } |
|
520 | + if (EE_Error::has_notices()) { |
|
521 | + EE_Error::get_notices(false, true, true); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Returns the first post which uses the specified shortcode |
|
529 | + * |
|
530 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | + * "[ESPRESSO_THANK_YOU" |
|
533 | + * (we don't search for the closing shortcode bracket because they might have added |
|
534 | + * parameter to the shortcode |
|
535 | + * @return WP_Post or NULl |
|
536 | + */ |
|
537 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | + { |
|
539 | + global $wpdb; |
|
540 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | + if ($post_id) { |
|
543 | + return get_post($post_id); |
|
544 | + } else { |
|
545 | + return null; |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * This function generates a post for critical espresso pages |
|
552 | + * |
|
553 | + * @access public |
|
554 | + * @static |
|
555 | + * @param array $critical_page |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public static function create_critical_page($critical_page) |
|
559 | + { |
|
560 | + |
|
561 | + $post_args = array( |
|
562 | + 'post_title' => $critical_page['name'], |
|
563 | + 'post_status' => 'publish', |
|
564 | + 'post_type' => 'page', |
|
565 | + 'comment_status' => 'closed', |
|
566 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | + ); |
|
568 | + |
|
569 | + $post_id = wp_insert_post($post_args); |
|
570 | + if (! $post_id) { |
|
571 | + $msg = sprintf( |
|
572 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | + $critical_page['name'] |
|
574 | + ); |
|
575 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | + return $critical_page; |
|
577 | + } |
|
578 | + // get newly created post's details |
|
579 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | + $msg = sprintf( |
|
581 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | + $critical_page['name'] |
|
583 | + ); |
|
584 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | + } |
|
586 | + |
|
587 | + return $critical_page; |
|
588 | + |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | + * The role being used to check is filterable. |
|
597 | + * |
|
598 | + * @since 4.6.0 |
|
599 | + * @global WPDB $wpdb |
|
600 | + * @return mixed null|int WP_user ID or NULL |
|
601 | + */ |
|
602 | + public static function get_default_creator_id() |
|
603 | + { |
|
604 | + global $wpdb; |
|
605 | + if ( ! empty(self::$_default_creator_id)) { |
|
606 | + return self::$_default_creator_id; |
|
607 | + }/**/ |
|
608 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | + $pre_filtered_id = apply_filters( |
|
611 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | + false, |
|
613 | + $role_to_check |
|
614 | + ); |
|
615 | + if ($pre_filtered_id !== false) { |
|
616 | + return (int)$pre_filtered_id; |
|
617 | + } |
|
618 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | + $query = $wpdb->prepare( |
|
620 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | + '%' . $role_to_check . '%' |
|
622 | + ); |
|
623 | + $user_id = $wpdb->get_var($query); |
|
624 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | + if ($user_id && (int)$user_id) { |
|
626 | + self::$_default_creator_id = (int)$user_id; |
|
627 | + return self::$_default_creator_id; |
|
628 | + } else { |
|
629 | + return null; |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * used by EE and EE addons during plugin activation to create tables. |
|
637 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | + * but includes extra logic regarding activations. |
|
639 | + * |
|
640 | + * @access public |
|
641 | + * @static |
|
642 | + * @param string $table_name without the $wpdb->prefix |
|
643 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | + * table query) |
|
645 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | + * and new once this function is done (ie, you really do want to CREATE a |
|
648 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | + * you just want to verify the table exists and matches this definition |
|
650 | + * (and if it HAS data in it you want to leave it be) |
|
651 | + * @return void |
|
652 | + * @throws EE_Error if there are database errors |
|
653 | + */ |
|
654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | + { |
|
656 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | + return; |
|
658 | + } |
|
659 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | + if ( ! function_exists('dbDelta')) { |
|
661 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | + } |
|
663 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | + // do we need to first delete an existing version of this table ? |
|
666 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | + // ok, delete the table... but ONLY if it's empty |
|
668 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | + } else if ( ! $deleted_safely) { |
|
673 | + // so we should be more cautious rather than just dropping tables so easily |
|
674 | + error_log( |
|
675 | + sprintf( |
|
676 | + __( |
|
677 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | + 'event_espresso' |
|
679 | + ), |
|
680 | + $wp_table_name, |
|
681 | + '<br/>', |
|
682 | + 'espresso_db_update' |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + } |
|
687 | + $engine = str_replace('ENGINE=', '', $engine); |
|
688 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * add_column_if_it_doesn't_exist |
|
695 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @static |
|
699 | + * @deprecated instead use TableManager::addColumn() |
|
700 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | + * @param string $column_name |
|
702 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | + * 'VARCHAR(10)' |
|
704 | + * @return bool|int |
|
705 | + */ |
|
706 | + public static function add_column_if_it_doesnt_exist( |
|
707 | + $table_name, |
|
708 | + $column_name, |
|
709 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | + ) { |
|
711 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * get_fields_on_table |
|
717 | + * Gets all the fields on the database table. |
|
718 | + * |
|
719 | + * @access public |
|
720 | + * @deprecated instead use TableManager::getTableColumns() |
|
721 | + * @static |
|
722 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | + * @return array of database column names |
|
724 | + */ |
|
725 | + public static function get_fields_on_table($table_name = null) |
|
726 | + { |
|
727 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * db_table_is_empty |
|
733 | + * |
|
734 | + * @access public\ |
|
735 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | + * @static |
|
737 | + * @param string $table_name |
|
738 | + * @return bool |
|
739 | + */ |
|
740 | + public static function db_table_is_empty($table_name) |
|
741 | + { |
|
742 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_db_table_if_empty |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @param string $table_name |
|
752 | + * @return bool | int |
|
753 | + */ |
|
754 | + public static function delete_db_table_if_empty($table_name) |
|
755 | + { |
|
756 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + return false; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * delete_unused_db_table |
|
765 | + * |
|
766 | + * @access public |
|
767 | + * @static |
|
768 | + * @deprecated instead use TableManager::dropTable() |
|
769 | + * @param string $table_name |
|
770 | + * @return bool | int |
|
771 | + */ |
|
772 | + public static function delete_unused_db_table($table_name) |
|
773 | + { |
|
774 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * drop_index |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @deprecated instead use TableManager::dropIndex() |
|
784 | + * @param string $table_name |
|
785 | + * @param string $index_name |
|
786 | + * @return bool | int |
|
787 | + */ |
|
788 | + public static function drop_index($table_name, $index_name) |
|
789 | + { |
|
790 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * create_database_tables |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @static |
|
800 | + * @throws EE_Error |
|
801 | + * @return boolean success (whether database is setup properly or not) |
|
802 | + */ |
|
803 | + public static function create_database_tables() |
|
804 | + { |
|
805 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | + //find the migration script that sets the database to be compatible with the code |
|
807 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | + if ($dms_name) { |
|
809 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | + $current_data_migration_script->set_migrating(false); |
|
811 | + $current_data_migration_script->schema_changes_before_migration(); |
|
812 | + $current_data_migration_script->schema_changes_after_migration(); |
|
813 | + if ($current_data_migration_script->get_errors()) { |
|
814 | + if (WP_DEBUG) { |
|
815 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | + } |
|
818 | + } else { |
|
819 | + EE_Error::add_error( |
|
820 | + __( |
|
821 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
822 | 822 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
823 | - 'event_espresso' |
|
824 | - ) |
|
825 | - ); |
|
826 | - } |
|
827 | - return false; |
|
828 | - } |
|
829 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | - } else { |
|
831 | - EE_Error::add_error( |
|
832 | - __( |
|
833 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
823 | + 'event_espresso' |
|
824 | + ) |
|
825 | + ); |
|
826 | + } |
|
827 | + return false; |
|
828 | + } |
|
829 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | + } else { |
|
831 | + EE_Error::add_error( |
|
832 | + __( |
|
833 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
834 | 834 | structure. So database is probably not setup properly', |
835 | - 'event_espresso' |
|
836 | - ), |
|
837 | - __FILE__, |
|
838 | - __FUNCTION__, |
|
839 | - __LINE__ |
|
840 | - ); |
|
841 | - return false; |
|
842 | - } |
|
843 | - return true; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * initialize_system_questions |
|
850 | - * |
|
851 | - * @access public |
|
852 | - * @static |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public static function initialize_system_questions() |
|
856 | - { |
|
857 | - // QUESTION GROUPS |
|
858 | - global $wpdb; |
|
859 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | - // what we have |
|
862 | - $question_groups = $wpdb->get_col($SQL); |
|
863 | - // check the response |
|
864 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | - // what we should have |
|
866 | - $QSG_systems = array(1, 2); |
|
867 | - // loop thru what we should have and compare to what we have |
|
868 | - foreach ($QSG_systems as $QSG_system) { |
|
869 | - // reset values array |
|
870 | - $QSG_values = array(); |
|
871 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
873 | - // add it |
|
874 | - switch ($QSG_system) { |
|
875 | - case 1: |
|
876 | - $QSG_values = array( |
|
877 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | - 'QSG_desc' => '', |
|
880 | - 'QSG_order' => 1, |
|
881 | - 'QSG_show_group_name' => 1, |
|
882 | - 'QSG_show_group_desc' => 1, |
|
883 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | - 'QSG_deleted' => 0, |
|
885 | - ); |
|
886 | - break; |
|
887 | - case 2: |
|
888 | - $QSG_values = array( |
|
889 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
891 | - 'QSG_desc' => '', |
|
892 | - 'QSG_order' => 2, |
|
893 | - 'QSG_show_group_name' => 1, |
|
894 | - 'QSG_show_group_desc' => 1, |
|
895 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | - 'QSG_deleted' => 0, |
|
897 | - ); |
|
898 | - break; |
|
899 | - } |
|
900 | - // make sure we have some values before inserting them |
|
901 | - if (! empty($QSG_values)) { |
|
902 | - // insert system question |
|
903 | - $wpdb->insert( |
|
904 | - $table_name, |
|
905 | - $QSG_values, |
|
906 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | - ); |
|
908 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | - } |
|
910 | - } |
|
911 | - } |
|
912 | - // QUESTIONS |
|
913 | - global $wpdb; |
|
914 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | - // what we have |
|
917 | - $questions = $wpdb->get_col($SQL); |
|
918 | - // what we should have |
|
919 | - $QST_systems = array( |
|
920 | - 'fname', |
|
921 | - 'lname', |
|
922 | - 'email', |
|
923 | - 'address', |
|
924 | - 'address2', |
|
925 | - 'city', |
|
926 | - 'country', |
|
927 | - 'state', |
|
928 | - 'zip', |
|
929 | - 'phone', |
|
930 | - ); |
|
931 | - $order_for_group_1 = 1; |
|
932 | - $order_for_group_2 = 1; |
|
933 | - // loop thru what we should have and compare to what we have |
|
934 | - foreach ($QST_systems as $QST_system) { |
|
935 | - // reset values array |
|
936 | - $QST_values = array(); |
|
937 | - // if we don't have what we should have |
|
938 | - if (! in_array($QST_system, $questions)) { |
|
939 | - // add it |
|
940 | - switch ($QST_system) { |
|
941 | - case 'fname': |
|
942 | - $QST_values = array( |
|
943 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | - 'QST_system' => 'fname', |
|
946 | - 'QST_type' => 'TEXT', |
|
947 | - 'QST_required' => 1, |
|
948 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | - 'QST_order' => 1, |
|
950 | - 'QST_admin_only' => 0, |
|
951 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | - 'QST_deleted' => 0, |
|
954 | - ); |
|
955 | - break; |
|
956 | - case 'lname': |
|
957 | - $QST_values = array( |
|
958 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | - 'QST_system' => 'lname', |
|
961 | - 'QST_type' => 'TEXT', |
|
962 | - 'QST_required' => 1, |
|
963 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | - 'QST_order' => 2, |
|
965 | - 'QST_admin_only' => 0, |
|
966 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | - 'QST_deleted' => 0, |
|
969 | - ); |
|
970 | - break; |
|
971 | - case 'email': |
|
972 | - $QST_values = array( |
|
973 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | - 'QST_system' => 'email', |
|
976 | - 'QST_type' => 'EMAIL', |
|
977 | - 'QST_required' => 1, |
|
978 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | - 'QST_order' => 3, |
|
980 | - 'QST_admin_only' => 0, |
|
981 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | - 'QST_deleted' => 0, |
|
984 | - ); |
|
985 | - break; |
|
986 | - case 'address': |
|
987 | - $QST_values = array( |
|
988 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | - 'QST_system' => 'address', |
|
991 | - 'QST_type' => 'TEXT', |
|
992 | - 'QST_required' => 0, |
|
993 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | - 'QST_order' => 4, |
|
995 | - 'QST_admin_only' => 0, |
|
996 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | - 'QST_deleted' => 0, |
|
999 | - ); |
|
1000 | - break; |
|
1001 | - case 'address2': |
|
1002 | - $QST_values = array( |
|
1003 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | - 'QST_system' => 'address2', |
|
1006 | - 'QST_type' => 'TEXT', |
|
1007 | - 'QST_required' => 0, |
|
1008 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | - 'QST_order' => 5, |
|
1010 | - 'QST_admin_only' => 0, |
|
1011 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | - 'QST_deleted' => 0, |
|
1014 | - ); |
|
1015 | - break; |
|
1016 | - case 'city': |
|
1017 | - $QST_values = array( |
|
1018 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | - 'QST_system' => 'city', |
|
1021 | - 'QST_type' => 'TEXT', |
|
1022 | - 'QST_required' => 0, |
|
1023 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | - 'QST_order' => 6, |
|
1025 | - 'QST_admin_only' => 0, |
|
1026 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | - 'QST_deleted' => 0, |
|
1029 | - ); |
|
1030 | - break; |
|
1031 | - case 'country': |
|
1032 | - $QST_values = array( |
|
1033 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | - 'QST_system' => 'country', |
|
1036 | - 'QST_type' => 'COUNTRY', |
|
1037 | - 'QST_required' => 0, |
|
1038 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | - 'QST_order' => 7, |
|
1040 | - 'QST_admin_only' => 0, |
|
1041 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | - 'QST_deleted' => 0, |
|
1043 | - ); |
|
1044 | - break; |
|
1045 | - case 'state': |
|
1046 | - $QST_values = array( |
|
1047 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | - 'QST_system' => 'state', |
|
1050 | - 'QST_type' => 'STATE', |
|
1051 | - 'QST_required' => 0, |
|
1052 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | - 'QST_order' => 8, |
|
1054 | - 'QST_admin_only' => 0, |
|
1055 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | - 'QST_deleted' => 0, |
|
1057 | - ); |
|
1058 | - break; |
|
1059 | - case 'zip': |
|
1060 | - $QST_values = array( |
|
1061 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | - 'QST_system' => 'zip', |
|
1064 | - 'QST_type' => 'TEXT', |
|
1065 | - 'QST_required' => 0, |
|
1066 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | - 'QST_order' => 9, |
|
1068 | - 'QST_admin_only' => 0, |
|
1069 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | - 'QST_deleted' => 0, |
|
1072 | - ); |
|
1073 | - break; |
|
1074 | - case 'phone': |
|
1075 | - $QST_values = array( |
|
1076 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | - 'QST_system' => 'phone', |
|
1079 | - 'QST_type' => 'TEXT', |
|
1080 | - 'QST_required' => 0, |
|
1081 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | - 'QST_order' => 10, |
|
1083 | - 'QST_admin_only' => 0, |
|
1084 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | - 'QST_deleted' => 0, |
|
1087 | - ); |
|
1088 | - break; |
|
1089 | - } |
|
1090 | - if (! empty($QST_values)) { |
|
1091 | - // insert system question |
|
1092 | - $wpdb->insert( |
|
1093 | - $table_name, |
|
1094 | - $QST_values, |
|
1095 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | - ); |
|
1097 | - $QST_ID = $wpdb->insert_id; |
|
1098 | - // QUESTION GROUP QUESTIONS |
|
1099 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | - } else { |
|
1102 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | - } |
|
1104 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | - } else { |
|
1107 | - $id_col = EEM_Question_Group::instance() |
|
1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | - if (is_array($id_col)) { |
|
1110 | - $QSG_ID = reset($id_col); |
|
1111 | - } else { |
|
1112 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | - EE_Log::instance()->log( |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - sprintf( |
|
1117 | - __( |
|
1118 | - 'Could not associate question %1$s to a question group because no system question |
|
835 | + 'event_espresso' |
|
836 | + ), |
|
837 | + __FILE__, |
|
838 | + __FUNCTION__, |
|
839 | + __LINE__ |
|
840 | + ); |
|
841 | + return false; |
|
842 | + } |
|
843 | + return true; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * initialize_system_questions |
|
850 | + * |
|
851 | + * @access public |
|
852 | + * @static |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public static function initialize_system_questions() |
|
856 | + { |
|
857 | + // QUESTION GROUPS |
|
858 | + global $wpdb; |
|
859 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | + // what we have |
|
862 | + $question_groups = $wpdb->get_col($SQL); |
|
863 | + // check the response |
|
864 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | + // what we should have |
|
866 | + $QSG_systems = array(1, 2); |
|
867 | + // loop thru what we should have and compare to what we have |
|
868 | + foreach ($QSG_systems as $QSG_system) { |
|
869 | + // reset values array |
|
870 | + $QSG_values = array(); |
|
871 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | + if (! in_array("$QSG_system", $question_groups)) { |
|
873 | + // add it |
|
874 | + switch ($QSG_system) { |
|
875 | + case 1: |
|
876 | + $QSG_values = array( |
|
877 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | + 'QSG_desc' => '', |
|
880 | + 'QSG_order' => 1, |
|
881 | + 'QSG_show_group_name' => 1, |
|
882 | + 'QSG_show_group_desc' => 1, |
|
883 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | + 'QSG_deleted' => 0, |
|
885 | + ); |
|
886 | + break; |
|
887 | + case 2: |
|
888 | + $QSG_values = array( |
|
889 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | + 'QSG_identifier' => 'address-information-' . time(), |
|
891 | + 'QSG_desc' => '', |
|
892 | + 'QSG_order' => 2, |
|
893 | + 'QSG_show_group_name' => 1, |
|
894 | + 'QSG_show_group_desc' => 1, |
|
895 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | + 'QSG_deleted' => 0, |
|
897 | + ); |
|
898 | + break; |
|
899 | + } |
|
900 | + // make sure we have some values before inserting them |
|
901 | + if (! empty($QSG_values)) { |
|
902 | + // insert system question |
|
903 | + $wpdb->insert( |
|
904 | + $table_name, |
|
905 | + $QSG_values, |
|
906 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | + ); |
|
908 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | + } |
|
910 | + } |
|
911 | + } |
|
912 | + // QUESTIONS |
|
913 | + global $wpdb; |
|
914 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | + // what we have |
|
917 | + $questions = $wpdb->get_col($SQL); |
|
918 | + // what we should have |
|
919 | + $QST_systems = array( |
|
920 | + 'fname', |
|
921 | + 'lname', |
|
922 | + 'email', |
|
923 | + 'address', |
|
924 | + 'address2', |
|
925 | + 'city', |
|
926 | + 'country', |
|
927 | + 'state', |
|
928 | + 'zip', |
|
929 | + 'phone', |
|
930 | + ); |
|
931 | + $order_for_group_1 = 1; |
|
932 | + $order_for_group_2 = 1; |
|
933 | + // loop thru what we should have and compare to what we have |
|
934 | + foreach ($QST_systems as $QST_system) { |
|
935 | + // reset values array |
|
936 | + $QST_values = array(); |
|
937 | + // if we don't have what we should have |
|
938 | + if (! in_array($QST_system, $questions)) { |
|
939 | + // add it |
|
940 | + switch ($QST_system) { |
|
941 | + case 'fname': |
|
942 | + $QST_values = array( |
|
943 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | + 'QST_system' => 'fname', |
|
946 | + 'QST_type' => 'TEXT', |
|
947 | + 'QST_required' => 1, |
|
948 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | + 'QST_order' => 1, |
|
950 | + 'QST_admin_only' => 0, |
|
951 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | + 'QST_deleted' => 0, |
|
954 | + ); |
|
955 | + break; |
|
956 | + case 'lname': |
|
957 | + $QST_values = array( |
|
958 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | + 'QST_system' => 'lname', |
|
961 | + 'QST_type' => 'TEXT', |
|
962 | + 'QST_required' => 1, |
|
963 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | + 'QST_order' => 2, |
|
965 | + 'QST_admin_only' => 0, |
|
966 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | + 'QST_deleted' => 0, |
|
969 | + ); |
|
970 | + break; |
|
971 | + case 'email': |
|
972 | + $QST_values = array( |
|
973 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | + 'QST_system' => 'email', |
|
976 | + 'QST_type' => 'EMAIL', |
|
977 | + 'QST_required' => 1, |
|
978 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | + 'QST_order' => 3, |
|
980 | + 'QST_admin_only' => 0, |
|
981 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | + 'QST_deleted' => 0, |
|
984 | + ); |
|
985 | + break; |
|
986 | + case 'address': |
|
987 | + $QST_values = array( |
|
988 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | + 'QST_system' => 'address', |
|
991 | + 'QST_type' => 'TEXT', |
|
992 | + 'QST_required' => 0, |
|
993 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | + 'QST_order' => 4, |
|
995 | + 'QST_admin_only' => 0, |
|
996 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | + 'QST_deleted' => 0, |
|
999 | + ); |
|
1000 | + break; |
|
1001 | + case 'address2': |
|
1002 | + $QST_values = array( |
|
1003 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | + 'QST_system' => 'address2', |
|
1006 | + 'QST_type' => 'TEXT', |
|
1007 | + 'QST_required' => 0, |
|
1008 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | + 'QST_order' => 5, |
|
1010 | + 'QST_admin_only' => 0, |
|
1011 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | + 'QST_deleted' => 0, |
|
1014 | + ); |
|
1015 | + break; |
|
1016 | + case 'city': |
|
1017 | + $QST_values = array( |
|
1018 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | + 'QST_system' => 'city', |
|
1021 | + 'QST_type' => 'TEXT', |
|
1022 | + 'QST_required' => 0, |
|
1023 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | + 'QST_order' => 6, |
|
1025 | + 'QST_admin_only' => 0, |
|
1026 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | + 'QST_deleted' => 0, |
|
1029 | + ); |
|
1030 | + break; |
|
1031 | + case 'country': |
|
1032 | + $QST_values = array( |
|
1033 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | + 'QST_system' => 'country', |
|
1036 | + 'QST_type' => 'COUNTRY', |
|
1037 | + 'QST_required' => 0, |
|
1038 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | + 'QST_order' => 7, |
|
1040 | + 'QST_admin_only' => 0, |
|
1041 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | + 'QST_deleted' => 0, |
|
1043 | + ); |
|
1044 | + break; |
|
1045 | + case 'state': |
|
1046 | + $QST_values = array( |
|
1047 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | + 'QST_system' => 'state', |
|
1050 | + 'QST_type' => 'STATE', |
|
1051 | + 'QST_required' => 0, |
|
1052 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | + 'QST_order' => 8, |
|
1054 | + 'QST_admin_only' => 0, |
|
1055 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | + 'QST_deleted' => 0, |
|
1057 | + ); |
|
1058 | + break; |
|
1059 | + case 'zip': |
|
1060 | + $QST_values = array( |
|
1061 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | + 'QST_system' => 'zip', |
|
1064 | + 'QST_type' => 'TEXT', |
|
1065 | + 'QST_required' => 0, |
|
1066 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | + 'QST_order' => 9, |
|
1068 | + 'QST_admin_only' => 0, |
|
1069 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | + 'QST_deleted' => 0, |
|
1072 | + ); |
|
1073 | + break; |
|
1074 | + case 'phone': |
|
1075 | + $QST_values = array( |
|
1076 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | + 'QST_system' => 'phone', |
|
1079 | + 'QST_type' => 'TEXT', |
|
1080 | + 'QST_required' => 0, |
|
1081 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | + 'QST_order' => 10, |
|
1083 | + 'QST_admin_only' => 0, |
|
1084 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | + 'QST_deleted' => 0, |
|
1087 | + ); |
|
1088 | + break; |
|
1089 | + } |
|
1090 | + if (! empty($QST_values)) { |
|
1091 | + // insert system question |
|
1092 | + $wpdb->insert( |
|
1093 | + $table_name, |
|
1094 | + $QST_values, |
|
1095 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | + ); |
|
1097 | + $QST_ID = $wpdb->insert_id; |
|
1098 | + // QUESTION GROUP QUESTIONS |
|
1099 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | + } else { |
|
1102 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | + } |
|
1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | + } else { |
|
1107 | + $id_col = EEM_Question_Group::instance() |
|
1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | + if (is_array($id_col)) { |
|
1110 | + $QSG_ID = reset($id_col); |
|
1111 | + } else { |
|
1112 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | + EE_Log::instance()->log( |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + sprintf( |
|
1117 | + __( |
|
1118 | + 'Could not associate question %1$s to a question group because no system question |
|
1119 | 1119 | group existed', |
1120 | - 'event_espresso' |
|
1121 | - ), |
|
1122 | - $QST_ID), |
|
1123 | - 'error'); |
|
1124 | - continue; |
|
1125 | - } |
|
1126 | - } |
|
1127 | - // add system questions to groups |
|
1128 | - $wpdb->insert( |
|
1129 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | - array( |
|
1131 | - 'QSG_ID' => $QSG_ID, |
|
1132 | - 'QST_ID' => $QST_ID, |
|
1133 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | - ), |
|
1135 | - array('%d', '%d', '%d') |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Makes sure the default payment method (Invoice) is active. |
|
1145 | - * This used to be done automatically as part of constructing the old gateways config |
|
1146 | - * |
|
1147 | - * @throws \EE_Error |
|
1148 | - */ |
|
1149 | - public static function insert_default_payment_methods() |
|
1150 | - { |
|
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | - } else { |
|
1155 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * insert_default_status_codes |
|
1161 | - * |
|
1162 | - * @access public |
|
1163 | - * @static |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - public static function insert_default_status_codes() |
|
1167 | - { |
|
1168 | - |
|
1169 | - global $wpdb; |
|
1170 | - |
|
1171 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | - |
|
1173 | - $table_name = EEM_Status::instance()->table(); |
|
1174 | - |
|
1175 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | - $wpdb->query($SQL); |
|
1177 | - |
|
1178 | - $SQL = "INSERT INTO $table_name |
|
1120 | + 'event_espresso' |
|
1121 | + ), |
|
1122 | + $QST_ID), |
|
1123 | + 'error'); |
|
1124 | + continue; |
|
1125 | + } |
|
1126 | + } |
|
1127 | + // add system questions to groups |
|
1128 | + $wpdb->insert( |
|
1129 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | + array( |
|
1131 | + 'QSG_ID' => $QSG_ID, |
|
1132 | + 'QST_ID' => $QST_ID, |
|
1133 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | + ), |
|
1135 | + array('%d', '%d', '%d') |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Makes sure the default payment method (Invoice) is active. |
|
1145 | + * This used to be done automatically as part of constructing the old gateways config |
|
1146 | + * |
|
1147 | + * @throws \EE_Error |
|
1148 | + */ |
|
1149 | + public static function insert_default_payment_methods() |
|
1150 | + { |
|
1151 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | + } else { |
|
1155 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * insert_default_status_codes |
|
1161 | + * |
|
1162 | + * @access public |
|
1163 | + * @static |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + public static function insert_default_status_codes() |
|
1167 | + { |
|
1168 | + |
|
1169 | + global $wpdb; |
|
1170 | + |
|
1171 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | + |
|
1173 | + $table_name = EEM_Status::instance()->table(); |
|
1174 | + |
|
1175 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | + $wpdb->query($SQL); |
|
1177 | + |
|
1178 | + $SQL = "INSERT INTO $table_name |
|
1179 | 1179 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1180 | 1180 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1181 | 1181 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1215,521 +1215,521 @@ discard block |
||
1215 | 1215 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1216 | 1216 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1217 | 1217 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1218 | - $wpdb->query($SQL); |
|
1219 | - |
|
1220 | - } |
|
1221 | - |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * create_upload_directories |
|
1227 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | - * |
|
1229 | - * @access public |
|
1230 | - * @static |
|
1231 | - * @return boolean success of verifying upload directories exist |
|
1232 | - */ |
|
1233 | - public static function create_upload_directories() |
|
1234 | - { |
|
1235 | - // Create the required folders |
|
1236 | - $folders = array( |
|
1237 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | - ); |
|
1243 | - foreach ($folders as $folder) { |
|
1244 | - try { |
|
1245 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | - @ chmod($folder, 0755); |
|
1247 | - } catch (EE_Error $e) { |
|
1248 | - EE_Error::add_error( |
|
1249 | - sprintf( |
|
1250 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | - $folder, |
|
1252 | - '<br />' . $e->getMessage() |
|
1253 | - ), |
|
1254 | - __FILE__, __FUNCTION__, __LINE__ |
|
1255 | - ); |
|
1256 | - //indicate we'll need to fix this later |
|
1257 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | - return false; |
|
1259 | - } |
|
1260 | - } |
|
1261 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | - //is disabled, there might be activation errors recorded in there |
|
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | - //remember EE's folders are all good |
|
1265 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | - return true; |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Whether the upload directories need to be fixed or not. |
|
1271 | - * If EE is installed but filesystem access isn't initially available, |
|
1272 | - * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | - * so there might be period of time when EE is installed but its |
|
1274 | - * upload directories aren't available. This indicates such a state |
|
1275 | - * |
|
1276 | - * @return boolean |
|
1277 | - */ |
|
1278 | - public static function upload_directories_incomplete() |
|
1279 | - { |
|
1280 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * generate_default_message_templates |
|
1286 | - * |
|
1287 | - * @static |
|
1288 | - * @throws EE_Error |
|
1289 | - * @return bool true means new templates were created. |
|
1290 | - * false means no templates were created. |
|
1291 | - * This is NOT an error flag. To check for errors you will want |
|
1292 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | - */ |
|
1294 | - public static function generate_default_message_templates() |
|
1295 | - { |
|
1296 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | - /* |
|
1218 | + $wpdb->query($SQL); |
|
1219 | + |
|
1220 | + } |
|
1221 | + |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * create_upload_directories |
|
1227 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | + * |
|
1229 | + * @access public |
|
1230 | + * @static |
|
1231 | + * @return boolean success of verifying upload directories exist |
|
1232 | + */ |
|
1233 | + public static function create_upload_directories() |
|
1234 | + { |
|
1235 | + // Create the required folders |
|
1236 | + $folders = array( |
|
1237 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | + ); |
|
1243 | + foreach ($folders as $folder) { |
|
1244 | + try { |
|
1245 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | + @ chmod($folder, 0755); |
|
1247 | + } catch (EE_Error $e) { |
|
1248 | + EE_Error::add_error( |
|
1249 | + sprintf( |
|
1250 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | + $folder, |
|
1252 | + '<br />' . $e->getMessage() |
|
1253 | + ), |
|
1254 | + __FILE__, __FUNCTION__, __LINE__ |
|
1255 | + ); |
|
1256 | + //indicate we'll need to fix this later |
|
1257 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | + return false; |
|
1259 | + } |
|
1260 | + } |
|
1261 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | + //is disabled, there might be activation errors recorded in there |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | + //remember EE's folders are all good |
|
1265 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | + return true; |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Whether the upload directories need to be fixed or not. |
|
1271 | + * If EE is installed but filesystem access isn't initially available, |
|
1272 | + * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | + * so there might be period of time when EE is installed but its |
|
1274 | + * upload directories aren't available. This indicates such a state |
|
1275 | + * |
|
1276 | + * @return boolean |
|
1277 | + */ |
|
1278 | + public static function upload_directories_incomplete() |
|
1279 | + { |
|
1280 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * generate_default_message_templates |
|
1286 | + * |
|
1287 | + * @static |
|
1288 | + * @throws EE_Error |
|
1289 | + * @return bool true means new templates were created. |
|
1290 | + * false means no templates were created. |
|
1291 | + * This is NOT an error flag. To check for errors you will want |
|
1292 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | + */ |
|
1294 | + public static function generate_default_message_templates() |
|
1295 | + { |
|
1296 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | + /* |
|
1299 | 1299 | * This first method is taking care of ensuring any default messengers |
1300 | 1300 | * that should be made active and have templates generated are done. |
1301 | 1301 | */ |
1302 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | - $message_resource_manager |
|
1304 | - ); |
|
1305 | - /** |
|
1306 | - * This method is verifying there are no NEW default message types |
|
1307 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | - */ |
|
1309 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | - $message_resource_manager |
|
1311 | - ); |
|
1312 | - //after all is done, let's persist these changes to the db. |
|
1313 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | - $message_resource_manager->update_active_messengers_option(); |
|
1315 | - // will return true if either of these are true. Otherwise will return false. |
|
1316 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | - * @return array|bool |
|
1324 | - * @throws \EE_Error |
|
1325 | - */ |
|
1326 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
1328 | - ) { |
|
1329 | - /** @type EE_messenger[] $active_messengers */ |
|
1330 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | - $templates_created = false; |
|
1333 | - foreach ($active_messengers as $active_messenger) { |
|
1334 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | - $default_message_type_names_to_activate = array(); |
|
1336 | - // looping through each default message type reported by the messenger |
|
1337 | - // and setup the actual message types to activate. |
|
1338 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | - // if already active or has already been activated before we skip |
|
1340 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | - // we also skip if the message type is not installed. |
|
1342 | - if ( |
|
1343 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | - $default_message_type_name_for_messenger, |
|
1345 | - $active_messenger->name |
|
1346 | - ) |
|
1347 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | - $active_messenger->name, |
|
1349 | - $default_message_type_name_for_messenger |
|
1350 | - ) |
|
1351 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | - ) { |
|
1353 | - continue; |
|
1354 | - } |
|
1355 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | - } |
|
1357 | - //let's activate! |
|
1358 | - $message_resource_manager->ensure_message_types_are_active( |
|
1359 | - $default_message_type_names_to_activate, |
|
1360 | - $active_messenger->name, |
|
1361 | - false |
|
1362 | - ); |
|
1363 | - //activate the templates for these message types |
|
1364 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | - $active_messenger->name, |
|
1367 | - $default_message_type_names_for_messenger, |
|
1368 | - '', |
|
1369 | - true |
|
1370 | - ); |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $templates_created; |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | - * |
|
1381 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | - * False means that there were no templates generated |
|
1384 | - * (which could simply mean there are no default message types for a messenger). |
|
1385 | - * @throws EE_Error |
|
1386 | - */ |
|
1387 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | - EE_Message_Resource_Manager $message_resource_manager |
|
1389 | - ) { |
|
1390 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | - $templates_generated = false; |
|
1394 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | - //verify the default message types match an installed message type. |
|
1397 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | - if ( |
|
1399 | - ! isset($installed_message_types[$name]) |
|
1400 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | - $name, |
|
1402 | - $messenger_to_generate->name |
|
1403 | - ) |
|
1404 | - ) { |
|
1405 | - unset($default_message_type_names_for_messenger[$key]); |
|
1406 | - } |
|
1407 | - } |
|
1408 | - // in previous iterations, the active_messengers option in the db |
|
1409 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | - // passing off to create templates (after the refactor is done). |
|
1412 | - // @todo remove this comment when determined not necessary. |
|
1413 | - $message_resource_manager->activate_messenger( |
|
1414 | - $messenger_to_generate->name, |
|
1415 | - $default_message_type_names_for_messenger, |
|
1416 | - false |
|
1417 | - ); |
|
1418 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | - $messenger_to_generate->name, |
|
1422 | - $default_message_type_names_for_messenger, |
|
1423 | - '', |
|
1424 | - true |
|
1425 | - ); |
|
1426 | - } |
|
1427 | - } |
|
1428 | - return $templates_generated; |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | - * It considers: |
|
1435 | - * - whether a messenger is already active in the db. |
|
1436 | - * - whether a messenger has been made active at any time in the past. |
|
1437 | - * |
|
1438 | - * @static |
|
1439 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | - * @return EE_messenger[] |
|
1441 | - */ |
|
1442 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | - EE_Message_Resource_Manager $message_resource_manager |
|
1444 | - ) { |
|
1445 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | - |
|
1449 | - $messengers_to_generate = array(); |
|
1450 | - foreach ($installed_messengers as $installed_messenger) { |
|
1451 | - //if installed messenger is a messenger that should be activated on install |
|
1452 | - //and is not already active |
|
1453 | - //and has never been activated |
|
1454 | - if ( |
|
1455 | - ! $installed_messenger->activate_on_install |
|
1456 | - || isset($active_messengers[$installed_messenger->name]) |
|
1457 | - || isset($has_activated[$installed_messenger->name]) |
|
1458 | - ) { |
|
1459 | - continue; |
|
1460 | - } |
|
1461 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | - } |
|
1463 | - return $messengers_to_generate; |
|
1464 | - } |
|
1465 | - |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * This simply validates active message types to ensure they actually match installed |
|
1469 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | - * rows are set inactive. |
|
1471 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | - * are still handled in here. |
|
1474 | - * |
|
1475 | - * @since 4.3.1 |
|
1476 | - * @return void |
|
1477 | - */ |
|
1478 | - public static function validate_messages_system() |
|
1479 | - { |
|
1480 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | - } |
|
1485 | - |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * create_no_ticket_prices_array |
|
1489 | - * |
|
1490 | - * @access public |
|
1491 | - * @static |
|
1492 | - * @return void |
|
1493 | - */ |
|
1494 | - public static function create_no_ticket_prices_array() |
|
1495 | - { |
|
1496 | - // this creates an array for tracking events that have no active ticket prices created |
|
1497 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | - if (! $espresso_no_ticket_prices) { |
|
1500 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | - } |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * plugin_deactivation |
|
1507 | - * |
|
1508 | - * @access public |
|
1509 | - * @static |
|
1510 | - * @return void |
|
1511 | - */ |
|
1512 | - public static function plugin_deactivation() |
|
1513 | - { |
|
1514 | - } |
|
1515 | - |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | - * (like post meta or term relations) |
|
1520 | - * |
|
1521 | - * @global wpdb $wpdb |
|
1522 | - * @throws \EE_Error |
|
1523 | - */ |
|
1524 | - public static function delete_all_espresso_cpt_data() |
|
1525 | - { |
|
1526 | - global $wpdb; |
|
1527 | - //get all the CPT post_types |
|
1528 | - $ee_post_types = array(); |
|
1529 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | - if (method_exists($model_name, 'instance')) { |
|
1531 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | - } |
|
1535 | - } |
|
1536 | - } |
|
1537 | - //get all our CPTs |
|
1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | - $cpt_ids = $wpdb->get_col($query); |
|
1540 | - //delete each post meta and term relations too |
|
1541 | - foreach ($cpt_ids as $post_id) { |
|
1542 | - wp_delete_post($post_id, true); |
|
1543 | - } |
|
1544 | - } |
|
1545 | - |
|
1546 | - /** |
|
1547 | - * Deletes all EE custom tables |
|
1548 | - * |
|
1549 | - * @return array |
|
1550 | - */ |
|
1551 | - public static function drop_espresso_tables() |
|
1552 | - { |
|
1553 | - $tables = array(); |
|
1554 | - // load registry |
|
1555 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | - if (method_exists($model_name, 'instance')) { |
|
1557 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | - if ($model_obj instanceof EEM_Base) { |
|
1559 | - foreach ($model_obj->get_tables() as $table) { |
|
1560 | - if (strpos($table->get_table_name(), 'esp_') |
|
1561 | - && |
|
1562 | - ( |
|
1563 | - is_main_site()//main site? nuke them all |
|
1564 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | - ) |
|
1566 | - ) { |
|
1567 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | - } |
|
1569 | - } |
|
1570 | - } |
|
1571 | - } |
|
1572 | - } |
|
1573 | - |
|
1574 | - //there are some tables whose models were removed. |
|
1575 | - //they should be removed when removing all EE core's data |
|
1576 | - $tables_without_models = array( |
|
1577 | - 'esp_promotion', |
|
1578 | - 'esp_promotion_applied', |
|
1579 | - 'esp_promotion_object', |
|
1580 | - 'esp_promotion_rule', |
|
1581 | - 'esp_rule', |
|
1582 | - ); |
|
1583 | - foreach ($tables_without_models as $table) { |
|
1584 | - $tables[$table] = $table; |
|
1585 | - } |
|
1586 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | - } |
|
1588 | - |
|
1589 | - |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | - * Returns the list actually deleted |
|
1595 | - * |
|
1596 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | - * @global WPDB $wpdb |
|
1598 | - * @param array $table_names |
|
1599 | - * @return array of table names which we deleted |
|
1600 | - */ |
|
1601 | - public static function drop_tables($table_names) |
|
1602 | - { |
|
1603 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | - } |
|
1605 | - |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * plugin_uninstall |
|
1610 | - * |
|
1611 | - * @access public |
|
1612 | - * @static |
|
1613 | - * @param bool $remove_all |
|
1614 | - * @return void |
|
1615 | - */ |
|
1616 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | - { |
|
1618 | - global $wpdb; |
|
1619 | - self::drop_espresso_tables(); |
|
1620 | - $wp_options_to_delete = array( |
|
1621 | - 'ee_no_ticket_prices' => true, |
|
1622 | - 'ee_active_messengers' => true, |
|
1623 | - 'ee_has_activated_messenger' => true, |
|
1624 | - 'ee_flush_rewrite_rules' => true, |
|
1625 | - 'ee_config' => false, |
|
1626 | - 'ee_data_migration_current_db_state' => true, |
|
1627 | - 'ee_data_migration_mapping_' => false, |
|
1628 | - 'ee_data_migration_script_' => false, |
|
1629 | - 'ee_data_migrations' => true, |
|
1630 | - 'ee_dms_map' => false, |
|
1631 | - 'ee_notices' => true, |
|
1632 | - 'lang_file_check_' => false, |
|
1633 | - 'ee_maintenance_mode' => true, |
|
1634 | - 'ee_ueip_optin' => true, |
|
1635 | - 'ee_ueip_has_notified' => true, |
|
1636 | - 'ee_plugin_activation_errors' => true, |
|
1637 | - 'ee_id_mapping_from' => false, |
|
1638 | - 'espresso_persistent_admin_notices' => true, |
|
1639 | - 'ee_encryption_key' => true, |
|
1640 | - 'pue_force_upgrade_' => false, |
|
1641 | - 'pue_json_error_' => false, |
|
1642 | - 'pue_install_key_' => false, |
|
1643 | - 'pue_verification_error_' => false, |
|
1644 | - 'pu_dismissed_upgrade_' => false, |
|
1645 | - 'external_updates-' => false, |
|
1646 | - 'ee_extra_data' => true, |
|
1647 | - 'ee_ssn_' => false, |
|
1648 | - 'ee_rss_' => false, |
|
1649 | - 'ee_rte_n_tx_' => false, |
|
1650 | - 'ee_pers_admin_notices' => true, |
|
1651 | - 'ee_job_parameters_' => false, |
|
1652 | - 'ee_upload_directories_incomplete' => true, |
|
1653 | - 'ee_verified_db_collations' => true, |
|
1654 | - ); |
|
1655 | - if (is_main_site()) { |
|
1656 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | - } |
|
1658 | - $undeleted_options = array(); |
|
1659 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | - if ($no_wildcard) { |
|
1661 | - if ( ! delete_option($option_name)) { |
|
1662 | - $undeleted_options[] = $option_name; |
|
1663 | - } |
|
1664 | - } else { |
|
1665 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | - } |
|
1670 | - } |
|
1671 | - } |
|
1672 | - } |
|
1673 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | - $db_update_sans_ee4 = array(); |
|
1677 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | - $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | - } |
|
1681 | - } |
|
1682 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | - } |
|
1684 | - $errors = ''; |
|
1685 | - if ( ! empty($undeleted_options)) { |
|
1686 | - $errors .= sprintf( |
|
1687 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | - '<br/>', |
|
1689 | - implode(',<br/>', $undeleted_options) |
|
1690 | - ); |
|
1691 | - } |
|
1692 | - if ( ! empty($errors)) { |
|
1693 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | - } |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * Gets the mysql error code from the last used query by wpdb |
|
1699 | - * |
|
1700 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | - */ |
|
1702 | - public static function last_wpdb_error_code() |
|
1703 | - { |
|
1704 | - global $wpdb; |
|
1705 | - if ($wpdb->use_mysqli) { |
|
1706 | - return mysqli_errno($wpdb->dbh); |
|
1707 | - } else { |
|
1708 | - return mysql_errno($wpdb->dbh); |
|
1709 | - } |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | - * |
|
1715 | - * @global wpdb $wpdb |
|
1716 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | - * @param string $table_name with or without $wpdb->prefix |
|
1718 | - * @return boolean |
|
1719 | - */ |
|
1720 | - public static function table_exists($table_name) |
|
1721 | - { |
|
1722 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * Resets the cache on EEH_Activation |
|
1727 | - */ |
|
1728 | - public static function reset() |
|
1729 | - { |
|
1730 | - self::$_default_creator_id = null; |
|
1731 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | - } |
|
1302 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | + $message_resource_manager |
|
1304 | + ); |
|
1305 | + /** |
|
1306 | + * This method is verifying there are no NEW default message types |
|
1307 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | + */ |
|
1309 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | + $message_resource_manager |
|
1311 | + ); |
|
1312 | + //after all is done, let's persist these changes to the db. |
|
1313 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | + $message_resource_manager->update_active_messengers_option(); |
|
1315 | + // will return true if either of these are true. Otherwise will return false. |
|
1316 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | + * @return array|bool |
|
1324 | + * @throws \EE_Error |
|
1325 | + */ |
|
1326 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
1328 | + ) { |
|
1329 | + /** @type EE_messenger[] $active_messengers */ |
|
1330 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | + $templates_created = false; |
|
1333 | + foreach ($active_messengers as $active_messenger) { |
|
1334 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | + $default_message_type_names_to_activate = array(); |
|
1336 | + // looping through each default message type reported by the messenger |
|
1337 | + // and setup the actual message types to activate. |
|
1338 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | + // if already active or has already been activated before we skip |
|
1340 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | + // we also skip if the message type is not installed. |
|
1342 | + if ( |
|
1343 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | + $default_message_type_name_for_messenger, |
|
1345 | + $active_messenger->name |
|
1346 | + ) |
|
1347 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | + $active_messenger->name, |
|
1349 | + $default_message_type_name_for_messenger |
|
1350 | + ) |
|
1351 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | + ) { |
|
1353 | + continue; |
|
1354 | + } |
|
1355 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | + } |
|
1357 | + //let's activate! |
|
1358 | + $message_resource_manager->ensure_message_types_are_active( |
|
1359 | + $default_message_type_names_to_activate, |
|
1360 | + $active_messenger->name, |
|
1361 | + false |
|
1362 | + ); |
|
1363 | + //activate the templates for these message types |
|
1364 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | + $active_messenger->name, |
|
1367 | + $default_message_type_names_for_messenger, |
|
1368 | + '', |
|
1369 | + true |
|
1370 | + ); |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $templates_created; |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | + * |
|
1381 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | + * False means that there were no templates generated |
|
1384 | + * (which could simply mean there are no default message types for a messenger). |
|
1385 | + * @throws EE_Error |
|
1386 | + */ |
|
1387 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | + EE_Message_Resource_Manager $message_resource_manager |
|
1389 | + ) { |
|
1390 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | + $templates_generated = false; |
|
1394 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | + //verify the default message types match an installed message type. |
|
1397 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | + if ( |
|
1399 | + ! isset($installed_message_types[$name]) |
|
1400 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | + $name, |
|
1402 | + $messenger_to_generate->name |
|
1403 | + ) |
|
1404 | + ) { |
|
1405 | + unset($default_message_type_names_for_messenger[$key]); |
|
1406 | + } |
|
1407 | + } |
|
1408 | + // in previous iterations, the active_messengers option in the db |
|
1409 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | + // passing off to create templates (after the refactor is done). |
|
1412 | + // @todo remove this comment when determined not necessary. |
|
1413 | + $message_resource_manager->activate_messenger( |
|
1414 | + $messenger_to_generate->name, |
|
1415 | + $default_message_type_names_for_messenger, |
|
1416 | + false |
|
1417 | + ); |
|
1418 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | + $messenger_to_generate->name, |
|
1422 | + $default_message_type_names_for_messenger, |
|
1423 | + '', |
|
1424 | + true |
|
1425 | + ); |
|
1426 | + } |
|
1427 | + } |
|
1428 | + return $templates_generated; |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | + * It considers: |
|
1435 | + * - whether a messenger is already active in the db. |
|
1436 | + * - whether a messenger has been made active at any time in the past. |
|
1437 | + * |
|
1438 | + * @static |
|
1439 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | + * @return EE_messenger[] |
|
1441 | + */ |
|
1442 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | + EE_Message_Resource_Manager $message_resource_manager |
|
1444 | + ) { |
|
1445 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | + |
|
1449 | + $messengers_to_generate = array(); |
|
1450 | + foreach ($installed_messengers as $installed_messenger) { |
|
1451 | + //if installed messenger is a messenger that should be activated on install |
|
1452 | + //and is not already active |
|
1453 | + //and has never been activated |
|
1454 | + if ( |
|
1455 | + ! $installed_messenger->activate_on_install |
|
1456 | + || isset($active_messengers[$installed_messenger->name]) |
|
1457 | + || isset($has_activated[$installed_messenger->name]) |
|
1458 | + ) { |
|
1459 | + continue; |
|
1460 | + } |
|
1461 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | + } |
|
1463 | + return $messengers_to_generate; |
|
1464 | + } |
|
1465 | + |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * This simply validates active message types to ensure they actually match installed |
|
1469 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | + * rows are set inactive. |
|
1471 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | + * are still handled in here. |
|
1474 | + * |
|
1475 | + * @since 4.3.1 |
|
1476 | + * @return void |
|
1477 | + */ |
|
1478 | + public static function validate_messages_system() |
|
1479 | + { |
|
1480 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | + } |
|
1485 | + |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * create_no_ticket_prices_array |
|
1489 | + * |
|
1490 | + * @access public |
|
1491 | + * @static |
|
1492 | + * @return void |
|
1493 | + */ |
|
1494 | + public static function create_no_ticket_prices_array() |
|
1495 | + { |
|
1496 | + // this creates an array for tracking events that have no active ticket prices created |
|
1497 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | + if (! $espresso_no_ticket_prices) { |
|
1500 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | + } |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * plugin_deactivation |
|
1507 | + * |
|
1508 | + * @access public |
|
1509 | + * @static |
|
1510 | + * @return void |
|
1511 | + */ |
|
1512 | + public static function plugin_deactivation() |
|
1513 | + { |
|
1514 | + } |
|
1515 | + |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | + * (like post meta or term relations) |
|
1520 | + * |
|
1521 | + * @global wpdb $wpdb |
|
1522 | + * @throws \EE_Error |
|
1523 | + */ |
|
1524 | + public static function delete_all_espresso_cpt_data() |
|
1525 | + { |
|
1526 | + global $wpdb; |
|
1527 | + //get all the CPT post_types |
|
1528 | + $ee_post_types = array(); |
|
1529 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | + if (method_exists($model_name, 'instance')) { |
|
1531 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | + } |
|
1535 | + } |
|
1536 | + } |
|
1537 | + //get all our CPTs |
|
1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | + $cpt_ids = $wpdb->get_col($query); |
|
1540 | + //delete each post meta and term relations too |
|
1541 | + foreach ($cpt_ids as $post_id) { |
|
1542 | + wp_delete_post($post_id, true); |
|
1543 | + } |
|
1544 | + } |
|
1545 | + |
|
1546 | + /** |
|
1547 | + * Deletes all EE custom tables |
|
1548 | + * |
|
1549 | + * @return array |
|
1550 | + */ |
|
1551 | + public static function drop_espresso_tables() |
|
1552 | + { |
|
1553 | + $tables = array(); |
|
1554 | + // load registry |
|
1555 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | + if (method_exists($model_name, 'instance')) { |
|
1557 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | + if ($model_obj instanceof EEM_Base) { |
|
1559 | + foreach ($model_obj->get_tables() as $table) { |
|
1560 | + if (strpos($table->get_table_name(), 'esp_') |
|
1561 | + && |
|
1562 | + ( |
|
1563 | + is_main_site()//main site? nuke them all |
|
1564 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | + ) |
|
1566 | + ) { |
|
1567 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | + } |
|
1569 | + } |
|
1570 | + } |
|
1571 | + } |
|
1572 | + } |
|
1573 | + |
|
1574 | + //there are some tables whose models were removed. |
|
1575 | + //they should be removed when removing all EE core's data |
|
1576 | + $tables_without_models = array( |
|
1577 | + 'esp_promotion', |
|
1578 | + 'esp_promotion_applied', |
|
1579 | + 'esp_promotion_object', |
|
1580 | + 'esp_promotion_rule', |
|
1581 | + 'esp_rule', |
|
1582 | + ); |
|
1583 | + foreach ($tables_without_models as $table) { |
|
1584 | + $tables[$table] = $table; |
|
1585 | + } |
|
1586 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | + } |
|
1588 | + |
|
1589 | + |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | + * Returns the list actually deleted |
|
1595 | + * |
|
1596 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | + * @global WPDB $wpdb |
|
1598 | + * @param array $table_names |
|
1599 | + * @return array of table names which we deleted |
|
1600 | + */ |
|
1601 | + public static function drop_tables($table_names) |
|
1602 | + { |
|
1603 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | + } |
|
1605 | + |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * plugin_uninstall |
|
1610 | + * |
|
1611 | + * @access public |
|
1612 | + * @static |
|
1613 | + * @param bool $remove_all |
|
1614 | + * @return void |
|
1615 | + */ |
|
1616 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | + { |
|
1618 | + global $wpdb; |
|
1619 | + self::drop_espresso_tables(); |
|
1620 | + $wp_options_to_delete = array( |
|
1621 | + 'ee_no_ticket_prices' => true, |
|
1622 | + 'ee_active_messengers' => true, |
|
1623 | + 'ee_has_activated_messenger' => true, |
|
1624 | + 'ee_flush_rewrite_rules' => true, |
|
1625 | + 'ee_config' => false, |
|
1626 | + 'ee_data_migration_current_db_state' => true, |
|
1627 | + 'ee_data_migration_mapping_' => false, |
|
1628 | + 'ee_data_migration_script_' => false, |
|
1629 | + 'ee_data_migrations' => true, |
|
1630 | + 'ee_dms_map' => false, |
|
1631 | + 'ee_notices' => true, |
|
1632 | + 'lang_file_check_' => false, |
|
1633 | + 'ee_maintenance_mode' => true, |
|
1634 | + 'ee_ueip_optin' => true, |
|
1635 | + 'ee_ueip_has_notified' => true, |
|
1636 | + 'ee_plugin_activation_errors' => true, |
|
1637 | + 'ee_id_mapping_from' => false, |
|
1638 | + 'espresso_persistent_admin_notices' => true, |
|
1639 | + 'ee_encryption_key' => true, |
|
1640 | + 'pue_force_upgrade_' => false, |
|
1641 | + 'pue_json_error_' => false, |
|
1642 | + 'pue_install_key_' => false, |
|
1643 | + 'pue_verification_error_' => false, |
|
1644 | + 'pu_dismissed_upgrade_' => false, |
|
1645 | + 'external_updates-' => false, |
|
1646 | + 'ee_extra_data' => true, |
|
1647 | + 'ee_ssn_' => false, |
|
1648 | + 'ee_rss_' => false, |
|
1649 | + 'ee_rte_n_tx_' => false, |
|
1650 | + 'ee_pers_admin_notices' => true, |
|
1651 | + 'ee_job_parameters_' => false, |
|
1652 | + 'ee_upload_directories_incomplete' => true, |
|
1653 | + 'ee_verified_db_collations' => true, |
|
1654 | + ); |
|
1655 | + if (is_main_site()) { |
|
1656 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | + } |
|
1658 | + $undeleted_options = array(); |
|
1659 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | + if ($no_wildcard) { |
|
1661 | + if ( ! delete_option($option_name)) { |
|
1662 | + $undeleted_options[] = $option_name; |
|
1663 | + } |
|
1664 | + } else { |
|
1665 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | + } |
|
1670 | + } |
|
1671 | + } |
|
1672 | + } |
|
1673 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | + $db_update_sans_ee4 = array(); |
|
1677 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | + } |
|
1681 | + } |
|
1682 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | + } |
|
1684 | + $errors = ''; |
|
1685 | + if ( ! empty($undeleted_options)) { |
|
1686 | + $errors .= sprintf( |
|
1687 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | + '<br/>', |
|
1689 | + implode(',<br/>', $undeleted_options) |
|
1690 | + ); |
|
1691 | + } |
|
1692 | + if ( ! empty($errors)) { |
|
1693 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | + } |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * Gets the mysql error code from the last used query by wpdb |
|
1699 | + * |
|
1700 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | + */ |
|
1702 | + public static function last_wpdb_error_code() |
|
1703 | + { |
|
1704 | + global $wpdb; |
|
1705 | + if ($wpdb->use_mysqli) { |
|
1706 | + return mysqli_errno($wpdb->dbh); |
|
1707 | + } else { |
|
1708 | + return mysql_errno($wpdb->dbh); |
|
1709 | + } |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | + * |
|
1715 | + * @global wpdb $wpdb |
|
1716 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | + * @param string $table_name with or without $wpdb->prefix |
|
1718 | + * @return boolean |
|
1719 | + */ |
|
1720 | + public static function table_exists($table_name) |
|
1721 | + { |
|
1722 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * Resets the cache on EEH_Activation |
|
1727 | + */ |
|
1728 | + public static function reset() |
|
1729 | + { |
|
1730 | + self::$_default_creator_id = null; |
|
1731 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | + } |
|
1733 | 1733 | } |
1734 | 1734 | // End of file EEH_Activation.helper.php |
1735 | 1735 | // Location: /helpers/EEH_Activation.core.php |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | * define and use the hook in a specific caffeinated/whatever class or file. |
11 | 11 | */ |
12 | 12 | // defined some new constants related to caffeinated folder |
13 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
14 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS); |
|
15 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS); |
|
16 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS); |
|
13 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
14 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS); |
|
15 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS); |
|
16 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function caf_helper_paths($paths) |
78 | 78 | { |
79 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
79 | + $paths[] = EE_CAF_CORE.'helpers'.DS; |
|
80 | 80 | return $paths; |
81 | 81 | } |
82 | 82 | |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | global $wpdb; |
99 | 99 | //use same method of getting creator id as the version introducing the change |
100 | 100 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
101 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | - $price_table = $wpdb->prefix . "esp_price"; |
|
101 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
102 | + $price_table = $wpdb->prefix."esp_price"; |
|
103 | 103 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
104 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
104 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; //include trashed price types |
|
105 | 105 | $tax_price_type_count = $wpdb->get_var($SQL); |
106 | 106 | if ($tax_price_type_count <= 1) { |
107 | 107 | $wpdb->insert( |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | 'PRT_wp_user' => $default_creator_id, |
116 | 116 | ), |
117 | 117 | array( |
118 | - '%s',//PRT_name |
|
119 | - '%d',//PBT_id |
|
120 | - '%d',//PRT_is_percent |
|
121 | - '%d',//PRT_order |
|
122 | - '%d',//PRT_deleted |
|
118 | + '%s', //PRT_name |
|
119 | + '%d', //PBT_id |
|
120 | + '%d', //PRT_is_percent |
|
121 | + '%d', //PRT_order |
|
122 | + '%d', //PRT_deleted |
|
123 | 123 | '%d', //PRT_wp_user |
124 | 124 | ) |
125 | 125 | ); |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | 'PRT_wp_user' => $default_creator_id, |
136 | 136 | ), |
137 | 137 | array( |
138 | - '%s',//PRT_name |
|
139 | - '%d',//PBT_id |
|
140 | - '%d',//PRT_is_percent |
|
141 | - '%d',//PRT_order |
|
142 | - '%d',//PRT_deleted |
|
138 | + '%s', //PRT_name |
|
139 | + '%d', //PBT_id |
|
140 | + '%d', //PRT_is_percent |
|
141 | + '%d', //PRT_order |
|
142 | + '%d', //PRT_deleted |
|
143 | 143 | '%d' //PRT_wp_user |
144 | 144 | ) |
145 | 145 | ); |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | 'PRC_wp_user' => $default_creator_id, |
160 | 160 | ), |
161 | 161 | array( |
162 | - '%d',//PRT_id |
|
163 | - '%f',//PRC_amount |
|
164 | - '%s',//PRC_name |
|
165 | - '%s',//PRC_desc |
|
166 | - '%d',//PRC_is_default |
|
167 | - '%d',//PRC_overrides |
|
168 | - '%d',//PRC_deleted |
|
169 | - '%d',//PRC_order |
|
170 | - '%d',//PRC_parent |
|
162 | + '%d', //PRT_id |
|
163 | + '%f', //PRC_amount |
|
164 | + '%s', //PRC_name |
|
165 | + '%s', //PRC_desc |
|
166 | + '%d', //PRC_is_default |
|
167 | + '%d', //PRC_overrides |
|
168 | + '%d', //PRC_deleted |
|
169 | + '%d', //PRC_order |
|
170 | + '%d', //PRC_parent |
|
171 | 171 | '%d' //PRC_wp_user |
172 | 172 | ) |
173 | 173 | ); |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function caffeinated_modules_to_register($modules_to_register = array()) |
189 | 189 | { |
190 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
190 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
191 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR); |
|
192 | 192 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
193 | 193 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
194 | 194 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public function caf_payment_methods($payment_method_paths) |
270 | 270 | { |
271 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
271 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
272 | 272 | $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
273 | 273 | return $payment_method_paths; |
274 | 274 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\database\TableAnalysis; |
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 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -29,277 +29,277 @@ discard block |
||
29 | 29 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
34 | - */ |
|
35 | - protected $_table_analysis; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EE_Brewing_Regular constructor. |
|
41 | - */ |
|
42 | - public function __construct(TableAnalysis $table_analysis) |
|
43 | - { |
|
44 | - $this->_table_analysis = $table_analysis; |
|
45 | - if (defined('EE_CAFF_PATH')) { |
|
46 | - // activation |
|
47 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
48 | - // load caff init |
|
49 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
50 | - // remove the "powered by" credit link from receipts and invoices |
|
51 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
52 | - // add caffeinated modules |
|
53 | - add_filter( |
|
54 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
55 | - array($this, 'caffeinated_modules_to_register') |
|
56 | - ); |
|
57 | - // load caff scripts |
|
58 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
59 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
62 | - array($this, 'caf_payment_methods') |
|
63 | - ); |
|
64 | - // caffeinated constructed |
|
65 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
66 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
67 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
75 | - * |
|
76 | - * @param array $paths original helper paths array |
|
77 | - * @return array new array of paths |
|
78 | - */ |
|
79 | - public function caf_helper_paths($paths) |
|
80 | - { |
|
81 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
82 | - return $paths; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
89 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
90 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
91 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
92 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
93 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
94 | - * Right now, we ASSUME the only price types in the system are default ones |
|
95 | - * |
|
96 | - * @global wpdb $wpdb |
|
97 | - */ |
|
98 | - public function initialize_caf_db_content() |
|
99 | - { |
|
100 | - global $wpdb; |
|
101 | - //use same method of getting creator id as the version introducing the change |
|
102 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
103 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
104 | - $price_table = $wpdb->prefix . "esp_price"; |
|
105 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
106 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
107 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
108 | - if ($tax_price_type_count <= 1) { |
|
109 | - $wpdb->insert( |
|
110 | - $price_type_table, |
|
111 | - array( |
|
112 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
113 | - 'PBT_ID' => 4, |
|
114 | - 'PRT_is_percent' => true, |
|
115 | - 'PRT_order' => 60, |
|
116 | - 'PRT_deleted' => false, |
|
117 | - 'PRT_wp_user' => $default_creator_id, |
|
118 | - ), |
|
119 | - array( |
|
120 | - '%s',//PRT_name |
|
121 | - '%d',//PBT_id |
|
122 | - '%d',//PRT_is_percent |
|
123 | - '%d',//PRT_order |
|
124 | - '%d',//PRT_deleted |
|
125 | - '%d', //PRT_wp_user |
|
126 | - ) |
|
127 | - ); |
|
128 | - //federal tax |
|
129 | - $result = $wpdb->insert( |
|
130 | - $price_type_table, |
|
131 | - array( |
|
132 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
133 | - 'PBT_ID' => 4, |
|
134 | - 'PRT_is_percent' => true, |
|
135 | - 'PRT_order' => 70, |
|
136 | - 'PRT_deleted' => false, |
|
137 | - 'PRT_wp_user' => $default_creator_id, |
|
138 | - ), |
|
139 | - array( |
|
140 | - '%s',//PRT_name |
|
141 | - '%d',//PBT_id |
|
142 | - '%d',//PRT_is_percent |
|
143 | - '%d',//PRT_order |
|
144 | - '%d',//PRT_deleted |
|
145 | - '%d' //PRT_wp_user |
|
146 | - ) |
|
147 | - ); |
|
148 | - if ($result) { |
|
149 | - $wpdb->insert( |
|
150 | - $price_table, |
|
151 | - array( |
|
152 | - 'PRT_ID' => $wpdb->insert_id, |
|
153 | - 'PRC_amount' => 15.00, |
|
154 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
155 | - 'PRC_desc' => '', |
|
156 | - 'PRC_is_default' => true, |
|
157 | - 'PRC_overrides' => null, |
|
158 | - 'PRC_deleted' => false, |
|
159 | - 'PRC_order' => 50, |
|
160 | - 'PRC_parent' => null, |
|
161 | - 'PRC_wp_user' => $default_creator_id, |
|
162 | - ), |
|
163 | - array( |
|
164 | - '%d',//PRT_id |
|
165 | - '%f',//PRC_amount |
|
166 | - '%s',//PRC_name |
|
167 | - '%s',//PRC_desc |
|
168 | - '%d',//PRC_is_default |
|
169 | - '%d',//PRC_overrides |
|
170 | - '%d',//PRC_deleted |
|
171 | - '%d',//PRC_order |
|
172 | - '%d',//PRC_parent |
|
173 | - '%d' //PRC_wp_user |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * caffeinated_modules_to_register |
|
185 | - * |
|
186 | - * @access public |
|
187 | - * @param array $modules_to_register |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
191 | - { |
|
192 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
193 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
194 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
195 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
196 | - } |
|
197 | - } |
|
198 | - return $modules_to_register; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - public function caffeinated_init() |
|
204 | - { |
|
205 | - // EE_Register_CPTs hooks |
|
206 | - add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
207 | - add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
208 | - add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
209 | - EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
210 | - // caffeinated_init__complete hook |
|
211 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - public function enqueue_caffeinated_scripts() |
|
217 | - { |
|
218 | - // sound of crickets... |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * callbacks below here |
|
225 | - * |
|
226 | - * @param array $taxonomy_array |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function filter_taxonomies(array $taxonomy_array) |
|
230 | - { |
|
231 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
232 | - return $taxonomy_array; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param array $cpt_array |
|
239 | - * @return mixed |
|
240 | - */ |
|
241 | - public function filter_cpts(array $cpt_array) |
|
242 | - { |
|
243 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
244 | - return $cpt_array; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param array $menuitems |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - public function nav_metabox_items(array $menuitems) |
|
254 | - { |
|
255 | - $menuitems[] = array( |
|
256 | - 'title' => __('Venue List', 'event_espresso'), |
|
257 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
258 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
259 | - ); |
|
260 | - return $menuitems; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
267 | - * |
|
268 | - * @param array $payment_method_paths |
|
269 | - * @return array values are folder paths to payment method folders |
|
270 | - */ |
|
271 | - public function caf_payment_methods($payment_method_paths) |
|
272 | - { |
|
273 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
274 | - $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
275 | - return $payment_method_paths; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Gets the injected table analyzer, or throws an exception |
|
282 | - * |
|
283 | - * @return TableAnalysis |
|
284 | - * @throws \EE_Error |
|
285 | - */ |
|
286 | - protected function _get_table_analysis() |
|
287 | - { |
|
288 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
289 | - return $this->_table_analysis; |
|
290 | - } else { |
|
291 | - throw new \EE_Error( |
|
292 | - sprintf( |
|
293 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
294 | - get_class($this) |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
32 | + /** |
|
33 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
34 | + */ |
|
35 | + protected $_table_analysis; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EE_Brewing_Regular constructor. |
|
41 | + */ |
|
42 | + public function __construct(TableAnalysis $table_analysis) |
|
43 | + { |
|
44 | + $this->_table_analysis = $table_analysis; |
|
45 | + if (defined('EE_CAFF_PATH')) { |
|
46 | + // activation |
|
47 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
48 | + // load caff init |
|
49 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
50 | + // remove the "powered by" credit link from receipts and invoices |
|
51 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
52 | + // add caffeinated modules |
|
53 | + add_filter( |
|
54 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
55 | + array($this, 'caffeinated_modules_to_register') |
|
56 | + ); |
|
57 | + // load caff scripts |
|
58 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
59 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
62 | + array($this, 'caf_payment_methods') |
|
63 | + ); |
|
64 | + // caffeinated constructed |
|
65 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
66 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
67 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
75 | + * |
|
76 | + * @param array $paths original helper paths array |
|
77 | + * @return array new array of paths |
|
78 | + */ |
|
79 | + public function caf_helper_paths($paths) |
|
80 | + { |
|
81 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
82 | + return $paths; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
89 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
90 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
91 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
92 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
93 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
94 | + * Right now, we ASSUME the only price types in the system are default ones |
|
95 | + * |
|
96 | + * @global wpdb $wpdb |
|
97 | + */ |
|
98 | + public function initialize_caf_db_content() |
|
99 | + { |
|
100 | + global $wpdb; |
|
101 | + //use same method of getting creator id as the version introducing the change |
|
102 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
103 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
104 | + $price_table = $wpdb->prefix . "esp_price"; |
|
105 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
106 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
107 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
108 | + if ($tax_price_type_count <= 1) { |
|
109 | + $wpdb->insert( |
|
110 | + $price_type_table, |
|
111 | + array( |
|
112 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
113 | + 'PBT_ID' => 4, |
|
114 | + 'PRT_is_percent' => true, |
|
115 | + 'PRT_order' => 60, |
|
116 | + 'PRT_deleted' => false, |
|
117 | + 'PRT_wp_user' => $default_creator_id, |
|
118 | + ), |
|
119 | + array( |
|
120 | + '%s',//PRT_name |
|
121 | + '%d',//PBT_id |
|
122 | + '%d',//PRT_is_percent |
|
123 | + '%d',//PRT_order |
|
124 | + '%d',//PRT_deleted |
|
125 | + '%d', //PRT_wp_user |
|
126 | + ) |
|
127 | + ); |
|
128 | + //federal tax |
|
129 | + $result = $wpdb->insert( |
|
130 | + $price_type_table, |
|
131 | + array( |
|
132 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
133 | + 'PBT_ID' => 4, |
|
134 | + 'PRT_is_percent' => true, |
|
135 | + 'PRT_order' => 70, |
|
136 | + 'PRT_deleted' => false, |
|
137 | + 'PRT_wp_user' => $default_creator_id, |
|
138 | + ), |
|
139 | + array( |
|
140 | + '%s',//PRT_name |
|
141 | + '%d',//PBT_id |
|
142 | + '%d',//PRT_is_percent |
|
143 | + '%d',//PRT_order |
|
144 | + '%d',//PRT_deleted |
|
145 | + '%d' //PRT_wp_user |
|
146 | + ) |
|
147 | + ); |
|
148 | + if ($result) { |
|
149 | + $wpdb->insert( |
|
150 | + $price_table, |
|
151 | + array( |
|
152 | + 'PRT_ID' => $wpdb->insert_id, |
|
153 | + 'PRC_amount' => 15.00, |
|
154 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
155 | + 'PRC_desc' => '', |
|
156 | + 'PRC_is_default' => true, |
|
157 | + 'PRC_overrides' => null, |
|
158 | + 'PRC_deleted' => false, |
|
159 | + 'PRC_order' => 50, |
|
160 | + 'PRC_parent' => null, |
|
161 | + 'PRC_wp_user' => $default_creator_id, |
|
162 | + ), |
|
163 | + array( |
|
164 | + '%d',//PRT_id |
|
165 | + '%f',//PRC_amount |
|
166 | + '%s',//PRC_name |
|
167 | + '%s',//PRC_desc |
|
168 | + '%d',//PRC_is_default |
|
169 | + '%d',//PRC_overrides |
|
170 | + '%d',//PRC_deleted |
|
171 | + '%d',//PRC_order |
|
172 | + '%d',//PRC_parent |
|
173 | + '%d' //PRC_wp_user |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * caffeinated_modules_to_register |
|
185 | + * |
|
186 | + * @access public |
|
187 | + * @param array $modules_to_register |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
191 | + { |
|
192 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
193 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
194 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
195 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
196 | + } |
|
197 | + } |
|
198 | + return $modules_to_register; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + public function caffeinated_init() |
|
204 | + { |
|
205 | + // EE_Register_CPTs hooks |
|
206 | + add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
207 | + add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
208 | + add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
209 | + EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
210 | + // caffeinated_init__complete hook |
|
211 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + public function enqueue_caffeinated_scripts() |
|
217 | + { |
|
218 | + // sound of crickets... |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * callbacks below here |
|
225 | + * |
|
226 | + * @param array $taxonomy_array |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function filter_taxonomies(array $taxonomy_array) |
|
230 | + { |
|
231 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
232 | + return $taxonomy_array; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param array $cpt_array |
|
239 | + * @return mixed |
|
240 | + */ |
|
241 | + public function filter_cpts(array $cpt_array) |
|
242 | + { |
|
243 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
244 | + return $cpt_array; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param array $menuitems |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + public function nav_metabox_items(array $menuitems) |
|
254 | + { |
|
255 | + $menuitems[] = array( |
|
256 | + 'title' => __('Venue List', 'event_espresso'), |
|
257 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
258 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
259 | + ); |
|
260 | + return $menuitems; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
267 | + * |
|
268 | + * @param array $payment_method_paths |
|
269 | + * @return array values are folder paths to payment method folders |
|
270 | + */ |
|
271 | + public function caf_payment_methods($payment_method_paths) |
|
272 | + { |
|
273 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
274 | + $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
275 | + return $payment_method_paths; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Gets the injected table analyzer, or throws an exception |
|
282 | + * |
|
283 | + * @return TableAnalysis |
|
284 | + * @throws \EE_Error |
|
285 | + */ |
|
286 | + protected function _get_table_analysis() |
|
287 | + { |
|
288 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
289 | + return $this->_table_analysis; |
|
290 | + } else { |
|
291 | + throw new \EE_Error( |
|
292 | + sprintf( |
|
293 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
294 | + get_class($this) |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | |
302 | 302 | |
303 | 303 | $brewing = new EE_Brewing_Regular( |
304 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
304 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
305 | 305 | ); |
306 | 306 | \ No newline at end of file |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $update_txn = true, |
88 | 88 | $cancel_url = '' |
89 | 89 | ) { |
90 | - if ((float)$amount < 0) { |
|
90 | + if ((float) $amount < 0) { |
|
91 | 91 | throw new EE_Error( |
92 | 92 | sprintf( |
93 | 93 | __( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
109 | 109 | $payment = $payment_method->type_obj()->process_payment( |
110 | 110 | $transaction, |
111 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
111 | + min($amount, $transaction->remaining()), //make sure we don't overcharge |
|
112 | 112 | $billing_form, |
113 | 113 | $return_url, |
114 | 114 | add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $separate_IPN_request = true |
196 | 196 | ) { |
197 | 197 | EE_Registry::instance()->load_model('Change_Log'); |
198 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
198 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
199 | 199 | EE_Processor_Base::set_IPN($separate_IPN_request); |
200 | 200 | $obj_for_log = null; |
201 | 201 | if ($transaction instanceof EE_Transaction) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | EEM_Change_Log::instance()->log( |
235 | 235 | EEM_Change_Log::type_gateway, |
236 | 236 | array( |
237 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
237 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
238 | 238 | 'current_url' => EEH_URL::current_url(), |
239 | 239 | 'payment' => $e->getPaymentProperties(), |
240 | 240 | 'IPN_data' => $e->getIpnData(), |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | EEM_Change_Log::instance()->log( |
272 | 272 | EEM_Change_Log::type_gateway, |
273 | 273 | array( |
274 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
274 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
275 | 275 | 'current_url' => EEH_URL::current_url(), |
276 | 276 | 'payment' => $e->getPaymentProperties(), |
277 | 277 | 'IPN_data' => $e->getIpnData(), |
@@ -633,15 +633,15 @@ discard block |
||
633 | 633 | //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
634 | 634 | if ($registration->paid() > 0) { |
635 | 635 | // ensure $available_refund_amount is NOT negative |
636 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
636 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
637 | 637 | // don't allow refund amount to exceed the available payment amount, OR the amount paid |
638 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
638 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
639 | 639 | // update $available_payment_amount |
640 | 640 | $available_refund_amount -= $refund_amount; |
641 | 641 | //calculate and set new REG_paid |
642 | 642 | $registration->set_paid($registration->paid() - $refund_amount); |
643 | 643 | // convert payment amount back to a negative value for storage in the db |
644 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
644 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
645 | 645 | // now save it |
646 | 646 | $this->_apply_registration_payment($registration, $payment, $refund_amount); |
647 | 647 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | EE_Registry::instance()->load_class('Processor_Base'); |
7 | 7 | |
@@ -18,748 +18,748 @@ discard block |
||
18 | 18 | class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Payment_Processor $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance; |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @singleton method used to instantiate class object |
|
31 | - * @access public |
|
32 | - * @return EE_Payment_Processor instance |
|
33 | - */ |
|
34 | - public static function instance() |
|
35 | - { |
|
36 | - // check if class object is instantiated |
|
37 | - if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
38 | - self::$_instance = new self(); |
|
39 | - } |
|
40 | - return self::$_instance; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return EE_Payment_Processor |
|
47 | - */ |
|
48 | - public static function reset() |
|
49 | - { |
|
50 | - self::$_instance = null; |
|
51 | - return self::instance(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - *private constructor to prevent direct creation |
|
58 | - * |
|
59 | - * @Constructor |
|
60 | - * @access private |
|
61 | - */ |
|
62 | - private function __construct() |
|
63 | - { |
|
64 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
65 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
72 | - * appropriately. Saves the payment that is generated |
|
73 | - * |
|
74 | - * @param EE_Payment_Method $payment_method |
|
75 | - * @param EE_Transaction $transaction |
|
76 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
77 | - * Leave null if payment is for the full amount owing |
|
78 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
79 | - * Receive_form_submission() should have |
|
80 | - * already been called on the billing form |
|
81 | - * (ie, its inputs should have their normalized values set). |
|
82 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
83 | - * where to go AFTER the offsite gateway |
|
84 | - * @param string $method like 'CART', indicates who the client who called this was |
|
85 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
86 | - * @param boolean $update_txn whether or not to call |
|
87 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
88 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
89 | - * @return \EE_Payment |
|
90 | - * @throws \EE_Error |
|
91 | - */ |
|
92 | - public function process_payment( |
|
93 | - EE_Payment_Method $payment_method, |
|
94 | - EE_Transaction $transaction, |
|
95 | - $amount = null, |
|
96 | - $billing_form = null, |
|
97 | - $return_url = null, |
|
98 | - $method = 'CART', |
|
99 | - $by_admin = false, |
|
100 | - $update_txn = true, |
|
101 | - $cancel_url = '' |
|
102 | - ) { |
|
103 | - if ((float)$amount < 0) { |
|
104 | - throw new EE_Error( |
|
105 | - sprintf( |
|
106 | - __( |
|
107 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
108 | - 'event_espresso' |
|
109 | - ), |
|
110 | - $amount, |
|
111 | - $transaction->ID() |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - // verify payment method |
|
116 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
117 | - // verify transaction |
|
118 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
119 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
120 | - // verify payment method type |
|
121 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
122 | - $payment = $payment_method->type_obj()->process_payment( |
|
123 | - $transaction, |
|
124 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
125 | - $billing_form, |
|
126 | - $return_url, |
|
127 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
128 | - $method, |
|
129 | - $by_admin |
|
130 | - ); |
|
131 | - // check if payment method uses an off-site gateway |
|
132 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
133 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
134 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
135 | - } |
|
136 | - return $payment; |
|
137 | - } else { |
|
138 | - EE_Error::add_error( |
|
139 | - sprintf( |
|
140 | - __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
141 | - '<br/>', |
|
142 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
143 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
144 | - ); |
|
145 | - return null; |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param EE_Transaction|int $transaction |
|
153 | - * @param EE_Payment_Method $payment_method |
|
154 | - * @throws EE_Error |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
158 | - { |
|
159 | - /** @type \EE_Transaction $transaction */ |
|
160 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
161 | - $primary_reg = $transaction->primary_registration(); |
|
162 | - if ( ! $primary_reg instanceof EE_Registration) { |
|
163 | - throw new EE_Error( |
|
164 | - sprintf( |
|
165 | - __( |
|
166 | - "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
167 | - "event_espresso" |
|
168 | - ), |
|
169 | - $transaction->ID() |
|
170 | - ) |
|
171 | - ); |
|
172 | - } |
|
173 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
174 | - $url = add_query_arg( |
|
175 | - array( |
|
176 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
177 | - 'ee_payment_method' => $payment_method->slug(), |
|
178 | - ), |
|
179 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
180 | - ); |
|
181 | - return $url; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
188 | - * we can easily find what registration the IPN is for and what payment method. |
|
189 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
190 | - * If a payment is found for the IPN info, it is saved. |
|
191 | - * |
|
192 | - * @param array $_req_data eg $_REQUEST |
|
193 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
194 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
195 | - * @param boolean $update_txn whether or not to call |
|
196 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
197 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
198 | - * or is processed manually ( false like Mijireh ) |
|
199 | - * @throws EE_Error |
|
200 | - * @throws Exception |
|
201 | - * @return EE_Payment |
|
202 | - */ |
|
203 | - public function process_ipn( |
|
204 | - $_req_data, |
|
205 | - $transaction = null, |
|
206 | - $payment_method = null, |
|
207 | - $update_txn = true, |
|
208 | - $separate_IPN_request = true |
|
209 | - ) { |
|
210 | - EE_Registry::instance()->load_model('Change_Log'); |
|
211 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
212 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
213 | - $obj_for_log = null; |
|
214 | - if ($transaction instanceof EE_Transaction) { |
|
215 | - $obj_for_log = $transaction; |
|
216 | - if ($payment_method instanceof EE_Payment_Method) { |
|
217 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
218 | - array( |
|
219 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
220 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
221 | - ) |
|
222 | - ); |
|
223 | - } |
|
224 | - } else if ($payment_method instanceof EE_Payment) { |
|
225 | - $obj_for_log = $payment_method; |
|
226 | - } |
|
227 | - $log = EEM_Change_Log::instance()->log( |
|
228 | - EEM_Change_Log::type_gateway, |
|
229 | - array('IPN data received' => $_req_data), |
|
230 | - $obj_for_log |
|
231 | - ); |
|
232 | - try { |
|
233 | - /** |
|
234 | - * @var EE_Payment $payment |
|
235 | - */ |
|
236 | - $payment = null; |
|
237 | - if ($transaction && $payment_method) { |
|
238 | - /** @type EE_Transaction $transaction */ |
|
239 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
240 | - /** @type EE_Payment_Method $payment_method */ |
|
241 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
242 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
243 | - try { |
|
244 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
245 | - $log->set_object($payment); |
|
246 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
247 | - EEM_Change_Log::instance()->log( |
|
248 | - EEM_Change_Log::type_gateway, |
|
249 | - array( |
|
250 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
251 | - 'current_url' => EEH_URL::current_url(), |
|
252 | - 'payment' => $e->getPaymentProperties(), |
|
253 | - 'IPN_data' => $e->getIpnData(), |
|
254 | - ), |
|
255 | - $obj_for_log |
|
256 | - ); |
|
257 | - return $e->getPayment(); |
|
258 | - } |
|
259 | - } else { |
|
260 | - // not a payment |
|
261 | - EE_Error::add_error( |
|
262 | - sprintf( |
|
263 | - __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
264 | - '<br/>', |
|
265 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
266 | - ), |
|
267 | - __FILE__, __FUNCTION__, __LINE__ |
|
268 | - ); |
|
269 | - } |
|
270 | - } else { |
|
271 | - //that's actually pretty ok. The IPN just wasn't able |
|
272 | - //to identify which transaction or payment method this was for |
|
273 | - // give all active payment methods a chance to claim it |
|
274 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
275 | - foreach ($active_payment_methods as $active_payment_method) { |
|
276 | - try { |
|
277 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
278 | - $payment_method = $active_payment_method; |
|
279 | - EEM_Change_Log::instance()->log( |
|
280 | - EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
281 | - ); |
|
282 | - break; |
|
283 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
284 | - EEM_Change_Log::instance()->log( |
|
285 | - EEM_Change_Log::type_gateway, |
|
286 | - array( |
|
287 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
288 | - 'current_url' => EEH_URL::current_url(), |
|
289 | - 'payment' => $e->getPaymentProperties(), |
|
290 | - 'IPN_data' => $e->getIpnData(), |
|
291 | - ), |
|
292 | - $obj_for_log |
|
293 | - ); |
|
294 | - return $e->getPayment(); |
|
295 | - } catch (EE_Error $e) { |
|
296 | - //that's fine- it apparently couldn't handle the IPN |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
301 | - if ($payment instanceof EE_Payment) { |
|
302 | - $payment->save(); |
|
303 | - // update the TXN |
|
304 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
305 | - } else { |
|
306 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
307 | - if ($payment_method) { |
|
308 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
309 | - } elseif ($transaction) { |
|
310 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
311 | - } |
|
312 | - } |
|
313 | - return $payment; |
|
314 | - } catch (EE_Error $e) { |
|
315 | - do_action( |
|
316 | - 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
317 | - __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
318 | - print_r($transaction, true), |
|
319 | - print_r($_req_data, true), |
|
320 | - $e->getMessage() |
|
321 | - ) |
|
322 | - ); |
|
323 | - throw $e; |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Removes any non-printable illegal characters from the input, |
|
331 | - * which might cause a raucous when trying to insert into the database |
|
332 | - * |
|
333 | - * @param array $request_data |
|
334 | - * @return array |
|
335 | - */ |
|
336 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
337 | - { |
|
338 | - $return_data = array(); |
|
339 | - foreach ($request_data as $key => $value) { |
|
340 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
341 | - } |
|
342 | - return $return_data; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Removes any non-printable illegal characters from the input, |
|
349 | - * which might cause a raucous when trying to insert into the database |
|
350 | - * |
|
351 | - * @param string $request_data |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - protected function _remove_unusable_characters($request_data) |
|
355 | - { |
|
356 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Should be called just before displaying the payment attempt results to the user, |
|
363 | - * when the payment attempt has finished. Some payment methods may have special |
|
364 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
365 | - * and then the user is redirected to a page that displays the payment's status, this |
|
366 | - * should be called while loading the page that displays the payment's status. If the user is |
|
367 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
368 | - * provider. |
|
369 | - * |
|
370 | - * @param EE_Transaction|int $transaction |
|
371 | - * @param bool $update_txn whether or not to call |
|
372 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
373 | - * @throws \EE_Error |
|
374 | - * @return EE_Payment |
|
375 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
376 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
377 | - */ |
|
378 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
379 | - { |
|
380 | - /** @var $transaction EE_Transaction */ |
|
381 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
382 | - $last_payment_method = $transaction->payment_method(); |
|
383 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
384 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
385 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
386 | - return $payment; |
|
387 | - } else { |
|
388 | - return null; |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
396 | - * |
|
397 | - * @param EE_Payment_Method $payment_method |
|
398 | - * @param EE_Payment $payment_to_refund |
|
399 | - * @param array $refund_info |
|
400 | - * @return EE_Payment |
|
401 | - * @throws \EE_Error |
|
402 | - */ |
|
403 | - public function process_refund( |
|
404 | - EE_Payment_Method $payment_method, |
|
405 | - EE_Payment $payment_to_refund, |
|
406 | - $refund_info = array() |
|
407 | - ) { |
|
408 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
409 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
410 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
411 | - } |
|
412 | - return $payment_to_refund; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * This should be called each time there may have been an update to a |
|
419 | - * payment on a transaction (ie, we asked for a payment to process a |
|
420 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
421 | - * we told a payment method to |
|
422 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
423 | - * process a refund. This should handle firing the correct hooks to |
|
424 | - * indicate |
|
425 | - * what exactly happened and updating the transaction appropriately). This |
|
426 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
427 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
428 | - * of transactions and payments, and to be tied to payment processing. |
|
429 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
430 | - * of previous code to decide whether or not to save (because the payment passed into |
|
431 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
432 | - * in which case we only want that payment object for some temporary usage during this request, |
|
433 | - * but we don't want it to be saved). |
|
434 | - * |
|
435 | - * @param EE_Transaction|int $transaction |
|
436 | - * @param EE_Payment $payment |
|
437 | - * @param boolean $update_txn |
|
438 | - * whether or not to call |
|
439 | - * EE_Transaction_Processor:: |
|
440 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
441 | - * (you can save 1 DB query if you know you're going |
|
442 | - * to save it later instead) |
|
443 | - * @param bool $IPN |
|
444 | - * if processing IPNs or other similar payment |
|
445 | - * related activities that occur in alternate |
|
446 | - * requests than the main one that is processing the |
|
447 | - * TXN, then set this to true to check whether the |
|
448 | - * TXN is locked before updating |
|
449 | - * @throws \EE_Error |
|
450 | - */ |
|
451 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
452 | - { |
|
453 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
454 | - /** @type EE_Transaction $transaction */ |
|
455 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
456 | - // can we freely update the TXN at this moment? |
|
457 | - if ($IPN && $transaction->is_locked()) { |
|
458 | - // don't update the transaction at this exact moment |
|
459 | - // because the TXN is active in another request |
|
460 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
461 | - time(), |
|
462 | - $transaction->ID(), |
|
463 | - $payment->ID() |
|
464 | - ); |
|
465 | - } else { |
|
466 | - // verify payment and that it has been saved |
|
467 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
468 | - if ( |
|
469 | - $payment->payment_method() instanceof EE_Payment_Method |
|
470 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
471 | - ) { |
|
472 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
473 | - // update TXN registrations with payment info |
|
474 | - $this->process_registration_payments($transaction, $payment); |
|
475 | - } |
|
476 | - $do_action = $payment->just_approved() |
|
477 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
478 | - : $do_action; |
|
479 | - } else { |
|
480 | - // send out notifications |
|
481 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
482 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
483 | - } |
|
484 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
485 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
486 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
487 | - // set new value for total paid |
|
488 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
489 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
490 | - if ($update_txn) { |
|
491 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
492 | - } |
|
493 | - } |
|
494 | - // granular hook for others to use. |
|
495 | - do_action($do_action, $transaction, $payment); |
|
496 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
497 | - //global hook for others to use. |
|
498 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
506 | - * |
|
507 | - * @param EE_Transaction $transaction |
|
508 | - * @param EE_Payment $payment |
|
509 | - * @param EE_Registration[] $registrations |
|
510 | - * @throws \EE_Error |
|
511 | - */ |
|
512 | - public function process_registration_payments( |
|
513 | - EE_Transaction $transaction, |
|
514 | - EE_Payment $payment, |
|
515 | - $registrations = array() |
|
516 | - ) { |
|
517 | - // only process if payment was successful |
|
518 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
519 | - return; |
|
520 | - } |
|
521 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
522 | - if (empty($registrations)) { |
|
523 | - // find registrations with monies owing that can receive a payment |
|
524 | - $registrations = $transaction->registrations( |
|
525 | - array( |
|
526 | - array( |
|
527 | - // only these reg statuses can receive payments |
|
528 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
529 | - 'REG_final_price' => array('!=', 0), |
|
530 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
531 | - ), |
|
532 | - ) |
|
533 | - ); |
|
534 | - } |
|
535 | - // still nothing ??!?? |
|
536 | - if (empty($registrations)) { |
|
537 | - return; |
|
538 | - } |
|
539 | - // todo: break out the following logic into a separate strategy class |
|
540 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
541 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
542 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
543 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
544 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
545 | - $refund = $payment->is_a_refund(); |
|
546 | - // how much is available to apply to registrations? |
|
547 | - $available_payment_amount = abs($payment->amount()); |
|
548 | - foreach ($registrations as $registration) { |
|
549 | - if ($registration instanceof EE_Registration) { |
|
550 | - // nothing left? |
|
551 | - if ($available_payment_amount <= 0) { |
|
552 | - break; |
|
553 | - } |
|
554 | - if ($refund) { |
|
555 | - $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
556 | - } else { |
|
557 | - $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
562 | - EE_Error::add_attention( |
|
563 | - sprintf( |
|
564 | - __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
565 | - 'event_espresso'), |
|
566 | - EEH_Template::format_currency($available_payment_amount), |
|
567 | - implode(', ', array_keys($registrations)), |
|
568 | - '<br/>', |
|
569 | - EEH_Template::format_currency($payment->amount()) |
|
570 | - ), |
|
571 | - __FILE__, __FUNCTION__, __LINE__ |
|
572 | - ); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * update registration REG_paid field after successful payment and link registration with payment |
|
580 | - * |
|
581 | - * @param EE_Registration $registration |
|
582 | - * @param EE_Payment $payment |
|
583 | - * @param float $available_payment_amount |
|
584 | - * @return float |
|
585 | - * @throws \EE_Error |
|
586 | - */ |
|
587 | - public function process_registration_payment( |
|
588 | - EE_Registration $registration, |
|
589 | - EE_Payment $payment, |
|
590 | - $available_payment_amount = 0.00 |
|
591 | - ) { |
|
592 | - $owing = $registration->final_price() - $registration->paid(); |
|
593 | - if ($owing > 0) { |
|
594 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
595 | - $payment_amount = min($available_payment_amount, $owing); |
|
596 | - // update $available_payment_amount |
|
597 | - $available_payment_amount -= $payment_amount; |
|
598 | - //calculate and set new REG_paid |
|
599 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
600 | - // now save it |
|
601 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
602 | - } |
|
603 | - return $available_payment_amount; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * update registration REG_paid field after successful payment and link registration with payment |
|
610 | - * |
|
611 | - * @param EE_Registration $registration |
|
612 | - * @param EE_Payment $payment |
|
613 | - * @param float $payment_amount |
|
614 | - * @return void |
|
615 | - * @throws \EE_Error |
|
616 | - */ |
|
617 | - protected function _apply_registration_payment( |
|
618 | - EE_Registration $registration, |
|
619 | - EE_Payment $payment, |
|
620 | - $payment_amount = 0.00 |
|
621 | - ) { |
|
622 | - // find any existing reg payment records for this registration and payment |
|
623 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
624 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
625 | - ); |
|
626 | - // if existing registration payment exists |
|
627 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
628 | - // then update that record |
|
629 | - $existing_reg_payment->set_amount($payment_amount); |
|
630 | - $existing_reg_payment->save(); |
|
631 | - } else { |
|
632 | - // or add new relation between registration and payment and set amount |
|
633 | - $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
634 | - // make it stick |
|
635 | - $registration->save(); |
|
636 | - } |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * update registration REG_paid field after refund and link registration with payment |
|
643 | - * |
|
644 | - * @param EE_Registration $registration |
|
645 | - * @param EE_Payment $payment |
|
646 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
647 | - * @return float |
|
648 | - * @throws \EE_Error |
|
649 | - */ |
|
650 | - public function process_registration_refund( |
|
651 | - EE_Registration $registration, |
|
652 | - EE_Payment $payment, |
|
653 | - $available_refund_amount = 0.00 |
|
654 | - ) { |
|
655 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
656 | - if ($registration->paid() > 0) { |
|
657 | - // ensure $available_refund_amount is NOT negative |
|
658 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
659 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
660 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
661 | - // update $available_payment_amount |
|
662 | - $available_refund_amount -= $refund_amount; |
|
663 | - //calculate and set new REG_paid |
|
664 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
665 | - // convert payment amount back to a negative value for storage in the db |
|
666 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
667 | - // now save it |
|
668 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
669 | - } |
|
670 | - return $available_refund_amount; |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * Process payments and transaction after payment process completed. |
|
677 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
678 | - * if this request happens to be processing an IPN, |
|
679 | - * then we will also set the Payment Options Reg Step to completed, |
|
680 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
681 | - * |
|
682 | - * @param EE_Transaction $transaction |
|
683 | - * @param EE_Payment $payment |
|
684 | - * @param bool $IPN |
|
685 | - * @throws \EE_Error |
|
686 | - */ |
|
687 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
688 | - { |
|
689 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
690 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
691 | - // is the Payment Options Reg Step completed ? |
|
692 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
693 | - // if the Payment Options Reg Step is completed... |
|
694 | - $revisit = $payment_options_step_completed === true ? true : false; |
|
695 | - // then this is kinda sorta a revisit with regards to payments at least |
|
696 | - $transaction_processor->set_revisit($revisit); |
|
697 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
698 | - if ( |
|
699 | - $IPN |
|
700 | - && $payment_options_step_completed !== true |
|
701 | - && ($payment->is_approved() || $payment->is_pending()) |
|
702 | - ) { |
|
703 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
704 | - 'payment_options' |
|
705 | - ); |
|
706 | - } |
|
707 | - // maybe update status, but don't save transaction just yet |
|
708 | - $transaction->update_status_based_on_total_paid(false); |
|
709 | - // check if 'finalize_registration' step has been completed... |
|
710 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
711 | - // if this is an IPN and the final step has not been initiated |
|
712 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
713 | - // and if it hasn't already been set as being started... |
|
714 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
715 | - } |
|
716 | - $transaction->save(); |
|
717 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
718 | - if ($IPN && $finalized !== false) { |
|
719 | - // and if we are all good to go, then send out notifications |
|
720 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
721 | - //ok, now process the transaction according to the payment |
|
722 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
723 | - } |
|
724 | - // DEBUG LOG |
|
725 | - $payment_method = $payment->payment_method(); |
|
726 | - if ($payment_method instanceof EE_Payment_Method) { |
|
727 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
728 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
729 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
730 | - if ($gateway instanceof EE_Gateway) { |
|
731 | - $gateway->log( |
|
732 | - array( |
|
733 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
734 | - 'transaction' => $transaction->model_field_array(), |
|
735 | - 'finalized' => $finalized, |
|
736 | - 'IPN' => $IPN, |
|
737 | - 'deliver_notifications' => has_filter( |
|
738 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
739 | - ), |
|
740 | - ), |
|
741 | - $payment |
|
742 | - ); |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Force posts to PayPal to use TLS v1.2. See: |
|
752 | - * https://core.trac.wordpress.org/ticket/36320 |
|
753 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
754 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
755 | - * This will affect paypal standard, pro, express, and payflow. |
|
756 | - */ |
|
757 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
758 | - { |
|
759 | - if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
760 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
761 | - //instead of the constant because it might not be defined |
|
762 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
763 | - } |
|
764 | - } |
|
21 | + /** |
|
22 | + * @var EE_Payment_Processor $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance; |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @singleton method used to instantiate class object |
|
31 | + * @access public |
|
32 | + * @return EE_Payment_Processor instance |
|
33 | + */ |
|
34 | + public static function instance() |
|
35 | + { |
|
36 | + // check if class object is instantiated |
|
37 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
38 | + self::$_instance = new self(); |
|
39 | + } |
|
40 | + return self::$_instance; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return EE_Payment_Processor |
|
47 | + */ |
|
48 | + public static function reset() |
|
49 | + { |
|
50 | + self::$_instance = null; |
|
51 | + return self::instance(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + *private constructor to prevent direct creation |
|
58 | + * |
|
59 | + * @Constructor |
|
60 | + * @access private |
|
61 | + */ |
|
62 | + private function __construct() |
|
63 | + { |
|
64 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
65 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
72 | + * appropriately. Saves the payment that is generated |
|
73 | + * |
|
74 | + * @param EE_Payment_Method $payment_method |
|
75 | + * @param EE_Transaction $transaction |
|
76 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
77 | + * Leave null if payment is for the full amount owing |
|
78 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
79 | + * Receive_form_submission() should have |
|
80 | + * already been called on the billing form |
|
81 | + * (ie, its inputs should have their normalized values set). |
|
82 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
83 | + * where to go AFTER the offsite gateway |
|
84 | + * @param string $method like 'CART', indicates who the client who called this was |
|
85 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
86 | + * @param boolean $update_txn whether or not to call |
|
87 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
88 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
89 | + * @return \EE_Payment |
|
90 | + * @throws \EE_Error |
|
91 | + */ |
|
92 | + public function process_payment( |
|
93 | + EE_Payment_Method $payment_method, |
|
94 | + EE_Transaction $transaction, |
|
95 | + $amount = null, |
|
96 | + $billing_form = null, |
|
97 | + $return_url = null, |
|
98 | + $method = 'CART', |
|
99 | + $by_admin = false, |
|
100 | + $update_txn = true, |
|
101 | + $cancel_url = '' |
|
102 | + ) { |
|
103 | + if ((float)$amount < 0) { |
|
104 | + throw new EE_Error( |
|
105 | + sprintf( |
|
106 | + __( |
|
107 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
108 | + 'event_espresso' |
|
109 | + ), |
|
110 | + $amount, |
|
111 | + $transaction->ID() |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + // verify payment method |
|
116 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
117 | + // verify transaction |
|
118 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
119 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
120 | + // verify payment method type |
|
121 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
122 | + $payment = $payment_method->type_obj()->process_payment( |
|
123 | + $transaction, |
|
124 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
125 | + $billing_form, |
|
126 | + $return_url, |
|
127 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
128 | + $method, |
|
129 | + $by_admin |
|
130 | + ); |
|
131 | + // check if payment method uses an off-site gateway |
|
132 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
133 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
134 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
135 | + } |
|
136 | + return $payment; |
|
137 | + } else { |
|
138 | + EE_Error::add_error( |
|
139 | + sprintf( |
|
140 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
141 | + '<br/>', |
|
142 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
143 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
144 | + ); |
|
145 | + return null; |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param EE_Transaction|int $transaction |
|
153 | + * @param EE_Payment_Method $payment_method |
|
154 | + * @throws EE_Error |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
158 | + { |
|
159 | + /** @type \EE_Transaction $transaction */ |
|
160 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
161 | + $primary_reg = $transaction->primary_registration(); |
|
162 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
163 | + throw new EE_Error( |
|
164 | + sprintf( |
|
165 | + __( |
|
166 | + "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
167 | + "event_espresso" |
|
168 | + ), |
|
169 | + $transaction->ID() |
|
170 | + ) |
|
171 | + ); |
|
172 | + } |
|
173 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
174 | + $url = add_query_arg( |
|
175 | + array( |
|
176 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
177 | + 'ee_payment_method' => $payment_method->slug(), |
|
178 | + ), |
|
179 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
180 | + ); |
|
181 | + return $url; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
188 | + * we can easily find what registration the IPN is for and what payment method. |
|
189 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
190 | + * If a payment is found for the IPN info, it is saved. |
|
191 | + * |
|
192 | + * @param array $_req_data eg $_REQUEST |
|
193 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
194 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
195 | + * @param boolean $update_txn whether or not to call |
|
196 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
197 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
198 | + * or is processed manually ( false like Mijireh ) |
|
199 | + * @throws EE_Error |
|
200 | + * @throws Exception |
|
201 | + * @return EE_Payment |
|
202 | + */ |
|
203 | + public function process_ipn( |
|
204 | + $_req_data, |
|
205 | + $transaction = null, |
|
206 | + $payment_method = null, |
|
207 | + $update_txn = true, |
|
208 | + $separate_IPN_request = true |
|
209 | + ) { |
|
210 | + EE_Registry::instance()->load_model('Change_Log'); |
|
211 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
212 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
213 | + $obj_for_log = null; |
|
214 | + if ($transaction instanceof EE_Transaction) { |
|
215 | + $obj_for_log = $transaction; |
|
216 | + if ($payment_method instanceof EE_Payment_Method) { |
|
217 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
218 | + array( |
|
219 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
220 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
221 | + ) |
|
222 | + ); |
|
223 | + } |
|
224 | + } else if ($payment_method instanceof EE_Payment) { |
|
225 | + $obj_for_log = $payment_method; |
|
226 | + } |
|
227 | + $log = EEM_Change_Log::instance()->log( |
|
228 | + EEM_Change_Log::type_gateway, |
|
229 | + array('IPN data received' => $_req_data), |
|
230 | + $obj_for_log |
|
231 | + ); |
|
232 | + try { |
|
233 | + /** |
|
234 | + * @var EE_Payment $payment |
|
235 | + */ |
|
236 | + $payment = null; |
|
237 | + if ($transaction && $payment_method) { |
|
238 | + /** @type EE_Transaction $transaction */ |
|
239 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
240 | + /** @type EE_Payment_Method $payment_method */ |
|
241 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
242 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
243 | + try { |
|
244 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
245 | + $log->set_object($payment); |
|
246 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
247 | + EEM_Change_Log::instance()->log( |
|
248 | + EEM_Change_Log::type_gateway, |
|
249 | + array( |
|
250 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
251 | + 'current_url' => EEH_URL::current_url(), |
|
252 | + 'payment' => $e->getPaymentProperties(), |
|
253 | + 'IPN_data' => $e->getIpnData(), |
|
254 | + ), |
|
255 | + $obj_for_log |
|
256 | + ); |
|
257 | + return $e->getPayment(); |
|
258 | + } |
|
259 | + } else { |
|
260 | + // not a payment |
|
261 | + EE_Error::add_error( |
|
262 | + sprintf( |
|
263 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
264 | + '<br/>', |
|
265 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
266 | + ), |
|
267 | + __FILE__, __FUNCTION__, __LINE__ |
|
268 | + ); |
|
269 | + } |
|
270 | + } else { |
|
271 | + //that's actually pretty ok. The IPN just wasn't able |
|
272 | + //to identify which transaction or payment method this was for |
|
273 | + // give all active payment methods a chance to claim it |
|
274 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
275 | + foreach ($active_payment_methods as $active_payment_method) { |
|
276 | + try { |
|
277 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
278 | + $payment_method = $active_payment_method; |
|
279 | + EEM_Change_Log::instance()->log( |
|
280 | + EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
281 | + ); |
|
282 | + break; |
|
283 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
284 | + EEM_Change_Log::instance()->log( |
|
285 | + EEM_Change_Log::type_gateway, |
|
286 | + array( |
|
287 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
288 | + 'current_url' => EEH_URL::current_url(), |
|
289 | + 'payment' => $e->getPaymentProperties(), |
|
290 | + 'IPN_data' => $e->getIpnData(), |
|
291 | + ), |
|
292 | + $obj_for_log |
|
293 | + ); |
|
294 | + return $e->getPayment(); |
|
295 | + } catch (EE_Error $e) { |
|
296 | + //that's fine- it apparently couldn't handle the IPN |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
301 | + if ($payment instanceof EE_Payment) { |
|
302 | + $payment->save(); |
|
303 | + // update the TXN |
|
304 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
305 | + } else { |
|
306 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
307 | + if ($payment_method) { |
|
308 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
309 | + } elseif ($transaction) { |
|
310 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
311 | + } |
|
312 | + } |
|
313 | + return $payment; |
|
314 | + } catch (EE_Error $e) { |
|
315 | + do_action( |
|
316 | + 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
317 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
318 | + print_r($transaction, true), |
|
319 | + print_r($_req_data, true), |
|
320 | + $e->getMessage() |
|
321 | + ) |
|
322 | + ); |
|
323 | + throw $e; |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Removes any non-printable illegal characters from the input, |
|
331 | + * which might cause a raucous when trying to insert into the database |
|
332 | + * |
|
333 | + * @param array $request_data |
|
334 | + * @return array |
|
335 | + */ |
|
336 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
337 | + { |
|
338 | + $return_data = array(); |
|
339 | + foreach ($request_data as $key => $value) { |
|
340 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
341 | + } |
|
342 | + return $return_data; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Removes any non-printable illegal characters from the input, |
|
349 | + * which might cause a raucous when trying to insert into the database |
|
350 | + * |
|
351 | + * @param string $request_data |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + protected function _remove_unusable_characters($request_data) |
|
355 | + { |
|
356 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Should be called just before displaying the payment attempt results to the user, |
|
363 | + * when the payment attempt has finished. Some payment methods may have special |
|
364 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
365 | + * and then the user is redirected to a page that displays the payment's status, this |
|
366 | + * should be called while loading the page that displays the payment's status. If the user is |
|
367 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
368 | + * provider. |
|
369 | + * |
|
370 | + * @param EE_Transaction|int $transaction |
|
371 | + * @param bool $update_txn whether or not to call |
|
372 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
373 | + * @throws \EE_Error |
|
374 | + * @return EE_Payment |
|
375 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
376 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
377 | + */ |
|
378 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
379 | + { |
|
380 | + /** @var $transaction EE_Transaction */ |
|
381 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
382 | + $last_payment_method = $transaction->payment_method(); |
|
383 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
384 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
385 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
386 | + return $payment; |
|
387 | + } else { |
|
388 | + return null; |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
396 | + * |
|
397 | + * @param EE_Payment_Method $payment_method |
|
398 | + * @param EE_Payment $payment_to_refund |
|
399 | + * @param array $refund_info |
|
400 | + * @return EE_Payment |
|
401 | + * @throws \EE_Error |
|
402 | + */ |
|
403 | + public function process_refund( |
|
404 | + EE_Payment_Method $payment_method, |
|
405 | + EE_Payment $payment_to_refund, |
|
406 | + $refund_info = array() |
|
407 | + ) { |
|
408 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
409 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
410 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
411 | + } |
|
412 | + return $payment_to_refund; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * This should be called each time there may have been an update to a |
|
419 | + * payment on a transaction (ie, we asked for a payment to process a |
|
420 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
421 | + * we told a payment method to |
|
422 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
423 | + * process a refund. This should handle firing the correct hooks to |
|
424 | + * indicate |
|
425 | + * what exactly happened and updating the transaction appropriately). This |
|
426 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
427 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
428 | + * of transactions and payments, and to be tied to payment processing. |
|
429 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
430 | + * of previous code to decide whether or not to save (because the payment passed into |
|
431 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
432 | + * in which case we only want that payment object for some temporary usage during this request, |
|
433 | + * but we don't want it to be saved). |
|
434 | + * |
|
435 | + * @param EE_Transaction|int $transaction |
|
436 | + * @param EE_Payment $payment |
|
437 | + * @param boolean $update_txn |
|
438 | + * whether or not to call |
|
439 | + * EE_Transaction_Processor:: |
|
440 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
441 | + * (you can save 1 DB query if you know you're going |
|
442 | + * to save it later instead) |
|
443 | + * @param bool $IPN |
|
444 | + * if processing IPNs or other similar payment |
|
445 | + * related activities that occur in alternate |
|
446 | + * requests than the main one that is processing the |
|
447 | + * TXN, then set this to true to check whether the |
|
448 | + * TXN is locked before updating |
|
449 | + * @throws \EE_Error |
|
450 | + */ |
|
451 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
452 | + { |
|
453 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
454 | + /** @type EE_Transaction $transaction */ |
|
455 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
456 | + // can we freely update the TXN at this moment? |
|
457 | + if ($IPN && $transaction->is_locked()) { |
|
458 | + // don't update the transaction at this exact moment |
|
459 | + // because the TXN is active in another request |
|
460 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
461 | + time(), |
|
462 | + $transaction->ID(), |
|
463 | + $payment->ID() |
|
464 | + ); |
|
465 | + } else { |
|
466 | + // verify payment and that it has been saved |
|
467 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
468 | + if ( |
|
469 | + $payment->payment_method() instanceof EE_Payment_Method |
|
470 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
471 | + ) { |
|
472 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
473 | + // update TXN registrations with payment info |
|
474 | + $this->process_registration_payments($transaction, $payment); |
|
475 | + } |
|
476 | + $do_action = $payment->just_approved() |
|
477 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
478 | + : $do_action; |
|
479 | + } else { |
|
480 | + // send out notifications |
|
481 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
482 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
483 | + } |
|
484 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
485 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
486 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
487 | + // set new value for total paid |
|
488 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
489 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
490 | + if ($update_txn) { |
|
491 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
492 | + } |
|
493 | + } |
|
494 | + // granular hook for others to use. |
|
495 | + do_action($do_action, $transaction, $payment); |
|
496 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
497 | + //global hook for others to use. |
|
498 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
506 | + * |
|
507 | + * @param EE_Transaction $transaction |
|
508 | + * @param EE_Payment $payment |
|
509 | + * @param EE_Registration[] $registrations |
|
510 | + * @throws \EE_Error |
|
511 | + */ |
|
512 | + public function process_registration_payments( |
|
513 | + EE_Transaction $transaction, |
|
514 | + EE_Payment $payment, |
|
515 | + $registrations = array() |
|
516 | + ) { |
|
517 | + // only process if payment was successful |
|
518 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
519 | + return; |
|
520 | + } |
|
521 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
522 | + if (empty($registrations)) { |
|
523 | + // find registrations with monies owing that can receive a payment |
|
524 | + $registrations = $transaction->registrations( |
|
525 | + array( |
|
526 | + array( |
|
527 | + // only these reg statuses can receive payments |
|
528 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
529 | + 'REG_final_price' => array('!=', 0), |
|
530 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
531 | + ), |
|
532 | + ) |
|
533 | + ); |
|
534 | + } |
|
535 | + // still nothing ??!?? |
|
536 | + if (empty($registrations)) { |
|
537 | + return; |
|
538 | + } |
|
539 | + // todo: break out the following logic into a separate strategy class |
|
540 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
541 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
542 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
543 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
544 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
545 | + $refund = $payment->is_a_refund(); |
|
546 | + // how much is available to apply to registrations? |
|
547 | + $available_payment_amount = abs($payment->amount()); |
|
548 | + foreach ($registrations as $registration) { |
|
549 | + if ($registration instanceof EE_Registration) { |
|
550 | + // nothing left? |
|
551 | + if ($available_payment_amount <= 0) { |
|
552 | + break; |
|
553 | + } |
|
554 | + if ($refund) { |
|
555 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
556 | + } else { |
|
557 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
562 | + EE_Error::add_attention( |
|
563 | + sprintf( |
|
564 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
565 | + 'event_espresso'), |
|
566 | + EEH_Template::format_currency($available_payment_amount), |
|
567 | + implode(', ', array_keys($registrations)), |
|
568 | + '<br/>', |
|
569 | + EEH_Template::format_currency($payment->amount()) |
|
570 | + ), |
|
571 | + __FILE__, __FUNCTION__, __LINE__ |
|
572 | + ); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * update registration REG_paid field after successful payment and link registration with payment |
|
580 | + * |
|
581 | + * @param EE_Registration $registration |
|
582 | + * @param EE_Payment $payment |
|
583 | + * @param float $available_payment_amount |
|
584 | + * @return float |
|
585 | + * @throws \EE_Error |
|
586 | + */ |
|
587 | + public function process_registration_payment( |
|
588 | + EE_Registration $registration, |
|
589 | + EE_Payment $payment, |
|
590 | + $available_payment_amount = 0.00 |
|
591 | + ) { |
|
592 | + $owing = $registration->final_price() - $registration->paid(); |
|
593 | + if ($owing > 0) { |
|
594 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
595 | + $payment_amount = min($available_payment_amount, $owing); |
|
596 | + // update $available_payment_amount |
|
597 | + $available_payment_amount -= $payment_amount; |
|
598 | + //calculate and set new REG_paid |
|
599 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
600 | + // now save it |
|
601 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
602 | + } |
|
603 | + return $available_payment_amount; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * update registration REG_paid field after successful payment and link registration with payment |
|
610 | + * |
|
611 | + * @param EE_Registration $registration |
|
612 | + * @param EE_Payment $payment |
|
613 | + * @param float $payment_amount |
|
614 | + * @return void |
|
615 | + * @throws \EE_Error |
|
616 | + */ |
|
617 | + protected function _apply_registration_payment( |
|
618 | + EE_Registration $registration, |
|
619 | + EE_Payment $payment, |
|
620 | + $payment_amount = 0.00 |
|
621 | + ) { |
|
622 | + // find any existing reg payment records for this registration and payment |
|
623 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
624 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
625 | + ); |
|
626 | + // if existing registration payment exists |
|
627 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
628 | + // then update that record |
|
629 | + $existing_reg_payment->set_amount($payment_amount); |
|
630 | + $existing_reg_payment->save(); |
|
631 | + } else { |
|
632 | + // or add new relation between registration and payment and set amount |
|
633 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
634 | + // make it stick |
|
635 | + $registration->save(); |
|
636 | + } |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * update registration REG_paid field after refund and link registration with payment |
|
643 | + * |
|
644 | + * @param EE_Registration $registration |
|
645 | + * @param EE_Payment $payment |
|
646 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
647 | + * @return float |
|
648 | + * @throws \EE_Error |
|
649 | + */ |
|
650 | + public function process_registration_refund( |
|
651 | + EE_Registration $registration, |
|
652 | + EE_Payment $payment, |
|
653 | + $available_refund_amount = 0.00 |
|
654 | + ) { |
|
655 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
656 | + if ($registration->paid() > 0) { |
|
657 | + // ensure $available_refund_amount is NOT negative |
|
658 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
659 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
660 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
661 | + // update $available_payment_amount |
|
662 | + $available_refund_amount -= $refund_amount; |
|
663 | + //calculate and set new REG_paid |
|
664 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
665 | + // convert payment amount back to a negative value for storage in the db |
|
666 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
667 | + // now save it |
|
668 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
669 | + } |
|
670 | + return $available_refund_amount; |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * Process payments and transaction after payment process completed. |
|
677 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
678 | + * if this request happens to be processing an IPN, |
|
679 | + * then we will also set the Payment Options Reg Step to completed, |
|
680 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
681 | + * |
|
682 | + * @param EE_Transaction $transaction |
|
683 | + * @param EE_Payment $payment |
|
684 | + * @param bool $IPN |
|
685 | + * @throws \EE_Error |
|
686 | + */ |
|
687 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
688 | + { |
|
689 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
690 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
691 | + // is the Payment Options Reg Step completed ? |
|
692 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
693 | + // if the Payment Options Reg Step is completed... |
|
694 | + $revisit = $payment_options_step_completed === true ? true : false; |
|
695 | + // then this is kinda sorta a revisit with regards to payments at least |
|
696 | + $transaction_processor->set_revisit($revisit); |
|
697 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
698 | + if ( |
|
699 | + $IPN |
|
700 | + && $payment_options_step_completed !== true |
|
701 | + && ($payment->is_approved() || $payment->is_pending()) |
|
702 | + ) { |
|
703 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
704 | + 'payment_options' |
|
705 | + ); |
|
706 | + } |
|
707 | + // maybe update status, but don't save transaction just yet |
|
708 | + $transaction->update_status_based_on_total_paid(false); |
|
709 | + // check if 'finalize_registration' step has been completed... |
|
710 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
711 | + // if this is an IPN and the final step has not been initiated |
|
712 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
713 | + // and if it hasn't already been set as being started... |
|
714 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
715 | + } |
|
716 | + $transaction->save(); |
|
717 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
718 | + if ($IPN && $finalized !== false) { |
|
719 | + // and if we are all good to go, then send out notifications |
|
720 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
721 | + //ok, now process the transaction according to the payment |
|
722 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
723 | + } |
|
724 | + // DEBUG LOG |
|
725 | + $payment_method = $payment->payment_method(); |
|
726 | + if ($payment_method instanceof EE_Payment_Method) { |
|
727 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
728 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
729 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
730 | + if ($gateway instanceof EE_Gateway) { |
|
731 | + $gateway->log( |
|
732 | + array( |
|
733 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
734 | + 'transaction' => $transaction->model_field_array(), |
|
735 | + 'finalized' => $finalized, |
|
736 | + 'IPN' => $IPN, |
|
737 | + 'deliver_notifications' => has_filter( |
|
738 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
739 | + ), |
|
740 | + ), |
|
741 | + $payment |
|
742 | + ); |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Force posts to PayPal to use TLS v1.2. See: |
|
752 | + * https://core.trac.wordpress.org/ticket/36320 |
|
753 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
754 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
755 | + * This will affect paypal standard, pro, express, and payflow. |
|
756 | + */ |
|
757 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
758 | + { |
|
759 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
760 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
761 | + //instead of the constant because it might not be defined |
|
762 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
763 | + } |
|
764 | + } |
|
765 | 765 | } |
@@ -163,7 +163,7 @@ |
||
163 | 163 | private function _display_minimum_recommended_php_version_notice() |
164 | 164 | { |
165 | 165 | EE_Error::add_persistent_admin_notice( |
166 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
166 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
167 | 167 | sprintf( |
168 | 168 | __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
169 | 169 | 'event_espresso'), |
@@ -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 | |
@@ -18,150 +18,150 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * converts a Request to a Response |
|
23 | - * |
|
24 | - * @param EE_Request $request |
|
25 | - * @param EE_Response $response |
|
26 | - * @return EE_Response |
|
27 | - */ |
|
28 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
29 | - { |
|
30 | - $this->_request = $request; |
|
31 | - $this->_response = $response; |
|
32 | - //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
33 | - //$this->_response->set_notice( 1, 'hey look at this' ); |
|
34 | - // check required WP version |
|
35 | - if ( ! $this->_minimum_wp_version_required()) { |
|
36 | - $this->_request->un_set('activate', true); |
|
37 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
38 | - //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
39 | - $this->_response->terminate_request(); |
|
40 | - $this->_response->deactivate_plugin(); |
|
41 | - } |
|
42 | - // check recommended PHP version |
|
43 | - if ( ! $this->_minimum_php_version_recommended()) { |
|
44 | - $this->_display_minimum_recommended_php_version_notice(); |
|
45 | - } |
|
46 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
47 | - //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
48 | - return $this->_response; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Helper method to assess installed wp version against given values. |
|
54 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
55 | - * |
|
56 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
57 | - * so consider that when sending in your values. |
|
58 | - * |
|
59 | - * @param string $version_to_check |
|
60 | - * @param string $operator |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
64 | - { |
|
65 | - global $wp_version; |
|
66 | - return version_compare( |
|
67 | - //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
68 | - //4.7-RC3-39519 |
|
69 | - strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
70 | - $version_to_check, |
|
71 | - $operator |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * _minimum_wp_version_required |
|
79 | - * |
|
80 | - * @access private |
|
81 | - * @return boolean |
|
82 | - */ |
|
83 | - private function _minimum_wp_version_required() |
|
84 | - { |
|
85 | - return self::check_wp_version(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * _check_php_version |
|
92 | - * |
|
93 | - * @access private |
|
94 | - * @param string $min_version |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
98 | - { |
|
99 | - return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * _minimum_php_version_recommended |
|
106 | - * |
|
107 | - * @access private |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - private function _minimum_php_version_recommended() |
|
111 | - { |
|
112 | - return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * minimum_wp_version_error |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function minimum_wp_version_error() |
|
123 | - { |
|
124 | - global $wp_version; |
|
125 | - ?> |
|
21 | + /** |
|
22 | + * converts a Request to a Response |
|
23 | + * |
|
24 | + * @param EE_Request $request |
|
25 | + * @param EE_Response $response |
|
26 | + * @return EE_Response |
|
27 | + */ |
|
28 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
29 | + { |
|
30 | + $this->_request = $request; |
|
31 | + $this->_response = $response; |
|
32 | + //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
33 | + //$this->_response->set_notice( 1, 'hey look at this' ); |
|
34 | + // check required WP version |
|
35 | + if ( ! $this->_minimum_wp_version_required()) { |
|
36 | + $this->_request->un_set('activate', true); |
|
37 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
38 | + //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
39 | + $this->_response->terminate_request(); |
|
40 | + $this->_response->deactivate_plugin(); |
|
41 | + } |
|
42 | + // check recommended PHP version |
|
43 | + if ( ! $this->_minimum_php_version_recommended()) { |
|
44 | + $this->_display_minimum_recommended_php_version_notice(); |
|
45 | + } |
|
46 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
47 | + //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
48 | + return $this->_response; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Helper method to assess installed wp version against given values. |
|
54 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
55 | + * |
|
56 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked against) |
|
57 | + * so consider that when sending in your values. |
|
58 | + * |
|
59 | + * @param string $version_to_check |
|
60 | + * @param string $operator |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
64 | + { |
|
65 | + global $wp_version; |
|
66 | + return version_compare( |
|
67 | + //first account for wp_version being pre-release (like RC, beta etc which are usually in the format like |
|
68 | + //4.7-RC3-39519 |
|
69 | + strpos($wp_version, '-') > 0 ? substr($wp_version, 0, strpos($wp_version, '-')) : $wp_version, |
|
70 | + $version_to_check, |
|
71 | + $operator |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * _minimum_wp_version_required |
|
79 | + * |
|
80 | + * @access private |
|
81 | + * @return boolean |
|
82 | + */ |
|
83 | + private function _minimum_wp_version_required() |
|
84 | + { |
|
85 | + return self::check_wp_version(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * _check_php_version |
|
92 | + * |
|
93 | + * @access private |
|
94 | + * @param string $min_version |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
98 | + { |
|
99 | + return version_compare(PHP_VERSION, $min_version, '>=') ? true : false; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * _minimum_php_version_recommended |
|
106 | + * |
|
107 | + * @access private |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + private function _minimum_php_version_recommended() |
|
111 | + { |
|
112 | + return $this->_check_php_version(EE_MIN_PHP_VER_RECOMMENDED); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * minimum_wp_version_error |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function minimum_wp_version_error() |
|
123 | + { |
|
124 | + global $wp_version; |
|
125 | + ?> |
|
126 | 126 | <div class="error"> |
127 | 127 | <p> |
128 | 128 | <?php |
129 | - printf( |
|
130 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
131 | - 'event_espresso'), |
|
132 | - EE_MIN_WP_VER_REQUIRED, |
|
133 | - $wp_version, |
|
134 | - '<br/>', |
|
135 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
136 | - ); |
|
137 | - ?> |
|
129 | + printf( |
|
130 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
131 | + 'event_espresso'), |
|
132 | + EE_MIN_WP_VER_REQUIRED, |
|
133 | + $wp_version, |
|
134 | + '<br/>', |
|
135 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
136 | + ); |
|
137 | + ?> |
|
138 | 138 | </p> |
139 | 139 | </div> |
140 | 140 | <?php |
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * _display_minimum_recommended_php_version_notice |
|
147 | - * |
|
148 | - * @access private |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - private function _display_minimum_recommended_php_version_notice() |
|
152 | - { |
|
153 | - EE_Error::add_persistent_admin_notice( |
|
154 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
155 | - sprintf( |
|
156 | - __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
157 | - 'event_espresso'), |
|
158 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
159 | - PHP_VERSION, |
|
160 | - '<br/>', |
|
161 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * _display_minimum_recommended_php_version_notice |
|
147 | + * |
|
148 | + * @access private |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + private function _display_minimum_recommended_php_version_notice() |
|
152 | + { |
|
153 | + EE_Error::add_persistent_admin_notice( |
|
154 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
155 | + sprintf( |
|
156 | + __('Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
157 | + 'event_espresso'), |
|
158 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
159 | + PHP_VERSION, |
|
160 | + '<br/>', |
|
161 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | 167 | } |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <h2><?php esc_html_e('What is the Event Espresso Messages System?', 'event_espresso'); ?></h2> |
2 | -<p><?php printf( esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>' ); ?></p> |
|
2 | +<p><?php printf(esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
3 | 3 | <p><?php esc_html_e('We\'ve intentionally created this framework so that we have as much flexibility as possible for future ideas that we think of (or customers think of) for the kinds of messages that get sent out related to your events.', 'event_espresso'); ?></p> |
4 | 4 | \ No newline at end of file |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>'); ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>') ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>') ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |