Completed
Branch BUG-10202-persistent-admin-not... (421dfc)
by
unknown
21:29 queued 10:59
created
core/EE_Payment_Processor.core.php 1 patch
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\ResettableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,748 +17,748 @@  discard block
 block discarded – undo
17 17
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Payment_Processor $_instance
22
-     * @access    private
23
-     */
24
-    private static $_instance;
25
-
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
-    /**
45
-     * @return EE_Payment_Processor
46
-     */
47
-    public static function reset()
48
-    {
49
-        self::$_instance = null;
50
-        return self::instance();
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     *private constructor to prevent direct creation
57
-     *
58
-     * @Constructor
59
-     * @access private
60
-     */
61
-    private function __construct()
62
-    {
63
-        do_action('AHEE__EE_Payment_Processor__construct');
64
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
71
-     * appropriately. Saves the payment that is generated
72
-     *
73
-     * @param EE_Payment_Method    $payment_method
74
-     * @param EE_Transaction       $transaction
75
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
76
-     *                                           Leave null if payment is for the full amount owing
77
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
78
-     *                                           Receive_form_submission() should have
79
-     *                                           already been called on the billing form
80
-     *                                           (ie, its inputs should have their normalized values set).
81
-     * @param string               $return_url   string used mostly by offsite gateways to specify
82
-     *                                           where to go AFTER the offsite gateway
83
-     * @param string               $method       like 'CART', indicates who the client who called this was
84
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
85
-     * @param boolean              $update_txn   whether or not to call
86
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
87
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
88
-     * @return \EE_Payment
89
-     * @throws \EE_Error
90
-     */
91
-    public function process_payment(
92
-        EE_Payment_Method $payment_method,
93
-        EE_Transaction $transaction,
94
-        $amount = null,
95
-        $billing_form = null,
96
-        $return_url = null,
97
-        $method = 'CART',
98
-        $by_admin = false,
99
-        $update_txn = true,
100
-        $cancel_url = ''
101
-    ) {
102
-        if ((float)$amount < 0) {
103
-            throw new EE_Error(
104
-                sprintf(
105
-                    __(
106
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
107
-                        'event_espresso'
108
-                    ),
109
-                    $amount,
110
-                    $transaction->ID()
111
-                )
112
-            );
113
-        }
114
-        // verify payment method
115
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
116
-        // verify transaction
117
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
118
-        $transaction->set_payment_method_ID($payment_method->ID());
119
-        // verify payment method type
120
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
121
-            $payment = $payment_method->type_obj()->process_payment(
122
-                $transaction,
123
-                min($amount, $transaction->remaining()),//make sure we don't overcharge
124
-                $billing_form,
125
-                $return_url,
126
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
127
-                $method,
128
-                $by_admin
129
-            );
130
-            // check if payment method uses an off-site gateway
131
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
132
-                // don't process payments for off-site gateways yet because no payment has occurred yet
133
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
134
-            }
135
-            return $payment;
136
-        } else {
137
-            EE_Error::add_error(
138
-                sprintf(
139
-                    __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
140
-                    '<br/>',
141
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
142
-                ), __FILE__, __FUNCTION__, __LINE__
143
-            );
144
-            return null;
145
-        }
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param EE_Transaction|int $transaction
152
-     * @param EE_Payment_Method  $payment_method
153
-     * @throws EE_Error
154
-     * @return string
155
-     */
156
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
157
-    {
158
-        /** @type \EE_Transaction $transaction */
159
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
160
-        $primary_reg = $transaction->primary_registration();
161
-        if ( ! $primary_reg instanceof EE_Registration) {
162
-            throw new EE_Error(
163
-                sprintf(
164
-                    __(
165
-                        "Cannot get IPN URL for transaction with ID %d because it has no primary registration",
166
-                        "event_espresso"
167
-                    ),
168
-                    $transaction->ID()
169
-                )
170
-            );
171
-        }
172
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
173
-        $url = add_query_arg(
174
-            array(
175
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
176
-                'ee_payment_method' => $payment_method->slug(),
177
-            ),
178
-            EE_Registry::instance()->CFG->core->txn_page_url()
179
-        );
180
-        return $url;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
187
-     * we can easily find what registration the IPN is for and what payment method.
188
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
189
-     * If a payment is found for the IPN info, it is saved.
190
-     *
191
-     * @param array              $_req_data            eg $_REQUEST
192
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
193
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
194
-     * @param boolean            $update_txn           whether or not to call
195
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
196
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
197
-     *                                                 or is processed manually ( false like Mijireh )
198
-     * @throws EE_Error
199
-     * @throws Exception
200
-     * @return EE_Payment
201
-     */
202
-    public function process_ipn(
203
-        $_req_data,
204
-        $transaction = null,
205
-        $payment_method = null,
206
-        $update_txn = true,
207
-        $separate_IPN_request = true
208
-    ) {
209
-        EE_Registry::instance()->load_model('Change_Log');
210
-        $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
211
-        EE_Processor_Base::set_IPN($separate_IPN_request);
212
-        $obj_for_log = null;
213
-        if ($transaction instanceof EE_Transaction) {
214
-            $obj_for_log = $transaction;
215
-            if ($payment_method instanceof EE_Payment_Method) {
216
-                $obj_for_log = EEM_Payment::instance()->get_one(
217
-                    array(
218
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
219
-                        'order_by' => array('PAY_timestamp' => 'desc'),
220
-                    )
221
-                );
222
-            }
223
-        } else if ($payment_method instanceof EE_Payment) {
224
-            $obj_for_log = $payment_method;
225
-        }
226
-        $log = EEM_Change_Log::instance()->log(
227
-            EEM_Change_Log::type_gateway,
228
-            array('IPN data received' => $_req_data),
229
-            $obj_for_log
230
-        );
231
-        try {
232
-            /**
233
-             * @var EE_Payment $payment
234
-             */
235
-            $payment = null;
236
-            if ($transaction && $payment_method) {
237
-                /** @type EE_Transaction $transaction */
238
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
239
-                /** @type EE_Payment_Method $payment_method */
240
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
241
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
242
-                    try {
243
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
244
-                        $log->set_object($payment);
245
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
246
-                        EEM_Change_Log::instance()->log(
247
-                            EEM_Change_Log::type_gateway,
248
-                            array(
249
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
250
-                                'current_url' => EEH_URL::current_url(),
251
-                                'payment'     => $e->getPaymentProperties(),
252
-                                'IPN_data'    => $e->getIpnData(),
253
-                            ),
254
-                            $obj_for_log
255
-                        );
256
-                        return $e->getPayment();
257
-                    }
258
-                } else {
259
-                    // not a payment
260
-                    EE_Error::add_error(
261
-                        sprintf(
262
-                            __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
263
-                            '<br/>',
264
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
265
-                        ),
266
-                        __FILE__, __FUNCTION__, __LINE__
267
-                    );
268
-                }
269
-            } else {
270
-                //that's actually pretty ok. The IPN just wasn't able
271
-                //to identify which transaction or payment method this was for
272
-                // give all active payment methods a chance to claim it
273
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
274
-                foreach ($active_payment_methods as $active_payment_method) {
275
-                    try {
276
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
277
-                        $payment_method = $active_payment_method;
278
-                        EEM_Change_Log::instance()->log(
279
-                            EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
280
-                        );
281
-                        break;
282
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
283
-                        EEM_Change_Log::instance()->log(
284
-                            EEM_Change_Log::type_gateway,
285
-                            array(
286
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
287
-                                'current_url' => EEH_URL::current_url(),
288
-                                'payment'     => $e->getPaymentProperties(),
289
-                                'IPN_data'    => $e->getIpnData(),
290
-                            ),
291
-                            $obj_for_log
292
-                        );
293
-                        return $e->getPayment();
294
-                    } catch (EE_Error $e) {
295
-                        //that's fine- it apparently couldn't handle the IPN
296
-                    }
297
-                }
298
-            }
299
-            // 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
300
-            if ($payment instanceof EE_Payment) {
301
-                $payment->save();
302
-                //  update the TXN
303
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
304
-            } else {
305
-                //we couldn't find the payment for this IPN... let's try and log at least SOMETHING
306
-                if ($payment_method) {
307
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
308
-                } elseif ($transaction) {
309
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
310
-                }
311
-            }
312
-            return $payment;
313
-        } catch (EE_Error $e) {
314
-            do_action(
315
-                'AHEE__log', __FILE__, __FUNCTION__, sprintf(
316
-                    __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
317
-                    print_r($transaction, true),
318
-                    print_r($_req_data, true),
319
-                    $e->getMessage()
320
-                )
321
-            );
322
-            throw $e;
323
-        }
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * Removes any non-printable illegal characters from the input,
330
-     * which might cause a raucous when trying to insert into the database
331
-     *
332
-     * @param  array $request_data
333
-     * @return array
334
-     */
335
-    protected function _remove_unusable_characters_from_array(array $request_data)
336
-    {
337
-        $return_data = array();
338
-        foreach ($request_data as $key => $value) {
339
-            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
340
-        }
341
-        return $return_data;
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * Removes any non-printable illegal characters from the input,
348
-     * which might cause a raucous when trying to insert into the database
349
-     *
350
-     * @param string $request_data
351
-     * @return string
352
-     */
353
-    protected function _remove_unusable_characters($request_data)
354
-    {
355
-        return preg_replace('/[^[:print:]]/', '', $request_data);
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * Should be called just before displaying the payment attempt results to the user,
362
-     * when the payment attempt has finished. Some payment methods may have special
363
-     * logic to perform here. For example, if process_payment() happens on a special request
364
-     * and then the user is redirected to a page that displays the payment's status, this
365
-     * should be called while loading the page that displays the payment's status. If the user is
366
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
367
-     * provider.
368
-     *
369
-     * @param EE_Transaction|int $transaction
370
-     * @param bool               $update_txn whether or not to call
371
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
372
-     * @throws \EE_Error
373
-     * @return EE_Payment
374
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
375
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
376
-     */
377
-    public function finalize_payment_for($transaction, $update_txn = true)
378
-    {
379
-        /** @var $transaction EE_Transaction */
380
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
381
-        $last_payment_method = $transaction->payment_method();
382
-        if ($last_payment_method instanceof EE_Payment_Method) {
383
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
384
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
385
-            return $payment;
386
-        } else {
387
-            return null;
388
-        }
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
395
-     *
396
-     * @param EE_Payment_Method $payment_method
397
-     * @param EE_Payment        $payment_to_refund
398
-     * @param array             $refund_info
399
-     * @return EE_Payment
400
-     * @throws \EE_Error
401
-     */
402
-    public function process_refund(
403
-        EE_Payment_Method $payment_method,
404
-        EE_Payment $payment_to_refund,
405
-        $refund_info = array()
406
-    ) {
407
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
408
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
409
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
410
-        }
411
-        return $payment_to_refund;
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * This should be called each time there may have been an update to a
418
-     * payment on a transaction (ie, we asked for a payment to process a
419
-     * payment for a transaction, or we told a payment method about an IPN, or
420
-     * we told a payment method to
421
-     * "finalize_payment_for" (a transaction), or we told a payment method to
422
-     * process a refund. This should handle firing the correct hooks to
423
-     * indicate
424
-     * what exactly happened and updating the transaction appropriately). This
425
-     * could be integrated directly into EE_Transaction upon save, but we want
426
-     * this logic to be separate from 'normal' plain-jane saving and updating
427
-     * of transactions and payments, and to be tied to payment processing.
428
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
429
-     * of previous code to decide whether or not to save (because the payment passed into
430
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
431
-     * in which case we only want that payment object for some temporary usage during this request,
432
-     * but we don't want it to be saved).
433
-     *
434
-     * @param EE_Transaction|int $transaction
435
-     * @param EE_Payment         $payment
436
-     * @param boolean            $update_txn
437
-     *                        whether or not to call
438
-     *                        EE_Transaction_Processor::
439
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
440
-     *                        (you can save 1 DB query if you know you're going
441
-     *                        to save it later instead)
442
-     * @param bool               $IPN
443
-     *                        if processing IPNs or other similar payment
444
-     *                        related activities that occur in alternate
445
-     *                        requests than the main one that is processing the
446
-     *                        TXN, then set this to true to check whether the
447
-     *                        TXN is locked before updating
448
-     * @throws \EE_Error
449
-     */
450
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
451
-    {
452
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
453
-        /** @type EE_Transaction $transaction */
454
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
455
-        // can we freely update the TXN at this moment?
456
-        if ($IPN && $transaction->is_locked()) {
457
-            // don't update the transaction at this exact moment
458
-            // because the TXN is active in another request
459
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
460
-                time(),
461
-                $transaction->ID(),
462
-                $payment->ID()
463
-            );
464
-        } else {
465
-            // verify payment and that it has been saved
466
-            if ($payment instanceof EE_Payment && $payment->ID()) {
467
-                if (
468
-                    $payment->payment_method() instanceof EE_Payment_Method
469
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
470
-                ) {
471
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
472
-                    // update TXN registrations with payment info
473
-                    $this->process_registration_payments($transaction, $payment);
474
-                }
475
-                $do_action = $payment->just_approved()
476
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
477
-                    : $do_action;
478
-            } else {
479
-                // send out notifications
480
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
481
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
482
-            }
483
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
484
-                /** @type EE_Transaction_Payments $transaction_payments */
485
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
486
-                // set new value for total paid
487
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
488
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
489
-                if ($update_txn) {
490
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
491
-                }
492
-            }
493
-            // granular hook for others to use.
494
-            do_action($do_action, $transaction, $payment);
495
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
496
-            //global hook for others to use.
497
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
498
-        }
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * update registrations REG_paid field after successful payment and link registrations with payment
505
-     *
506
-     * @param EE_Transaction    $transaction
507
-     * @param EE_Payment        $payment
508
-     * @param EE_Registration[] $registrations
509
-     * @throws \EE_Error
510
-     */
511
-    public function process_registration_payments(
512
-        EE_Transaction $transaction,
513
-        EE_Payment $payment,
514
-        $registrations = array()
515
-    ) {
516
-        // only process if payment was successful
517
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
518
-            return;
519
-        }
520
-        //EEM_Registration::instance()->show_next_x_db_queries();
521
-        if (empty($registrations)) {
522
-            // find registrations with monies owing that can receive a payment
523
-            $registrations = $transaction->registrations(
524
-                array(
525
-                    array(
526
-                        // only these reg statuses can receive payments
527
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
528
-                        'REG_final_price'  => array('!=', 0),
529
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
530
-                    ),
531
-                )
532
-            );
533
-        }
534
-        // still nothing ??!??
535
-        if (empty($registrations)) {
536
-            return;
537
-        }
538
-        // todo: break out the following logic into a separate strategy class
539
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
540
-        // todo: which would apply payments using the capitalist "first come first paid" approach
541
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
542
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
543
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
544
-        $refund = $payment->is_a_refund();
545
-        // how much is available to apply to registrations?
546
-        $available_payment_amount = abs($payment->amount());
547
-        foreach ($registrations as $registration) {
548
-            if ($registration instanceof EE_Registration) {
549
-                // nothing left?
550
-                if ($available_payment_amount <= 0) {
551
-                    break;
552
-                }
553
-                if ($refund) {
554
-                    $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
555
-                } else {
556
-                    $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
557
-                }
558
-            }
559
-        }
560
-        if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
561
-            EE_Error::add_attention(
562
-                sprintf(
563
-                    __('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).',
564
-                        'event_espresso'),
565
-                    EEH_Template::format_currency($available_payment_amount),
566
-                    implode(', ', array_keys($registrations)),
567
-                    '<br/>',
568
-                    EEH_Template::format_currency($payment->amount())
569
-                ),
570
-                __FILE__, __FUNCTION__, __LINE__
571
-            );
572
-        }
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * update registration REG_paid field after successful payment and link registration with payment
579
-     *
580
-     * @param EE_Registration $registration
581
-     * @param EE_Payment      $payment
582
-     * @param float           $available_payment_amount
583
-     * @return float
584
-     * @throws \EE_Error
585
-     */
586
-    public function process_registration_payment(
587
-        EE_Registration $registration,
588
-        EE_Payment $payment,
589
-        $available_payment_amount = 0.00
590
-    ) {
591
-        $owing = $registration->final_price() - $registration->paid();
592
-        if ($owing > 0) {
593
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
594
-            $payment_amount = min($available_payment_amount, $owing);
595
-            // update $available_payment_amount
596
-            $available_payment_amount -= $payment_amount;
597
-            //calculate and set new REG_paid
598
-            $registration->set_paid($registration->paid() + $payment_amount);
599
-            // now save it
600
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
601
-        }
602
-        return $available_payment_amount;
603
-    }
604
-
605
-
606
-
607
-    /**
608
-     * update registration REG_paid field after successful payment and link registration with payment
609
-     *
610
-     * @param EE_Registration $registration
611
-     * @param EE_Payment      $payment
612
-     * @param float           $payment_amount
613
-     * @return void
614
-     * @throws \EE_Error
615
-     */
616
-    protected function _apply_registration_payment(
617
-        EE_Registration $registration,
618
-        EE_Payment $payment,
619
-        $payment_amount = 0.00
620
-    ) {
621
-        // find any existing reg payment records for this registration and payment
622
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
623
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
624
-        );
625
-        // if existing registration payment exists
626
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
627
-            // then update that record
628
-            $existing_reg_payment->set_amount($payment_amount);
629
-            $existing_reg_payment->save();
630
-        } else {
631
-            // or add new relation between registration and payment and set amount
632
-            $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
633
-            // make it stick
634
-            $registration->save();
635
-        }
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * update registration REG_paid field after refund and link registration with payment
642
-     *
643
-     * @param EE_Registration $registration
644
-     * @param EE_Payment      $payment
645
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
646
-     * @return float
647
-     * @throws \EE_Error
648
-     */
649
-    public function process_registration_refund(
650
-        EE_Registration $registration,
651
-        EE_Payment $payment,
652
-        $available_refund_amount = 0.00
653
-    ) {
654
-        //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
655
-        if ($registration->paid() > 0) {
656
-            // ensure $available_refund_amount is NOT negative
657
-            $available_refund_amount = (float)abs($available_refund_amount);
658
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
659
-            $refund_amount = min($available_refund_amount, (float)$registration->paid());
660
-            // update $available_payment_amount
661
-            $available_refund_amount -= $refund_amount;
662
-            //calculate and set new REG_paid
663
-            $registration->set_paid($registration->paid() - $refund_amount);
664
-            // convert payment amount back to a negative value for storage in the db
665
-            $refund_amount = (float)abs($refund_amount) * -1;
666
-            // now save it
667
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
668
-        }
669
-        return $available_refund_amount;
670
-    }
671
-
672
-
673
-
674
-    /**
675
-     * Process payments and transaction after payment process completed.
676
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
677
-     * if this request happens to be processing an IPN,
678
-     * then we will also set the Payment Options Reg Step to completed,
679
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
680
-     *
681
-     * @param EE_Transaction $transaction
682
-     * @param EE_Payment     $payment
683
-     * @param bool           $IPN
684
-     * @throws \EE_Error
685
-     */
686
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
687
-    {
688
-        /** @type EE_Transaction_Processor $transaction_processor */
689
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
690
-        // is the Payment Options Reg Step completed ?
691
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
692
-        // if the Payment Options Reg Step is completed...
693
-        $revisit = $payment_options_step_completed === true ? true : false;
694
-        // then this is kinda sorta a revisit with regards to payments at least
695
-        $transaction_processor->set_revisit($revisit);
696
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
697
-        if (
698
-            $IPN
699
-            && $payment_options_step_completed !== true
700
-            && ($payment->is_approved() || $payment->is_pending())
701
-        ) {
702
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
703
-                'payment_options'
704
-            );
705
-        }
706
-        // maybe update status, but don't save transaction just yet
707
-        $transaction->update_status_based_on_total_paid(false);
708
-        // check if 'finalize_registration' step has been completed...
709
-        $finalized = $transaction->reg_step_completed('finalize_registration');
710
-        //  if this is an IPN and the final step has not been initiated
711
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
712
-            // and if it hasn't already been set as being started...
713
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
714
-        }
715
-        $transaction->save();
716
-        // because the above will return false if the final step was not fully completed, we need to check again...
717
-        if ($IPN && $finalized !== false) {
718
-            // and if we are all good to go, then send out notifications
719
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
720
-            //ok, now process the transaction according to the payment
721
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
722
-        }
723
-        // DEBUG LOG
724
-        $payment_method = $payment->payment_method();
725
-        if ($payment_method instanceof EE_Payment_Method) {
726
-            $payment_method_type_obj = $payment_method->type_obj();
727
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
728
-                $gateway = $payment_method_type_obj->get_gateway();
729
-                if ($gateway instanceof EE_Gateway) {
730
-                    $gateway->log(
731
-                        array(
732
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
733
-                            'transaction'           => $transaction->model_field_array(),
734
-                            'finalized'             => $finalized,
735
-                            'IPN'                   => $IPN,
736
-                            'deliver_notifications' => has_filter(
737
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
738
-                            ),
739
-                        ),
740
-                        $payment
741
-                    );
742
-                }
743
-            }
744
-        }
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * Force posts to PayPal to use TLS v1.2. See:
751
-     * https://core.trac.wordpress.org/ticket/36320
752
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
753
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
754
-     * This will affect paypal standard, pro, express, and payflow.
755
-     */
756
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
757
-    {
758
-        if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
759
-            //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
760
-            //instead of the constant because it might not be defined
761
-            curl_setopt($handle, CURLOPT_SSLVERSION, 1);
762
-        }
763
-    }
20
+	/**
21
+	 * @var EE_Payment_Processor $_instance
22
+	 * @access    private
23
+	 */
24
+	private static $_instance;
25
+
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
+	/**
45
+	 * @return EE_Payment_Processor
46
+	 */
47
+	public static function reset()
48
+	{
49
+		self::$_instance = null;
50
+		return self::instance();
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 *private constructor to prevent direct creation
57
+	 *
58
+	 * @Constructor
59
+	 * @access private
60
+	 */
61
+	private function __construct()
62
+	{
63
+		do_action('AHEE__EE_Payment_Processor__construct');
64
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
71
+	 * appropriately. Saves the payment that is generated
72
+	 *
73
+	 * @param EE_Payment_Method    $payment_method
74
+	 * @param EE_Transaction       $transaction
75
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
76
+	 *                                           Leave null if payment is for the full amount owing
77
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
78
+	 *                                           Receive_form_submission() should have
79
+	 *                                           already been called on the billing form
80
+	 *                                           (ie, its inputs should have their normalized values set).
81
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
82
+	 *                                           where to go AFTER the offsite gateway
83
+	 * @param string               $method       like 'CART', indicates who the client who called this was
84
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
85
+	 * @param boolean              $update_txn   whether or not to call
86
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
87
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
88
+	 * @return \EE_Payment
89
+	 * @throws \EE_Error
90
+	 */
91
+	public function process_payment(
92
+		EE_Payment_Method $payment_method,
93
+		EE_Transaction $transaction,
94
+		$amount = null,
95
+		$billing_form = null,
96
+		$return_url = null,
97
+		$method = 'CART',
98
+		$by_admin = false,
99
+		$update_txn = true,
100
+		$cancel_url = ''
101
+	) {
102
+		if ((float)$amount < 0) {
103
+			throw new EE_Error(
104
+				sprintf(
105
+					__(
106
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
107
+						'event_espresso'
108
+					),
109
+					$amount,
110
+					$transaction->ID()
111
+				)
112
+			);
113
+		}
114
+		// verify payment method
115
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
116
+		// verify transaction
117
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
118
+		$transaction->set_payment_method_ID($payment_method->ID());
119
+		// verify payment method type
120
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
121
+			$payment = $payment_method->type_obj()->process_payment(
122
+				$transaction,
123
+				min($amount, $transaction->remaining()),//make sure we don't overcharge
124
+				$billing_form,
125
+				$return_url,
126
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
127
+				$method,
128
+				$by_admin
129
+			);
130
+			// check if payment method uses an off-site gateway
131
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
132
+				// don't process payments for off-site gateways yet because no payment has occurred yet
133
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
134
+			}
135
+			return $payment;
136
+		} else {
137
+			EE_Error::add_error(
138
+				sprintf(
139
+					__('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
140
+					'<br/>',
141
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
142
+				), __FILE__, __FUNCTION__, __LINE__
143
+			);
144
+			return null;
145
+		}
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param EE_Transaction|int $transaction
152
+	 * @param EE_Payment_Method  $payment_method
153
+	 * @throws EE_Error
154
+	 * @return string
155
+	 */
156
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
157
+	{
158
+		/** @type \EE_Transaction $transaction */
159
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
160
+		$primary_reg = $transaction->primary_registration();
161
+		if ( ! $primary_reg instanceof EE_Registration) {
162
+			throw new EE_Error(
163
+				sprintf(
164
+					__(
165
+						"Cannot get IPN URL for transaction with ID %d because it has no primary registration",
166
+						"event_espresso"
167
+					),
168
+					$transaction->ID()
169
+				)
170
+			);
171
+		}
172
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
173
+		$url = add_query_arg(
174
+			array(
175
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
176
+				'ee_payment_method' => $payment_method->slug(),
177
+			),
178
+			EE_Registry::instance()->CFG->core->txn_page_url()
179
+		);
180
+		return $url;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
187
+	 * we can easily find what registration the IPN is for and what payment method.
188
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
189
+	 * If a payment is found for the IPN info, it is saved.
190
+	 *
191
+	 * @param array              $_req_data            eg $_REQUEST
192
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
193
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
194
+	 * @param boolean            $update_txn           whether or not to call
195
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
196
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
197
+	 *                                                 or is processed manually ( false like Mijireh )
198
+	 * @throws EE_Error
199
+	 * @throws Exception
200
+	 * @return EE_Payment
201
+	 */
202
+	public function process_ipn(
203
+		$_req_data,
204
+		$transaction = null,
205
+		$payment_method = null,
206
+		$update_txn = true,
207
+		$separate_IPN_request = true
208
+	) {
209
+		EE_Registry::instance()->load_model('Change_Log');
210
+		$_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
211
+		EE_Processor_Base::set_IPN($separate_IPN_request);
212
+		$obj_for_log = null;
213
+		if ($transaction instanceof EE_Transaction) {
214
+			$obj_for_log = $transaction;
215
+			if ($payment_method instanceof EE_Payment_Method) {
216
+				$obj_for_log = EEM_Payment::instance()->get_one(
217
+					array(
218
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
219
+						'order_by' => array('PAY_timestamp' => 'desc'),
220
+					)
221
+				);
222
+			}
223
+		} else if ($payment_method instanceof EE_Payment) {
224
+			$obj_for_log = $payment_method;
225
+		}
226
+		$log = EEM_Change_Log::instance()->log(
227
+			EEM_Change_Log::type_gateway,
228
+			array('IPN data received' => $_req_data),
229
+			$obj_for_log
230
+		);
231
+		try {
232
+			/**
233
+			 * @var EE_Payment $payment
234
+			 */
235
+			$payment = null;
236
+			if ($transaction && $payment_method) {
237
+				/** @type EE_Transaction $transaction */
238
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
239
+				/** @type EE_Payment_Method $payment_method */
240
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
241
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
242
+					try {
243
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
244
+						$log->set_object($payment);
245
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
246
+						EEM_Change_Log::instance()->log(
247
+							EEM_Change_Log::type_gateway,
248
+							array(
249
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
250
+								'current_url' => EEH_URL::current_url(),
251
+								'payment'     => $e->getPaymentProperties(),
252
+								'IPN_data'    => $e->getIpnData(),
253
+							),
254
+							$obj_for_log
255
+						);
256
+						return $e->getPayment();
257
+					}
258
+				} else {
259
+					// not a payment
260
+					EE_Error::add_error(
261
+						sprintf(
262
+							__('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
263
+							'<br/>',
264
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
265
+						),
266
+						__FILE__, __FUNCTION__, __LINE__
267
+					);
268
+				}
269
+			} else {
270
+				//that's actually pretty ok. The IPN just wasn't able
271
+				//to identify which transaction or payment method this was for
272
+				// give all active payment methods a chance to claim it
273
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
274
+				foreach ($active_payment_methods as $active_payment_method) {
275
+					try {
276
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
277
+						$payment_method = $active_payment_method;
278
+						EEM_Change_Log::instance()->log(
279
+							EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
280
+						);
281
+						break;
282
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
283
+						EEM_Change_Log::instance()->log(
284
+							EEM_Change_Log::type_gateway,
285
+							array(
286
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
287
+								'current_url' => EEH_URL::current_url(),
288
+								'payment'     => $e->getPaymentProperties(),
289
+								'IPN_data'    => $e->getIpnData(),
290
+							),
291
+							$obj_for_log
292
+						);
293
+						return $e->getPayment();
294
+					} catch (EE_Error $e) {
295
+						//that's fine- it apparently couldn't handle the IPN
296
+					}
297
+				}
298
+			}
299
+			// 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
300
+			if ($payment instanceof EE_Payment) {
301
+				$payment->save();
302
+				//  update the TXN
303
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
304
+			} else {
305
+				//we couldn't find the payment for this IPN... let's try and log at least SOMETHING
306
+				if ($payment_method) {
307
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
308
+				} elseif ($transaction) {
309
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
310
+				}
311
+			}
312
+			return $payment;
313
+		} catch (EE_Error $e) {
314
+			do_action(
315
+				'AHEE__log', __FILE__, __FUNCTION__, sprintf(
316
+					__('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
317
+					print_r($transaction, true),
318
+					print_r($_req_data, true),
319
+					$e->getMessage()
320
+				)
321
+			);
322
+			throw $e;
323
+		}
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * Removes any non-printable illegal characters from the input,
330
+	 * which might cause a raucous when trying to insert into the database
331
+	 *
332
+	 * @param  array $request_data
333
+	 * @return array
334
+	 */
335
+	protected function _remove_unusable_characters_from_array(array $request_data)
336
+	{
337
+		$return_data = array();
338
+		foreach ($request_data as $key => $value) {
339
+			$return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
340
+		}
341
+		return $return_data;
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * Removes any non-printable illegal characters from the input,
348
+	 * which might cause a raucous when trying to insert into the database
349
+	 *
350
+	 * @param string $request_data
351
+	 * @return string
352
+	 */
353
+	protected function _remove_unusable_characters($request_data)
354
+	{
355
+		return preg_replace('/[^[:print:]]/', '', $request_data);
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * Should be called just before displaying the payment attempt results to the user,
362
+	 * when the payment attempt has finished. Some payment methods may have special
363
+	 * logic to perform here. For example, if process_payment() happens on a special request
364
+	 * and then the user is redirected to a page that displays the payment's status, this
365
+	 * should be called while loading the page that displays the payment's status. If the user is
366
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
367
+	 * provider.
368
+	 *
369
+	 * @param EE_Transaction|int $transaction
370
+	 * @param bool               $update_txn whether or not to call
371
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
372
+	 * @throws \EE_Error
373
+	 * @return EE_Payment
374
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
375
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
376
+	 */
377
+	public function finalize_payment_for($transaction, $update_txn = true)
378
+	{
379
+		/** @var $transaction EE_Transaction */
380
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
381
+		$last_payment_method = $transaction->payment_method();
382
+		if ($last_payment_method instanceof EE_Payment_Method) {
383
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
384
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
385
+			return $payment;
386
+		} else {
387
+			return null;
388
+		}
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
395
+	 *
396
+	 * @param EE_Payment_Method $payment_method
397
+	 * @param EE_Payment        $payment_to_refund
398
+	 * @param array             $refund_info
399
+	 * @return EE_Payment
400
+	 * @throws \EE_Error
401
+	 */
402
+	public function process_refund(
403
+		EE_Payment_Method $payment_method,
404
+		EE_Payment $payment_to_refund,
405
+		$refund_info = array()
406
+	) {
407
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
408
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
409
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
410
+		}
411
+		return $payment_to_refund;
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * This should be called each time there may have been an update to a
418
+	 * payment on a transaction (ie, we asked for a payment to process a
419
+	 * payment for a transaction, or we told a payment method about an IPN, or
420
+	 * we told a payment method to
421
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
422
+	 * process a refund. This should handle firing the correct hooks to
423
+	 * indicate
424
+	 * what exactly happened and updating the transaction appropriately). This
425
+	 * could be integrated directly into EE_Transaction upon save, but we want
426
+	 * this logic to be separate from 'normal' plain-jane saving and updating
427
+	 * of transactions and payments, and to be tied to payment processing.
428
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
429
+	 * of previous code to decide whether or not to save (because the payment passed into
430
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
431
+	 * in which case we only want that payment object for some temporary usage during this request,
432
+	 * but we don't want it to be saved).
433
+	 *
434
+	 * @param EE_Transaction|int $transaction
435
+	 * @param EE_Payment         $payment
436
+	 * @param boolean            $update_txn
437
+	 *                        whether or not to call
438
+	 *                        EE_Transaction_Processor::
439
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
440
+	 *                        (you can save 1 DB query if you know you're going
441
+	 *                        to save it later instead)
442
+	 * @param bool               $IPN
443
+	 *                        if processing IPNs or other similar payment
444
+	 *                        related activities that occur in alternate
445
+	 *                        requests than the main one that is processing the
446
+	 *                        TXN, then set this to true to check whether the
447
+	 *                        TXN is locked before updating
448
+	 * @throws \EE_Error
449
+	 */
450
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
451
+	{
452
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
453
+		/** @type EE_Transaction $transaction */
454
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
455
+		// can we freely update the TXN at this moment?
456
+		if ($IPN && $transaction->is_locked()) {
457
+			// don't update the transaction at this exact moment
458
+			// because the TXN is active in another request
459
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
460
+				time(),
461
+				$transaction->ID(),
462
+				$payment->ID()
463
+			);
464
+		} else {
465
+			// verify payment and that it has been saved
466
+			if ($payment instanceof EE_Payment && $payment->ID()) {
467
+				if (
468
+					$payment->payment_method() instanceof EE_Payment_Method
469
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
470
+				) {
471
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
472
+					// update TXN registrations with payment info
473
+					$this->process_registration_payments($transaction, $payment);
474
+				}
475
+				$do_action = $payment->just_approved()
476
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
477
+					: $do_action;
478
+			} else {
479
+				// send out notifications
480
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
481
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
482
+			}
483
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
484
+				/** @type EE_Transaction_Payments $transaction_payments */
485
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
486
+				// set new value for total paid
487
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
488
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
489
+				if ($update_txn) {
490
+					$this->_post_payment_processing($transaction, $payment, $IPN);
491
+				}
492
+			}
493
+			// granular hook for others to use.
494
+			do_action($do_action, $transaction, $payment);
495
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
496
+			//global hook for others to use.
497
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
498
+		}
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * update registrations REG_paid field after successful payment and link registrations with payment
505
+	 *
506
+	 * @param EE_Transaction    $transaction
507
+	 * @param EE_Payment        $payment
508
+	 * @param EE_Registration[] $registrations
509
+	 * @throws \EE_Error
510
+	 */
511
+	public function process_registration_payments(
512
+		EE_Transaction $transaction,
513
+		EE_Payment $payment,
514
+		$registrations = array()
515
+	) {
516
+		// only process if payment was successful
517
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
518
+			return;
519
+		}
520
+		//EEM_Registration::instance()->show_next_x_db_queries();
521
+		if (empty($registrations)) {
522
+			// find registrations with monies owing that can receive a payment
523
+			$registrations = $transaction->registrations(
524
+				array(
525
+					array(
526
+						// only these reg statuses can receive payments
527
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
528
+						'REG_final_price'  => array('!=', 0),
529
+						'REG_final_price*' => array('!=', 'REG_paid', true),
530
+					),
531
+				)
532
+			);
533
+		}
534
+		// still nothing ??!??
535
+		if (empty($registrations)) {
536
+			return;
537
+		}
538
+		// todo: break out the following logic into a separate strategy class
539
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
540
+		// todo: which would apply payments using the capitalist "first come first paid" approach
541
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
542
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
543
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
544
+		$refund = $payment->is_a_refund();
545
+		// how much is available to apply to registrations?
546
+		$available_payment_amount = abs($payment->amount());
547
+		foreach ($registrations as $registration) {
548
+			if ($registration instanceof EE_Registration) {
549
+				// nothing left?
550
+				if ($available_payment_amount <= 0) {
551
+					break;
552
+				}
553
+				if ($refund) {
554
+					$available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
555
+				} else {
556
+					$available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
557
+				}
558
+			}
559
+		}
560
+		if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
561
+			EE_Error::add_attention(
562
+				sprintf(
563
+					__('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).',
564
+						'event_espresso'),
565
+					EEH_Template::format_currency($available_payment_amount),
566
+					implode(', ', array_keys($registrations)),
567
+					'<br/>',
568
+					EEH_Template::format_currency($payment->amount())
569
+				),
570
+				__FILE__, __FUNCTION__, __LINE__
571
+			);
572
+		}
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * update registration REG_paid field after successful payment and link registration with payment
579
+	 *
580
+	 * @param EE_Registration $registration
581
+	 * @param EE_Payment      $payment
582
+	 * @param float           $available_payment_amount
583
+	 * @return float
584
+	 * @throws \EE_Error
585
+	 */
586
+	public function process_registration_payment(
587
+		EE_Registration $registration,
588
+		EE_Payment $payment,
589
+		$available_payment_amount = 0.00
590
+	) {
591
+		$owing = $registration->final_price() - $registration->paid();
592
+		if ($owing > 0) {
593
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
594
+			$payment_amount = min($available_payment_amount, $owing);
595
+			// update $available_payment_amount
596
+			$available_payment_amount -= $payment_amount;
597
+			//calculate and set new REG_paid
598
+			$registration->set_paid($registration->paid() + $payment_amount);
599
+			// now save it
600
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
601
+		}
602
+		return $available_payment_amount;
603
+	}
604
+
605
+
606
+
607
+	/**
608
+	 * update registration REG_paid field after successful payment and link registration with payment
609
+	 *
610
+	 * @param EE_Registration $registration
611
+	 * @param EE_Payment      $payment
612
+	 * @param float           $payment_amount
613
+	 * @return void
614
+	 * @throws \EE_Error
615
+	 */
616
+	protected function _apply_registration_payment(
617
+		EE_Registration $registration,
618
+		EE_Payment $payment,
619
+		$payment_amount = 0.00
620
+	) {
621
+		// find any existing reg payment records for this registration and payment
622
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
623
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
624
+		);
625
+		// if existing registration payment exists
626
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
627
+			// then update that record
628
+			$existing_reg_payment->set_amount($payment_amount);
629
+			$existing_reg_payment->save();
630
+		} else {
631
+			// or add new relation between registration and payment and set amount
632
+			$registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
633
+			// make it stick
634
+			$registration->save();
635
+		}
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * update registration REG_paid field after refund and link registration with payment
642
+	 *
643
+	 * @param EE_Registration $registration
644
+	 * @param EE_Payment      $payment
645
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
646
+	 * @return float
647
+	 * @throws \EE_Error
648
+	 */
649
+	public function process_registration_refund(
650
+		EE_Registration $registration,
651
+		EE_Payment $payment,
652
+		$available_refund_amount = 0.00
653
+	) {
654
+		//EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
655
+		if ($registration->paid() > 0) {
656
+			// ensure $available_refund_amount is NOT negative
657
+			$available_refund_amount = (float)abs($available_refund_amount);
658
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
659
+			$refund_amount = min($available_refund_amount, (float)$registration->paid());
660
+			// update $available_payment_amount
661
+			$available_refund_amount -= $refund_amount;
662
+			//calculate and set new REG_paid
663
+			$registration->set_paid($registration->paid() - $refund_amount);
664
+			// convert payment amount back to a negative value for storage in the db
665
+			$refund_amount = (float)abs($refund_amount) * -1;
666
+			// now save it
667
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
668
+		}
669
+		return $available_refund_amount;
670
+	}
671
+
672
+
673
+
674
+	/**
675
+	 * Process payments and transaction after payment process completed.
676
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
677
+	 * if this request happens to be processing an IPN,
678
+	 * then we will also set the Payment Options Reg Step to completed,
679
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
680
+	 *
681
+	 * @param EE_Transaction $transaction
682
+	 * @param EE_Payment     $payment
683
+	 * @param bool           $IPN
684
+	 * @throws \EE_Error
685
+	 */
686
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
687
+	{
688
+		/** @type EE_Transaction_Processor $transaction_processor */
689
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
690
+		// is the Payment Options Reg Step completed ?
691
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
692
+		// if the Payment Options Reg Step is completed...
693
+		$revisit = $payment_options_step_completed === true ? true : false;
694
+		// then this is kinda sorta a revisit with regards to payments at least
695
+		$transaction_processor->set_revisit($revisit);
696
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
697
+		if (
698
+			$IPN
699
+			&& $payment_options_step_completed !== true
700
+			&& ($payment->is_approved() || $payment->is_pending())
701
+		) {
702
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
703
+				'payment_options'
704
+			);
705
+		}
706
+		// maybe update status, but don't save transaction just yet
707
+		$transaction->update_status_based_on_total_paid(false);
708
+		// check if 'finalize_registration' step has been completed...
709
+		$finalized = $transaction->reg_step_completed('finalize_registration');
710
+		//  if this is an IPN and the final step has not been initiated
711
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
712
+			// and if it hasn't already been set as being started...
713
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
714
+		}
715
+		$transaction->save();
716
+		// because the above will return false if the final step was not fully completed, we need to check again...
717
+		if ($IPN && $finalized !== false) {
718
+			// and if we are all good to go, then send out notifications
719
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
720
+			//ok, now process the transaction according to the payment
721
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
722
+		}
723
+		// DEBUG LOG
724
+		$payment_method = $payment->payment_method();
725
+		if ($payment_method instanceof EE_Payment_Method) {
726
+			$payment_method_type_obj = $payment_method->type_obj();
727
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
728
+				$gateway = $payment_method_type_obj->get_gateway();
729
+				if ($gateway instanceof EE_Gateway) {
730
+					$gateway->log(
731
+						array(
732
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
733
+							'transaction'           => $transaction->model_field_array(),
734
+							'finalized'             => $finalized,
735
+							'IPN'                   => $IPN,
736
+							'deliver_notifications' => has_filter(
737
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
738
+							),
739
+						),
740
+						$payment
741
+					);
742
+				}
743
+			}
744
+		}
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * Force posts to PayPal to use TLS v1.2. See:
751
+	 * https://core.trac.wordpress.org/ticket/36320
752
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
753
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
754
+	 * This will affect paypal standard, pro, express, and payflow.
755
+	 */
756
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
757
+	{
758
+		if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
759
+			//Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
760
+			//instead of the constant because it might not be defined
761
+			curl_setopt($handle, CURLOPT_SSLVERSION, 1);
762
+		}
763
+	}
764 764
 }
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@
 block discarded – undo
32 32
 	 * @return \EventEspresso\core\Psr4Autoloader
33 33
 	 */
34 34
 	public function initializeAutoloader() {
35
-        static $initialized = false;
36
-        if ( ! $initialized) {
37
-            // instantiate PSR4 autoloader
35
+		static $initialized = false;
36
+		if ( ! $initialized) {
37
+			// instantiate PSR4 autoloader
38 38
 			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
39
-            EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
40
-            // register the autoloader
41
-            EE_Psr4AutoloaderInit::$psr4_loader->register();
42
-            // register the base directories for the namespace prefix
43
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
44
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
45
-            $initialized = true;
46
-        }
47
-    }
39
+			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
40
+			// register the autoloader
41
+			EE_Psr4AutoloaderInit::$psr4_loader->register();
42
+			// register the base directories for the namespace prefix
43
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
44
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
45
+			$initialized = true;
46
+		}
47
+	}
48 48
 
49 49
 
50 50
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@
 block discarded – undo
35 35
         static $initialized = false;
36 36
         if ( ! $initialized) {
37 37
             // instantiate PSR4 autoloader
38
-			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
38
+			espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php');
39 39
             EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
40 40
             // register the autoloader
41 41
             EE_Psr4AutoloaderInit::$psr4_loader->register();
42 42
             // register the base directories for the namespace prefix
43 43
             EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
44
-            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
44
+            EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
45 45
             $initialized = true;
46 46
         }
47 47
     }
Please login to merge, or discard this patch.
core/EE_Registry.core.php 2 patches
Indentation   +1538 added lines, -1538 removed lines patch added patch discarded remove patch
@@ -22,1544 +22,1544 @@
 block discarded – undo
22 22
 class EE_Registry implements ResettableInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var EE_Registry $_instance
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     * @var EE_Dependency_Map $_dependency_map
32
-     */
33
-    protected $_dependency_map;
34
-
35
-    /**
36
-     * @var array $_class_abbreviations
37
-     */
38
-    protected $_class_abbreviations = array();
39
-
40
-    /**
41
-     * @var CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     * @var EE_Cart $CART
47
-     */
48
-    public $CART;
49
-
50
-    /**
51
-     * @var EE_Config $CFG
52
-     */
53
-    public $CFG;
54
-
55
-    /**
56
-     * @var EE_Network_Config $NET_CFG
57
-     */
58
-    public $NET_CFG;
59
-
60
-    /**
61
-     * StdClass object for storing library classes in
62
-     *
63
-     * @var StdClass $LIB
64
-     */
65
-    public $LIB;
66
-
67
-    /**
68
-     * @var EE_Request_Handler $REQ
69
-     */
70
-    public $REQ;
71
-
72
-    /**
73
-     * @var EE_Session $SSN
74
-     */
75
-    public $SSN;
76
-
77
-    /**
78
-     * @since 4.5.0
79
-     * @var EE_Capabilities $CAP
80
-     */
81
-    public $CAP;
82
-
83
-    /**
84
-     * @since 4.9.0
85
-     * @var EE_Message_Resource_Manager $MRM
86
-     */
87
-    public $MRM;
88
-
89
-
90
-    /**
91
-     * @var Registry $AssetsRegistry
92
-     */
93
-    public $AssetsRegistry;
94
-
95
-    /**
96
-     * StdClass object for holding addons which have registered themselves to work with EE core
97
-     *
98
-     * @var EE_Addon[] $addons
99
-     */
100
-    public $addons;
101
-
102
-    /**
103
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
104
-     *
105
-     * @var EEM_Base[] $models
106
-     */
107
-    public $models = array();
108
-
109
-    /**
110
-     * @var EED_Module[] $modules
111
-     */
112
-    public $modules;
113
-
114
-    /**
115
-     * @var EES_Shortcode[] $shortcodes
116
-     */
117
-    public $shortcodes;
118
-
119
-    /**
120
-     * @var WP_Widget[] $widgets
121
-     */
122
-    public $widgets;
123
-
124
-    /**
125
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
126
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
127
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
128
-     * classnames (eg "EEM_Event")
129
-     *
130
-     * @var array $non_abstract_db_models
131
-     */
132
-    public $non_abstract_db_models = array();
133
-
134
-
135
-    /**
136
-     * internationalization for JS strings
137
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
138
-     *    in js file:  var translatedString = eei18n.string_key;
139
-     *
140
-     * @var array $i18n_js_strings
141
-     */
142
-    public static $i18n_js_strings = array();
143
-
144
-
145
-    /**
146
-     * $main_file - path to espresso.php
147
-     *
148
-     * @var array $main_file
149
-     */
150
-    public $main_file;
151
-
152
-    /**
153
-     * array of ReflectionClass objects where the key is the class name
154
-     *
155
-     * @var ReflectionClass[] $_reflectors
156
-     */
157
-    public $_reflectors;
158
-
159
-    /**
160
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
161
-     *
162
-     * @var boolean $_cache_on
163
-     */
164
-    protected $_cache_on = true;
165
-
166
-
167
-
168
-    /**
169
-     * @singleton method used to instantiate class object
170
-     * @param  EE_Dependency_Map $dependency_map
171
-     * @return EE_Registry instance
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidInterfaceException
174
-     * @throws InvalidDataTypeException
175
-     */
176
-    public static function instance(EE_Dependency_Map $dependency_map = null)
177
-    {
178
-        // check if class object is instantiated
179
-        if (! self::$_instance instanceof EE_Registry) {
180
-            self::$_instance = new self($dependency_map);
181
-        }
182
-        return self::$_instance;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * protected constructor to prevent direct creation
189
-     *
190
-     * @Constructor
191
-     * @param  EE_Dependency_Map $dependency_map
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @throws InvalidArgumentException
195
-     */
196
-    protected function __construct(EE_Dependency_Map $dependency_map)
197
-    {
198
-        $this->_dependency_map = $dependency_map;
199
-        $this->LIB = new stdClass();
200
-        $this->addons = new stdClass();
201
-        $this->modules = new stdClass();
202
-        $this->shortcodes = new stdClass();
203
-        $this->widgets = new stdClass();
204
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * initialize
211
-     *
212
-     * @throws EE_Error
213
-     * @throws ReflectionException
214
-     */
215
-    public function initialize()
216
-    {
217
-        $this->_class_abbreviations = apply_filters(
218
-            'FHEE__EE_Registry____construct___class_abbreviations',
219
-            array(
220
-                'EE_Config'                                       => 'CFG',
221
-                'EE_Session'                                      => 'SSN',
222
-                'EE_Capabilities'                                 => 'CAP',
223
-                'EE_Cart'                                         => 'CART',
224
-                'EE_Network_Config'                               => 'NET_CFG',
225
-                'EE_Request_Handler'                              => 'REQ',
226
-                'EE_Message_Resource_Manager'                     => 'MRM',
227
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
228
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
229
-            )
230
-        );
231
-        $this->load_core('Base', array(), true);
232
-        // add our request and response objects to the cache
233
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
234
-        $this->_set_cached_class(
235
-            $request_loader(),
236
-            'EE_Request'
237
-        );
238
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
239
-        $this->_set_cached_class(
240
-            $response_loader(),
241
-            'EE_Response'
242
-        );
243
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * @return void
250
-     */
251
-    public function init()
252
-    {
253
-        // Get current page protocol
254
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
255
-        // Output admin-ajax.php URL with same protocol as current page
256
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
257
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * localize_i18n_js_strings
264
-     *
265
-     * @return string
266
-     */
267
-    public static function localize_i18n_js_strings()
268
-    {
269
-        $i18n_js_strings = (array)self::$i18n_js_strings;
270
-        foreach ($i18n_js_strings as $key => $value) {
271
-            if (is_scalar($value)) {
272
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
273
-            }
274
-        }
275
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * @param mixed string | EED_Module $module
282
-     * @throws EE_Error
283
-     * @throws ReflectionException
284
-     */
285
-    public function add_module($module)
286
-    {
287
-        if ($module instanceof EED_Module) {
288
-            $module_class = get_class($module);
289
-            $this->modules->{$module_class} = $module;
290
-        } else {
291
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
292
-                $this->load_core('Module_Request_Router');
293
-            }
294
-            EE_Module_Request_Router::module_factory($module);
295
-        }
296
-    }
297
-
298
-
299
-
300
-    /**
301
-     * @param string $module_name
302
-     * @return mixed EED_Module | NULL
303
-     */
304
-    public function get_module($module_name = '')
305
-    {
306
-        return isset($this->modules->{$module_name})
307
-            ? $this->modules->{$module_name}
308
-            : null;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * loads core classes - must be singletons
315
-     *
316
-     * @param string $class_name - simple class name ie: session
317
-     * @param mixed  $arguments
318
-     * @param bool   $load_only
319
-     * @return mixed
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public function load_core($class_name, $arguments = array(), $load_only = false)
324
-    {
325
-        $core_paths = apply_filters(
326
-            'FHEE__EE_Registry__load_core__core_paths',
327
-            array(
328
-                EE_CORE,
329
-                EE_ADMIN,
330
-                EE_CPTS,
331
-                EE_CORE . 'data_migration_scripts' . DS,
332
-                EE_CORE . 'capabilities' . DS,
333
-                EE_CORE . 'request_stack' . DS,
334
-                EE_CORE . 'middleware' . DS,
335
-            )
336
-        );
337
-        // retrieve instantiated class
338
-        return $this->_load(
339
-            $core_paths,
340
-            'EE_',
341
-            $class_name,
342
-            'core',
343
-            $arguments,
344
-            false,
345
-            true,
346
-            $load_only
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * loads service classes
354
-     *
355
-     * @param string $class_name - simple class name ie: session
356
-     * @param mixed  $arguments
357
-     * @param bool   $load_only
358
-     * @return mixed
359
-     * @throws EE_Error
360
-     * @throws ReflectionException
361
-     */
362
-    public function load_service($class_name, $arguments = array(), $load_only = false)
363
-    {
364
-        $service_paths = apply_filters(
365
-            'FHEE__EE_Registry__load_service__service_paths',
366
-            array(
367
-                EE_CORE . 'services' . DS,
368
-            )
369
-        );
370
-        // retrieve instantiated class
371
-        return $this->_load(
372
-            $service_paths,
373
-            'EE_',
374
-            $class_name,
375
-            'class',
376
-            $arguments,
377
-            false,
378
-            true,
379
-            $load_only
380
-        );
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * loads data_migration_scripts
387
-     *
388
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
389
-     * @param mixed  $arguments
390
-     * @return EE_Data_Migration_Script_Base|mixed
391
-     * @throws EE_Error
392
-     * @throws ReflectionException
393
-     */
394
-    public function load_dms($class_name, $arguments = array())
395
-    {
396
-        // retrieve instantiated class
397
-        return $this->_load(
398
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
399
-            'EE_DMS_',
400
-            $class_name,
401
-            'dms',
402
-            $arguments,
403
-            false,
404
-            false
405
-        );
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * loads object creating classes - must be singletons
412
-     *
413
-     * @param string $class_name - simple class name ie: attendee
414
-     * @param mixed  $arguments  - an array of arguments to pass to the class
415
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
416
-     *                           instantiate
417
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
418
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
419
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
420
-     *                           (default)
421
-     * @return EE_Base_Class | bool
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
426
-    {
427
-        $paths = apply_filters(
428
-            'FHEE__EE_Registry__load_class__paths', array(
429
-            EE_CORE,
430
-            EE_CLASSES,
431
-            EE_BUSINESS,
432
-        )
433
-        );
434
-        // retrieve instantiated class
435
-        return $this->_load(
436
-            $paths,
437
-            'EE_',
438
-            $class_name,
439
-            'class',
440
-            $arguments,
441
-            $from_db,
442
-            $cache,
443
-            $load_only
444
-        );
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * loads helper classes - must be singletons
451
-     *
452
-     * @param string $class_name - simple class name ie: price
453
-     * @param mixed  $arguments
454
-     * @param bool   $load_only
455
-     * @return EEH_Base | bool
456
-     * @throws EE_Error
457
-     * @throws ReflectionException
458
-     */
459
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
460
-    {
461
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
462
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
463
-        // retrieve instantiated class
464
-        return $this->_load(
465
-            $helper_paths,
466
-            'EEH_',
467
-            $class_name,
468
-            'helper',
469
-            $arguments,
470
-            false,
471
-            true,
472
-            $load_only
473
-        );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * loads core classes - must be singletons
480
-     *
481
-     * @param string $class_name - simple class name ie: session
482
-     * @param mixed  $arguments
483
-     * @param bool   $load_only
484
-     * @param bool   $cache      whether to cache the object or not.
485
-     * @return mixed
486
-     * @throws EE_Error
487
-     * @throws ReflectionException
488
-     */
489
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
490
-    {
491
-        $paths = array(
492
-            EE_LIBRARIES,
493
-            EE_LIBRARIES . 'messages' . DS,
494
-            EE_LIBRARIES . 'shortcodes' . DS,
495
-            EE_LIBRARIES . 'qtips' . DS,
496
-            EE_LIBRARIES . 'payment_methods' . DS,
497
-            EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
498
-        );
499
-        // retrieve instantiated class
500
-        return $this->_load(
501
-            $paths,
502
-            'EE_',
503
-            $class_name,
504
-            'lib',
505
-            $arguments,
506
-            false,
507
-            $cache,
508
-            $load_only
509
-        );
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * loads model classes - must be singletons
516
-     *
517
-     * @param string $class_name - simple class name ie: price
518
-     * @param mixed  $arguments
519
-     * @param bool   $load_only
520
-     * @return EEM_Base | bool
521
-     * @throws EE_Error
522
-     * @throws ReflectionException
523
-     */
524
-    public function load_model($class_name, $arguments = array(), $load_only = false)
525
-    {
526
-        $paths = apply_filters(
527
-            'FHEE__EE_Registry__load_model__paths', array(
528
-            EE_MODELS,
529
-            EE_CORE,
530
-        )
531
-        );
532
-        // retrieve instantiated class
533
-        return $this->_load(
534
-            $paths,
535
-            'EEM_',
536
-            $class_name,
537
-            'model',
538
-            $arguments,
539
-            false,
540
-            true,
541
-            $load_only
542
-        );
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * loads model classes - must be singletons
549
-     *
550
-     * @param string $class_name - simple class name ie: price
551
-     * @param mixed  $arguments
552
-     * @param bool   $load_only
553
-     * @return mixed | bool
554
-     * @throws EE_Error
555
-     * @throws ReflectionException
556
-     */
557
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
558
-    {
559
-        $paths = array(
560
-            EE_MODELS . 'fields' . DS,
561
-            EE_MODELS . 'helpers' . DS,
562
-            EE_MODELS . 'relations' . DS,
563
-            EE_MODELS . 'strategies' . DS,
564
-        );
565
-        // retrieve instantiated class
566
-        return $this->_load(
567
-            $paths,
568
-            'EE_',
569
-            $class_name,
570
-            '',
571
-            $arguments,
572
-            false,
573
-            true,
574
-            $load_only
575
-        );
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * Determines if $model_name is the name of an actual EE model.
582
-     *
583
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
584
-     * @return boolean
585
-     */
586
-    public function is_model_name($model_name)
587
-    {
588
-        return isset($this->models[$model_name]);
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * generic class loader
595
-     *
596
-     * @param string $path_to_file - directory path to file location, not including filename
597
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
598
-     * @param string $type         - file type - core? class? helper? model?
599
-     * @param mixed  $arguments
600
-     * @param bool   $load_only
601
-     * @return mixed
602
-     * @throws EE_Error
603
-     * @throws ReflectionException
604
-     */
605
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
606
-    {
607
-        // retrieve instantiated class
608
-        return $this->_load(
609
-            $path_to_file,
610
-            '',
611
-            $file_name,
612
-            $type,
613
-            $arguments,
614
-            false,
615
-            true,
616
-            $load_only
617
-        );
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     * @param string $path_to_file - directory path to file location, not including filename
624
-     * @param string $class_name   - full class name  ie:  My_Class
625
-     * @param string $type         - file type - core? class? helper? model?
626
-     * @param mixed  $arguments
627
-     * @param bool   $load_only
628
-     * @return bool|EE_Addon|object
629
-     * @throws EE_Error
630
-     * @throws ReflectionException
631
-     */
632
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
633
-    {
634
-        // retrieve instantiated class
635
-        return $this->_load(
636
-            $path_to_file,
637
-            'addon',
638
-            $class_name,
639
-            $type,
640
-            $arguments,
641
-            false,
642
-            true,
643
-            $load_only
644
-        );
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * instantiates, caches, and automatically resolves dependencies
651
-     * for classes that use a Fully Qualified Class Name.
652
-     * if the class is not capable of being loaded using PSR-4 autoloading,
653
-     * then you need to use one of the existing load_*() methods
654
-     * which can resolve the classname and filepath from the passed arguments
655
-     *
656
-     * @param bool|string $class_name   Fully Qualified Class Name
657
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
658
-     * @param bool        $cache        whether to cache the instantiated object for reuse
659
-     * @param bool        $from_db      some classes are instantiated from the db
660
-     *                                  and thus call a different method to instantiate
661
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
662
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
663
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
664
-     *                                  object = class loaded and instantiated successfully.
665
-     *                                  bool = fail or success when $load_only is true
666
-     * @throws EE_Error
667
-     * @throws ReflectionException
668
-     */
669
-    public function create(
670
-        $class_name = false,
671
-        $arguments = array(),
672
-        $cache = false,
673
-        $from_db = false,
674
-        $load_only = false,
675
-        $addon = false
676
-    ) {
677
-        $class_name = ltrim($class_name, '\\');
678
-        $class_name = $this->_dependency_map->get_alias($class_name);
679
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
680
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
681
-        // or it could return null if the class just could not be found anywhere
682
-        if ($class_exists instanceof $class_name || $class_exists === null){
683
-            // either way, return the results
684
-            return $class_exists;
685
-        }
686
-        $class_name = $class_exists;
687
-        // if we're only loading the class and it already exists, then let's just return true immediately
688
-        if ($load_only) {
689
-            return true;
690
-        }
691
-        $addon = $addon
692
-            ? 'addon'
693
-            : '';
694
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
695
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
696
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
697
-        if ($this->_cache_on && $cache && ! $load_only) {
698
-            // return object if it's already cached
699
-            $cached_class = $this->_get_cached_class($class_name, $addon);
700
-            if ($cached_class !== null) {
701
-                return $cached_class;
702
-            }
703
-        }
704
-        // obtain the loader method from the dependency map
705
-        $loader = $this->_dependency_map->class_loader($class_name);
706
-        // instantiate the requested object
707
-        if ($loader instanceof Closure) {
708
-            $class_obj = $loader($arguments);
709
-        } else if ($loader && method_exists($this, $loader)) {
710
-            $class_obj = $this->{$loader}($class_name, $arguments);
711
-        } else {
712
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
713
-        }
714
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
715
-            // save it for later... kinda like gum  { : $
716
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
717
-        }
718
-        $this->_cache_on = true;
719
-        return $class_obj;
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
726
-     *
727
-     * @param string $class_name
728
-     * @param array  $arguments
729
-     * @param int    $attempt
730
-     * @return mixed
731
-     */
732
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
733
-        if (is_object($class_name) || class_exists($class_name)) {
734
-            return $class_name;
735
-        }
736
-        switch ($attempt) {
737
-            case 1:
738
-                // if it's a FQCN then maybe the class is registered with a preceding \
739
-                $class_name = strpos($class_name, '\\') !== false
740
-                    ? '\\' . ltrim($class_name, '\\')
741
-                    : $class_name;
742
-                break;
743
-            case 2:
744
-                //
745
-                $loader = $this->_dependency_map->class_loader($class_name);
746
-                if ($loader && method_exists($this, $loader)) {
747
-                    return $this->{$loader}($class_name, $arguments);
748
-                }
749
-                break;
750
-            case 3:
751
-            default;
752
-                return null;
753
-        }
754
-        $attempt++;
755
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
756
-    }
757
-
758
-
759
-
760
-    /**
761
-     * instantiates, caches, and injects dependencies for classes
762
-     *
763
-     * @param array       $file_paths   an array of paths to folders to look in
764
-     * @param string      $class_prefix EE  or EEM or... ???
765
-     * @param bool|string $class_name   $class name
766
-     * @param string      $type         file type - core? class? helper? model?
767
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
768
-     * @param bool        $from_db      some classes are instantiated from the db
769
-     *                                  and thus call a different method to instantiate
770
-     * @param bool        $cache        whether to cache the instantiated object for reuse
771
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
772
-     * @return bool|null|object null = failure to load or instantiate class object.
773
-     *                                  object = class loaded and instantiated successfully.
774
-     *                                  bool = fail or success when $load_only is true
775
-     * @throws EE_Error
776
-     * @throws ReflectionException
777
-     */
778
-    protected function _load(
779
-        $file_paths = array(),
780
-        $class_prefix = 'EE_',
781
-        $class_name = false,
782
-        $type = 'class',
783
-        $arguments = array(),
784
-        $from_db = false,
785
-        $cache = true,
786
-        $load_only = false
787
-    ) {
788
-        $class_name = ltrim($class_name, '\\');
789
-        // strip php file extension
790
-        $class_name = str_replace('.php', '', trim($class_name));
791
-        // does the class have a prefix ?
792
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
793
-            // make sure $class_prefix is uppercase
794
-            $class_prefix = strtoupper(trim($class_prefix));
795
-            // add class prefix ONCE!!!
796
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
797
-        }
798
-        $class_name = $this->_dependency_map->get_alias($class_name);
799
-        $class_exists = class_exists($class_name, false);
800
-        // if we're only loading the class and it already exists, then let's just return true immediately
801
-        if ($load_only && $class_exists) {
802
-            return true;
803
-        }
804
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
805
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
806
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
807
-        if ($this->_cache_on && $cache && ! $load_only) {
808
-            // return object if it's already cached
809
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
810
-            if ($cached_class !== null) {
811
-                return $cached_class;
812
-            }
813
-        }
814
-        // if the class doesn't already exist.. then we need to try and find the file and load it
815
-        if (! $class_exists) {
816
-            // get full path to file
817
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
818
-            // load the file
819
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
820
-            // if loading failed, or we are only loading a file but NOT instantiating an object
821
-            if (! $loaded || $load_only) {
822
-                // return boolean if only loading, or null if an object was expected
823
-                return $load_only
824
-                    ? $loaded
825
-                    : null;
826
-            }
827
-        }
828
-        // instantiate the requested object
829
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
830
-        if ($this->_cache_on && $cache) {
831
-            // save it for later... kinda like gum  { : $
832
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
833
-        }
834
-        $this->_cache_on = true;
835
-        return $class_obj;
836
-    }
837
-
838
-
839
-
840
-    /**
841
-     * @param string $class_name
842
-     * @param string $default have to specify something, but not anything that will conflict
843
-     * @return mixed|string
844
-     */
845
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
846
-    {
847
-        return isset($this->_class_abbreviations[$class_name])
848
-            ? $this->_class_abbreviations[$class_name]
849
-            : $default;
850
-    }
851
-
852
-    /**
853
-     * attempts to find a cached version of the requested class
854
-     * by looking in the following places:
855
-     *        $this->{$class_abbreviation}            ie:    $this->CART
856
-     *        $this->{$class_name}                        ie:    $this->Some_Class
857
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
858
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
859
-     *
860
-     * @param string $class_name
861
-     * @param string $class_prefix
862
-     * @return mixed
863
-     */
864
-    protected function _get_cached_class($class_name, $class_prefix = '')
865
-    {
866
-        if ($class_name === 'EE_Registry') {
867
-            return $this;
868
-        }
869
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
870
-        $class_name = str_replace('\\', '_', $class_name);
871
-        // check if class has already been loaded, and return it if it has been
872
-        if (isset($this->{$class_abbreviation})) {
873
-            return $this->{$class_abbreviation};
874
-        }
875
-        if (isset ($this->{$class_name})) {
876
-            return $this->{$class_name};
877
-        }
878
-        if (isset ($this->LIB->{$class_name})) {
879
-            return $this->LIB->{$class_name};
880
-        }
881
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
882
-            return $this->addons->{$class_name};
883
-        }
884
-        return null;
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * removes a cached version of the requested class
891
-     *
892
-     * @param string  $class_name
893
-     * @param boolean $addon
894
-     * @return boolean
895
-     */
896
-    public function clear_cached_class($class_name, $addon = false)
897
-    {
898
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
899
-        $class_name = str_replace('\\', '_', $class_name);
900
-        // check if class has already been loaded, and return it if it has been
901
-        if (isset($this->{$class_abbreviation})) {
902
-            $this->{$class_abbreviation} = null;
903
-            return true;
904
-        }
905
-        if (isset($this->{$class_name})) {
906
-            $this->{$class_name} = null;
907
-            return true;
908
-        }
909
-        if (isset($this->LIB->{$class_name})) {
910
-            unset($this->LIB->{$class_name});
911
-            return true;
912
-        }
913
-        if ($addon && isset($this->addons->{$class_name})) {
914
-            unset($this->addons->{$class_name});
915
-            return true;
916
-        }
917
-        return false;
918
-    }
919
-
920
-
921
-
922
-    /**
923
-     * attempts to find a full valid filepath for the requested class.
924
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
925
-     * then returns that path if the target file has been found and is readable
926
-     *
927
-     * @param string $class_name
928
-     * @param string $type
929
-     * @param array  $file_paths
930
-     * @return string | bool
931
-     */
932
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
933
-    {
934
-        // make sure $file_paths is an array
935
-        $file_paths = is_array($file_paths)
936
-            ? $file_paths
937
-            : array($file_paths);
938
-        // cycle thru paths
939
-        foreach ($file_paths as $key => $file_path) {
940
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
941
-            $file_path = $file_path
942
-                ? str_replace(array('/', '\\'), DS, $file_path)
943
-                : EE_CLASSES;
944
-            // prep file type
945
-            $type = ! empty($type)
946
-                ? trim($type, '.') . '.'
947
-                : '';
948
-            // build full file path
949
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
950
-            //does the file exist and can be read ?
951
-            if (is_readable($file_paths[$key])) {
952
-                return $file_paths[$key];
953
-            }
954
-        }
955
-        return false;
956
-    }
957
-
958
-
959
-
960
-    /**
961
-     * basically just performs a require_once()
962
-     * but with some error handling
963
-     *
964
-     * @param  string $path
965
-     * @param  string $class_name
966
-     * @param  string $type
967
-     * @param  array  $file_paths
968
-     * @return bool
969
-     * @throws EE_Error
970
-     * @throws ReflectionException
971
-     */
972
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
973
-    {
974
-        $this->resolve_legacy_class_parent($class_name);
975
-        // don't give up! you gotta...
976
-        try {
977
-            //does the file exist and can it be read ?
978
-            if (! $path) {
979
-                // so sorry, can't find the file
980
-                throw new EE_Error (
981
-                    sprintf(
982
-                        esc_html__(
983
-                            'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
984
-                            'event_espresso'
985
-                        ),
986
-                        trim($type, '.'),
987
-                        $class_name,
988
-                        '<br />' . implode(',<br />', $file_paths)
989
-                    )
990
-                );
991
-            }
992
-            // get the file
993
-            require_once($path);
994
-            // if the class isn't already declared somewhere
995
-            if (class_exists($class_name, false) === false) {
996
-                // so sorry, not a class
997
-                throw new EE_Error(
998
-                    sprintf(
999
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1000
-                        $type,
1001
-                        $path,
1002
-                        $class_name
1003
-                    )
1004
-                );
1005
-            }
1006
-        } catch (EE_Error $e) {
1007
-            $e->get_error();
1008
-            return false;
1009
-        }
1010
-        return true;
1011
-    }
1012
-
1013
-
1014
-
1015
-    /**
1016
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1017
-     * before their class declaration in order to ensure that the parent class was loaded.
1018
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1019
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1020
-     *
1021
-     * @param string $class_name
1022
-     */
1023
-    protected function resolve_legacy_class_parent($class_name = '')
1024
-    {
1025
-        try {
1026
-            $legacy_parent_class_map = array(
1027
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1028
-            );
1029
-            if(isset($legacy_parent_class_map[$class_name])) {
1030
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1031
-            }
1032
-        } catch (Exception $exception) {
1033
-        }
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * _create_object
1040
-     * Attempts to instantiate the requested class via any of the
1041
-     * commonly used instantiation methods employed throughout EE.
1042
-     * The priority for instantiation is as follows:
1043
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1044
-     *        - model objects via their 'new_instance_from_db' method
1045
-     *        - model objects via their 'new_instance' method
1046
-     *        - "singleton" classes" via their 'instance' method
1047
-     *    - standard instantiable classes via their __constructor
1048
-     * Prior to instantiation, if the classname exists in the dependency_map,
1049
-     * then the constructor for the requested class will be examined to determine
1050
-     * if any dependencies exist, and if they can be injected.
1051
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1052
-     *
1053
-     * @param string $class_name
1054
-     * @param array  $arguments
1055
-     * @param string $type
1056
-     * @param bool   $from_db
1057
-     * @return null|object
1058
-     * @throws EE_Error
1059
-     * @throws ReflectionException
1060
-     */
1061
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1062
-    {
1063
-        // create reflection
1064
-        $reflector = $this->get_ReflectionClass($class_name);
1065
-        // make sure arguments are an array
1066
-        $arguments = is_array($arguments)
1067
-            ? $arguments
1068
-            : array($arguments);
1069
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1070
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1071
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1072
-            ? $arguments
1073
-            : array($arguments);
1074
-        // attempt to inject dependencies ?
1075
-        if ($this->_dependency_map->has($class_name)) {
1076
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1077
-        }
1078
-        // instantiate the class if possible
1079
-        if ($reflector->isAbstract()) {
1080
-            // nothing to instantiate, loading file was enough
1081
-            // does not throw an exception so $instantiation_mode is unused
1082
-            // $instantiation_mode = "1) no constructor abstract class";
1083
-            return true;
1084
-        }
1085
-        if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1086
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1087
-            // $instantiation_mode = "2) no constructor but instantiable";
1088
-            return $reflector->newInstance();
1089
-        }
1090
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1091
-            // $instantiation_mode = "3) new_instance_from_db()";
1092
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1093
-        }
1094
-        if (method_exists($class_name, 'new_instance')) {
1095
-            // $instantiation_mode = "4) new_instance()";
1096
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1097
-        }
1098
-        if (method_exists($class_name, 'instance')) {
1099
-            // $instantiation_mode = "5) instance()";
1100
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1101
-        }
1102
-        if ($reflector->isInstantiable()) {
1103
-            // $instantiation_mode = "6) constructor";
1104
-            return $reflector->newInstanceArgs($arguments);
1105
-        }
1106
-        // heh ? something's not right !
1107
-        throw new EE_Error(
1108
-            sprintf(
1109
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1110
-                $type,
1111
-                $class_name
1112
-            )
1113
-        );
1114
-    }
1115
-
1116
-
1117
-
1118
-    /**
1119
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1120
-     * @param array $array
1121
-     * @return bool
1122
-     */
1123
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1124
-    {
1125
-        return ! empty($array)
1126
-            ? array_keys($array) === range(0, count($array) - 1)
1127
-            : true;
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * getReflectionClass
1134
-     * checks if a ReflectionClass object has already been generated for a class
1135
-     * and returns that instead of creating a new one
1136
-     *
1137
-     * @param string $class_name
1138
-     * @return ReflectionClass
1139
-     * @throws ReflectionException
1140
-     */
1141
-    public function get_ReflectionClass($class_name)
1142
-    {
1143
-        if (
1144
-            ! isset($this->_reflectors[$class_name])
1145
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1146
-        ) {
1147
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1148
-        }
1149
-        return $this->_reflectors[$class_name];
1150
-    }
1151
-
1152
-
1153
-
1154
-    /**
1155
-     * _resolve_dependencies
1156
-     * examines the constructor for the requested class to determine
1157
-     * if any dependencies exist, and if they can be injected.
1158
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1159
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1160
-     * For example:
1161
-     *        if attempting to load a class "Foo" with the following constructor:
1162
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1163
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1164
-     *        but only IF they are NOT already present in the incoming arguments array,
1165
-     *        and the correct classes can be loaded
1166
-     *
1167
-     * @param ReflectionClass $reflector
1168
-     * @param string          $class_name
1169
-     * @param array           $arguments
1170
-     * @return array
1171
-     * @throws EE_Error
1172
-     * @throws ReflectionException
1173
-     */
1174
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1175
-    {
1176
-        // let's examine the constructor
1177
-        $constructor = $reflector->getConstructor();
1178
-        // whu? huh? nothing?
1179
-        if (! $constructor) {
1180
-            return $arguments;
1181
-        }
1182
-        // get constructor parameters
1183
-        $params = $constructor->getParameters();
1184
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1185
-        $argument_keys = array_keys($arguments);
1186
-        // now loop thru all of the constructors expected parameters
1187
-        foreach ($params as $index => $param) {
1188
-            // is this a dependency for a specific class ?
1189
-            $param_class = $param->getClass()
1190
-                ? $param->getClass()->name
1191
-                : null;
1192
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1193
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1194
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1195
-                : $param_class;
1196
-            if (
1197
-                // param is not even a class
1198
-                $param_class === null
1199
-                // and something already exists in the incoming arguments for this param
1200
-                && array_key_exists($index, $argument_keys)
1201
-                && array_key_exists($argument_keys[$index], $arguments)
1202
-            ) {
1203
-                // so let's skip this argument and move on to the next
1204
-                continue;
1205
-            }
1206
-            if (
1207
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1208
-                $param_class !== null
1209
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1210
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1211
-            ) {
1212
-                // skip this argument and move on to the next
1213
-                continue;
1214
-            }
1215
-            if (
1216
-                // parameter is type hinted as a class, and should be injected
1217
-                $param_class !== null
1218
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1219
-            ) {
1220
-                $arguments = $this->_resolve_dependency(
1221
-                    $class_name,
1222
-                    $param_class,
1223
-                    $arguments,
1224
-                    $index,
1225
-                    $argument_keys
1226
-                );
1227
-            } else {
1228
-                try {
1229
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1230
-                        ? $param->getDefaultValue()
1231
-                        : null;
1232
-                } catch (ReflectionException $e) {
1233
-                    throw new ReflectionException(
1234
-                        sprintf(
1235
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1236
-                            $e->getMessage(),
1237
-                            $param->getName(),
1238
-                            $class_name
1239
-                        )
1240
-                    );
1241
-                }
1242
-            }
1243
-        }
1244
-        return $arguments;
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * @param string $class_name
1251
-     * @param string $param_class
1252
-     * @param array  $arguments
1253
-     * @param mixed  $index
1254
-     * @param array  $argument_keys
1255
-     * @return array
1256
-     * @throws EE_Error
1257
-     * @throws ReflectionException
1258
-     * @throws InvalidArgumentException
1259
-     * @throws InvalidInterfaceException
1260
-     * @throws InvalidDataTypeException
1261
-     */
1262
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1263
-    {
1264
-        $dependency = null;
1265
-        // should dependency be loaded from cache ?
1266
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1267
-            $class_name,
1268
-            $param_class
1269
-        );
1270
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1271
-        // we might have a dependency...
1272
-        // let's MAYBE try and find it in our cache if that's what's been requested
1273
-        $cached_class = $cache_on
1274
-            ? $this->_get_cached_class($param_class)
1275
-            : null;
1276
-        // and grab it if it exists
1277
-        if ($cached_class instanceof $param_class) {
1278
-            $dependency = $cached_class;
1279
-        } else if ($param_class !== $class_name) {
1280
-            // obtain the loader method from the dependency map
1281
-            $loader = $this->_dependency_map->class_loader($param_class);
1282
-            // is loader a custom closure ?
1283
-            if ($loader instanceof Closure) {
1284
-                $dependency = $loader($arguments);
1285
-            } else {
1286
-                // set the cache on property for the recursive loading call
1287
-                $this->_cache_on = $cache_on;
1288
-                // if not, then let's try and load it via the registry
1289
-                if ($loader && method_exists($this, $loader)) {
1290
-                    $dependency = $this->{$loader}($param_class);
1291
-                } else {
1292
-                    $dependency = LoaderFactory::getLoader()->load(
1293
-                        $param_class,
1294
-                        array(),
1295
-                        $cache_on
1296
-                    );
1297
-                }
1298
-            }
1299
-        }
1300
-        // did we successfully find the correct dependency ?
1301
-        if ($dependency instanceof $param_class) {
1302
-            // then let's inject it into the incoming array of arguments at the correct location
1303
-            $arguments[$index] = $dependency;
1304
-        }
1305
-        return $arguments;
1306
-    }
1307
-
1308
-
1309
-
1310
-    /**
1311
-     * _set_cached_class
1312
-     * attempts to cache the instantiated class locally
1313
-     * in one of the following places, in the following order:
1314
-     *        $this->{class_abbreviation}   ie:    $this->CART
1315
-     *        $this->{$class_name}          ie:    $this->Some_Class
1316
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1317
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1318
-     *
1319
-     * @param object $class_obj
1320
-     * @param string $class_name
1321
-     * @param string $class_prefix
1322
-     * @param bool   $from_db
1323
-     * @return void
1324
-     */
1325
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1326
-    {
1327
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1328
-            return;
1329
-        }
1330
-        // return newly instantiated class
1331
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1332
-        if ($class_abbreviation) {
1333
-            $this->{$class_abbreviation} = $class_obj;
1334
-            return;
1335
-        }
1336
-        $class_name = str_replace('\\', '_', $class_name);
1337
-        if (property_exists($this, $class_name)) {
1338
-            $this->{$class_name} = $class_obj;
1339
-            return;
1340
-        }
1341
-        if ($class_prefix === 'addon') {
1342
-            $this->addons->{$class_name} = $class_obj;
1343
-            return;
1344
-        }
1345
-        if (! $from_db) {
1346
-            $this->LIB->{$class_name} = $class_obj;
1347
-        }
1348
-    }
1349
-
1350
-
1351
-
1352
-    /**
1353
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1354
-     *
1355
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1356
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1357
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1358
-     * @param array  $arguments
1359
-     * @return object
1360
-     */
1361
-    public static function factory($classname, $arguments = array())
1362
-    {
1363
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1364
-        if ($loader instanceof Closure) {
1365
-            return $loader($arguments);
1366
-        }
1367
-        if (method_exists(self::instance(), $loader)) {
1368
-            return self::instance()->{$loader}($classname, $arguments);
1369
-        }
1370
-        return null;
1371
-    }
1372
-
1373
-
1374
-
1375
-    /**
1376
-     * Gets the addon by its name/slug (not classname. For that, just
1377
-     * use the classname as the property name on EE_Config::instance()->addons)
1378
-     *
1379
-     * @param string $name
1380
-     * @return EE_Addon
1381
-     */
1382
-    public function get_addon_by_name($name)
1383
-    {
1384
-        foreach ($this->addons as $addon) {
1385
-            if ($addon->name() === $name) {
1386
-                return $addon;
1387
-            }
1388
-        }
1389
-        return null;
1390
-    }
1391
-
1392
-
1393
-
1394
-    /**
1395
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1396
-     * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1397
-     * name is the addon's classname. So if you just want to get the addon by classname, use
1398
-     * EE_Config::instance()->addons->{classname}
1399
-     *
1400
-     * @return EE_Addon[] where the KEYS are the addon's name()
1401
-     */
1402
-    public function get_addons_by_name()
1403
-    {
1404
-        $addons = array();
1405
-        foreach ($this->addons as $addon) {
1406
-            $addons[$addon->name()] = $addon;
1407
-        }
1408
-        return $addons;
1409
-    }
1410
-
1411
-
1412
-
1413
-    /**
1414
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1415
-     * a stale copy of it around
1416
-     *
1417
-     * @param string $model_name
1418
-     * @return \EEM_Base
1419
-     * @throws \EE_Error
1420
-     */
1421
-    public function reset_model($model_name)
1422
-    {
1423
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1424
-            ? "EEM_{$model_name}"
1425
-            : $model_name;
1426
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1427
-            return null;
1428
-        }
1429
-        //get that model reset it and make sure we nuke the old reference to it
1430
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1431
-            && is_callable(
1432
-                array($model_class_name, 'reset')
1433
-            )) {
1434
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1435
-        } else {
1436
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1437
-        }
1438
-        return $this->LIB->{$model_class_name};
1439
-    }
1440
-
1441
-
1442
-
1443
-    /**
1444
-     * Resets the registry.
1445
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1446
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1447
-     * - $_dependency_map
1448
-     * - $_class_abbreviations
1449
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1450
-     * - $REQ:  Still on the same request so no need to change.
1451
-     * - $CAP: There is no site specific state in the EE_Capability class.
1452
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1453
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1454
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1455
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1456
-     *             switch or on the restore.
1457
-     * - $modules
1458
-     * - $shortcodes
1459
-     * - $widgets
1460
-     *
1461
-     * @param boolean $hard             [deprecated]
1462
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1463
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1464
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1465
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1466
-     *                                  client
1467
-     *                                  code instead can just change the model context to a different blog id if
1468
-     *                                  necessary
1469
-     * @return EE_Registry
1470
-     * @throws EE_Error
1471
-     * @throws ReflectionException
1472
-     */
1473
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1474
-    {
1475
-        $instance = self::instance();
1476
-        $instance->_cache_on = true;
1477
-        // reset some "special" classes
1478
-        EEH_Activation::reset();
1479
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1480
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1481
-        $instance->CART = null;
1482
-        $instance->MRM = null;
1483
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1484
-        //messages reset
1485
-        EED_Messages::reset();
1486
-        //handle of objects cached on LIB
1487
-        foreach (array('LIB', 'modules') as $cache) {
1488
-            foreach ($instance->{$cache} as $class_name => $class) {
1489
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1490
-                    unset($instance->{$cache}->{$class_name});
1491
-                }
1492
-            }
1493
-        }
1494
-        return $instance;
1495
-    }
1496
-
1497
-
1498
-
1499
-    /**
1500
-     * if passed object implements ResettableInterface, then call it's reset() method
1501
-     * if passed object implements InterminableInterface, then return false,
1502
-     * to indicate that it should NOT be cleared from the Registry cache
1503
-     *
1504
-     * @param      $object
1505
-     * @param bool $reset_models
1506
-     * @return bool returns true if cached object should be unset
1507
-     */
1508
-    private static function _reset_and_unset_object($object, $reset_models)
1509
-    {
1510
-        if (! is_object($object)) {
1511
-            // don't unset anything that's not an object
1512
-            return false;
1513
-        }
1514
-        if ($object instanceof EED_Module) {
1515
-            $object::reset();
1516
-            // don't unset modules
1517
-            return false;
1518
-        }
1519
-        if ($object instanceof ResettableInterface) {
1520
-            if ($object instanceof EEM_Base) {
1521
-                if ($reset_models) {
1522
-                    $object->reset();
1523
-                    return true;
1524
-                }
1525
-                return false;
1526
-            }
1527
-            $object->reset();
1528
-            return true;
1529
-        }
1530
-        if (! $object instanceof InterminableInterface) {
1531
-            return true;
1532
-        }
1533
-        return false;
1534
-    }
1535
-
1536
-
1537
-
1538
-    /**
1539
-     * Gets all the custom post type models defined
1540
-     *
1541
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1542
-     */
1543
-    public function cpt_models()
1544
-    {
1545
-        $cpt_models = array();
1546
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1547
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1548
-                $cpt_models[$short_name] = $classname;
1549
-            }
1550
-        }
1551
-        return $cpt_models;
1552
-    }
1553
-
1554
-
1555
-
1556
-    /**
1557
-     * @return \EE_Config
1558
-     */
1559
-    public static function CFG()
1560
-    {
1561
-        return self::instance()->CFG;
1562
-    }
25
+	/**
26
+	 * @var EE_Registry $_instance
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 * @var EE_Dependency_Map $_dependency_map
32
+	 */
33
+	protected $_dependency_map;
34
+
35
+	/**
36
+	 * @var array $_class_abbreviations
37
+	 */
38
+	protected $_class_abbreviations = array();
39
+
40
+	/**
41
+	 * @var CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 * @var EE_Cart $CART
47
+	 */
48
+	public $CART;
49
+
50
+	/**
51
+	 * @var EE_Config $CFG
52
+	 */
53
+	public $CFG;
54
+
55
+	/**
56
+	 * @var EE_Network_Config $NET_CFG
57
+	 */
58
+	public $NET_CFG;
59
+
60
+	/**
61
+	 * StdClass object for storing library classes in
62
+	 *
63
+	 * @var StdClass $LIB
64
+	 */
65
+	public $LIB;
66
+
67
+	/**
68
+	 * @var EE_Request_Handler $REQ
69
+	 */
70
+	public $REQ;
71
+
72
+	/**
73
+	 * @var EE_Session $SSN
74
+	 */
75
+	public $SSN;
76
+
77
+	/**
78
+	 * @since 4.5.0
79
+	 * @var EE_Capabilities $CAP
80
+	 */
81
+	public $CAP;
82
+
83
+	/**
84
+	 * @since 4.9.0
85
+	 * @var EE_Message_Resource_Manager $MRM
86
+	 */
87
+	public $MRM;
88
+
89
+
90
+	/**
91
+	 * @var Registry $AssetsRegistry
92
+	 */
93
+	public $AssetsRegistry;
94
+
95
+	/**
96
+	 * StdClass object for holding addons which have registered themselves to work with EE core
97
+	 *
98
+	 * @var EE_Addon[] $addons
99
+	 */
100
+	public $addons;
101
+
102
+	/**
103
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
104
+	 *
105
+	 * @var EEM_Base[] $models
106
+	 */
107
+	public $models = array();
108
+
109
+	/**
110
+	 * @var EED_Module[] $modules
111
+	 */
112
+	public $modules;
113
+
114
+	/**
115
+	 * @var EES_Shortcode[] $shortcodes
116
+	 */
117
+	public $shortcodes;
118
+
119
+	/**
120
+	 * @var WP_Widget[] $widgets
121
+	 */
122
+	public $widgets;
123
+
124
+	/**
125
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
126
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
127
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
128
+	 * classnames (eg "EEM_Event")
129
+	 *
130
+	 * @var array $non_abstract_db_models
131
+	 */
132
+	public $non_abstract_db_models = array();
133
+
134
+
135
+	/**
136
+	 * internationalization for JS strings
137
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
138
+	 *    in js file:  var translatedString = eei18n.string_key;
139
+	 *
140
+	 * @var array $i18n_js_strings
141
+	 */
142
+	public static $i18n_js_strings = array();
143
+
144
+
145
+	/**
146
+	 * $main_file - path to espresso.php
147
+	 *
148
+	 * @var array $main_file
149
+	 */
150
+	public $main_file;
151
+
152
+	/**
153
+	 * array of ReflectionClass objects where the key is the class name
154
+	 *
155
+	 * @var ReflectionClass[] $_reflectors
156
+	 */
157
+	public $_reflectors;
158
+
159
+	/**
160
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
161
+	 *
162
+	 * @var boolean $_cache_on
163
+	 */
164
+	protected $_cache_on = true;
165
+
166
+
167
+
168
+	/**
169
+	 * @singleton method used to instantiate class object
170
+	 * @param  EE_Dependency_Map $dependency_map
171
+	 * @return EE_Registry instance
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidInterfaceException
174
+	 * @throws InvalidDataTypeException
175
+	 */
176
+	public static function instance(EE_Dependency_Map $dependency_map = null)
177
+	{
178
+		// check if class object is instantiated
179
+		if (! self::$_instance instanceof EE_Registry) {
180
+			self::$_instance = new self($dependency_map);
181
+		}
182
+		return self::$_instance;
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * protected constructor to prevent direct creation
189
+	 *
190
+	 * @Constructor
191
+	 * @param  EE_Dependency_Map $dependency_map
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @throws InvalidArgumentException
195
+	 */
196
+	protected function __construct(EE_Dependency_Map $dependency_map)
197
+	{
198
+		$this->_dependency_map = $dependency_map;
199
+		$this->LIB = new stdClass();
200
+		$this->addons = new stdClass();
201
+		$this->modules = new stdClass();
202
+		$this->shortcodes = new stdClass();
203
+		$this->widgets = new stdClass();
204
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * initialize
211
+	 *
212
+	 * @throws EE_Error
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function initialize()
216
+	{
217
+		$this->_class_abbreviations = apply_filters(
218
+			'FHEE__EE_Registry____construct___class_abbreviations',
219
+			array(
220
+				'EE_Config'                                       => 'CFG',
221
+				'EE_Session'                                      => 'SSN',
222
+				'EE_Capabilities'                                 => 'CAP',
223
+				'EE_Cart'                                         => 'CART',
224
+				'EE_Network_Config'                               => 'NET_CFG',
225
+				'EE_Request_Handler'                              => 'REQ',
226
+				'EE_Message_Resource_Manager'                     => 'MRM',
227
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
228
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
229
+			)
230
+		);
231
+		$this->load_core('Base', array(), true);
232
+		// add our request and response objects to the cache
233
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
234
+		$this->_set_cached_class(
235
+			$request_loader(),
236
+			'EE_Request'
237
+		);
238
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
239
+		$this->_set_cached_class(
240
+			$response_loader(),
241
+			'EE_Response'
242
+		);
243
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * @return void
250
+	 */
251
+	public function init()
252
+	{
253
+		// Get current page protocol
254
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
255
+		// Output admin-ajax.php URL with same protocol as current page
256
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
257
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * localize_i18n_js_strings
264
+	 *
265
+	 * @return string
266
+	 */
267
+	public static function localize_i18n_js_strings()
268
+	{
269
+		$i18n_js_strings = (array)self::$i18n_js_strings;
270
+		foreach ($i18n_js_strings as $key => $value) {
271
+			if (is_scalar($value)) {
272
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
273
+			}
274
+		}
275
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * @param mixed string | EED_Module $module
282
+	 * @throws EE_Error
283
+	 * @throws ReflectionException
284
+	 */
285
+	public function add_module($module)
286
+	{
287
+		if ($module instanceof EED_Module) {
288
+			$module_class = get_class($module);
289
+			$this->modules->{$module_class} = $module;
290
+		} else {
291
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
292
+				$this->load_core('Module_Request_Router');
293
+			}
294
+			EE_Module_Request_Router::module_factory($module);
295
+		}
296
+	}
297
+
298
+
299
+
300
+	/**
301
+	 * @param string $module_name
302
+	 * @return mixed EED_Module | NULL
303
+	 */
304
+	public function get_module($module_name = '')
305
+	{
306
+		return isset($this->modules->{$module_name})
307
+			? $this->modules->{$module_name}
308
+			: null;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * loads core classes - must be singletons
315
+	 *
316
+	 * @param string $class_name - simple class name ie: session
317
+	 * @param mixed  $arguments
318
+	 * @param bool   $load_only
319
+	 * @return mixed
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public function load_core($class_name, $arguments = array(), $load_only = false)
324
+	{
325
+		$core_paths = apply_filters(
326
+			'FHEE__EE_Registry__load_core__core_paths',
327
+			array(
328
+				EE_CORE,
329
+				EE_ADMIN,
330
+				EE_CPTS,
331
+				EE_CORE . 'data_migration_scripts' . DS,
332
+				EE_CORE . 'capabilities' . DS,
333
+				EE_CORE . 'request_stack' . DS,
334
+				EE_CORE . 'middleware' . DS,
335
+			)
336
+		);
337
+		// retrieve instantiated class
338
+		return $this->_load(
339
+			$core_paths,
340
+			'EE_',
341
+			$class_name,
342
+			'core',
343
+			$arguments,
344
+			false,
345
+			true,
346
+			$load_only
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * loads service classes
354
+	 *
355
+	 * @param string $class_name - simple class name ie: session
356
+	 * @param mixed  $arguments
357
+	 * @param bool   $load_only
358
+	 * @return mixed
359
+	 * @throws EE_Error
360
+	 * @throws ReflectionException
361
+	 */
362
+	public function load_service($class_name, $arguments = array(), $load_only = false)
363
+	{
364
+		$service_paths = apply_filters(
365
+			'FHEE__EE_Registry__load_service__service_paths',
366
+			array(
367
+				EE_CORE . 'services' . DS,
368
+			)
369
+		);
370
+		// retrieve instantiated class
371
+		return $this->_load(
372
+			$service_paths,
373
+			'EE_',
374
+			$class_name,
375
+			'class',
376
+			$arguments,
377
+			false,
378
+			true,
379
+			$load_only
380
+		);
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * loads data_migration_scripts
387
+	 *
388
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
389
+	 * @param mixed  $arguments
390
+	 * @return EE_Data_Migration_Script_Base|mixed
391
+	 * @throws EE_Error
392
+	 * @throws ReflectionException
393
+	 */
394
+	public function load_dms($class_name, $arguments = array())
395
+	{
396
+		// retrieve instantiated class
397
+		return $this->_load(
398
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
399
+			'EE_DMS_',
400
+			$class_name,
401
+			'dms',
402
+			$arguments,
403
+			false,
404
+			false
405
+		);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * loads object creating classes - must be singletons
412
+	 *
413
+	 * @param string $class_name - simple class name ie: attendee
414
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
415
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
416
+	 *                           instantiate
417
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
418
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
419
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
420
+	 *                           (default)
421
+	 * @return EE_Base_Class | bool
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
426
+	{
427
+		$paths = apply_filters(
428
+			'FHEE__EE_Registry__load_class__paths', array(
429
+			EE_CORE,
430
+			EE_CLASSES,
431
+			EE_BUSINESS,
432
+		)
433
+		);
434
+		// retrieve instantiated class
435
+		return $this->_load(
436
+			$paths,
437
+			'EE_',
438
+			$class_name,
439
+			'class',
440
+			$arguments,
441
+			$from_db,
442
+			$cache,
443
+			$load_only
444
+		);
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * loads helper classes - must be singletons
451
+	 *
452
+	 * @param string $class_name - simple class name ie: price
453
+	 * @param mixed  $arguments
454
+	 * @param bool   $load_only
455
+	 * @return EEH_Base | bool
456
+	 * @throws EE_Error
457
+	 * @throws ReflectionException
458
+	 */
459
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
460
+	{
461
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
462
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
463
+		// retrieve instantiated class
464
+		return $this->_load(
465
+			$helper_paths,
466
+			'EEH_',
467
+			$class_name,
468
+			'helper',
469
+			$arguments,
470
+			false,
471
+			true,
472
+			$load_only
473
+		);
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * loads core classes - must be singletons
480
+	 *
481
+	 * @param string $class_name - simple class name ie: session
482
+	 * @param mixed  $arguments
483
+	 * @param bool   $load_only
484
+	 * @param bool   $cache      whether to cache the object or not.
485
+	 * @return mixed
486
+	 * @throws EE_Error
487
+	 * @throws ReflectionException
488
+	 */
489
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
490
+	{
491
+		$paths = array(
492
+			EE_LIBRARIES,
493
+			EE_LIBRARIES . 'messages' . DS,
494
+			EE_LIBRARIES . 'shortcodes' . DS,
495
+			EE_LIBRARIES . 'qtips' . DS,
496
+			EE_LIBRARIES . 'payment_methods' . DS,
497
+			EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
498
+		);
499
+		// retrieve instantiated class
500
+		return $this->_load(
501
+			$paths,
502
+			'EE_',
503
+			$class_name,
504
+			'lib',
505
+			$arguments,
506
+			false,
507
+			$cache,
508
+			$load_only
509
+		);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * loads model classes - must be singletons
516
+	 *
517
+	 * @param string $class_name - simple class name ie: price
518
+	 * @param mixed  $arguments
519
+	 * @param bool   $load_only
520
+	 * @return EEM_Base | bool
521
+	 * @throws EE_Error
522
+	 * @throws ReflectionException
523
+	 */
524
+	public function load_model($class_name, $arguments = array(), $load_only = false)
525
+	{
526
+		$paths = apply_filters(
527
+			'FHEE__EE_Registry__load_model__paths', array(
528
+			EE_MODELS,
529
+			EE_CORE,
530
+		)
531
+		);
532
+		// retrieve instantiated class
533
+		return $this->_load(
534
+			$paths,
535
+			'EEM_',
536
+			$class_name,
537
+			'model',
538
+			$arguments,
539
+			false,
540
+			true,
541
+			$load_only
542
+		);
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * loads model classes - must be singletons
549
+	 *
550
+	 * @param string $class_name - simple class name ie: price
551
+	 * @param mixed  $arguments
552
+	 * @param bool   $load_only
553
+	 * @return mixed | bool
554
+	 * @throws EE_Error
555
+	 * @throws ReflectionException
556
+	 */
557
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
558
+	{
559
+		$paths = array(
560
+			EE_MODELS . 'fields' . DS,
561
+			EE_MODELS . 'helpers' . DS,
562
+			EE_MODELS . 'relations' . DS,
563
+			EE_MODELS . 'strategies' . DS,
564
+		);
565
+		// retrieve instantiated class
566
+		return $this->_load(
567
+			$paths,
568
+			'EE_',
569
+			$class_name,
570
+			'',
571
+			$arguments,
572
+			false,
573
+			true,
574
+			$load_only
575
+		);
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * Determines if $model_name is the name of an actual EE model.
582
+	 *
583
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
584
+	 * @return boolean
585
+	 */
586
+	public function is_model_name($model_name)
587
+	{
588
+		return isset($this->models[$model_name]);
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * generic class loader
595
+	 *
596
+	 * @param string $path_to_file - directory path to file location, not including filename
597
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
598
+	 * @param string $type         - file type - core? class? helper? model?
599
+	 * @param mixed  $arguments
600
+	 * @param bool   $load_only
601
+	 * @return mixed
602
+	 * @throws EE_Error
603
+	 * @throws ReflectionException
604
+	 */
605
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
606
+	{
607
+		// retrieve instantiated class
608
+		return $this->_load(
609
+			$path_to_file,
610
+			'',
611
+			$file_name,
612
+			$type,
613
+			$arguments,
614
+			false,
615
+			true,
616
+			$load_only
617
+		);
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 * @param string $path_to_file - directory path to file location, not including filename
624
+	 * @param string $class_name   - full class name  ie:  My_Class
625
+	 * @param string $type         - file type - core? class? helper? model?
626
+	 * @param mixed  $arguments
627
+	 * @param bool   $load_only
628
+	 * @return bool|EE_Addon|object
629
+	 * @throws EE_Error
630
+	 * @throws ReflectionException
631
+	 */
632
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
633
+	{
634
+		// retrieve instantiated class
635
+		return $this->_load(
636
+			$path_to_file,
637
+			'addon',
638
+			$class_name,
639
+			$type,
640
+			$arguments,
641
+			false,
642
+			true,
643
+			$load_only
644
+		);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * instantiates, caches, and automatically resolves dependencies
651
+	 * for classes that use a Fully Qualified Class Name.
652
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
653
+	 * then you need to use one of the existing load_*() methods
654
+	 * which can resolve the classname and filepath from the passed arguments
655
+	 *
656
+	 * @param bool|string $class_name   Fully Qualified Class Name
657
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
658
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
659
+	 * @param bool        $from_db      some classes are instantiated from the db
660
+	 *                                  and thus call a different method to instantiate
661
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
662
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
663
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
664
+	 *                                  object = class loaded and instantiated successfully.
665
+	 *                                  bool = fail or success when $load_only is true
666
+	 * @throws EE_Error
667
+	 * @throws ReflectionException
668
+	 */
669
+	public function create(
670
+		$class_name = false,
671
+		$arguments = array(),
672
+		$cache = false,
673
+		$from_db = false,
674
+		$load_only = false,
675
+		$addon = false
676
+	) {
677
+		$class_name = ltrim($class_name, '\\');
678
+		$class_name = $this->_dependency_map->get_alias($class_name);
679
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
680
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
681
+		// or it could return null if the class just could not be found anywhere
682
+		if ($class_exists instanceof $class_name || $class_exists === null){
683
+			// either way, return the results
684
+			return $class_exists;
685
+		}
686
+		$class_name = $class_exists;
687
+		// if we're only loading the class and it already exists, then let's just return true immediately
688
+		if ($load_only) {
689
+			return true;
690
+		}
691
+		$addon = $addon
692
+			? 'addon'
693
+			: '';
694
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
695
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
696
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
697
+		if ($this->_cache_on && $cache && ! $load_only) {
698
+			// return object if it's already cached
699
+			$cached_class = $this->_get_cached_class($class_name, $addon);
700
+			if ($cached_class !== null) {
701
+				return $cached_class;
702
+			}
703
+		}
704
+		// obtain the loader method from the dependency map
705
+		$loader = $this->_dependency_map->class_loader($class_name);
706
+		// instantiate the requested object
707
+		if ($loader instanceof Closure) {
708
+			$class_obj = $loader($arguments);
709
+		} else if ($loader && method_exists($this, $loader)) {
710
+			$class_obj = $this->{$loader}($class_name, $arguments);
711
+		} else {
712
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
713
+		}
714
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
715
+			// save it for later... kinda like gum  { : $
716
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
717
+		}
718
+		$this->_cache_on = true;
719
+		return $class_obj;
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
726
+	 *
727
+	 * @param string $class_name
728
+	 * @param array  $arguments
729
+	 * @param int    $attempt
730
+	 * @return mixed
731
+	 */
732
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
733
+		if (is_object($class_name) || class_exists($class_name)) {
734
+			return $class_name;
735
+		}
736
+		switch ($attempt) {
737
+			case 1:
738
+				// if it's a FQCN then maybe the class is registered with a preceding \
739
+				$class_name = strpos($class_name, '\\') !== false
740
+					? '\\' . ltrim($class_name, '\\')
741
+					: $class_name;
742
+				break;
743
+			case 2:
744
+				//
745
+				$loader = $this->_dependency_map->class_loader($class_name);
746
+				if ($loader && method_exists($this, $loader)) {
747
+					return $this->{$loader}($class_name, $arguments);
748
+				}
749
+				break;
750
+			case 3:
751
+			default;
752
+				return null;
753
+		}
754
+		$attempt++;
755
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
756
+	}
757
+
758
+
759
+
760
+	/**
761
+	 * instantiates, caches, and injects dependencies for classes
762
+	 *
763
+	 * @param array       $file_paths   an array of paths to folders to look in
764
+	 * @param string      $class_prefix EE  or EEM or... ???
765
+	 * @param bool|string $class_name   $class name
766
+	 * @param string      $type         file type - core? class? helper? model?
767
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
768
+	 * @param bool        $from_db      some classes are instantiated from the db
769
+	 *                                  and thus call a different method to instantiate
770
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
771
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
772
+	 * @return bool|null|object null = failure to load or instantiate class object.
773
+	 *                                  object = class loaded and instantiated successfully.
774
+	 *                                  bool = fail or success when $load_only is true
775
+	 * @throws EE_Error
776
+	 * @throws ReflectionException
777
+	 */
778
+	protected function _load(
779
+		$file_paths = array(),
780
+		$class_prefix = 'EE_',
781
+		$class_name = false,
782
+		$type = 'class',
783
+		$arguments = array(),
784
+		$from_db = false,
785
+		$cache = true,
786
+		$load_only = false
787
+	) {
788
+		$class_name = ltrim($class_name, '\\');
789
+		// strip php file extension
790
+		$class_name = str_replace('.php', '', trim($class_name));
791
+		// does the class have a prefix ?
792
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
793
+			// make sure $class_prefix is uppercase
794
+			$class_prefix = strtoupper(trim($class_prefix));
795
+			// add class prefix ONCE!!!
796
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
797
+		}
798
+		$class_name = $this->_dependency_map->get_alias($class_name);
799
+		$class_exists = class_exists($class_name, false);
800
+		// if we're only loading the class and it already exists, then let's just return true immediately
801
+		if ($load_only && $class_exists) {
802
+			return true;
803
+		}
804
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
805
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
806
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
807
+		if ($this->_cache_on && $cache && ! $load_only) {
808
+			// return object if it's already cached
809
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
810
+			if ($cached_class !== null) {
811
+				return $cached_class;
812
+			}
813
+		}
814
+		// if the class doesn't already exist.. then we need to try and find the file and load it
815
+		if (! $class_exists) {
816
+			// get full path to file
817
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
818
+			// load the file
819
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
820
+			// if loading failed, or we are only loading a file but NOT instantiating an object
821
+			if (! $loaded || $load_only) {
822
+				// return boolean if only loading, or null if an object was expected
823
+				return $load_only
824
+					? $loaded
825
+					: null;
826
+			}
827
+		}
828
+		// instantiate the requested object
829
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
830
+		if ($this->_cache_on && $cache) {
831
+			// save it for later... kinda like gum  { : $
832
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
833
+		}
834
+		$this->_cache_on = true;
835
+		return $class_obj;
836
+	}
837
+
838
+
839
+
840
+	/**
841
+	 * @param string $class_name
842
+	 * @param string $default have to specify something, but not anything that will conflict
843
+	 * @return mixed|string
844
+	 */
845
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
846
+	{
847
+		return isset($this->_class_abbreviations[$class_name])
848
+			? $this->_class_abbreviations[$class_name]
849
+			: $default;
850
+	}
851
+
852
+	/**
853
+	 * attempts to find a cached version of the requested class
854
+	 * by looking in the following places:
855
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
856
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
857
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
858
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
859
+	 *
860
+	 * @param string $class_name
861
+	 * @param string $class_prefix
862
+	 * @return mixed
863
+	 */
864
+	protected function _get_cached_class($class_name, $class_prefix = '')
865
+	{
866
+		if ($class_name === 'EE_Registry') {
867
+			return $this;
868
+		}
869
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
870
+		$class_name = str_replace('\\', '_', $class_name);
871
+		// check if class has already been loaded, and return it if it has been
872
+		if (isset($this->{$class_abbreviation})) {
873
+			return $this->{$class_abbreviation};
874
+		}
875
+		if (isset ($this->{$class_name})) {
876
+			return $this->{$class_name};
877
+		}
878
+		if (isset ($this->LIB->{$class_name})) {
879
+			return $this->LIB->{$class_name};
880
+		}
881
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
882
+			return $this->addons->{$class_name};
883
+		}
884
+		return null;
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * removes a cached version of the requested class
891
+	 *
892
+	 * @param string  $class_name
893
+	 * @param boolean $addon
894
+	 * @return boolean
895
+	 */
896
+	public function clear_cached_class($class_name, $addon = false)
897
+	{
898
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
899
+		$class_name = str_replace('\\', '_', $class_name);
900
+		// check if class has already been loaded, and return it if it has been
901
+		if (isset($this->{$class_abbreviation})) {
902
+			$this->{$class_abbreviation} = null;
903
+			return true;
904
+		}
905
+		if (isset($this->{$class_name})) {
906
+			$this->{$class_name} = null;
907
+			return true;
908
+		}
909
+		if (isset($this->LIB->{$class_name})) {
910
+			unset($this->LIB->{$class_name});
911
+			return true;
912
+		}
913
+		if ($addon && isset($this->addons->{$class_name})) {
914
+			unset($this->addons->{$class_name});
915
+			return true;
916
+		}
917
+		return false;
918
+	}
919
+
920
+
921
+
922
+	/**
923
+	 * attempts to find a full valid filepath for the requested class.
924
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
925
+	 * then returns that path if the target file has been found and is readable
926
+	 *
927
+	 * @param string $class_name
928
+	 * @param string $type
929
+	 * @param array  $file_paths
930
+	 * @return string | bool
931
+	 */
932
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
933
+	{
934
+		// make sure $file_paths is an array
935
+		$file_paths = is_array($file_paths)
936
+			? $file_paths
937
+			: array($file_paths);
938
+		// cycle thru paths
939
+		foreach ($file_paths as $key => $file_path) {
940
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
941
+			$file_path = $file_path
942
+				? str_replace(array('/', '\\'), DS, $file_path)
943
+				: EE_CLASSES;
944
+			// prep file type
945
+			$type = ! empty($type)
946
+				? trim($type, '.') . '.'
947
+				: '';
948
+			// build full file path
949
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
950
+			//does the file exist and can be read ?
951
+			if (is_readable($file_paths[$key])) {
952
+				return $file_paths[$key];
953
+			}
954
+		}
955
+		return false;
956
+	}
957
+
958
+
959
+
960
+	/**
961
+	 * basically just performs a require_once()
962
+	 * but with some error handling
963
+	 *
964
+	 * @param  string $path
965
+	 * @param  string $class_name
966
+	 * @param  string $type
967
+	 * @param  array  $file_paths
968
+	 * @return bool
969
+	 * @throws EE_Error
970
+	 * @throws ReflectionException
971
+	 */
972
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
973
+	{
974
+		$this->resolve_legacy_class_parent($class_name);
975
+		// don't give up! you gotta...
976
+		try {
977
+			//does the file exist and can it be read ?
978
+			if (! $path) {
979
+				// so sorry, can't find the file
980
+				throw new EE_Error (
981
+					sprintf(
982
+						esc_html__(
983
+							'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
984
+							'event_espresso'
985
+						),
986
+						trim($type, '.'),
987
+						$class_name,
988
+						'<br />' . implode(',<br />', $file_paths)
989
+					)
990
+				);
991
+			}
992
+			// get the file
993
+			require_once($path);
994
+			// if the class isn't already declared somewhere
995
+			if (class_exists($class_name, false) === false) {
996
+				// so sorry, not a class
997
+				throw new EE_Error(
998
+					sprintf(
999
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1000
+						$type,
1001
+						$path,
1002
+						$class_name
1003
+					)
1004
+				);
1005
+			}
1006
+		} catch (EE_Error $e) {
1007
+			$e->get_error();
1008
+			return false;
1009
+		}
1010
+		return true;
1011
+	}
1012
+
1013
+
1014
+
1015
+	/**
1016
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1017
+	 * before their class declaration in order to ensure that the parent class was loaded.
1018
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1019
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1020
+	 *
1021
+	 * @param string $class_name
1022
+	 */
1023
+	protected function resolve_legacy_class_parent($class_name = '')
1024
+	{
1025
+		try {
1026
+			$legacy_parent_class_map = array(
1027
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1028
+			);
1029
+			if(isset($legacy_parent_class_map[$class_name])) {
1030
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1031
+			}
1032
+		} catch (Exception $exception) {
1033
+		}
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * _create_object
1040
+	 * Attempts to instantiate the requested class via any of the
1041
+	 * commonly used instantiation methods employed throughout EE.
1042
+	 * The priority for instantiation is as follows:
1043
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1044
+	 *        - model objects via their 'new_instance_from_db' method
1045
+	 *        - model objects via their 'new_instance' method
1046
+	 *        - "singleton" classes" via their 'instance' method
1047
+	 *    - standard instantiable classes via their __constructor
1048
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1049
+	 * then the constructor for the requested class will be examined to determine
1050
+	 * if any dependencies exist, and if they can be injected.
1051
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1052
+	 *
1053
+	 * @param string $class_name
1054
+	 * @param array  $arguments
1055
+	 * @param string $type
1056
+	 * @param bool   $from_db
1057
+	 * @return null|object
1058
+	 * @throws EE_Error
1059
+	 * @throws ReflectionException
1060
+	 */
1061
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1062
+	{
1063
+		// create reflection
1064
+		$reflector = $this->get_ReflectionClass($class_name);
1065
+		// make sure arguments are an array
1066
+		$arguments = is_array($arguments)
1067
+			? $arguments
1068
+			: array($arguments);
1069
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1070
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1071
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1072
+			? $arguments
1073
+			: array($arguments);
1074
+		// attempt to inject dependencies ?
1075
+		if ($this->_dependency_map->has($class_name)) {
1076
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1077
+		}
1078
+		// instantiate the class if possible
1079
+		if ($reflector->isAbstract()) {
1080
+			// nothing to instantiate, loading file was enough
1081
+			// does not throw an exception so $instantiation_mode is unused
1082
+			// $instantiation_mode = "1) no constructor abstract class";
1083
+			return true;
1084
+		}
1085
+		if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1086
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1087
+			// $instantiation_mode = "2) no constructor but instantiable";
1088
+			return $reflector->newInstance();
1089
+		}
1090
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1091
+			// $instantiation_mode = "3) new_instance_from_db()";
1092
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1093
+		}
1094
+		if (method_exists($class_name, 'new_instance')) {
1095
+			// $instantiation_mode = "4) new_instance()";
1096
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1097
+		}
1098
+		if (method_exists($class_name, 'instance')) {
1099
+			// $instantiation_mode = "5) instance()";
1100
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1101
+		}
1102
+		if ($reflector->isInstantiable()) {
1103
+			// $instantiation_mode = "6) constructor";
1104
+			return $reflector->newInstanceArgs($arguments);
1105
+		}
1106
+		// heh ? something's not right !
1107
+		throw new EE_Error(
1108
+			sprintf(
1109
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1110
+				$type,
1111
+				$class_name
1112
+			)
1113
+		);
1114
+	}
1115
+
1116
+
1117
+
1118
+	/**
1119
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1120
+	 * @param array $array
1121
+	 * @return bool
1122
+	 */
1123
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1124
+	{
1125
+		return ! empty($array)
1126
+			? array_keys($array) === range(0, count($array) - 1)
1127
+			: true;
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * getReflectionClass
1134
+	 * checks if a ReflectionClass object has already been generated for a class
1135
+	 * and returns that instead of creating a new one
1136
+	 *
1137
+	 * @param string $class_name
1138
+	 * @return ReflectionClass
1139
+	 * @throws ReflectionException
1140
+	 */
1141
+	public function get_ReflectionClass($class_name)
1142
+	{
1143
+		if (
1144
+			! isset($this->_reflectors[$class_name])
1145
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1146
+		) {
1147
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1148
+		}
1149
+		return $this->_reflectors[$class_name];
1150
+	}
1151
+
1152
+
1153
+
1154
+	/**
1155
+	 * _resolve_dependencies
1156
+	 * examines the constructor for the requested class to determine
1157
+	 * if any dependencies exist, and if they can be injected.
1158
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1159
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1160
+	 * For example:
1161
+	 *        if attempting to load a class "Foo" with the following constructor:
1162
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1163
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1164
+	 *        but only IF they are NOT already present in the incoming arguments array,
1165
+	 *        and the correct classes can be loaded
1166
+	 *
1167
+	 * @param ReflectionClass $reflector
1168
+	 * @param string          $class_name
1169
+	 * @param array           $arguments
1170
+	 * @return array
1171
+	 * @throws EE_Error
1172
+	 * @throws ReflectionException
1173
+	 */
1174
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1175
+	{
1176
+		// let's examine the constructor
1177
+		$constructor = $reflector->getConstructor();
1178
+		// whu? huh? nothing?
1179
+		if (! $constructor) {
1180
+			return $arguments;
1181
+		}
1182
+		// get constructor parameters
1183
+		$params = $constructor->getParameters();
1184
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1185
+		$argument_keys = array_keys($arguments);
1186
+		// now loop thru all of the constructors expected parameters
1187
+		foreach ($params as $index => $param) {
1188
+			// is this a dependency for a specific class ?
1189
+			$param_class = $param->getClass()
1190
+				? $param->getClass()->name
1191
+				: null;
1192
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1193
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1194
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1195
+				: $param_class;
1196
+			if (
1197
+				// param is not even a class
1198
+				$param_class === null
1199
+				// and something already exists in the incoming arguments for this param
1200
+				&& array_key_exists($index, $argument_keys)
1201
+				&& array_key_exists($argument_keys[$index], $arguments)
1202
+			) {
1203
+				// so let's skip this argument and move on to the next
1204
+				continue;
1205
+			}
1206
+			if (
1207
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1208
+				$param_class !== null
1209
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1210
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1211
+			) {
1212
+				// skip this argument and move on to the next
1213
+				continue;
1214
+			}
1215
+			if (
1216
+				// parameter is type hinted as a class, and should be injected
1217
+				$param_class !== null
1218
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1219
+			) {
1220
+				$arguments = $this->_resolve_dependency(
1221
+					$class_name,
1222
+					$param_class,
1223
+					$arguments,
1224
+					$index,
1225
+					$argument_keys
1226
+				);
1227
+			} else {
1228
+				try {
1229
+					$arguments[$index] = $param->isDefaultValueAvailable()
1230
+						? $param->getDefaultValue()
1231
+						: null;
1232
+				} catch (ReflectionException $e) {
1233
+					throw new ReflectionException(
1234
+						sprintf(
1235
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1236
+							$e->getMessage(),
1237
+							$param->getName(),
1238
+							$class_name
1239
+						)
1240
+					);
1241
+				}
1242
+			}
1243
+		}
1244
+		return $arguments;
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * @param string $class_name
1251
+	 * @param string $param_class
1252
+	 * @param array  $arguments
1253
+	 * @param mixed  $index
1254
+	 * @param array  $argument_keys
1255
+	 * @return array
1256
+	 * @throws EE_Error
1257
+	 * @throws ReflectionException
1258
+	 * @throws InvalidArgumentException
1259
+	 * @throws InvalidInterfaceException
1260
+	 * @throws InvalidDataTypeException
1261
+	 */
1262
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1263
+	{
1264
+		$dependency = null;
1265
+		// should dependency be loaded from cache ?
1266
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1267
+			$class_name,
1268
+			$param_class
1269
+		);
1270
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1271
+		// we might have a dependency...
1272
+		// let's MAYBE try and find it in our cache if that's what's been requested
1273
+		$cached_class = $cache_on
1274
+			? $this->_get_cached_class($param_class)
1275
+			: null;
1276
+		// and grab it if it exists
1277
+		if ($cached_class instanceof $param_class) {
1278
+			$dependency = $cached_class;
1279
+		} else if ($param_class !== $class_name) {
1280
+			// obtain the loader method from the dependency map
1281
+			$loader = $this->_dependency_map->class_loader($param_class);
1282
+			// is loader a custom closure ?
1283
+			if ($loader instanceof Closure) {
1284
+				$dependency = $loader($arguments);
1285
+			} else {
1286
+				// set the cache on property for the recursive loading call
1287
+				$this->_cache_on = $cache_on;
1288
+				// if not, then let's try and load it via the registry
1289
+				if ($loader && method_exists($this, $loader)) {
1290
+					$dependency = $this->{$loader}($param_class);
1291
+				} else {
1292
+					$dependency = LoaderFactory::getLoader()->load(
1293
+						$param_class,
1294
+						array(),
1295
+						$cache_on
1296
+					);
1297
+				}
1298
+			}
1299
+		}
1300
+		// did we successfully find the correct dependency ?
1301
+		if ($dependency instanceof $param_class) {
1302
+			// then let's inject it into the incoming array of arguments at the correct location
1303
+			$arguments[$index] = $dependency;
1304
+		}
1305
+		return $arguments;
1306
+	}
1307
+
1308
+
1309
+
1310
+	/**
1311
+	 * _set_cached_class
1312
+	 * attempts to cache the instantiated class locally
1313
+	 * in one of the following places, in the following order:
1314
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1315
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1316
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1317
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1318
+	 *
1319
+	 * @param object $class_obj
1320
+	 * @param string $class_name
1321
+	 * @param string $class_prefix
1322
+	 * @param bool   $from_db
1323
+	 * @return void
1324
+	 */
1325
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1326
+	{
1327
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1328
+			return;
1329
+		}
1330
+		// return newly instantiated class
1331
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1332
+		if ($class_abbreviation) {
1333
+			$this->{$class_abbreviation} = $class_obj;
1334
+			return;
1335
+		}
1336
+		$class_name = str_replace('\\', '_', $class_name);
1337
+		if (property_exists($this, $class_name)) {
1338
+			$this->{$class_name} = $class_obj;
1339
+			return;
1340
+		}
1341
+		if ($class_prefix === 'addon') {
1342
+			$this->addons->{$class_name} = $class_obj;
1343
+			return;
1344
+		}
1345
+		if (! $from_db) {
1346
+			$this->LIB->{$class_name} = $class_obj;
1347
+		}
1348
+	}
1349
+
1350
+
1351
+
1352
+	/**
1353
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1354
+	 *
1355
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1356
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1357
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1358
+	 * @param array  $arguments
1359
+	 * @return object
1360
+	 */
1361
+	public static function factory($classname, $arguments = array())
1362
+	{
1363
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1364
+		if ($loader instanceof Closure) {
1365
+			return $loader($arguments);
1366
+		}
1367
+		if (method_exists(self::instance(), $loader)) {
1368
+			return self::instance()->{$loader}($classname, $arguments);
1369
+		}
1370
+		return null;
1371
+	}
1372
+
1373
+
1374
+
1375
+	/**
1376
+	 * Gets the addon by its name/slug (not classname. For that, just
1377
+	 * use the classname as the property name on EE_Config::instance()->addons)
1378
+	 *
1379
+	 * @param string $name
1380
+	 * @return EE_Addon
1381
+	 */
1382
+	public function get_addon_by_name($name)
1383
+	{
1384
+		foreach ($this->addons as $addon) {
1385
+			if ($addon->name() === $name) {
1386
+				return $addon;
1387
+			}
1388
+		}
1389
+		return null;
1390
+	}
1391
+
1392
+
1393
+
1394
+	/**
1395
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1396
+	 * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1397
+	 * name is the addon's classname. So if you just want to get the addon by classname, use
1398
+	 * EE_Config::instance()->addons->{classname}
1399
+	 *
1400
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1401
+	 */
1402
+	public function get_addons_by_name()
1403
+	{
1404
+		$addons = array();
1405
+		foreach ($this->addons as $addon) {
1406
+			$addons[$addon->name()] = $addon;
1407
+		}
1408
+		return $addons;
1409
+	}
1410
+
1411
+
1412
+
1413
+	/**
1414
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1415
+	 * a stale copy of it around
1416
+	 *
1417
+	 * @param string $model_name
1418
+	 * @return \EEM_Base
1419
+	 * @throws \EE_Error
1420
+	 */
1421
+	public function reset_model($model_name)
1422
+	{
1423
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1424
+			? "EEM_{$model_name}"
1425
+			: $model_name;
1426
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1427
+			return null;
1428
+		}
1429
+		//get that model reset it and make sure we nuke the old reference to it
1430
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1431
+			&& is_callable(
1432
+				array($model_class_name, 'reset')
1433
+			)) {
1434
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1435
+		} else {
1436
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1437
+		}
1438
+		return $this->LIB->{$model_class_name};
1439
+	}
1440
+
1441
+
1442
+
1443
+	/**
1444
+	 * Resets the registry.
1445
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1446
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1447
+	 * - $_dependency_map
1448
+	 * - $_class_abbreviations
1449
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1450
+	 * - $REQ:  Still on the same request so no need to change.
1451
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1452
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1453
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1454
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1455
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1456
+	 *             switch or on the restore.
1457
+	 * - $modules
1458
+	 * - $shortcodes
1459
+	 * - $widgets
1460
+	 *
1461
+	 * @param boolean $hard             [deprecated]
1462
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1463
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1464
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1465
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1466
+	 *                                  client
1467
+	 *                                  code instead can just change the model context to a different blog id if
1468
+	 *                                  necessary
1469
+	 * @return EE_Registry
1470
+	 * @throws EE_Error
1471
+	 * @throws ReflectionException
1472
+	 */
1473
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1474
+	{
1475
+		$instance = self::instance();
1476
+		$instance->_cache_on = true;
1477
+		// reset some "special" classes
1478
+		EEH_Activation::reset();
1479
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1480
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1481
+		$instance->CART = null;
1482
+		$instance->MRM = null;
1483
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1484
+		//messages reset
1485
+		EED_Messages::reset();
1486
+		//handle of objects cached on LIB
1487
+		foreach (array('LIB', 'modules') as $cache) {
1488
+			foreach ($instance->{$cache} as $class_name => $class) {
1489
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1490
+					unset($instance->{$cache}->{$class_name});
1491
+				}
1492
+			}
1493
+		}
1494
+		return $instance;
1495
+	}
1496
+
1497
+
1498
+
1499
+	/**
1500
+	 * if passed object implements ResettableInterface, then call it's reset() method
1501
+	 * if passed object implements InterminableInterface, then return false,
1502
+	 * to indicate that it should NOT be cleared from the Registry cache
1503
+	 *
1504
+	 * @param      $object
1505
+	 * @param bool $reset_models
1506
+	 * @return bool returns true if cached object should be unset
1507
+	 */
1508
+	private static function _reset_and_unset_object($object, $reset_models)
1509
+	{
1510
+		if (! is_object($object)) {
1511
+			// don't unset anything that's not an object
1512
+			return false;
1513
+		}
1514
+		if ($object instanceof EED_Module) {
1515
+			$object::reset();
1516
+			// don't unset modules
1517
+			return false;
1518
+		}
1519
+		if ($object instanceof ResettableInterface) {
1520
+			if ($object instanceof EEM_Base) {
1521
+				if ($reset_models) {
1522
+					$object->reset();
1523
+					return true;
1524
+				}
1525
+				return false;
1526
+			}
1527
+			$object->reset();
1528
+			return true;
1529
+		}
1530
+		if (! $object instanceof InterminableInterface) {
1531
+			return true;
1532
+		}
1533
+		return false;
1534
+	}
1535
+
1536
+
1537
+
1538
+	/**
1539
+	 * Gets all the custom post type models defined
1540
+	 *
1541
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1542
+	 */
1543
+	public function cpt_models()
1544
+	{
1545
+		$cpt_models = array();
1546
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1547
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1548
+				$cpt_models[$short_name] = $classname;
1549
+			}
1550
+		}
1551
+		return $cpt_models;
1552
+	}
1553
+
1554
+
1555
+
1556
+	/**
1557
+	 * @return \EE_Config
1558
+	 */
1559
+	public static function CFG()
1560
+	{
1561
+		return self::instance()->CFG;
1562
+	}
1563 1563
 
1564 1564
 
1565 1565
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     public static function instance(EE_Dependency_Map $dependency_map = null)
177 177
     {
178 178
         // check if class object is instantiated
179
-        if (! self::$_instance instanceof EE_Registry) {
179
+        if ( ! self::$_instance instanceof EE_Registry) {
180 180
             self::$_instance = new self($dependency_map);
181 181
         }
182 182
         return self::$_instance;
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
      */
267 267
     public static function localize_i18n_js_strings()
268 268
     {
269
-        $i18n_js_strings = (array)self::$i18n_js_strings;
269
+        $i18n_js_strings = (array) self::$i18n_js_strings;
270 270
         foreach ($i18n_js_strings as $key => $value) {
271 271
             if (is_scalar($value)) {
272
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
272
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
273 273
             }
274 274
         }
275
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
275
+        return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */';
276 276
     }
277 277
 
278 278
 
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
                 EE_CORE,
329 329
                 EE_ADMIN,
330 330
                 EE_CPTS,
331
-                EE_CORE . 'data_migration_scripts' . DS,
332
-                EE_CORE . 'capabilities' . DS,
333
-                EE_CORE . 'request_stack' . DS,
334
-                EE_CORE . 'middleware' . DS,
331
+                EE_CORE.'data_migration_scripts'.DS,
332
+                EE_CORE.'capabilities'.DS,
333
+                EE_CORE.'request_stack'.DS,
334
+                EE_CORE.'middleware'.DS,
335 335
             )
336 336
         );
337 337
         // retrieve instantiated class
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         $service_paths = apply_filters(
365 365
             'FHEE__EE_Registry__load_service__service_paths',
366 366
             array(
367
-                EE_CORE . 'services' . DS,
367
+                EE_CORE.'services'.DS,
368 368
             )
369 369
         );
370 370
         // retrieve instantiated class
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
     {
491 491
         $paths = array(
492 492
             EE_LIBRARIES,
493
-            EE_LIBRARIES . 'messages' . DS,
494
-            EE_LIBRARIES . 'shortcodes' . DS,
495
-            EE_LIBRARIES . 'qtips' . DS,
496
-            EE_LIBRARIES . 'payment_methods' . DS,
497
-            EE_LIBRARIES . 'messages' . DS . 'defaults' . DS,
493
+            EE_LIBRARIES.'messages'.DS,
494
+            EE_LIBRARIES.'shortcodes'.DS,
495
+            EE_LIBRARIES.'qtips'.DS,
496
+            EE_LIBRARIES.'payment_methods'.DS,
497
+            EE_LIBRARIES.'messages'.DS.'defaults'.DS,
498 498
         );
499 499
         // retrieve instantiated class
500 500
         return $this->_load(
@@ -557,10 +557,10 @@  discard block
 block discarded – undo
557 557
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
558 558
     {
559 559
         $paths = array(
560
-            EE_MODELS . 'fields' . DS,
561
-            EE_MODELS . 'helpers' . DS,
562
-            EE_MODELS . 'relations' . DS,
563
-            EE_MODELS . 'strategies' . DS,
560
+            EE_MODELS.'fields'.DS,
561
+            EE_MODELS.'helpers'.DS,
562
+            EE_MODELS.'relations'.DS,
563
+            EE_MODELS.'strategies'.DS,
564 564
         );
565 565
         // retrieve instantiated class
566 566
         return $this->_load(
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
         $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
680 680
         // if a non-FQCN was passed, then verifyClassExists() might return an object
681 681
         // or it could return null if the class just could not be found anywhere
682
-        if ($class_exists instanceof $class_name || $class_exists === null){
682
+        if ($class_exists instanceof $class_name || $class_exists === null) {
683 683
             // either way, return the results
684 684
             return $class_exists;
685 685
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
             case 1:
738 738
                 // if it's a FQCN then maybe the class is registered with a preceding \
739 739
                 $class_name = strpos($class_name, '\\') !== false
740
-                    ? '\\' . ltrim($class_name, '\\')
740
+                    ? '\\'.ltrim($class_name, '\\')
741 741
                     : $class_name;
742 742
                 break;
743 743
             case 2:
@@ -789,11 +789,11 @@  discard block
 block discarded – undo
789 789
         // strip php file extension
790 790
         $class_name = str_replace('.php', '', trim($class_name));
791 791
         // does the class have a prefix ?
792
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
792
+        if ( ! empty($class_prefix) && $class_prefix !== 'addon') {
793 793
             // make sure $class_prefix is uppercase
794 794
             $class_prefix = strtoupper(trim($class_prefix));
795 795
             // add class prefix ONCE!!!
796
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
796
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
797 797
         }
798 798
         $class_name = $this->_dependency_map->get_alias($class_name);
799 799
         $class_exists = class_exists($class_name, false);
@@ -812,13 +812,13 @@  discard block
 block discarded – undo
812 812
             }
813 813
         }
814 814
         // if the class doesn't already exist.. then we need to try and find the file and load it
815
-        if (! $class_exists) {
815
+        if ( ! $class_exists) {
816 816
             // get full path to file
817 817
             $path = $this->_resolve_path($class_name, $type, $file_paths);
818 818
             // load the file
819 819
             $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
820 820
             // if loading failed, or we are only loading a file but NOT instantiating an object
821
-            if (! $loaded || $load_only) {
821
+            if ( ! $loaded || $load_only) {
822 822
                 // return boolean if only loading, or null if an object was expected
823 823
                 return $load_only
824 824
                     ? $loaded
@@ -943,10 +943,10 @@  discard block
 block discarded – undo
943 943
                 : EE_CLASSES;
944 944
             // prep file type
945 945
             $type = ! empty($type)
946
-                ? trim($type, '.') . '.'
946
+                ? trim($type, '.').'.'
947 947
                 : '';
948 948
             // build full file path
949
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
949
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
950 950
             //does the file exist and can be read ?
951 951
             if (is_readable($file_paths[$key])) {
952 952
                 return $file_paths[$key];
@@ -975,9 +975,9 @@  discard block
 block discarded – undo
975 975
         // don't give up! you gotta...
976 976
         try {
977 977
             //does the file exist and can it be read ?
978
-            if (! $path) {
978
+            if ( ! $path) {
979 979
                 // so sorry, can't find the file
980
-                throw new EE_Error (
980
+                throw new EE_Error(
981 981
                     sprintf(
982 982
                         esc_html__(
983 983
                             'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
                         ),
986 986
                         trim($type, '.'),
987 987
                         $class_name,
988
-                        '<br />' . implode(',<br />', $file_paths)
988
+                        '<br />'.implode(',<br />', $file_paths)
989 989
                     )
990 990
                 );
991 991
             }
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
             $legacy_parent_class_map = array(
1027 1027
                 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1028 1028
             );
1029
-            if(isset($legacy_parent_class_map[$class_name])) {
1030
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1029
+            if (isset($legacy_parent_class_map[$class_name])) {
1030
+                require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name];
1031 1031
             }
1032 1032
         } catch (Exception $exception) {
1033 1033
         }
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
         // let's examine the constructor
1177 1177
         $constructor = $reflector->getConstructor();
1178 1178
         // whu? huh? nothing?
1179
-        if (! $constructor) {
1179
+        if ( ! $constructor) {
1180 1180
             return $arguments;
1181 1181
         }
1182 1182
         // get constructor parameters
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
             $this->addons->{$class_name} = $class_obj;
1343 1343
             return;
1344 1344
         }
1345
-        if (! $from_db) {
1345
+        if ( ! $from_db) {
1346 1346
             $this->LIB->{$class_name} = $class_obj;
1347 1347
         }
1348 1348
     }
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1424 1424
             ? "EEM_{$model_name}"
1425 1425
             : $model_name;
1426
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1426
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1427 1427
             return null;
1428 1428
         }
1429 1429
         //get that model reset it and make sure we nuke the old reference to it
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
         $instance->_cache_on = true;
1477 1477
         // reset some "special" classes
1478 1478
         EEH_Activation::reset();
1479
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1479
+        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1480 1480
         $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1481 1481
         $instance->CART = null;
1482 1482
         $instance->MRM = null;
@@ -1507,7 +1507,7 @@  discard block
 block discarded – undo
1507 1507
      */
1508 1508
     private static function _reset_and_unset_object($object, $reset_models)
1509 1509
     {
1510
-        if (! is_object($object)) {
1510
+        if ( ! is_object($object)) {
1511 1511
             // don't unset anything that's not an object
1512 1512
             return false;
1513 1513
         }
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
             $object->reset();
1528 1528
             return true;
1529 1529
         }
1530
-        if (! $object instanceof InterminableInterface) {
1530
+        if ( ! $object instanceof InterminableInterface) {
1531 1531
             return true;
1532 1532
         }
1533 1533
         return false;
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -23,204 +23,204 @@
 block discarded – undo
23 23
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Request $request
28
-     */
29
-    protected $request;
26
+	/**
27
+	 * @var EE_Request $request
28
+	 */
29
+	protected $request;
30 30
 
31
-    /**
32
-     * @var EE_Response $response
33
-     */
34
-    protected $response;
31
+	/**
32
+	 * @var EE_Response $response
33
+	 */
34
+	protected $response;
35 35
 
36
-    /**
37
-     * @var EE_Dependency_Map $dependency_map
38
-     */
39
-    protected $dependency_map;
36
+	/**
37
+	 * @var EE_Dependency_Map $dependency_map
38
+	 */
39
+	protected $dependency_map;
40 40
 
41
-    /**
42
-     * @var EE_Registry $registry
43
-     */
44
-    protected $registry;
41
+	/**
42
+	 * @var EE_Registry $registry
43
+	 */
44
+	protected $registry;
45 45
 
46 46
 
47 47
 
48
-    /**
49
-     * EE_Load_Espresso_Core constructor
50
-     */
48
+	/**
49
+	 * EE_Load_Espresso_Core constructor
50
+	 */
51 51
 	public function __construct() {
52
-        // deprecated functions
53
-        espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
54
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * handle
61
-     * sets hooks for running rest of system
62
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
-     * starting EE Addons from any other point may lead to problems
64
-     *
65
-     * @param EE_Request  $request
66
-     * @param EE_Response $response
67
-     * @return EE_Response
68
-     * @throws EE_Error
69
-     * @throws InvalidDataTypeException
70
-     * @throws InvalidInterfaceException
71
-     * @throws InvalidArgumentException
72
-     */
73
-    public function handle_request(EE_Request $request, EE_Response $response)
74
-    {
75
-        $this->request = $request;
76
-        $this->response = $response;
77
-        // info about how to load classes required by other classes
78
-        $this->dependency_map = $this->_load_dependency_map();
79
-        // central repository for classes
80
-        $this->registry = $this->_load_registry();
81
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
82
-        $loader = LoaderFactory::getLoader($this->registry);
83
-        $this->dependency_map->setLoader($loader);
84
-        // build DI container
85
-        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
86
-        // $OpenCoffeeShop->addRecipes();
87
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
88
-        // workarounds for PHP < 5.3
89
-        $this->_load_class_tools();
90
-        // deprecated functions
91
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
92
-        // WP cron jobs
93
-        $loader->getShared('EE_Cron_Tasks');
94
-        $loader->getShared('EE_Request_Handler');
95
-        $loader->getShared('EE_System');
96
-        return $this->response;
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * @return EE_Request
103
-     */
104
-    public function request()
105
-    {
106
-        return $this->request;
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * @return EE_Response
113
-     */
114
-    public function response()
115
-    {
116
-        return $this->response;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @return EE_Dependency_Map
123
-     * @throws EE_Error
124
-     */
125
-    public function dependency_map()
126
-    {
127
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
128
-            throw new EE_Error(
129
-                sprintf(
130
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
131
-                    print_r($this->dependency_map, true)
132
-                )
133
-            );
134
-        }
135
-        return $this->dependency_map;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * @return EE_Registry
142
-     * @throws EE_Error
143
-     */
144
-    public function registry()
145
-    {
146
-        if (! $this->registry instanceof EE_Registry) {
147
-            throw new EE_Error(
148
-                sprintf(
149
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
150
-                    print_r($this->registry, true)
151
-                )
152
-            );
153
-        }
154
-        return $this->registry;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return EE_Dependency_Map
161
-     */
162
-    private function _load_dependency_map()
163
-    {
164
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
165
-            EE_Error::add_error(
166
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
167
-                __FILE__, __FUNCTION__, __LINE__
168
-            );
169
-            wp_die(EE_Error::get_notices());
170
-        }
171
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
172
-        return EE_Dependency_Map::instance($this->request, $this->response);
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @return EE_Registry
179
-     */
180
-    private function _load_registry()
181
-    {
182
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
183
-            EE_Error::add_error(
184
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
185
-                __FILE__, __FUNCTION__, __LINE__
186
-            );
187
-            wp_die(EE_Error::get_notices());
188
-        }
189
-        require_once(EE_CORE . 'EE_Registry.core.php');
190
-        return EE_Registry::instance($this->dependency_map);
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @return void
197
-     */
198
-    private function _load_class_tools()
199
-    {
200
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
201
-            EE_Error::add_error(
202
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
203
-                __FILE__, __FUNCTION__, __LINE__
204
-            );
205
-        }
206
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * called after the request stack has been fully processed
213
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
214
-     *
215
-     * @param EE_Request  $request
216
-     * @param EE_Response $response
217
-     */
218
-    public function handle_response(EE_Request $request, EE_Response $response)
219
-    {
220
-        if ($response->plugin_deactivated()) {
221
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
222
-        }
223
-    }
52
+		// deprecated functions
53
+		espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
54
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * handle
61
+	 * sets hooks for running rest of system
62
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
+	 * starting EE Addons from any other point may lead to problems
64
+	 *
65
+	 * @param EE_Request  $request
66
+	 * @param EE_Response $response
67
+	 * @return EE_Response
68
+	 * @throws EE_Error
69
+	 * @throws InvalidDataTypeException
70
+	 * @throws InvalidInterfaceException
71
+	 * @throws InvalidArgumentException
72
+	 */
73
+	public function handle_request(EE_Request $request, EE_Response $response)
74
+	{
75
+		$this->request = $request;
76
+		$this->response = $response;
77
+		// info about how to load classes required by other classes
78
+		$this->dependency_map = $this->_load_dependency_map();
79
+		// central repository for classes
80
+		$this->registry = $this->_load_registry();
81
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
82
+		$loader = LoaderFactory::getLoader($this->registry);
83
+		$this->dependency_map->setLoader($loader);
84
+		// build DI container
85
+		// $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
86
+		// $OpenCoffeeShop->addRecipes();
87
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
88
+		// workarounds for PHP < 5.3
89
+		$this->_load_class_tools();
90
+		// deprecated functions
91
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
92
+		// WP cron jobs
93
+		$loader->getShared('EE_Cron_Tasks');
94
+		$loader->getShared('EE_Request_Handler');
95
+		$loader->getShared('EE_System');
96
+		return $this->response;
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * @return EE_Request
103
+	 */
104
+	public function request()
105
+	{
106
+		return $this->request;
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * @return EE_Response
113
+	 */
114
+	public function response()
115
+	{
116
+		return $this->response;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @return EE_Dependency_Map
123
+	 * @throws EE_Error
124
+	 */
125
+	public function dependency_map()
126
+	{
127
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
128
+			throw new EE_Error(
129
+				sprintf(
130
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
131
+					print_r($this->dependency_map, true)
132
+				)
133
+			);
134
+		}
135
+		return $this->dependency_map;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * @return EE_Registry
142
+	 * @throws EE_Error
143
+	 */
144
+	public function registry()
145
+	{
146
+		if (! $this->registry instanceof EE_Registry) {
147
+			throw new EE_Error(
148
+				sprintf(
149
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
150
+					print_r($this->registry, true)
151
+				)
152
+			);
153
+		}
154
+		return $this->registry;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return EE_Dependency_Map
161
+	 */
162
+	private function _load_dependency_map()
163
+	{
164
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
165
+			EE_Error::add_error(
166
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
167
+				__FILE__, __FUNCTION__, __LINE__
168
+			);
169
+			wp_die(EE_Error::get_notices());
170
+		}
171
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
172
+		return EE_Dependency_Map::instance($this->request, $this->response);
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @return EE_Registry
179
+	 */
180
+	private function _load_registry()
181
+	{
182
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
183
+			EE_Error::add_error(
184
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
185
+				__FILE__, __FUNCTION__, __LINE__
186
+			);
187
+			wp_die(EE_Error::get_notices());
188
+		}
189
+		require_once(EE_CORE . 'EE_Registry.core.php');
190
+		return EE_Registry::instance($this->dependency_map);
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @return void
197
+	 */
198
+	private function _load_class_tools()
199
+	{
200
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
201
+			EE_Error::add_error(
202
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
203
+				__FILE__, __FUNCTION__, __LINE__
204
+			);
205
+		}
206
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * called after the request stack has been fully processed
213
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
214
+	 *
215
+	 * @param EE_Request  $request
216
+	 * @param EE_Response $response
217
+	 */
218
+	public function handle_response(EE_Request $request, EE_Response $response)
219
+	{
220
+		if ($response->plugin_deactivated()) {
221
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
222
+		}
223
+	}
224 224
 
225 225
 
226 226
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
      */
51 51
 	public function __construct() {
52 52
         // deprecated functions
53
-        espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php');
54
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
53
+        espresso_load_required('EE_Base', EE_CORE.'EE_Base.core.php');
54
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
55 55
     }
56 56
 
57 57
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         // workarounds for PHP < 5.3
89 89
         $this->_load_class_tools();
90 90
         // deprecated functions
91
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
91
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
92 92
         // WP cron jobs
93 93
         $loader->getShared('EE_Cron_Tasks');
94 94
         $loader->getShared('EE_Request_Handler');
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function dependency_map()
126 126
     {
127
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
127
+        if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
128 128
             throw new EE_Error(
129 129
                 sprintf(
130 130
                     __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function registry()
145 145
     {
146
-        if (! $this->registry instanceof EE_Registry) {
146
+        if ( ! $this->registry instanceof EE_Registry) {
147 147
             throw new EE_Error(
148 148
                 sprintf(
149 149
                     __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
      */
162 162
     private function _load_dependency_map()
163 163
     {
164
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
164
+        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
165 165
             EE_Error::add_error(
166 166
                 __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
167 167
                 __FILE__, __FUNCTION__, __LINE__
168 168
             );
169 169
             wp_die(EE_Error::get_notices());
170 170
         }
171
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
171
+        require_once(EE_CORE.'EE_Dependency_Map.core.php');
172 172
         return EE_Dependency_Map::instance($this->request, $this->response);
173 173
     }
174 174
 
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
      */
180 180
     private function _load_registry()
181 181
     {
182
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
182
+        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
183 183
             EE_Error::add_error(
184 184
                 __('The EE_Registry core class could not be loaded.', 'event_espresso'),
185 185
                 __FILE__, __FUNCTION__, __LINE__
186 186
             );
187 187
             wp_die(EE_Error::get_notices());
188 188
         }
189
-        require_once(EE_CORE . 'EE_Registry.core.php');
189
+        require_once(EE_CORE.'EE_Registry.core.php');
190 190
         return EE_Registry::instance($this->dependency_map);
191 191
     }
192 192
 
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
      */
198 198
     private function _load_class_tools()
199 199
     {
200
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
200
+        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
201 201
             EE_Error::add_error(
202 202
                 __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
203 203
                 __FILE__, __FUNCTION__, __LINE__
204 204
             );
205 205
         }
206
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
206
+        require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
207 207
     }
208 208
 
209 209
 
Please login to merge, or discard this patch.
core/EE_Addon.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
      * Sets addon_name
141 141
      *
142 142
      * @param string $addon_name
143
-     * @return boolean
143
+     * @return string
144 144
      */
145 145
     public function set_name($addon_name)
146 146
     {
Please login to merge, or discard this patch.
Indentation   +714 added lines, -714 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,702 +25,702 @@  discard block
 block discarded – undo
25 25
 {
26 26
 
27 27
 
28
-    /**
29
-     * prefix to be added onto an addon's plugin slug to make a wp option name
30
-     * which will be used to store the plugin's activation history
31
-     */
32
-    const ee_addon_version_history_option_prefix = 'ee_version_history_';
33
-
34
-    /**
35
-     * @var $_version
36
-     * @type string
37
-     */
38
-    protected $_version = '';
39
-
40
-    /**
41
-     * @var $_min_core_version
42
-     * @type string
43
-     */
44
-    protected $_min_core_version = '';
45
-
46
-    /**
47
-     * derived from plugin 'main_file_path using plugin_basename()
48
-     *
49
-     * @type string $_plugin_basename
50
-     */
51
-    protected $_plugin_basename = '';
52
-
53
-    /**
54
-     * A non-internationalized name to identify this addon for use in URLs, etc
55
-     *
56
-     * @type string $_plugin_slug
57
-     */
58
-    protected $_plugin_slug = '';
59
-
60
-    /**
61
-     * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
62
-     *
63
-     * @type string _addon_name
64
-     */
65
-    protected $_addon_name = '';
66
-
67
-    /**
68
-     * one of the EE_System::req_type_* constants
69
-     *
70
-     * @type int $_req_type
71
-     */
72
-    protected $_req_type;
73
-
74
-    /**
75
-     * page slug to be used when generating the "Settings" link on the WP plugin page
76
-     *
77
-     * @type string $_plugin_action_slug
78
-     */
79
-    protected $_plugin_action_slug = '';
80
-
81
-    /**
82
-     * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
83
-     * that can be used for adding upgrading/marketing info
84
-     *
85
-     * @type array $_plugins_page_row
86
-     */
87
-    protected $_plugins_page_row = array();
88
-
89
-
90
-    /**
91
-     *    class constructor
92
-     */
93
-    public function __construct()
94
-    {
95
-        add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
96
-    }
97
-
98
-
99
-    /**
100
-     * @param mixed $version
101
-     */
102
-    public function set_version($version = null)
103
-    {
104
-        $this->_version = $version;
105
-    }
106
-
107
-
108
-    /**
109
-     * get__version
110
-     *
111
-     * @return string
112
-     */
113
-    public function version()
114
-    {
115
-        return $this->_version;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param mixed $min_core_version
121
-     */
122
-    public function set_min_core_version($min_core_version = null)
123
-    {
124
-        $this->_min_core_version = $min_core_version;
125
-    }
126
-
127
-
128
-    /**
129
-     * get__min_core_version
130
-     *
131
-     * @return string
132
-     */
133
-    public function min_core_version()
134
-    {
135
-        return $this->_min_core_version;
136
-    }
137
-
138
-
139
-    /**
140
-     * Sets addon_name
141
-     *
142
-     * @param string $addon_name
143
-     * @return boolean
144
-     */
145
-    public function set_name($addon_name)
146
-    {
147
-        return $this->_addon_name = $addon_name;
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets addon_name
153
-     *
154
-     * @return string
155
-     */
156
-    public function name()
157
-    {
158
-        return $this->_addon_name;
159
-    }
160
-
161
-
162
-    /**
163
-     * @return string
164
-     */
165
-    public function plugin_basename()
166
-    {
167
-
168
-        return $this->_plugin_basename;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $plugin_basename
174
-     */
175
-    public function set_plugin_basename($plugin_basename)
176
-    {
177
-
178
-        $this->_plugin_basename = $plugin_basename;
179
-    }
180
-
181
-
182
-    /**
183
-     * @return string
184
-     */
185
-    public function plugin_slug()
186
-    {
187
-
188
-        return $this->_plugin_slug;
189
-    }
190
-
191
-
192
-    /**
193
-     * @param string $plugin_slug
194
-     */
195
-    public function set_plugin_slug($plugin_slug)
196
-    {
197
-
198
-        $this->_plugin_slug = $plugin_slug;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return string
204
-     */
205
-    public function plugin_action_slug()
206
-    {
207
-
208
-        return $this->_plugin_action_slug;
209
-    }
210
-
211
-
212
-    /**
213
-     * @param string $plugin_action_slug
214
-     */
215
-    public function set_plugin_action_slug($plugin_action_slug)
216
-    {
217
-
218
-        $this->_plugin_action_slug = $plugin_action_slug;
219
-    }
220
-
221
-
222
-    /**
223
-     * @return array
224
-     */
225
-    public function get_plugins_page_row()
226
-    {
227
-
228
-        return $this->_plugins_page_row;
229
-    }
230
-
231
-
232
-    /**
233
-     * @param array $plugins_page_row
234
-     */
235
-    public function set_plugins_page_row($plugins_page_row = array())
236
-    {
237
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
238
-        if (! is_array($plugins_page_row) && strpos($plugins_page_row,
239
-                '<h3>Promotions Addon Upsell Info</h3>') !== false) {
240
-            $plugins_page_row = '';
241
-        }
242
-        $this->_plugins_page_row = $plugins_page_row;
243
-    }
244
-
245
-
246
-    /**
247
-     * Called when EE core detects this addon has been activated for the first time.
248
-     * If the site isn't in maintenance mode, should setup the addon's database
249
-     *
250
-     * @return void
251
-     */
252
-    public function new_install()
253
-    {
254
-        $classname = get_class($this);
255
-        do_action("AHEE__{$classname}__new_install");
256
-        do_action('AHEE__EE_Addon__new_install', $this);
257
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
258
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
259
-            array($this, 'initialize_db_if_no_migrations_required'));
260
-    }
261
-
262
-
263
-    /**
264
-     * Called when EE core detects this addon has been reactivated. When this happens,
265
-     * it's good to just check that your data is still intact
266
-     *
267
-     * @return void
268
-     */
269
-    public function reactivation()
270
-    {
271
-        $classname = get_class($this);
272
-        do_action("AHEE__{$classname}__reactivation");
273
-        do_action('AHEE__EE_Addon__reactivation', $this);
274
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
276
-            array($this, 'initialize_db_if_no_migrations_required'));
277
-    }
278
-
279
-
280
-    public function deactivation()
281
-    {
282
-        $classname = get_class($this);
28
+	/**
29
+	 * prefix to be added onto an addon's plugin slug to make a wp option name
30
+	 * which will be used to store the plugin's activation history
31
+	 */
32
+	const ee_addon_version_history_option_prefix = 'ee_version_history_';
33
+
34
+	/**
35
+	 * @var $_version
36
+	 * @type string
37
+	 */
38
+	protected $_version = '';
39
+
40
+	/**
41
+	 * @var $_min_core_version
42
+	 * @type string
43
+	 */
44
+	protected $_min_core_version = '';
45
+
46
+	/**
47
+	 * derived from plugin 'main_file_path using plugin_basename()
48
+	 *
49
+	 * @type string $_plugin_basename
50
+	 */
51
+	protected $_plugin_basename = '';
52
+
53
+	/**
54
+	 * A non-internationalized name to identify this addon for use in URLs, etc
55
+	 *
56
+	 * @type string $_plugin_slug
57
+	 */
58
+	protected $_plugin_slug = '';
59
+
60
+	/**
61
+	 * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/
62
+	 *
63
+	 * @type string _addon_name
64
+	 */
65
+	protected $_addon_name = '';
66
+
67
+	/**
68
+	 * one of the EE_System::req_type_* constants
69
+	 *
70
+	 * @type int $_req_type
71
+	 */
72
+	protected $_req_type;
73
+
74
+	/**
75
+	 * page slug to be used when generating the "Settings" link on the WP plugin page
76
+	 *
77
+	 * @type string $_plugin_action_slug
78
+	 */
79
+	protected $_plugin_action_slug = '';
80
+
81
+	/**
82
+	 * if not empty, inserts a new table row after this plugin's row on the WP Plugins page
83
+	 * that can be used for adding upgrading/marketing info
84
+	 *
85
+	 * @type array $_plugins_page_row
86
+	 */
87
+	protected $_plugins_page_row = array();
88
+
89
+
90
+	/**
91
+	 *    class constructor
92
+	 */
93
+	public function __construct()
94
+	{
95
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param mixed $version
101
+	 */
102
+	public function set_version($version = null)
103
+	{
104
+		$this->_version = $version;
105
+	}
106
+
107
+
108
+	/**
109
+	 * get__version
110
+	 *
111
+	 * @return string
112
+	 */
113
+	public function version()
114
+	{
115
+		return $this->_version;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param mixed $min_core_version
121
+	 */
122
+	public function set_min_core_version($min_core_version = null)
123
+	{
124
+		$this->_min_core_version = $min_core_version;
125
+	}
126
+
127
+
128
+	/**
129
+	 * get__min_core_version
130
+	 *
131
+	 * @return string
132
+	 */
133
+	public function min_core_version()
134
+	{
135
+		return $this->_min_core_version;
136
+	}
137
+
138
+
139
+	/**
140
+	 * Sets addon_name
141
+	 *
142
+	 * @param string $addon_name
143
+	 * @return boolean
144
+	 */
145
+	public function set_name($addon_name)
146
+	{
147
+		return $this->_addon_name = $addon_name;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets addon_name
153
+	 *
154
+	 * @return string
155
+	 */
156
+	public function name()
157
+	{
158
+		return $this->_addon_name;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @return string
164
+	 */
165
+	public function plugin_basename()
166
+	{
167
+
168
+		return $this->_plugin_basename;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $plugin_basename
174
+	 */
175
+	public function set_plugin_basename($plugin_basename)
176
+	{
177
+
178
+		$this->_plugin_basename = $plugin_basename;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return string
184
+	 */
185
+	public function plugin_slug()
186
+	{
187
+
188
+		return $this->_plugin_slug;
189
+	}
190
+
191
+
192
+	/**
193
+	 * @param string $plugin_slug
194
+	 */
195
+	public function set_plugin_slug($plugin_slug)
196
+	{
197
+
198
+		$this->_plugin_slug = $plugin_slug;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return string
204
+	 */
205
+	public function plugin_action_slug()
206
+	{
207
+
208
+		return $this->_plugin_action_slug;
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param string $plugin_action_slug
214
+	 */
215
+	public function set_plugin_action_slug($plugin_action_slug)
216
+	{
217
+
218
+		$this->_plugin_action_slug = $plugin_action_slug;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @return array
224
+	 */
225
+	public function get_plugins_page_row()
226
+	{
227
+
228
+		return $this->_plugins_page_row;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param array $plugins_page_row
234
+	 */
235
+	public function set_plugins_page_row($plugins_page_row = array())
236
+	{
237
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
238
+		if (! is_array($plugins_page_row) && strpos($plugins_page_row,
239
+				'<h3>Promotions Addon Upsell Info</h3>') !== false) {
240
+			$plugins_page_row = '';
241
+		}
242
+		$this->_plugins_page_row = $plugins_page_row;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Called when EE core detects this addon has been activated for the first time.
248
+	 * If the site isn't in maintenance mode, should setup the addon's database
249
+	 *
250
+	 * @return void
251
+	 */
252
+	public function new_install()
253
+	{
254
+		$classname = get_class($this);
255
+		do_action("AHEE__{$classname}__new_install");
256
+		do_action('AHEE__EE_Addon__new_install', $this);
257
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
258
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
259
+			array($this, 'initialize_db_if_no_migrations_required'));
260
+	}
261
+
262
+
263
+	/**
264
+	 * Called when EE core detects this addon has been reactivated. When this happens,
265
+	 * it's good to just check that your data is still intact
266
+	 *
267
+	 * @return void
268
+	 */
269
+	public function reactivation()
270
+	{
271
+		$classname = get_class($this);
272
+		do_action("AHEE__{$classname}__reactivation");
273
+		do_action('AHEE__EE_Addon__reactivation', $this);
274
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
275
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
276
+			array($this, 'initialize_db_if_no_migrations_required'));
277
+	}
278
+
279
+
280
+	public function deactivation()
281
+	{
282
+		$classname = get_class($this);
283 283
 //		echo "Deactivating $classname";die;
284
-        do_action("AHEE__{$classname}__deactivation");
285
-        do_action('AHEE__EE_Addon__deactivation', $this);
286
-        //check if the site no longer needs to be in maintenance mode
287
-        EE_Register_Addon::deregister($this->name());
288
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
289
-    }
290
-
291
-
292
-    /**
293
-     * Takes care of double-checking that we're not in maintenance mode, and then
294
-     * initializing this addon's necessary initial data. This is called by default on new activations
295
-     * and reactivations
296
-     *
297
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
298
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
299
-     * @return void
300
-     * @throws \EE_Error
301
-     */
302
-    public function initialize_db_if_no_migrations_required($verify_schema = true)
303
-    {
304
-        if ($verify_schema === '') {
305
-            //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
306
-            //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
307
-            //calls them with an argument of an empty string (ie ""), which evaluates to false
308
-            //so we need to treat the empty string as if nothing had been passed, and should instead use the default
309
-            $verify_schema = true;
310
-        }
311
-        if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
312
-            if ($verify_schema) {
313
-                $this->initialize_db();
314
-            }
315
-            $this->initialize_default_data();
316
-            //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
317
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to(
318
-                array(
319
-                    'slug'    => $this->name(),
320
-                    'version' => $this->version(),
321
-                )
322
-            );
323
-            /* make sure core's data is a-ok
284
+		do_action("AHEE__{$classname}__deactivation");
285
+		do_action('AHEE__EE_Addon__deactivation', $this);
286
+		//check if the site no longer needs to be in maintenance mode
287
+		EE_Register_Addon::deregister($this->name());
288
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
289
+	}
290
+
291
+
292
+	/**
293
+	 * Takes care of double-checking that we're not in maintenance mode, and then
294
+	 * initializing this addon's necessary initial data. This is called by default on new activations
295
+	 * and reactivations
296
+	 *
297
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
298
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
299
+	 * @return void
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function initialize_db_if_no_migrations_required($verify_schema = true)
303
+	{
304
+		if ($verify_schema === '') {
305
+			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
306
+			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
307
+			//calls them with an argument of an empty string (ie ""), which evaluates to false
308
+			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
309
+			$verify_schema = true;
310
+		}
311
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
312
+			if ($verify_schema) {
313
+				$this->initialize_db();
314
+			}
315
+			$this->initialize_default_data();
316
+			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
317
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
318
+				array(
319
+					'slug'    => $this->name(),
320
+					'version' => $this->version(),
321
+				)
322
+			);
323
+			/* make sure core's data is a-ok
324 324
              * (at the time of writing, we especially want to verify all the caps are present
325 325
              * because payment method type capabilities are added dynamically, and it's
326 326
              * possible this addon added a payment method. But it's also possible
327 327
              * other data needs to be verified)
328 328
              */
329
-            EEH_Activation::initialize_db_content();
330
-            update_option('ee_flush_rewrite_rules', true);
331
-            //in case there are lots of addons being activated at once, let's force garbage collection
332
-            //to help avoid memory limit errors
333
-            //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
334
-            gc_collect_cycles();
335
-        } else {
336
-            //ask the data migration manager to init this addon's data
337
-            //when migrations are finished because we can't do it now
338
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
339
-        }
340
-    }
341
-
342
-
343
-    /**
344
-     * Used to setup this addon's database tables, but not necessarily any default
345
-     * data in them. The default is to actually use the most up-to-date data migration script
346
-     * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
347
-     * methods to setup the db.
348
-     */
349
-    public function initialize_db()
350
-    {
351
-        //find the migration script that sets the database to be compatible with the code
352
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
353
-        if ($current_dms_name) {
354
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
355
-            $current_data_migration_script->set_migrating(false);
356
-            $current_data_migration_script->schema_changes_before_migration();
357
-            $current_data_migration_script->schema_changes_after_migration();
358
-            if ($current_data_migration_script->get_errors()) {
359
-                foreach ($current_data_migration_script->get_errors() as $error) {
360
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
361
-                }
362
-            }
363
-        }
364
-        //if not DMS was found that should be ok. This addon just doesn't require any database changes
365
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
366
-            array(
367
-                'slug'    => $this->name(),
368
-                'version' => $this->version(),
369
-            )
370
-        );
371
-    }
372
-
373
-
374
-    /**
375
-     * If you want to setup default data for the addon, override this method, and call
376
-     * parent::initialize_default_data() from within it. This is normally called
377
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
378
-     * and should verify default data is present (but this is also called
379
-     * on reactivations and just after migrations, so please verify you actually want
380
-     * to ADD default data, because it may already be present).
381
-     * However, please call this parent (currently it just fires a hook which other
382
-     * addons may be depending on)
383
-     */
384
-    public function initialize_default_data()
385
-    {
386
-        /**
387
-         * Called when an addon is ensuring its default data is set (possibly called
388
-         * on a reactivation, so first check for the absence of other data before setting
389
-         * default data)
390
-         *
391
-         * @param EE_Addon $addon the addon that called this
392
-         */
393
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
394
-        //override to insert default data. It is safe to use the models here
395
-        //because the site should not be in maintenance mode
396
-    }
397
-
398
-
399
-    /**
400
-     * EE Core detected that this addon has been upgraded. We should check if there
401
-     * are any new migration scripts, and if so put the site into maintenance mode until
402
-     * they're ran
403
-     *
404
-     * @return void
405
-     */
406
-    public function upgrade()
407
-    {
408
-        $classname = get_class($this);
409
-        do_action("AHEE__{$classname}__upgrade");
410
-        do_action('AHEE__EE_Addon__upgrade', $this);
411
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
412
-        //also it's possible there is new default data that needs to be added
413
-        add_action(
414
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
415
-            array($this, 'initialize_db_if_no_migrations_required')
416
-        );
417
-    }
418
-
419
-
420
-    /**
421
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
422
-     */
423
-    public function downgrade()
424
-    {
425
-        $classname = get_class($this);
426
-        do_action("AHEE__{$classname}__downgrade");
427
-        do_action('AHEE__EE_Addon__downgrade', $this);
428
-        //it's possible there's old default data that needs to be double-checked
429
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
430
-            array($this, 'initialize_db_if_no_migrations_required'));
431
-    }
432
-
433
-
434
-    /**
435
-     * set_db_update_option_name
436
-     * Until we do something better, we'll just check for migration scripts upon
437
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
438
-     *
439
-     * @return bool
440
-     */
441
-    public function set_db_update_option_name()
442
-    {
443
-        EE_Error::doing_it_wrong(__FUNCTION__,
444
-            __('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
445
-                'event_espresso'), '4.3.0.alpha.016');
446
-        //let's just handle this on the next request, ok? right now we're just not really ready
447
-        return $this->set_activation_indicator_option();
448
-    }
449
-
450
-
451
-    /**
452
-     * Returns the name of the activation indicator option
453
-     * (an option which is set temporarily to indicate that this addon was just activated)
454
-     *
455
-     * @deprecated since version 4.3.0.alpha.016
456
-     * @return string
457
-     */
458
-    public function get_db_update_option_name()
459
-    {
460
-        EE_Error::doing_it_wrong(__FUNCTION__,
461
-            __('EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
462
-                'event_espresso'), '4.3.0.alpha.016');
463
-        return $this->get_activation_indicator_option_name();
464
-    }
465
-
466
-
467
-    /**
468
-     * When the addon is activated, this should be called to set a wordpress option that
469
-     * indicates it was activated. This is especially useful for detecting reactivations.
470
-     *
471
-     * @return bool
472
-     */
473
-    public function set_activation_indicator_option()
474
-    {
475
-        // let's just handle this on the next request, ok? right now we're just not really ready
476
-        return update_option($this->get_activation_indicator_option_name(), true);
477
-    }
478
-
479
-
480
-    /**
481
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
482
-     *
483
-     * @return string
484
-     */
485
-    public function get_activation_indicator_option_name()
486
-    {
487
-        return 'ee_activation_' . $this->name();
488
-    }
489
-
490
-
491
-    /**
492
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
493
-     *
494
-     * @param int $req_type
495
-     */
496
-    public function set_req_type($req_type)
497
-    {
498
-        $this->_req_type = $req_type;
499
-    }
500
-
501
-
502
-    /**
503
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
504
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
505
-     * EE_System when it is checking for new install or upgrades of addons
506
-     */
507
-    public function detect_req_type()
508
-    {
509
-        if (! $this->_req_type) {
510
-            $this->detect_activation_or_upgrade();
511
-        }
512
-        return $this->_req_type;
513
-    }
514
-
515
-
516
-    /**
517
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
518
-     * Should only be called once per request
519
-     *
520
-     * @return void
521
-     */
522
-    public function detect_activation_or_upgrade()
523
-    {
524
-        $activation_history_for_addon = $this->get_activation_history();
329
+			EEH_Activation::initialize_db_content();
330
+			update_option('ee_flush_rewrite_rules', true);
331
+			//in case there are lots of addons being activated at once, let's force garbage collection
332
+			//to help avoid memory limit errors
333
+			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
334
+			gc_collect_cycles();
335
+		} else {
336
+			//ask the data migration manager to init this addon's data
337
+			//when migrations are finished because we can't do it now
338
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
339
+		}
340
+	}
341
+
342
+
343
+	/**
344
+	 * Used to setup this addon's database tables, but not necessarily any default
345
+	 * data in them. The default is to actually use the most up-to-date data migration script
346
+	 * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration()
347
+	 * methods to setup the db.
348
+	 */
349
+	public function initialize_db()
350
+	{
351
+		//find the migration script that sets the database to be compatible with the code
352
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
353
+		if ($current_dms_name) {
354
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
355
+			$current_data_migration_script->set_migrating(false);
356
+			$current_data_migration_script->schema_changes_before_migration();
357
+			$current_data_migration_script->schema_changes_after_migration();
358
+			if ($current_data_migration_script->get_errors()) {
359
+				foreach ($current_data_migration_script->get_errors() as $error) {
360
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
361
+				}
362
+			}
363
+		}
364
+		//if not DMS was found that should be ok. This addon just doesn't require any database changes
365
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
366
+			array(
367
+				'slug'    => $this->name(),
368
+				'version' => $this->version(),
369
+			)
370
+		);
371
+	}
372
+
373
+
374
+	/**
375
+	 * If you want to setup default data for the addon, override this method, and call
376
+	 * parent::initialize_default_data() from within it. This is normally called
377
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
378
+	 * and should verify default data is present (but this is also called
379
+	 * on reactivations and just after migrations, so please verify you actually want
380
+	 * to ADD default data, because it may already be present).
381
+	 * However, please call this parent (currently it just fires a hook which other
382
+	 * addons may be depending on)
383
+	 */
384
+	public function initialize_default_data()
385
+	{
386
+		/**
387
+		 * Called when an addon is ensuring its default data is set (possibly called
388
+		 * on a reactivation, so first check for the absence of other data before setting
389
+		 * default data)
390
+		 *
391
+		 * @param EE_Addon $addon the addon that called this
392
+		 */
393
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
394
+		//override to insert default data. It is safe to use the models here
395
+		//because the site should not be in maintenance mode
396
+	}
397
+
398
+
399
+	/**
400
+	 * EE Core detected that this addon has been upgraded. We should check if there
401
+	 * are any new migration scripts, and if so put the site into maintenance mode until
402
+	 * they're ran
403
+	 *
404
+	 * @return void
405
+	 */
406
+	public function upgrade()
407
+	{
408
+		$classname = get_class($this);
409
+		do_action("AHEE__{$classname}__upgrade");
410
+		do_action('AHEE__EE_Addon__upgrade', $this);
411
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
412
+		//also it's possible there is new default data that needs to be added
413
+		add_action(
414
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
415
+			array($this, 'initialize_db_if_no_migrations_required')
416
+		);
417
+	}
418
+
419
+
420
+	/**
421
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
422
+	 */
423
+	public function downgrade()
424
+	{
425
+		$classname = get_class($this);
426
+		do_action("AHEE__{$classname}__downgrade");
427
+		do_action('AHEE__EE_Addon__downgrade', $this);
428
+		//it's possible there's old default data that needs to be double-checked
429
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
430
+			array($this, 'initialize_db_if_no_migrations_required'));
431
+	}
432
+
433
+
434
+	/**
435
+	 * set_db_update_option_name
436
+	 * Until we do something better, we'll just check for migration scripts upon
437
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
438
+	 *
439
+	 * @return bool
440
+	 */
441
+	public function set_db_update_option_name()
442
+	{
443
+		EE_Error::doing_it_wrong(__FUNCTION__,
444
+			__('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
445
+				'event_espresso'), '4.3.0.alpha.016');
446
+		//let's just handle this on the next request, ok? right now we're just not really ready
447
+		return $this->set_activation_indicator_option();
448
+	}
449
+
450
+
451
+	/**
452
+	 * Returns the name of the activation indicator option
453
+	 * (an option which is set temporarily to indicate that this addon was just activated)
454
+	 *
455
+	 * @deprecated since version 4.3.0.alpha.016
456
+	 * @return string
457
+	 */
458
+	public function get_db_update_option_name()
459
+	{
460
+		EE_Error::doing_it_wrong(__FUNCTION__,
461
+			__('EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
462
+				'event_espresso'), '4.3.0.alpha.016');
463
+		return $this->get_activation_indicator_option_name();
464
+	}
465
+
466
+
467
+	/**
468
+	 * When the addon is activated, this should be called to set a wordpress option that
469
+	 * indicates it was activated. This is especially useful for detecting reactivations.
470
+	 *
471
+	 * @return bool
472
+	 */
473
+	public function set_activation_indicator_option()
474
+	{
475
+		// let's just handle this on the next request, ok? right now we're just not really ready
476
+		return update_option($this->get_activation_indicator_option_name(), true);
477
+	}
478
+
479
+
480
+	/**
481
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
482
+	 *
483
+	 * @return string
484
+	 */
485
+	public function get_activation_indicator_option_name()
486
+	{
487
+		return 'ee_activation_' . $this->name();
488
+	}
489
+
490
+
491
+	/**
492
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
493
+	 *
494
+	 * @param int $req_type
495
+	 */
496
+	public function set_req_type($req_type)
497
+	{
498
+		$this->_req_type = $req_type;
499
+	}
500
+
501
+
502
+	/**
503
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
504
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
505
+	 * EE_System when it is checking for new install or upgrades of addons
506
+	 */
507
+	public function detect_req_type()
508
+	{
509
+		if (! $this->_req_type) {
510
+			$this->detect_activation_or_upgrade();
511
+		}
512
+		return $this->_req_type;
513
+	}
514
+
515
+
516
+	/**
517
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
518
+	 * Should only be called once per request
519
+	 *
520
+	 * @return void
521
+	 */
522
+	public function detect_activation_or_upgrade()
523
+	{
524
+		$activation_history_for_addon = $this->get_activation_history();
525 525
 //		d($activation_history_for_addon);
526
-        $request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon,
527
-            $this->get_activation_indicator_option_name(), $this->version());
528
-        $this->set_req_type($request_type);
529
-        $classname = get_class($this);
530
-        switch ($request_type) {
531
-            case EE_System::req_type_new_activation:
532
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
533
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
534
-                $this->new_install();
535
-                $this->update_list_of_installed_versions($activation_history_for_addon);
536
-                break;
537
-            case EE_System::req_type_reactivation:
538
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
539
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
540
-                $this->reactivation();
541
-                $this->update_list_of_installed_versions($activation_history_for_addon);
542
-                break;
543
-            case EE_System::req_type_upgrade:
544
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
545
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
546
-                $this->upgrade();
547
-                $this->update_list_of_installed_versions($activation_history_for_addon);
548
-                break;
549
-            case EE_System::req_type_downgrade:
550
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
551
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
552
-                $this->downgrade();
553
-                $this->update_list_of_installed_versions($activation_history_for_addon);
554
-                break;
555
-            case EE_System::req_type_normal:
556
-            default:
526
+		$request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon,
527
+			$this->get_activation_indicator_option_name(), $this->version());
528
+		$this->set_req_type($request_type);
529
+		$classname = get_class($this);
530
+		switch ($request_type) {
531
+			case EE_System::req_type_new_activation:
532
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
533
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
534
+				$this->new_install();
535
+				$this->update_list_of_installed_versions($activation_history_for_addon);
536
+				break;
537
+			case EE_System::req_type_reactivation:
538
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
539
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
540
+				$this->reactivation();
541
+				$this->update_list_of_installed_versions($activation_history_for_addon);
542
+				break;
543
+			case EE_System::req_type_upgrade:
544
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
545
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
546
+				$this->upgrade();
547
+				$this->update_list_of_installed_versions($activation_history_for_addon);
548
+				break;
549
+			case EE_System::req_type_downgrade:
550
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
551
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
552
+				$this->downgrade();
553
+				$this->update_list_of_installed_versions($activation_history_for_addon);
554
+				break;
555
+			case EE_System::req_type_normal:
556
+			default:
557 557
 //				$this->_maybe_redirect_to_ee_about();
558
-                break;
559
-        }
560
-
561
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
562
-    }
563
-
564
-    /**
565
-     * Updates the version history for this addon
566
-     *
567
-     * @param array  $version_history
568
-     * @param string $current_version_to_add
569
-     * @return boolean success
570
-     */
571
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572
-    {
573
-        if (! $version_history) {
574
-            $version_history = $this->get_activation_history();
575
-        }
576
-        if ($current_version_to_add === null) {
577
-            $current_version_to_add = $this->version();
578
-        }
579
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
580
-        // resave
558
+				break;
559
+		}
560
+
561
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
562
+	}
563
+
564
+	/**
565
+	 * Updates the version history for this addon
566
+	 *
567
+	 * @param array  $version_history
568
+	 * @param string $current_version_to_add
569
+	 * @return boolean success
570
+	 */
571
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572
+	{
573
+		if (! $version_history) {
574
+			$version_history = $this->get_activation_history();
575
+		}
576
+		if ($current_version_to_add === null) {
577
+			$current_version_to_add = $this->version();
578
+		}
579
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
580
+		// resave
581 581
 //		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
582
-        return update_option($this->get_activation_history_option_name(), $version_history);
583
-    }
584
-
585
-    /**
586
-     * Gets the name of the wp option that stores the activation history
587
-     * of this addon
588
-     *
589
-     * @return string
590
-     */
591
-    public function get_activation_history_option_name()
592
-    {
593
-        return self::ee_addon_version_history_option_prefix . $this->name();
594
-    }
595
-
596
-
597
-    /**
598
-     * Gets the wp option which stores the activation history for this addon
599
-     *
600
-     * @return array
601
-     */
602
-    public function get_activation_history()
603
-    {
604
-        return get_option($this->get_activation_history_option_name(), null);
605
-    }
606
-
607
-
608
-    /**
609
-     * @param string $config_section
610
-     */
611
-    public function set_config_section($config_section = '')
612
-    {
613
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
614
-    }
615
-
616
-    /**
617
-     *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
618
-     *
619
-     * @type string
620
-     */
621
-    protected $_main_plugin_file;
622
-
623
-    /**
624
-     * Sets the filepath to the main plugin file
625
-     *
626
-     * @param string $filepath
627
-     */
628
-    public function set_main_plugin_file($filepath)
629
-    {
630
-        $this->_main_plugin_file = $filepath;
631
-    }
632
-
633
-    /**
634
-     * gets the filepath to teh main file
635
-     *
636
-     * @return string
637
-     */
638
-    public function get_main_plugin_file()
639
-    {
640
-        return $this->_main_plugin_file;
641
-    }
642
-
643
-    /**
644
-     * Gets the filename (no path) of the main file (the main file loaded
645
-     * by WP)
646
-     *
647
-     * @return string
648
-     */
649
-    public function get_main_plugin_file_basename()
650
-    {
651
-        return plugin_basename($this->get_main_plugin_file());
652
-    }
653
-
654
-    /**
655
-     * Gets the folder name which contains the main plugin file
656
-     *
657
-     * @return string
658
-     */
659
-    public function get_main_plugin_file_dirname()
660
-    {
661
-        return dirname($this->get_main_plugin_file());
662
-    }
663
-
664
-
665
-    /**
666
-     * sets hooks used in the admin
667
-     *
668
-     * @return void
669
-     */
670
-    public function admin_init()
671
-    {
672
-        // is admin and not in M-Mode ?
673
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676
-        }
677
-    }
678
-
679
-
680
-    /**
681
-     * plugin_actions
682
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
683
-     *
684
-     * @param $links
685
-     * @param $file
686
-     * @return array
687
-     */
688
-    public function plugin_action_links($links, $file)
689
-    {
690
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691
-            // before other links
692
-            array_unshift($links,
693
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
694
-        }
695
-        return $links;
696
-    }
697
-
698
-
699
-    /**
700
-     * after_plugin_row
701
-     * Add additional content to the plugins page plugin row
702
-     * Inserts another row
703
-     *
704
-     * @param $plugin_file
705
-     * @param $plugin_data
706
-     * @param $status
707
-     * @return void
708
-     */
709
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
710
-    {
711
-
712
-        $after_plugin_row = '';
713
-        if ($plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '') {
714
-            $class            = $status ? 'active' : 'inactive';
715
-            $plugins_page_row = $this->get_plugins_page_row();
716
-            $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717
-            $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718
-            $description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
721
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
722
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723
-                $after_plugin_row .= '<style>
582
+		return update_option($this->get_activation_history_option_name(), $version_history);
583
+	}
584
+
585
+	/**
586
+	 * Gets the name of the wp option that stores the activation history
587
+	 * of this addon
588
+	 *
589
+	 * @return string
590
+	 */
591
+	public function get_activation_history_option_name()
592
+	{
593
+		return self::ee_addon_version_history_option_prefix . $this->name();
594
+	}
595
+
596
+
597
+	/**
598
+	 * Gets the wp option which stores the activation history for this addon
599
+	 *
600
+	 * @return array
601
+	 */
602
+	public function get_activation_history()
603
+	{
604
+		return get_option($this->get_activation_history_option_name(), null);
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param string $config_section
610
+	 */
611
+	public function set_config_section($config_section = '')
612
+	{
613
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
614
+	}
615
+
616
+	/**
617
+	 *    filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
618
+	 *
619
+	 * @type string
620
+	 */
621
+	protected $_main_plugin_file;
622
+
623
+	/**
624
+	 * Sets the filepath to the main plugin file
625
+	 *
626
+	 * @param string $filepath
627
+	 */
628
+	public function set_main_plugin_file($filepath)
629
+	{
630
+		$this->_main_plugin_file = $filepath;
631
+	}
632
+
633
+	/**
634
+	 * gets the filepath to teh main file
635
+	 *
636
+	 * @return string
637
+	 */
638
+	public function get_main_plugin_file()
639
+	{
640
+		return $this->_main_plugin_file;
641
+	}
642
+
643
+	/**
644
+	 * Gets the filename (no path) of the main file (the main file loaded
645
+	 * by WP)
646
+	 *
647
+	 * @return string
648
+	 */
649
+	public function get_main_plugin_file_basename()
650
+	{
651
+		return plugin_basename($this->get_main_plugin_file());
652
+	}
653
+
654
+	/**
655
+	 * Gets the folder name which contains the main plugin file
656
+	 *
657
+	 * @return string
658
+	 */
659
+	public function get_main_plugin_file_dirname()
660
+	{
661
+		return dirname($this->get_main_plugin_file());
662
+	}
663
+
664
+
665
+	/**
666
+	 * sets hooks used in the admin
667
+	 *
668
+	 * @return void
669
+	 */
670
+	public function admin_init()
671
+	{
672
+		// is admin and not in M-Mode ?
673
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676
+		}
677
+	}
678
+
679
+
680
+	/**
681
+	 * plugin_actions
682
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
683
+	 *
684
+	 * @param $links
685
+	 * @param $file
686
+	 * @return array
687
+	 */
688
+	public function plugin_action_links($links, $file)
689
+	{
690
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691
+			// before other links
692
+			array_unshift($links,
693
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
694
+		}
695
+		return $links;
696
+	}
697
+
698
+
699
+	/**
700
+	 * after_plugin_row
701
+	 * Add additional content to the plugins page plugin row
702
+	 * Inserts another row
703
+	 *
704
+	 * @param $plugin_file
705
+	 * @param $plugin_data
706
+	 * @param $status
707
+	 * @return void
708
+	 */
709
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
710
+	{
711
+
712
+		$after_plugin_row = '';
713
+		if ($plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '') {
714
+			$class            = $status ? 'active' : 'inactive';
715
+			$plugins_page_row = $this->get_plugins_page_row();
716
+			$link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717
+			$link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718
+			$description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
721
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
722
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723
+				$after_plugin_row .= '<style>
724 724
 .ee-button,
725 725
 .ee-button:active,
726 726
 .ee-button:visited {
@@ -757,35 +757,35 @@  discard block
 block discarded – undo
757 757
 }
758 758
 .ee-button:active { top:0; }
759 759
 </style>';
760
-                $after_plugin_row .= '
760
+				$after_plugin_row .= '
761 761
 <p class="ee-addon-upsell-info-dv">
762 762
 	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
763 763
 </p>';
764
-                $after_plugin_row .= '</td>';
765
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
766
-                $after_plugin_row .= $description;
767
-                $after_plugin_row .= '</td>';
768
-                $after_plugin_row .= '</tr>';
769
-            } else {
770
-                $after_plugin_row .= $description;
771
-            }
772
-        }
773
-
774
-        echo $after_plugin_row;
775
-    }
776
-
777
-
778
-    /**
779
-     * a safe space for addons to add additional logic like setting hooks
780
-     * that will run immediately after addon registration
781
-     * making this a great place for code that needs to be "omnipresent"
782
-     *
783
-     * @since 4.9.26
784
-     */
785
-    public function after_registration()
786
-    {
787
-        // cricket chirp... cricket chirp...
788
-    }
764
+				$after_plugin_row .= '</td>';
765
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
766
+				$after_plugin_row .= $description;
767
+				$after_plugin_row .= '</td>';
768
+				$after_plugin_row .= '</tr>';
769
+			} else {
770
+				$after_plugin_row .= $description;
771
+			}
772
+		}
773
+
774
+		echo $after_plugin_row;
775
+	}
776
+
777
+
778
+	/**
779
+	 * a safe space for addons to add additional logic like setting hooks
780
+	 * that will run immediately after addon registration
781
+	 * making this a great place for code that needs to be "omnipresent"
782
+	 *
783
+	 * @since 4.9.26
784
+	 */
785
+	public function after_registration()
786
+	{
787
+		// cricket chirp... cricket chirp...
788
+	}
789 789
 
790 790
 
791 791
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     public function set_plugins_page_row($plugins_page_row = array())
236 236
     {
237 237
         // sigh.... check for example content that I stupidly merged to master and remove it if found
238
-        if (! is_array($plugins_page_row) && strpos($plugins_page_row,
238
+        if ( ! is_array($plugins_page_row) && strpos($plugins_page_row,
239 239
                 '<h3>Promotions Addon Upsell Info</h3>') !== false) {
240 240
             $plugins_page_row = '';
241 241
         }
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
      */
485 485
     public function get_activation_indicator_option_name()
486 486
     {
487
-        return 'ee_activation_' . $this->name();
487
+        return 'ee_activation_'.$this->name();
488 488
     }
489 489
 
490 490
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      */
507 507
     public function detect_req_type()
508 508
     {
509
-        if (! $this->_req_type) {
509
+        if ( ! $this->_req_type) {
510 510
             $this->detect_activation_or_upgrade();
511 511
         }
512 512
         return $this->_req_type;
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      */
571 571
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
572 572
     {
573
-        if (! $version_history) {
573
+        if ( ! $version_history) {
574 574
             $version_history = $this->get_activation_history();
575 575
         }
576 576
         if ($current_version_to_add === null) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
      */
591 591
     public function get_activation_history_option_name()
592 592
     {
593
-        return self::ee_addon_version_history_option_prefix . $this->name();
593
+        return self::ee_addon_version_history_option_prefix.$this->name();
594 594
     }
595 595
 
596 596
 
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
         // is admin and not in M-Mode ?
673 673
         if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
674 674
             add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
675
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
675
+            add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
676 676
         }
677 677
     }
678 678
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
         if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
691 691
             // before other links
692 692
             array_unshift($links,
693
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __('Settings') . '</a>');
693
+                '<a href="admin.php?page='.$this->plugin_action_slug().'">'.__('Settings').'</a>');
694 694
         }
695 695
         return $links;
696 696
     }
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
             $link_text        = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
717 717
             $link_url         = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
718 718
             $description      = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
719
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
719
+            if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
720
+                $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
721 721
                 $after_plugin_row .= '<th class="check-column" scope="row"></th>';
722 722
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
723 723
                 $after_plugin_row .= '<style>
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 </style>';
760 760
                 $after_plugin_row .= '
761 761
 <p class="ee-addon-upsell-info-dv">
762
-	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
762
+	<a class="ee-button" href="' . $link_url.'">'.$link_text.' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
763 763
 </p>';
764 764
                 $after_plugin_row .= '</td>';
765 765
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
Please login to merge, or discard this patch.
espresso.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
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
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            '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.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'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.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.073');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.073');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
+    if ( ! function_exists('espresso_duplicate_plugin_error')) {
42 42
         /**
43 43
          *    espresso_duplicate_plugin_error
44 44
          *    displays if more than one version of EE is activated at the same time
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
 } else {
65 65
     define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67 67
         /**
68 68
          * espresso_minimum_php_version_error
69 69
          *
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
                 return;
128 128
             }
129 129
             // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
130
+            if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
131
+                require_once   EE_HELPERS.'EEH_Debug_Tools.helper.php';
132 132
                 \EEH_Debug_Tools::instance();
133 133
             }
134 134
             // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
135
+            if (is_readable(EE_CORE.'EE_Error.core.php')) {
136
+                require_once EE_CORE.'EE_Error.core.php';
137 137
             } else {
138 138
                 wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139 139
             }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             if (is_readable($full_path_to_file)) {
154 154
                 require_once $full_path_to_file;
155 155
             } else {
156
-                throw new \EE_Error (
156
+                throw new \EE_Error(
157 157
                     sprintf(
158 158
                         esc_html__(
159 159
                             'The %s class file could not be located or is not readable due to file permissions.',
@@ -179,47 +179,47 @@  discard block
 block discarded – undo
179 179
          */
180 180
         function bootstrap_espresso()
181 181
         {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
182
+            require_once __DIR__.'/core/espresso_definitions.php';
183 183
             try {
184 184
                 espresso_load_error_handling();
185 185
                 espresso_load_required(
186 186
                     'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+                    EE_CORE.'helpers'.DS.'EEH_Base.helper.php'
188 188
                 );
189 189
                 espresso_load_required(
190 190
                     'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+                    EE_CORE.'interfaces'.DS.'EEHI_File.interface.php'
192 192
                 );
193 193
                 espresso_load_required(
194 194
                     'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+                    EE_CORE.'helpers'.DS.'EEH_File.helper.php'
196 196
                 );
197 197
                 espresso_load_required(
198 198
                     'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+                    EE_CORE.'helpers'.DS.'EEH_Array.helper.php'
200 200
                 );
201 201
                 // instantiate and configure PSR4 autoloader
202 202
                 espresso_load_required(
203 203
                     'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
204
+                    EE_CORE.'Psr4Autoloader.php'
205 205
                 );
206 206
                 espresso_load_required(
207 207
                     'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+                    EE_CORE.'EE_Psr4AutoloaderInit.core.php'
209 209
                 );
210 210
                 $AutoloaderInit = new EE_Psr4AutoloaderInit();
211 211
                 $AutoloaderInit->initializeAutoloader();
212 212
                 espresso_load_required(
213 213
                     'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+                    EE_CORE.'request_stack'.DS.'EE_Request.core.php'
215 215
                 );
216 216
                 espresso_load_required(
217 217
                     'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+                    EE_CORE.'request_stack'.DS.'EE_Response.core.php'
219 219
                 );
220 220
                 espresso_load_required(
221 221
                     'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
+                    EE_CORE.'EE_Bootstrap.core.php'
223 223
                 );
224 224
                 // bootstrap EE and the request stack
225 225
                 new EE_Bootstrap(
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
                     new EE_Response()
228 228
                 );
229 229
             } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
+                require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php';
231 231
                 new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232 232
             }
233 233
         }
234 234
         bootstrap_espresso();
235 235
     }
236 236
 }
237
-if (! function_exists('espresso_deactivate_plugin')) {
237
+if ( ! function_exists('espresso_deactivate_plugin')) {
238 238
     /**
239 239
      *    deactivate_plugin
240 240
      * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
      */
246 246
     function espresso_deactivate_plugin($plugin_basename = '')
247 247
     {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
248
+        if ( ! function_exists('deactivate_plugins')) {
249
+            require_once ABSPATH.'wp-admin/includes/plugin.php';
250 250
         }
251 251
         unset($_GET['activate'], $_REQUEST['activate']);
252 252
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this patch.
core/services/notifications/PersistentAdminNoticeManager.php 1 patch
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -27,338 +27,338 @@
 block discarded – undo
27 27
 class PersistentAdminNoticeManager
28 28
 {
29 29
 
30
-    const WP_OPTION_KEY = 'ee_pers_admin_notices';
31
-
32
-    /**
33
-     * @var Collection|PersistentAdminNotice[] $notice_collection
34
-     */
35
-    private $notice_collection;
36
-
37
-    /**
38
-     * @type string $return_url
39
-     */
40
-    private $return_url;
41
-
42
-    /**
43
-     * @type CapabilitiesChecker $capabilities_checker
44
-     */
45
-    private $capabilities_checker;
46
-
47
-    /**
48
-     * @type EE_Request $request
49
-     */
50
-    private $request;
51
-
52
-
53
-
54
-    /**
55
-     * CapChecker constructor
56
-     *
57
-     * @param string $return_url
58
-     * @param CapabilitiesChecker $capabilities_checker
59
-     * @param EE_Request          $request
60
-     * @throws InvalidDataTypeException
61
-     */
62
-    public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request)
63
-    {
64
-        $this->setReturnUrl($return_url);
65
-        $this->capabilities_checker = $capabilities_checker;
66
-        $this->request = $request;
67
-        //ok so we want to enable the entire admin
68
-        add_action('admin_notices', array($this, 'displayNotices'), 9);
69
-        add_action('network_admin_notices', array($this, 'displayNotices'), 9);
70
-        add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
71
-        add_action('shutdown', array($this, 'saveNotices'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param string $return_url
78
-     * @throws InvalidDataTypeException
79
-     */
80
-    private function setReturnUrl($return_url)
81
-    {
82
-        if ( ! is_string($return_url)) {
83
-            throw new InvalidDataTypeException('$return_url', $return_url, 'string');
84
-        }
85
-        $this->return_url = $return_url;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @return Collection
92
-     * @throws InvalidInterfaceException
93
-     * @throws InvalidDataTypeException
94
-     * @throws DomainException
95
-     */
96
-    protected function getPersistentAdminNoticeCollection()
97
-    {
98
-        if ( ! $this->notice_collection instanceof Collection) {
99
-            $this->notice_collection = new Collection(
100
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
101
-            );
102
-            $this->retrieveStoredNotices();
103
-            $this->registerNotices();
104
-        }
105
-        return $this->notice_collection;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
112
-     *
113
-     * @return void
114
-     * @throws DomainException
115
-     * @throws InvalidDataTypeException
116
-     */
117
-    public function retrieveStoredNotices()
118
-    {
119
-        $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
120
-        // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__);
121
-        if ( ! empty($persistent_admin_notices)) {
122
-            foreach ($persistent_admin_notices as $name => $details) {
123
-                if (is_array($details)){
124
-                    if (
125
-                        ! isset(
126
-                            $details['message'],
127
-                            $details['capability'],
128
-                            $details['cap_context'],
129
-                            $details['dismissed']
130
-                        )
131
-                    ) {
132
-                        throw new DomainException(
133
-                            sprintf(
134
-                                esc_html__(
135
-                                    'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
136
-                                    'event_espresso'
137
-                                ),
138
-                                $name
139
-                            )
140
-                        );
141
-                    }
142
-                    // new format for nag notices
143
-                    new PersistentAdminNotice(
144
-                        $name,
145
-                        $details['message'],
146
-                        false,
147
-                        $details['capability'],
148
-                        $details['cap_context'],
149
-                        $details['dismissed']
150
-                    );
151
-                } else {
152
-                    try {
153
-                        // old nag notices, that we want to convert to the new format
154
-                        new PersistentAdminNotice(
155
-                            $name,
156
-                            (string)$details,
157
-                            false,
158
-                            '',
159
-                            '',
160
-                            empty($details)
161
-                        );
162
-                    } catch (\Exception $e) {
163
-                        EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
164
-                    }
165
-                }
166
-                // each notice will self register when the action hook in registerNotices is triggered
167
-            }
168
-        }
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * exposes the Persistent Admin Notice Collection via an action
175
-     * so that PersistentAdminNotice objects can be added and/or removed
176
-     * without compromising the actual collection like a filter would
177
-     */
178
-    public function registerNotices()
179
-    {
180
-        do_action(
181
-            'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
182
-            $this->notice_collection
183
-        );
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @throws DomainException
190
-     * @throws InvalidClassException
191
-     * @throws InvalidDataTypeException
192
-     * @throws InvalidInterfaceException
193
-     */
194
-    public function displayNotices()
195
-    {
196
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
197
-        if ($this->notice_collection->hasObjects()) {
198
-            // and display notices
199
-            foreach ($this->notice_collection as $persistent_admin_notice) {
200
-                /** @var PersistentAdminNotice $persistent_admin_notice */
201
-                // don't display notices that have already been dismissed
202
-                if ($persistent_admin_notice->getDismissed()) {
203
-                    continue;
204
-                }
205
-                try {
206
-                    $this->capabilities_checker->processCapCheck(
207
-                        $persistent_admin_notice->getCapCheck()
208
-                    );
209
-                } catch (InsufficientPermissionsException $e) {
210
-                    // user does not have required cap, so skip to next notice
211
-                    // and just eat the exception - nom nom nom nom
212
-                    continue;
213
-                }
214
-                $this->displayPersistentAdminNotice($persistent_admin_notice);
215
-            }
216
-        }
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * does what it's named
223
-     *
224
-     * @return bool
225
-     */
226
-    public function enqueueAssets()
227
-    {
228
-        static $print_scripts = true;
229
-        if (! $print_scripts) {
230
-            return $print_scripts;
231
-        }
232
-        wp_register_script(
233
-            'espresso_core',
234
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
235
-            array('jquery'),
236
-            EVENT_ESPRESSO_VERSION,
237
-            true
238
-        );
239
-        wp_register_script(
240
-            'ee_error_js',
241
-            EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
242
-            array('espresso_core'),
243
-            EVENT_ESPRESSO_VERSION,
244
-            true
245
-        );
246
-        wp_enqueue_script('ee_error_js');
247
-        $print_scripts = true;
248
-        return $print_scripts;
249
-    }
250
-
251
-
252
-
253
-
254
-    /**
255
-     * displayPersistentAdminNoticeHtml
256
-     *
257
-     * @param  PersistentAdminNotice $persistent_admin_notice
258
-     */
259
-    public function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
260
-    {
261
-        // used in template for printing css
262
-        $print_styles = $this->enqueueAssets();
263
-        wp_localize_script(
264
-            'espresso_core',
265
-            'ee_dismiss',
266
-            array(
267
-                'nag_notice'    => $persistent_admin_notice->getName(),
268
-                'return_url'    => urlencode($this->return_url),
269
-                'ajax_url'      => WP_AJAX_URL,
270
-                'unknown_error' => esc_html__(
271
-                    'An unknown error has occurred on the server while attempting to dismiss this notice.',
272
-                    'event_espresso'
273
-                )
274
-            )
275
-        );
276
-        // used in template
277
-        $persistent_admin_notice_name = $persistent_admin_notice->getName();
278
-        $persistent_admin_notice_message = $persistent_admin_notice->getMessage();
279
-        require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php';
280
-    }
281
-
282
-
283
-
284
-    /**
285
-     * dismissNotice
286
-     *
287
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
288
-     * @param bool   $purge    if true, then delete it from the db
289
-     * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
290
-     * @return void
291
-     * @throws InvalidInterfaceException
292
-     * @throws InvalidDataTypeException
293
-     * @throws DomainException
294
-     */
295
-    public function dismissNotice($pan_name = '', $purge = false, $return = false)
296
-    {
297
-        $pan_name = $this->request->get('ee_nag_notice', $pan_name);
298
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
299
-        if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)){
300
-            /** @var PersistentAdminNotice $persistent_admin_notice */
301
-            $persistent_admin_notice = $this->notice_collection->get($pan_name);
302
-            $persistent_admin_notice->setDismissed(true);
303
-            $persistent_admin_notice->setPurge($purge);
304
-            $this->saveNotices();
305
-        }
306
-        if ($return) {
307
-            return;
308
-        }
309
-        if ($this->request->ajax) {
310
-            // grab any notices and concatenate into string
311
-            echo wp_json_encode(
312
-                array(
313
-                    'errors' => implode('<br />', EE_Error::get_notices(false))
314
-                )
315
-            );
316
-            exit();
317
-        }
318
-        // save errors to a transient to be displayed on next request (after redirect)
319
-        EE_Error::get_notices(false, true);
320
-        wp_safe_redirect(
321
-            urldecode(
322
-                $this->request->get('return_url', '')
323
-            )
324
-        );
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * saveNotices
331
-     *
332
-     * @throws DomainException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    public function saveNotices()
337
-    {
338
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
339
-        if ($this->notice_collection->hasObjects()) {
340
-            $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
341
-            //maybe initialize persistent_admin_notices
342
-            if (empty($persistent_admin_notices)) {
343
-                add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
344
-            }
345
-            foreach ($this->notice_collection as $persistent_admin_notice) {
346
-                // are we deleting this notice ?
347
-                if ($persistent_admin_notice->getPurge()) {
348
-                    unset($persistent_admin_notices[$persistent_admin_notice->getName()]);
349
-                } else {
350
-                    /** @var PersistentAdminNotice $persistent_admin_notice */
351
-                    $persistent_admin_notices[$persistent_admin_notice->getName()] = array(
352
-                        'message'     => $persistent_admin_notice->getMessage(),
353
-                        'capability'  => $persistent_admin_notice->getCapability(),
354
-                        'cap_context' => $persistent_admin_notice->getCapContext(),
355
-                        'dismissed'   => $persistent_admin_notice->getDismissed(),
356
-                    );
357
-                }
358
-            }
359
-            update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
360
-        }
361
-    }
30
+	const WP_OPTION_KEY = 'ee_pers_admin_notices';
31
+
32
+	/**
33
+	 * @var Collection|PersistentAdminNotice[] $notice_collection
34
+	 */
35
+	private $notice_collection;
36
+
37
+	/**
38
+	 * @type string $return_url
39
+	 */
40
+	private $return_url;
41
+
42
+	/**
43
+	 * @type CapabilitiesChecker $capabilities_checker
44
+	 */
45
+	private $capabilities_checker;
46
+
47
+	/**
48
+	 * @type EE_Request $request
49
+	 */
50
+	private $request;
51
+
52
+
53
+
54
+	/**
55
+	 * CapChecker constructor
56
+	 *
57
+	 * @param string $return_url
58
+	 * @param CapabilitiesChecker $capabilities_checker
59
+	 * @param EE_Request          $request
60
+	 * @throws InvalidDataTypeException
61
+	 */
62
+	public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request)
63
+	{
64
+		$this->setReturnUrl($return_url);
65
+		$this->capabilities_checker = $capabilities_checker;
66
+		$this->request = $request;
67
+		//ok so we want to enable the entire admin
68
+		add_action('admin_notices', array($this, 'displayNotices'), 9);
69
+		add_action('network_admin_notices', array($this, 'displayNotices'), 9);
70
+		add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
71
+		add_action('shutdown', array($this, 'saveNotices'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param string $return_url
78
+	 * @throws InvalidDataTypeException
79
+	 */
80
+	private function setReturnUrl($return_url)
81
+	{
82
+		if ( ! is_string($return_url)) {
83
+			throw new InvalidDataTypeException('$return_url', $return_url, 'string');
84
+		}
85
+		$this->return_url = $return_url;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @return Collection
92
+	 * @throws InvalidInterfaceException
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws DomainException
95
+	 */
96
+	protected function getPersistentAdminNoticeCollection()
97
+	{
98
+		if ( ! $this->notice_collection instanceof Collection) {
99
+			$this->notice_collection = new Collection(
100
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
101
+			);
102
+			$this->retrieveStoredNotices();
103
+			$this->registerNotices();
104
+		}
105
+		return $this->notice_collection;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
112
+	 *
113
+	 * @return void
114
+	 * @throws DomainException
115
+	 * @throws InvalidDataTypeException
116
+	 */
117
+	public function retrieveStoredNotices()
118
+	{
119
+		$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
120
+		// \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__);
121
+		if ( ! empty($persistent_admin_notices)) {
122
+			foreach ($persistent_admin_notices as $name => $details) {
123
+				if (is_array($details)){
124
+					if (
125
+						! isset(
126
+							$details['message'],
127
+							$details['capability'],
128
+							$details['cap_context'],
129
+							$details['dismissed']
130
+						)
131
+					) {
132
+						throw new DomainException(
133
+							sprintf(
134
+								esc_html__(
135
+									'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
136
+									'event_espresso'
137
+								),
138
+								$name
139
+							)
140
+						);
141
+					}
142
+					// new format for nag notices
143
+					new PersistentAdminNotice(
144
+						$name,
145
+						$details['message'],
146
+						false,
147
+						$details['capability'],
148
+						$details['cap_context'],
149
+						$details['dismissed']
150
+					);
151
+				} else {
152
+					try {
153
+						// old nag notices, that we want to convert to the new format
154
+						new PersistentAdminNotice(
155
+							$name,
156
+							(string)$details,
157
+							false,
158
+							'',
159
+							'',
160
+							empty($details)
161
+						);
162
+					} catch (\Exception $e) {
163
+						EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
164
+					}
165
+				}
166
+				// each notice will self register when the action hook in registerNotices is triggered
167
+			}
168
+		}
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * exposes the Persistent Admin Notice Collection via an action
175
+	 * so that PersistentAdminNotice objects can be added and/or removed
176
+	 * without compromising the actual collection like a filter would
177
+	 */
178
+	public function registerNotices()
179
+	{
180
+		do_action(
181
+			'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
182
+			$this->notice_collection
183
+		);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @throws DomainException
190
+	 * @throws InvalidClassException
191
+	 * @throws InvalidDataTypeException
192
+	 * @throws InvalidInterfaceException
193
+	 */
194
+	public function displayNotices()
195
+	{
196
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
197
+		if ($this->notice_collection->hasObjects()) {
198
+			// and display notices
199
+			foreach ($this->notice_collection as $persistent_admin_notice) {
200
+				/** @var PersistentAdminNotice $persistent_admin_notice */
201
+				// don't display notices that have already been dismissed
202
+				if ($persistent_admin_notice->getDismissed()) {
203
+					continue;
204
+				}
205
+				try {
206
+					$this->capabilities_checker->processCapCheck(
207
+						$persistent_admin_notice->getCapCheck()
208
+					);
209
+				} catch (InsufficientPermissionsException $e) {
210
+					// user does not have required cap, so skip to next notice
211
+					// and just eat the exception - nom nom nom nom
212
+					continue;
213
+				}
214
+				$this->displayPersistentAdminNotice($persistent_admin_notice);
215
+			}
216
+		}
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * does what it's named
223
+	 *
224
+	 * @return bool
225
+	 */
226
+	public function enqueueAssets()
227
+	{
228
+		static $print_scripts = true;
229
+		if (! $print_scripts) {
230
+			return $print_scripts;
231
+		}
232
+		wp_register_script(
233
+			'espresso_core',
234
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
235
+			array('jquery'),
236
+			EVENT_ESPRESSO_VERSION,
237
+			true
238
+		);
239
+		wp_register_script(
240
+			'ee_error_js',
241
+			EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
242
+			array('espresso_core'),
243
+			EVENT_ESPRESSO_VERSION,
244
+			true
245
+		);
246
+		wp_enqueue_script('ee_error_js');
247
+		$print_scripts = true;
248
+		return $print_scripts;
249
+	}
250
+
251
+
252
+
253
+
254
+	/**
255
+	 * displayPersistentAdminNoticeHtml
256
+	 *
257
+	 * @param  PersistentAdminNotice $persistent_admin_notice
258
+	 */
259
+	public function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
260
+	{
261
+		// used in template for printing css
262
+		$print_styles = $this->enqueueAssets();
263
+		wp_localize_script(
264
+			'espresso_core',
265
+			'ee_dismiss',
266
+			array(
267
+				'nag_notice'    => $persistent_admin_notice->getName(),
268
+				'return_url'    => urlencode($this->return_url),
269
+				'ajax_url'      => WP_AJAX_URL,
270
+				'unknown_error' => esc_html__(
271
+					'An unknown error has occurred on the server while attempting to dismiss this notice.',
272
+					'event_espresso'
273
+				)
274
+			)
275
+		);
276
+		// used in template
277
+		$persistent_admin_notice_name = $persistent_admin_notice->getName();
278
+		$persistent_admin_notice_message = $persistent_admin_notice->getMessage();
279
+		require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php';
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * dismissNotice
286
+	 *
287
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
288
+	 * @param bool   $purge    if true, then delete it from the db
289
+	 * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
290
+	 * @return void
291
+	 * @throws InvalidInterfaceException
292
+	 * @throws InvalidDataTypeException
293
+	 * @throws DomainException
294
+	 */
295
+	public function dismissNotice($pan_name = '', $purge = false, $return = false)
296
+	{
297
+		$pan_name = $this->request->get('ee_nag_notice', $pan_name);
298
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
299
+		if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)){
300
+			/** @var PersistentAdminNotice $persistent_admin_notice */
301
+			$persistent_admin_notice = $this->notice_collection->get($pan_name);
302
+			$persistent_admin_notice->setDismissed(true);
303
+			$persistent_admin_notice->setPurge($purge);
304
+			$this->saveNotices();
305
+		}
306
+		if ($return) {
307
+			return;
308
+		}
309
+		if ($this->request->ajax) {
310
+			// grab any notices and concatenate into string
311
+			echo wp_json_encode(
312
+				array(
313
+					'errors' => implode('<br />', EE_Error::get_notices(false))
314
+				)
315
+			);
316
+			exit();
317
+		}
318
+		// save errors to a transient to be displayed on next request (after redirect)
319
+		EE_Error::get_notices(false, true);
320
+		wp_safe_redirect(
321
+			urldecode(
322
+				$this->request->get('return_url', '')
323
+			)
324
+		);
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * saveNotices
331
+	 *
332
+	 * @throws DomainException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	public function saveNotices()
337
+	{
338
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
339
+		if ($this->notice_collection->hasObjects()) {
340
+			$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
341
+			//maybe initialize persistent_admin_notices
342
+			if (empty($persistent_admin_notices)) {
343
+				add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
344
+			}
345
+			foreach ($this->notice_collection as $persistent_admin_notice) {
346
+				// are we deleting this notice ?
347
+				if ($persistent_admin_notice->getPurge()) {
348
+					unset($persistent_admin_notices[$persistent_admin_notice->getName()]);
349
+				} else {
350
+					/** @var PersistentAdminNotice $persistent_admin_notice */
351
+					$persistent_admin_notices[$persistent_admin_notice->getName()] = array(
352
+						'message'     => $persistent_admin_notice->getMessage(),
353
+						'capability'  => $persistent_admin_notice->getCapability(),
354
+						'cap_context' => $persistent_admin_notice->getCapContext(),
355
+						'dismissed'   => $persistent_admin_notice->getDismissed(),
356
+					);
357
+				}
358
+			}
359
+			update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
360
+		}
361
+	}
362 362
 
363 363
 
364 364
 
Please login to merge, or discard this patch.
core/middleware/EE_Recommended_Versions.core.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -21,155 +21,155 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * converts a Request to a Response
26
-     *
27
-     * @param EE_Request  $request
28
-     * @param EE_Response $response
29
-     * @return EE_Response
30
-     * @throws InvalidDataTypeException
31
-     */
32
-    public function handle_request(EE_Request $request, EE_Response $response)
33
-    {
34
-        $this->_request  = $request;
35
-        $this->_response = $response;
36
-        //$this->_response->add_output( "\n\t IN >>  " . __CLASS__ );
37
-        //$this->_response->set_notice( 1, 'hey look at this' );
38
-        // check required WP version
39
-        if (! $this->_minimum_wp_version_required()) {
40
-            $this->_request->un_set('activate', true);
41
-            add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1);
42
-            //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' );
43
-            $this->_response->terminate_request();
44
-            $this->_response->deactivate_plugin();
45
-        }
46
-        // check recommended PHP version
47
-        if (! $this->_minimum_php_version_recommended()) {
48
-            $this->_display_minimum_recommended_php_version_notice();
49
-        }
50
-        $this->_response = $this->process_request_stack($this->_request, $this->_response);
51
-        //$this->_response->add_output( "\n\t OUT << " . __CLASS__ );
52
-        return $this->_response;
53
-    }
54
-
55
-
56
-    /**
57
-     * Helper method to assess installed wp version against given values.
58
-     * By default this compares the required minimum version of WP for EE against the installed version of WP
59
-     * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
60
-     * against) so consider that when sending in your values.
61
-     *
62
-     * @param string $version_to_check
63
-     * @param string $operator
64
-     * @return bool
65
-     */
66
-    public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
67
-    {
68
-        global $wp_version;
69
-        return version_compare(
70
-            // first account for wp_version being pre-release
71
-            // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
72
-            strpos($wp_version, '-') > 0
73
-                ? substr($wp_version, 0, strpos($wp_version, '-'))
74
-                : $wp_version,
75
-            $version_to_check,
76
-            $operator
77
-        );
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     *    _minimum_wp_version_required
84
-     *
85
-     * @access private
86
-     * @return boolean
87
-     */
88
-    private function _minimum_wp_version_required()
89
-    {
90
-        return EE_Recommended_Versions::check_wp_version();
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    _check_php_version
97
-     *
98
-     * @access private
99
-     * @param string $min_version
100
-     * @return boolean
101
-     */
102
-    private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED)
103
-    {
104
-        return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     *    _minimum_php_version_recommended
111
-     *
112
-     * @access private
113
-     * @return boolean
114
-     */
115
-    private function _minimum_php_version_recommended()
116
-    {
117
-        return $this->_check_php_version();
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     *    minimum_wp_version_error
124
-     *
125
-     * @return void
126
-     */
127
-    public function minimum_wp_version_error()
128
-    {
129
-        global $wp_version;
130
-        ?>
24
+	/**
25
+	 * converts a Request to a Response
26
+	 *
27
+	 * @param EE_Request  $request
28
+	 * @param EE_Response $response
29
+	 * @return EE_Response
30
+	 * @throws InvalidDataTypeException
31
+	 */
32
+	public function handle_request(EE_Request $request, EE_Response $response)
33
+	{
34
+		$this->_request  = $request;
35
+		$this->_response = $response;
36
+		//$this->_response->add_output( "\n\t IN >>  " . __CLASS__ );
37
+		//$this->_response->set_notice( 1, 'hey look at this' );
38
+		// check required WP version
39
+		if (! $this->_minimum_wp_version_required()) {
40
+			$this->_request->un_set('activate', true);
41
+			add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1);
42
+			//$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' );
43
+			$this->_response->terminate_request();
44
+			$this->_response->deactivate_plugin();
45
+		}
46
+		// check recommended PHP version
47
+		if (! $this->_minimum_php_version_recommended()) {
48
+			$this->_display_minimum_recommended_php_version_notice();
49
+		}
50
+		$this->_response = $this->process_request_stack($this->_request, $this->_response);
51
+		//$this->_response->add_output( "\n\t OUT << " . __CLASS__ );
52
+		return $this->_response;
53
+	}
54
+
55
+
56
+	/**
57
+	 * Helper method to assess installed wp version against given values.
58
+	 * By default this compares the required minimum version of WP for EE against the installed version of WP
59
+	 * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
60
+	 * against) so consider that when sending in your values.
61
+	 *
62
+	 * @param string $version_to_check
63
+	 * @param string $operator
64
+	 * @return bool
65
+	 */
66
+	public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
67
+	{
68
+		global $wp_version;
69
+		return version_compare(
70
+			// first account for wp_version being pre-release
71
+			// (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
72
+			strpos($wp_version, '-') > 0
73
+				? substr($wp_version, 0, strpos($wp_version, '-'))
74
+				: $wp_version,
75
+			$version_to_check,
76
+			$operator
77
+		);
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 *    _minimum_wp_version_required
84
+	 *
85
+	 * @access private
86
+	 * @return boolean
87
+	 */
88
+	private function _minimum_wp_version_required()
89
+	{
90
+		return EE_Recommended_Versions::check_wp_version();
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    _check_php_version
97
+	 *
98
+	 * @access private
99
+	 * @param string $min_version
100
+	 * @return boolean
101
+	 */
102
+	private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED)
103
+	{
104
+		return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 *    _minimum_php_version_recommended
111
+	 *
112
+	 * @access private
113
+	 * @return boolean
114
+	 */
115
+	private function _minimum_php_version_recommended()
116
+	{
117
+		return $this->_check_php_version();
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 *    minimum_wp_version_error
124
+	 *
125
+	 * @return void
126
+	 */
127
+	public function minimum_wp_version_error()
128
+	{
129
+		global $wp_version;
130
+		?>
131 131
         <div class="error">
132 132
             <p>
133 133
                 <?php
134
-                printf(
135
-                    __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
136
-                        'event_espresso'),
137
-                    EE_MIN_WP_VER_REQUIRED,
138
-                    $wp_version,
139
-                    '<br/>',
140
-                    '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
141
-                );
142
-                ?>
134
+				printf(
135
+					__('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
136
+						'event_espresso'),
137
+					EE_MIN_WP_VER_REQUIRED,
138
+					$wp_version,
139
+					'<br/>',
140
+					'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
141
+				);
142
+				?>
143 143
             </p>
144 144
         </div>
145 145
         <?php
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     *    _display_minimum_recommended_php_version_notice
152
-     *
153
-     * @access private
154
-     * @return void
155
-     * @throws InvalidDataTypeException
156
-     */
157
-    private function _display_minimum_recommended_php_version_notice()
158
-    {
159
-        new PersistentAdminNotice(
160
-            'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
161
-            sprintf(
162
-                __(
163
-                    'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
164
-                    'event_espresso'
165
-                ),
166
-                EE_MIN_PHP_VER_RECOMMENDED,
167
-                PHP_VERSION,
168
-                '<br/>',
169
-                '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
170
-            )
171
-        );
172
-    }
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 *    _display_minimum_recommended_php_version_notice
152
+	 *
153
+	 * @access private
154
+	 * @return void
155
+	 * @throws InvalidDataTypeException
156
+	 */
157
+	private function _display_minimum_recommended_php_version_notice()
158
+	{
159
+		new PersistentAdminNotice(
160
+			'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
161
+			sprintf(
162
+				__(
163
+					'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
164
+					'event_espresso'
165
+				),
166
+				EE_MIN_PHP_VER_RECOMMENDED,
167
+				PHP_VERSION,
168
+				'<br/>',
169
+				'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
170
+			)
171
+		);
172
+	}
173 173
 
174 174
 
175 175
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         //$this->_response->add_output( "\n\t IN >>  " . __CLASS__ );
37 37
         //$this->_response->set_notice( 1, 'hey look at this' );
38 38
         // check required WP version
39
-        if (! $this->_minimum_wp_version_required()) {
39
+        if ( ! $this->_minimum_wp_version_required()) {
40 40
             $this->_request->un_set('activate', true);
41 41
             add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1);
42 42
             //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' );
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             $this->_response->deactivate_plugin();
45 45
         }
46 46
         // check recommended PHP version
47
-        if (! $this->_minimum_php_version_recommended()) {
47
+        if ( ! $this->_minimum_php_version_recommended()) {
48 48
             $this->_display_minimum_recommended_php_version_notice();
49 49
         }
50 50
         $this->_response = $this->process_request_stack($this->_request, $this->_response);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     private function _display_minimum_recommended_php_version_notice()
158 158
     {
159 159
         new PersistentAdminNotice(
160
-            'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
160
+            'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended',
161 161
             sprintf(
162 162
                 __(
163 163
                     'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
Please login to merge, or discard this patch.
core/EE_Error.core.php 1 patch
Indentation   +1032 added lines, -1032 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 // if you're a dev and want to receive all errors via email
12 12
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
13 13
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
14
-    set_error_handler(array('EE_Error', 'error_handler'));
15
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14
+	set_error_handler(array('EE_Error', 'error_handler'));
15
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
16 16
 }
17 17
 
18 18
 
@@ -28,253 +28,253 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * name of the file to log exceptions to
33
-     *
34
-     * @var string
35
-     */
36
-    private static $_exception_log_file = 'espresso_error_log.txt';
37
-
38
-    /**
39
-     *    stores details for all exception
40
-     *
41
-     * @var array
42
-     */
43
-    private static $_all_exceptions = array();
44
-
45
-    /**
46
-     *    tracks number of errors
47
-     *
48
-     * @var int
49
-     */
50
-    private static $_error_count = 0;
51
-
52
-    /**
53
-     * @var array $_espresso_notices
54
-     */
55
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
-
57
-
58
-
59
-    /**
60
-     * @override default exception handling
61
-     * @param string         $message
62
-     * @param int            $code
63
-     * @param Exception|null $previous
64
-     */
65
-    public function __construct($message, $code = 0, Exception $previous = null)
66
-    {
67
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
68
-            parent::__construct($message, $code);
69
-        } else {
70
-            parent::__construct($message, $code, $previous);
71
-        }
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    error_handler
78
-     *
79
-     * @param $code
80
-     * @param $message
81
-     * @param $file
82
-     * @param $line
83
-     * @return void
84
-     */
85
-    public static function error_handler($code, $message, $file, $line)
86
-    {
87
-        $type = EE_Error::error_type($code);
88
-        $site = site_url();
89
-        switch ($site) {
90
-            case 'http://ee4.eventespresso.com/' :
91
-            case 'http://ee4decaf.eventespresso.com/' :
92
-            case 'http://ee4hf.eventespresso.com/' :
93
-            case 'http://ee4a.eventespresso.com/' :
94
-            case 'http://ee4ad.eventespresso.com/' :
95
-            case 'http://ee4b.eventespresso.com/' :
96
-            case 'http://ee4bd.eventespresso.com/' :
97
-            case 'http://ee4d.eventespresso.com/' :
98
-            case 'http://ee4dd.eventespresso.com/' :
99
-                $to = '[email protected]';
100
-                break;
101
-            default :
102
-                $to = get_option('admin_email');
103
-        }
104
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
106
-        if (function_exists('wp_mail')) {
107
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
-            wp_mail($to, $subject, $msg);
109
-        }
110
-        echo '<div id="message" class="espresso-notices error"><p>';
111
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
-        echo '<br /></p></div>';
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * error_type
119
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
120
-     *
121
-     * @param $code
122
-     * @return string
123
-     */
124
-    public static function error_type($code)
125
-    {
126
-        switch ($code) {
127
-            case E_ERROR: // 1 //
128
-                return 'E_ERROR';
129
-            case E_WARNING: // 2 //
130
-                return 'E_WARNING';
131
-            case E_PARSE: // 4 //
132
-                return 'E_PARSE';
133
-            case E_NOTICE: // 8 //
134
-                return 'E_NOTICE';
135
-            case E_CORE_ERROR: // 16 //
136
-                return 'E_CORE_ERROR';
137
-            case E_CORE_WARNING: // 32 //
138
-                return 'E_CORE_WARNING';
139
-            case E_COMPILE_ERROR: // 64 //
140
-                return 'E_COMPILE_ERROR';
141
-            case E_COMPILE_WARNING: // 128 //
142
-                return 'E_COMPILE_WARNING';
143
-            case E_USER_ERROR: // 256 //
144
-                return 'E_USER_ERROR';
145
-            case E_USER_WARNING: // 512 //
146
-                return 'E_USER_WARNING';
147
-            case E_USER_NOTICE: // 1024 //
148
-                return 'E_USER_NOTICE';
149
-            case E_STRICT: // 2048 //
150
-                return 'E_STRICT';
151
-            case E_RECOVERABLE_ERROR: // 4096 //
152
-                return 'E_RECOVERABLE_ERROR';
153
-            case E_DEPRECATED: // 8192 //
154
-                return 'E_DEPRECATED';
155
-            case E_USER_DEPRECATED: // 16384 //
156
-                return 'E_USER_DEPRECATED';
157
-            case E_ALL: // 16384 //
158
-                return 'E_ALL';
159
-        }
160
-        return '';
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     *    fatal_error_handler
167
-     *
168
-     * @return void
169
-     */
170
-    public static function fatal_error_handler()
171
-    {
172
-        $last_error = error_get_last();
173
-        if ($last_error['type'] === E_ERROR) {
174
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
175
-        }
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * _format_error
182
-     *
183
-     * @param $code
184
-     * @param $message
185
-     * @param $file
186
-     * @param $line
187
-     * @return string
188
-     */
189
-    private static function _format_error($code, $message, $file, $line)
190
-    {
191
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
192
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
193
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
194
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
195
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
196
-        $html .= '</tbody></table>';
197
-        return $html;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * set_content_type
204
-     *
205
-     * @param $content_type
206
-     * @return string
207
-     */
208
-    public static function set_content_type($content_type)
209
-    {
210
-        return 'text/html';
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * @return void
217
-     * @throws EE_Error
218
-     * @throws ReflectionException
219
-     */
220
-    public function get_error()
221
-    {
222
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
223
-            throw $this;
224
-        }
225
-        // get separate user and developer messages if they exist
226
-        $msg = explode('||', $this->getMessage());
227
-        $user_msg = $msg[0];
228
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
229
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
230
-        // add details to _all_exceptions array
231
-        $x_time = time();
232
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
233
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
234
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
235
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
236
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
237
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
238
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
239
-        self::$_error_count++;
240
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
241
-        $this->display_errors();
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * @param bool   $check_stored
248
-     * @param string $type_to_check
249
-     * @return bool
250
-     */
251
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
252
-    {
253
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
254
-                     && ! empty(self::$_espresso_notices[$type_to_check])
255
-            ? true
256
-            : false;
257
-        if ($check_stored && ! $has_error) {
258
-            $notices = (array)get_option('ee_notices', array());
259
-            foreach ($notices as $type => $notice) {
260
-                if ($type === $type_to_check && $notice) {
261
-                    return true;
262
-                }
263
-            }
264
-        }
265
-        return $has_error;
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * @echo string
272
-     * @throws \ReflectionException
273
-     */
274
-    public function display_errors()
275
-    {
276
-        $trace_details = '';
277
-        $output = '
31
+	/**
32
+	 * name of the file to log exceptions to
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private static $_exception_log_file = 'espresso_error_log.txt';
37
+
38
+	/**
39
+	 *    stores details for all exception
40
+	 *
41
+	 * @var array
42
+	 */
43
+	private static $_all_exceptions = array();
44
+
45
+	/**
46
+	 *    tracks number of errors
47
+	 *
48
+	 * @var int
49
+	 */
50
+	private static $_error_count = 0;
51
+
52
+	/**
53
+	 * @var array $_espresso_notices
54
+	 */
55
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
+
57
+
58
+
59
+	/**
60
+	 * @override default exception handling
61
+	 * @param string         $message
62
+	 * @param int            $code
63
+	 * @param Exception|null $previous
64
+	 */
65
+	public function __construct($message, $code = 0, Exception $previous = null)
66
+	{
67
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
68
+			parent::__construct($message, $code);
69
+		} else {
70
+			parent::__construct($message, $code, $previous);
71
+		}
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    error_handler
78
+	 *
79
+	 * @param $code
80
+	 * @param $message
81
+	 * @param $file
82
+	 * @param $line
83
+	 * @return void
84
+	 */
85
+	public static function error_handler($code, $message, $file, $line)
86
+	{
87
+		$type = EE_Error::error_type($code);
88
+		$site = site_url();
89
+		switch ($site) {
90
+			case 'http://ee4.eventespresso.com/' :
91
+			case 'http://ee4decaf.eventespresso.com/' :
92
+			case 'http://ee4hf.eventespresso.com/' :
93
+			case 'http://ee4a.eventespresso.com/' :
94
+			case 'http://ee4ad.eventespresso.com/' :
95
+			case 'http://ee4b.eventespresso.com/' :
96
+			case 'http://ee4bd.eventespresso.com/' :
97
+			case 'http://ee4d.eventespresso.com/' :
98
+			case 'http://ee4dd.eventespresso.com/' :
99
+				$to = '[email protected]';
100
+				break;
101
+			default :
102
+				$to = get_option('admin_email');
103
+		}
104
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
106
+		if (function_exists('wp_mail')) {
107
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
+			wp_mail($to, $subject, $msg);
109
+		}
110
+		echo '<div id="message" class="espresso-notices error"><p>';
111
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
+		echo '<br /></p></div>';
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * error_type
119
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
120
+	 *
121
+	 * @param $code
122
+	 * @return string
123
+	 */
124
+	public static function error_type($code)
125
+	{
126
+		switch ($code) {
127
+			case E_ERROR: // 1 //
128
+				return 'E_ERROR';
129
+			case E_WARNING: // 2 //
130
+				return 'E_WARNING';
131
+			case E_PARSE: // 4 //
132
+				return 'E_PARSE';
133
+			case E_NOTICE: // 8 //
134
+				return 'E_NOTICE';
135
+			case E_CORE_ERROR: // 16 //
136
+				return 'E_CORE_ERROR';
137
+			case E_CORE_WARNING: // 32 //
138
+				return 'E_CORE_WARNING';
139
+			case E_COMPILE_ERROR: // 64 //
140
+				return 'E_COMPILE_ERROR';
141
+			case E_COMPILE_WARNING: // 128 //
142
+				return 'E_COMPILE_WARNING';
143
+			case E_USER_ERROR: // 256 //
144
+				return 'E_USER_ERROR';
145
+			case E_USER_WARNING: // 512 //
146
+				return 'E_USER_WARNING';
147
+			case E_USER_NOTICE: // 1024 //
148
+				return 'E_USER_NOTICE';
149
+			case E_STRICT: // 2048 //
150
+				return 'E_STRICT';
151
+			case E_RECOVERABLE_ERROR: // 4096 //
152
+				return 'E_RECOVERABLE_ERROR';
153
+			case E_DEPRECATED: // 8192 //
154
+				return 'E_DEPRECATED';
155
+			case E_USER_DEPRECATED: // 16384 //
156
+				return 'E_USER_DEPRECATED';
157
+			case E_ALL: // 16384 //
158
+				return 'E_ALL';
159
+		}
160
+		return '';
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 *    fatal_error_handler
167
+	 *
168
+	 * @return void
169
+	 */
170
+	public static function fatal_error_handler()
171
+	{
172
+		$last_error = error_get_last();
173
+		if ($last_error['type'] === E_ERROR) {
174
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
175
+		}
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * _format_error
182
+	 *
183
+	 * @param $code
184
+	 * @param $message
185
+	 * @param $file
186
+	 * @param $line
187
+	 * @return string
188
+	 */
189
+	private static function _format_error($code, $message, $file, $line)
190
+	{
191
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
192
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
193
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
194
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
195
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
196
+		$html .= '</tbody></table>';
197
+		return $html;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * set_content_type
204
+	 *
205
+	 * @param $content_type
206
+	 * @return string
207
+	 */
208
+	public static function set_content_type($content_type)
209
+	{
210
+		return 'text/html';
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * @return void
217
+	 * @throws EE_Error
218
+	 * @throws ReflectionException
219
+	 */
220
+	public function get_error()
221
+	{
222
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
223
+			throw $this;
224
+		}
225
+		// get separate user and developer messages if they exist
226
+		$msg = explode('||', $this->getMessage());
227
+		$user_msg = $msg[0];
228
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
229
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
230
+		// add details to _all_exceptions array
231
+		$x_time = time();
232
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
233
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
234
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
235
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
236
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
237
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
238
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
239
+		self::$_error_count++;
240
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
241
+		$this->display_errors();
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * @param bool   $check_stored
248
+	 * @param string $type_to_check
249
+	 * @return bool
250
+	 */
251
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
252
+	{
253
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
254
+					 && ! empty(self::$_espresso_notices[$type_to_check])
255
+			? true
256
+			: false;
257
+		if ($check_stored && ! $has_error) {
258
+			$notices = (array)get_option('ee_notices', array());
259
+			foreach ($notices as $type => $notice) {
260
+				if ($type === $type_to_check && $notice) {
261
+					return true;
262
+				}
263
+			}
264
+		}
265
+		return $has_error;
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * @echo string
272
+	 * @throws \ReflectionException
273
+	 */
274
+	public function display_errors()
275
+	{
276
+		$trace_details = '';
277
+		$output = '
278 278
 <style type="text/css">
279 279
 	#ee-error-message {
280 280
 		max-width:90% !important;
@@ -330,21 +330,21 @@  discard block
 block discarded – undo
330 330
 	}
331 331
 </style>
332 332
 <div id="ee-error-message" class="error">';
333
-        if (! WP_DEBUG) {
334
-            $output .= '
333
+		if (! WP_DEBUG) {
334
+			$output .= '
335 335
 	<p>';
336
-        }
337
-        // cycle thru errors
338
-        foreach (self::$_all_exceptions as $time => $ex) {
339
-            $error_code = '';
340
-            // process trace info
341
-            if (empty($ex['trace'])) {
342
-                $trace_details .= __(
343
-                    'Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso'
345
-                );
346
-            } else {
347
-                $trace_details .= '
336
+		}
337
+		// cycle thru errors
338
+		foreach (self::$_all_exceptions as $time => $ex) {
339
+			$error_code = '';
340
+			// process trace info
341
+			if (empty($ex['trace'])) {
342
+				$trace_details .= __(
343
+					'Sorry, but no trace information was available for this exception.',
344
+					'event_espresso'
345
+				);
346
+			} else {
347
+				$trace_details .= '
348 348
 			<div id="ee-trace-details">
349 349
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
350 350
 				<tr>
@@ -354,43 +354,43 @@  discard block
 block discarded – undo
354 354
 					<th scope="col" align="left">Class</th>
355 355
 					<th scope="col" align="left">Method( arguments )</th>
356 356
 				</tr>';
357
-                $last_on_stack = count($ex['trace']) - 1;
358
-                // reverse array so that stack is in proper chronological order
359
-                $sorted_trace = array_reverse($ex['trace']);
360
-                foreach ($sorted_trace as $nmbr => $trace) {
361
-                    $file = isset($trace['file']) ? $trace['file'] : '';
362
-                    $class = isset($trace['class']) ? $trace['class'] : '';
363
-                    $type = isset($trace['type']) ? $trace['type'] : '';
364
-                    $function = isset($trace['function']) ? $trace['function'] : '';
365
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
366
-                    $line = isset($trace['line']) ? $trace['line'] : '';
367
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
368
-                    if (empty($file) && ! empty($class)) {
369
-                        $a = new ReflectionClass($class);
370
-                        $file = $a->getFileName();
371
-                        if (empty($line) && ! empty($function)) {
372
-                            try {
373
-                                //if $function is a closure, this throws an exception
374
-                                $b = new ReflectionMethod($class, $function);
375
-                                $line = $b->getStartLine();
376
-                            } catch (Exception $closure_exception) {
377
-                                $line = 'unknown';
378
-                            }
379
-                        }
380
-                    }
381
-                    if ($nmbr === $last_on_stack) {
382
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
383
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
384
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
385
-                    }
386
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
387
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
388
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
389
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
390
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
391
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
392
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
393
-                    $trace_details .= '
357
+				$last_on_stack = count($ex['trace']) - 1;
358
+				// reverse array so that stack is in proper chronological order
359
+				$sorted_trace = array_reverse($ex['trace']);
360
+				foreach ($sorted_trace as $nmbr => $trace) {
361
+					$file = isset($trace['file']) ? $trace['file'] : '';
362
+					$class = isset($trace['class']) ? $trace['class'] : '';
363
+					$type = isset($trace['type']) ? $trace['type'] : '';
364
+					$function = isset($trace['function']) ? $trace['function'] : '';
365
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
366
+					$line = isset($trace['line']) ? $trace['line'] : '';
367
+					$zebra = ($nmbr % 2) ? ' odd' : '';
368
+					if (empty($file) && ! empty($class)) {
369
+						$a = new ReflectionClass($class);
370
+						$file = $a->getFileName();
371
+						if (empty($line) && ! empty($function)) {
372
+							try {
373
+								//if $function is a closure, this throws an exception
374
+								$b = new ReflectionMethod($class, $function);
375
+								$line = $b->getStartLine();
376
+							} catch (Exception $closure_exception) {
377
+								$line = 'unknown';
378
+							}
379
+						}
380
+					}
381
+					if ($nmbr === $last_on_stack) {
382
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
383
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
384
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
385
+					}
386
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
387
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
388
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
389
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
390
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
391
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
392
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
393
+					$trace_details .= '
394 394
 					<tr>
395 395
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
396 396
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -398,516 +398,516 @@  discard block
 block discarded – undo
398 398
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
399 399
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
400 400
 					</tr>';
401
-                }
402
-                $trace_details .= '
401
+				}
402
+				$trace_details .= '
403 403
 			 </table>
404 404
 			</div>';
405
-            }
406
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
407
-            // add generic non-identifying messages for non-privileged users
408
-            if (! WP_DEBUG) {
409
-                $output .= '<span class="ee-error-user-msg-spn">'
410
-                           . trim($ex['msg'])
411
-                           . '</span> &nbsp; <sup>'
412
-                           . $ex['code']
413
-                           . '</sup><br />';
414
-            } else {
415
-                // or helpful developer messages if debugging is on
416
-                $output .= '
405
+			}
406
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
407
+			// add generic non-identifying messages for non-privileged users
408
+			if (! WP_DEBUG) {
409
+				$output .= '<span class="ee-error-user-msg-spn">'
410
+						   . trim($ex['msg'])
411
+						   . '</span> &nbsp; <sup>'
412
+						   . $ex['code']
413
+						   . '</sup><br />';
414
+			} else {
415
+				// or helpful developer messages if debugging is on
416
+				$output .= '
417 417
 		<div class="ee-error-dev-msg-dv">
418 418
 			<p class="ee-error-dev-msg-pg">
419 419
 				<strong class="ee-error-dev-msg-str">An '
420
-                           . $ex['name']
421
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
422
-                           . $ex['code']
423
-                           . '</span><br />
420
+						   . $ex['name']
421
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
422
+						   . $ex['code']
423
+						   . '</span><br />
424 424
 				<span class="big-text">"'
425
-                           . trim($ex['msg'])
426
-                           . '"</span><br/>
425
+						   . trim($ex['msg'])
426
+						   . '"</span><br/>
427 427
 				<a id="display-ee-error-trace-'
428
-                           . self::$_error_count
429
-                           . $time
430
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
431
-                           . self::$_error_count
432
-                           . $time
433
-                           . '">
428
+						   . self::$_error_count
429
+						   . $time
430
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
431
+						   . self::$_error_count
432
+						   . $time
433
+						   . '">
434 434
 					'
435
-                           . __('click to view backtrace and class/method details', 'event_espresso')
436
-                           . '
435
+						   . __('click to view backtrace and class/method details', 'event_espresso')
436
+						   . '
437 437
 				</a><br />
438 438
 				<span class="small-text lt-grey-text">'
439
-                           . $ex['file']
440
-                           . ' &nbsp; ( line no: '
441
-                           . $ex['line']
442
-                           . ' )</span>
439
+						   . $ex['file']
440
+						   . ' &nbsp; ( line no: '
441
+						   . $ex['line']
442
+						   . ' )</span>
443 443
 			</p>
444 444
 			<div id="ee-error-trace-'
445
-                           . self::$_error_count
446
-                           . $time
447
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
445
+						   . self::$_error_count
446
+						   . $time
447
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
448 448
 				'
449
-                           . $trace_details;
450
-                if (! empty($class)) {
451
-                    $output .= '
449
+						   . $trace_details;
450
+				if (! empty($class)) {
451
+					$output .= '
452 452
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
453 453
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
454 454
 						<h3>Class Details</h3>';
455
-                    $a = new ReflectionClass($class);
456
-                    $output .= '
455
+					$a = new ReflectionClass($class);
456
+					$output .= '
457 457
 						<pre>' . $a . '</pre>
458 458
 					</div>
459 459
 				</div>';
460
-                }
461
-                $output .= '
460
+				}
461
+				$output .= '
462 462
 			</div>
463 463
 		</div>
464 464
 		<br />';
465
-            }
466
-            $this->write_to_error_log($time, $ex);
467
-        }
468
-        // remove last linebreak
469
-        $output = substr($output, 0, -6);
470
-        if (! WP_DEBUG) {
471
-            $output .= '
465
+			}
466
+			$this->write_to_error_log($time, $ex);
467
+		}
468
+		// remove last linebreak
469
+		$output = substr($output, 0, -6);
470
+		if (! WP_DEBUG) {
471
+			$output .= '
472 472
 	</p>';
473
-        }
474
-        $output .= '
473
+		}
474
+		$output .= '
475 475
 </div>';
476
-        $output .= self::_print_scripts(true);
477
-        if (defined('DOING_AJAX')) {
478
-            echo wp_json_encode(array('error' => $output));
479
-            exit();
480
-        }
481
-        echo $output;
482
-        die();
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     *    generate string from exception trace args
489
-     *
490
-     * @param array $arguments
491
-     * @param bool  $array
492
-     * @return string
493
-     */
494
-    private function _convert_args_to_string($arguments = array(), $array = false)
495
-    {
496
-        $arg_string = '';
497
-        if (! empty($arguments)) {
498
-            $args = array();
499
-            foreach ($arguments as $arg) {
500
-                if (! empty($arg)) {
501
-                    if (is_string($arg)) {
502
-                        $args[] = " '" . $arg . "'";
503
-                    } elseif (is_array($arg)) {
504
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
505
-                    } elseif ($arg === null) {
506
-                        $args[] = ' NULL';
507
-                    } elseif (is_bool($arg)) {
508
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
509
-                    } elseif (is_object($arg)) {
510
-                        $args[] = ' OBJECT ' . get_class($arg);
511
-                    } elseif (is_resource($arg)) {
512
-                        $args[] = get_resource_type($arg);
513
-                    } else {
514
-                        $args[] = $arg;
515
-                    }
516
-                }
517
-            }
518
-            $arg_string = implode(', ', $args);
519
-        }
520
-        if ($array) {
521
-            $arg_string .= ' )';
522
-        }
523
-        return $arg_string;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    add error message
530
-     *
531
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
532
-     *                            separate messages for user || dev
533
-     * @param        string $file the file that the error occurred in - just use __FILE__
534
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
535
-     * @param        string $line the line number where the error occurred - just use __LINE__
536
-     * @return        void
537
-     */
538
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
539
-    {
540
-        self::_add_notice('errors', $msg, $file, $func, $line);
541
-        self::$_error_count++;
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
548
-     * adds an error
549
-     *
550
-     * @param string $msg
551
-     * @param string $file
552
-     * @param string $func
553
-     * @param string $line
554
-     * @throws EE_Error
555
-     */
556
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
557
-    {
558
-        if (WP_DEBUG) {
559
-            throw new EE_Error($msg);
560
-        }
561
-        EE_Error::add_error($msg, $file, $func, $line);
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     *    add success message
568
-     *
569
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
570
-     *                            separate messages for user || dev
571
-     * @param        string $file the file that the error occurred in - just use __FILE__
572
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
573
-     * @param        string $line the line number where the error occurred - just use __LINE__
574
-     * @return        void
575
-     */
576
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
577
-    {
578
-        self::_add_notice('success', $msg, $file, $func, $line);
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     *    add attention message
585
-     *
586
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
587
-     *                            separate messages for user || dev
588
-     * @param        string $file the file that the error occurred in - just use __FILE__
589
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
590
-     * @param        string $line the line number where the error occurred - just use __LINE__
591
-     * @return        void
592
-     */
593
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
594
-    {
595
-        self::_add_notice('attention', $msg, $file, $func, $line);
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * @param string $type whether the message is for a success or error notification
602
-     * @param string $msg the message to display to users or developers
603
-     *                    - adding a double pipe || (OR) creates separate messages for user || dev
604
-     * @param string $file the file that the error occurred in - just use __FILE__
605
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
606
-     * @param string $line the line number where the error occurred - just use __LINE__
607
-     * @return void
608
-     */
609
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
610
-    {
611
-        if (empty($msg)) {
612
-            EE_Error::doing_it_wrong(
613
-                'EE_Error::add_' . $type . '()',
614
-                sprintf(
615
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
616
-                        'event_espresso'),
617
-                    $type,
618
-                    $file,
619
-                    $line
620
-                ),
621
-                EVENT_ESPRESSO_VERSION
622
-            );
623
-        }
624
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
625
-            EE_Error::doing_it_wrong(
626
-                'EE_Error::add_error()',
627
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
628
-                    'event_espresso'),
629
-                EVENT_ESPRESSO_VERSION
630
-            );
631
-        }
632
-        // get separate user and developer messages if they exist
633
-        $msg      = explode('||', $msg);
634
-        $user_msg = $msg[0];
635
-        $dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
636
-        /**
637
-         * Do an action so other code can be triggered when a notice is created
638
-         *
639
-         * @param string $type     can be 'errors', 'attention', or 'success'
640
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
641
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
642
-         * @param string $file     file where error was generated
643
-         * @param string $func     function where error was generated
644
-         * @param string $line     line where error was generated
645
-         */
646
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
647
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
648
-        // add notice if message exists
649
-        if (! empty($msg)) {
650
-            // get error code
651
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
652
-            if (WP_DEBUG && $type === 'errors') {
653
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
654
-            }
655
-            // add notice. Index by code if it's not blank
656
-            if ($notice_code) {
657
-                self::$_espresso_notices[$type][$notice_code] = $msg;
658
-            } else {
659
-                self::$_espresso_notices[$type][] = $msg;
660
-            }
661
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * in some case it may be necessary to overwrite the existing success messages
668
-     *
669
-     * @return        void
670
-     */
671
-    public static function overwrite_success()
672
-    {
673
-        self::$_espresso_notices['success'] = false;
674
-    }
675
-
676
-
677
-
678
-    /**
679
-     * in some case it may be necessary to overwrite the existing attention messages
680
-     *
681
-     * @return void
682
-     */
683
-    public static function overwrite_attention()
684
-    {
685
-        self::$_espresso_notices['attention'] = false;
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * in some case it may be necessary to overwrite the existing error messages
692
-     *
693
-     * @return void
694
-     */
695
-    public static function overwrite_errors()
696
-    {
697
-        self::$_espresso_notices['errors'] = false;
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * @return void
704
-     */
705
-    public static function reset_notices()
706
-    {
707
-        self::$_espresso_notices['success']   = false;
708
-        self::$_espresso_notices['attention'] = false;
709
-        self::$_espresso_notices['errors']    = false;
710
-    }
711
-
712
-
713
-
714
-    /**
715
-     * @return int
716
-     */
717
-    public static function has_notices()
718
-    {
719
-        $has_notices = 0;
720
-        // check for success messages
721
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) 
722
-            ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) 
726
-            ? 2
727
-            : $has_notices;
728
-        // check for error messages
729
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) 
730
-            ? 1
731
-            : $has_notices;
732
-        return $has_notices;
733
-    }
734
-
735
-
736
-    /**
737
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
738
-     *
739
-     * @since 4.9.0
740
-     * @return array
741
-     */
742
-    public static function get_vanilla_notices()
743
-    {
744
-        return array(
745
-            'success'   => isset(self::$_espresso_notices['success'])
746
-                ? self::$_espresso_notices['success']
747
-                : array(),
748
-            'attention' => isset(self::$_espresso_notices['attention'])
749
-                ? self::$_espresso_notices['attention']
750
-                : array(),
751
-            'errors'    => isset(self::$_espresso_notices['errors'])
752
-                ? self::$_espresso_notices['errors']
753
-                : array(),
754
-        );
755
-    }
756
-
757
-
758
-
759
-    /**
760
-     * compile all error or success messages into one string
761
-     *
762
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
763
-     * @param boolean $format_output     whether or not to format the messages for display in the WP admin
764
-     * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
765
-     *                                          - ONLY do this just before redirecting
766
-     * @param boolean $remove_empty      whether or not to unset empty messages
767
-     * @return array
768
-     */
769
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
770
-    {
771
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
772
-        $success_messages   = '';
773
-        $attention_messages = '';
774
-        $error_messages     = '';
775
-        $print_scripts      = false;
776
-        // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
777
-        // either save notices to the db
778
-        if ($save_to_transient) {
779
-            update_option('ee_notices', self::$_espresso_notices);
780
-            return array();
781
-        }
782
-        // grab any notices that have been previously saved
783
-        if ($notices = get_option('ee_notices', false)) {
784
-            foreach ($notices as $type => $notice) {
785
-                if (is_array($notice) && ! empty($notice)) {
786
-                    // make sure that existing notice type is an array
787
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
788
-                                                      && ! empty(self::$_espresso_notices[$type])
789
-                        ? self::$_espresso_notices[$type] : array();
790
-                    // merge stored notices with any newly created ones
791
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
792
-                    $print_scripts                  = true;
793
-                }
794
-            }
795
-            // now clear any stored notices
796
-            update_option('ee_notices', false);
797
-        }
798
-        // check for success messages
799
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
800
-            // combine messages
801
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
802
-            $print_scripts    = true;
803
-        }
804
-        // check for attention messages
805
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
806
-            // combine messages
807
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
808
-            $print_scripts      = true;
809
-        }
810
-        // check for error messages
811
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
812
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
813
-                ? __('The following errors have occurred:<br />', 'event_espresso')
814
-                : __('An error has occurred:<br />', 'event_espresso');
815
-            // combine messages
816
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
817
-            $print_scripts  = true;
818
-        }
819
-        if ($format_output) {
820
-
821
-            $notices = '<div id="espresso-notices">';
822
-            $close = is_admin() ? ''
823
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
824
-            if ($success_messages !== '') {
825
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-success';
826
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
827
-                //showMessage( $success_messages );
828
-                $notices .= '<div id="'
829
-                            . $css_id
830
-                            . '" class="espresso-notices '
831
-                            . $css_class
832
-                            . '" style="display:none;"><p>'
833
-                            . $success_messages
834
-                            . '</p>'
835
-                            . $close
836
-                            . '</div>';
837
-            }
838
-            if ($attention_messages !== '') {
839
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
840
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
841
-                //showMessage( $error_messages, TRUE );
842
-                $notices .= '<div id="'
843
-                            . $css_id
844
-                            . '" class="espresso-notices '
845
-                            . $css_class
846
-                            . '" style="display:none;"><p>'
847
-                            . $attention_messages
848
-                            . '</p>'
849
-                            . $close
850
-                            . '</div>';
851
-            }
852
-            if ($error_messages !== '') {
853
-                $css_id    = is_admin() ? 'message' : 'espresso-notices-error';
854
-                $css_class = is_admin() ? 'error' : 'error fade-away';
855
-                //showMessage( $error_messages, TRUE );
856
-                $notices .= '<div id="'
857
-                            . $css_id
858
-                            . '" class="espresso-notices '
859
-                            . $css_class
860
-                            . '" style="display:none;"><p>'
861
-                            . $error_messages
862
-                            . '</p>'
863
-                            . $close
864
-                            . '</div>';
865
-            }
866
-            $notices .= '</div>';
867
-        } else {
868
-
869
-            $notices = array(
870
-                'success'   => $success_messages,
871
-                'attention' => $attention_messages,
872
-                'errors'    => $error_messages,
873
-            );
874
-            if ($remove_empty) {
875
-                // remove empty notices
876
-                foreach ($notices as $type => $notice) {
877
-                    if (empty($notice)) {
878
-                        unset($notices[$type]);
879
-                    }
880
-                }
881
-            }
882
-        }
883
-        if ($print_scripts) {
884
-            self::_print_scripts();
885
-        }
886
-        return $notices;
887
-    }
888
-
889
-
890
-
891
-    /**
892
-     * _print_scripts
893
-     *
894
-     * @param    bool $force_print
895
-     * @return    string
896
-     */
897
-    private static function _print_scripts($force_print = false)
898
-    {
899
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
900
-            if (wp_script_is('ee_error_js', 'enqueued')) {
901
-                return '';
902
-            }
903
-            if (wp_script_is('ee_error_js', 'registered')) {
904
-                wp_enqueue_style('espresso_default');
905
-                wp_enqueue_style('espresso_custom_css');
906
-                wp_enqueue_script('ee_error_js');
907
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
908
-            }
909
-        } else {
910
-            return '
476
+		$output .= self::_print_scripts(true);
477
+		if (defined('DOING_AJAX')) {
478
+			echo wp_json_encode(array('error' => $output));
479
+			exit();
480
+		}
481
+		echo $output;
482
+		die();
483
+	}
484
+
485
+
486
+
487
+	/**
488
+	 *    generate string from exception trace args
489
+	 *
490
+	 * @param array $arguments
491
+	 * @param bool  $array
492
+	 * @return string
493
+	 */
494
+	private function _convert_args_to_string($arguments = array(), $array = false)
495
+	{
496
+		$arg_string = '';
497
+		if (! empty($arguments)) {
498
+			$args = array();
499
+			foreach ($arguments as $arg) {
500
+				if (! empty($arg)) {
501
+					if (is_string($arg)) {
502
+						$args[] = " '" . $arg . "'";
503
+					} elseif (is_array($arg)) {
504
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
505
+					} elseif ($arg === null) {
506
+						$args[] = ' NULL';
507
+					} elseif (is_bool($arg)) {
508
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
509
+					} elseif (is_object($arg)) {
510
+						$args[] = ' OBJECT ' . get_class($arg);
511
+					} elseif (is_resource($arg)) {
512
+						$args[] = get_resource_type($arg);
513
+					} else {
514
+						$args[] = $arg;
515
+					}
516
+				}
517
+			}
518
+			$arg_string = implode(', ', $args);
519
+		}
520
+		if ($array) {
521
+			$arg_string .= ' )';
522
+		}
523
+		return $arg_string;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    add error message
530
+	 *
531
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
532
+	 *                            separate messages for user || dev
533
+	 * @param        string $file the file that the error occurred in - just use __FILE__
534
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
535
+	 * @param        string $line the line number where the error occurred - just use __LINE__
536
+	 * @return        void
537
+	 */
538
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
539
+	{
540
+		self::_add_notice('errors', $msg, $file, $func, $line);
541
+		self::$_error_count++;
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
548
+	 * adds an error
549
+	 *
550
+	 * @param string $msg
551
+	 * @param string $file
552
+	 * @param string $func
553
+	 * @param string $line
554
+	 * @throws EE_Error
555
+	 */
556
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
557
+	{
558
+		if (WP_DEBUG) {
559
+			throw new EE_Error($msg);
560
+		}
561
+		EE_Error::add_error($msg, $file, $func, $line);
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 *    add success message
568
+	 *
569
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
570
+	 *                            separate messages for user || dev
571
+	 * @param        string $file the file that the error occurred in - just use __FILE__
572
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
573
+	 * @param        string $line the line number where the error occurred - just use __LINE__
574
+	 * @return        void
575
+	 */
576
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
577
+	{
578
+		self::_add_notice('success', $msg, $file, $func, $line);
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 *    add attention message
585
+	 *
586
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
587
+	 *                            separate messages for user || dev
588
+	 * @param        string $file the file that the error occurred in - just use __FILE__
589
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
590
+	 * @param        string $line the line number where the error occurred - just use __LINE__
591
+	 * @return        void
592
+	 */
593
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
594
+	{
595
+		self::_add_notice('attention', $msg, $file, $func, $line);
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * @param string $type whether the message is for a success or error notification
602
+	 * @param string $msg the message to display to users or developers
603
+	 *                    - adding a double pipe || (OR) creates separate messages for user || dev
604
+	 * @param string $file the file that the error occurred in - just use __FILE__
605
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
606
+	 * @param string $line the line number where the error occurred - just use __LINE__
607
+	 * @return void
608
+	 */
609
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
610
+	{
611
+		if (empty($msg)) {
612
+			EE_Error::doing_it_wrong(
613
+				'EE_Error::add_' . $type . '()',
614
+				sprintf(
615
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
616
+						'event_espresso'),
617
+					$type,
618
+					$file,
619
+					$line
620
+				),
621
+				EVENT_ESPRESSO_VERSION
622
+			);
623
+		}
624
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
625
+			EE_Error::doing_it_wrong(
626
+				'EE_Error::add_error()',
627
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
628
+					'event_espresso'),
629
+				EVENT_ESPRESSO_VERSION
630
+			);
631
+		}
632
+		// get separate user and developer messages if they exist
633
+		$msg      = explode('||', $msg);
634
+		$user_msg = $msg[0];
635
+		$dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
636
+		/**
637
+		 * Do an action so other code can be triggered when a notice is created
638
+		 *
639
+		 * @param string $type     can be 'errors', 'attention', or 'success'
640
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
641
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
642
+		 * @param string $file     file where error was generated
643
+		 * @param string $func     function where error was generated
644
+		 * @param string $line     line where error was generated
645
+		 */
646
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
647
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
648
+		// add notice if message exists
649
+		if (! empty($msg)) {
650
+			// get error code
651
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
652
+			if (WP_DEBUG && $type === 'errors') {
653
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
654
+			}
655
+			// add notice. Index by code if it's not blank
656
+			if ($notice_code) {
657
+				self::$_espresso_notices[$type][$notice_code] = $msg;
658
+			} else {
659
+				self::$_espresso_notices[$type][] = $msg;
660
+			}
661
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * in some case it may be necessary to overwrite the existing success messages
668
+	 *
669
+	 * @return        void
670
+	 */
671
+	public static function overwrite_success()
672
+	{
673
+		self::$_espresso_notices['success'] = false;
674
+	}
675
+
676
+
677
+
678
+	/**
679
+	 * in some case it may be necessary to overwrite the existing attention messages
680
+	 *
681
+	 * @return void
682
+	 */
683
+	public static function overwrite_attention()
684
+	{
685
+		self::$_espresso_notices['attention'] = false;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * in some case it may be necessary to overwrite the existing error messages
692
+	 *
693
+	 * @return void
694
+	 */
695
+	public static function overwrite_errors()
696
+	{
697
+		self::$_espresso_notices['errors'] = false;
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * @return void
704
+	 */
705
+	public static function reset_notices()
706
+	{
707
+		self::$_espresso_notices['success']   = false;
708
+		self::$_espresso_notices['attention'] = false;
709
+		self::$_espresso_notices['errors']    = false;
710
+	}
711
+
712
+
713
+
714
+	/**
715
+	 * @return int
716
+	 */
717
+	public static function has_notices()
718
+	{
719
+		$has_notices = 0;
720
+		// check for success messages
721
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) 
722
+			? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) 
726
+			? 2
727
+			: $has_notices;
728
+		// check for error messages
729
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) 
730
+			? 1
731
+			: $has_notices;
732
+		return $has_notices;
733
+	}
734
+
735
+
736
+	/**
737
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
738
+	 *
739
+	 * @since 4.9.0
740
+	 * @return array
741
+	 */
742
+	public static function get_vanilla_notices()
743
+	{
744
+		return array(
745
+			'success'   => isset(self::$_espresso_notices['success'])
746
+				? self::$_espresso_notices['success']
747
+				: array(),
748
+			'attention' => isset(self::$_espresso_notices['attention'])
749
+				? self::$_espresso_notices['attention']
750
+				: array(),
751
+			'errors'    => isset(self::$_espresso_notices['errors'])
752
+				? self::$_espresso_notices['errors']
753
+				: array(),
754
+		);
755
+	}
756
+
757
+
758
+
759
+	/**
760
+	 * compile all error or success messages into one string
761
+	 *
762
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
763
+	 * @param boolean $format_output     whether or not to format the messages for display in the WP admin
764
+	 * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
765
+	 *                                          - ONLY do this just before redirecting
766
+	 * @param boolean $remove_empty      whether or not to unset empty messages
767
+	 * @return array
768
+	 */
769
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
770
+	{
771
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
772
+		$success_messages   = '';
773
+		$attention_messages = '';
774
+		$error_messages     = '';
775
+		$print_scripts      = false;
776
+		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
777
+		// either save notices to the db
778
+		if ($save_to_transient) {
779
+			update_option('ee_notices', self::$_espresso_notices);
780
+			return array();
781
+		}
782
+		// grab any notices that have been previously saved
783
+		if ($notices = get_option('ee_notices', false)) {
784
+			foreach ($notices as $type => $notice) {
785
+				if (is_array($notice) && ! empty($notice)) {
786
+					// make sure that existing notice type is an array
787
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
788
+													  && ! empty(self::$_espresso_notices[$type])
789
+						? self::$_espresso_notices[$type] : array();
790
+					// merge stored notices with any newly created ones
791
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
792
+					$print_scripts                  = true;
793
+				}
794
+			}
795
+			// now clear any stored notices
796
+			update_option('ee_notices', false);
797
+		}
798
+		// check for success messages
799
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
800
+			// combine messages
801
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
802
+			$print_scripts    = true;
803
+		}
804
+		// check for attention messages
805
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
806
+			// combine messages
807
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
808
+			$print_scripts      = true;
809
+		}
810
+		// check for error messages
811
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
812
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
813
+				? __('The following errors have occurred:<br />', 'event_espresso')
814
+				: __('An error has occurred:<br />', 'event_espresso');
815
+			// combine messages
816
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
817
+			$print_scripts  = true;
818
+		}
819
+		if ($format_output) {
820
+
821
+			$notices = '<div id="espresso-notices">';
822
+			$close = is_admin() ? ''
823
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
824
+			if ($success_messages !== '') {
825
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-success';
826
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
827
+				//showMessage( $success_messages );
828
+				$notices .= '<div id="'
829
+							. $css_id
830
+							. '" class="espresso-notices '
831
+							. $css_class
832
+							. '" style="display:none;"><p>'
833
+							. $success_messages
834
+							. '</p>'
835
+							. $close
836
+							. '</div>';
837
+			}
838
+			if ($attention_messages !== '') {
839
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
840
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
841
+				//showMessage( $error_messages, TRUE );
842
+				$notices .= '<div id="'
843
+							. $css_id
844
+							. '" class="espresso-notices '
845
+							. $css_class
846
+							. '" style="display:none;"><p>'
847
+							. $attention_messages
848
+							. '</p>'
849
+							. $close
850
+							. '</div>';
851
+			}
852
+			if ($error_messages !== '') {
853
+				$css_id    = is_admin() ? 'message' : 'espresso-notices-error';
854
+				$css_class = is_admin() ? 'error' : 'error fade-away';
855
+				//showMessage( $error_messages, TRUE );
856
+				$notices .= '<div id="'
857
+							. $css_id
858
+							. '" class="espresso-notices '
859
+							. $css_class
860
+							. '" style="display:none;"><p>'
861
+							. $error_messages
862
+							. '</p>'
863
+							. $close
864
+							. '</div>';
865
+			}
866
+			$notices .= '</div>';
867
+		} else {
868
+
869
+			$notices = array(
870
+				'success'   => $success_messages,
871
+				'attention' => $attention_messages,
872
+				'errors'    => $error_messages,
873
+			);
874
+			if ($remove_empty) {
875
+				// remove empty notices
876
+				foreach ($notices as $type => $notice) {
877
+					if (empty($notice)) {
878
+						unset($notices[$type]);
879
+					}
880
+				}
881
+			}
882
+		}
883
+		if ($print_scripts) {
884
+			self::_print_scripts();
885
+		}
886
+		return $notices;
887
+	}
888
+
889
+
890
+
891
+	/**
892
+	 * _print_scripts
893
+	 *
894
+	 * @param    bool $force_print
895
+	 * @return    string
896
+	 */
897
+	private static function _print_scripts($force_print = false)
898
+	{
899
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
900
+			if (wp_script_is('ee_error_js', 'enqueued')) {
901
+				return '';
902
+			}
903
+			if (wp_script_is('ee_error_js', 'registered')) {
904
+				wp_enqueue_style('espresso_default');
905
+				wp_enqueue_style('espresso_custom_css');
906
+				wp_enqueue_script('ee_error_js');
907
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
908
+			}
909
+		} else {
910
+			return '
911 911
 <script>
912 912
 /* <![CDATA[ */
913 913
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -917,235 +917,235 @@  discard block
 block discarded – undo
917 917
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
918 918
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
919 919
 ';
920
-        }
921
-        return '';
922
-    }
923
-
924
-
925
-
926
-    /**
927
-     * @return void
928
-     */
929
-    public static function enqueue_error_scripts()
930
-    {
931
-        self::_print_scripts();
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * create error code from filepath, function name,
938
-     * and line number where exception or error was thrown
939
-     *
940
-     * @param string $file
941
-     * @param string $func
942
-     * @param string $line
943
-     * @return string
944
-     */
945
-    public static function generate_error_code($file = '', $func = '', $line = '')
946
-    {
947
-        $file       = explode('.', basename($file));
948
-        $error_code = ! empty($file[0]) ? $file[0] : '';
949
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
950
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
951
-        return $error_code;
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * write exception details to log file
958
-     *
959
-     * @param int   $time
960
-     * @param array $ex
961
-     * @param bool  $clear
962
-     * @return void
963
-     */
964
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
965
-    {
966
-        if (empty($ex)) {
967
-            return;
968
-        }
969
-        if (! $time) {
970
-            $time = time();
971
-        }
972
-        $exception_log = '----------------------------------------------------------------------------------------'
973
-                         . PHP_EOL;
974
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
975
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
976
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
977
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
978
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
979
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
980
-        $exception_log .= $ex['string'] . PHP_EOL;
981
-        $exception_log .= '----------------------------------------------------------------------------------------'
982
-                          . PHP_EOL;
983
-        try {
984
-            EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR
985
-                                                         . 'logs'
986
-                                                         . DS
987
-                                                         . self::$_exception_log_file);
988
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
989
-            if (! $clear) {
990
-                //get existing log file and append new log info
991
-                $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR
992
-                                                             . 'logs'
993
-                                                             . DS
994
-                                                             . self::$_exception_log_file) . $exception_log;
995
-            }
996
-            EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
997
-                $exception_log);
998
-        } catch (EE_Error $e) {
999
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1000
-                'event_espresso'), $e->getMessage()));
1001
-        }
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1008
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1009
-     * but the code execution is done in a manner that could lead to unexpected results
1010
-     * (i.e. running to early, or too late in WP or EE loading process).
1011
-     * A good test for knowing whether to use this method is:
1012
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1013
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1014
-     * 2. If this is loaded before something else, it won't break anything,
1015
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1016
-     *
1017
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1018
-     * @param string $function      The function that was called
1019
-     * @param string $message       A message explaining what has been done incorrectly
1020
-     * @param string $version       The version of Event Espresso where the error was added
1021
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1022
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1023
-     *                              but not have any notices appear until a later version. This allows developers
1024
-     *                              extra time to update their code before notices appear.
1025
-     * @param int    $error_type
1026
-     */
1027
-    public static function doing_it_wrong(
1028
-        $function,
1029
-        $message,
1030
-        $version,
1031
-        $applies_when = '',
1032
-        $error_type = null
1033
-    ) {
1034
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1035
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1036
-        }
1037
-    }
1038
-
1039
-
1040
-
1041
-    /**
1042
-     * Like get_notices, but returns an array of all the notices of the given type.
1043
-     *
1044
-     * @return array {
1045
-     *  @type array $success   all the success messages
1046
-     *  @type array $errors    all the error messages
1047
-     *  @type array $attention all the attention messages
1048
-     * }
1049
-     */
1050
-    public static function get_raw_notices()
1051
-    {
1052
-        return self::$_espresso_notices;
1053
-    }
1054
-
1055
-
1056
-
1057
-    /**
1058
-     * @deprecated 4.9.27
1059
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1060
-     * @param string $pan_message  the message to be stored persistently until dismissed
1061
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1062
-     * @return void
1063
-     * @throws InvalidDataTypeException
1064
-     */
1065
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1066
-    {
1067
-        new PersistentAdminNotice(
1068
-            $pan_name,
1069
-            $pan_message,
1070
-            $force_update
1071
-        );
1072
-        EE_Error::doing_it_wrong(
1073
-            __METHOD__,
1074
-            sprintf(
1075
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1076
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1077
-            ),
1078
-            '4.9.27'
1079
-        );
1080
-    }
1081
-
1082
-
1083
-
1084
-    /**
1085
-     * @deprecated 4.9.27
1086
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1087
-     * @param bool   $purge
1088
-     * @param bool   $return
1089
-     * @throws DomainException
1090
-     * @throws InvalidInterfaceException
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws ServiceNotFoundException
1093
-     * @throws InvalidArgumentException
1094
-     */
1095
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1096
-    {
1097
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1098
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1099
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1100
-        );
1101
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1102
-        EE_Error::doing_it_wrong(
1103
-            __METHOD__,
1104
-            sprintf(
1105
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1106
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1107
-            ),
1108
-            '4.9.27'
1109
-        );
1110
-    }
1111
-
1112
-
1113
-
1114
-    /**
1115
-     * @deprecated 4.9.27
1116
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1117
-     * @param  string $pan_message the message to be stored persistently until dismissed
1118
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1119
-     */
1120
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1121
-    {
1122
-        EE_Error::doing_it_wrong(
1123
-            __METHOD__,
1124
-            sprintf(
1125
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1126
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1127
-            ),
1128
-            '4.9.27'
1129
-        );
1130
-    }
1131
-
1132
-
1133
-
1134
-    /**
1135
-     * @deprecated 4.9.27
1136
-     * @param string $return_url
1137
-     */
1138
-    public static function get_persistent_admin_notices($return_url = '')
1139
-    {
1140
-        EE_Error::doing_it_wrong(
1141
-            __METHOD__,
1142
-            sprintf(
1143
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1144
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1145
-            ),
1146
-            '4.9.27'
1147
-        );
1148
-    }
920
+		}
921
+		return '';
922
+	}
923
+
924
+
925
+
926
+	/**
927
+	 * @return void
928
+	 */
929
+	public static function enqueue_error_scripts()
930
+	{
931
+		self::_print_scripts();
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * create error code from filepath, function name,
938
+	 * and line number where exception or error was thrown
939
+	 *
940
+	 * @param string $file
941
+	 * @param string $func
942
+	 * @param string $line
943
+	 * @return string
944
+	 */
945
+	public static function generate_error_code($file = '', $func = '', $line = '')
946
+	{
947
+		$file       = explode('.', basename($file));
948
+		$error_code = ! empty($file[0]) ? $file[0] : '';
949
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
950
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
951
+		return $error_code;
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * write exception details to log file
958
+	 *
959
+	 * @param int   $time
960
+	 * @param array $ex
961
+	 * @param bool  $clear
962
+	 * @return void
963
+	 */
964
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
965
+	{
966
+		if (empty($ex)) {
967
+			return;
968
+		}
969
+		if (! $time) {
970
+			$time = time();
971
+		}
972
+		$exception_log = '----------------------------------------------------------------------------------------'
973
+						 . PHP_EOL;
974
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
975
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
976
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
977
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
978
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
979
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
980
+		$exception_log .= $ex['string'] . PHP_EOL;
981
+		$exception_log .= '----------------------------------------------------------------------------------------'
982
+						  . PHP_EOL;
983
+		try {
984
+			EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR
985
+														 . 'logs'
986
+														 . DS
987
+														 . self::$_exception_log_file);
988
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
989
+			if (! $clear) {
990
+				//get existing log file and append new log info
991
+				$exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR
992
+															 . 'logs'
993
+															 . DS
994
+															 . self::$_exception_log_file) . $exception_log;
995
+			}
996
+			EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
997
+				$exception_log);
998
+		} catch (EE_Error $e) {
999
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1000
+				'event_espresso'), $e->getMessage()));
1001
+		}
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1008
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1009
+	 * but the code execution is done in a manner that could lead to unexpected results
1010
+	 * (i.e. running to early, or too late in WP or EE loading process).
1011
+	 * A good test for knowing whether to use this method is:
1012
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1013
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1014
+	 * 2. If this is loaded before something else, it won't break anything,
1015
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1016
+	 *
1017
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1018
+	 * @param string $function      The function that was called
1019
+	 * @param string $message       A message explaining what has been done incorrectly
1020
+	 * @param string $version       The version of Event Espresso where the error was added
1021
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1022
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1023
+	 *                              but not have any notices appear until a later version. This allows developers
1024
+	 *                              extra time to update their code before notices appear.
1025
+	 * @param int    $error_type
1026
+	 */
1027
+	public static function doing_it_wrong(
1028
+		$function,
1029
+		$message,
1030
+		$version,
1031
+		$applies_when = '',
1032
+		$error_type = null
1033
+	) {
1034
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1035
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1036
+		}
1037
+	}
1038
+
1039
+
1040
+
1041
+	/**
1042
+	 * Like get_notices, but returns an array of all the notices of the given type.
1043
+	 *
1044
+	 * @return array {
1045
+	 *  @type array $success   all the success messages
1046
+	 *  @type array $errors    all the error messages
1047
+	 *  @type array $attention all the attention messages
1048
+	 * }
1049
+	 */
1050
+	public static function get_raw_notices()
1051
+	{
1052
+		return self::$_espresso_notices;
1053
+	}
1054
+
1055
+
1056
+
1057
+	/**
1058
+	 * @deprecated 4.9.27
1059
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1060
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1061
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1062
+	 * @return void
1063
+	 * @throws InvalidDataTypeException
1064
+	 */
1065
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1066
+	{
1067
+		new PersistentAdminNotice(
1068
+			$pan_name,
1069
+			$pan_message,
1070
+			$force_update
1071
+		);
1072
+		EE_Error::doing_it_wrong(
1073
+			__METHOD__,
1074
+			sprintf(
1075
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1076
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1077
+			),
1078
+			'4.9.27'
1079
+		);
1080
+	}
1081
+
1082
+
1083
+
1084
+	/**
1085
+	 * @deprecated 4.9.27
1086
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1087
+	 * @param bool   $purge
1088
+	 * @param bool   $return
1089
+	 * @throws DomainException
1090
+	 * @throws InvalidInterfaceException
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws ServiceNotFoundException
1093
+	 * @throws InvalidArgumentException
1094
+	 */
1095
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1096
+	{
1097
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1098
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1099
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1100
+		);
1101
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1102
+		EE_Error::doing_it_wrong(
1103
+			__METHOD__,
1104
+			sprintf(
1105
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1106
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1107
+			),
1108
+			'4.9.27'
1109
+		);
1110
+	}
1111
+
1112
+
1113
+
1114
+	/**
1115
+	 * @deprecated 4.9.27
1116
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1117
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1118
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1119
+	 */
1120
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1121
+	{
1122
+		EE_Error::doing_it_wrong(
1123
+			__METHOD__,
1124
+			sprintf(
1125
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1126
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1127
+			),
1128
+			'4.9.27'
1129
+		);
1130
+	}
1131
+
1132
+
1133
+
1134
+	/**
1135
+	 * @deprecated 4.9.27
1136
+	 * @param string $return_url
1137
+	 */
1138
+	public static function get_persistent_admin_notices($return_url = '')
1139
+	{
1140
+		EE_Error::doing_it_wrong(
1141
+			__METHOD__,
1142
+			sprintf(
1143
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1144
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1145
+			),
1146
+			'4.9.27'
1147
+		);
1148
+	}
1149 1149
 
1150 1150
 
1151 1151
 
@@ -1160,27 +1160,27 @@  discard block
 block discarded – undo
1160 1160
  */
1161 1161
 function espresso_error_enqueue_scripts()
1162 1162
 {
1163
-    // js for error handling
1164
-    wp_register_script(
1165
-        'espresso_core',
1166
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1167
-        array('jquery'),
1168
-        EVENT_ESPRESSO_VERSION,
1169
-        false
1170
-    );
1171
-    wp_register_script(
1172
-        'ee_error_js',
1173
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1174
-        array('espresso_core'),
1175
-        EVENT_ESPRESSO_VERSION,
1176
-        false
1177
-    );
1163
+	// js for error handling
1164
+	wp_register_script(
1165
+		'espresso_core',
1166
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1167
+		array('jquery'),
1168
+		EVENT_ESPRESSO_VERSION,
1169
+		false
1170
+	);
1171
+	wp_register_script(
1172
+		'ee_error_js',
1173
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1174
+		array('espresso_core'),
1175
+		EVENT_ESPRESSO_VERSION,
1176
+		false
1177
+	);
1178 1178
 }
1179 1179
 
1180 1180
 if (is_admin()) {
1181
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1181
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1182 1182
 } else {
1183
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1183
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1184 1184
 }
1185 1185
 
1186 1186
 
Please login to merge, or discard this patch.