@@ -18,842 +18,842 @@ |
||
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 | - * @singleton method used to instantiate class object |
|
30 | - * @access public |
|
31 | - * @return EE_Payment_Processor instance |
|
32 | - */ |
|
33 | - public static function instance() |
|
34 | - { |
|
35 | - // check if class object is instantiated |
|
36 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
37 | - self::$_instance = new self(); |
|
38 | - } |
|
39 | - return self::$_instance; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return EE_Payment_Processor |
|
45 | - */ |
|
46 | - public static function reset() |
|
47 | - { |
|
48 | - self::$_instance = null; |
|
49 | - return self::instance(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - *private constructor to prevent direct creation |
|
55 | - * |
|
56 | - * @Constructor |
|
57 | - * @access private |
|
58 | - */ |
|
59 | - private function __construct() |
|
60 | - { |
|
61 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
62 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
68 | - * appropriately. Saves the payment that is generated |
|
69 | - * |
|
70 | - * @param EE_Payment_Method $payment_method |
|
71 | - * @param EE_Transaction $transaction |
|
72 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
73 | - * Leave null if payment is for the full amount owing |
|
74 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
75 | - * Receive_form_submission() should have |
|
76 | - * already been called on the billing form |
|
77 | - * (ie, its inputs should have their normalized values set). |
|
78 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
79 | - * where to go AFTER the offsite gateway |
|
80 | - * @param string $method like 'CART', indicates who the client who called this was |
|
81 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
82 | - * @param boolean $update_txn whether or not to call |
|
83 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
84 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
85 | - * @return EE_Payment |
|
86 | - * @throws EE_Error |
|
87 | - * @throws InvalidArgumentException |
|
88 | - * @throws ReflectionException |
|
89 | - * @throws RuntimeException |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - * @throws InvalidInterfaceException |
|
92 | - */ |
|
93 | - public function process_payment( |
|
94 | - EE_Payment_Method $payment_method, |
|
95 | - EE_Transaction $transaction, |
|
96 | - $amount = null, |
|
97 | - $billing_form = null, |
|
98 | - $return_url = null, |
|
99 | - $method = 'CART', |
|
100 | - $by_admin = false, |
|
101 | - $update_txn = true, |
|
102 | - $cancel_url = '' |
|
103 | - ) { |
|
104 | - if ((float) $amount < 0) { |
|
105 | - throw new EE_Error( |
|
106 | - sprintf( |
|
107 | - __( |
|
108 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - $amount, |
|
112 | - $transaction->ID() |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - // verify payment method |
|
117 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
118 | - $payment_method, |
|
119 | - true |
|
120 | - ); |
|
121 | - // verify transaction |
|
122 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
123 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
124 | - // verify payment method type |
|
125 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
126 | - $payment = $payment_method->type_obj()->process_payment( |
|
127 | - $transaction, |
|
128 | - min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
129 | - $billing_form, |
|
130 | - $return_url, |
|
131 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
132 | - $method, |
|
133 | - $by_admin |
|
134 | - ); |
|
135 | - // check if payment method uses an off-site gateway |
|
136 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
137 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
138 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
139 | - } |
|
140 | - return $payment; |
|
141 | - } |
|
142 | - EE_Error::add_error( |
|
143 | - sprintf( |
|
144 | - __( |
|
145 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - '<br/>', |
|
149 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
150 | - ), |
|
151 | - __FILE__, |
|
152 | - __FUNCTION__, |
|
153 | - __LINE__ |
|
154 | - ); |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param EE_Transaction|int $transaction |
|
161 | - * @param EE_Payment_Method $payment_method |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws InvalidDataTypeException |
|
166 | - * @throws InvalidInterfaceException |
|
167 | - */ |
|
168 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
169 | - { |
|
170 | - /** @type \EE_Transaction $transaction */ |
|
171 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
172 | - $primary_reg = $transaction->primary_registration(); |
|
173 | - if (! $primary_reg instanceof EE_Registration) { |
|
174 | - throw new EE_Error( |
|
175 | - sprintf( |
|
176 | - __( |
|
177 | - 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
178 | - 'event_espresso' |
|
179 | - ), |
|
180 | - $transaction->ID() |
|
181 | - ) |
|
182 | - ); |
|
183 | - } |
|
184 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
185 | - $payment_method, |
|
186 | - true |
|
187 | - ); |
|
188 | - $url = add_query_arg( |
|
189 | - array( |
|
190 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
191 | - 'ee_payment_method' => $payment_method->slug(), |
|
192 | - ), |
|
193 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
194 | - ); |
|
195 | - return $url; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
201 | - * we can easily find what registration the IPN is for and what payment method. |
|
202 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
203 | - * If a payment is found for the IPN info, it is saved. |
|
204 | - * |
|
205 | - * @param array $_req_data eg $_REQUEST |
|
206 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
207 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
208 | - * @param boolean $update_txn whether or not to call |
|
209 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
210 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
211 | - * or is processed manually ( false like Mijireh ) |
|
212 | - * @throws EE_Error |
|
213 | - * @throws Exception |
|
214 | - * @return EE_Payment |
|
215 | - * @throws \RuntimeException |
|
216 | - * @throws \ReflectionException |
|
217 | - * @throws \InvalidArgumentException |
|
218 | - * @throws InvalidInterfaceException |
|
219 | - * @throws InvalidDataTypeException |
|
220 | - */ |
|
221 | - public function process_ipn( |
|
222 | - $_req_data, |
|
223 | - $transaction = null, |
|
224 | - $payment_method = null, |
|
225 | - $update_txn = true, |
|
226 | - $separate_IPN_request = true |
|
227 | - ) { |
|
228 | - EE_Registry::instance()->load_model('Change_Log'); |
|
229 | - $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
230 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
231 | - $obj_for_log = null; |
|
232 | - if ($transaction instanceof EE_Transaction) { |
|
233 | - $obj_for_log = $transaction; |
|
234 | - if ($payment_method instanceof EE_Payment_Method) { |
|
235 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
236 | - array( |
|
237 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
238 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - } elseif ($payment_method instanceof EE_Payment) { |
|
243 | - $obj_for_log = $payment_method; |
|
244 | - } |
|
245 | - $log = EEM_Change_Log::instance()->log( |
|
246 | - EEM_Change_Log::type_gateway, |
|
247 | - array('IPN data received' => $_req_data), |
|
248 | - $obj_for_log |
|
249 | - ); |
|
250 | - try { |
|
251 | - /** |
|
252 | - * @var EE_Payment $payment |
|
253 | - */ |
|
254 | - $payment = null; |
|
255 | - if ($transaction && $payment_method) { |
|
256 | - /** @type EE_Transaction $transaction */ |
|
257 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
258 | - /** @type EE_Payment_Method $payment_method */ |
|
259 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
260 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
261 | - try { |
|
262 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
263 | - $log->set_object($payment); |
|
264 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
265 | - EEM_Change_Log::instance()->log( |
|
266 | - EEM_Change_Log::type_gateway, |
|
267 | - array( |
|
268 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
269 | - 'current_url' => EEH_URL::current_url(), |
|
270 | - 'payment' => $e->getPaymentProperties(), |
|
271 | - 'IPN_data' => $e->getIpnData(), |
|
272 | - ), |
|
273 | - $obj_for_log |
|
274 | - ); |
|
275 | - return $e->getPayment(); |
|
276 | - } |
|
277 | - } else { |
|
278 | - // not a payment |
|
279 | - EE_Error::add_error( |
|
280 | - sprintf( |
|
281 | - __( |
|
282 | - '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.', |
|
283 | - 'event_espresso' |
|
284 | - ), |
|
285 | - '<br/>', |
|
286 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
287 | - ), |
|
288 | - __FILE__, |
|
289 | - __FUNCTION__, |
|
290 | - __LINE__ |
|
291 | - ); |
|
292 | - } |
|
293 | - } else { |
|
294 | - // that's actually pretty ok. The IPN just wasn't able |
|
295 | - // to identify which transaction or payment method this was for |
|
296 | - // give all active payment methods a chance to claim it |
|
297 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
298 | - foreach ($active_payment_methods as $active_payment_method) { |
|
299 | - try { |
|
300 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
301 | - $payment_method = $active_payment_method; |
|
302 | - EEM_Change_Log::instance()->log( |
|
303 | - EEM_Change_Log::type_gateway, |
|
304 | - array('IPN data' => $_req_data), |
|
305 | - $payment |
|
306 | - ); |
|
307 | - break; |
|
308 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
309 | - EEM_Change_Log::instance()->log( |
|
310 | - EEM_Change_Log::type_gateway, |
|
311 | - array( |
|
312 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
313 | - 'current_url' => EEH_URL::current_url(), |
|
314 | - 'payment' => $e->getPaymentProperties(), |
|
315 | - 'IPN_data' => $e->getIpnData(), |
|
316 | - ), |
|
317 | - $obj_for_log |
|
318 | - ); |
|
319 | - return $e->getPayment(); |
|
320 | - } catch (EE_Error $e) { |
|
321 | - // that's fine- it apparently couldn't handle the IPN |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
326 | - if ($payment instanceof EE_Payment) { |
|
327 | - $payment->save(); |
|
328 | - // update the TXN |
|
329 | - $this->update_txn_based_on_payment( |
|
330 | - $transaction, |
|
331 | - $payment, |
|
332 | - $update_txn, |
|
333 | - $separate_IPN_request |
|
334 | - ); |
|
335 | - } else { |
|
336 | - // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
337 | - if ($payment_method) { |
|
338 | - EEM_Change_Log::instance()->log( |
|
339 | - EEM_Change_Log::type_gateway, |
|
340 | - array('IPN data' => $_req_data), |
|
341 | - $payment_method |
|
342 | - ); |
|
343 | - } elseif ($transaction) { |
|
344 | - EEM_Change_Log::instance()->log( |
|
345 | - EEM_Change_Log::type_gateway, |
|
346 | - array('IPN data' => $_req_data), |
|
347 | - $transaction |
|
348 | - ); |
|
349 | - } |
|
350 | - } |
|
351 | - return $payment; |
|
352 | - } catch (EE_Error $e) { |
|
353 | - do_action( |
|
354 | - 'AHEE__log', |
|
355 | - __FILE__, |
|
356 | - __FUNCTION__, |
|
357 | - sprintf( |
|
358 | - __( |
|
359 | - 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - print_r($transaction, true), |
|
363 | - print_r($_req_data, true), |
|
364 | - $e->getMessage() |
|
365 | - ) |
|
366 | - ); |
|
367 | - throw $e; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Removes any non-printable illegal characters from the input, |
|
374 | - * which might cause a raucous when trying to insert into the database |
|
375 | - * |
|
376 | - * @param array $request_data |
|
377 | - * @return array |
|
378 | - */ |
|
379 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
380 | - { |
|
381 | - $return_data = array(); |
|
382 | - foreach ($request_data as $key => $value) { |
|
383 | - $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
384 | - $value |
|
385 | - ); |
|
386 | - } |
|
387 | - return $return_data; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Removes any non-printable illegal characters from the input, |
|
393 | - * which might cause a raucous when trying to insert into the database |
|
394 | - * |
|
395 | - * @param string $request_data |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - protected function _remove_unusable_characters($request_data) |
|
399 | - { |
|
400 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * Should be called just before displaying the payment attempt results to the user, |
|
406 | - * when the payment attempt has finished. Some payment methods may have special |
|
407 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
408 | - * and then the user is redirected to a page that displays the payment's status, this |
|
409 | - * should be called while loading the page that displays the payment's status. If the user is |
|
410 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
411 | - * provider. |
|
412 | - * |
|
413 | - * @param EE_Transaction|int $transaction |
|
414 | - * @param bool $update_txn whether or not to call |
|
415 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
416 | - * @return EE_Payment |
|
417 | - * @throws EE_Error |
|
418 | - * @throws InvalidArgumentException |
|
419 | - * @throws ReflectionException |
|
420 | - * @throws RuntimeException |
|
421 | - * @throws InvalidDataTypeException |
|
422 | - * @throws InvalidInterfaceException |
|
423 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
424 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
425 | - */ |
|
426 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
427 | - { |
|
428 | - /** @var $transaction EE_Transaction */ |
|
429 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
430 | - $last_payment_method = $transaction->payment_method(); |
|
431 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
432 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
433 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
434 | - return $payment; |
|
435 | - } |
|
436 | - return null; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
442 | - * |
|
443 | - * @param EE_Payment_Method $payment_method |
|
444 | - * @param EE_Payment $payment_to_refund |
|
445 | - * @param array $refund_info |
|
446 | - * @return EE_Payment |
|
447 | - * @throws EE_Error |
|
448 | - * @throws InvalidArgumentException |
|
449 | - * @throws ReflectionException |
|
450 | - * @throws RuntimeException |
|
451 | - * @throws InvalidDataTypeException |
|
452 | - * @throws InvalidInterfaceException |
|
453 | - */ |
|
454 | - public function process_refund( |
|
455 | - EE_Payment_Method $payment_method, |
|
456 | - EE_Payment $payment_to_refund, |
|
457 | - array $refund_info = array() |
|
458 | - ) { |
|
459 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
460 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
461 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
462 | - } |
|
463 | - return $payment_to_refund; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * This should be called each time there may have been an update to a |
|
469 | - * payment on a transaction (ie, we asked for a payment to process a |
|
470 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
471 | - * we told a payment method to |
|
472 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
473 | - * process a refund. This should handle firing the correct hooks to |
|
474 | - * indicate |
|
475 | - * what exactly happened and updating the transaction appropriately). This |
|
476 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
477 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
478 | - * of transactions and payments, and to be tied to payment processing. |
|
479 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
480 | - * of previous code to decide whether or not to save (because the payment passed into |
|
481 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
482 | - * in which case we only want that payment object for some temporary usage during this request, |
|
483 | - * but we don't want it to be saved). |
|
484 | - * |
|
485 | - * @param EE_Transaction|int $transaction |
|
486 | - * @param EE_Payment $payment |
|
487 | - * @param boolean $update_txn |
|
488 | - * whether or not to call |
|
489 | - * EE_Transaction_Processor:: |
|
490 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
491 | - * (you can save 1 DB query if you know you're going |
|
492 | - * to save it later instead) |
|
493 | - * @param bool $IPN |
|
494 | - * if processing IPNs or other similar payment |
|
495 | - * related activities that occur in alternate |
|
496 | - * requests than the main one that is processing the |
|
497 | - * TXN, then set this to true to check whether the |
|
498 | - * TXN is locked before updating |
|
499 | - * @throws EE_Error |
|
500 | - * @throws InvalidArgumentException |
|
501 | - * @throws ReflectionException |
|
502 | - * @throws RuntimeException |
|
503 | - * @throws InvalidDataTypeException |
|
504 | - * @throws InvalidInterfaceException |
|
505 | - */ |
|
506 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
507 | - { |
|
508 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
509 | - /** @type EE_Transaction $transaction */ |
|
510 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
511 | - // can we freely update the TXN at this moment? |
|
512 | - if ($IPN && $transaction->is_locked()) { |
|
513 | - // don't update the transaction at this exact moment |
|
514 | - // because the TXN is active in another request |
|
515 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
516 | - time(), |
|
517 | - $transaction->ID(), |
|
518 | - $payment->ID() |
|
519 | - ); |
|
520 | - } else { |
|
521 | - // verify payment and that it has been saved |
|
522 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
523 | - if ($payment->payment_method() instanceof EE_Payment_Method |
|
524 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
525 | - ) { |
|
526 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
527 | - // update TXN registrations with payment info |
|
528 | - $this->process_registration_payments($transaction, $payment); |
|
529 | - } |
|
530 | - $do_action = $payment->just_approved() |
|
531 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
532 | - : $do_action; |
|
533 | - } else { |
|
534 | - // send out notifications |
|
535 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
536 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
537 | - } |
|
538 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
539 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
540 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
541 | - // set new value for total paid |
|
542 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
543 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
544 | - if ($update_txn) { |
|
545 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
546 | - } |
|
547 | - } |
|
548 | - // granular hook for others to use. |
|
549 | - do_action($do_action, $transaction, $payment); |
|
550 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
551 | - // global hook for others to use. |
|
552 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
553 | - } |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
559 | - * |
|
560 | - * @param EE_Transaction $transaction |
|
561 | - * @param EE_Payment $payment |
|
562 | - * @param EE_Registration[] $registrations |
|
563 | - * @throws EE_Error |
|
564 | - * @throws InvalidArgumentException |
|
565 | - * @throws RuntimeException |
|
566 | - * @throws InvalidDataTypeException |
|
567 | - * @throws InvalidInterfaceException |
|
568 | - */ |
|
569 | - public function process_registration_payments( |
|
570 | - EE_Transaction $transaction, |
|
571 | - EE_Payment $payment, |
|
572 | - array $registrations = array() |
|
573 | - ) { |
|
574 | - // only process if payment was successful |
|
575 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
576 | - return; |
|
577 | - } |
|
578 | - // EEM_Registration::instance()->show_next_x_db_queries(); |
|
579 | - if (empty($registrations)) { |
|
580 | - // find registrations with monies owing that can receive a payment |
|
581 | - $registrations = $transaction->registrations( |
|
582 | - array( |
|
583 | - array( |
|
584 | - // only these reg statuses can receive payments |
|
585 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
586 | - 'REG_final_price' => array('!=', 0), |
|
587 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
588 | - ), |
|
589 | - ) |
|
590 | - ); |
|
591 | - } |
|
592 | - // still nothing ??!?? |
|
593 | - if (empty($registrations)) { |
|
594 | - return; |
|
595 | - } |
|
596 | - // todo: break out the following logic into a separate strategy class |
|
597 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
598 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
599 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
600 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
601 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
602 | - $refund = $payment->is_a_refund(); |
|
603 | - // how much is available to apply to registrations? |
|
604 | - $available_payment_amount = abs($payment->amount()); |
|
605 | - foreach ($registrations as $registration) { |
|
606 | - if ($registration instanceof EE_Registration) { |
|
607 | - // nothing left? |
|
608 | - if ($available_payment_amount <= 0) { |
|
609 | - break; |
|
610 | - } |
|
611 | - if ($refund) { |
|
612 | - $available_payment_amount = $this->process_registration_refund( |
|
613 | - $registration, |
|
614 | - $payment, |
|
615 | - $available_payment_amount |
|
616 | - ); |
|
617 | - } else { |
|
618 | - $available_payment_amount = $this->process_registration_payment( |
|
619 | - $registration, |
|
620 | - $payment, |
|
621 | - $available_payment_amount |
|
622 | - ); |
|
623 | - } |
|
624 | - } |
|
625 | - } |
|
626 | - if ($available_payment_amount > 0 |
|
627 | - && apply_filters( |
|
628 | - 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
629 | - false |
|
630 | - )) { |
|
631 | - EE_Error::add_attention( |
|
632 | - sprintf( |
|
633 | - __( |
|
634 | - '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).', |
|
635 | - 'event_espresso' |
|
636 | - ), |
|
637 | - EEH_Template::format_currency($available_payment_amount), |
|
638 | - implode(', ', array_keys($registrations)), |
|
639 | - '<br/>', |
|
640 | - EEH_Template::format_currency($payment->amount()) |
|
641 | - ), |
|
642 | - __FILE__, |
|
643 | - __FUNCTION__, |
|
644 | - __LINE__ |
|
645 | - ); |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * update registration REG_paid field after successful payment and link registration with payment |
|
652 | - * |
|
653 | - * @param EE_Registration $registration |
|
654 | - * @param EE_Payment $payment |
|
655 | - * @param float $available_payment_amount |
|
656 | - * @return float |
|
657 | - * @throws EE_Error |
|
658 | - * @throws InvalidArgumentException |
|
659 | - * @throws RuntimeException |
|
660 | - * @throws InvalidDataTypeException |
|
661 | - * @throws InvalidInterfaceException |
|
662 | - */ |
|
663 | - public function process_registration_payment( |
|
664 | - EE_Registration $registration, |
|
665 | - EE_Payment $payment, |
|
666 | - $available_payment_amount = 0.00 |
|
667 | - ) { |
|
668 | - $owing = $registration->final_price() - $registration->paid(); |
|
669 | - if ($owing > 0) { |
|
670 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
671 | - $payment_amount = min($available_payment_amount, $owing); |
|
672 | - // update $available_payment_amount |
|
673 | - $available_payment_amount -= $payment_amount; |
|
674 | - // calculate and set new REG_paid |
|
675 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
676 | - // now save it |
|
677 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
678 | - } |
|
679 | - return $available_payment_amount; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * update registration REG_paid field after successful payment and link registration with payment |
|
685 | - * |
|
686 | - * @param EE_Registration $registration |
|
687 | - * @param EE_Payment $payment |
|
688 | - * @param float $payment_amount |
|
689 | - * @return void |
|
690 | - * @throws EE_Error |
|
691 | - * @throws InvalidArgumentException |
|
692 | - * @throws InvalidDataTypeException |
|
693 | - * @throws InvalidInterfaceException |
|
694 | - */ |
|
695 | - protected function _apply_registration_payment( |
|
696 | - EE_Registration $registration, |
|
697 | - EE_Payment $payment, |
|
698 | - $payment_amount = 0.00 |
|
699 | - ) { |
|
700 | - // find any existing reg payment records for this registration and payment |
|
701 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
702 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
703 | - ); |
|
704 | - // if existing registration payment exists |
|
705 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
706 | - // then update that record |
|
707 | - $existing_reg_payment->set_amount($payment_amount); |
|
708 | - $existing_reg_payment->save(); |
|
709 | - } else { |
|
710 | - // or add new relation between registration and payment and set amount |
|
711 | - $registration->_add_relation_to( |
|
712 | - $payment, |
|
713 | - 'Payment', |
|
714 | - array('RPY_amount' => $payment_amount) |
|
715 | - ); |
|
716 | - // make it stick |
|
717 | - $registration->save(); |
|
718 | - } |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * update registration REG_paid field after refund and link registration with payment |
|
724 | - * |
|
725 | - * @param EE_Registration $registration |
|
726 | - * @param EE_Payment $payment |
|
727 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
728 | - * @return float |
|
729 | - * @throws EE_Error |
|
730 | - * @throws InvalidArgumentException |
|
731 | - * @throws RuntimeException |
|
732 | - * @throws InvalidDataTypeException |
|
733 | - * @throws InvalidInterfaceException |
|
734 | - */ |
|
735 | - public function process_registration_refund( |
|
736 | - EE_Registration $registration, |
|
737 | - EE_Payment $payment, |
|
738 | - $available_refund_amount = 0.00 |
|
739 | - ) { |
|
740 | - // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
741 | - if ($registration->paid() > 0) { |
|
742 | - // ensure $available_refund_amount is NOT negative |
|
743 | - $available_refund_amount = (float) abs($available_refund_amount); |
|
744 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
745 | - $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
746 | - // update $available_payment_amount |
|
747 | - $available_refund_amount -= $refund_amount; |
|
748 | - // calculate and set new REG_paid |
|
749 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
750 | - // convert payment amount back to a negative value for storage in the db |
|
751 | - $refund_amount = (float) abs($refund_amount) * -1; |
|
752 | - // now save it |
|
753 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
754 | - } |
|
755 | - return $available_refund_amount; |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - /** |
|
760 | - * Process payments and transaction after payment process completed. |
|
761 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
762 | - * if this request happens to be processing an IPN, |
|
763 | - * then we will also set the Payment Options Reg Step to completed, |
|
764 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
765 | - * |
|
766 | - * @param EE_Transaction $transaction |
|
767 | - * @param EE_Payment $payment |
|
768 | - * @param bool $IPN |
|
769 | - * @throws EE_Error |
|
770 | - * @throws InvalidArgumentException |
|
771 | - * @throws ReflectionException |
|
772 | - * @throws RuntimeException |
|
773 | - * @throws InvalidDataTypeException |
|
774 | - * @throws InvalidInterfaceException |
|
775 | - */ |
|
776 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
777 | - { |
|
778 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
779 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
780 | - // is the Payment Options Reg Step completed ? |
|
781 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
782 | - // if the Payment Options Reg Step is completed... |
|
783 | - $revisit = $payment_options_step_completed === true; |
|
784 | - // then this is kinda sorta a revisit with regards to payments at least |
|
785 | - $transaction_processor->set_revisit($revisit); |
|
786 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
787 | - if ($IPN |
|
788 | - && $payment_options_step_completed !== true |
|
789 | - && ($payment->is_approved() || $payment->is_pending()) |
|
790 | - ) { |
|
791 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
792 | - 'payment_options' |
|
793 | - ); |
|
794 | - } |
|
795 | - // maybe update status, but don't save transaction just yet |
|
796 | - $transaction->update_status_based_on_total_paid(false); |
|
797 | - // check if 'finalize_registration' step has been completed... |
|
798 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
799 | - // if this is an IPN and the final step has not been initiated |
|
800 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
801 | - // and if it hasn't already been set as being started... |
|
802 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
803 | - } |
|
804 | - $transaction->save(); |
|
805 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
806 | - if ($IPN && $finalized !== false) { |
|
807 | - // and if we are all good to go, then send out notifications |
|
808 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
809 | - // ok, now process the transaction according to the payment |
|
810 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
811 | - $transaction, |
|
812 | - $payment |
|
813 | - ); |
|
814 | - } |
|
815 | - // DEBUG LOG |
|
816 | - $payment_method = $payment->payment_method(); |
|
817 | - if ($payment_method instanceof EE_Payment_Method) { |
|
818 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
819 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
820 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
821 | - if ($gateway instanceof EE_Gateway) { |
|
822 | - $gateway->log( |
|
823 | - array( |
|
824 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
825 | - 'transaction' => $transaction->model_field_array(), |
|
826 | - 'finalized' => $finalized, |
|
827 | - 'IPN' => $IPN, |
|
828 | - 'deliver_notifications' => has_filter( |
|
829 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
830 | - ), |
|
831 | - ), |
|
832 | - $payment |
|
833 | - ); |
|
834 | - } |
|
835 | - } |
|
836 | - } |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * Force posts to PayPal to use TLS v1.2. See: |
|
842 | - * https://core.trac.wordpress.org/ticket/36320 |
|
843 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
844 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
845 | - * This will affect PayPal standard, pro, express, and Payflow. |
|
846 | - * |
|
847 | - * @param $handle |
|
848 | - * @param $r |
|
849 | - * @param $url |
|
850 | - */ |
|
851 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
852 | - { |
|
853 | - if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
854 | - // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
855 | - // instead of the constant because it might not be defined |
|
856 | - curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
857 | - } |
|
858 | - } |
|
21 | + /** |
|
22 | + * @var EE_Payment_Processor $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @singleton method used to instantiate class object |
|
30 | + * @access public |
|
31 | + * @return EE_Payment_Processor instance |
|
32 | + */ |
|
33 | + public static function instance() |
|
34 | + { |
|
35 | + // check if class object is instantiated |
|
36 | + if (! self::$_instance instanceof EE_Payment_Processor) { |
|
37 | + self::$_instance = new self(); |
|
38 | + } |
|
39 | + return self::$_instance; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return EE_Payment_Processor |
|
45 | + */ |
|
46 | + public static function reset() |
|
47 | + { |
|
48 | + self::$_instance = null; |
|
49 | + return self::instance(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + *private constructor to prevent direct creation |
|
55 | + * |
|
56 | + * @Constructor |
|
57 | + * @access private |
|
58 | + */ |
|
59 | + private function __construct() |
|
60 | + { |
|
61 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
62 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
68 | + * appropriately. Saves the payment that is generated |
|
69 | + * |
|
70 | + * @param EE_Payment_Method $payment_method |
|
71 | + * @param EE_Transaction $transaction |
|
72 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
73 | + * Leave null if payment is for the full amount owing |
|
74 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
75 | + * Receive_form_submission() should have |
|
76 | + * already been called on the billing form |
|
77 | + * (ie, its inputs should have their normalized values set). |
|
78 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
79 | + * where to go AFTER the offsite gateway |
|
80 | + * @param string $method like 'CART', indicates who the client who called this was |
|
81 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
82 | + * @param boolean $update_txn whether or not to call |
|
83 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
84 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
85 | + * @return EE_Payment |
|
86 | + * @throws EE_Error |
|
87 | + * @throws InvalidArgumentException |
|
88 | + * @throws ReflectionException |
|
89 | + * @throws RuntimeException |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + * @throws InvalidInterfaceException |
|
92 | + */ |
|
93 | + public function process_payment( |
|
94 | + EE_Payment_Method $payment_method, |
|
95 | + EE_Transaction $transaction, |
|
96 | + $amount = null, |
|
97 | + $billing_form = null, |
|
98 | + $return_url = null, |
|
99 | + $method = 'CART', |
|
100 | + $by_admin = false, |
|
101 | + $update_txn = true, |
|
102 | + $cancel_url = '' |
|
103 | + ) { |
|
104 | + if ((float) $amount < 0) { |
|
105 | + throw new EE_Error( |
|
106 | + sprintf( |
|
107 | + __( |
|
108 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + $amount, |
|
112 | + $transaction->ID() |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + // verify payment method |
|
117 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
118 | + $payment_method, |
|
119 | + true |
|
120 | + ); |
|
121 | + // verify transaction |
|
122 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
123 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
124 | + // verify payment method type |
|
125 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
126 | + $payment = $payment_method->type_obj()->process_payment( |
|
127 | + $transaction, |
|
128 | + min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
129 | + $billing_form, |
|
130 | + $return_url, |
|
131 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
132 | + $method, |
|
133 | + $by_admin |
|
134 | + ); |
|
135 | + // check if payment method uses an off-site gateway |
|
136 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
137 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
138 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
139 | + } |
|
140 | + return $payment; |
|
141 | + } |
|
142 | + EE_Error::add_error( |
|
143 | + sprintf( |
|
144 | + __( |
|
145 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + '<br/>', |
|
149 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
150 | + ), |
|
151 | + __FILE__, |
|
152 | + __FUNCTION__, |
|
153 | + __LINE__ |
|
154 | + ); |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param EE_Transaction|int $transaction |
|
161 | + * @param EE_Payment_Method $payment_method |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws InvalidDataTypeException |
|
166 | + * @throws InvalidInterfaceException |
|
167 | + */ |
|
168 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
169 | + { |
|
170 | + /** @type \EE_Transaction $transaction */ |
|
171 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
172 | + $primary_reg = $transaction->primary_registration(); |
|
173 | + if (! $primary_reg instanceof EE_Registration) { |
|
174 | + throw new EE_Error( |
|
175 | + sprintf( |
|
176 | + __( |
|
177 | + 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
178 | + 'event_espresso' |
|
179 | + ), |
|
180 | + $transaction->ID() |
|
181 | + ) |
|
182 | + ); |
|
183 | + } |
|
184 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
185 | + $payment_method, |
|
186 | + true |
|
187 | + ); |
|
188 | + $url = add_query_arg( |
|
189 | + array( |
|
190 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
191 | + 'ee_payment_method' => $payment_method->slug(), |
|
192 | + ), |
|
193 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
194 | + ); |
|
195 | + return $url; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
201 | + * we can easily find what registration the IPN is for and what payment method. |
|
202 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
203 | + * If a payment is found for the IPN info, it is saved. |
|
204 | + * |
|
205 | + * @param array $_req_data eg $_REQUEST |
|
206 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
207 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
208 | + * @param boolean $update_txn whether or not to call |
|
209 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
210 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
211 | + * or is processed manually ( false like Mijireh ) |
|
212 | + * @throws EE_Error |
|
213 | + * @throws Exception |
|
214 | + * @return EE_Payment |
|
215 | + * @throws \RuntimeException |
|
216 | + * @throws \ReflectionException |
|
217 | + * @throws \InvalidArgumentException |
|
218 | + * @throws InvalidInterfaceException |
|
219 | + * @throws InvalidDataTypeException |
|
220 | + */ |
|
221 | + public function process_ipn( |
|
222 | + $_req_data, |
|
223 | + $transaction = null, |
|
224 | + $payment_method = null, |
|
225 | + $update_txn = true, |
|
226 | + $separate_IPN_request = true |
|
227 | + ) { |
|
228 | + EE_Registry::instance()->load_model('Change_Log'); |
|
229 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
230 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
231 | + $obj_for_log = null; |
|
232 | + if ($transaction instanceof EE_Transaction) { |
|
233 | + $obj_for_log = $transaction; |
|
234 | + if ($payment_method instanceof EE_Payment_Method) { |
|
235 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
236 | + array( |
|
237 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
238 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + } elseif ($payment_method instanceof EE_Payment) { |
|
243 | + $obj_for_log = $payment_method; |
|
244 | + } |
|
245 | + $log = EEM_Change_Log::instance()->log( |
|
246 | + EEM_Change_Log::type_gateway, |
|
247 | + array('IPN data received' => $_req_data), |
|
248 | + $obj_for_log |
|
249 | + ); |
|
250 | + try { |
|
251 | + /** |
|
252 | + * @var EE_Payment $payment |
|
253 | + */ |
|
254 | + $payment = null; |
|
255 | + if ($transaction && $payment_method) { |
|
256 | + /** @type EE_Transaction $transaction */ |
|
257 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
258 | + /** @type EE_Payment_Method $payment_method */ |
|
259 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
260 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
261 | + try { |
|
262 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
263 | + $log->set_object($payment); |
|
264 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
265 | + EEM_Change_Log::instance()->log( |
|
266 | + EEM_Change_Log::type_gateway, |
|
267 | + array( |
|
268 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
269 | + 'current_url' => EEH_URL::current_url(), |
|
270 | + 'payment' => $e->getPaymentProperties(), |
|
271 | + 'IPN_data' => $e->getIpnData(), |
|
272 | + ), |
|
273 | + $obj_for_log |
|
274 | + ); |
|
275 | + return $e->getPayment(); |
|
276 | + } |
|
277 | + } else { |
|
278 | + // not a payment |
|
279 | + EE_Error::add_error( |
|
280 | + sprintf( |
|
281 | + __( |
|
282 | + '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.', |
|
283 | + 'event_espresso' |
|
284 | + ), |
|
285 | + '<br/>', |
|
286 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
287 | + ), |
|
288 | + __FILE__, |
|
289 | + __FUNCTION__, |
|
290 | + __LINE__ |
|
291 | + ); |
|
292 | + } |
|
293 | + } else { |
|
294 | + // that's actually pretty ok. The IPN just wasn't able |
|
295 | + // to identify which transaction or payment method this was for |
|
296 | + // give all active payment methods a chance to claim it |
|
297 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
298 | + foreach ($active_payment_methods as $active_payment_method) { |
|
299 | + try { |
|
300 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
301 | + $payment_method = $active_payment_method; |
|
302 | + EEM_Change_Log::instance()->log( |
|
303 | + EEM_Change_Log::type_gateway, |
|
304 | + array('IPN data' => $_req_data), |
|
305 | + $payment |
|
306 | + ); |
|
307 | + break; |
|
308 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
309 | + EEM_Change_Log::instance()->log( |
|
310 | + EEM_Change_Log::type_gateway, |
|
311 | + array( |
|
312 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
313 | + 'current_url' => EEH_URL::current_url(), |
|
314 | + 'payment' => $e->getPaymentProperties(), |
|
315 | + 'IPN_data' => $e->getIpnData(), |
|
316 | + ), |
|
317 | + $obj_for_log |
|
318 | + ); |
|
319 | + return $e->getPayment(); |
|
320 | + } catch (EE_Error $e) { |
|
321 | + // that's fine- it apparently couldn't handle the IPN |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
326 | + if ($payment instanceof EE_Payment) { |
|
327 | + $payment->save(); |
|
328 | + // update the TXN |
|
329 | + $this->update_txn_based_on_payment( |
|
330 | + $transaction, |
|
331 | + $payment, |
|
332 | + $update_txn, |
|
333 | + $separate_IPN_request |
|
334 | + ); |
|
335 | + } else { |
|
336 | + // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
337 | + if ($payment_method) { |
|
338 | + EEM_Change_Log::instance()->log( |
|
339 | + EEM_Change_Log::type_gateway, |
|
340 | + array('IPN data' => $_req_data), |
|
341 | + $payment_method |
|
342 | + ); |
|
343 | + } elseif ($transaction) { |
|
344 | + EEM_Change_Log::instance()->log( |
|
345 | + EEM_Change_Log::type_gateway, |
|
346 | + array('IPN data' => $_req_data), |
|
347 | + $transaction |
|
348 | + ); |
|
349 | + } |
|
350 | + } |
|
351 | + return $payment; |
|
352 | + } catch (EE_Error $e) { |
|
353 | + do_action( |
|
354 | + 'AHEE__log', |
|
355 | + __FILE__, |
|
356 | + __FUNCTION__, |
|
357 | + sprintf( |
|
358 | + __( |
|
359 | + 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + print_r($transaction, true), |
|
363 | + print_r($_req_data, true), |
|
364 | + $e->getMessage() |
|
365 | + ) |
|
366 | + ); |
|
367 | + throw $e; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Removes any non-printable illegal characters from the input, |
|
374 | + * which might cause a raucous when trying to insert into the database |
|
375 | + * |
|
376 | + * @param array $request_data |
|
377 | + * @return array |
|
378 | + */ |
|
379 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
380 | + { |
|
381 | + $return_data = array(); |
|
382 | + foreach ($request_data as $key => $value) { |
|
383 | + $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
384 | + $value |
|
385 | + ); |
|
386 | + } |
|
387 | + return $return_data; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Removes any non-printable illegal characters from the input, |
|
393 | + * which might cause a raucous when trying to insert into the database |
|
394 | + * |
|
395 | + * @param string $request_data |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + protected function _remove_unusable_characters($request_data) |
|
399 | + { |
|
400 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * Should be called just before displaying the payment attempt results to the user, |
|
406 | + * when the payment attempt has finished. Some payment methods may have special |
|
407 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
408 | + * and then the user is redirected to a page that displays the payment's status, this |
|
409 | + * should be called while loading the page that displays the payment's status. If the user is |
|
410 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
411 | + * provider. |
|
412 | + * |
|
413 | + * @param EE_Transaction|int $transaction |
|
414 | + * @param bool $update_txn whether or not to call |
|
415 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
416 | + * @return EE_Payment |
|
417 | + * @throws EE_Error |
|
418 | + * @throws InvalidArgumentException |
|
419 | + * @throws ReflectionException |
|
420 | + * @throws RuntimeException |
|
421 | + * @throws InvalidDataTypeException |
|
422 | + * @throws InvalidInterfaceException |
|
423 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
424 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
425 | + */ |
|
426 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
427 | + { |
|
428 | + /** @var $transaction EE_Transaction */ |
|
429 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
430 | + $last_payment_method = $transaction->payment_method(); |
|
431 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
432 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
433 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
434 | + return $payment; |
|
435 | + } |
|
436 | + return null; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
442 | + * |
|
443 | + * @param EE_Payment_Method $payment_method |
|
444 | + * @param EE_Payment $payment_to_refund |
|
445 | + * @param array $refund_info |
|
446 | + * @return EE_Payment |
|
447 | + * @throws EE_Error |
|
448 | + * @throws InvalidArgumentException |
|
449 | + * @throws ReflectionException |
|
450 | + * @throws RuntimeException |
|
451 | + * @throws InvalidDataTypeException |
|
452 | + * @throws InvalidInterfaceException |
|
453 | + */ |
|
454 | + public function process_refund( |
|
455 | + EE_Payment_Method $payment_method, |
|
456 | + EE_Payment $payment_to_refund, |
|
457 | + array $refund_info = array() |
|
458 | + ) { |
|
459 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
460 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
461 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
462 | + } |
|
463 | + return $payment_to_refund; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * This should be called each time there may have been an update to a |
|
469 | + * payment on a transaction (ie, we asked for a payment to process a |
|
470 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
471 | + * we told a payment method to |
|
472 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
473 | + * process a refund. This should handle firing the correct hooks to |
|
474 | + * indicate |
|
475 | + * what exactly happened and updating the transaction appropriately). This |
|
476 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
477 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
478 | + * of transactions and payments, and to be tied to payment processing. |
|
479 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
480 | + * of previous code to decide whether or not to save (because the payment passed into |
|
481 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
482 | + * in which case we only want that payment object for some temporary usage during this request, |
|
483 | + * but we don't want it to be saved). |
|
484 | + * |
|
485 | + * @param EE_Transaction|int $transaction |
|
486 | + * @param EE_Payment $payment |
|
487 | + * @param boolean $update_txn |
|
488 | + * whether or not to call |
|
489 | + * EE_Transaction_Processor:: |
|
490 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
491 | + * (you can save 1 DB query if you know you're going |
|
492 | + * to save it later instead) |
|
493 | + * @param bool $IPN |
|
494 | + * if processing IPNs or other similar payment |
|
495 | + * related activities that occur in alternate |
|
496 | + * requests than the main one that is processing the |
|
497 | + * TXN, then set this to true to check whether the |
|
498 | + * TXN is locked before updating |
|
499 | + * @throws EE_Error |
|
500 | + * @throws InvalidArgumentException |
|
501 | + * @throws ReflectionException |
|
502 | + * @throws RuntimeException |
|
503 | + * @throws InvalidDataTypeException |
|
504 | + * @throws InvalidInterfaceException |
|
505 | + */ |
|
506 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
507 | + { |
|
508 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
509 | + /** @type EE_Transaction $transaction */ |
|
510 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
511 | + // can we freely update the TXN at this moment? |
|
512 | + if ($IPN && $transaction->is_locked()) { |
|
513 | + // don't update the transaction at this exact moment |
|
514 | + // because the TXN is active in another request |
|
515 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
516 | + time(), |
|
517 | + $transaction->ID(), |
|
518 | + $payment->ID() |
|
519 | + ); |
|
520 | + } else { |
|
521 | + // verify payment and that it has been saved |
|
522 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
523 | + if ($payment->payment_method() instanceof EE_Payment_Method |
|
524 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
525 | + ) { |
|
526 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
527 | + // update TXN registrations with payment info |
|
528 | + $this->process_registration_payments($transaction, $payment); |
|
529 | + } |
|
530 | + $do_action = $payment->just_approved() |
|
531 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
532 | + : $do_action; |
|
533 | + } else { |
|
534 | + // send out notifications |
|
535 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
536 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
537 | + } |
|
538 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
539 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
540 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
541 | + // set new value for total paid |
|
542 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
543 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
544 | + if ($update_txn) { |
|
545 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
546 | + } |
|
547 | + } |
|
548 | + // granular hook for others to use. |
|
549 | + do_action($do_action, $transaction, $payment); |
|
550 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
551 | + // global hook for others to use. |
|
552 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
553 | + } |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
559 | + * |
|
560 | + * @param EE_Transaction $transaction |
|
561 | + * @param EE_Payment $payment |
|
562 | + * @param EE_Registration[] $registrations |
|
563 | + * @throws EE_Error |
|
564 | + * @throws InvalidArgumentException |
|
565 | + * @throws RuntimeException |
|
566 | + * @throws InvalidDataTypeException |
|
567 | + * @throws InvalidInterfaceException |
|
568 | + */ |
|
569 | + public function process_registration_payments( |
|
570 | + EE_Transaction $transaction, |
|
571 | + EE_Payment $payment, |
|
572 | + array $registrations = array() |
|
573 | + ) { |
|
574 | + // only process if payment was successful |
|
575 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
576 | + return; |
|
577 | + } |
|
578 | + // EEM_Registration::instance()->show_next_x_db_queries(); |
|
579 | + if (empty($registrations)) { |
|
580 | + // find registrations with monies owing that can receive a payment |
|
581 | + $registrations = $transaction->registrations( |
|
582 | + array( |
|
583 | + array( |
|
584 | + // only these reg statuses can receive payments |
|
585 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
586 | + 'REG_final_price' => array('!=', 0), |
|
587 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
588 | + ), |
|
589 | + ) |
|
590 | + ); |
|
591 | + } |
|
592 | + // still nothing ??!?? |
|
593 | + if (empty($registrations)) { |
|
594 | + return; |
|
595 | + } |
|
596 | + // todo: break out the following logic into a separate strategy class |
|
597 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
598 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
599 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
600 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
601 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
602 | + $refund = $payment->is_a_refund(); |
|
603 | + // how much is available to apply to registrations? |
|
604 | + $available_payment_amount = abs($payment->amount()); |
|
605 | + foreach ($registrations as $registration) { |
|
606 | + if ($registration instanceof EE_Registration) { |
|
607 | + // nothing left? |
|
608 | + if ($available_payment_amount <= 0) { |
|
609 | + break; |
|
610 | + } |
|
611 | + if ($refund) { |
|
612 | + $available_payment_amount = $this->process_registration_refund( |
|
613 | + $registration, |
|
614 | + $payment, |
|
615 | + $available_payment_amount |
|
616 | + ); |
|
617 | + } else { |
|
618 | + $available_payment_amount = $this->process_registration_payment( |
|
619 | + $registration, |
|
620 | + $payment, |
|
621 | + $available_payment_amount |
|
622 | + ); |
|
623 | + } |
|
624 | + } |
|
625 | + } |
|
626 | + if ($available_payment_amount > 0 |
|
627 | + && apply_filters( |
|
628 | + 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
629 | + false |
|
630 | + )) { |
|
631 | + EE_Error::add_attention( |
|
632 | + sprintf( |
|
633 | + __( |
|
634 | + '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).', |
|
635 | + 'event_espresso' |
|
636 | + ), |
|
637 | + EEH_Template::format_currency($available_payment_amount), |
|
638 | + implode(', ', array_keys($registrations)), |
|
639 | + '<br/>', |
|
640 | + EEH_Template::format_currency($payment->amount()) |
|
641 | + ), |
|
642 | + __FILE__, |
|
643 | + __FUNCTION__, |
|
644 | + __LINE__ |
|
645 | + ); |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * update registration REG_paid field after successful payment and link registration with payment |
|
652 | + * |
|
653 | + * @param EE_Registration $registration |
|
654 | + * @param EE_Payment $payment |
|
655 | + * @param float $available_payment_amount |
|
656 | + * @return float |
|
657 | + * @throws EE_Error |
|
658 | + * @throws InvalidArgumentException |
|
659 | + * @throws RuntimeException |
|
660 | + * @throws InvalidDataTypeException |
|
661 | + * @throws InvalidInterfaceException |
|
662 | + */ |
|
663 | + public function process_registration_payment( |
|
664 | + EE_Registration $registration, |
|
665 | + EE_Payment $payment, |
|
666 | + $available_payment_amount = 0.00 |
|
667 | + ) { |
|
668 | + $owing = $registration->final_price() - $registration->paid(); |
|
669 | + if ($owing > 0) { |
|
670 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
671 | + $payment_amount = min($available_payment_amount, $owing); |
|
672 | + // update $available_payment_amount |
|
673 | + $available_payment_amount -= $payment_amount; |
|
674 | + // calculate and set new REG_paid |
|
675 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
676 | + // now save it |
|
677 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
678 | + } |
|
679 | + return $available_payment_amount; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * update registration REG_paid field after successful payment and link registration with payment |
|
685 | + * |
|
686 | + * @param EE_Registration $registration |
|
687 | + * @param EE_Payment $payment |
|
688 | + * @param float $payment_amount |
|
689 | + * @return void |
|
690 | + * @throws EE_Error |
|
691 | + * @throws InvalidArgumentException |
|
692 | + * @throws InvalidDataTypeException |
|
693 | + * @throws InvalidInterfaceException |
|
694 | + */ |
|
695 | + protected function _apply_registration_payment( |
|
696 | + EE_Registration $registration, |
|
697 | + EE_Payment $payment, |
|
698 | + $payment_amount = 0.00 |
|
699 | + ) { |
|
700 | + // find any existing reg payment records for this registration and payment |
|
701 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
702 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
703 | + ); |
|
704 | + // if existing registration payment exists |
|
705 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
706 | + // then update that record |
|
707 | + $existing_reg_payment->set_amount($payment_amount); |
|
708 | + $existing_reg_payment->save(); |
|
709 | + } else { |
|
710 | + // or add new relation between registration and payment and set amount |
|
711 | + $registration->_add_relation_to( |
|
712 | + $payment, |
|
713 | + 'Payment', |
|
714 | + array('RPY_amount' => $payment_amount) |
|
715 | + ); |
|
716 | + // make it stick |
|
717 | + $registration->save(); |
|
718 | + } |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * update registration REG_paid field after refund and link registration with payment |
|
724 | + * |
|
725 | + * @param EE_Registration $registration |
|
726 | + * @param EE_Payment $payment |
|
727 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
728 | + * @return float |
|
729 | + * @throws EE_Error |
|
730 | + * @throws InvalidArgumentException |
|
731 | + * @throws RuntimeException |
|
732 | + * @throws InvalidDataTypeException |
|
733 | + * @throws InvalidInterfaceException |
|
734 | + */ |
|
735 | + public function process_registration_refund( |
|
736 | + EE_Registration $registration, |
|
737 | + EE_Payment $payment, |
|
738 | + $available_refund_amount = 0.00 |
|
739 | + ) { |
|
740 | + // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
741 | + if ($registration->paid() > 0) { |
|
742 | + // ensure $available_refund_amount is NOT negative |
|
743 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
744 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
745 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
746 | + // update $available_payment_amount |
|
747 | + $available_refund_amount -= $refund_amount; |
|
748 | + // calculate and set new REG_paid |
|
749 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
750 | + // convert payment amount back to a negative value for storage in the db |
|
751 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
752 | + // now save it |
|
753 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
754 | + } |
|
755 | + return $available_refund_amount; |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + /** |
|
760 | + * Process payments and transaction after payment process completed. |
|
761 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
762 | + * if this request happens to be processing an IPN, |
|
763 | + * then we will also set the Payment Options Reg Step to completed, |
|
764 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
765 | + * |
|
766 | + * @param EE_Transaction $transaction |
|
767 | + * @param EE_Payment $payment |
|
768 | + * @param bool $IPN |
|
769 | + * @throws EE_Error |
|
770 | + * @throws InvalidArgumentException |
|
771 | + * @throws ReflectionException |
|
772 | + * @throws RuntimeException |
|
773 | + * @throws InvalidDataTypeException |
|
774 | + * @throws InvalidInterfaceException |
|
775 | + */ |
|
776 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
777 | + { |
|
778 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
779 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
780 | + // is the Payment Options Reg Step completed ? |
|
781 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
782 | + // if the Payment Options Reg Step is completed... |
|
783 | + $revisit = $payment_options_step_completed === true; |
|
784 | + // then this is kinda sorta a revisit with regards to payments at least |
|
785 | + $transaction_processor->set_revisit($revisit); |
|
786 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
787 | + if ($IPN |
|
788 | + && $payment_options_step_completed !== true |
|
789 | + && ($payment->is_approved() || $payment->is_pending()) |
|
790 | + ) { |
|
791 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
792 | + 'payment_options' |
|
793 | + ); |
|
794 | + } |
|
795 | + // maybe update status, but don't save transaction just yet |
|
796 | + $transaction->update_status_based_on_total_paid(false); |
|
797 | + // check if 'finalize_registration' step has been completed... |
|
798 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
799 | + // if this is an IPN and the final step has not been initiated |
|
800 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
801 | + // and if it hasn't already been set as being started... |
|
802 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
803 | + } |
|
804 | + $transaction->save(); |
|
805 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
806 | + if ($IPN && $finalized !== false) { |
|
807 | + // and if we are all good to go, then send out notifications |
|
808 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
809 | + // ok, now process the transaction according to the payment |
|
810 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
811 | + $transaction, |
|
812 | + $payment |
|
813 | + ); |
|
814 | + } |
|
815 | + // DEBUG LOG |
|
816 | + $payment_method = $payment->payment_method(); |
|
817 | + if ($payment_method instanceof EE_Payment_Method) { |
|
818 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
819 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
820 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
821 | + if ($gateway instanceof EE_Gateway) { |
|
822 | + $gateway->log( |
|
823 | + array( |
|
824 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
825 | + 'transaction' => $transaction->model_field_array(), |
|
826 | + 'finalized' => $finalized, |
|
827 | + 'IPN' => $IPN, |
|
828 | + 'deliver_notifications' => has_filter( |
|
829 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
830 | + ), |
|
831 | + ), |
|
832 | + $payment |
|
833 | + ); |
|
834 | + } |
|
835 | + } |
|
836 | + } |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * Force posts to PayPal to use TLS v1.2. See: |
|
842 | + * https://core.trac.wordpress.org/ticket/36320 |
|
843 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
844 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
845 | + * This will affect PayPal standard, pro, express, and Payflow. |
|
846 | + * |
|
847 | + * @param $handle |
|
848 | + * @param $r |
|
849 | + * @param $url |
|
850 | + */ |
|
851 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
852 | + { |
|
853 | + if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
854 | + // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
855 | + // instead of the constant because it might not be defined |
|
856 | + curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
857 | + } |
|
858 | + } |
|
859 | 859 | } |
@@ -37,31 +37,31 @@ discard block |
||
37 | 37 | * @param string $action_or_filter |
38 | 38 | */ |
39 | 39 | function deprecated_espresso_action_or_filter_doing_it_wrong( |
40 | - $deprecated_filter, |
|
41 | - $replacement, |
|
42 | - $replacement_location, |
|
43 | - $version_deprecated, |
|
44 | - $version_applies, |
|
45 | - $action_or_filter = 'action' |
|
40 | + $deprecated_filter, |
|
41 | + $replacement, |
|
42 | + $replacement_location, |
|
43 | + $version_deprecated, |
|
44 | + $version_applies, |
|
45 | + $action_or_filter = 'action' |
|
46 | 46 | ) { |
47 | - $action_or_filter = $action_or_filter === 'action' |
|
48 | - ? esc_html__('action', 'event_espresso') |
|
49 | - : esc_html__('filter', 'event_espresso'); |
|
50 | - EE_Error::doing_it_wrong( |
|
51 | - $deprecated_filter, |
|
52 | - sprintf( |
|
53 | - __( |
|
54 | - 'This %1$s is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"', |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - $action_or_filter, |
|
58 | - $replacement, |
|
59 | - $replacement_location, |
|
60 | - '<br />' |
|
61 | - ), |
|
62 | - $version_deprecated, |
|
63 | - $version_applies |
|
64 | - ); |
|
47 | + $action_or_filter = $action_or_filter === 'action' |
|
48 | + ? esc_html__('action', 'event_espresso') |
|
49 | + : esc_html__('filter', 'event_espresso'); |
|
50 | + EE_Error::doing_it_wrong( |
|
51 | + $deprecated_filter, |
|
52 | + sprintf( |
|
53 | + __( |
|
54 | + 'This %1$s is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"', |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + $action_or_filter, |
|
58 | + $replacement, |
|
59 | + $replacement_location, |
|
60 | + '<br />' |
|
61 | + ), |
|
62 | + $version_deprecated, |
|
63 | + $version_applies |
|
64 | + ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,90 +73,90 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) |
75 | 75 | { |
76 | - // list of old filters |
|
77 | - $deprecated_filters = array( |
|
78 | - 'update_registration_details' => true, |
|
79 | - 'process_payment' => true, |
|
80 | - 'finalize_registration' => true, |
|
81 | - 'and_proceed_to_payment' => true, |
|
82 | - 'proceed_to' => true, |
|
83 | - ); |
|
84 | - // loop thru and call doing_it_wrong() or remove any that aren't being used |
|
85 | - foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
86 | - // was this filter called ? |
|
87 | - if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) { |
|
88 | - // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
|
89 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
90 | - 'ee_read_ee', |
|
91 | - 'hide_doing_it_wrong_for_deprecated_SPCO_filter' |
|
92 | - ) && ! defined('DOING_AJAX')) { |
|
93 | - EE_Error::doing_it_wrong( |
|
94 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
95 | - sprintf( |
|
96 | - __( |
|
97 | - 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', |
|
98 | - 'event_espresso' |
|
99 | - ), |
|
100 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
101 | - '<br />', |
|
102 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
103 | - '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
|
104 | - ), |
|
105 | - '4.6.10' |
|
106 | - ); |
|
107 | - } |
|
108 | - } else { |
|
109 | - unset($deprecated_filters[ $deprecated_filter ]); |
|
110 | - } |
|
111 | - } |
|
112 | - if (! empty($deprecated_filters)) { |
|
113 | - |
|
114 | - if ($checkout->current_step->slug( |
|
115 | - ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
116 | - $submit_button_text = apply_filters( |
|
117 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', |
|
118 | - $submit_button_text |
|
119 | - ); |
|
120 | - } elseif ($checkout->current_step->slug( |
|
121 | - ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
122 | - $submit_button_text = apply_filters( |
|
123 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', |
|
124 | - $submit_button_text |
|
125 | - ); |
|
126 | - } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug( |
|
127 | - ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
128 | - $submit_button_text = apply_filters( |
|
129 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', |
|
130 | - $submit_button_text |
|
131 | - ); |
|
132 | - } |
|
133 | - if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
134 | - if ($checkout->payment_required() && $checkout->next_step->slug( |
|
135 | - ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
136 | - $submit_button_text .= apply_filters( |
|
137 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', |
|
138 | - $submit_button_text |
|
139 | - ); |
|
140 | - } |
|
141 | - if ($checkout->next_step->slug( |
|
142 | - ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
143 | - $submit_button_text = apply_filters( |
|
144 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', |
|
145 | - $submit_button_text |
|
146 | - ) . $checkout->next_step->name(); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - } |
|
151 | - return $submit_button_text; |
|
76 | + // list of old filters |
|
77 | + $deprecated_filters = array( |
|
78 | + 'update_registration_details' => true, |
|
79 | + 'process_payment' => true, |
|
80 | + 'finalize_registration' => true, |
|
81 | + 'and_proceed_to_payment' => true, |
|
82 | + 'proceed_to' => true, |
|
83 | + ); |
|
84 | + // loop thru and call doing_it_wrong() or remove any that aren't being used |
|
85 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
86 | + // was this filter called ? |
|
87 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) { |
|
88 | + // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
|
89 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
90 | + 'ee_read_ee', |
|
91 | + 'hide_doing_it_wrong_for_deprecated_SPCO_filter' |
|
92 | + ) && ! defined('DOING_AJAX')) { |
|
93 | + EE_Error::doing_it_wrong( |
|
94 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
95 | + sprintf( |
|
96 | + __( |
|
97 | + 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', |
|
98 | + 'event_espresso' |
|
99 | + ), |
|
100 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
101 | + '<br />', |
|
102 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
103 | + '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
|
104 | + ), |
|
105 | + '4.6.10' |
|
106 | + ); |
|
107 | + } |
|
108 | + } else { |
|
109 | + unset($deprecated_filters[ $deprecated_filter ]); |
|
110 | + } |
|
111 | + } |
|
112 | + if (! empty($deprecated_filters)) { |
|
113 | + |
|
114 | + if ($checkout->current_step->slug( |
|
115 | + ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
116 | + $submit_button_text = apply_filters( |
|
117 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', |
|
118 | + $submit_button_text |
|
119 | + ); |
|
120 | + } elseif ($checkout->current_step->slug( |
|
121 | + ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
122 | + $submit_button_text = apply_filters( |
|
123 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', |
|
124 | + $submit_button_text |
|
125 | + ); |
|
126 | + } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug( |
|
127 | + ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
128 | + $submit_button_text = apply_filters( |
|
129 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', |
|
130 | + $submit_button_text |
|
131 | + ); |
|
132 | + } |
|
133 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
134 | + if ($checkout->payment_required() && $checkout->next_step->slug( |
|
135 | + ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
136 | + $submit_button_text .= apply_filters( |
|
137 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', |
|
138 | + $submit_button_text |
|
139 | + ); |
|
140 | + } |
|
141 | + if ($checkout->next_step->slug( |
|
142 | + ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
143 | + $submit_button_text = apply_filters( |
|
144 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', |
|
145 | + $submit_button_text |
|
146 | + ) . $checkout->next_step->name(); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + } |
|
151 | + return $submit_button_text; |
|
152 | 152 | |
153 | 153 | } |
154 | 154 | |
155 | 155 | add_filter( |
156 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
157 | - 'ee_deprecated__registration_checkout__button_text', |
|
158 | - 10, |
|
159 | - 2 |
|
156 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
157 | + 'ee_deprecated__registration_checkout__button_text', |
|
158 | + 10, |
|
159 | + 2 |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | |
@@ -168,54 +168,54 @@ discard block |
||
168 | 168 | */ |
169 | 169 | function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) |
170 | 170 | { |
171 | - $action_ref = null; |
|
172 | - $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') |
|
173 | - ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
174 | - $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') |
|
175 | - ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
176 | - if ($action_ref) { |
|
177 | - |
|
178 | - EE_Error::doing_it_wrong( |
|
179 | - $action_ref, |
|
180 | - sprintf( |
|
181 | - __( |
|
182 | - 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', |
|
183 | - 'event_espresso' |
|
184 | - ), |
|
185 | - '<br />', |
|
186 | - '/core/business/EE_Transaction_Processor.class.php', |
|
187 | - 'AHEE__EE_Transaction_Processor__finalize', |
|
188 | - 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
189 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
190 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing' |
|
191 | - ), |
|
192 | - '4.6.0' |
|
193 | - ); |
|
194 | - switch ($action_ref) { |
|
195 | - case 'AHEE__EE_Transaction__finalize__new_transaction' : |
|
196 | - do_action( |
|
197 | - 'AHEE__EE_Transaction__finalize__new_transaction', |
|
198 | - $checkout->transaction, |
|
199 | - $checkout->admin_request |
|
200 | - ); |
|
201 | - break; |
|
202 | - case 'AHEE__EE_Transaction__finalize__all_transaction' : |
|
203 | - do_action( |
|
204 | - 'AHEE__EE_Transaction__finalize__new_transaction', |
|
205 | - $checkout->transaction, |
|
206 | - array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), |
|
207 | - $checkout->admin_request |
|
208 | - ); |
|
209 | - break; |
|
210 | - } |
|
211 | - } |
|
171 | + $action_ref = null; |
|
172 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') |
|
173 | + ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
174 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') |
|
175 | + ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
176 | + if ($action_ref) { |
|
177 | + |
|
178 | + EE_Error::doing_it_wrong( |
|
179 | + $action_ref, |
|
180 | + sprintf( |
|
181 | + __( |
|
182 | + 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', |
|
183 | + 'event_espresso' |
|
184 | + ), |
|
185 | + '<br />', |
|
186 | + '/core/business/EE_Transaction_Processor.class.php', |
|
187 | + 'AHEE__EE_Transaction_Processor__finalize', |
|
188 | + 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
189 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
190 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing' |
|
191 | + ), |
|
192 | + '4.6.0' |
|
193 | + ); |
|
194 | + switch ($action_ref) { |
|
195 | + case 'AHEE__EE_Transaction__finalize__new_transaction' : |
|
196 | + do_action( |
|
197 | + 'AHEE__EE_Transaction__finalize__new_transaction', |
|
198 | + $checkout->transaction, |
|
199 | + $checkout->admin_request |
|
200 | + ); |
|
201 | + break; |
|
202 | + case 'AHEE__EE_Transaction__finalize__all_transaction' : |
|
203 | + do_action( |
|
204 | + 'AHEE__EE_Transaction__finalize__new_transaction', |
|
205 | + $checkout->transaction, |
|
206 | + array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), |
|
207 | + $checkout->admin_request |
|
208 | + ); |
|
209 | + break; |
|
210 | + } |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | add_action( |
215 | - 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
216 | - 'ee_deprecated_finalize_transaction', |
|
217 | - 10, |
|
218 | - 2 |
|
215 | + 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
|
216 | + 'ee_deprecated_finalize_transaction', |
|
217 | + 10, |
|
218 | + 2 |
|
219 | 219 | ); |
220 | 220 | /** |
221 | 221 | * ee_deprecated_finalize_registration |
@@ -224,35 +224,35 @@ discard block |
||
224 | 224 | */ |
225 | 225 | function ee_deprecated_finalize_registration(EE_Registration $registration) |
226 | 226 | { |
227 | - $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') |
|
228 | - ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null; |
|
229 | - if ($action_ref) { |
|
230 | - EE_Error::doing_it_wrong( |
|
231 | - $action_ref, |
|
232 | - sprintf( |
|
233 | - __( |
|
234 | - 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', |
|
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - '<br />', |
|
238 | - '/core/business/EE_Registration_Processor.class.php', |
|
239 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications' |
|
240 | - ), |
|
241 | - '4.6.0' |
|
242 | - ); |
|
243 | - do_action( |
|
244 | - 'AHEE__EE_Registration__finalize__update_and_new_reg', |
|
245 | - $registration, |
|
246 | - (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) |
|
247 | - ); |
|
248 | - } |
|
227 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') |
|
228 | + ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null; |
|
229 | + if ($action_ref) { |
|
230 | + EE_Error::doing_it_wrong( |
|
231 | + $action_ref, |
|
232 | + sprintf( |
|
233 | + __( |
|
234 | + 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + '<br />', |
|
238 | + '/core/business/EE_Registration_Processor.class.php', |
|
239 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications' |
|
240 | + ), |
|
241 | + '4.6.0' |
|
242 | + ); |
|
243 | + do_action( |
|
244 | + 'AHEE__EE_Registration__finalize__update_and_new_reg', |
|
245 | + $registration, |
|
246 | + (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)) |
|
247 | + ); |
|
248 | + } |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | add_action( |
252 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
253 | - 'ee_deprecated_finalize_registration', |
|
254 | - 10, |
|
255 | - 1 |
|
252 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
253 | + 'ee_deprecated_finalize_registration', |
|
254 | + 10, |
|
255 | + 1 |
|
256 | 256 | ); |
257 | 257 | |
258 | 258 | |
@@ -262,44 +262,44 @@ discard block |
||
262 | 262 | */ |
263 | 263 | function ee_deprecated_hooks() |
264 | 264 | { |
265 | - /** |
|
266 | - * @var $hooks array where keys are hook names, and their values are array{ |
|
267 | - * @type string $version when deprecated |
|
268 | - * @type string $alternative saying what to use instead |
|
269 | - * @type boolean $still_works whether or not the hook still works |
|
270 | - * } |
|
271 | - */ |
|
272 | - $hooks = array( |
|
273 | - 'AHEE__EE_System___do_setup_validations' => array( |
|
274 | - 'version' => '4.6.0', |
|
275 | - 'alternative' => __( |
|
276 | - 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', |
|
277 | - 'event_espresso' |
|
278 | - ), |
|
279 | - 'still_works' => false, |
|
280 | - ), |
|
281 | - ); |
|
282 | - foreach ($hooks as $name => $deprecation_info) { |
|
283 | - if (has_action($name)) { |
|
284 | - EE_Error::doing_it_wrong( |
|
285 | - $name, |
|
286 | - sprintf( |
|
287 | - __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
288 | - $deprecation_info['still_works'] ? __( |
|
289 | - 'It *may* work as an attempt to build in backwards compatibility.', |
|
290 | - 'event_espresso' |
|
291 | - ) : __('It has been completely removed.', 'event_espresso'), |
|
292 | - isset($deprecation_info['alternative']) |
|
293 | - ? $deprecation_info['alternative'] |
|
294 | - : __( |
|
295 | - 'Please read the current EE4 documentation further or contact Support.', |
|
296 | - 'event_espresso' |
|
297 | - ) |
|
298 | - ), |
|
299 | - isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
300 | - ); |
|
301 | - } |
|
302 | - } |
|
265 | + /** |
|
266 | + * @var $hooks array where keys are hook names, and their values are array{ |
|
267 | + * @type string $version when deprecated |
|
268 | + * @type string $alternative saying what to use instead |
|
269 | + * @type boolean $still_works whether or not the hook still works |
|
270 | + * } |
|
271 | + */ |
|
272 | + $hooks = array( |
|
273 | + 'AHEE__EE_System___do_setup_validations' => array( |
|
274 | + 'version' => '4.6.0', |
|
275 | + 'alternative' => __( |
|
276 | + 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', |
|
277 | + 'event_espresso' |
|
278 | + ), |
|
279 | + 'still_works' => false, |
|
280 | + ), |
|
281 | + ); |
|
282 | + foreach ($hooks as $name => $deprecation_info) { |
|
283 | + if (has_action($name)) { |
|
284 | + EE_Error::doing_it_wrong( |
|
285 | + $name, |
|
286 | + sprintf( |
|
287 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
288 | + $deprecation_info['still_works'] ? __( |
|
289 | + 'It *may* work as an attempt to build in backwards compatibility.', |
|
290 | + 'event_espresso' |
|
291 | + ) : __('It has been completely removed.', 'event_espresso'), |
|
292 | + isset($deprecation_info['alternative']) |
|
293 | + ? $deprecation_info['alternative'] |
|
294 | + : __( |
|
295 | + 'Please read the current EE4 documentation further or contact Support.', |
|
296 | + 'event_espresso' |
|
297 | + ) |
|
298 | + ), |
|
299 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
300 | + ); |
|
301 | + } |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
@@ -314,34 +314,34 @@ discard block |
||
314 | 314 | */ |
315 | 315 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
316 | 316 | { |
317 | - $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
318 | - || has_action( |
|
319 | - 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' |
|
320 | - ); |
|
321 | - if ($in_use) { |
|
322 | - $msg = __( |
|
323 | - 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
|
324 | - . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
|
325 | - . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end ' |
|
326 | - . 'to add other actions after a form submission has been received.', |
|
327 | - 'event_espresso' |
|
328 | - ); |
|
329 | - EE_Error::doing_it_wrong( |
|
330 | - __CLASS__ . '::' . __FUNCTION__, |
|
331 | - $msg, |
|
332 | - '4.8.32.rc.000' |
|
333 | - ); |
|
334 | - // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
|
335 | - if (is_admin() && ! defined('DOING_AJAX')) { |
|
336 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
337 | - } |
|
338 | - } |
|
339 | - return $in_use; |
|
317 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
318 | + || has_action( |
|
319 | + 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' |
|
320 | + ); |
|
321 | + if ($in_use) { |
|
322 | + $msg = __( |
|
323 | + 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
|
324 | + . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
|
325 | + . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end ' |
|
326 | + . 'to add other actions after a form submission has been received.', |
|
327 | + 'event_espresso' |
|
328 | + ); |
|
329 | + EE_Error::doing_it_wrong( |
|
330 | + __CLASS__ . '::' . __FUNCTION__, |
|
331 | + $msg, |
|
332 | + '4.8.32.rc.000' |
|
333 | + ); |
|
334 | + // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
|
335 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
336 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
337 | + } |
|
338 | + } |
|
339 | + return $in_use; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | add_action( |
343 | - 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', |
|
344 | - 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' |
|
343 | + 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', |
|
344 | + 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' |
|
345 | 345 | ); |
346 | 346 | |
347 | 347 | /** |
@@ -353,77 +353,77 @@ discard block |
||
353 | 353 | */ |
354 | 354 | function ee_deprecated_update_attendee_registration_form_old($admin_page) |
355 | 355 | { |
356 | - // check if the old hooks are in use. If not, do the default |
|
357 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
358 | - || ! $admin_page instanceof EE_Admin_Page) { |
|
359 | - return; |
|
360 | - } |
|
361 | - $req_data = $admin_page->get_request_data(); |
|
362 | - $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false; |
|
363 | - $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false; |
|
364 | - $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
365 | - if (! $REG_ID || ! $qstns) { |
|
366 | - EE_Error::add_error( |
|
367 | - __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), |
|
368 | - __FILE__, |
|
369 | - __FUNCTION__, |
|
370 | - __LINE__ |
|
371 | - ); |
|
372 | - } |
|
373 | - $success = true; |
|
374 | - |
|
375 | - // allow others to get in on this awesome fun :D |
|
376 | - do_action( |
|
377 | - 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', |
|
378 | - $REG_ID, |
|
379 | - $qstns |
|
380 | - ); |
|
381 | - // loop thru questions... FINALLY!!! |
|
382 | - |
|
383 | - foreach ($qstns as $QST_ID => $qstn) { |
|
384 | - // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
|
385 | - if (! is_array($qstn)) { |
|
386 | - $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
387 | - continue; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - foreach ($qstn as $ANS_ID => $ANS_value) { |
|
392 | - // get answer |
|
393 | - $query_params = array( |
|
394 | - 0 => array( |
|
395 | - 'ANS_ID' => $ANS_ID, |
|
396 | - 'REG_ID' => $REG_ID, |
|
397 | - 'QST_ID' => $QST_ID, |
|
398 | - ), |
|
399 | - ); |
|
400 | - $answer = EEM_Answer::instance()->get_one($query_params); |
|
401 | - // this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
|
402 | - if (! $answer instanceof EE_Answer) { |
|
403 | - $set_values = array( |
|
404 | - 'QST_ID' => $QST_ID, |
|
405 | - 'REG_ID' => $REG_ID, |
|
406 | - 'ANS_value' => $qstn, |
|
407 | - ); |
|
408 | - $success = EEM_Answer::instance()->insert($set_values); |
|
409 | - continue 2; |
|
410 | - } |
|
411 | - |
|
412 | - $answer->set('ANS_value', $ANS_value); |
|
413 | - $success = $answer->save(); |
|
414 | - } |
|
415 | - } |
|
416 | - $what = __('Registration Form', 'event_espresso'); |
|
417 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
418 | - $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
419 | - exit; |
|
356 | + // check if the old hooks are in use. If not, do the default |
|
357 | + if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
358 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
359 | + return; |
|
360 | + } |
|
361 | + $req_data = $admin_page->get_request_data(); |
|
362 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false; |
|
363 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false; |
|
364 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
365 | + if (! $REG_ID || ! $qstns) { |
|
366 | + EE_Error::add_error( |
|
367 | + __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), |
|
368 | + __FILE__, |
|
369 | + __FUNCTION__, |
|
370 | + __LINE__ |
|
371 | + ); |
|
372 | + } |
|
373 | + $success = true; |
|
374 | + |
|
375 | + // allow others to get in on this awesome fun :D |
|
376 | + do_action( |
|
377 | + 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', |
|
378 | + $REG_ID, |
|
379 | + $qstns |
|
380 | + ); |
|
381 | + // loop thru questions... FINALLY!!! |
|
382 | + |
|
383 | + foreach ($qstns as $QST_ID => $qstn) { |
|
384 | + // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
|
385 | + if (! is_array($qstn)) { |
|
386 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
387 | + continue; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
392 | + // get answer |
|
393 | + $query_params = array( |
|
394 | + 0 => array( |
|
395 | + 'ANS_ID' => $ANS_ID, |
|
396 | + 'REG_ID' => $REG_ID, |
|
397 | + 'QST_ID' => $QST_ID, |
|
398 | + ), |
|
399 | + ); |
|
400 | + $answer = EEM_Answer::instance()->get_one($query_params); |
|
401 | + // this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
|
402 | + if (! $answer instanceof EE_Answer) { |
|
403 | + $set_values = array( |
|
404 | + 'QST_ID' => $QST_ID, |
|
405 | + 'REG_ID' => $REG_ID, |
|
406 | + 'ANS_value' => $qstn, |
|
407 | + ); |
|
408 | + $success = EEM_Answer::instance()->insert($set_values); |
|
409 | + continue 2; |
|
410 | + } |
|
411 | + |
|
412 | + $answer->set('ANS_value', $ANS_value); |
|
413 | + $success = $answer->save(); |
|
414 | + } |
|
415 | + } |
|
416 | + $what = __('Registration Form', 'event_espresso'); |
|
417 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
418 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
419 | + exit; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | add_action( |
423 | - 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', |
|
424 | - 'ee_deprecated_update_attendee_registration_form_old', |
|
425 | - 10, |
|
426 | - 1 |
|
423 | + 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', |
|
424 | + 'ee_deprecated_update_attendee_registration_form_old', |
|
425 | + 10, |
|
426 | + 1 |
|
427 | 427 | ); |
428 | 428 | /** |
429 | 429 | * Render the registration admin page's custom questions area in the old fashion |
@@ -439,50 +439,50 @@ discard block |
||
439 | 439 | */ |
440 | 440 | function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) |
441 | 441 | { |
442 | - // check if the old hooks are in use. If not, do the default |
|
443 | - if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
444 | - || ! $admin_page instanceof EE_Admin_Page) { |
|
445 | - return $do_default_action; |
|
446 | - } |
|
447 | - add_filter( |
|
448 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
449 | - array($admin_page, 'form_before_question_group'), |
|
450 | - 10, |
|
451 | - 1 |
|
452 | - ); |
|
453 | - add_filter( |
|
454 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
455 | - array($admin_page, 'form_after_question_group'), |
|
456 | - 10, |
|
457 | - 1 |
|
458 | - ); |
|
459 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
460 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
461 | - |
|
462 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( |
|
463 | - $registration, |
|
464 | - $registration->get( |
|
465 | - 'EVT_ID' |
|
466 | - ) |
|
467 | - ); |
|
468 | - |
|
469 | - EE_Registry::instance()->load_helper('Form_Fields'); |
|
470 | - $template_args = array( |
|
471 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
472 | - 'reg_questions_form_action' => 'edit_registration', |
|
473 | - 'REG_ID' => $registration->ID(), |
|
474 | - ); |
|
475 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
476 | - echo EEH_Template::display_template($template_path, $template_args, true); |
|
477 | - // indicate that we should not do the default admin page code |
|
478 | - return false; |
|
442 | + // check if the old hooks are in use. If not, do the default |
|
443 | + if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
444 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
445 | + return $do_default_action; |
|
446 | + } |
|
447 | + add_filter( |
|
448 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
449 | + array($admin_page, 'form_before_question_group'), |
|
450 | + 10, |
|
451 | + 1 |
|
452 | + ); |
|
453 | + add_filter( |
|
454 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
455 | + array($admin_page, 'form_after_question_group'), |
|
456 | + 10, |
|
457 | + 1 |
|
458 | + ); |
|
459 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
460 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
461 | + |
|
462 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( |
|
463 | + $registration, |
|
464 | + $registration->get( |
|
465 | + 'EVT_ID' |
|
466 | + ) |
|
467 | + ); |
|
468 | + |
|
469 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
470 | + $template_args = array( |
|
471 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
472 | + 'reg_questions_form_action' => 'edit_registration', |
|
473 | + 'REG_ID' => $registration->ID(), |
|
474 | + ); |
|
475 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
476 | + echo EEH_Template::display_template($template_path, $template_args, true); |
|
477 | + // indicate that we should not do the default admin page code |
|
478 | + return false; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | add_action( |
482 | - 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
483 | - 'ee_deprecated_reg_questions_meta_box_old', |
|
484 | - 10, |
|
485 | - 3 |
|
482 | + 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
483 | + 'ee_deprecated_reg_questions_meta_box_old', |
|
484 | + 10, |
|
485 | + 3 |
|
486 | 486 | ); |
487 | 487 | |
488 | 488 | |
@@ -499,42 +499,42 @@ discard block |
||
499 | 499 | class EE_Message_Template_Defaults extends EE_Base |
500 | 500 | { |
501 | 501 | |
502 | - /** |
|
503 | - * EE_Message_Template_Defaults constructor. |
|
504 | - * |
|
505 | - * @param EE_messages $messages |
|
506 | - * @param $messenger_name |
|
507 | - * @param $message_type_name |
|
508 | - * @param int $GRP_ID |
|
509 | - * @return EE_Messages_Template_Defaults |
|
510 | - */ |
|
511 | - public function __construct( |
|
512 | - EE_messages $messages, |
|
513 | - $messenger_name, |
|
514 | - $message_type_name, |
|
515 | - $GRP_ID = 0 |
|
516 | - ) { |
|
517 | - EE_Error::doing_it_wrong( |
|
518 | - __FUNCTION__, |
|
519 | - __( |
|
520 | - 'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - '4.9.0' |
|
524 | - ); |
|
525 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
526 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
527 | - $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
528 | - $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
529 | - return EE_Registry::instance()->load_lib( |
|
530 | - 'Messages_Template_Defaults', |
|
531 | - array( |
|
532 | - $GRP_ID, |
|
533 | - $messenger, |
|
534 | - $message_type, |
|
535 | - ) |
|
536 | - ); |
|
537 | - } |
|
502 | + /** |
|
503 | + * EE_Message_Template_Defaults constructor. |
|
504 | + * |
|
505 | + * @param EE_messages $messages |
|
506 | + * @param $messenger_name |
|
507 | + * @param $message_type_name |
|
508 | + * @param int $GRP_ID |
|
509 | + * @return EE_Messages_Template_Defaults |
|
510 | + */ |
|
511 | + public function __construct( |
|
512 | + EE_messages $messages, |
|
513 | + $messenger_name, |
|
514 | + $message_type_name, |
|
515 | + $GRP_ID = 0 |
|
516 | + ) { |
|
517 | + EE_Error::doing_it_wrong( |
|
518 | + __FUNCTION__, |
|
519 | + __( |
|
520 | + 'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + '4.9.0' |
|
524 | + ); |
|
525 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
526 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
527 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
528 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
529 | + return EE_Registry::instance()->load_lib( |
|
530 | + 'Messages_Template_Defaults', |
|
531 | + array( |
|
532 | + $GRP_ID, |
|
533 | + $messenger, |
|
534 | + $message_type, |
|
535 | + ) |
|
536 | + ); |
|
537 | + } |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | |
@@ -552,525 +552,525 @@ discard block |
||
552 | 552 | class EE_messages |
553 | 553 | { |
554 | 554 | |
555 | - /** @type EE_messenger[] */ |
|
556 | - protected $_active_messengers = array(); |
|
557 | - |
|
558 | - /** @type array */ |
|
559 | - protected $_active_message_types = array(); |
|
560 | - |
|
561 | - /** @type EE_message_type[] */ |
|
562 | - protected $_installed_message_types = array(); |
|
563 | - |
|
564 | - /** @type EE_messenger */ |
|
565 | - protected $_messenger; |
|
566 | - |
|
567 | - /** @type EE_message_type */ |
|
568 | - protected $_message_type; |
|
569 | - |
|
570 | - /** @type array */ |
|
571 | - protected $_contexts = array(); |
|
572 | - |
|
573 | - /** @type EE_Message_Resource_Manager $_message_resource_manager */ |
|
574 | - protected $_message_resource_manager; |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * EE_messages constructor. |
|
579 | - * |
|
580 | - * @deprecated 4.9.0 |
|
581 | - */ |
|
582 | - public function __construct() |
|
583 | - { |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * @param string $method |
|
589 | - */ |
|
590 | - public function _class_is_deprecated($method) |
|
591 | - { |
|
592 | - EE_Error::doing_it_wrong( |
|
593 | - 'EE_messages::' . $method, |
|
594 | - __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
595 | - '4.9.0', |
|
596 | - '4.10.0.p' |
|
597 | - ); |
|
598 | - // Please use EE_Message_Resource_Manager instead |
|
599 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - /** |
|
604 | - * @deprecated 4.9.0 |
|
605 | - * @param string $messenger_name |
|
606 | - * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
|
607 | - */ |
|
608 | - public function ensure_messenger_is_active($messenger_name) |
|
609 | - { |
|
610 | - // EE_messages has been deprecated |
|
611 | - $this->_class_is_deprecated(__FUNCTION__); |
|
612 | - return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * @deprecated 4.9.0 |
|
618 | - * @param string $message_type message type name |
|
619 | - * @param $messenger |
|
620 | - * @return bool true if it got activated (or was active) and false if not. |
|
621 | - * @throws \EE_Error |
|
622 | - */ |
|
623 | - public function ensure_message_type_is_active($message_type, $messenger) |
|
624 | - { |
|
625 | - // EE_messages has been deprecated |
|
626 | - $this->_class_is_deprecated(__FUNCTION__); |
|
627 | - return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * @deprecated 4.9.0 |
|
633 | - * @param string $messenger_name |
|
634 | - * @param array $mts_to_activate (optional) An array of message types to activate with this messenger. |
|
635 | - * If included we do NOT setup the default message types (assuming they |
|
636 | - * are already setup.) |
|
637 | - * @return boolean an array of generated templates or false if nothing generated/activated. |
|
638 | - */ |
|
639 | - public function activate_messenger($messenger_name, $mts_to_activate = array()) |
|
640 | - { |
|
641 | - // EE_messages has been deprecated |
|
642 | - $this->_class_is_deprecated(__FUNCTION__); |
|
643 | - return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * @deprecated 4.9.0 |
|
649 | - * @param EE_messenger $messenger messenger used in trigger |
|
650 | - * @param EE_message_type $message_type message type used in trigger |
|
651 | - * |
|
652 | - * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
653 | - */ |
|
654 | - public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
655 | - { |
|
656 | - // EE_messages has been deprecated |
|
657 | - $this->_class_is_deprecated(__FUNCTION__); |
|
658 | - return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * @deprecated 4.9.0 |
|
664 | - * @param string $messenger |
|
665 | - * @return EE_messenger | null |
|
666 | - */ |
|
667 | - public function get_messenger_if_active($messenger) |
|
668 | - { |
|
669 | - // EE_messages has been deprecated |
|
670 | - $this->_class_is_deprecated(__FUNCTION__); |
|
671 | - return $this->_message_resource_manager->get_active_messenger($messenger); |
|
672 | - } |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * @deprecated 4.9.0 |
|
677 | - * @param EE_Message $message |
|
678 | - * @return array An array with 'messenger' and 'message_type' as the index and the corresponding valid object if |
|
679 | - * available. |
|
680 | - * Eg. Valid Messenger and Message Type: |
|
681 | - * array( |
|
682 | - * 'messenger' => new EE_Email_messenger(), |
|
683 | - * 'message_type' => new EE_Registration_Approved_message_type() |
|
684 | - * ) |
|
685 | - * Valid Messenger and Invalid Message Type: |
|
686 | - * array( |
|
687 | - * 'messenger' => new EE_Email_messenger(), |
|
688 | - * 'message_type' => null |
|
689 | - * ) |
|
690 | - */ |
|
691 | - public function validate_for_use(EE_Message $message) |
|
692 | - { |
|
693 | - // EE_messages has been deprecated |
|
694 | - $this->_class_is_deprecated(__FUNCTION__); |
|
695 | - return array( |
|
696 | - 'messenger' => $message->messenger_object(), |
|
697 | - 'message_type' => $message->message_type_object(), |
|
698 | - ); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * @deprecated 4.9.0 |
|
704 | - * @param string $type What type of message are we sending (corresponds to message types) |
|
705 | - * @param mixed $vars Data being sent for parsing in the message |
|
706 | - * @param string $sending_messenger if included then we ONLY use the specified messenger for delivery. |
|
707 | - * Otherwise we cycle through all active messengers. |
|
708 | - * @param string $generating_messenger if included then this messenger is used for generating the message |
|
709 | - * templates (but not for sending). |
|
710 | - * @param string $context If included then only a message type for a specific context will be |
|
711 | - * generated. |
|
712 | - * @param bool $send Default TRUE. If false, then this will just return the generated |
|
713 | - * EE_messages objects which might be used by the trigger to setup a batch |
|
714 | - * message (typically html messenger uses it). |
|
715 | - * @return bool |
|
716 | - */ |
|
717 | - public function send_message( |
|
718 | - $type, |
|
719 | - $vars, |
|
720 | - $sending_messenger = '', |
|
721 | - $generating_messenger = '', |
|
722 | - $context = '', |
|
723 | - $send = true |
|
724 | - ) { |
|
725 | - // EE_messages has been deprecated |
|
726 | - $this->_class_is_deprecated(__FUNCTION__); |
|
727 | - /** @type EE_Messages_Processor $processor */ |
|
728 | - $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
729 | - $error = false; |
|
730 | - // try to intelligently determine what method we'll call based on the incoming data. |
|
731 | - // if generating and sending are different then generate and send immediately. |
|
732 | - if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
733 | - // in the legacy system, when generating and sending were different, that means all the |
|
734 | - // vars are already in the request object. So let's just use that. |
|
735 | - try { |
|
736 | - /** @type EE_Message_To_Generate_From_Request $mtg */ |
|
737 | - $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
738 | - $processor->generate_and_send_now($mtg); |
|
739 | - } catch (EE_Error $e) { |
|
740 | - $error_msg = __( |
|
741 | - 'Please note that a system message failed to send due to a technical issue.', |
|
742 | - 'event_espresso' |
|
743 | - ); |
|
744 | - // add specific message for developers if WP_DEBUG in on |
|
745 | - $error_msg .= '||' . $e->getMessage(); |
|
746 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
747 | - $error = true; |
|
748 | - } |
|
749 | - } else { |
|
750 | - $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
751 | - // let's find out if there were any errors and how many successfully were queued. |
|
752 | - $count_errors = $processor->get_queue()->count_STS_in_queue( |
|
753 | - array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
754 | - ); |
|
755 | - $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
756 | - $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
757 | - $count_errors = $count_errors + $count_retry; |
|
758 | - if ($count_errors > 0) { |
|
759 | - $error = true; |
|
760 | - if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
761 | - $message = sprintf( |
|
762 | - __( |
|
763 | - 'There were %d errors and %d messages successfully queued for generation and sending', |
|
764 | - 'event_espresso' |
|
765 | - ), |
|
766 | - $count_errors, |
|
767 | - $count_queued |
|
768 | - ); |
|
769 | - } elseif ($count_errors > 1 && $count_queued === 1) { |
|
770 | - $message = sprintf( |
|
771 | - __( |
|
772 | - 'There were %d errors and %d message successfully queued for generation.', |
|
773 | - 'event_espresso' |
|
774 | - ), |
|
775 | - $count_errors, |
|
776 | - $count_queued |
|
777 | - ); |
|
778 | - } elseif ($count_errors === 1 && $count_queued > 1) { |
|
779 | - $message = sprintf( |
|
780 | - __( |
|
781 | - 'There was %d error and %d messages successfully queued for generation.', |
|
782 | - 'event_espresso' |
|
783 | - ), |
|
784 | - $count_errors, |
|
785 | - $count_queued |
|
786 | - ); |
|
787 | - } else { |
|
788 | - $message = sprintf( |
|
789 | - __( |
|
790 | - 'There was %d message that failed to be queued for generation.', |
|
791 | - 'event_espresso' |
|
792 | - ), |
|
793 | - $count_errors |
|
794 | - ); |
|
795 | - } |
|
796 | - EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
797 | - } else { |
|
798 | - if ($count_queued === 1) { |
|
799 | - $message = sprintf( |
|
800 | - __( |
|
801 | - '%d message successfully queued for generation.', |
|
802 | - 'event_espresso' |
|
803 | - ), |
|
804 | - $count_queued |
|
805 | - ); |
|
806 | - } else { |
|
807 | - $message = sprintf( |
|
808 | - __( |
|
809 | - '%d messages were successfully queued for generation.', |
|
810 | - 'event_espresso' |
|
811 | - ), |
|
812 | - $count_queued |
|
813 | - ); |
|
814 | - } |
|
815 | - EE_Error::add_success($message); |
|
816 | - } |
|
817 | - } |
|
818 | - // if no error then return the generated message(s). |
|
819 | - if (! $error && ! $send) { |
|
820 | - $generated_queue = $processor->generate_queue(false); |
|
821 | - // get message and return. |
|
822 | - $generated_queue->get_message_repository()->rewind(); |
|
823 | - $messages = array(); |
|
824 | - while ($generated_queue->get_message_repository()->valid()) { |
|
825 | - $message = $generated_queue->get_message_repository()->current(); |
|
826 | - if ($message instanceof EE_Message) { |
|
827 | - // set properties that might be expected by add-ons (backward compat) |
|
828 | - $message->content = $message->content(); |
|
829 | - $message->template_pack = $message->get_template_pack(); |
|
830 | - $message->template_variation = $message->get_template_pack_variation(); |
|
831 | - $messages[] = $message; |
|
832 | - } |
|
833 | - $generated_queue->get_message_repository()->next(); |
|
834 | - } |
|
835 | - return $messages; |
|
836 | - } |
|
837 | - return $error ? false |
|
838 | - : true; // yeah backwards eh? Really what we're returning is if there is a total success for all the messages or not. We'll modify this once we get message recording in place. |
|
839 | - } |
|
840 | - |
|
841 | - |
|
842 | - /** |
|
843 | - * @deprecated 4.9.0 |
|
844 | - * @param string $type This should correspond with a valid message type |
|
845 | - * @param string $context This should correspond with a valid context for the message type |
|
846 | - * @param string $messenger This should correspond with a valid messenger. |
|
847 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
848 | - * preview |
|
849 | - * @return string The body of the message. |
|
850 | - */ |
|
851 | - public function preview_message($type, $context, $messenger, $send = false) |
|
852 | - { |
|
853 | - // EE_messages has been deprecated |
|
854 | - $this->_class_is_deprecated(__FUNCTION__); |
|
855 | - return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * @since 4.5.0 |
|
861 | - * @deprecated 4.9.0 Moved to EED_Messages Module |
|
862 | - * @param string $messenger a string matching a valid active messenger in the system |
|
863 | - * @param string $message_type Although it seems contrary to the name of the method, a message type name is still |
|
864 | - * required to send along the message type to the messenger because this is used for |
|
865 | - * determining what specific variations might be loaded for the generated message. |
|
866 | - * @param stdClass $message a stdClass object in the format expected by the messenger. |
|
867 | - * |
|
868 | - * @return bool success or fail. |
|
869 | - */ |
|
870 | - public function send_message_with_messenger_only($messenger, $message_type, $message) |
|
871 | - { |
|
872 | - // EE_messages has been deprecated |
|
873 | - $this->_class_is_deprecated(__FUNCTION__); |
|
874 | - // setup for sending to new method. |
|
875 | - /** @type EE_Messages_Queue $queue */ |
|
876 | - $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
877 | - // make sure we have a proper message object |
|
878 | - if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
879 | - $msg = EE_Message_Factory::create( |
|
880 | - array( |
|
881 | - 'MSG_messenger' => $messenger, |
|
882 | - 'MSG_message_type' => $message_type, |
|
883 | - 'MSG_content' => $message->content, |
|
884 | - 'MSG_subject' => $message->subject, |
|
885 | - ) |
|
886 | - ); |
|
887 | - } else { |
|
888 | - $msg = $message; |
|
889 | - } |
|
890 | - if (! $msg instanceof EE_Message) { |
|
891 | - return false; |
|
892 | - } |
|
893 | - // make sure any content in a content property (if not empty) is set on the MSG_content. |
|
894 | - if (! empty($msg->content)) { |
|
895 | - $msg->set('MSG_content', $msg->content); |
|
896 | - } |
|
897 | - $queue->add($msg); |
|
898 | - return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * @deprecated 4.9.0 |
|
904 | - * @param $messenger |
|
905 | - * @param string $message_type message type that the templates are being created for |
|
906 | - * @param int $GRP_ID |
|
907 | - * @param bool $is_global |
|
908 | - * @return array|object if creation is successful then we return an array of info, otherwise an error_object is |
|
909 | - * returned. |
|
910 | - * @throws \EE_Error |
|
911 | - */ |
|
912 | - public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) |
|
913 | - { |
|
914 | - // EE_messages has been deprecated |
|
915 | - $this->_class_is_deprecated(__FUNCTION__); |
|
916 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
917 | - return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * @deprecated 4.9.0 |
|
923 | - * @param string $messenger_name name of EE_messenger |
|
924 | - * @param string $message_type_name name of EE_message_type |
|
925 | - * @return array |
|
926 | - */ |
|
927 | - public function get_fields($messenger_name, $message_type_name) |
|
928 | - { |
|
929 | - // EE_messages has been deprecated |
|
930 | - $this->_class_is_deprecated(__FUNCTION__); |
|
931 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
932 | - return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * @deprecated 4.9.0 |
|
938 | - * @access public |
|
939 | - * @param string $type we can indicate just returning installed message types |
|
940 | - * or messengers (or both) via this parameter. |
|
941 | - * @param bool $skip_cache if true then we skip the cache and retrieve via files. |
|
942 | - * @return array multidimensional array of messenger and message_type objects |
|
943 | - * (messengers index, and message_type index); |
|
944 | - */ |
|
945 | - public function get_installed($type = 'all', $skip_cache = false) |
|
946 | - { |
|
947 | - // EE_messages has been deprecated |
|
948 | - $this->_class_is_deprecated(__FUNCTION__); |
|
949 | - if ($skip_cache) { |
|
950 | - $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
|
951 | - } |
|
952 | - switch ($type) { |
|
953 | - case 'messengers' : |
|
954 | - return array( |
|
955 | - 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
956 | - ); |
|
957 | - break; |
|
958 | - case 'message_types' : |
|
959 | - return array( |
|
960 | - 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
961 | - ); |
|
962 | - break; |
|
963 | - case 'all' : |
|
964 | - default : |
|
965 | - return array( |
|
966 | - 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
967 | - 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
968 | - ); |
|
969 | - break; |
|
970 | - } |
|
971 | - } |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * @deprecated 4.9.0 |
|
976 | - * @return \EE_messenger[] |
|
977 | - */ |
|
978 | - public function get_active_messengers() |
|
979 | - { |
|
980 | - // EE_messages has been deprecated |
|
981 | - $this->_class_is_deprecated(__FUNCTION__); |
|
982 | - return $this->_message_resource_manager->active_messengers(); |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - /** |
|
987 | - * @deprecated 4.9.0 |
|
988 | - * @return array array of message_type references (string) |
|
989 | - */ |
|
990 | - public function get_active_message_types() |
|
991 | - { |
|
992 | - // EE_messages has been deprecated |
|
993 | - $this->_class_is_deprecated(__FUNCTION__); |
|
994 | - return $this->_message_resource_manager->list_of_active_message_types(); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * @deprecated 4.9.0 |
|
1000 | - * @return EE_message_type[] |
|
1001 | - */ |
|
1002 | - public function get_active_message_type_objects() |
|
1003 | - { |
|
1004 | - // EE_messages has been deprecated |
|
1005 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1006 | - return $this->_message_resource_manager->get_active_message_type_objects(); |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * @deprecated 4.9.0 |
|
1012 | - * @since 4.5.0 |
|
1013 | - * @param string $messenger The messenger being checked |
|
1014 | - * @return EE_message_type[] (or empty array if none present) |
|
1015 | - */ |
|
1016 | - public function get_active_message_types_per_messenger($messenger) |
|
1017 | - { |
|
1018 | - // EE_messages has been deprecated |
|
1019 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1020 | - return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * @deprecated 4.9.0 |
|
1026 | - * @param string $messenger The string should correspond to the messenger (message types are |
|
1027 | - * @param string $message_type The string should correspond to a message type. |
|
1028 | - * @return EE_message_type|null |
|
1029 | - */ |
|
1030 | - public function get_active_message_type($messenger, $message_type) |
|
1031 | - { |
|
1032 | - // EE_messages has been deprecated |
|
1033 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1034 | - return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * @deprecated 4.9.0 |
|
1040 | - * @return array|\EE_message_type[] |
|
1041 | - */ |
|
1042 | - public function get_installed_message_types() |
|
1043 | - { |
|
1044 | - // EE_messages has been deprecated |
|
1045 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1046 | - return $this->_message_resource_manager->installed_message_types(); |
|
1047 | - } |
|
1048 | - |
|
1049 | - |
|
1050 | - /** |
|
1051 | - * @deprecated 4.9.0 |
|
1052 | - * @return array |
|
1053 | - */ |
|
1054 | - public function get_installed_messengers() |
|
1055 | - { |
|
1056 | - // EE_messages has been deprecated |
|
1057 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1058 | - return $this->_message_resource_manager->installed_messengers(); |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * @deprecated 4.9.0 |
|
1064 | - * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by |
|
1065 | - * message type. |
|
1066 | - * @return array |
|
1067 | - */ |
|
1068 | - public function get_all_contexts($slugs_only = true) |
|
1069 | - { |
|
1070 | - // EE_messages has been deprecated |
|
1071 | - $this->_class_is_deprecated(__FUNCTION__); |
|
1072 | - return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
1073 | - } |
|
555 | + /** @type EE_messenger[] */ |
|
556 | + protected $_active_messengers = array(); |
|
557 | + |
|
558 | + /** @type array */ |
|
559 | + protected $_active_message_types = array(); |
|
560 | + |
|
561 | + /** @type EE_message_type[] */ |
|
562 | + protected $_installed_message_types = array(); |
|
563 | + |
|
564 | + /** @type EE_messenger */ |
|
565 | + protected $_messenger; |
|
566 | + |
|
567 | + /** @type EE_message_type */ |
|
568 | + protected $_message_type; |
|
569 | + |
|
570 | + /** @type array */ |
|
571 | + protected $_contexts = array(); |
|
572 | + |
|
573 | + /** @type EE_Message_Resource_Manager $_message_resource_manager */ |
|
574 | + protected $_message_resource_manager; |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * EE_messages constructor. |
|
579 | + * |
|
580 | + * @deprecated 4.9.0 |
|
581 | + */ |
|
582 | + public function __construct() |
|
583 | + { |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * @param string $method |
|
589 | + */ |
|
590 | + public function _class_is_deprecated($method) |
|
591 | + { |
|
592 | + EE_Error::doing_it_wrong( |
|
593 | + 'EE_messages::' . $method, |
|
594 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
595 | + '4.9.0', |
|
596 | + '4.10.0.p' |
|
597 | + ); |
|
598 | + // Please use EE_Message_Resource_Manager instead |
|
599 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + /** |
|
604 | + * @deprecated 4.9.0 |
|
605 | + * @param string $messenger_name |
|
606 | + * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
|
607 | + */ |
|
608 | + public function ensure_messenger_is_active($messenger_name) |
|
609 | + { |
|
610 | + // EE_messages has been deprecated |
|
611 | + $this->_class_is_deprecated(__FUNCTION__); |
|
612 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * @deprecated 4.9.0 |
|
618 | + * @param string $message_type message type name |
|
619 | + * @param $messenger |
|
620 | + * @return bool true if it got activated (or was active) and false if not. |
|
621 | + * @throws \EE_Error |
|
622 | + */ |
|
623 | + public function ensure_message_type_is_active($message_type, $messenger) |
|
624 | + { |
|
625 | + // EE_messages has been deprecated |
|
626 | + $this->_class_is_deprecated(__FUNCTION__); |
|
627 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * @deprecated 4.9.0 |
|
633 | + * @param string $messenger_name |
|
634 | + * @param array $mts_to_activate (optional) An array of message types to activate with this messenger. |
|
635 | + * If included we do NOT setup the default message types (assuming they |
|
636 | + * are already setup.) |
|
637 | + * @return boolean an array of generated templates or false if nothing generated/activated. |
|
638 | + */ |
|
639 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) |
|
640 | + { |
|
641 | + // EE_messages has been deprecated |
|
642 | + $this->_class_is_deprecated(__FUNCTION__); |
|
643 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * @deprecated 4.9.0 |
|
649 | + * @param EE_messenger $messenger messenger used in trigger |
|
650 | + * @param EE_message_type $message_type message type used in trigger |
|
651 | + * |
|
652 | + * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
653 | + */ |
|
654 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
655 | + { |
|
656 | + // EE_messages has been deprecated |
|
657 | + $this->_class_is_deprecated(__FUNCTION__); |
|
658 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * @deprecated 4.9.0 |
|
664 | + * @param string $messenger |
|
665 | + * @return EE_messenger | null |
|
666 | + */ |
|
667 | + public function get_messenger_if_active($messenger) |
|
668 | + { |
|
669 | + // EE_messages has been deprecated |
|
670 | + $this->_class_is_deprecated(__FUNCTION__); |
|
671 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
672 | + } |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * @deprecated 4.9.0 |
|
677 | + * @param EE_Message $message |
|
678 | + * @return array An array with 'messenger' and 'message_type' as the index and the corresponding valid object if |
|
679 | + * available. |
|
680 | + * Eg. Valid Messenger and Message Type: |
|
681 | + * array( |
|
682 | + * 'messenger' => new EE_Email_messenger(), |
|
683 | + * 'message_type' => new EE_Registration_Approved_message_type() |
|
684 | + * ) |
|
685 | + * Valid Messenger and Invalid Message Type: |
|
686 | + * array( |
|
687 | + * 'messenger' => new EE_Email_messenger(), |
|
688 | + * 'message_type' => null |
|
689 | + * ) |
|
690 | + */ |
|
691 | + public function validate_for_use(EE_Message $message) |
|
692 | + { |
|
693 | + // EE_messages has been deprecated |
|
694 | + $this->_class_is_deprecated(__FUNCTION__); |
|
695 | + return array( |
|
696 | + 'messenger' => $message->messenger_object(), |
|
697 | + 'message_type' => $message->message_type_object(), |
|
698 | + ); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * @deprecated 4.9.0 |
|
704 | + * @param string $type What type of message are we sending (corresponds to message types) |
|
705 | + * @param mixed $vars Data being sent for parsing in the message |
|
706 | + * @param string $sending_messenger if included then we ONLY use the specified messenger for delivery. |
|
707 | + * Otherwise we cycle through all active messengers. |
|
708 | + * @param string $generating_messenger if included then this messenger is used for generating the message |
|
709 | + * templates (but not for sending). |
|
710 | + * @param string $context If included then only a message type for a specific context will be |
|
711 | + * generated. |
|
712 | + * @param bool $send Default TRUE. If false, then this will just return the generated |
|
713 | + * EE_messages objects which might be used by the trigger to setup a batch |
|
714 | + * message (typically html messenger uses it). |
|
715 | + * @return bool |
|
716 | + */ |
|
717 | + public function send_message( |
|
718 | + $type, |
|
719 | + $vars, |
|
720 | + $sending_messenger = '', |
|
721 | + $generating_messenger = '', |
|
722 | + $context = '', |
|
723 | + $send = true |
|
724 | + ) { |
|
725 | + // EE_messages has been deprecated |
|
726 | + $this->_class_is_deprecated(__FUNCTION__); |
|
727 | + /** @type EE_Messages_Processor $processor */ |
|
728 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
729 | + $error = false; |
|
730 | + // try to intelligently determine what method we'll call based on the incoming data. |
|
731 | + // if generating and sending are different then generate and send immediately. |
|
732 | + if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
733 | + // in the legacy system, when generating and sending were different, that means all the |
|
734 | + // vars are already in the request object. So let's just use that. |
|
735 | + try { |
|
736 | + /** @type EE_Message_To_Generate_From_Request $mtg */ |
|
737 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
738 | + $processor->generate_and_send_now($mtg); |
|
739 | + } catch (EE_Error $e) { |
|
740 | + $error_msg = __( |
|
741 | + 'Please note that a system message failed to send due to a technical issue.', |
|
742 | + 'event_espresso' |
|
743 | + ); |
|
744 | + // add specific message for developers if WP_DEBUG in on |
|
745 | + $error_msg .= '||' . $e->getMessage(); |
|
746 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
747 | + $error = true; |
|
748 | + } |
|
749 | + } else { |
|
750 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
751 | + // let's find out if there were any errors and how many successfully were queued. |
|
752 | + $count_errors = $processor->get_queue()->count_STS_in_queue( |
|
753 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
754 | + ); |
|
755 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
756 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
757 | + $count_errors = $count_errors + $count_retry; |
|
758 | + if ($count_errors > 0) { |
|
759 | + $error = true; |
|
760 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
761 | + $message = sprintf( |
|
762 | + __( |
|
763 | + 'There were %d errors and %d messages successfully queued for generation and sending', |
|
764 | + 'event_espresso' |
|
765 | + ), |
|
766 | + $count_errors, |
|
767 | + $count_queued |
|
768 | + ); |
|
769 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
770 | + $message = sprintf( |
|
771 | + __( |
|
772 | + 'There were %d errors and %d message successfully queued for generation.', |
|
773 | + 'event_espresso' |
|
774 | + ), |
|
775 | + $count_errors, |
|
776 | + $count_queued |
|
777 | + ); |
|
778 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
779 | + $message = sprintf( |
|
780 | + __( |
|
781 | + 'There was %d error and %d messages successfully queued for generation.', |
|
782 | + 'event_espresso' |
|
783 | + ), |
|
784 | + $count_errors, |
|
785 | + $count_queued |
|
786 | + ); |
|
787 | + } else { |
|
788 | + $message = sprintf( |
|
789 | + __( |
|
790 | + 'There was %d message that failed to be queued for generation.', |
|
791 | + 'event_espresso' |
|
792 | + ), |
|
793 | + $count_errors |
|
794 | + ); |
|
795 | + } |
|
796 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
797 | + } else { |
|
798 | + if ($count_queued === 1) { |
|
799 | + $message = sprintf( |
|
800 | + __( |
|
801 | + '%d message successfully queued for generation.', |
|
802 | + 'event_espresso' |
|
803 | + ), |
|
804 | + $count_queued |
|
805 | + ); |
|
806 | + } else { |
|
807 | + $message = sprintf( |
|
808 | + __( |
|
809 | + '%d messages were successfully queued for generation.', |
|
810 | + 'event_espresso' |
|
811 | + ), |
|
812 | + $count_queued |
|
813 | + ); |
|
814 | + } |
|
815 | + EE_Error::add_success($message); |
|
816 | + } |
|
817 | + } |
|
818 | + // if no error then return the generated message(s). |
|
819 | + if (! $error && ! $send) { |
|
820 | + $generated_queue = $processor->generate_queue(false); |
|
821 | + // get message and return. |
|
822 | + $generated_queue->get_message_repository()->rewind(); |
|
823 | + $messages = array(); |
|
824 | + while ($generated_queue->get_message_repository()->valid()) { |
|
825 | + $message = $generated_queue->get_message_repository()->current(); |
|
826 | + if ($message instanceof EE_Message) { |
|
827 | + // set properties that might be expected by add-ons (backward compat) |
|
828 | + $message->content = $message->content(); |
|
829 | + $message->template_pack = $message->get_template_pack(); |
|
830 | + $message->template_variation = $message->get_template_pack_variation(); |
|
831 | + $messages[] = $message; |
|
832 | + } |
|
833 | + $generated_queue->get_message_repository()->next(); |
|
834 | + } |
|
835 | + return $messages; |
|
836 | + } |
|
837 | + return $error ? false |
|
838 | + : true; // yeah backwards eh? Really what we're returning is if there is a total success for all the messages or not. We'll modify this once we get message recording in place. |
|
839 | + } |
|
840 | + |
|
841 | + |
|
842 | + /** |
|
843 | + * @deprecated 4.9.0 |
|
844 | + * @param string $type This should correspond with a valid message type |
|
845 | + * @param string $context This should correspond with a valid context for the message type |
|
846 | + * @param string $messenger This should correspond with a valid messenger. |
|
847 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
848 | + * preview |
|
849 | + * @return string The body of the message. |
|
850 | + */ |
|
851 | + public function preview_message($type, $context, $messenger, $send = false) |
|
852 | + { |
|
853 | + // EE_messages has been deprecated |
|
854 | + $this->_class_is_deprecated(__FUNCTION__); |
|
855 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * @since 4.5.0 |
|
861 | + * @deprecated 4.9.0 Moved to EED_Messages Module |
|
862 | + * @param string $messenger a string matching a valid active messenger in the system |
|
863 | + * @param string $message_type Although it seems contrary to the name of the method, a message type name is still |
|
864 | + * required to send along the message type to the messenger because this is used for |
|
865 | + * determining what specific variations might be loaded for the generated message. |
|
866 | + * @param stdClass $message a stdClass object in the format expected by the messenger. |
|
867 | + * |
|
868 | + * @return bool success or fail. |
|
869 | + */ |
|
870 | + public function send_message_with_messenger_only($messenger, $message_type, $message) |
|
871 | + { |
|
872 | + // EE_messages has been deprecated |
|
873 | + $this->_class_is_deprecated(__FUNCTION__); |
|
874 | + // setup for sending to new method. |
|
875 | + /** @type EE_Messages_Queue $queue */ |
|
876 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
877 | + // make sure we have a proper message object |
|
878 | + if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
879 | + $msg = EE_Message_Factory::create( |
|
880 | + array( |
|
881 | + 'MSG_messenger' => $messenger, |
|
882 | + 'MSG_message_type' => $message_type, |
|
883 | + 'MSG_content' => $message->content, |
|
884 | + 'MSG_subject' => $message->subject, |
|
885 | + ) |
|
886 | + ); |
|
887 | + } else { |
|
888 | + $msg = $message; |
|
889 | + } |
|
890 | + if (! $msg instanceof EE_Message) { |
|
891 | + return false; |
|
892 | + } |
|
893 | + // make sure any content in a content property (if not empty) is set on the MSG_content. |
|
894 | + if (! empty($msg->content)) { |
|
895 | + $msg->set('MSG_content', $msg->content); |
|
896 | + } |
|
897 | + $queue->add($msg); |
|
898 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * @deprecated 4.9.0 |
|
904 | + * @param $messenger |
|
905 | + * @param string $message_type message type that the templates are being created for |
|
906 | + * @param int $GRP_ID |
|
907 | + * @param bool $is_global |
|
908 | + * @return array|object if creation is successful then we return an array of info, otherwise an error_object is |
|
909 | + * returned. |
|
910 | + * @throws \EE_Error |
|
911 | + */ |
|
912 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) |
|
913 | + { |
|
914 | + // EE_messages has been deprecated |
|
915 | + $this->_class_is_deprecated(__FUNCTION__); |
|
916 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
917 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * @deprecated 4.9.0 |
|
923 | + * @param string $messenger_name name of EE_messenger |
|
924 | + * @param string $message_type_name name of EE_message_type |
|
925 | + * @return array |
|
926 | + */ |
|
927 | + public function get_fields($messenger_name, $message_type_name) |
|
928 | + { |
|
929 | + // EE_messages has been deprecated |
|
930 | + $this->_class_is_deprecated(__FUNCTION__); |
|
931 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
932 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * @deprecated 4.9.0 |
|
938 | + * @access public |
|
939 | + * @param string $type we can indicate just returning installed message types |
|
940 | + * or messengers (or both) via this parameter. |
|
941 | + * @param bool $skip_cache if true then we skip the cache and retrieve via files. |
|
942 | + * @return array multidimensional array of messenger and message_type objects |
|
943 | + * (messengers index, and message_type index); |
|
944 | + */ |
|
945 | + public function get_installed($type = 'all', $skip_cache = false) |
|
946 | + { |
|
947 | + // EE_messages has been deprecated |
|
948 | + $this->_class_is_deprecated(__FUNCTION__); |
|
949 | + if ($skip_cache) { |
|
950 | + $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
|
951 | + } |
|
952 | + switch ($type) { |
|
953 | + case 'messengers' : |
|
954 | + return array( |
|
955 | + 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
956 | + ); |
|
957 | + break; |
|
958 | + case 'message_types' : |
|
959 | + return array( |
|
960 | + 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
961 | + ); |
|
962 | + break; |
|
963 | + case 'all' : |
|
964 | + default : |
|
965 | + return array( |
|
966 | + 'messenger' => $this->_message_resource_manager->installed_messengers(), |
|
967 | + 'message_type' => $this->_message_resource_manager->installed_message_types(), |
|
968 | + ); |
|
969 | + break; |
|
970 | + } |
|
971 | + } |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * @deprecated 4.9.0 |
|
976 | + * @return \EE_messenger[] |
|
977 | + */ |
|
978 | + public function get_active_messengers() |
|
979 | + { |
|
980 | + // EE_messages has been deprecated |
|
981 | + $this->_class_is_deprecated(__FUNCTION__); |
|
982 | + return $this->_message_resource_manager->active_messengers(); |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + /** |
|
987 | + * @deprecated 4.9.0 |
|
988 | + * @return array array of message_type references (string) |
|
989 | + */ |
|
990 | + public function get_active_message_types() |
|
991 | + { |
|
992 | + // EE_messages has been deprecated |
|
993 | + $this->_class_is_deprecated(__FUNCTION__); |
|
994 | + return $this->_message_resource_manager->list_of_active_message_types(); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * @deprecated 4.9.0 |
|
1000 | + * @return EE_message_type[] |
|
1001 | + */ |
|
1002 | + public function get_active_message_type_objects() |
|
1003 | + { |
|
1004 | + // EE_messages has been deprecated |
|
1005 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1006 | + return $this->_message_resource_manager->get_active_message_type_objects(); |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * @deprecated 4.9.0 |
|
1012 | + * @since 4.5.0 |
|
1013 | + * @param string $messenger The messenger being checked |
|
1014 | + * @return EE_message_type[] (or empty array if none present) |
|
1015 | + */ |
|
1016 | + public function get_active_message_types_per_messenger($messenger) |
|
1017 | + { |
|
1018 | + // EE_messages has been deprecated |
|
1019 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1020 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * @deprecated 4.9.0 |
|
1026 | + * @param string $messenger The string should correspond to the messenger (message types are |
|
1027 | + * @param string $message_type The string should correspond to a message type. |
|
1028 | + * @return EE_message_type|null |
|
1029 | + */ |
|
1030 | + public function get_active_message_type($messenger, $message_type) |
|
1031 | + { |
|
1032 | + // EE_messages has been deprecated |
|
1033 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1034 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * @deprecated 4.9.0 |
|
1040 | + * @return array|\EE_message_type[] |
|
1041 | + */ |
|
1042 | + public function get_installed_message_types() |
|
1043 | + { |
|
1044 | + // EE_messages has been deprecated |
|
1045 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1046 | + return $this->_message_resource_manager->installed_message_types(); |
|
1047 | + } |
|
1048 | + |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * @deprecated 4.9.0 |
|
1052 | + * @return array |
|
1053 | + */ |
|
1054 | + public function get_installed_messengers() |
|
1055 | + { |
|
1056 | + // EE_messages has been deprecated |
|
1057 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1058 | + return $this->_message_resource_manager->installed_messengers(); |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * @deprecated 4.9.0 |
|
1064 | + * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by |
|
1065 | + * message type. |
|
1066 | + * @return array |
|
1067 | + */ |
|
1068 | + public function get_all_contexts($slugs_only = true) |
|
1069 | + { |
|
1070 | + // EE_messages has been deprecated |
|
1071 | + $this->_class_is_deprecated(__FUNCTION__); |
|
1072 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
1073 | + } |
|
1074 | 1074 | |
1075 | 1075 | |
1076 | 1076 | } |
@@ -1129,88 +1129,88 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | |
1131 | 1131 | add_filter( |
1132 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1133 | - function ($event_list_iframe_css) { |
|
1134 | - if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1135 | - return $event_list_iframe_css; |
|
1136 | - } |
|
1137 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1138 | - 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1139 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1140 | - '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1141 | - '4.9.14', |
|
1142 | - '5.0.0', |
|
1143 | - 'filter' |
|
1144 | - ); |
|
1145 | - return apply_filters( |
|
1146 | - 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1147 | - $event_list_iframe_css |
|
1148 | - ); |
|
1149 | - } |
|
1132 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1133 | + function ($event_list_iframe_css) { |
|
1134 | + if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1135 | + return $event_list_iframe_css; |
|
1136 | + } |
|
1137 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1138 | + 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1139 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
1140 | + '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1141 | + '4.9.14', |
|
1142 | + '5.0.0', |
|
1143 | + 'filter' |
|
1144 | + ); |
|
1145 | + return apply_filters( |
|
1146 | + 'FHEE__EventsArchiveIframe__event_list_iframe__css', |
|
1147 | + $event_list_iframe_css |
|
1148 | + ); |
|
1149 | + } |
|
1150 | 1150 | ); |
1151 | 1151 | add_filter( |
1152 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1153 | - function ($event_list_iframe_js) { |
|
1154 | - if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1155 | - return $event_list_iframe_js; |
|
1156 | - } |
|
1157 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1158 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1159 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1160 | - '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1161 | - '4.9.14', |
|
1162 | - '5.0.0', |
|
1163 | - 'filter' |
|
1164 | - ); |
|
1165 | - return apply_filters( |
|
1166 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1167 | - $event_list_iframe_js |
|
1168 | - ); |
|
1169 | - } |
|
1152 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1153 | + function ($event_list_iframe_js) { |
|
1154 | + if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1155 | + return $event_list_iframe_js; |
|
1156 | + } |
|
1157 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1158 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1159 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
1160 | + '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()', |
|
1161 | + '4.9.14', |
|
1162 | + '5.0.0', |
|
1163 | + 'filter' |
|
1164 | + ); |
|
1165 | + return apply_filters( |
|
1166 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
1167 | + $event_list_iframe_js |
|
1168 | + ); |
|
1169 | + } |
|
1170 | 1170 | ); |
1171 | 1171 | add_action( |
1172 | - 'AHEE__EE_Capabilities__addCaps__complete', |
|
1173 | - function ($capabilities_map) { |
|
1174 | - if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1175 | - return; |
|
1176 | - } |
|
1177 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1178 | - 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1179 | - 'AHEE__EE_Capabilities__addCaps__complete', |
|
1180 | - '\EE_Capabilities::addCaps()', |
|
1181 | - '4.9.42', |
|
1182 | - '5.0.0' |
|
1183 | - ); |
|
1184 | - do_action( |
|
1185 | - 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1186 | - $capabilities_map |
|
1187 | - ); |
|
1188 | - } |
|
1172 | + 'AHEE__EE_Capabilities__addCaps__complete', |
|
1173 | + function ($capabilities_map) { |
|
1174 | + if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1175 | + return; |
|
1176 | + } |
|
1177 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1178 | + 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1179 | + 'AHEE__EE_Capabilities__addCaps__complete', |
|
1180 | + '\EE_Capabilities::addCaps()', |
|
1181 | + '4.9.42', |
|
1182 | + '5.0.0' |
|
1183 | + ); |
|
1184 | + do_action( |
|
1185 | + 'AHEE__EE_Capabilities__init_role_caps__complete', |
|
1186 | + $capabilities_map |
|
1187 | + ); |
|
1188 | + } |
|
1189 | 1189 | ); |
1190 | 1190 | |
1191 | 1191 | add_filter( |
1192 | - 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1193 | - function ($existing_attendee, $registration, $attendee_data) { |
|
1194 | - if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1195 | - return $existing_attendee; |
|
1196 | - } |
|
1197 | - deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1198 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1199 | - 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1200 | - '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()', |
|
1201 | - '4.9.34', |
|
1202 | - '5.0.0', |
|
1203 | - 'filter' |
|
1204 | - ); |
|
1205 | - return apply_filters( |
|
1206 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1207 | - $existing_attendee, |
|
1208 | - $registration, |
|
1209 | - $attendee_data |
|
1210 | - ); |
|
1211 | - }, |
|
1212 | - 10, |
|
1213 | - 3 |
|
1192 | + 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1193 | + function ($existing_attendee, $registration, $attendee_data) { |
|
1194 | + if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1195 | + return $existing_attendee; |
|
1196 | + } |
|
1197 | + deprecated_espresso_action_or_filter_doing_it_wrong( |
|
1198 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1199 | + 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
|
1200 | + '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()', |
|
1201 | + '4.9.34', |
|
1202 | + '5.0.0', |
|
1203 | + 'filter' |
|
1204 | + ); |
|
1205 | + return apply_filters( |
|
1206 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1207 | + $existing_attendee, |
|
1208 | + $registration, |
|
1209 | + $attendee_data |
|
1210 | + ); |
|
1211 | + }, |
|
1212 | + 10, |
|
1213 | + 3 |
|
1214 | 1214 | ); |
1215 | 1215 | |
1216 | 1216 | /** |
@@ -1221,88 +1221,88 @@ discard block |
||
1221 | 1221 | class EE_Event_List_Query extends WP_Query |
1222 | 1222 | { |
1223 | 1223 | |
1224 | - private $title; |
|
1225 | - |
|
1226 | - private $css_class; |
|
1227 | - |
|
1228 | - private $category_slug; |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * EE_Event_List_Query constructor. |
|
1232 | - * |
|
1233 | - * @param array $args |
|
1234 | - */ |
|
1235 | - public function __construct($args = array()) |
|
1236 | - { |
|
1237 | - \EE_Error::doing_it_wrong( |
|
1238 | - __METHOD__, |
|
1239 | - __( |
|
1240 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1241 | - 'event_espresso' |
|
1242 | - ), |
|
1243 | - '4.9.27', |
|
1244 | - '5.0.0' |
|
1245 | - ); |
|
1246 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1247 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1248 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1249 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1250 | - // the current "page" we are viewing |
|
1251 | - $paged = max(1, get_query_var('paged')); |
|
1252 | - // Force these args |
|
1253 | - $args = array_merge( |
|
1254 | - $args, |
|
1255 | - array( |
|
1256 | - 'post_type' => 'espresso_events', |
|
1257 | - 'posts_per_page' => $limit, |
|
1258 | - 'update_post_term_cache' => false, |
|
1259 | - 'update_post_meta_cache' => false, |
|
1260 | - 'paged' => $paged, |
|
1261 | - 'offset' => ($paged - 1) * $limit, |
|
1262 | - ) |
|
1263 | - ); |
|
1264 | - // run the query |
|
1265 | - parent::__construct($args); |
|
1266 | - } |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * event_list_title |
|
1271 | - * |
|
1272 | - * @param string $event_list_title |
|
1273 | - * @return string |
|
1274 | - */ |
|
1275 | - public function event_list_title($event_list_title = '') |
|
1276 | - { |
|
1277 | - if (! empty($this->title)) { |
|
1278 | - return $this->title; |
|
1279 | - } |
|
1280 | - return $event_list_title; |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * event_list_css |
|
1286 | - * |
|
1287 | - * @param string $event_list_css |
|
1288 | - * @return string |
|
1289 | - */ |
|
1290 | - public function event_list_css($event_list_css = '') |
|
1291 | - { |
|
1292 | - $event_list_css .= ! empty($event_list_css) |
|
1293 | - ? ' ' |
|
1294 | - : ''; |
|
1295 | - $event_list_css .= ! empty($this->css_class) |
|
1296 | - ? $this->css_class |
|
1297 | - : ''; |
|
1298 | - $event_list_css .= ! empty($event_list_css) |
|
1299 | - ? ' ' |
|
1300 | - : ''; |
|
1301 | - $event_list_css .= ! empty($this->category_slug) |
|
1302 | - ? $this->category_slug |
|
1303 | - : ''; |
|
1304 | - return $event_list_css; |
|
1305 | - } |
|
1224 | + private $title; |
|
1225 | + |
|
1226 | + private $css_class; |
|
1227 | + |
|
1228 | + private $category_slug; |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * EE_Event_List_Query constructor. |
|
1232 | + * |
|
1233 | + * @param array $args |
|
1234 | + */ |
|
1235 | + public function __construct($args = array()) |
|
1236 | + { |
|
1237 | + \EE_Error::doing_it_wrong( |
|
1238 | + __METHOD__, |
|
1239 | + __( |
|
1240 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1241 | + 'event_espresso' |
|
1242 | + ), |
|
1243 | + '4.9.27', |
|
1244 | + '5.0.0' |
|
1245 | + ); |
|
1246 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1247 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1248 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1249 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1250 | + // the current "page" we are viewing |
|
1251 | + $paged = max(1, get_query_var('paged')); |
|
1252 | + // Force these args |
|
1253 | + $args = array_merge( |
|
1254 | + $args, |
|
1255 | + array( |
|
1256 | + 'post_type' => 'espresso_events', |
|
1257 | + 'posts_per_page' => $limit, |
|
1258 | + 'update_post_term_cache' => false, |
|
1259 | + 'update_post_meta_cache' => false, |
|
1260 | + 'paged' => $paged, |
|
1261 | + 'offset' => ($paged - 1) * $limit, |
|
1262 | + ) |
|
1263 | + ); |
|
1264 | + // run the query |
|
1265 | + parent::__construct($args); |
|
1266 | + } |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * event_list_title |
|
1271 | + * |
|
1272 | + * @param string $event_list_title |
|
1273 | + * @return string |
|
1274 | + */ |
|
1275 | + public function event_list_title($event_list_title = '') |
|
1276 | + { |
|
1277 | + if (! empty($this->title)) { |
|
1278 | + return $this->title; |
|
1279 | + } |
|
1280 | + return $event_list_title; |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * event_list_css |
|
1286 | + * |
|
1287 | + * @param string $event_list_css |
|
1288 | + * @return string |
|
1289 | + */ |
|
1290 | + public function event_list_css($event_list_css = '') |
|
1291 | + { |
|
1292 | + $event_list_css .= ! empty($event_list_css) |
|
1293 | + ? ' ' |
|
1294 | + : ''; |
|
1295 | + $event_list_css .= ! empty($this->css_class) |
|
1296 | + ? $this->css_class |
|
1297 | + : ''; |
|
1298 | + $event_list_css .= ! empty($event_list_css) |
|
1299 | + ? ' ' |
|
1300 | + : ''; |
|
1301 | + $event_list_css .= ! empty($this->category_slug) |
|
1302 | + ? $this->category_slug |
|
1303 | + : ''; |
|
1304 | + return $event_list_css; |
|
1305 | + } |
|
1306 | 1306 | |
1307 | 1307 | } |
1308 | 1308 | |
@@ -1319,66 +1319,66 @@ discard block |
||
1319 | 1319 | { |
1320 | 1320 | |
1321 | 1321 | |
1322 | - /** |
|
1323 | - * class constructor |
|
1324 | - * |
|
1325 | - * @deprecated 4.9.59.p |
|
1326 | - */ |
|
1327 | - public function __construct() |
|
1328 | - { |
|
1329 | - EE_Error::doing_it_wrong( |
|
1330 | - __METHOD__, |
|
1331 | - sprintf( |
|
1332 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1333 | - __CLASS__, |
|
1334 | - 'EventEspresso\core\services\licensing\LicenseServices' |
|
1335 | - ), |
|
1336 | - '4.9.59.p' |
|
1337 | - ); |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * The purpose of this function is to display information about Event Espresso data collection |
|
1343 | - * and a optin selection for extra data collecting by users. |
|
1344 | - * |
|
1345 | - * @param bool $extra |
|
1346 | - * @return string html. |
|
1347 | - * @deprecated 4.9.59.p |
|
1348 | - */ |
|
1349 | - public static function espresso_data_collection_optin_text($extra = true) |
|
1350 | - { |
|
1351 | - EE_Error::doing_it_wrong( |
|
1352 | - __METHOD__, |
|
1353 | - sprintf( |
|
1354 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1355 | - __METHOD__, |
|
1356 | - 'EventEspresso\core\domain\services\Stats::optinText' |
|
1357 | - ), |
|
1358 | - '4.9.59.p' |
|
1359 | - ); |
|
1360 | - Stats::optinText($extra); |
|
1361 | - } |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
1365 | - * |
|
1366 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
1367 | - * identify plugins. Defaults to core update |
|
1368 | - * @return boolean True if update available, false if not. |
|
1369 | - * @deprecated 4.9.59.p |
|
1370 | - */ |
|
1371 | - public static function is_update_available($basename = '') |
|
1372 | - { |
|
1373 | - EE_Error::doing_it_wrong( |
|
1374 | - __METHOD__, |
|
1375 | - sprintf( |
|
1376 | - esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1377 | - __METHOD__, |
|
1378 | - 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
1379 | - ), |
|
1380 | - '4.9.59.p' |
|
1381 | - ); |
|
1382 | - return LicenseService::isUpdateAvailable($basename); |
|
1383 | - } |
|
1322 | + /** |
|
1323 | + * class constructor |
|
1324 | + * |
|
1325 | + * @deprecated 4.9.59.p |
|
1326 | + */ |
|
1327 | + public function __construct() |
|
1328 | + { |
|
1329 | + EE_Error::doing_it_wrong( |
|
1330 | + __METHOD__, |
|
1331 | + sprintf( |
|
1332 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1333 | + __CLASS__, |
|
1334 | + 'EventEspresso\core\services\licensing\LicenseServices' |
|
1335 | + ), |
|
1336 | + '4.9.59.p' |
|
1337 | + ); |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * The purpose of this function is to display information about Event Espresso data collection |
|
1343 | + * and a optin selection for extra data collecting by users. |
|
1344 | + * |
|
1345 | + * @param bool $extra |
|
1346 | + * @return string html. |
|
1347 | + * @deprecated 4.9.59.p |
|
1348 | + */ |
|
1349 | + public static function espresso_data_collection_optin_text($extra = true) |
|
1350 | + { |
|
1351 | + EE_Error::doing_it_wrong( |
|
1352 | + __METHOD__, |
|
1353 | + sprintf( |
|
1354 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1355 | + __METHOD__, |
|
1356 | + 'EventEspresso\core\domain\services\Stats::optinText' |
|
1357 | + ), |
|
1358 | + '4.9.59.p' |
|
1359 | + ); |
|
1360 | + Stats::optinText($extra); |
|
1361 | + } |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
1365 | + * |
|
1366 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
1367 | + * identify plugins. Defaults to core update |
|
1368 | + * @return boolean True if update available, false if not. |
|
1369 | + * @deprecated 4.9.59.p |
|
1370 | + */ |
|
1371 | + public static function is_update_available($basename = '') |
|
1372 | + { |
|
1373 | + EE_Error::doing_it_wrong( |
|
1374 | + __METHOD__, |
|
1375 | + sprintf( |
|
1376 | + esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'), |
|
1377 | + __METHOD__, |
|
1378 | + 'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable' |
|
1379 | + ), |
|
1380 | + '4.9.59.p' |
|
1381 | + ); |
|
1382 | + return LicenseService::isUpdateAvailable($basename); |
|
1383 | + } |
|
1384 | 1384 | } |
1385 | 1385 | \ No newline at end of file |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.001'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.001'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |