Completed
Branch models-cleanup/main (de94a1)
by
unknown
86:45 queued 77:08
created
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
21 21
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
22 22
      * @param $string
23
-     * @param $start
24
-     * @param $length
23
+     * @param integer $start
24
+     * @param integer $length
25 25
      * @return bool|string
26 26
      */
27 27
     function mb_strcut($string, $start, $length = null)
Please login to merge, or discard this patch.
Indentation   +669 added lines, -669 removed lines patch added patch discarded remove patch
@@ -13,677 +13,677 @@
 block discarded – undo
13 13
 
14 14
 // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
15 15
 if (! function_exists('mb_strcut')) {
16
-    /**
17
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
18
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
19
-     * @param $string
20
-     * @param $start
21
-     * @param $length
22
-     * @return bool|string
23
-     */
24
-    function mb_strcut($string, $start, $length = null)
25
-    {
26
-        return mb_substr($string, $start, $length);
27
-    }
16
+	/**
17
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
18
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
19
+	 * @param $string
20
+	 * @param $start
21
+	 * @param $length
22
+	 * @return bool|string
23
+	 */
24
+	function mb_strcut($string, $start, $length = null)
25
+	{
26
+		return mb_substr($string, $start, $length);
27
+	}
28 28
 }
29 29
 class EEG_Paypal_Express extends EE_Offsite_Gateway
30 30
 {
31 31
 
32
-    /**
33
-     * Merchant API Username.
34
-     *
35
-     * @var string
36
-     */
37
-    protected $_api_username;
38
-
39
-    /**
40
-     * Merchant API Password.
41
-     *
42
-     * @var string
43
-     */
44
-    protected $_api_password;
45
-
46
-    /**
47
-     * API Signature.
48
-     *
49
-     * @var string
50
-     */
51
-    protected $_api_signature;
52
-
53
-    /**
54
-     * Request Shipping address on PP checkout page.
55
-     *
56
-     * @var string
57
-     */
58
-    protected $_request_shipping_addr;
59
-
60
-    /**
61
-     * Business/personal logo.
62
-     *
63
-     * @var string
64
-     */
65
-    protected $_image_url;
66
-
67
-    /**
68
-     * gateway URL variable
69
-     *
70
-     * @var string
71
-     */
72
-    protected $_base_gateway_url = '';
73
-
74
-
75
-
76
-    /**
77
-     * EEG_Paypal_Express constructor.
78
-     */
79
-    public function __construct()
80
-    {
81
-        $this->_currencies_supported = array(
82
-            'USD',
83
-            'AUD',
84
-            'BRL',
85
-            'CAD',
86
-            'CZK',
87
-            'DKK',
88
-            'EUR',
89
-            'HKD',
90
-            'HUF',
91
-            'ILS',
92
-            'JPY',
93
-            'MYR',
94
-            'MXN',
95
-            'NOK',
96
-            'NZD',
97
-            'PHP',
98
-            'PLN',
99
-            'GBP',
100
-            'RUB',
101
-            'SGD',
102
-            'SEK',
103
-            'CHF',
104
-            'TWD',
105
-            'THB',
106
-            'TRY',
107
-            'INR',
108
-        );
109
-        parent::__construct();
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
116
-     *
117
-     * @param array $settings_array
118
-     */
119
-    public function set_settings($settings_array)
120
-    {
121
-        parent::set_settings($settings_array);
122
-        // Redirect URL.
123
-        $this->_base_gateway_url = $this->_debug_mode
124
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
125
-            : 'https://api-3t.paypal.com/nvp';
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @param EEI_Payment $payment
132
-     * @param array       $billing_info
133
-     * @param string      $return_url
134
-     * @param string      $notify_url
135
-     * @param string      $cancel_url
136
-     * @return \EE_Payment|\EEI_Payment
137
-     * @throws \EE_Error
138
-     */
139
-    public function set_redirection_info(
140
-        $payment,
141
-        $billing_info = array(),
142
-        $return_url = null,
143
-        $notify_url = null,
144
-        $cancel_url = null
145
-    ) {
146
-        if (! $payment instanceof EEI_Payment) {
147
-            $payment->set_gateway_response(
148
-                esc_html__(
149
-                    'Error. No associated payment was found.',
150
-                    'event_espresso'
151
-                )
152
-            );
153
-            $payment->set_status($this->_pay_model->failed_status());
154
-            return $payment;
155
-        }
156
-        $transaction = $payment->transaction();
157
-        if (! $transaction instanceof EEI_Transaction) {
158
-            $payment->set_gateway_response(
159
-                esc_html__(
160
-                    'Could not process this payment because it has no associated transaction.',
161
-                    'event_espresso'
162
-                )
163
-            );
164
-            $payment->set_status($this->_pay_model->failed_status());
165
-            return $payment;
166
-        }
167
-        $gateway_formatter = $this->_get_gateway_formatter();
168
-        $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
169
-        $primary_registration = $transaction->primary_registration();
170
-        $primary_attendee = $primary_registration instanceof EE_Registration
171
-            ? $primary_registration->attendee()
172
-            : false;
173
-        $locale = explode('-', get_bloginfo('language'));
174
-        // Gather request parameters.
175
-        $token_request_dtls = array(
176
-            'METHOD'                         => 'SetExpressCheckout',
177
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
178
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
179
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
180
-            'RETURNURL'                      => $return_url,
181
-            'CANCELURL'                      => $cancel_url,
182
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
183
-            // Buyer does not need to create a PayPal account to check out.
184
-            // This is referred to as PayPal Account Optional.
185
-            'SOLUTIONTYPE'                   => 'Sole',
186
-            // Locale of the pages displayed by PayPal during Express Checkout.
187
-            'LOCALECODE'                     => $locale[1]
188
-        );
189
-        // Show itemized list.
190
-        $itemized_list = $this->itemize_list($payment, $transaction);
191
-        $token_request_dtls = array_merge($token_request_dtls, $itemized_list);
192
-        // Automatically filling out shipping and contact information.
193
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
194
-            // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
195
-            $token_request_dtls['NOSHIPPING'] = '2';
196
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
197
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
198
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
199
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
200
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
201
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
202
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
203
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
204
-        } elseif (! $this->_request_shipping_addr) {
205
-            // Do not request shipping details on the PP Checkout page.
206
-            $token_request_dtls['NOSHIPPING'] = '1';
207
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
208
-        }
209
-        // Used a business/personal logo on the PayPal page.
210
-        if (! empty($this->_image_url)) {
211
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
212
-        }
213
-        $token_request_dtls = apply_filters(
214
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
215
-            $token_request_dtls,
216
-            $this
217
-        );
218
-        // Request PayPal token.
219
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
220
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
221
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
222
-            ? $token_rstatus['args']
223
-            : array();
224
-        if ($token_rstatus['status']) {
225
-            // We got the Token so we may continue with the payment and redirect the client.
226
-            $payment->set_details($response_args);
227
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
228
-            $payment->set_redirect_url(
229
-                $gateway_url
230
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
231
-                . $response_args['TOKEN']
232
-            );
233
-        } else {
234
-            if (isset($response_args['L_ERRORCODE'])) {
235
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
236
-            } else {
237
-                $payment->set_gateway_response(
238
-                    esc_html__(
239
-                        'Error occurred while trying to setup the Express Checkout.',
240
-                        'event_espresso'
241
-                    )
242
-                );
243
-            }
244
-            $payment->set_details($response_args);
245
-            $payment->set_status($this->_pay_model->failed_status());
246
-        }
247
-        return $payment;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param array           $update_info {
254
-     * @type string           $gateway_txn_id
255
-     * @type string status an EEMI_Payment status
256
-     *                                     }
257
-     * @param EEI_Transaction $transaction
258
-     * @return EEI_Payment
259
-     */
260
-    public function handle_payment_update($update_info, $transaction)
261
-    {
262
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
263
-        if ($payment instanceof EEI_Payment) {
264
-            $this->log(array('Return from Authorization' => $update_info), $payment);
265
-            $transaction = $payment->transaction();
266
-            if (! $transaction instanceof EEI_Transaction) {
267
-                $payment->set_gateway_response(
268
-                    esc_html__(
269
-                        'Could not process this payment because it has no associated transaction.',
270
-                        'event_espresso'
271
-                    )
272
-                );
273
-                $payment->set_status($this->_pay_model->failed_status());
274
-                return $payment;
275
-            }
276
-            $primary_registrant = $transaction->primary_registration();
277
-            $payment_details = $payment->details();
278
-            // Check if we still have the token.
279
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
280
-                $payment->set_status($this->_pay_model->failed_status());
281
-                return $payment;
282
-            }
283
-            $cdetails_request_dtls = array(
284
-                'METHOD' => 'GetExpressCheckoutDetails',
285
-                'TOKEN'  => $payment_details['TOKEN'],
286
-            );
287
-            // Request Customer Details.
288
-            $cdetails_request_response = $this->_ppExpress_request(
289
-                $cdetails_request_dtls,
290
-                'Customer Details',
291
-                $payment
292
-            );
293
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
294
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
295
-                ? $cdetails_rstatus['args']
296
-                : array();
297
-            if ($cdetails_rstatus['status']) {
298
-                // We got the PayerID so now we can Complete the transaction.
299
-                $docheckout_request_dtls = array(
300
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
301
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
302
-                    'TOKEN'                          => $payment_details['TOKEN'],
303
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
304
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
305
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
306
-                );
307
-                 // Include itemized list.
308
-                $itemized_list = $this->itemize_list(
309
-                    $payment,
310
-                    $transaction,
311
-                    $cdata_response_args
312
-                );
313
-                $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
314
-                // Payment Checkout/Capture.
315
-                $docheckout_request_response = $this->_ppExpress_request(
316
-                    $docheckout_request_dtls,
317
-                    'Do Payment',
318
-                    $payment
319
-                );
320
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
321
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
322
-                    ? $docheckout_rstatus['args']
323
-                    : array();
324
-                if ($docheckout_rstatus['status']) {
325
-                    // All is well, payment approved.
326
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
327
-                        $primary_registrant->reg_code()
328
-                        : '';
329
-                    $payment->set_extra_accntng($primary_registration_code);
330
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
331
-                        ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
332
-                        : 0);
333
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
334
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
335
-                        : null);
336
-                    $payment->set_details($cdata_response_args);
337
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
338
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
339
-                        : '');
340
-                    $payment->set_status($this->_pay_model->approved_status());
341
-                } else {
342
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
343
-                        $payment->set_gateway_response(
344
-                            $docheckout_response_args['L_ERRORCODE']
345
-                            . '; '
346
-                            . $docheckout_response_args['L_SHORTMESSAGE']
347
-                        );
348
-                    } else {
349
-                        $payment->set_gateway_response(
350
-                            esc_html__(
351
-                                'Error occurred while trying to Capture the funds.',
352
-                                'event_espresso'
353
-                            )
354
-                        );
355
-                    }
356
-                    $payment->set_details($docheckout_response_args);
357
-                    $payment->set_status($this->_pay_model->declined_status());
358
-                }
359
-            } else {
360
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
361
-                    $payment->set_gateway_response(
362
-                        $cdata_response_args['L_ERRORCODE']
363
-                        . '; '
364
-                        . $cdata_response_args['L_SHORTMESSAGE']
365
-                    );
366
-                } else {
367
-                    $payment->set_gateway_response(
368
-                        esc_html__(
369
-                            'Error occurred while trying to get payment Details from PayPal.',
370
-                            'event_espresso'
371
-                        )
372
-                    );
373
-                }
374
-                $payment->set_details($cdata_response_args);
375
-                $payment->set_status($this->_pay_model->failed_status());
376
-            }
377
-        } else {
378
-            $payment->set_gateway_response(
379
-                esc_html__(
380
-                    'Error occurred while trying to process the payment.',
381
-                    'event_espresso'
382
-                )
383
-            );
384
-            $payment->set_status($this->_pay_model->failed_status());
385
-        }
386
-        return $payment;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     *  Make a list of items that are in the giver transaction.
393
-     *
394
-     * @param EEI_Payment     $payment
395
-     * @param EEI_Transaction $transaction
396
-     * @param array           $request_response_args Data from a previous communication with PP.
397
-     * @return array
398
-     */
399
-    public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
400
-    {
401
-        $itemized_list = array();
402
-        $gateway_formatter = $this->_get_gateway_formatter();
403
-        // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
404
-        if (
405
-            ! empty($request_response_args)
406
-            && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
407
-            && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
408
-        ) {
409
-            foreach ($request_response_args as $arg_key => $arg_val) {
410
-                if (
411
-                    strpos($arg_key, 'PAYMENTREQUEST_') !== false
412
-                    && strpos($arg_key, 'NOTIFYURL') === false
413
-                ) {
414
-                    $itemized_list[ $arg_key ] = $arg_val;
415
-                }
416
-            }
417
-            // If we got only a few Items then something is not right.
418
-            if (count($itemized_list) > 2) {
419
-                return $itemized_list;
420
-            } else {
421
-                if (WP_DEBUG) {
422
-                    throw new EE_Error(
423
-                        sprintf(
424
-                            esc_html__(
425
-                                // @codingStandardsIgnoreStart
426
-                                'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
427
-                                // @codingStandardsIgnoreEnd
428
-                                'event_espresso'
429
-                            ),
430
-                            wp_json_encode($itemized_list)
431
-                        )
432
-                    );
433
-                }
434
-                // Reset the list and log an error, maybe allow to try and generate a new list (below).
435
-                $itemized_list = array();
436
-                $this->log(
437
-                    array(
438
-                        (string) esc_html__(
439
-                            'Could not generate a proper item list with:',
440
-                            'event_espresso'
441
-                        ) => $request_response_args
442
-                    ),
443
-                    $payment
444
-                );
445
-            }
446
-        }
447
-        // ...otherwise we generate a new list for this transaction.
448
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
449
-            $item_num = 0;
450
-            $itemized_sum = 0;
451
-            $total_line_items = $transaction->total_line_item();
452
-            // Go through each item in the list.
453
-            foreach ($total_line_items->get_items() as $line_item) {
454
-                if ($line_item instanceof EE_Line_Item) {
455
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
456
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
457
-                        continue;
458
-                    }
459
-                    $unit_price = $line_item->unit_price();
460
-                    $line_item_quantity = $line_item->quantity();
461
-                    // This is a discount.
462
-                    if ($line_item->is_percent()) {
463
-                        $unit_price = $line_item->total();
464
-                        $line_item_quantity = 1;
465
-                    }
466
-                    // Item Name.
467
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
468
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
469
-                        0,
470
-                        127
471
-                    );
472
-                    // Item description.
473
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
474
-                        $gateway_formatter->formatLineItemDesc($line_item, $payment),
475
-                        0,
476
-                        127
477
-                    );
478
-                    // Cost of individual item.
479
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
480
-                    // Item Number.
481
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
482
-                    // Item quantity.
483
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
484
-                    // Digital item is sold.
485
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
486
-                    $itemized_sum += $line_item->total();
487
-                    ++$item_num;
488
-                }
489
-            }
490
-            // Item's sales S/H and tax amount.
491
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
492
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
493
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
494
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
495
-            $itemized_sum_diff_from_txn_total = round(
496
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
497
-                2
498
-            );
499
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
500
-            // add the difference as an extra line item.
501
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
502
-                // Item Name.
503
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
504
-                    esc_html__(
505
-                        'Other (promotion/surcharge/cancellation)',
506
-                        'event_espresso'
507
-                    ),
508
-                    0,
509
-                    127
510
-                );
511
-                // Item description.
512
-                $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
513
-                // Cost of individual item.
514
-                $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
515
-                    $itemized_sum_diff_from_txn_total
516
-                );
517
-                // Item Number.
518
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
519
-                // Item quantity.
520
-                $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
521
-                // Digital item is sold.
522
-                $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
523
-                $item_num++;
524
-            }
525
-        } else {
526
-            // Just one Item.
527
-            // Item Name.
528
-            $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
529
-                $gateway_formatter->formatPartialPaymentLineItemName($payment),
530
-                0,
531
-                127
532
-            );
533
-            // Item description.
534
-            $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
535
-                $gateway_formatter->formatPartialPaymentLineItemDesc($payment),
536
-                0,
537
-                127
538
-            );
539
-            // Cost of individual item.
540
-            $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
541
-            // Item Number.
542
-            $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
543
-            // Item quantity.
544
-            $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
545
-            // Digital item is sold.
546
-            $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
547
-            // Item's sales S/H and tax amount.
548
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
549
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
550
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
551
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
552
-        }
553
-        return $itemized_list;
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     *  Make the Express checkout request.
560
-     *
561
-     * @param array       $request_params
562
-     * @param string      $request_text
563
-     * @param EEI_Payment $payment
564
-     * @return mixed
565
-     */
566
-    public function _ppExpress_request($request_params, $request_text, $payment)
567
-    {
568
-        $request_dtls = array(
569
-            'VERSION' => '204.0',
570
-            'USER' => $this->_api_username,
571
-            'PWD' => $this->_api_password,
572
-            'SIGNATURE' => $this->_api_signature,
573
-            // EE will blow up if you change this
574
-            'BUTTONSOURCE' => 'EventEspresso_SP',
575
-        );
576
-        $dtls = array_merge($request_dtls, $request_params);
577
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
578
-        // Request Customer Details.
579
-        $request_response = wp_remote_post(
580
-            $this->_base_gateway_url,
581
-            array(
582
-                'method'      => 'POST',
583
-                'timeout'     => 45,
584
-                'httpversion' => '1.1',
585
-                'cookies'     => array(),
586
-                'headers'     => array(),
587
-                'body'        => http_build_query($dtls, '', '&'),
588
-            )
589
-        );
590
-        // Log the response.
591
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
592
-        return $request_response;
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     *  Check the response status.
599
-     *
600
-     * @param mixed $request_response
601
-     * @return array
602
-     */
603
-    public function _ppExpress_check_response($request_response)
604
-    {
605
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
606
-            // If we got here then there was an error in this request.
607
-            return array('status' => false, 'args' => $request_response);
608
-        }
609
-        $response_args = array();
610
-        parse_str(urldecode($request_response['body']), $response_args);
611
-        if (! isset($response_args['ACK'])) {
612
-            return array('status' => false, 'args' => $request_response);
613
-        }
614
-        if (
615
-            (
616
-                isset($response_args['PAYERID'])
617
-                || isset($response_args['TOKEN'])
618
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
619
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
620
-            )
621
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
622
-        ) {
623
-            // Response status OK, return response parameters for further processing.
624
-            return array('status' => true, 'args' => $response_args);
625
-        }
626
-        $errors = $this->_get_errors($response_args);
627
-        return array('status' => false, 'args' => $errors);
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     *  Log a "Cleared" request.
634
-     *
635
-     * @param array       $request
636
-     * @param EEI_Payment $payment
637
-     * @param string      $info
638
-     * @return void
639
-     */
640
-    private function _log_clean_request($request, $payment, $info)
641
-    {
642
-        $cleaned_request_data = $request;
643
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
644
-        $this->log(array($info => $cleaned_request_data), $payment);
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     *  Get error from the response data.
651
-     *
652
-     * @param array $data_array
653
-     * @return array
654
-     */
655
-    private function _get_errors($data_array)
656
-    {
657
-        $errors = array();
658
-        $n = 0;
659
-        while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
660
-            $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
661
-                ? $data_array[ "L_ERRORCODE{$n}" ]
662
-                : '';
663
-            $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
664
-                ? $data_array[ "L_SEVERITYCODE{$n}" ]
665
-                : '';
666
-            $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
667
-                ? $data_array[ "L_SHORTMESSAGE{$n}" ]
668
-                : '';
669
-            $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
670
-                ? $data_array[ "L_LONGMESSAGE{$n}" ]
671
-                : '';
672
-            if ($n === 0) {
673
-                $errors = array(
674
-                    'L_ERRORCODE'    => $l_error_code,
675
-                    'L_SHORTMESSAGE' => $l_short_message,
676
-                    'L_LONGMESSAGE'  => $l_long_message,
677
-                    'L_SEVERITYCODE' => $l_severity_code,
678
-                );
679
-            } else {
680
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
681
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
682
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
683
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
684
-            }
685
-            $n++;
686
-        }
687
-        return $errors;
688
-    }
32
+	/**
33
+	 * Merchant API Username.
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $_api_username;
38
+
39
+	/**
40
+	 * Merchant API Password.
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $_api_password;
45
+
46
+	/**
47
+	 * API Signature.
48
+	 *
49
+	 * @var string
50
+	 */
51
+	protected $_api_signature;
52
+
53
+	/**
54
+	 * Request Shipping address on PP checkout page.
55
+	 *
56
+	 * @var string
57
+	 */
58
+	protected $_request_shipping_addr;
59
+
60
+	/**
61
+	 * Business/personal logo.
62
+	 *
63
+	 * @var string
64
+	 */
65
+	protected $_image_url;
66
+
67
+	/**
68
+	 * gateway URL variable
69
+	 *
70
+	 * @var string
71
+	 */
72
+	protected $_base_gateway_url = '';
73
+
74
+
75
+
76
+	/**
77
+	 * EEG_Paypal_Express constructor.
78
+	 */
79
+	public function __construct()
80
+	{
81
+		$this->_currencies_supported = array(
82
+			'USD',
83
+			'AUD',
84
+			'BRL',
85
+			'CAD',
86
+			'CZK',
87
+			'DKK',
88
+			'EUR',
89
+			'HKD',
90
+			'HUF',
91
+			'ILS',
92
+			'JPY',
93
+			'MYR',
94
+			'MXN',
95
+			'NOK',
96
+			'NZD',
97
+			'PHP',
98
+			'PLN',
99
+			'GBP',
100
+			'RUB',
101
+			'SGD',
102
+			'SEK',
103
+			'CHF',
104
+			'TWD',
105
+			'THB',
106
+			'TRY',
107
+			'INR',
108
+		);
109
+		parent::__construct();
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
116
+	 *
117
+	 * @param array $settings_array
118
+	 */
119
+	public function set_settings($settings_array)
120
+	{
121
+		parent::set_settings($settings_array);
122
+		// Redirect URL.
123
+		$this->_base_gateway_url = $this->_debug_mode
124
+			? 'https://api-3t.sandbox.paypal.com/nvp'
125
+			: 'https://api-3t.paypal.com/nvp';
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @param EEI_Payment $payment
132
+	 * @param array       $billing_info
133
+	 * @param string      $return_url
134
+	 * @param string      $notify_url
135
+	 * @param string      $cancel_url
136
+	 * @return \EE_Payment|\EEI_Payment
137
+	 * @throws \EE_Error
138
+	 */
139
+	public function set_redirection_info(
140
+		$payment,
141
+		$billing_info = array(),
142
+		$return_url = null,
143
+		$notify_url = null,
144
+		$cancel_url = null
145
+	) {
146
+		if (! $payment instanceof EEI_Payment) {
147
+			$payment->set_gateway_response(
148
+				esc_html__(
149
+					'Error. No associated payment was found.',
150
+					'event_espresso'
151
+				)
152
+			);
153
+			$payment->set_status($this->_pay_model->failed_status());
154
+			return $payment;
155
+		}
156
+		$transaction = $payment->transaction();
157
+		if (! $transaction instanceof EEI_Transaction) {
158
+			$payment->set_gateway_response(
159
+				esc_html__(
160
+					'Could not process this payment because it has no associated transaction.',
161
+					'event_espresso'
162
+				)
163
+			);
164
+			$payment->set_status($this->_pay_model->failed_status());
165
+			return $payment;
166
+		}
167
+		$gateway_formatter = $this->_get_gateway_formatter();
168
+		$order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
169
+		$primary_registration = $transaction->primary_registration();
170
+		$primary_attendee = $primary_registration instanceof EE_Registration
171
+			? $primary_registration->attendee()
172
+			: false;
173
+		$locale = explode('-', get_bloginfo('language'));
174
+		// Gather request parameters.
175
+		$token_request_dtls = array(
176
+			'METHOD'                         => 'SetExpressCheckout',
177
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
178
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
179
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
180
+			'RETURNURL'                      => $return_url,
181
+			'CANCELURL'                      => $cancel_url,
182
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
183
+			// Buyer does not need to create a PayPal account to check out.
184
+			// This is referred to as PayPal Account Optional.
185
+			'SOLUTIONTYPE'                   => 'Sole',
186
+			// Locale of the pages displayed by PayPal during Express Checkout.
187
+			'LOCALECODE'                     => $locale[1]
188
+		);
189
+		// Show itemized list.
190
+		$itemized_list = $this->itemize_list($payment, $transaction);
191
+		$token_request_dtls = array_merge($token_request_dtls, $itemized_list);
192
+		// Automatically filling out shipping and contact information.
193
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
194
+			// If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
195
+			$token_request_dtls['NOSHIPPING'] = '2';
196
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
197
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
198
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
199
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
200
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
201
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
202
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
203
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
204
+		} elseif (! $this->_request_shipping_addr) {
205
+			// Do not request shipping details on the PP Checkout page.
206
+			$token_request_dtls['NOSHIPPING'] = '1';
207
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
208
+		}
209
+		// Used a business/personal logo on the PayPal page.
210
+		if (! empty($this->_image_url)) {
211
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
212
+		}
213
+		$token_request_dtls = apply_filters(
214
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
215
+			$token_request_dtls,
216
+			$this
217
+		);
218
+		// Request PayPal token.
219
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
220
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
221
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
222
+			? $token_rstatus['args']
223
+			: array();
224
+		if ($token_rstatus['status']) {
225
+			// We got the Token so we may continue with the payment and redirect the client.
226
+			$payment->set_details($response_args);
227
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
228
+			$payment->set_redirect_url(
229
+				$gateway_url
230
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
231
+				. $response_args['TOKEN']
232
+			);
233
+		} else {
234
+			if (isset($response_args['L_ERRORCODE'])) {
235
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
236
+			} else {
237
+				$payment->set_gateway_response(
238
+					esc_html__(
239
+						'Error occurred while trying to setup the Express Checkout.',
240
+						'event_espresso'
241
+					)
242
+				);
243
+			}
244
+			$payment->set_details($response_args);
245
+			$payment->set_status($this->_pay_model->failed_status());
246
+		}
247
+		return $payment;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param array           $update_info {
254
+	 * @type string           $gateway_txn_id
255
+	 * @type string status an EEMI_Payment status
256
+	 *                                     }
257
+	 * @param EEI_Transaction $transaction
258
+	 * @return EEI_Payment
259
+	 */
260
+	public function handle_payment_update($update_info, $transaction)
261
+	{
262
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
263
+		if ($payment instanceof EEI_Payment) {
264
+			$this->log(array('Return from Authorization' => $update_info), $payment);
265
+			$transaction = $payment->transaction();
266
+			if (! $transaction instanceof EEI_Transaction) {
267
+				$payment->set_gateway_response(
268
+					esc_html__(
269
+						'Could not process this payment because it has no associated transaction.',
270
+						'event_espresso'
271
+					)
272
+				);
273
+				$payment->set_status($this->_pay_model->failed_status());
274
+				return $payment;
275
+			}
276
+			$primary_registrant = $transaction->primary_registration();
277
+			$payment_details = $payment->details();
278
+			// Check if we still have the token.
279
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
280
+				$payment->set_status($this->_pay_model->failed_status());
281
+				return $payment;
282
+			}
283
+			$cdetails_request_dtls = array(
284
+				'METHOD' => 'GetExpressCheckoutDetails',
285
+				'TOKEN'  => $payment_details['TOKEN'],
286
+			);
287
+			// Request Customer Details.
288
+			$cdetails_request_response = $this->_ppExpress_request(
289
+				$cdetails_request_dtls,
290
+				'Customer Details',
291
+				$payment
292
+			);
293
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
294
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
295
+				? $cdetails_rstatus['args']
296
+				: array();
297
+			if ($cdetails_rstatus['status']) {
298
+				// We got the PayerID so now we can Complete the transaction.
299
+				$docheckout_request_dtls = array(
300
+					'METHOD'                         => 'DoExpressCheckoutPayment',
301
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
302
+					'TOKEN'                          => $payment_details['TOKEN'],
303
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
304
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
305
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
306
+				);
307
+				 // Include itemized list.
308
+				$itemized_list = $this->itemize_list(
309
+					$payment,
310
+					$transaction,
311
+					$cdata_response_args
312
+				);
313
+				$docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
314
+				// Payment Checkout/Capture.
315
+				$docheckout_request_response = $this->_ppExpress_request(
316
+					$docheckout_request_dtls,
317
+					'Do Payment',
318
+					$payment
319
+				);
320
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
321
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
322
+					? $docheckout_rstatus['args']
323
+					: array();
324
+				if ($docheckout_rstatus['status']) {
325
+					// All is well, payment approved.
326
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
327
+						$primary_registrant->reg_code()
328
+						: '';
329
+					$payment->set_extra_accntng($primary_registration_code);
330
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
331
+						? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
332
+						: 0);
333
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
334
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
335
+						: null);
336
+					$payment->set_details($cdata_response_args);
337
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
338
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
339
+						: '');
340
+					$payment->set_status($this->_pay_model->approved_status());
341
+				} else {
342
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
343
+						$payment->set_gateway_response(
344
+							$docheckout_response_args['L_ERRORCODE']
345
+							. '; '
346
+							. $docheckout_response_args['L_SHORTMESSAGE']
347
+						);
348
+					} else {
349
+						$payment->set_gateway_response(
350
+							esc_html__(
351
+								'Error occurred while trying to Capture the funds.',
352
+								'event_espresso'
353
+							)
354
+						);
355
+					}
356
+					$payment->set_details($docheckout_response_args);
357
+					$payment->set_status($this->_pay_model->declined_status());
358
+				}
359
+			} else {
360
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
361
+					$payment->set_gateway_response(
362
+						$cdata_response_args['L_ERRORCODE']
363
+						. '; '
364
+						. $cdata_response_args['L_SHORTMESSAGE']
365
+					);
366
+				} else {
367
+					$payment->set_gateway_response(
368
+						esc_html__(
369
+							'Error occurred while trying to get payment Details from PayPal.',
370
+							'event_espresso'
371
+						)
372
+					);
373
+				}
374
+				$payment->set_details($cdata_response_args);
375
+				$payment->set_status($this->_pay_model->failed_status());
376
+			}
377
+		} else {
378
+			$payment->set_gateway_response(
379
+				esc_html__(
380
+					'Error occurred while trying to process the payment.',
381
+					'event_espresso'
382
+				)
383
+			);
384
+			$payment->set_status($this->_pay_model->failed_status());
385
+		}
386
+		return $payment;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 *  Make a list of items that are in the giver transaction.
393
+	 *
394
+	 * @param EEI_Payment     $payment
395
+	 * @param EEI_Transaction $transaction
396
+	 * @param array           $request_response_args Data from a previous communication with PP.
397
+	 * @return array
398
+	 */
399
+	public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
400
+	{
401
+		$itemized_list = array();
402
+		$gateway_formatter = $this->_get_gateway_formatter();
403
+		// If we have data from a previous communication with PP (on this transaction) we may use that for our list...
404
+		if (
405
+			! empty($request_response_args)
406
+			&& array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
407
+			&& array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
408
+		) {
409
+			foreach ($request_response_args as $arg_key => $arg_val) {
410
+				if (
411
+					strpos($arg_key, 'PAYMENTREQUEST_') !== false
412
+					&& strpos($arg_key, 'NOTIFYURL') === false
413
+				) {
414
+					$itemized_list[ $arg_key ] = $arg_val;
415
+				}
416
+			}
417
+			// If we got only a few Items then something is not right.
418
+			if (count($itemized_list) > 2) {
419
+				return $itemized_list;
420
+			} else {
421
+				if (WP_DEBUG) {
422
+					throw new EE_Error(
423
+						sprintf(
424
+							esc_html__(
425
+								// @codingStandardsIgnoreStart
426
+								'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
427
+								// @codingStandardsIgnoreEnd
428
+								'event_espresso'
429
+							),
430
+							wp_json_encode($itemized_list)
431
+						)
432
+					);
433
+				}
434
+				// Reset the list and log an error, maybe allow to try and generate a new list (below).
435
+				$itemized_list = array();
436
+				$this->log(
437
+					array(
438
+						(string) esc_html__(
439
+							'Could not generate a proper item list with:',
440
+							'event_espresso'
441
+						) => $request_response_args
442
+					),
443
+					$payment
444
+				);
445
+			}
446
+		}
447
+		// ...otherwise we generate a new list for this transaction.
448
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
449
+			$item_num = 0;
450
+			$itemized_sum = 0;
451
+			$total_line_items = $transaction->total_line_item();
452
+			// Go through each item in the list.
453
+			foreach ($total_line_items->get_items() as $line_item) {
454
+				if ($line_item instanceof EE_Line_Item) {
455
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
456
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
457
+						continue;
458
+					}
459
+					$unit_price = $line_item->unit_price();
460
+					$line_item_quantity = $line_item->quantity();
461
+					// This is a discount.
462
+					if ($line_item->is_percent()) {
463
+						$unit_price = $line_item->total();
464
+						$line_item_quantity = 1;
465
+					}
466
+					// Item Name.
467
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
468
+						$gateway_formatter->formatLineItemName($line_item, $payment),
469
+						0,
470
+						127
471
+					);
472
+					// Item description.
473
+					$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
474
+						$gateway_formatter->formatLineItemDesc($line_item, $payment),
475
+						0,
476
+						127
477
+					);
478
+					// Cost of individual item.
479
+					$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
480
+					// Item Number.
481
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
482
+					// Item quantity.
483
+					$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
484
+					// Digital item is sold.
485
+					$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
486
+					$itemized_sum += $line_item->total();
487
+					++$item_num;
488
+				}
489
+			}
490
+			// Item's sales S/H and tax amount.
491
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
492
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
493
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
494
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
495
+			$itemized_sum_diff_from_txn_total = round(
496
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
497
+				2
498
+			);
499
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
500
+			// add the difference as an extra line item.
501
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
502
+				// Item Name.
503
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
504
+					esc_html__(
505
+						'Other (promotion/surcharge/cancellation)',
506
+						'event_espresso'
507
+					),
508
+					0,
509
+					127
510
+				);
511
+				// Item description.
512
+				$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
513
+				// Cost of individual item.
514
+				$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
515
+					$itemized_sum_diff_from_txn_total
516
+				);
517
+				// Item Number.
518
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
519
+				// Item quantity.
520
+				$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
521
+				// Digital item is sold.
522
+				$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
523
+				$item_num++;
524
+			}
525
+		} else {
526
+			// Just one Item.
527
+			// Item Name.
528
+			$itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
529
+				$gateway_formatter->formatPartialPaymentLineItemName($payment),
530
+				0,
531
+				127
532
+			);
533
+			// Item description.
534
+			$itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
535
+				$gateway_formatter->formatPartialPaymentLineItemDesc($payment),
536
+				0,
537
+				127
538
+			);
539
+			// Cost of individual item.
540
+			$itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
541
+			// Item Number.
542
+			$itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
543
+			// Item quantity.
544
+			$itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
545
+			// Digital item is sold.
546
+			$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
547
+			// Item's sales S/H and tax amount.
548
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
549
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
550
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
551
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
552
+		}
553
+		return $itemized_list;
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 *  Make the Express checkout request.
560
+	 *
561
+	 * @param array       $request_params
562
+	 * @param string      $request_text
563
+	 * @param EEI_Payment $payment
564
+	 * @return mixed
565
+	 */
566
+	public function _ppExpress_request($request_params, $request_text, $payment)
567
+	{
568
+		$request_dtls = array(
569
+			'VERSION' => '204.0',
570
+			'USER' => $this->_api_username,
571
+			'PWD' => $this->_api_password,
572
+			'SIGNATURE' => $this->_api_signature,
573
+			// EE will blow up if you change this
574
+			'BUTTONSOURCE' => 'EventEspresso_SP',
575
+		);
576
+		$dtls = array_merge($request_dtls, $request_params);
577
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
578
+		// Request Customer Details.
579
+		$request_response = wp_remote_post(
580
+			$this->_base_gateway_url,
581
+			array(
582
+				'method'      => 'POST',
583
+				'timeout'     => 45,
584
+				'httpversion' => '1.1',
585
+				'cookies'     => array(),
586
+				'headers'     => array(),
587
+				'body'        => http_build_query($dtls, '', '&'),
588
+			)
589
+		);
590
+		// Log the response.
591
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
592
+		return $request_response;
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 *  Check the response status.
599
+	 *
600
+	 * @param mixed $request_response
601
+	 * @return array
602
+	 */
603
+	public function _ppExpress_check_response($request_response)
604
+	{
605
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
606
+			// If we got here then there was an error in this request.
607
+			return array('status' => false, 'args' => $request_response);
608
+		}
609
+		$response_args = array();
610
+		parse_str(urldecode($request_response['body']), $response_args);
611
+		if (! isset($response_args['ACK'])) {
612
+			return array('status' => false, 'args' => $request_response);
613
+		}
614
+		if (
615
+			(
616
+				isset($response_args['PAYERID'])
617
+				|| isset($response_args['TOKEN'])
618
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
619
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
620
+			)
621
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
622
+		) {
623
+			// Response status OK, return response parameters for further processing.
624
+			return array('status' => true, 'args' => $response_args);
625
+		}
626
+		$errors = $this->_get_errors($response_args);
627
+		return array('status' => false, 'args' => $errors);
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 *  Log a "Cleared" request.
634
+	 *
635
+	 * @param array       $request
636
+	 * @param EEI_Payment $payment
637
+	 * @param string      $info
638
+	 * @return void
639
+	 */
640
+	private function _log_clean_request($request, $payment, $info)
641
+	{
642
+		$cleaned_request_data = $request;
643
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
644
+		$this->log(array($info => $cleaned_request_data), $payment);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 *  Get error from the response data.
651
+	 *
652
+	 * @param array $data_array
653
+	 * @return array
654
+	 */
655
+	private function _get_errors($data_array)
656
+	{
657
+		$errors = array();
658
+		$n = 0;
659
+		while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
660
+			$l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
661
+				? $data_array[ "L_ERRORCODE{$n}" ]
662
+				: '';
663
+			$l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
664
+				? $data_array[ "L_SEVERITYCODE{$n}" ]
665
+				: '';
666
+			$l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
667
+				? $data_array[ "L_SHORTMESSAGE{$n}" ]
668
+				: '';
669
+			$l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
670
+				? $data_array[ "L_LONGMESSAGE{$n}" ]
671
+				: '';
672
+			if ($n === 0) {
673
+				$errors = array(
674
+					'L_ERRORCODE'    => $l_error_code,
675
+					'L_SHORTMESSAGE' => $l_short_message,
676
+					'L_LONGMESSAGE'  => $l_long_message,
677
+					'L_SEVERITYCODE' => $l_severity_code,
678
+				);
679
+			} else {
680
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
681
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
682
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
683
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
684
+			}
685
+			$n++;
686
+		}
687
+		return $errors;
688
+	}
689 689
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
15
-if (! function_exists('mb_strcut')) {
15
+if ( ! function_exists('mb_strcut')) {
16 16
     /**
17 17
      * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
18 18
      * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         $notify_url = null,
144 144
         $cancel_url = null
145 145
     ) {
146
-        if (! $payment instanceof EEI_Payment) {
146
+        if ( ! $payment instanceof EEI_Payment) {
147 147
             $payment->set_gateway_response(
148 148
                 esc_html__(
149 149
                     'Error. No associated payment was found.',
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
             return $payment;
155 155
         }
156 156
         $transaction = $payment->transaction();
157
-        if (! $transaction instanceof EEI_Transaction) {
157
+        if ( ! $transaction instanceof EEI_Transaction) {
158 158
             $payment->set_gateway_response(
159 159
                 esc_html__(
160 160
                     'Could not process this payment because it has no associated transaction.',
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
202 202
             $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
203 203
             $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
204
-        } elseif (! $this->_request_shipping_addr) {
204
+        } elseif ( ! $this->_request_shipping_addr) {
205 205
             // Do not request shipping details on the PP Checkout page.
206 206
             $token_request_dtls['NOSHIPPING'] = '1';
207 207
             $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
208 208
         }
209 209
         // Used a business/personal logo on the PayPal page.
210
-        if (! empty($this->_image_url)) {
210
+        if ( ! empty($this->_image_url)) {
211 211
             $token_request_dtls['LOGOIMG'] = $this->_image_url;
212 212
         }
213 213
         $token_request_dtls = apply_filters(
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
             );
233 233
         } else {
234 234
             if (isset($response_args['L_ERRORCODE'])) {
235
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
235
+                $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
236 236
             } else {
237 237
                 $payment->set_gateway_response(
238 238
                     esc_html__(
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
         if ($payment instanceof EEI_Payment) {
264 264
             $this->log(array('Return from Authorization' => $update_info), $payment);
265 265
             $transaction = $payment->transaction();
266
-            if (! $transaction instanceof EEI_Transaction) {
266
+            if ( ! $transaction instanceof EEI_Transaction) {
267 267
                 $payment->set_gateway_response(
268 268
                     esc_html__(
269 269
                         'Could not process this payment because it has no associated transaction.',
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
             $primary_registrant = $transaction->primary_registration();
277 277
             $payment_details = $payment->details();
278 278
             // Check if we still have the token.
279
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
279
+            if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
280 280
                 $payment->set_status($this->_pay_model->failed_status());
281 281
                 return $payment;
282 282
             }
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
                     strpos($arg_key, 'PAYMENTREQUEST_') !== false
412 412
                     && strpos($arg_key, 'NOTIFYURL') === false
413 413
                 ) {
414
-                    $itemized_list[ $arg_key ] = $arg_val;
414
+                    $itemized_list[$arg_key] = $arg_val;
415 415
                 }
416 416
             }
417 417
             // If we got only a few Items then something is not right.
@@ -464,25 +464,25 @@  discard block
 block discarded – undo
464 464
                         $line_item_quantity = 1;
465 465
                     }
466 466
                     // Item Name.
467
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
467
+                    $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
468 468
                         $gateway_formatter->formatLineItemName($line_item, $payment),
469 469
                         0,
470 470
                         127
471 471
                     );
472 472
                     // Item description.
473
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
473
+                    $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut(
474 474
                         $gateway_formatter->formatLineItemDesc($line_item, $payment),
475 475
                         0,
476 476
                         127
477 477
                     );
478 478
                     // Cost of individual item.
479
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
479
+                    $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price);
480 480
                     // Item Number.
481
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
481
+                    $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
482 482
                     // Item quantity.
483
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
483
+                    $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity;
484 484
                     // Digital item is sold.
485
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
485
+                    $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
486 486
                     $itemized_sum += $line_item->total();
487 487
                     ++$item_num;
488 488
                 }
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
             // add the difference as an extra line item.
501 501
             if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
502 502
                 // Item Name.
503
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
503
+                $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut(
504 504
                     esc_html__(
505 505
                         'Other (promotion/surcharge/cancellation)',
506 506
                         'event_espresso'
@@ -509,17 +509,17 @@  discard block
 block discarded – undo
509 509
                     127
510 510
                 );
511 511
                 // Item description.
512
-                $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
512
+                $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
513 513
                 // Cost of individual item.
514
-                $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
514
+                $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency(
515 515
                     $itemized_sum_diff_from_txn_total
516 516
                 );
517 517
                 // Item Number.
518
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
518
+                $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
519 519
                 // Item quantity.
520
-                $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
520
+                $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
521 521
                 // Digital item is sold.
522
-                $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
522
+                $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
523 523
                 $item_num++;
524 524
             }
525 525
         } else {
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
             'BUTTONSOURCE' => 'EventEspresso_SP',
575 575
         );
576 576
         $dtls = array_merge($request_dtls, $request_params);
577
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
577
+        $this->_log_clean_request($dtls, $payment, $request_text.' Request');
578 578
         // Request Customer Details.
579 579
         $request_response = wp_remote_post(
580 580
             $this->_base_gateway_url,
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
             )
589 589
         );
590 590
         // Log the response.
591
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
591
+        $this->log(array($request_text.' Response' => $request_response), $payment);
592 592
         return $request_response;
593 593
     }
594 594
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
         }
609 609
         $response_args = array();
610 610
         parse_str(urldecode($request_response['body']), $response_args);
611
-        if (! isset($response_args['ACK'])) {
611
+        if ( ! isset($response_args['ACK'])) {
612 612
             return array('status' => false, 'args' => $request_response);
613 613
         }
614 614
         if (
@@ -656,18 +656,18 @@  discard block
 block discarded – undo
656 656
     {
657 657
         $errors = array();
658 658
         $n = 0;
659
-        while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
660
-            $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
661
-                ? $data_array[ "L_ERRORCODE{$n}" ]
659
+        while (isset($data_array["L_ERRORCODE{$n}"])) {
660
+            $l_error_code = isset($data_array["L_ERRORCODE{$n}"])
661
+                ? $data_array["L_ERRORCODE{$n}"]
662 662
                 : '';
663
-            $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
664
-                ? $data_array[ "L_SEVERITYCODE{$n}" ]
663
+            $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
664
+                ? $data_array["L_SEVERITYCODE{$n}"]
665 665
                 : '';
666
-            $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
667
-                ? $data_array[ "L_SHORTMESSAGE{$n}" ]
666
+            $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
667
+                ? $data_array["L_SHORTMESSAGE{$n}"]
668 668
                 : '';
669
-            $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
670
-                ? $data_array[ "L_LONGMESSAGE{$n}" ]
669
+            $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
670
+                ? $data_array["L_LONGMESSAGE{$n}"]
671 671
                 : '';
672 672
             if ($n === 0) {
673 673
                 $errors = array(
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
                     'L_SEVERITYCODE' => $l_severity_code,
678 678
                 );
679 679
             } else {
680
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
681
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
682
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
683
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
680
+                $errors['L_ERRORCODE'] .= ', '.$l_error_code;
681
+                $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
682
+                $errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
683
+                $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
684 684
             }
685 685
             $n++;
686 686
         }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -924,7 +924,7 @@
 block discarded – undo
924 924
      * handles toggling the checkin status for the registration,
925 925
      *
926 926
      * @access protected
927
-     * @return int|void
927
+     * @return integer
928 928
      * @throws EE_Error
929 929
      * @throws InvalidArgumentException
930 930
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +1213 added lines, -1213 removed lines patch added patch discarded remove patch
@@ -16,1270 +16,1270 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
-                'require_nonce' => false,
113
-            ),
114
-            'event_registrations'   => array(
115
-                'nav'           => array(
116
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
-                    'order'      => 10,
118
-                    'persistent' => true,
119
-                ),
120
-                'help_tabs'     => array(
121
-                    'registrations_event_checkin_help_tab'                       => array(
122
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
-                        'filename' => 'registrations_event_checkin',
124
-                    ),
125
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
126
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
-                        'filename' => 'registrations_event_checkin_table_column_headings',
128
-                    ),
129
-                    'registrations_event_checkin_filters_help_tab'               => array(
130
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
-                        'filename' => 'registrations_event_checkin_filters',
132
-                    ),
133
-                    'registrations_event_checkin_views_help_tab'                 => array(
134
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
-                        'filename' => 'registrations_event_checkin_views',
136
-                    ),
137
-                    'registrations_event_checkin_other_help_tab'                 => array(
138
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
-                        'filename' => 'registrations_event_checkin_other',
140
-                    ),
141
-                ),
142
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
-                // 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
-                'qtips'         => array('Registration_List_Table_Tips'),
145
-                'list_table'    => 'EE_Event_Registrations_List_Table',
146
-                'metaboxes'     => array(),
147
-                'require_nonce' => false,
148
-            ),
149
-            'registration_checkins' => array(
150
-                'nav'           => array(
151
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
-                    'order'      => 15,
153
-                    'persistent' => false,
154
-                    'url'        => '',
155
-                ),
156
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
-                // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
-                'metaboxes'     => array(),
159
-                'require_nonce' => false,
160
-            ),
161
-        );
162
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
163
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
+				'require_nonce' => false,
113
+			),
114
+			'event_registrations'   => array(
115
+				'nav'           => array(
116
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
+					'order'      => 10,
118
+					'persistent' => true,
119
+				),
120
+				'help_tabs'     => array(
121
+					'registrations_event_checkin_help_tab'                       => array(
122
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
+						'filename' => 'registrations_event_checkin',
124
+					),
125
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
126
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
+						'filename' => 'registrations_event_checkin_table_column_headings',
128
+					),
129
+					'registrations_event_checkin_filters_help_tab'               => array(
130
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
+						'filename' => 'registrations_event_checkin_filters',
132
+					),
133
+					'registrations_event_checkin_views_help_tab'                 => array(
134
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
+						'filename' => 'registrations_event_checkin_views',
136
+					),
137
+					'registrations_event_checkin_other_help_tab'                 => array(
138
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
+						'filename' => 'registrations_event_checkin_other',
140
+					),
141
+				),
142
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
+				// 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
+				'qtips'         => array('Registration_List_Table_Tips'),
145
+				'list_table'    => 'EE_Event_Registrations_List_Table',
146
+				'metaboxes'     => array(),
147
+				'require_nonce' => false,
148
+			),
149
+			'registration_checkins' => array(
150
+				'nav'           => array(
151
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
+					'order'      => 15,
153
+					'persistent' => false,
154
+					'url'        => '',
155
+				),
156
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
+				// 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
+				'metaboxes'     => array(),
159
+				'require_nonce' => false,
160
+			),
161
+		);
162
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
163
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
+	}
166 166
 
167 167
 
168
-    /**
169
-     * Ajax hooks for all routes in this page.
170
-     */
171
-    protected function _ajax_hooks()
172
-    {
173
-        parent::_ajax_hooks();
174
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
-    }
168
+	/**
169
+	 * Ajax hooks for all routes in this page.
170
+	 */
171
+	protected function _ajax_hooks()
172
+	{
173
+		parent::_ajax_hooks();
174
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * Global scripts for all routes in this page.
180
-     */
181
-    public function load_scripts_styles()
182
-    {
183
-        parent::load_scripts_styles();
184
-        // if newsletter message type is active then let's add filter and load js for it.
185
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
-            // enqueue newsletter js
187
-            wp_enqueue_script(
188
-                'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
-                array('ee-dialog'),
191
-                EVENT_ESPRESSO_VERSION,
192
-                true
193
-            );
194
-            wp_enqueue_style(
195
-                'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
-                array(),
198
-                EVENT_ESPRESSO_VERSION
199
-            );
200
-            // hook in buttons for newsletter message type trigger.
201
-            add_action(
202
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
-                array($this, 'add_newsletter_action_buttons'),
204
-                10
205
-            );
206
-        }
207
-    }
178
+	/**
179
+	 * Global scripts for all routes in this page.
180
+	 */
181
+	public function load_scripts_styles()
182
+	{
183
+		parent::load_scripts_styles();
184
+		// if newsletter message type is active then let's add filter and load js for it.
185
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
+			// enqueue newsletter js
187
+			wp_enqueue_script(
188
+				'ee-newsletter-trigger',
189
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
+				array('ee-dialog'),
191
+				EVENT_ESPRESSO_VERSION,
192
+				true
193
+			);
194
+			wp_enqueue_style(
195
+				'ee-newsletter-trigger-css',
196
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
+				array(),
198
+				EVENT_ESPRESSO_VERSION
199
+			);
200
+			// hook in buttons for newsletter message type trigger.
201
+			add_action(
202
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
+				array($this, 'add_newsletter_action_buttons'),
204
+				10
205
+			);
206
+		}
207
+	}
208 208
 
209 209
 
210
-    /**
211
-     * Scripts and styles for just the reports route.
212
-     */
213
-    public function load_scripts_styles_reports()
214
-    {
215
-        wp_register_script(
216
-            'ee-reg-reports-js',
217
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
-            array('google-charts'),
219
-            EVENT_ESPRESSO_VERSION,
220
-            true
221
-        );
222
-        wp_enqueue_script('ee-reg-reports-js');
223
-        $this->_registration_reports_js_setup();
224
-    }
210
+	/**
211
+	 * Scripts and styles for just the reports route.
212
+	 */
213
+	public function load_scripts_styles_reports()
214
+	{
215
+		wp_register_script(
216
+			'ee-reg-reports-js',
217
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
+			array('google-charts'),
219
+			EVENT_ESPRESSO_VERSION,
220
+			true
221
+		);
222
+		wp_enqueue_script('ee-reg-reports-js');
223
+		$this->_registration_reports_js_setup();
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Register screen options for event_registrations route.
229
-     */
230
-    protected function _add_screen_options_event_registrations()
231
-    {
232
-        $this->_per_page_screen_option();
233
-    }
227
+	/**
228
+	 * Register screen options for event_registrations route.
229
+	 */
230
+	protected function _add_screen_options_event_registrations()
231
+	{
232
+		$this->_per_page_screen_option();
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * Register screen options for registration_checkins route
238
-     */
239
-    protected function _add_screen_options_registration_checkins()
240
-    {
241
-        $page_title = $this->_admin_page_title;
242
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
-        $this->_per_page_screen_option();
244
-        $this->_admin_page_title = $page_title;
245
-    }
236
+	/**
237
+	 * Register screen options for registration_checkins route
238
+	 */
239
+	protected function _add_screen_options_registration_checkins()
240
+	{
241
+		$page_title = $this->_admin_page_title;
242
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
+		$this->_per_page_screen_option();
244
+		$this->_admin_page_title = $page_title;
245
+	}
246 246
 
247 247
 
248
-    /**
249
-     * Set views property for event_registrations route.
250
-     */
251
-    protected function _set_list_table_views_event_registrations()
252
-    {
253
-        $this->_views = array(
254
-            'all' => array(
255
-                'slug'        => 'all',
256
-                'label'       => esc_html__('All', 'event_espresso'),
257
-                'count'       => 0,
258
-                'bulk_action' => ! isset($this->_req_data['event_id'])
259
-                    ? array()
260
-                    : array(
261
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
-                    ),
263
-            ),
264
-        );
265
-    }
248
+	/**
249
+	 * Set views property for event_registrations route.
250
+	 */
251
+	protected function _set_list_table_views_event_registrations()
252
+	{
253
+		$this->_views = array(
254
+			'all' => array(
255
+				'slug'        => 'all',
256
+				'label'       => esc_html__('All', 'event_espresso'),
257
+				'count'       => 0,
258
+				'bulk_action' => ! isset($this->_req_data['event_id'])
259
+					? array()
260
+					: array(
261
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
+					),
263
+			),
264
+		);
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Set views property for registration_checkins route.
270
-     */
271
-    protected function _set_list_table_views_registration_checkins()
272
-    {
273
-        $this->_views = array(
274
-            'all' => array(
275
-                'slug'        => 'all',
276
-                'label'       => esc_html__('All', 'event_espresso'),
277
-                'count'       => 0,
278
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
-            ),
280
-        );
281
-    }
268
+	/**
269
+	 * Set views property for registration_checkins route.
270
+	 */
271
+	protected function _set_list_table_views_registration_checkins()
272
+	{
273
+		$this->_views = array(
274
+			'all' => array(
275
+				'slug'        => 'all',
276
+				'label'       => esc_html__('All', 'event_espresso'),
277
+				'count'       => 0,
278
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
+			),
280
+		);
281
+	}
282 282
 
283 283
 
284
-    /**
285
-     * callback for ajax action.
286
-     *
287
-     * @since 4.3.0
288
-     * @return void (JSON)
289
-     * @throws EE_Error
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function get_newsletter_form_content()
295
-    {
296
-        // do a nonce check cause we're not coming in from an normal route here.
297
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
-            $this->_req_data['get_newsletter_form_content_nonce']
299
-        ) : '';
300
-        $nonce_ref = 'get_newsletter_form_content_nonce';
301
-        $this->_verify_nonce($nonce, $nonce_ref);
302
-        // let's get the mtp for the incoming MTP_ ID
303
-        if (! isset($this->_req_data['GRP_ID'])) {
304
-            EE_Error::add_error(
305
-                esc_html__(
306
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
-                    'event_espresso'
308
-                ),
309
-                __FILE__,
310
-                __FUNCTION__,
311
-                __LINE__
312
-            );
313
-            $this->_template_args['success'] = false;
314
-            $this->_template_args['error'] = true;
315
-            $this->_return_json();
316
-        }
317
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
-        if (! $MTPG instanceof EE_Message_Template_Group) {
319
-            EE_Error::add_error(
320
-                sprintf(
321
-                    esc_html__(
322
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
-                        'event_espresso'
324
-                    ),
325
-                    $this->_req_data['GRP_ID']
326
-                ),
327
-                __FILE__,
328
-                __FUNCTION__,
329
-                __LINE__
330
-            );
331
-            $this->_template_args['success'] = false;
332
-            $this->_template_args['error'] = true;
333
-            $this->_return_json();
334
-        }
335
-        $MTPs = $MTPG->context_templates();
336
-        $MTPs = $MTPs['attendee'];
337
-        $template_fields = array();
338
-        /** @var EE_Message_Template $MTP */
339
-        foreach ($MTPs as $MTP) {
340
-            $field = $MTP->get('MTP_template_field');
341
-            if ($field === 'content') {
342
-                $content = $MTP->get('MTP_content');
343
-                if (! empty($content['newsletter_content'])) {
344
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
345
-                }
346
-                continue;
347
-            }
348
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
-        }
350
-        $this->_template_args['success'] = true;
351
-        $this->_template_args['error'] = false;
352
-        $this->_template_args['data'] = array(
353
-            'batch_message_from'    => isset($template_fields['from'])
354
-                ? $template_fields['from']
355
-                : '',
356
-            'batch_message_subject' => isset($template_fields['subject'])
357
-                ? $template_fields['subject']
358
-                : '',
359
-            'batch_message_content' => isset($template_fields['newsletter_content'])
360
-                ? $template_fields['newsletter_content']
361
-                : '',
362
-        );
363
-        $this->_return_json();
364
-    }
284
+	/**
285
+	 * callback for ajax action.
286
+	 *
287
+	 * @since 4.3.0
288
+	 * @return void (JSON)
289
+	 * @throws EE_Error
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function get_newsletter_form_content()
295
+	{
296
+		// do a nonce check cause we're not coming in from an normal route here.
297
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
+			$this->_req_data['get_newsletter_form_content_nonce']
299
+		) : '';
300
+		$nonce_ref = 'get_newsletter_form_content_nonce';
301
+		$this->_verify_nonce($nonce, $nonce_ref);
302
+		// let's get the mtp for the incoming MTP_ ID
303
+		if (! isset($this->_req_data['GRP_ID'])) {
304
+			EE_Error::add_error(
305
+				esc_html__(
306
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
+					'event_espresso'
308
+				),
309
+				__FILE__,
310
+				__FUNCTION__,
311
+				__LINE__
312
+			);
313
+			$this->_template_args['success'] = false;
314
+			$this->_template_args['error'] = true;
315
+			$this->_return_json();
316
+		}
317
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
+		if (! $MTPG instanceof EE_Message_Template_Group) {
319
+			EE_Error::add_error(
320
+				sprintf(
321
+					esc_html__(
322
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
+						'event_espresso'
324
+					),
325
+					$this->_req_data['GRP_ID']
326
+				),
327
+				__FILE__,
328
+				__FUNCTION__,
329
+				__LINE__
330
+			);
331
+			$this->_template_args['success'] = false;
332
+			$this->_template_args['error'] = true;
333
+			$this->_return_json();
334
+		}
335
+		$MTPs = $MTPG->context_templates();
336
+		$MTPs = $MTPs['attendee'];
337
+		$template_fields = array();
338
+		/** @var EE_Message_Template $MTP */
339
+		foreach ($MTPs as $MTP) {
340
+			$field = $MTP->get('MTP_template_field');
341
+			if ($field === 'content') {
342
+				$content = $MTP->get('MTP_content');
343
+				if (! empty($content['newsletter_content'])) {
344
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
345
+				}
346
+				continue;
347
+			}
348
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
+		}
350
+		$this->_template_args['success'] = true;
351
+		$this->_template_args['error'] = false;
352
+		$this->_template_args['data'] = array(
353
+			'batch_message_from'    => isset($template_fields['from'])
354
+				? $template_fields['from']
355
+				: '',
356
+			'batch_message_subject' => isset($template_fields['subject'])
357
+				? $template_fields['subject']
358
+				: '',
359
+			'batch_message_content' => isset($template_fields['newsletter_content'])
360
+				? $template_fields['newsletter_content']
361
+				: '',
362
+		);
363
+		$this->_return_json();
364
+	}
365 365
 
366 366
 
367
-    /**
368
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
-     *
370
-     * @since 4.3.0
371
-     * @param EE_Admin_List_Table $list_table
372
-     * @return void
373
-     * @throws InvalidArgumentException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidInterfaceException
376
-     */
377
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
-    {
379
-        if (
380
-            ! EE_Registry::instance()->CAP->current_user_can(
381
-                'ee_send_message',
382
-                'espresso_registrations_newsletter_selected_send'
383
-            )
384
-        ) {
385
-            return;
386
-        }
387
-        $routes_to_add_to = array(
388
-            'contact_list',
389
-            'event_registrations',
390
-            'default',
391
-        );
392
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
393
-            if (
394
-                ($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
395
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
396
-            ) {
397
-                echo '';
398
-            } else {
399
-                $button_text = sprintf(
400
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
401
-                    '<span class="send-selected-newsletter-count">0</span>'
402
-                );
403
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
404
-                     . '<span class="dashicons dashicons-email "></span>'
405
-                     . $button_text
406
-                     . '</button>';
407
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
408
-            }
409
-        }
410
-    }
367
+	/**
368
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
+	 *
370
+	 * @since 4.3.0
371
+	 * @param EE_Admin_List_Table $list_table
372
+	 * @return void
373
+	 * @throws InvalidArgumentException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidInterfaceException
376
+	 */
377
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
+	{
379
+		if (
380
+			! EE_Registry::instance()->CAP->current_user_can(
381
+				'ee_send_message',
382
+				'espresso_registrations_newsletter_selected_send'
383
+			)
384
+		) {
385
+			return;
386
+		}
387
+		$routes_to_add_to = array(
388
+			'contact_list',
389
+			'event_registrations',
390
+			'default',
391
+		);
392
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
393
+			if (
394
+				($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
395
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
396
+			) {
397
+				echo '';
398
+			} else {
399
+				$button_text = sprintf(
400
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
401
+					'<span class="send-selected-newsletter-count">0</span>'
402
+				);
403
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
404
+					 . '<span class="dashicons dashicons-email "></span>'
405
+					 . $button_text
406
+					 . '</button>';
407
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
408
+			}
409
+		}
410
+	}
411 411
 
412 412
 
413
-    /**
414
-     * @throws DomainException
415
-     * @throws EE_Error
416
-     * @throws InvalidArgumentException
417
-     * @throws InvalidDataTypeException
418
-     * @throws InvalidInterfaceException
419
-     */
420
-    public function newsletter_send_form_skeleton()
421
-    {
422
-        $list_table = $this->_list_table_object;
423
-        $codes = array();
424
-        // need to templates for the newsletter message type for the template selector.
425
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
426
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
427
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
428
-        );
429
-        foreach ($mtps as $mtp) {
430
-            $name = $mtp->name();
431
-            $values[] = array(
432
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
433
-                'id'   => $mtp->ID(),
434
-            );
435
-        }
436
-        // need to get a list of shortcodes that are available for the newsletter message type.
437
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
438
-            'newsletter',
439
-            'email',
440
-            array(),
441
-            'attendee',
442
-            false
443
-        );
444
-        foreach ($shortcodes as $field => $shortcode_array) {
445
-            $available_shortcodes = array();
446
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
447
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
448
-                    ? 'content'
449
-                    : $field;
450
-                $field_id = 'batch-message-' . strtolower($field_id);
451
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
452
-                                          . $shortcode
453
-                                          . '" data-linked-input-id="' . $field_id . '">'
454
-                                          . $shortcode
455
-                                          . '</span>';
456
-            }
457
-            $codes[ $field ] = implode(', ', $available_shortcodes);
458
-        }
459
-        $shortcodes = $codes;
460
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
461
-        $form_template_args = array(
462
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
463
-            'form_route'        => 'newsletter_selected_send',
464
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
465
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
466
-            'redirect_back_to'  => $this->_req_action,
467
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
468
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
469
-            'shortcodes'        => $shortcodes,
470
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
471
-        );
472
-        EEH_Template::display_template($form_template, $form_template_args);
473
-    }
413
+	/**
414
+	 * @throws DomainException
415
+	 * @throws EE_Error
416
+	 * @throws InvalidArgumentException
417
+	 * @throws InvalidDataTypeException
418
+	 * @throws InvalidInterfaceException
419
+	 */
420
+	public function newsletter_send_form_skeleton()
421
+	{
422
+		$list_table = $this->_list_table_object;
423
+		$codes = array();
424
+		// need to templates for the newsletter message type for the template selector.
425
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
426
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
427
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
428
+		);
429
+		foreach ($mtps as $mtp) {
430
+			$name = $mtp->name();
431
+			$values[] = array(
432
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
433
+				'id'   => $mtp->ID(),
434
+			);
435
+		}
436
+		// need to get a list of shortcodes that are available for the newsletter message type.
437
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
438
+			'newsletter',
439
+			'email',
440
+			array(),
441
+			'attendee',
442
+			false
443
+		);
444
+		foreach ($shortcodes as $field => $shortcode_array) {
445
+			$available_shortcodes = array();
446
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
447
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
448
+					? 'content'
449
+					: $field;
450
+				$field_id = 'batch-message-' . strtolower($field_id);
451
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
452
+										  . $shortcode
453
+										  . '" data-linked-input-id="' . $field_id . '">'
454
+										  . $shortcode
455
+										  . '</span>';
456
+			}
457
+			$codes[ $field ] = implode(', ', $available_shortcodes);
458
+		}
459
+		$shortcodes = $codes;
460
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
461
+		$form_template_args = array(
462
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
463
+			'form_route'        => 'newsletter_selected_send',
464
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
465
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
466
+			'redirect_back_to'  => $this->_req_action,
467
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
468
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
469
+			'shortcodes'        => $shortcodes,
470
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
471
+		);
472
+		EEH_Template::display_template($form_template, $form_template_args);
473
+	}
474 474
 
475 475
 
476
-    /**
477
-     * Handles sending selected registrations/contacts a newsletter.
478
-     *
479
-     * @since  4.3.0
480
-     * @return void
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     */
486
-    protected function _newsletter_selected_send()
487
-    {
488
-        $success = true;
489
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
490
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
491
-            EE_Error::add_error(
492
-                esc_html__(
493
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
494
-                    'event_espresso'
495
-                ),
496
-                __FILE__,
497
-                __FUNCTION__,
498
-                __LINE__
499
-            );
500
-            $success = false;
501
-        }
502
-        if ($success) {
503
-            // update Message template in case there are any changes
504
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
505
-                $this->_req_data['newsletter_mtp_selected']
506
-            );
507
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
508
-                ? $Message_Template_Group->context_templates()
509
-                : array();
510
-            if (empty($Message_Templates)) {
511
-                EE_Error::add_error(
512
-                    esc_html__(
513
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
514
-                        'event_espresso'
515
-                    ),
516
-                    __FILE__,
517
-                    __FUNCTION__,
518
-                    __LINE__
519
-                );
520
-            }
521
-            // let's just update the specific fields
522
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
523
-                if ($Message_Template instanceof EE_Message_Template) {
524
-                    $field = $Message_Template->get('MTP_template_field');
525
-                    $content = $Message_Template->get('MTP_content');
526
-                    $new_content = $content;
527
-                    switch ($field) {
528
-                        case 'from':
529
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
530
-                                ? $this->_req_data['batch_message']['from']
531
-                                : $content;
532
-                            break;
533
-                        case 'subject':
534
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
535
-                                ? $this->_req_data['batch_message']['subject']
536
-                                : $content;
537
-                            break;
538
-                        case 'content':
539
-                            $new_content = $content;
540
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
541
-                                ? $this->_req_data['batch_message']['content']
542
-                                : $content['newsletter_content'];
543
-                            break;
544
-                        default:
545
-                            // continue the foreach loop, we don't want to set $new_content nor save.
546
-                            continue 2;
547
-                    }
548
-                    $Message_Template->set('MTP_content', $new_content);
549
-                    $Message_Template->save();
550
-                }
551
-            }
552
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
553
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
554
-                ? $this->_req_data['batch_message']['id_type']
555
-                : 'registration';
556
-            // id_type will affect how we assemble the ids.
557
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
558
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
559
-                : array();
560
-            $registrations_used_for_contact_data = array();
561
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
562
-            switch ($id_type) {
563
-                case 'registration':
564
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
565
-                        array(
566
-                            array(
567
-                                'REG_ID' => array('IN', $ids),
568
-                            ),
569
-                        )
570
-                    );
571
-                    break;
572
-                case 'contact':
573
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
574
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
575
-                                                                               $ids
576
-                                                                           );
577
-                    break;
578
-            }
579
-            do_action_ref_array(
580
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
581
-                array(
582
-                    $registrations_used_for_contact_data,
583
-                    $Message_Template_Group->ID(),
584
-                )
585
-            );
586
-            // kept for backward compat, internally we no longer use this action.
587
-            // @deprecated 4.8.36.rc.002
588
-            $contacts = $id_type === 'registration'
589
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
590
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
591
-            do_action_ref_array(
592
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
593
-                array(
594
-                    $contacts,
595
-                    $Message_Template_Group->ID(),
596
-                )
597
-            );
598
-        }
599
-        $query_args = array(
600
-            'action' => ! empty($this->_req_data['redirect_back_to'])
601
-                ? $this->_req_data['redirect_back_to']
602
-                : 'default',
603
-        );
604
-        $this->_redirect_after_action(false, '', '', $query_args, true);
605
-    }
476
+	/**
477
+	 * Handles sending selected registrations/contacts a newsletter.
478
+	 *
479
+	 * @since  4.3.0
480
+	 * @return void
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 */
486
+	protected function _newsletter_selected_send()
487
+	{
488
+		$success = true;
489
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
490
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
491
+			EE_Error::add_error(
492
+				esc_html__(
493
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
494
+					'event_espresso'
495
+				),
496
+				__FILE__,
497
+				__FUNCTION__,
498
+				__LINE__
499
+			);
500
+			$success = false;
501
+		}
502
+		if ($success) {
503
+			// update Message template in case there are any changes
504
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
505
+				$this->_req_data['newsletter_mtp_selected']
506
+			);
507
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
508
+				? $Message_Template_Group->context_templates()
509
+				: array();
510
+			if (empty($Message_Templates)) {
511
+				EE_Error::add_error(
512
+					esc_html__(
513
+						'Unable to retrieve message template fields from the db. Messages not sent.',
514
+						'event_espresso'
515
+					),
516
+					__FILE__,
517
+					__FUNCTION__,
518
+					__LINE__
519
+				);
520
+			}
521
+			// let's just update the specific fields
522
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
523
+				if ($Message_Template instanceof EE_Message_Template) {
524
+					$field = $Message_Template->get('MTP_template_field');
525
+					$content = $Message_Template->get('MTP_content');
526
+					$new_content = $content;
527
+					switch ($field) {
528
+						case 'from':
529
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
530
+								? $this->_req_data['batch_message']['from']
531
+								: $content;
532
+							break;
533
+						case 'subject':
534
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
535
+								? $this->_req_data['batch_message']['subject']
536
+								: $content;
537
+							break;
538
+						case 'content':
539
+							$new_content = $content;
540
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
541
+								? $this->_req_data['batch_message']['content']
542
+								: $content['newsletter_content'];
543
+							break;
544
+						default:
545
+							// continue the foreach loop, we don't want to set $new_content nor save.
546
+							continue 2;
547
+					}
548
+					$Message_Template->set('MTP_content', $new_content);
549
+					$Message_Template->save();
550
+				}
551
+			}
552
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
553
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
554
+				? $this->_req_data['batch_message']['id_type']
555
+				: 'registration';
556
+			// id_type will affect how we assemble the ids.
557
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
558
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
559
+				: array();
560
+			$registrations_used_for_contact_data = array();
561
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
562
+			switch ($id_type) {
563
+				case 'registration':
564
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
565
+						array(
566
+							array(
567
+								'REG_ID' => array('IN', $ids),
568
+							),
569
+						)
570
+					);
571
+					break;
572
+				case 'contact':
573
+					$registrations_used_for_contact_data = EEM_Registration::instance()
574
+																		   ->get_latest_registration_for_each_of_given_contacts(
575
+																			   $ids
576
+																		   );
577
+					break;
578
+			}
579
+			do_action_ref_array(
580
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
581
+				array(
582
+					$registrations_used_for_contact_data,
583
+					$Message_Template_Group->ID(),
584
+				)
585
+			);
586
+			// kept for backward compat, internally we no longer use this action.
587
+			// @deprecated 4.8.36.rc.002
588
+			$contacts = $id_type === 'registration'
589
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
590
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
591
+			do_action_ref_array(
592
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
593
+				array(
594
+					$contacts,
595
+					$Message_Template_Group->ID(),
596
+				)
597
+			);
598
+		}
599
+		$query_args = array(
600
+			'action' => ! empty($this->_req_data['redirect_back_to'])
601
+				? $this->_req_data['redirect_back_to']
602
+				: 'default',
603
+		);
604
+		$this->_redirect_after_action(false, '', '', $query_args, true);
605
+	}
606 606
 
607 607
 
608
-    /**
609
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
610
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
611
-     */
612
-    protected function _registration_reports_js_setup()
613
-    {
614
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
615
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
616
-    }
608
+	/**
609
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
610
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
611
+	 */
612
+	protected function _registration_reports_js_setup()
613
+	{
614
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
615
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
616
+	}
617 617
 
618 618
 
619
-    /**
620
-     *        generates Business Reports regarding Registrations
621
-     *
622
-     * @access protected
623
-     * @return void
624
-     * @throws DomainException
625
-     */
626
-    protected function _registration_reports()
627
-    {
628
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
629
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
630
-            $template_path,
631
-            $this->_reports_template_data,
632
-            true
633
-        );
634
-        // the final template wrapper
635
-        $this->display_admin_page_with_no_sidebar();
636
-    }
619
+	/**
620
+	 *        generates Business Reports regarding Registrations
621
+	 *
622
+	 * @access protected
623
+	 * @return void
624
+	 * @throws DomainException
625
+	 */
626
+	protected function _registration_reports()
627
+	{
628
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
629
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
630
+			$template_path,
631
+			$this->_reports_template_data,
632
+			true
633
+		);
634
+		// the final template wrapper
635
+		$this->display_admin_page_with_no_sidebar();
636
+	}
637 637
 
638 638
 
639
-    /**
640
-     * Generates Business Report showing total registrations per day.
641
-     *
642
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
643
-     * @return string
644
-     * @throws EE_Error
645
-     * @throws InvalidArgumentException
646
-     * @throws InvalidDataTypeException
647
-     * @throws InvalidInterfaceException
648
-     */
649
-    private function _registrations_per_day_report($period = '-1 month')
650
-    {
651
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
652
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
653
-        $results = (array) $results;
654
-        $regs = array();
655
-        $subtitle = '';
656
-        if ($results) {
657
-            $column_titles = array();
658
-            $tracker = 0;
659
-            foreach ($results as $result) {
660
-                $report_column_values = array();
661
-                foreach ($result as $property_name => $property_value) {
662
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
663
-                        : (int) $property_value;
664
-                    $report_column_values[] = $property_value;
665
-                    if ($tracker === 0) {
666
-                        if ($property_name === 'Registration_REG_date') {
667
-                            $column_titles[] = esc_html__(
668
-                                'Date (only days with registrations are shown)',
669
-                                'event_espresso'
670
-                            );
671
-                        } else {
672
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
673
-                        }
674
-                    }
675
-                }
676
-                $tracker++;
677
-                $regs[] = $report_column_values;
678
-            }
679
-            // make sure the column_titles is pushed to the beginning of the array
680
-            array_unshift($regs, $column_titles);
681
-            // setup the date range.
682
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
683
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
684
-            $ending_date = new DateTime("now", $DateTimeZone);
685
-            $subtitle = sprintf(
686
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
687
-                $beginning_date->format('Y-m-d'),
688
-                $ending_date->format('Y-m-d')
689
-            );
690
-        }
691
-        $report_title = esc_html__('Total Registrations per Day', 'event_espresso');
692
-        $report_params = array(
693
-            'title'     => $report_title,
694
-            'subtitle'  => $subtitle,
695
-            'id'        => $report_ID,
696
-            'regs'      => $regs,
697
-            'noResults' => empty($regs),
698
-            'noRegsMsg' => sprintf(
699
-                esc_html__(
700
-                    '%sThere are currently no registration records in the last month for this report.%s',
701
-                    'event_espresso'
702
-                ),
703
-                '<h2>' . $report_title . '</h2><p>',
704
-                '</p>'
705
-            ),
706
-        );
707
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
708
-        return $report_ID;
709
-    }
639
+	/**
640
+	 * Generates Business Report showing total registrations per day.
641
+	 *
642
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
643
+	 * @return string
644
+	 * @throws EE_Error
645
+	 * @throws InvalidArgumentException
646
+	 * @throws InvalidDataTypeException
647
+	 * @throws InvalidInterfaceException
648
+	 */
649
+	private function _registrations_per_day_report($period = '-1 month')
650
+	{
651
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
652
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
653
+		$results = (array) $results;
654
+		$regs = array();
655
+		$subtitle = '';
656
+		if ($results) {
657
+			$column_titles = array();
658
+			$tracker = 0;
659
+			foreach ($results as $result) {
660
+				$report_column_values = array();
661
+				foreach ($result as $property_name => $property_value) {
662
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
663
+						: (int) $property_value;
664
+					$report_column_values[] = $property_value;
665
+					if ($tracker === 0) {
666
+						if ($property_name === 'Registration_REG_date') {
667
+							$column_titles[] = esc_html__(
668
+								'Date (only days with registrations are shown)',
669
+								'event_espresso'
670
+							);
671
+						} else {
672
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
673
+						}
674
+					}
675
+				}
676
+				$tracker++;
677
+				$regs[] = $report_column_values;
678
+			}
679
+			// make sure the column_titles is pushed to the beginning of the array
680
+			array_unshift($regs, $column_titles);
681
+			// setup the date range.
682
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
683
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
684
+			$ending_date = new DateTime("now", $DateTimeZone);
685
+			$subtitle = sprintf(
686
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
687
+				$beginning_date->format('Y-m-d'),
688
+				$ending_date->format('Y-m-d')
689
+			);
690
+		}
691
+		$report_title = esc_html__('Total Registrations per Day', 'event_espresso');
692
+		$report_params = array(
693
+			'title'     => $report_title,
694
+			'subtitle'  => $subtitle,
695
+			'id'        => $report_ID,
696
+			'regs'      => $regs,
697
+			'noResults' => empty($regs),
698
+			'noRegsMsg' => sprintf(
699
+				esc_html__(
700
+					'%sThere are currently no registration records in the last month for this report.%s',
701
+					'event_espresso'
702
+				),
703
+				'<h2>' . $report_title . '</h2><p>',
704
+				'</p>'
705
+			),
706
+		);
707
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
708
+		return $report_ID;
709
+	}
710 710
 
711 711
 
712
-    /**
713
-     * Generates Business Report showing total registrations per event.
714
-     *
715
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
716
-     * @return string
717
-     * @throws EE_Error
718
-     * @throws InvalidArgumentException
719
-     * @throws InvalidDataTypeException
720
-     * @throws InvalidInterfaceException
721
-     */
722
-    private function _registrations_per_event_report($period = '-1 month')
723
-    {
724
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
725
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
726
-        $results = (array) $results;
727
-        $regs = array();
728
-        $subtitle = '';
729
-        if ($results) {
730
-            $column_titles = array();
731
-            $tracker = 0;
732
-            foreach ($results as $result) {
733
-                $report_column_values = array();
734
-                foreach ($result as $property_name => $property_value) {
735
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
736
-                        $property_value,
737
-                        4,
738
-                        '...'
739
-                    ) : (int) $property_value;
740
-                    $report_column_values[] = $property_value;
741
-                    if ($tracker === 0) {
742
-                        if ($property_name === 'Registration_Event') {
743
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
744
-                        } else {
745
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
746
-                        }
747
-                    }
748
-                }
749
-                $tracker++;
750
-                $regs[] = $report_column_values;
751
-            }
752
-            // make sure the column_titles is pushed to the beginning of the array
753
-            array_unshift($regs, $column_titles);
754
-            // setup the date range.
755
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
756
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
757
-            $ending_date = new DateTime("now", $DateTimeZone);
758
-            $subtitle = sprintf(
759
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
760
-                $beginning_date->format('Y-m-d'),
761
-                $ending_date->format('Y-m-d')
762
-            );
763
-        }
764
-        $report_title = esc_html__('Total Registrations per Event', 'event_espresso');
765
-        $report_params = array(
766
-            'title'     => $report_title,
767
-            'subtitle'  => $subtitle,
768
-            'id'        => $report_ID,
769
-            'regs'      => $regs,
770
-            'noResults' => empty($regs),
771
-            'noRegsMsg' => sprintf(
772
-                esc_html__(
773
-                    '%sThere are currently no registration records in the last month for this report.%s',
774
-                    'event_espresso'
775
-                ),
776
-                '<h2>' . $report_title . '</h2><p>',
777
-                '</p>'
778
-            ),
779
-        );
780
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
781
-        return $report_ID;
782
-    }
712
+	/**
713
+	 * Generates Business Report showing total registrations per event.
714
+	 *
715
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
716
+	 * @return string
717
+	 * @throws EE_Error
718
+	 * @throws InvalidArgumentException
719
+	 * @throws InvalidDataTypeException
720
+	 * @throws InvalidInterfaceException
721
+	 */
722
+	private function _registrations_per_event_report($period = '-1 month')
723
+	{
724
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
725
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
726
+		$results = (array) $results;
727
+		$regs = array();
728
+		$subtitle = '';
729
+		if ($results) {
730
+			$column_titles = array();
731
+			$tracker = 0;
732
+			foreach ($results as $result) {
733
+				$report_column_values = array();
734
+				foreach ($result as $property_name => $property_value) {
735
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
736
+						$property_value,
737
+						4,
738
+						'...'
739
+					) : (int) $property_value;
740
+					$report_column_values[] = $property_value;
741
+					if ($tracker === 0) {
742
+						if ($property_name === 'Registration_Event') {
743
+							$column_titles[] = esc_html__('Event', 'event_espresso');
744
+						} else {
745
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
746
+						}
747
+					}
748
+				}
749
+				$tracker++;
750
+				$regs[] = $report_column_values;
751
+			}
752
+			// make sure the column_titles is pushed to the beginning of the array
753
+			array_unshift($regs, $column_titles);
754
+			// setup the date range.
755
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
756
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
757
+			$ending_date = new DateTime("now", $DateTimeZone);
758
+			$subtitle = sprintf(
759
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
760
+				$beginning_date->format('Y-m-d'),
761
+				$ending_date->format('Y-m-d')
762
+			);
763
+		}
764
+		$report_title = esc_html__('Total Registrations per Event', 'event_espresso');
765
+		$report_params = array(
766
+			'title'     => $report_title,
767
+			'subtitle'  => $subtitle,
768
+			'id'        => $report_ID,
769
+			'regs'      => $regs,
770
+			'noResults' => empty($regs),
771
+			'noRegsMsg' => sprintf(
772
+				esc_html__(
773
+					'%sThere are currently no registration records in the last month for this report.%s',
774
+					'event_espresso'
775
+				),
776
+				'<h2>' . $report_title . '</h2><p>',
777
+				'</p>'
778
+			),
779
+		);
780
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
781
+		return $report_ID;
782
+	}
783 783
 
784 784
 
785
-    /**
786
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
787
-     *
788
-     * @access protected
789
-     * @return void
790
-     * @throws EE_Error
791
-     * @throws InvalidArgumentException
792
-     * @throws InvalidDataTypeException
793
-     * @throws InvalidInterfaceException
794
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
795
-     */
796
-    protected function _registration_checkin_list_table()
797
-    {
798
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
-        $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
800
-        /** @var EE_Registration $registration */
801
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
802
-        if (! $registration instanceof EE_Registration) {
803
-            throw new EE_Error(
804
-                sprintf(
805
-                    esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
806
-                    $reg_id
807
-                )
808
-            );
809
-        }
810
-        $attendee = $registration->attendee();
811
-        $this->_admin_page_title .= $this->get_action_link_or_button(
812
-            'new_registration',
813
-            'add-registrant',
814
-            array('event_id' => $registration->event_ID()),
815
-            'add-new-h2'
816
-        );
817
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
818
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
819
-        $legend_items = array(
820
-            'checkin'  => array(
821
-                'class' => $checked_in->cssClasses(),
822
-                'desc'  => $checked_in->legendLabel(),
823
-            ),
824
-            'checkout' => array(
825
-                'class' => $checked_out->cssClasses(),
826
-                'desc'  => $checked_out->legendLabel(),
827
-            ),
828
-        );
829
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
830
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
831
-        /** @var EE_Datetime $datetime */
832
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
833
-        $datetime_label = '';
834
-        if ($datetime instanceof EE_Datetime) {
835
-            $datetime_label = $datetime->get_dtt_display_name(true);
836
-            $datetime_label .= ! empty($datetime_label)
837
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
838
-                : $datetime->get_dtt_display_name();
839
-        }
840
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
841
-            ? EE_Admin_Page::add_query_args_and_nonce(
842
-                array(
843
-                    'action'   => 'event_registrations',
844
-                    'event_id' => $registration->event_ID(),
845
-                    'DTT_ID'   => $dtt_id,
846
-                ),
847
-                $this->_admin_base_url
848
-            )
849
-            : '';
850
-        $datetime_link = ! empty($datetime_link)
851
-            ? '<a href="' . $datetime_link . '">'
852
-              . '<span id="checkin-dtt">'
853
-              . $datetime_label
854
-              . '</span></a>'
855
-            : $datetime_label;
856
-        $attendee_name = $attendee instanceof EE_Attendee
857
-            ? $attendee->full_name()
858
-            : '';
859
-        $attendee_link = $attendee instanceof EE_Attendee
860
-            ? $attendee->get_admin_details_link()
861
-            : '';
862
-        $attendee_link = ! empty($attendee_link)
863
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
864
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
865
-              . '<span id="checkin-attendee-name">'
866
-              . $attendee_name
867
-              . '</span></a>'
868
-            : '';
869
-        $event_link = $registration->event() instanceof EE_Event
870
-            ? $registration->event()->get_admin_details_link()
871
-            : '';
872
-        $event_link = ! empty($event_link)
873
-            ? '<a href="' . $event_link . '"'
874
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
875
-              . '<span id="checkin-event-name">'
876
-              . $registration->event_name()
877
-              . '</span>'
878
-              . '</a>'
879
-            : '';
880
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
881
-            ? '<h2>' . sprintf(
882
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
883
-                $attendee_link,
884
-                $datetime_link,
885
-                $event_link
886
-            ) . '</h2>'
887
-            : '';
888
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
889
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
890
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
891
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
892
-        $this->display_admin_list_table_page_with_no_sidebar();
893
-    }
785
+	/**
786
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
787
+	 *
788
+	 * @access protected
789
+	 * @return void
790
+	 * @throws EE_Error
791
+	 * @throws InvalidArgumentException
792
+	 * @throws InvalidDataTypeException
793
+	 * @throws InvalidInterfaceException
794
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
795
+	 */
796
+	protected function _registration_checkin_list_table()
797
+	{
798
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
+		$reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
800
+		/** @var EE_Registration $registration */
801
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
802
+		if (! $registration instanceof EE_Registration) {
803
+			throw new EE_Error(
804
+				sprintf(
805
+					esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
806
+					$reg_id
807
+				)
808
+			);
809
+		}
810
+		$attendee = $registration->attendee();
811
+		$this->_admin_page_title .= $this->get_action_link_or_button(
812
+			'new_registration',
813
+			'add-registrant',
814
+			array('event_id' => $registration->event_ID()),
815
+			'add-new-h2'
816
+		);
817
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
818
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
819
+		$legend_items = array(
820
+			'checkin'  => array(
821
+				'class' => $checked_in->cssClasses(),
822
+				'desc'  => $checked_in->legendLabel(),
823
+			),
824
+			'checkout' => array(
825
+				'class' => $checked_out->cssClasses(),
826
+				'desc'  => $checked_out->legendLabel(),
827
+			),
828
+		);
829
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
830
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
831
+		/** @var EE_Datetime $datetime */
832
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
833
+		$datetime_label = '';
834
+		if ($datetime instanceof EE_Datetime) {
835
+			$datetime_label = $datetime->get_dtt_display_name(true);
836
+			$datetime_label .= ! empty($datetime_label)
837
+				? ' (' . $datetime->get_dtt_display_name() . ')'
838
+				: $datetime->get_dtt_display_name();
839
+		}
840
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
841
+			? EE_Admin_Page::add_query_args_and_nonce(
842
+				array(
843
+					'action'   => 'event_registrations',
844
+					'event_id' => $registration->event_ID(),
845
+					'DTT_ID'   => $dtt_id,
846
+				),
847
+				$this->_admin_base_url
848
+			)
849
+			: '';
850
+		$datetime_link = ! empty($datetime_link)
851
+			? '<a href="' . $datetime_link . '">'
852
+			  . '<span id="checkin-dtt">'
853
+			  . $datetime_label
854
+			  . '</span></a>'
855
+			: $datetime_label;
856
+		$attendee_name = $attendee instanceof EE_Attendee
857
+			? $attendee->full_name()
858
+			: '';
859
+		$attendee_link = $attendee instanceof EE_Attendee
860
+			? $attendee->get_admin_details_link()
861
+			: '';
862
+		$attendee_link = ! empty($attendee_link)
863
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
864
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
865
+			  . '<span id="checkin-attendee-name">'
866
+			  . $attendee_name
867
+			  . '</span></a>'
868
+			: '';
869
+		$event_link = $registration->event() instanceof EE_Event
870
+			? $registration->event()->get_admin_details_link()
871
+			: '';
872
+		$event_link = ! empty($event_link)
873
+			? '<a href="' . $event_link . '"'
874
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
875
+			  . '<span id="checkin-event-name">'
876
+			  . $registration->event_name()
877
+			  . '</span>'
878
+			  . '</a>'
879
+			: '';
880
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
881
+			? '<h2>' . sprintf(
882
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
883
+				$attendee_link,
884
+				$datetime_link,
885
+				$event_link
886
+			) . '</h2>'
887
+			: '';
888
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
889
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
890
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
891
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
892
+		$this->display_admin_list_table_page_with_no_sidebar();
893
+	}
894 894
 
895 895
 
896
-    /**
897
-     * toggle the Check-in status for the given registration (coming from ajax)
898
-     *
899
-     * @return void (JSON)
900
-     * @throws EE_Error
901
-     * @throws InvalidArgumentException
902
-     * @throws InvalidDataTypeException
903
-     * @throws InvalidInterfaceException
904
-     */
905
-    public function toggle_checkin_status()
906
-    {
907
-        // first make sure we have the necessary data
908
-        if (! isset($this->_req_data['_regid'])) {
909
-            EE_Error::add_error(
910
-                esc_html__(
911
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
912
-                    'event_espresso'
913
-                ),
914
-                __FILE__,
915
-                __FUNCTION__,
916
-                __LINE__
917
-            );
918
-            $this->_template_args['success'] = false;
919
-            $this->_template_args['error'] = true;
920
-            $this->_return_json();
921
-        };
922
-        // do a nonce check cause we're not coming in from an normal route here.
923
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
924
-            : '';
925
-        $nonce_ref = 'checkin_nonce';
926
-        $this->_verify_nonce($nonce, $nonce_ref);
927
-        // beautiful! Made it this far so let's get the status.
928
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
929
-        // setup new class to return via ajax
930
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
931
-        $this->_template_args['success'] = true;
932
-        $this->_return_json();
933
-    }
896
+	/**
897
+	 * toggle the Check-in status for the given registration (coming from ajax)
898
+	 *
899
+	 * @return void (JSON)
900
+	 * @throws EE_Error
901
+	 * @throws InvalidArgumentException
902
+	 * @throws InvalidDataTypeException
903
+	 * @throws InvalidInterfaceException
904
+	 */
905
+	public function toggle_checkin_status()
906
+	{
907
+		// first make sure we have the necessary data
908
+		if (! isset($this->_req_data['_regid'])) {
909
+			EE_Error::add_error(
910
+				esc_html__(
911
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
912
+					'event_espresso'
913
+				),
914
+				__FILE__,
915
+				__FUNCTION__,
916
+				__LINE__
917
+			);
918
+			$this->_template_args['success'] = false;
919
+			$this->_template_args['error'] = true;
920
+			$this->_return_json();
921
+		};
922
+		// do a nonce check cause we're not coming in from an normal route here.
923
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
924
+			: '';
925
+		$nonce_ref = 'checkin_nonce';
926
+		$this->_verify_nonce($nonce, $nonce_ref);
927
+		// beautiful! Made it this far so let's get the status.
928
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
929
+		// setup new class to return via ajax
930
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
931
+		$this->_template_args['success'] = true;
932
+		$this->_return_json();
933
+	}
934 934
 
935 935
 
936
-    /**
937
-     * handles toggling the checkin status for the registration,
938
-     *
939
-     * @access protected
940
-     * @return int|void
941
-     * @throws EE_Error
942
-     * @throws InvalidArgumentException
943
-     * @throws InvalidDataTypeException
944
-     * @throws InvalidInterfaceException
945
-     */
946
-    protected function _toggle_checkin_status()
947
-    {
948
-        // first let's get the query args out of the way for the redirect
949
-        $query_args = array(
950
-            'action'   => 'event_registrations',
951
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
952
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
953
-        );
954
-        $new_status = false;
955
-        // bulk action check in toggle
956
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
957
-            // cycle thru checkboxes
958
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
959
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
960
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
961
-            }
962
-        } elseif (isset($this->_req_data['_regid'])) {
963
-            // coming from ajax request
964
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
965
-            $query_args['DTT_ID'] = $DTT_ID;
966
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
967
-        } else {
968
-            EE_Error::add_error(
969
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
970
-                __FILE__,
971
-                __FUNCTION__,
972
-                __LINE__
973
-            );
974
-        }
975
-        if (defined('DOING_AJAX')) {
976
-            return $new_status;
977
-        }
978
-        $this->_redirect_after_action(false, '', '', $query_args, true);
979
-    }
936
+	/**
937
+	 * handles toggling the checkin status for the registration,
938
+	 *
939
+	 * @access protected
940
+	 * @return int|void
941
+	 * @throws EE_Error
942
+	 * @throws InvalidArgumentException
943
+	 * @throws InvalidDataTypeException
944
+	 * @throws InvalidInterfaceException
945
+	 */
946
+	protected function _toggle_checkin_status()
947
+	{
948
+		// first let's get the query args out of the way for the redirect
949
+		$query_args = array(
950
+			'action'   => 'event_registrations',
951
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
952
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
953
+		);
954
+		$new_status = false;
955
+		// bulk action check in toggle
956
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
957
+			// cycle thru checkboxes
958
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
959
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
960
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
961
+			}
962
+		} elseif (isset($this->_req_data['_regid'])) {
963
+			// coming from ajax request
964
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
965
+			$query_args['DTT_ID'] = $DTT_ID;
966
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
967
+		} else {
968
+			EE_Error::add_error(
969
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
970
+				__FILE__,
971
+				__FUNCTION__,
972
+				__LINE__
973
+			);
974
+		}
975
+		if (defined('DOING_AJAX')) {
976
+			return $new_status;
977
+		}
978
+		$this->_redirect_after_action(false, '', '', $query_args, true);
979
+	}
980 980
 
981 981
 
982
-    /**
983
-     * This is toggles a single Check-in for the given registration and datetime.
984
-     *
985
-     * @param  int $REG_ID The registration we're toggling
986
-     * @param  int $DTT_ID The datetime we're toggling
987
-     * @return int The new status toggled to.
988
-     * @throws EE_Error
989
-     * @throws InvalidArgumentException
990
-     * @throws InvalidDataTypeException
991
-     * @throws InvalidInterfaceException
992
-     */
993
-    private function _toggle_checkin($REG_ID, $DTT_ID)
994
-    {
995
-        /** @var EE_Registration $REG */
996
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
997
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
998
-        if ($new_status !== false) {
999
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1000
-        } else {
1001
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1002
-            $new_status = false;
1003
-        }
1004
-        return $new_status;
1005
-    }
982
+	/**
983
+	 * This is toggles a single Check-in for the given registration and datetime.
984
+	 *
985
+	 * @param  int $REG_ID The registration we're toggling
986
+	 * @param  int $DTT_ID The datetime we're toggling
987
+	 * @return int The new status toggled to.
988
+	 * @throws EE_Error
989
+	 * @throws InvalidArgumentException
990
+	 * @throws InvalidDataTypeException
991
+	 * @throws InvalidInterfaceException
992
+	 */
993
+	private function _toggle_checkin($REG_ID, $DTT_ID)
994
+	{
995
+		/** @var EE_Registration $REG */
996
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
997
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
998
+		if ($new_status !== false) {
999
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1000
+		} else {
1001
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1002
+			$new_status = false;
1003
+		}
1004
+		return $new_status;
1005
+	}
1006 1006
 
1007 1007
 
1008
-    /**
1009
-     * Takes care of deleting multiple EE_Checkin table rows
1010
-     *
1011
-     * @access protected
1012
-     * @return void
1013
-     * @throws EE_Error
1014
-     * @throws InvalidArgumentException
1015
-     * @throws InvalidDataTypeException
1016
-     * @throws InvalidInterfaceException
1017
-     */
1018
-    protected function _delete_checkin_rows()
1019
-    {
1020
-        $query_args = array(
1021
-            'action'  => 'registration_checkins',
1022
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1023
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1024
-        );
1025
-        $errors = 0;
1026
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1027
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1028
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1029
-                    $errors++;
1030
-                }
1031
-            }
1032
-        } else {
1033
-            EE_Error::add_error(
1034
-                esc_html__(
1035
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1036
-                    'event_espresso'
1037
-                ),
1038
-                __FILE__,
1039
-                __FUNCTION__,
1040
-                __LINE__
1041
-            );
1042
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1043
-        }
1044
-        if ($errors > 0) {
1045
-            EE_Error::add_error(
1046
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1047
-                __FILE__,
1048
-                __FUNCTION__,
1049
-                __LINE__
1050
-            );
1051
-        } else {
1052
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1053
-        }
1054
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1055
-    }
1008
+	/**
1009
+	 * Takes care of deleting multiple EE_Checkin table rows
1010
+	 *
1011
+	 * @access protected
1012
+	 * @return void
1013
+	 * @throws EE_Error
1014
+	 * @throws InvalidArgumentException
1015
+	 * @throws InvalidDataTypeException
1016
+	 * @throws InvalidInterfaceException
1017
+	 */
1018
+	protected function _delete_checkin_rows()
1019
+	{
1020
+		$query_args = array(
1021
+			'action'  => 'registration_checkins',
1022
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1023
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1024
+		);
1025
+		$errors = 0;
1026
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1027
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1028
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1029
+					$errors++;
1030
+				}
1031
+			}
1032
+		} else {
1033
+			EE_Error::add_error(
1034
+				esc_html__(
1035
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1036
+					'event_espresso'
1037
+				),
1038
+				__FILE__,
1039
+				__FUNCTION__,
1040
+				__LINE__
1041
+			);
1042
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1043
+		}
1044
+		if ($errors > 0) {
1045
+			EE_Error::add_error(
1046
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1047
+				__FILE__,
1048
+				__FUNCTION__,
1049
+				__LINE__
1050
+			);
1051
+		} else {
1052
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1053
+		}
1054
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1055
+	}
1056 1056
 
1057 1057
 
1058
-    /**
1059
-     * Deletes a single EE_Checkin row
1060
-     *
1061
-     * @return void
1062
-     * @throws EE_Error
1063
-     * @throws InvalidArgumentException
1064
-     * @throws InvalidDataTypeException
1065
-     * @throws InvalidInterfaceException
1066
-     */
1067
-    protected function _delete_checkin_row()
1068
-    {
1069
-        $query_args = array(
1070
-            'action'  => 'registration_checkins',
1071
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1072
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1073
-        );
1074
-        if (! empty($this->_req_data['CHK_ID'])) {
1075
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1076
-                EE_Error::add_error(
1077
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1078
-                    __FILE__,
1079
-                    __FUNCTION__,
1080
-                    __LINE__
1081
-                );
1082
-            } else {
1083
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1084
-            }
1085
-        } else {
1086
-            EE_Error::add_error(
1087
-                esc_html__(
1088
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1089
-                    'event_espresso'
1090
-                ),
1091
-                __FILE__,
1092
-                __FUNCTION__,
1093
-                __LINE__
1094
-            );
1095
-        }
1096
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1097
-    }
1058
+	/**
1059
+	 * Deletes a single EE_Checkin row
1060
+	 *
1061
+	 * @return void
1062
+	 * @throws EE_Error
1063
+	 * @throws InvalidArgumentException
1064
+	 * @throws InvalidDataTypeException
1065
+	 * @throws InvalidInterfaceException
1066
+	 */
1067
+	protected function _delete_checkin_row()
1068
+	{
1069
+		$query_args = array(
1070
+			'action'  => 'registration_checkins',
1071
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1072
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1073
+		);
1074
+		if (! empty($this->_req_data['CHK_ID'])) {
1075
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1076
+				EE_Error::add_error(
1077
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1078
+					__FILE__,
1079
+					__FUNCTION__,
1080
+					__LINE__
1081
+				);
1082
+			} else {
1083
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1084
+			}
1085
+		} else {
1086
+			EE_Error::add_error(
1087
+				esc_html__(
1088
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1089
+					'event_espresso'
1090
+				),
1091
+				__FILE__,
1092
+				__FUNCTION__,
1093
+				__LINE__
1094
+			);
1095
+		}
1096
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1097
+	}
1098 1098
 
1099 1099
 
1100
-    /**
1101
-     *        generates HTML for the Event Registrations List Table
1102
-     *
1103
-     * @access protected
1104
-     * @return void
1105
-     * @throws EE_Error
1106
-     * @throws InvalidArgumentException
1107
-     * @throws InvalidDataTypeException
1108
-     * @throws InvalidInterfaceException
1109
-     */
1110
-    protected function _event_registrations_list_table()
1111
-    {
1112
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1113
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1114
-            ? $this->get_action_link_or_button(
1115
-                'new_registration',
1116
-                'add-registrant',
1117
-                array('event_id' => $this->_req_data['event_id']),
1118
-                'add-new-h2',
1119
-                '',
1120
-                false
1121
-            )
1122
-            : '';
1123
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1124
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1125
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1126
-        $legend_items = array(
1127
-            'star-icon'        => array(
1128
-                'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1129
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1130
-            ),
1131
-            'checkin'          => array(
1132
-                'class' => $checked_in->cssClasses(),
1133
-                'desc'  => $checked_in->legendLabel(),
1134
-            ),
1135
-            'checkout'         => array(
1136
-                'class' => $checked_out->cssClasses(),
1137
-                'desc'  => $checked_out->legendLabel(),
1138
-            ),
1139
-            'nocheckinrecord'  => array(
1140
-                'class' => $checked_never->cssClasses(),
1141
-                'desc'  => $checked_never->legendLabel(),
1142
-            ),
1143
-            'approved_status'  => array(
1144
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1145
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1146
-            ),
1147
-            'cancelled_status' => array(
1148
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1149
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1150
-            ),
1151
-            'declined_status'  => array(
1152
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1153
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1154
-            ),
1155
-            'not_approved'     => array(
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1158
-            ),
1159
-            'pending_status'   => array(
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1162
-            ),
1163
-            'wait_list'        => array(
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1166
-            ),
1167
-        );
1168
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1169
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1170
-        /** @var EE_Event $event */
1171
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1172
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1173
-            ? '<h2>' . sprintf(
1174
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1175
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1176
-            ) . '</h2>'
1177
-            : '';
1178
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1179
-        // the event.
1180
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1181
-        $datetime = null;
1182
-        if ($event instanceof EE_Event) {
1183
-            $datetimes_on_event = $event->datetimes();
1184
-            if (count($datetimes_on_event) === 1) {
1185
-                $datetime = reset($datetimes_on_event);
1186
-            }
1187
-        }
1188
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1189
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1190
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1191
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1192
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1193
-            $this->_template_args['before_list_table'] .= $datetime->name();
1194
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1195
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1196
-        }
1197
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1198
-        // column represents
1199
-        if (! $datetime instanceof EE_Datetime) {
1200
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1201
-                                                          . esc_html__(
1202
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1203
-                                                              'event_espresso'
1204
-                                                          )
1205
-                                                          . '</p>';
1206
-        }
1207
-        $this->display_admin_list_table_page_with_no_sidebar();
1208
-    }
1100
+	/**
1101
+	 *        generates HTML for the Event Registrations List Table
1102
+	 *
1103
+	 * @access protected
1104
+	 * @return void
1105
+	 * @throws EE_Error
1106
+	 * @throws InvalidArgumentException
1107
+	 * @throws InvalidDataTypeException
1108
+	 * @throws InvalidInterfaceException
1109
+	 */
1110
+	protected function _event_registrations_list_table()
1111
+	{
1112
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1113
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1114
+			? $this->get_action_link_or_button(
1115
+				'new_registration',
1116
+				'add-registrant',
1117
+				array('event_id' => $this->_req_data['event_id']),
1118
+				'add-new-h2',
1119
+				'',
1120
+				false
1121
+			)
1122
+			: '';
1123
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1124
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1125
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1126
+		$legend_items = array(
1127
+			'star-icon'        => array(
1128
+				'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1129
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1130
+			),
1131
+			'checkin'          => array(
1132
+				'class' => $checked_in->cssClasses(),
1133
+				'desc'  => $checked_in->legendLabel(),
1134
+			),
1135
+			'checkout'         => array(
1136
+				'class' => $checked_out->cssClasses(),
1137
+				'desc'  => $checked_out->legendLabel(),
1138
+			),
1139
+			'nocheckinrecord'  => array(
1140
+				'class' => $checked_never->cssClasses(),
1141
+				'desc'  => $checked_never->legendLabel(),
1142
+			),
1143
+			'approved_status'  => array(
1144
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1145
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1146
+			),
1147
+			'cancelled_status' => array(
1148
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1149
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1150
+			),
1151
+			'declined_status'  => array(
1152
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1153
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1154
+			),
1155
+			'not_approved'     => array(
1156
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1158
+			),
1159
+			'pending_status'   => array(
1160
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1162
+			),
1163
+			'wait_list'        => array(
1164
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1166
+			),
1167
+		);
1168
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1169
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1170
+		/** @var EE_Event $event */
1171
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1172
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1173
+			? '<h2>' . sprintf(
1174
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1175
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1176
+			) . '</h2>'
1177
+			: '';
1178
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1179
+		// the event.
1180
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1181
+		$datetime = null;
1182
+		if ($event instanceof EE_Event) {
1183
+			$datetimes_on_event = $event->datetimes();
1184
+			if (count($datetimes_on_event) === 1) {
1185
+				$datetime = reset($datetimes_on_event);
1186
+			}
1187
+		}
1188
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1189
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1190
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1191
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1192
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1193
+			$this->_template_args['before_list_table'] .= $datetime->name();
1194
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1195
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1196
+		}
1197
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1198
+		// column represents
1199
+		if (! $datetime instanceof EE_Datetime) {
1200
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1201
+														  . esc_html__(
1202
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1203
+															  'event_espresso'
1204
+														  )
1205
+														  . '</p>';
1206
+		}
1207
+		$this->display_admin_list_table_page_with_no_sidebar();
1208
+	}
1209 1209
 
1210
-    /**
1211
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1212
-     * conditions)
1213
-     *
1214
-     * @return void ends the request by a redirect or download
1215
-     */
1216
-    public function _registrations_checkin_report()
1217
-    {
1218
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1219
-    }
1210
+	/**
1211
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1212
+	 * conditions)
1213
+	 *
1214
+	 * @return void ends the request by a redirect or download
1215
+	 */
1216
+	public function _registrations_checkin_report()
1217
+	{
1218
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1219
+	}
1220 1220
 
1221
-    /**
1222
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1223
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1224
-     *
1225
-     * @param array $request
1226
-     * @param int   $per_page
1227
-     * @param bool  $count
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     */
1231
-    protected function _get_checkin_query_params_from_request(
1232
-        $request,
1233
-        $per_page = 10,
1234
-        $count = false
1235
-    ) {
1236
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1237
-        // unlike the regular registrations list table,
1238
-        $status_ids_array = apply_filters(
1239
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1240
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1241
-        );
1242
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1243
-        return $query_params;
1244
-    }
1221
+	/**
1222
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1223
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1224
+	 *
1225
+	 * @param array $request
1226
+	 * @param int   $per_page
1227
+	 * @param bool  $count
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 */
1231
+	protected function _get_checkin_query_params_from_request(
1232
+		$request,
1233
+		$per_page = 10,
1234
+		$count = false
1235
+	) {
1236
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1237
+		// unlike the regular registrations list table,
1238
+		$status_ids_array = apply_filters(
1239
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1240
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1241
+		);
1242
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1243
+		return $query_params;
1244
+	}
1245 1245
 
1246 1246
 
1247
-    /**
1248
-     * Gets registrations for an event
1249
-     *
1250
-     * @param int    $per_page
1251
-     * @param bool   $count whether to return count or data.
1252
-     * @param bool   $trash
1253
-     * @param string $orderby
1254
-     * @return EE_Registration[]|int
1255
-     * @throws EE_Error
1256
-     * @throws InvalidArgumentException
1257
-     * @throws InvalidDataTypeException
1258
-     * @throws InvalidInterfaceException
1259
-     */
1260
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1261
-    {
1262
-        // normalize some request params that get setup by the parent `get_registrations` method.
1263
-        $request = $this->_req_data;
1264
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1265
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1266
-        if ($trash) {
1267
-            $request['status'] = 'trash';
1268
-        }
1269
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1270
-        /**
1271
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1272
-         *
1273
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1274
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1275
-         *                             or if you have the development copy of EE you can view this at the path:
1276
-         *                             /docs/G--Model-System/model-query-params.md
1277
-         */
1278
-        $query_params['group_by'] = '';
1247
+	/**
1248
+	 * Gets registrations for an event
1249
+	 *
1250
+	 * @param int    $per_page
1251
+	 * @param bool   $count whether to return count or data.
1252
+	 * @param bool   $trash
1253
+	 * @param string $orderby
1254
+	 * @return EE_Registration[]|int
1255
+	 * @throws EE_Error
1256
+	 * @throws InvalidArgumentException
1257
+	 * @throws InvalidDataTypeException
1258
+	 * @throws InvalidInterfaceException
1259
+	 */
1260
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1261
+	{
1262
+		// normalize some request params that get setup by the parent `get_registrations` method.
1263
+		$request = $this->_req_data;
1264
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1265
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1266
+		if ($trash) {
1267
+			$request['status'] = 'trash';
1268
+		}
1269
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1270
+		/**
1271
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1272
+		 *
1273
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1274
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1275
+		 *                             or if you have the development copy of EE you can view this at the path:
1276
+		 *                             /docs/G--Model-System/model-query-params.md
1277
+		 */
1278
+		$query_params['group_by'] = '';
1279 1279
 
1280
-        return $count
1281
-            ? EEM_Registration::instance()->count($query_params)
1282
-            /** @type EE_Registration[] */
1283
-            : EEM_Registration::instance()->get_all($query_params);
1284
-    }
1280
+		return $count
1281
+			? EEM_Registration::instance()->count($query_params)
1282
+			/** @type EE_Registration[] */
1283
+			: EEM_Registration::instance()->get_all($query_params);
1284
+	}
1285 1285
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
     public function __construct($routing = true)
33 33
     {
34 34
         parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
35
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
36
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
37
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
38
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
39 39
         }
40 40
     }
41 41
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
             // enqueue newsletter js
187 187
             wp_enqueue_script(
188 188
                 'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
190 190
                 array('ee-dialog'),
191 191
                 EVENT_ESPRESSO_VERSION,
192 192
                 true
193 193
             );
194 194
             wp_enqueue_style(
195 195
                 'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
197 197
                 array(),
198 198
                 EVENT_ESPRESSO_VERSION
199 199
             );
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     {
215 215
         wp_register_script(
216 216
             'ee-reg-reports-js',
217
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
218 218
             array('google-charts'),
219 219
             EVENT_ESPRESSO_VERSION,
220 220
             true
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         $nonce_ref = 'get_newsletter_form_content_nonce';
301 301
         $this->_verify_nonce($nonce, $nonce_ref);
302 302
         // let's get the mtp for the incoming MTP_ ID
303
-        if (! isset($this->_req_data['GRP_ID'])) {
303
+        if ( ! isset($this->_req_data['GRP_ID'])) {
304 304
             EE_Error::add_error(
305 305
                 esc_html__(
306 306
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             $this->_return_json();
316 316
         }
317 317
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
-        if (! $MTPG instanceof EE_Message_Template_Group) {
318
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
319 319
             EE_Error::add_error(
320 320
                 sprintf(
321 321
                     esc_html__(
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
             $field = $MTP->get('MTP_template_field');
341 341
             if ($field === 'content') {
342 342
                 $content = $MTP->get('MTP_content');
343
-                if (! empty($content['newsletter_content'])) {
343
+                if ( ! empty($content['newsletter_content'])) {
344 344
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
345 345
                 }
346 346
                 continue;
347 347
             }
348
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
+            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
349 349
         }
350 350
         $this->_template_args['success'] = true;
351 351
         $this->_template_args['error'] = false;
@@ -447,17 +447,17 @@  discard block
 block discarded – undo
447 447
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
448 448
                     ? 'content'
449 449
                     : $field;
450
-                $field_id = 'batch-message-' . strtolower($field_id);
450
+                $field_id = 'batch-message-'.strtolower($field_id);
451 451
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
452 452
                                           . $shortcode
453
-                                          . '" data-linked-input-id="' . $field_id . '">'
453
+                                          . '" data-linked-input-id="'.$field_id.'">'
454 454
                                           . $shortcode
455 455
                                           . '</span>';
456 456
             }
457
-            $codes[ $field ] = implode(', ', $available_shortcodes);
457
+            $codes[$field] = implode(', ', $available_shortcodes);
458 458
         }
459 459
         $shortcodes = $codes;
460
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
460
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
461 461
         $form_template_args = array(
462 462
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
463 463
             'form_route'        => 'newsletter_selected_send',
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
      */
626 626
     protected function _registration_reports()
627 627
     {
628
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
628
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
629 629
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
630 630
             $template_path,
631 631
             $this->_reports_template_data,
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
             array_unshift($regs, $column_titles);
681 681
             // setup the date range.
682 682
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
683
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
683
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
684 684
             $ending_date = new DateTime("now", $DateTimeZone);
685 685
             $subtitle = sprintf(
686 686
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
                     '%sThere are currently no registration records in the last month for this report.%s',
701 701
                     'event_espresso'
702 702
                 ),
703
-                '<h2>' . $report_title . '</h2><p>',
703
+                '<h2>'.$report_title.'</h2><p>',
704 704
                 '</p>'
705 705
             ),
706 706
         );
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
             array_unshift($regs, $column_titles);
754 754
             // setup the date range.
755 755
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
756
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
756
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
757 757
             $ending_date = new DateTime("now", $DateTimeZone);
758 758
             $subtitle = sprintf(
759 759
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
                     '%sThere are currently no registration records in the last month for this report.%s',
774 774
                     'event_espresso'
775 775
                 ),
776
-                '<h2>' . $report_title . '</h2><p>',
776
+                '<h2>'.$report_title.'</h2><p>',
777 777
                 '</p>'
778 778
             ),
779 779
         );
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
         $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
800 800
         /** @var EE_Registration $registration */
801 801
         $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
802
-        if (! $registration instanceof EE_Registration) {
802
+        if ( ! $registration instanceof EE_Registration) {
803 803
             throw new EE_Error(
804 804
                 sprintf(
805 805
                     esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
         if ($datetime instanceof EE_Datetime) {
835 835
             $datetime_label = $datetime->get_dtt_display_name(true);
836 836
             $datetime_label .= ! empty($datetime_label)
837
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
837
+                ? ' ('.$datetime->get_dtt_display_name().')'
838 838
                 : $datetime->get_dtt_display_name();
839 839
         }
840 840
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
             )
849 849
             : '';
850 850
         $datetime_link = ! empty($datetime_link)
851
-            ? '<a href="' . $datetime_link . '">'
851
+            ? '<a href="'.$datetime_link.'">'
852 852
               . '<span id="checkin-dtt">'
853 853
               . $datetime_label
854 854
               . '</span></a>'
@@ -860,8 +860,8 @@  discard block
 block discarded – undo
860 860
             ? $attendee->get_admin_details_link()
861 861
             : '';
862 862
         $attendee_link = ! empty($attendee_link)
863
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
864
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
863
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
864
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
865 865
               . '<span id="checkin-attendee-name">'
866 866
               . $attendee_name
867 867
               . '</span></a>'
@@ -870,25 +870,25 @@  discard block
 block discarded – undo
870 870
             ? $registration->event()->get_admin_details_link()
871 871
             : '';
872 872
         $event_link = ! empty($event_link)
873
-            ? '<a href="' . $event_link . '"'
874
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
873
+            ? '<a href="'.$event_link.'"'
874
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
875 875
               . '<span id="checkin-event-name">'
876 876
               . $registration->event_name()
877 877
               . '</span>'
878 878
               . '</a>'
879 879
             : '';
880 880
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
881
-            ? '<h2>' . sprintf(
881
+            ? '<h2>'.sprintf(
882 882
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
883 883
                 $attendee_link,
884 884
                 $datetime_link,
885 885
                 $event_link
886
-            ) . '</h2>'
886
+            ).'</h2>'
887 887
             : '';
888 888
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
889
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
889
+            ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : '';
890 890
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
891
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
891
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
892 892
         $this->display_admin_list_table_page_with_no_sidebar();
893 893
     }
894 894
 
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
     public function toggle_checkin_status()
906 906
     {
907 907
         // first make sure we have the necessary data
908
-        if (! isset($this->_req_data['_regid'])) {
908
+        if ( ! isset($this->_req_data['_regid'])) {
909 909
             EE_Error::add_error(
910 910
                 esc_html__(
911 911
                     'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
         // beautiful! Made it this far so let's get the status.
928 928
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
929 929
         // setup new class to return via ajax
930
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
930
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
931 931
         $this->_template_args['success'] = true;
932 932
         $this->_return_json();
933 933
     }
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
         );
954 954
         $new_status = false;
955 955
         // bulk action check in toggle
956
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
956
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
957 957
             // cycle thru checkboxes
958 958
             while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
959 959
                 $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1024 1024
         );
1025 1025
         $errors = 0;
1026
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1026
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1027 1027
             while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1028
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1028
+                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1029 1029
                     $errors++;
1030 1030
                 }
1031 1031
             }
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
             'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1072 1072
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1073 1073
         );
1074
-        if (! empty($this->_req_data['CHK_ID'])) {
1075
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1074
+        if ( ! empty($this->_req_data['CHK_ID'])) {
1075
+            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1076 1076
                 EE_Error::add_error(
1077 1077
                     esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1078 1078
                     __FILE__,
@@ -1141,27 +1141,27 @@  discard block
 block discarded – undo
1141 1141
                 'desc'  => $checked_never->legendLabel(),
1142 1142
             ),
1143 1143
             'approved_status'  => array(
1144
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1144
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1145 1145
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1146 1146
             ),
1147 1147
             'cancelled_status' => array(
1148
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1148
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1149 1149
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1150 1150
             ),
1151 1151
             'declined_status'  => array(
1152
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1152
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1153 1153
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1154 1154
             ),
1155 1155
             'not_approved'     => array(
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1156
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1157 1157
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1158 1158
             ),
1159 1159
             'pending_status'   => array(
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1160
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1161 1161
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1162 1162
             ),
1163 1163
             'wait_list'        => array(
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1164
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1165 1165
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1166 1166
             ),
1167 1167
         );
@@ -1170,10 +1170,10 @@  discard block
 block discarded – undo
1170 1170
         /** @var EE_Event $event */
1171 1171
         $event = EEM_Event::instance()->get_one_by_ID($event_id);
1172 1172
         $this->_template_args['before_list_table'] = $event instanceof EE_Event
1173
-            ? '<h2>' . sprintf(
1173
+            ? '<h2>'.sprintf(
1174 1174
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1175 1175
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1176
-            ) . '</h2>'
1176
+            ).'</h2>'
1177 1177
             : '';
1178 1178
         // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1179 1179
         // the event.
@@ -1191,12 +1191,12 @@  discard block
 block discarded – undo
1191 1191
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1192 1192
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1193 1193
             $this->_template_args['before_list_table'] .= $datetime->name();
1194
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1194
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1195 1195
             $this->_template_args['before_list_table'] .= '</span></h2>';
1196 1196
         }
1197 1197
         // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1198 1198
         // column represents
1199
-        if (! $datetime instanceof EE_Datetime) {
1199
+        if ( ! $datetime instanceof EE_Datetime) {
1200 1200
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1201 1201
                                                           . esc_html__(
1202 1202
                                                               'In this view, the check-in status represents the latest check-in record for the registration in that row.',
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Button_Display_Strategy.strategy.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -12,32 +12,32 @@
 block discarded – undo
12 12
 class EE_Button_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @return string of html to display the input
17
-     */
18
-    public function display()
19
-    {
20
-        $default_value = $this->_input->get_default();
21
-        if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
-            $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
-        }
24
-        $html = $this->_opening_tag('button');
25
-        $html .= $this->_attributes_string(
26
-            array_merge(
27
-                $this->_standard_attributes_array(),
28
-                array(
29
-                    'value' => $default_value,
30
-                )
31
-            )
32
-        );
33
-        if ($this->_input instanceof EE_Button_Input) {
34
-            $button_content = $this->_input->button_content();
35
-        } else {
36
-            $button_content = $this->_input->get_default();
37
-        }
38
-        $html .= '>';
39
-        $html .= $button_content;
40
-        $html .= $this->_closing_tag();
41
-        return $html;
42
-    }
15
+	/**
16
+	 * @return string of html to display the input
17
+	 */
18
+	public function display()
19
+	{
20
+		$default_value = $this->_input->get_default();
21
+		if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) {
22
+			$default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value);
23
+		}
24
+		$html = $this->_opening_tag('button');
25
+		$html .= $this->_attributes_string(
26
+			array_merge(
27
+				$this->_standard_attributes_array(),
28
+				array(
29
+					'value' => $default_value,
30
+				)
31
+			)
32
+		);
33
+		if ($this->_input instanceof EE_Button_Input) {
34
+			$button_content = $this->_input->button_content();
35
+		} else {
36
+			$button_content = $this->_input->get_default();
37
+		}
38
+		$html .= '>';
39
+		$html .= $button_content;
40
+		$html .= $this->_closing_tag();
41
+		return $html;
42
+	}
43 43
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 
122 122
 
123 123
     /**
124
-     * @return Version
124
+     * @return string
125 125
      */
126 126
     public function versionValueObject()
127 127
     {
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,231 +17,231 @@
 block discarded – undo
17 17
 abstract class DomainBase implements DomainInterface
18 18
 {
19 19
 
20
-    const ASSETS_FOLDER = 'assets/';
21
-
22
-    /**
23
-     * Equivalent to `__FILE__` for main plugin file.
24
-     *
25
-     * @var FilePath
26
-     */
27
-    private $plugin_file;
28
-
29
-    /**
30
-     * String indicating version for plugin
31
-     *
32
-     * @var string
33
-     */
34
-    private $version;
35
-
36
-    /**
37
-     * @var string $plugin_basename
38
-     */
39
-    private $plugin_basename;
40
-
41
-    /**
42
-     * @var string $plugin_path
43
-     */
44
-    private $plugin_path;
45
-
46
-    /**
47
-     * @var string $plugin_url
48
-     */
49
-    private $plugin_url;
50
-
51
-    /**
52
-     * @var string $asset_namespace
53
-     */
54
-    private $asset_namespace;
55
-
56
-    /**
57
-     * @var string $assets_path
58
-     */
59
-    private $assets_path;
60
-
61
-    /**
62
-     * @var bool
63
-     */
64
-    protected $initialized = false;
65
-
66
-
67
-    /**
68
-     * Initializes internal properties.
69
-     *
70
-     * @param FilePath $plugin_file
71
-     * @param Version  $version
72
-     * @param string $asset_namespace
73
-     */
74
-    public function __construct(
75
-        FilePath $plugin_file,
76
-        Version $version,
77
-        string $asset_namespace = Domain::ASSET_NAMESPACE
78
-    ) {
79
-        $this->plugin_file = $plugin_file;
80
-        $this->version     = $version;
81
-        $this->initialize($asset_namespace);
82
-    }
83
-
84
-
85
-    /**
86
-     * @param string $asset_namespace
87
-     * @return void
88
-     * @since $VID:$
89
-     */
90
-    public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91
-    {
92
-        if (! $this->initialized) {
93
-            $this->plugin_basename = plugin_basename($this->pluginFile());
94
-            $this->plugin_path     = plugin_dir_path($this->pluginFile());
95
-            $this->plugin_url      = plugin_dir_url($this->pluginFile());
96
-            $this->setAssetNamespace($asset_namespace);
97
-            $this->setDistributionAssetsPath();
98
-            $this->initialized = true;
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * @param string $asset_namespace
105
-     * @return void
106
-     */
107
-    public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108
-    {
109
-        if (! $this->asset_namespace) {
110
-            $this->asset_namespace = sanitize_key(
111
-                // convert directory separators to dashes and remove file extension
112
-                str_replace(['/', '.php'], ['-', ''], $asset_namespace)
113
-            );
114
-        }
115
-    }
116
-
117
-
118
-    /**
119
-     * @throws DomainException
120
-     * @since $VID:$
121
-     */
122
-    private function setDistributionAssetsPath()
123
-    {
124
-        $assets_folder_paths = [
125
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
126
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
127
-        ];
128
-        foreach ($assets_folder_paths as $assets_folder_path) {
129
-            if (is_readable($assets_folder_path)) {
130
-                $this->assets_path = trailingslashit($assets_folder_path);
131
-                // once we find a valid path, just break out of loop
132
-                break;
133
-            }
134
-        }
135
-    }
136
-
137
-
138
-    /**
139
-     * @return string
140
-     */
141
-    public function pluginFile(): string
142
-    {
143
-        return (string) $this->plugin_file;
144
-    }
145
-
146
-
147
-    /**
148
-     * @return FilePath
149
-     */
150
-    public function pluginFileObject(): FilePath
151
-    {
152
-        return $this->plugin_file;
153
-    }
154
-
155
-
156
-    /**
157
-     * @return string
158
-     */
159
-    public function pluginBasename(): string
160
-    {
161
-        return $this->plugin_basename;
162
-    }
163
-
164
-
165
-    /**
166
-     * @param string $additional_path
167
-     * @return string
168
-     */
169
-    public function pluginPath($additional_path = ''): string
170
-    {
171
-        return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_path . $additional_path
173
-            : $this->plugin_path;
174
-    }
175
-
176
-
177
-    /**
178
-     * @param string $additional_path
179
-     * @return string
180
-     */
181
-    public function pluginUrl($additional_path = ''): string
182
-    {
183
-        return is_string($additional_path) && $additional_path !== ''
184
-            ? $this->plugin_url . $additional_path
185
-            : $this->plugin_url;
186
-    }
187
-
188
-
189
-    /**
190
-     * @return string
191
-     */
192
-    public function version(): string
193
-    {
194
-        return (string) $this->version;
195
-    }
196
-
197
-
198
-    /**
199
-     * @return Version
200
-     */
201
-    public function versionValueObject()
202
-    {
203
-        return $this->version;
204
-    }
205
-
206
-
207
-    /**
208
-     * @return string
209
-     */
210
-    public function distributionAssetsFolder(): string
211
-    {
212
-        return DomainBase::ASSETS_FOLDER;
213
-    }
214
-
215
-
216
-    /**
217
-     * @param string $additional_path
218
-     * @return string
219
-     */
220
-    public function distributionAssetsPath($additional_path = ''): string
221
-    {
222
-        return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->assets_path . $additional_path
224
-            : $this->assets_path;
225
-    }
226
-
227
-
228
-    /**
229
-     * @param string $additional_path
230
-     * @return string
231
-     */
232
-    public function distributionAssetsUrl($additional_path = ''): string
233
-    {
234
-        return is_string($additional_path) && $additional_path !== ''
235
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
237
-    }
238
-
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    public function assetNamespace(): string
244
-    {
245
-        return $this->asset_namespace;
246
-    }
20
+	const ASSETS_FOLDER = 'assets/';
21
+
22
+	/**
23
+	 * Equivalent to `__FILE__` for main plugin file.
24
+	 *
25
+	 * @var FilePath
26
+	 */
27
+	private $plugin_file;
28
+
29
+	/**
30
+	 * String indicating version for plugin
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $version;
35
+
36
+	/**
37
+	 * @var string $plugin_basename
38
+	 */
39
+	private $plugin_basename;
40
+
41
+	/**
42
+	 * @var string $plugin_path
43
+	 */
44
+	private $plugin_path;
45
+
46
+	/**
47
+	 * @var string $plugin_url
48
+	 */
49
+	private $plugin_url;
50
+
51
+	/**
52
+	 * @var string $asset_namespace
53
+	 */
54
+	private $asset_namespace;
55
+
56
+	/**
57
+	 * @var string $assets_path
58
+	 */
59
+	private $assets_path;
60
+
61
+	/**
62
+	 * @var bool
63
+	 */
64
+	protected $initialized = false;
65
+
66
+
67
+	/**
68
+	 * Initializes internal properties.
69
+	 *
70
+	 * @param FilePath $plugin_file
71
+	 * @param Version  $version
72
+	 * @param string $asset_namespace
73
+	 */
74
+	public function __construct(
75
+		FilePath $plugin_file,
76
+		Version $version,
77
+		string $asset_namespace = Domain::ASSET_NAMESPACE
78
+	) {
79
+		$this->plugin_file = $plugin_file;
80
+		$this->version     = $version;
81
+		$this->initialize($asset_namespace);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param string $asset_namespace
87
+	 * @return void
88
+	 * @since $VID:$
89
+	 */
90
+	public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91
+	{
92
+		if (! $this->initialized) {
93
+			$this->plugin_basename = plugin_basename($this->pluginFile());
94
+			$this->plugin_path     = plugin_dir_path($this->pluginFile());
95
+			$this->plugin_url      = plugin_dir_url($this->pluginFile());
96
+			$this->setAssetNamespace($asset_namespace);
97
+			$this->setDistributionAssetsPath();
98
+			$this->initialized = true;
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param string $asset_namespace
105
+	 * @return void
106
+	 */
107
+	public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108
+	{
109
+		if (! $this->asset_namespace) {
110
+			$this->asset_namespace = sanitize_key(
111
+				// convert directory separators to dashes and remove file extension
112
+				str_replace(['/', '.php'], ['-', ''], $asset_namespace)
113
+			);
114
+		}
115
+	}
116
+
117
+
118
+	/**
119
+	 * @throws DomainException
120
+	 * @since $VID:$
121
+	 */
122
+	private function setDistributionAssetsPath()
123
+	{
124
+		$assets_folder_paths = [
125
+			$this->plugin_path . DomainBase::ASSETS_FOLDER,
126
+			$this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
127
+		];
128
+		foreach ($assets_folder_paths as $assets_folder_path) {
129
+			if (is_readable($assets_folder_path)) {
130
+				$this->assets_path = trailingslashit($assets_folder_path);
131
+				// once we find a valid path, just break out of loop
132
+				break;
133
+			}
134
+		}
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return string
140
+	 */
141
+	public function pluginFile(): string
142
+	{
143
+		return (string) $this->plugin_file;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @return FilePath
149
+	 */
150
+	public function pluginFileObject(): FilePath
151
+	{
152
+		return $this->plugin_file;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @return string
158
+	 */
159
+	public function pluginBasename(): string
160
+	{
161
+		return $this->plugin_basename;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param string $additional_path
167
+	 * @return string
168
+	 */
169
+	public function pluginPath($additional_path = ''): string
170
+	{
171
+		return is_string($additional_path) && $additional_path !== ''
172
+			? $this->plugin_path . $additional_path
173
+			: $this->plugin_path;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @param string $additional_path
179
+	 * @return string
180
+	 */
181
+	public function pluginUrl($additional_path = ''): string
182
+	{
183
+		return is_string($additional_path) && $additional_path !== ''
184
+			? $this->plugin_url . $additional_path
185
+			: $this->plugin_url;
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return string
191
+	 */
192
+	public function version(): string
193
+	{
194
+		return (string) $this->version;
195
+	}
196
+
197
+
198
+	/**
199
+	 * @return Version
200
+	 */
201
+	public function versionValueObject()
202
+	{
203
+		return $this->version;
204
+	}
205
+
206
+
207
+	/**
208
+	 * @return string
209
+	 */
210
+	public function distributionAssetsFolder(): string
211
+	{
212
+		return DomainBase::ASSETS_FOLDER;
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param string $additional_path
218
+	 * @return string
219
+	 */
220
+	public function distributionAssetsPath($additional_path = ''): string
221
+	{
222
+		return is_string($additional_path) && $additional_path !== ''
223
+			? $this->assets_path . $additional_path
224
+			: $this->assets_path;
225
+	}
226
+
227
+
228
+	/**
229
+	 * @param string $additional_path
230
+	 * @return string
231
+	 */
232
+	public function distributionAssetsUrl($additional_path = ''): string
233
+	{
234
+		return is_string($additional_path) && $additional_path !== ''
235
+			? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
+			: $this->plugin_url . DomainBase::ASSETS_FOLDER;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	public function assetNamespace(): string
244
+	{
245
+		return $this->asset_namespace;
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
91 91
     {
92
-        if (! $this->initialized) {
92
+        if ( ! $this->initialized) {
93 93
             $this->plugin_basename = plugin_basename($this->pluginFile());
94 94
             $this->plugin_path     = plugin_dir_path($this->pluginFile());
95 95
             $this->plugin_url      = plugin_dir_url($this->pluginFile());
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
108 108
     {
109
-        if (! $this->asset_namespace) {
109
+        if ( ! $this->asset_namespace) {
110 110
             $this->asset_namespace = sanitize_key(
111 111
                 // convert directory separators to dashes and remove file extension
112 112
                 str_replace(['/', '.php'], ['-', ''], $asset_namespace)
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
     private function setDistributionAssetsPath()
123 123
     {
124 124
         $assets_folder_paths = [
125
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
126
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
125
+            $this->plugin_path.DomainBase::ASSETS_FOLDER,
126
+            $this->plugin_path.'src/'.DomainBase::ASSETS_FOLDER,
127 127
         ];
128 128
         foreach ($assets_folder_paths as $assets_folder_path) {
129 129
             if (is_readable($assets_folder_path)) {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     public function pluginPath($additional_path = ''): string
170 170
     {
171 171
         return is_string($additional_path) && $additional_path !== ''
172
-            ? $this->plugin_path . $additional_path
172
+            ? $this->plugin_path.$additional_path
173 173
             : $this->plugin_path;
174 174
     }
175 175
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     public function pluginUrl($additional_path = ''): string
182 182
     {
183 183
         return is_string($additional_path) && $additional_path !== ''
184
-            ? $this->plugin_url . $additional_path
184
+            ? $this->plugin_url.$additional_path
185 185
             : $this->plugin_url;
186 186
     }
187 187
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     public function distributionAssetsPath($additional_path = ''): string
221 221
     {
222 222
         return is_string($additional_path) && $additional_path !== ''
223
-            ? $this->assets_path . $additional_path
223
+            ? $this->assets_path.$additional_path
224 224
             : $this->assets_path;
225 225
     }
226 226
 
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
     public function distributionAssetsUrl($additional_path = ''): string
233 233
     {
234 234
         return is_string($additional_path) && $additional_path !== ''
235
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
236
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
235
+            ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path
236
+            : $this->plugin_url.DomainBase::ASSETS_FOLDER;
237 237
     }
238 238
 
239 239
 
Please login to merge, or discard this patch.
core/domain/entities/contexts/RequestTypeContext.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     public function __construct($slug, $description)
92 92
     {
93 93
         parent::__construct($slug, $description);
94
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
94
+        if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) {
95 95
             throw new InvalidArgumentException(
96 96
                 sprintf(
97 97
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -16,185 +16,185 @@
 block discarded – undo
16 16
 class RequestTypeContext extends Context
17 17
 {
18 18
 
19
-    /**
20
-     * indicates that the current request involves some form of activation
21
-     */
22
-    const ACTIVATION = 'activation-request';
23
-
24
-    /**
25
-     * indicates that the current request is for the admin but is not being made via AJAX
26
-     */
27
-    const ADMIN = 'non-ajax-admin-request';
28
-
29
-    /**
30
-     * indicates that the current request is for the admin AND is being made via AJAX
31
-     */
32
-    const AJAX_ADMIN = 'admin-ajax-request';
33
-
34
-    /**
35
-     * indicates that the current request is for the frontend AND is being made via AJAX
36
-     */
37
-    const AJAX_FRONT = 'frontend-ajax-request';
38
-
39
-    /**
40
-     * indicates that the current request is for the WP Heartbeat
41
-     */
42
-    const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
-
44
-    /**
45
-     * indicates that the current request is being made via AJAX, but is NOT for EE
46
-     */
47
-    const AJAX_OTHER = 'other-ajax-request';
48
-
49
-    /**
50
-     * indicates that the current request is for the EE REST API
51
-     */
52
-    const API = 'rest-api';
53
-
54
-    /**
55
-     * indicates that the current request is from the command line
56
-     */
57
-    const CLI = 'command-line';
58
-
59
-    /**
60
-     * indicates that the current request is for a WP_Cron
61
-     */
62
-    const CRON = 'wp-cron';
63
-
64
-    /**
65
-     * indicates that the current request is for a feed (ie: RSS)
66
-     */
67
-    const FEED = 'feed-request';
68
-
69
-    /**
70
-     * indicates that the current request is for the frontend but is not being made via AJAX
71
-     */
72
-    const FRONTEND = 'non-ajax-frontend-request';
73
-
74
-    /**
75
-     * indicates that the current request is for content that is to be displayed within an iframe
76
-     */
77
-    const IFRAME = 'iframe-request';
78
-
79
-    /**
80
-     * indicates that the current request is for the EE GraphQL manager
81
-     */
82
-    const GQL = 'graphql';
83
-
84
-    /**
85
-     * indicates that the current request is for the WP REST API
86
-     */
87
-    const WP_API = 'wp-rest-api';
88
-
89
-    /**
90
-     * indicates that the current request is a loopback sent from WP core to test for errors
91
-     */
92
-    const WP_SCRAPE = 'wordpress-scrape';
93
-
94
-    /**
95
-     * @var boolean $is_activation
96
-     */
97
-    private $is_activation = false;
98
-
99
-    /**
100
-     * @var boolean $is_unit_testing
101
-     */
102
-    private $is_unit_testing = false;
103
-
104
-    /**
105
-     * @var array $valid_request_types
106
-     */
107
-    private $valid_request_types = array();
108
-
109
-
110
-    /**
111
-     * RequestTypeContext constructor.
112
-     *
113
-     * @param string $slug
114
-     * @param string $description
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function __construct($slug, $description)
118
-    {
119
-        parent::__construct($slug, $description);
120
-        if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
-            throw new InvalidArgumentException(
122
-                sprintf(
123
-                    esc_html__(
124
-                        'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
-                        'event_espresso'
126
-                    ),
127
-                    '<br />',
128
-                    var_export($this->validRequestTypes(), true)
129
-                )
130
-            );
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function validRequestTypes()
139
-    {
140
-        if (empty($this->valid_request_types)) {
141
-            $this->valid_request_types = apply_filters(
142
-                'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
-                array(
144
-                    RequestTypeContext::ACTIVATION,
145
-                    RequestTypeContext::ADMIN,
146
-                    RequestTypeContext::AJAX_ADMIN,
147
-                    RequestTypeContext::AJAX_FRONT,
148
-                    RequestTypeContext::AJAX_HEARTBEAT,
149
-                    RequestTypeContext::AJAX_OTHER,
150
-                    RequestTypeContext::API,
151
-                    RequestTypeContext::CLI,
152
-                    RequestTypeContext::CRON,
153
-                    RequestTypeContext::FEED,
154
-                    RequestTypeContext::FRONTEND,
155
-                    RequestTypeContext::GQL,
156
-                    RequestTypeContext::IFRAME,
157
-                    RequestTypeContext::WP_API,
158
-                    RequestTypeContext::WP_SCRAPE,
159
-                )
160
-            );
161
-        }
162
-        return $this->valid_request_types;
163
-    }
164
-
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    public function isActivation()
170
-    {
171
-        return $this->is_activation;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param bool $is_activation
177
-     */
178
-    public function setIsActivation($is_activation = false)
179
-    {
180
-        $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-    /**
185
-     * @return bool
186
-     */
187
-    public function isUnitTesting()
188
-    {
189
-        return $this->is_unit_testing;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param bool $is_unit_testing
195
-     */
196
-    public function setIsUnitTesting($is_unit_testing = false)
197
-    {
198
-        $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
-    }
19
+	/**
20
+	 * indicates that the current request involves some form of activation
21
+	 */
22
+	const ACTIVATION = 'activation-request';
23
+
24
+	/**
25
+	 * indicates that the current request is for the admin but is not being made via AJAX
26
+	 */
27
+	const ADMIN = 'non-ajax-admin-request';
28
+
29
+	/**
30
+	 * indicates that the current request is for the admin AND is being made via AJAX
31
+	 */
32
+	const AJAX_ADMIN = 'admin-ajax-request';
33
+
34
+	/**
35
+	 * indicates that the current request is for the frontend AND is being made via AJAX
36
+	 */
37
+	const AJAX_FRONT = 'frontend-ajax-request';
38
+
39
+	/**
40
+	 * indicates that the current request is for the WP Heartbeat
41
+	 */
42
+	const AJAX_HEARTBEAT = 'admin-ajax-heartbeat';
43
+
44
+	/**
45
+	 * indicates that the current request is being made via AJAX, but is NOT for EE
46
+	 */
47
+	const AJAX_OTHER = 'other-ajax-request';
48
+
49
+	/**
50
+	 * indicates that the current request is for the EE REST API
51
+	 */
52
+	const API = 'rest-api';
53
+
54
+	/**
55
+	 * indicates that the current request is from the command line
56
+	 */
57
+	const CLI = 'command-line';
58
+
59
+	/**
60
+	 * indicates that the current request is for a WP_Cron
61
+	 */
62
+	const CRON = 'wp-cron';
63
+
64
+	/**
65
+	 * indicates that the current request is for a feed (ie: RSS)
66
+	 */
67
+	const FEED = 'feed-request';
68
+
69
+	/**
70
+	 * indicates that the current request is for the frontend but is not being made via AJAX
71
+	 */
72
+	const FRONTEND = 'non-ajax-frontend-request';
73
+
74
+	/**
75
+	 * indicates that the current request is for content that is to be displayed within an iframe
76
+	 */
77
+	const IFRAME = 'iframe-request';
78
+
79
+	/**
80
+	 * indicates that the current request is for the EE GraphQL manager
81
+	 */
82
+	const GQL = 'graphql';
83
+
84
+	/**
85
+	 * indicates that the current request is for the WP REST API
86
+	 */
87
+	const WP_API = 'wp-rest-api';
88
+
89
+	/**
90
+	 * indicates that the current request is a loopback sent from WP core to test for errors
91
+	 */
92
+	const WP_SCRAPE = 'wordpress-scrape';
93
+
94
+	/**
95
+	 * @var boolean $is_activation
96
+	 */
97
+	private $is_activation = false;
98
+
99
+	/**
100
+	 * @var boolean $is_unit_testing
101
+	 */
102
+	private $is_unit_testing = false;
103
+
104
+	/**
105
+	 * @var array $valid_request_types
106
+	 */
107
+	private $valid_request_types = array();
108
+
109
+
110
+	/**
111
+	 * RequestTypeContext constructor.
112
+	 *
113
+	 * @param string $slug
114
+	 * @param string $description
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function __construct($slug, $description)
118
+	{
119
+		parent::__construct($slug, $description);
120
+		if (! in_array($this->slug(), $this->validRequestTypes(), true)) {
121
+			throw new InvalidArgumentException(
122
+				sprintf(
123
+					esc_html__(
124
+						'The RequestTypeContext slug must be one of the following values: %1$s %2$s',
125
+						'event_espresso'
126
+					),
127
+					'<br />',
128
+					var_export($this->validRequestTypes(), true)
129
+				)
130
+			);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function validRequestTypes()
139
+	{
140
+		if (empty($this->valid_request_types)) {
141
+			$this->valid_request_types = apply_filters(
142
+				'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes',
143
+				array(
144
+					RequestTypeContext::ACTIVATION,
145
+					RequestTypeContext::ADMIN,
146
+					RequestTypeContext::AJAX_ADMIN,
147
+					RequestTypeContext::AJAX_FRONT,
148
+					RequestTypeContext::AJAX_HEARTBEAT,
149
+					RequestTypeContext::AJAX_OTHER,
150
+					RequestTypeContext::API,
151
+					RequestTypeContext::CLI,
152
+					RequestTypeContext::CRON,
153
+					RequestTypeContext::FEED,
154
+					RequestTypeContext::FRONTEND,
155
+					RequestTypeContext::GQL,
156
+					RequestTypeContext::IFRAME,
157
+					RequestTypeContext::WP_API,
158
+					RequestTypeContext::WP_SCRAPE,
159
+				)
160
+			);
161
+		}
162
+		return $this->valid_request_types;
163
+	}
164
+
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	public function isActivation()
170
+	{
171
+		return $this->is_activation;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param bool $is_activation
177
+	 */
178
+	public function setIsActivation($is_activation = false)
179
+	{
180
+		$this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return bool
186
+	 */
187
+	public function isUnitTesting()
188
+	{
189
+		return $this->is_unit_testing;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param bool $is_unit_testing
195
+	 */
196
+	public function setIsUnitTesting($is_unit_testing = false)
197
+	{
198
+		$this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
core/libraries/messages/validators/EE_Messages_Validator.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -505,7 +505,7 @@
 block discarded – undo
505 505
      *
506 506
      * @param  string $value            string to evaluate
507 507
      * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
508
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
+     * @return false|string (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
509 509
      */
510 510
     protected function _invalid_shortcodes($value, $valid_shortcodes)
511 511
     {
Please login to merge, or discard this patch.
Indentation   +624 added lines, -624 removed lines patch added patch discarded remove patch
@@ -17,628 +17,628 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
-     * These are used for retrieving objects etc.
23
-     *
24
-     * @var string
25
-     */
26
-    protected $_m_name;
27
-    protected $_mt_name;
28
-
29
-
30
-    /**
31
-     * This will hold any error messages from the validation process.
32
-     * The _errors property holds an associative array of error messages
33
-     * listing the field as the key and the message as the value.
34
-     *
35
-     * @var array()
36
-     */
37
-    private $_errors = array();
38
-
39
-
40
-    /**
41
-     * holds an array of fields being validated
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_fields;
46
-
47
-
48
-    /**
49
-     * this will hold the incoming context
50
-     *
51
-     * @var string
52
-     */
53
-    protected $_context;
54
-
55
-
56
-    /**
57
-     * this holds an array of fields and the relevant validation information
58
-     * that the incoming fields data get validated against.
59
-     * This gets setup in the _set_props() method.
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_validators;
64
-
65
-
66
-    /**
67
-     * holds the messenger object
68
-     *
69
-     * @var object
70
-     */
71
-    protected $_messenger;
72
-
73
-
74
-    /**
75
-     * holds the message type object
76
-     *
77
-     * @var object
78
-     */
79
-    protected $_message_type;
80
-
81
-
82
-    /**
83
-     * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
-     *
85
-     * @var array
86
-     */
87
-    protected $_valid_shortcodes_modifier;
88
-
89
-
90
-    /**
91
-     * There may be times where a message type wants to include a shortcode group but exclude specific
92
-     * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
-     * they will not be allowed.
94
-     * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_specific_shortcode_excludes = array();
99
-
100
-
101
-    /**
102
-     * Runs the validator using the incoming fields array as the fields/values to check.
103
-     *
104
-     * @param array $fields The fields sent by the EEM object.
105
-     * @param       $context
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public function __construct($fields, $context)
110
-    {
111
-        // check that _m_name and _mt_name have been set by child class otherwise we get out.
112
-        if (empty($this->_m_name) || empty($this->_mt_name)) {
113
-            throw new EE_Error(
114
-                esc_html__(
115
-                    'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
-                    'event_espresso'
117
-                )
118
-            );
119
-        }
120
-        $this->_fields  = $fields;
121
-        $this->_context = $context;
122
-
123
-        // load messenger and message_type objects and the related shortcode objects.
124
-        $this->_load_objects();
125
-
126
-
127
-        // modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
-        $this->_modify_validator();
129
-
130
-
131
-        // let's set validators property
132
-        $this->_set_validators();
133
-    }
134
-
135
-
136
-    /**
137
-     * Child classes instantiate this and use it to modify the _validator_config array property
138
-     * for the messenger using messengers set_validate_config() method.
139
-     * This is so we can specify specific validation instructions for a messenger/message_type combo
140
-     * that aren't handled by the defaults setup in the messenger.
141
-     *
142
-     * @abstract
143
-     * @access protected
144
-     * @return void
145
-     */
146
-    abstract protected function _modify_validator();
147
-
148
-
149
-    /**
150
-     * loads all objects used by validator
151
-     *
152
-     * @access private
153
-     * @throws \EE_Error
154
-     */
155
-    private function _load_objects()
156
-    {
157
-        // load messenger
158
-        $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
-        $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
161
-
162
-        if (! class_exists($messenger)) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
-                    $this->_m_name
167
-                )
168
-            );
169
-        }
170
-
171
-        $this->_messenger = new $messenger();
172
-
173
-        // load message type
174
-        $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
-        $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
177
-
178
-        if (! class_exists($message_type)) {
179
-            throw new EE_Error(
180
-                sprintf(
181
-                    esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
-                    $this->_mt_name
183
-                )
184
-            );
185
-        }
186
-
187
-        $this->_message_type = new $message_type();
188
-    }
189
-
190
-
191
-    /**
192
-     * used to set the $_validators property
193
-     *
194
-     * @access private
195
-     * @return void
196
-     * @throws ReflectionException
197
-     */
198
-    private function _set_validators()
199
-    {
200
-        // let's get all valid shortcodes from mt and message type
201
-        // (messenger will have its set in the _validator_config property for the messenger)
202
-        $mt_codes = $this->_message_type->get_valid_shortcodes();
203
-
204
-
205
-        // get messenger validator_config
206
-        $msgr_validator = $this->_messenger->get_validator_config();
207
-
208
-
209
-        // we only want the valid shortcodes for the given context!
210
-        $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
212
-
213
-        // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
-        // into a single array (so we can get the appropriate shortcode objects for the groups)
215
-        $shortcode_groups = $mt_codes;
216
-        $groups_per_field = array();
217
-
218
-        foreach ($msgr_validator as $field => $config) {
219
-            if (empty($config) || ! isset($config['shortcodes'])) {
220
-                continue;
221
-            }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
-        }
225
-
226
-        $shortcode_groups = array_unique($shortcode_groups);
227
-
228
-        // okay now we've got our groups.
229
-        // Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
-        $codes_from_objs = array();
231
-
232
-        foreach ($shortcode_groups as $group) {
233
-            $ref       = ucwords(str_replace('_', ' ', $group));
234
-            $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
236
-            if (class_exists($classname)) {
237
-                $a                       = new ReflectionClass($classname);
238
-                $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
240
-            }
241
-        }
242
-
243
-
244
-        // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
-        $final_mt_codes = array();
246
-        foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
-        }
249
-
250
-        $mt_codes = $final_mt_codes;
251
-
252
-
253
-        // k now in this next loop we're going to loop through $msgr_validator again
254
-        // and setup the _validators property from the data we've setup so far.
255
-        foreach ($msgr_validator as $field => $config) {
256
-            // if required shortcode is not in our list of codes for the given field, then we skip this field.
257
-            $required = isset($config['required'])
258
-                ? array_intersect($config['required'], array_keys($mt_codes))
259
-                : true;
260
-            if (empty($required)) {
261
-                continue;
262
-            }
263
-
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
-                // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
268
-                    $codes_from_objs
269
-                );
270
-            } elseif (isset($groups_per_field[ $field ])) {
271
-                // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
274
-                    $codes_from_objs
275
-                );
276
-            } elseif (empty($config)) {
277
-                // if empty config then we're assuming we're just going to use the shortcodes from the message type
278
-                // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
-            } elseif (isset($config['specific_shortcodes'])) {
281
-                // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
-            } else {
284
-                // otherwise the shortcodes are what is set by the messenger for that field
285
-                foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
289
-                }
290
-            }
291
-
292
-            // now let's just make sure that any excluded specific shortcodes are removed.
293
-            $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
-                    }
299
-                }
300
-            }
301
-
302
-            // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * This just returns the validators property that contains information
310
-     * about the various shortcodes and their availability with each field
311
-     *
312
-     * @return array
313
-     */
314
-    public function get_validators()
315
-    {
316
-        return $this->_validators;
317
-    }
318
-
319
-
320
-    /**
321
-     * This simply returns the specific shortcode_excludes property that is set.
322
-     *
323
-     * @since 4.5.0
324
-     * @return array
325
-     */
326
-    public function get_specific_shortcode_excludes()
327
-    {
328
-        // specific validator filter
329
-        $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
-            $this->_specific_shortcode_excludes,
332
-            $this->_context
333
-        );
334
-        // global filter
335
-        return apply_filters(
336
-            'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
-            $shortcode_excludes,
338
-            $this->_context,
339
-            $this
340
-        );
341
-    }
342
-
343
-
344
-    /**
345
-     * This is the main method that handles validation
346
-     * What it does is loop through the _fields (the ones that get validated)
347
-     * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
-     *
349
-     * @access public
350
-     * @return mixed (bool|array)  if errors present we return the array otherwise true
351
-     */
352
-    public function validate()
353
-    {
354
-        // some defaults
355
-        $template_fields = $this->_messenger->get_template_fields();
356
-        // loop through the fields and check!
357
-        foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
359
-            $err_msg               = '';
360
-            $field_label           = '';
361
-            // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
364
-                continue;
365
-            }
366
-
367
-            // get the translated field label!
368
-            // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
371
-                    $field_label = $field;
372
-                } else {
373
-                    // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
375
-                }
376
-            }
377
-
378
-            // if field label is empty OR is equal to the current field
379
-            // then we need to loop through the 'extra' fields in the template_fields config (if present)
380
-            if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
-                foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
-                    foreach ($secondary_field as $name => $values) {
383
-                        if ($name === $field) {
384
-                            $field_label = $values['label'];
385
-                        }
386
-
387
-                        // if we've got a 'main' secondary field, let's see if that matches what field we're on
388
-                        // which means it contains the label for this field.
389
-                        if ($name === 'main' && $main_field === $field_label) {
390
-                            $field_label = $values['label'];
391
-                        }
392
-                    }
393
-                }
394
-            }
395
-
396
-            // field is present. Let's validate shortcodes first (but only if shortcodes present).
397
-            if (
398
-                isset($this->_validators[ $field ]['shortcodes'])
399
-                && ! empty($this->_validators[ $field ]['shortcodes'])
400
-            ) {
401
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
402
-                // if true then that means there is a returned error message
403
-                // that we'll need to add to the _errors array for this field.
404
-                if ($invalid_shortcodes) {
405
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
406
-                    $err_msg = sprintf(
407
-                        esc_html__(
408
-                            '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409
-                            'event_espresso'
410
-                        ),
411
-                        '<strong>' . $field_label . '</strong>',
412
-                        $invalid_shortcodes,
413
-                        '<p>',
414
-                        '</p >'
415
-                    );
416
-                    $err_msg .= sprintf(
417
-                        esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
418
-                        implode(', ', $v_s),
419
-                        '<strong>',
420
-                        '</strong>'
421
-                    );
422
-                }
423
-            }
424
-
425
-            // if there's a "type" to be validated then let's do that too.
426
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
-                switch ($this->_validators[ $field ]['type']) {
428
-                    case 'number':
429
-                        if (! is_numeric($value)) {
430
-                            $err_msg .= sprintf(
431
-                                esc_html__(
432
-                                    '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
433
-                                    'event_espresso'
434
-                                ),
435
-                                $field_label,
436
-                                $value,
437
-                                '<p>',
438
-                                '</p >'
439
-                            );
440
-                        }
441
-                        break;
442
-                    case 'email':
443
-                        $valid_email = $this->_validate_email($value);
444
-                        if (! $valid_email) {
445
-                            $err_msg .= htmlentities(
446
-                                sprintf(
447
-                                    esc_html__(
448
-                                        'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
449
-                                        'event_espresso'
450
-                                    ),
451
-                                    $field_label
452
-                                )
453
-                            );
454
-                        }
455
-                        break;
456
-                    default:
457
-                        break;
458
-                }
459
-            }
460
-
461
-            // if $err_msg isn't empty let's setup the _errors array for this field.
462
-            if (! empty($err_msg)) {
463
-                $this->_errors[ $field ]['msg'] = $err_msg;
464
-            } else {
465
-                unset($this->_errors[ $field ]);
466
-            }
467
-        }
468
-
469
-        // if we have ANY errors, then we want to make sure we return the values
470
-        // for ALL the fields so the user doesn't have to retype them all.
471
-        if (! empty($this->_errors)) {
472
-            foreach ($this->_fields as $field => $value) {
473
-                $this->_errors[ $field ]['value'] = stripslashes($value);
474
-            }
475
-        }
476
-
477
-        // return any errors or just TRUE if everything validates
478
-        return empty($this->_errors) ? true : $this->_errors;
479
-    }
480
-
481
-
482
-    /**
483
-     * Reassembles and returns an array of valid shortcodes
484
-     * given the array of groups and array of shortcodes indexed by group.
485
-     *
486
-     * @param  array $groups          array of shortcode groups that we want shortcodes for
487
-     * @param  array $codes_from_objs All the codes available.
488
-     * @return array                   an array of actual shortcodes (that will be used for validation).
489
-     */
490
-    private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
491
-    {
492
-        $shortcodes = array();
493
-        foreach ($groups as $group) {
494
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
495
-        }
496
-        return $shortcodes;
497
-    }
498
-
499
-
500
-    /**
501
-     * Validates a string against a list of accepted shortcodes
502
-     * This function takes in an array of shortcodes
503
-     * and makes sure that the given string ONLY contains shortcodes in that array.
504
-     *
505
-     * @param  string $value            string to evaluate
506
-     * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
507
-     * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
-     */
509
-    protected function _invalid_shortcodes($value, $valid_shortcodes)
510
-    {
511
-        // first we need to go through the string and get the shortcodes in the string
512
-        preg_match_all('/(\[.+?\])/', $value, $matches);
513
-        $incoming_shortcodes = (array) $matches[0];
514
-
515
-        // get a diff of the shortcodes in the string vs the valid shortcodes
516
-        $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
517
-
518
-        // we need to account for custom codes so let's loop through the diff and remove any of those type of codes
519
-        foreach ($diff as $ind => $code) {
520
-            if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
521
-                // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522
-                $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523
-                // does this exist in the $valid_shortcodes?  If so then unset.
524
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
-                    unset($diff[ $ind ]);
526
-                }
527
-            }
528
-        }
529
-
530
-        if (empty($diff)) {
531
-            return false;
532
-        } //there is no diff, we have no invalid shortcodes, so return
533
-
534
-        // made it here? then let's assemble the error message
535
-        $invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
537
-        return $invalid_shortcodes;
538
-    }
539
-
540
-
541
-    /**
542
-     * Validates an incoming string and makes sure we have valid emails in the string.
543
-     *
544
-     * @param  string $value incoming value to validate
545
-     * @return bool        true if the string validates, false if it doesn't
546
-     */
547
-    protected function _validate_email($value)
548
-    {
549
-        $validate = true;
550
-        $or_val   = $value;
551
-
552
-        // empty strings will validate because this is how a message template
553
-        // for a particular context can be "turned off" (if there is no email then no message)
554
-        if (empty($value)) {
555
-            return $validate;
556
-        }
557
-
558
-        // first determine if there ARE any shortcodes.
559
-        // If there are shortcodes and then later we find that there were no other valid emails
560
-        // but the field isn't empty...
561
-        // that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
562
-        $has_shortcodes = preg_match('/(\[.+?\])/', $value);
563
-
564
-        // first we need to strip out all the shortcodes!
565
-        $value = preg_replace('/(\[.+?\])/', '', $value);
566
-
567
-        // if original value is not empty and new value is, then we've parsed out a shortcode
568
-        // and we now have an empty string which DOES validate.
569
-        // We also validate complete empty field for email because
570
-        // its possible that this message is being "turned off" for a particular context
571
-
572
-
573
-        if (! empty($or_val) && empty($value)) {
574
-            return $validate;
575
-        }
576
-
577
-        // trim any commas from beginning and end of string ( after whitespace trimmed );
578
-        $value = trim(trim($value), ',');
579
-
580
-
581
-        // next we need to split up the string if its comma delimited.
582
-        $emails = explode(',', $value);
583
-        $empty  = false; // used to indicate that there is an empty comma.
584
-        // now let's loop through the emails and do our checks
585
-        foreach ($emails as $email) {
586
-            if (empty($email)) {
587
-                $empty = true;
588
-                continue;
589
-            }
590
-
591
-            // trim whitespace
592
-            $email = trim($email);
593
-            // either its of type "[email protected]", or its of type "fname lname <[email protected]>"
594
-            if (is_email($email)) {
595
-                continue;
596
-            }
597
-            $matches  = array();
598
-            $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
599
-            if ($validate && is_email($matches[2])) {
600
-                continue;
601
-            }
602
-            return false;
603
-        }
604
-
605
-        $validate = $empty && ! $has_shortcodes ? false : $validate;
606
-
607
-        return $validate;
608
-    }
609
-
610
-
611
-    /**
612
-     * Magic getter
613
-     * Using this to provide back compat with add-ons referencing deprecated properties.
614
-     *
615
-     * @param string $property Property being requested
616
-     * @throws Exception
617
-     * @return mixed
618
-     */
619
-    public function __get($property)
620
-    {
621
-        $expected_properties_map = array(
622
-            /**
623
-             * @deprecated 4.9.0
624
-             */
625
-            '_MSGR'   => '_messenger',
626
-            /**
627
-             * @deprecated 4.9.0
628
-             */
629
-            '_MSGTYP' => '_message_type',
630
-        );
631
-
632
-        if (isset($expected_properties_map[ $property ])) {
633
-            return $this->{$expected_properties_map[ $property ]};
634
-        }
635
-
636
-        throw new Exception(
637
-            sprintf(
638
-                esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
639
-                $property,
640
-                get_class($this)
641
-            )
642
-        );
643
-    }
20
+	/**
21
+	 * These properties just hold the name for the Messenger and Message Type (defined by child classes).
22
+	 * These are used for retrieving objects etc.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	protected $_m_name;
27
+	protected $_mt_name;
28
+
29
+
30
+	/**
31
+	 * This will hold any error messages from the validation process.
32
+	 * The _errors property holds an associative array of error messages
33
+	 * listing the field as the key and the message as the value.
34
+	 *
35
+	 * @var array()
36
+	 */
37
+	private $_errors = array();
38
+
39
+
40
+	/**
41
+	 * holds an array of fields being validated
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_fields;
46
+
47
+
48
+	/**
49
+	 * this will hold the incoming context
50
+	 *
51
+	 * @var string
52
+	 */
53
+	protected $_context;
54
+
55
+
56
+	/**
57
+	 * this holds an array of fields and the relevant validation information
58
+	 * that the incoming fields data get validated against.
59
+	 * This gets setup in the _set_props() method.
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_validators;
64
+
65
+
66
+	/**
67
+	 * holds the messenger object
68
+	 *
69
+	 * @var object
70
+	 */
71
+	protected $_messenger;
72
+
73
+
74
+	/**
75
+	 * holds the message type object
76
+	 *
77
+	 * @var object
78
+	 */
79
+	protected $_message_type;
80
+
81
+
82
+	/**
83
+	 * will hold any valid_shortcode modifications made by the _modify_validator() method.
84
+	 *
85
+	 * @var array
86
+	 */
87
+	protected $_valid_shortcodes_modifier;
88
+
89
+
90
+	/**
91
+	 * There may be times where a message type wants to include a shortcode group but exclude specific
92
+	 * shortcodes.  If that's the case then it can set this property as an array of shortcodes to exclude and
93
+	 * they will not be allowed.
94
+	 * Array should be indexed by field and values are an array of specific shortcodes to exclude.
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_specific_shortcode_excludes = array();
99
+
100
+
101
+	/**
102
+	 * Runs the validator using the incoming fields array as the fields/values to check.
103
+	 *
104
+	 * @param array $fields The fields sent by the EEM object.
105
+	 * @param       $context
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function __construct($fields, $context)
110
+	{
111
+		// check that _m_name and _mt_name have been set by child class otherwise we get out.
112
+		if (empty($this->_m_name) || empty($this->_mt_name)) {
113
+			throw new EE_Error(
114
+				esc_html__(
115
+					'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property.  Check that the child class is doing this',
116
+					'event_espresso'
117
+				)
118
+			);
119
+		}
120
+		$this->_fields  = $fields;
121
+		$this->_context = $context;
122
+
123
+		// load messenger and message_type objects and the related shortcode objects.
124
+		$this->_load_objects();
125
+
126
+
127
+		// modify any messenger/message_type specific validation instructions.  This is what child classes define.
128
+		$this->_modify_validator();
129
+
130
+
131
+		// let's set validators property
132
+		$this->_set_validators();
133
+	}
134
+
135
+
136
+	/**
137
+	 * Child classes instantiate this and use it to modify the _validator_config array property
138
+	 * for the messenger using messengers set_validate_config() method.
139
+	 * This is so we can specify specific validation instructions for a messenger/message_type combo
140
+	 * that aren't handled by the defaults setup in the messenger.
141
+	 *
142
+	 * @abstract
143
+	 * @access protected
144
+	 * @return void
145
+	 */
146
+	abstract protected function _modify_validator();
147
+
148
+
149
+	/**
150
+	 * loads all objects used by validator
151
+	 *
152
+	 * @access private
153
+	 * @throws \EE_Error
154
+	 */
155
+	private function _load_objects()
156
+	{
157
+		// load messenger
158
+		$messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159
+		$messenger = str_replace(' ', '_', $messenger);
160
+		$messenger = 'EE_' . $messenger . '_messenger';
161
+
162
+		if (! class_exists($messenger)) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
166
+					$this->_m_name
167
+				)
168
+			);
169
+		}
170
+
171
+		$this->_messenger = new $messenger();
172
+
173
+		// load message type
174
+		$message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175
+		$message_type = str_replace(' ', '_', $message_type);
176
+		$message_type = 'EE_' . $message_type . '_message_type';
177
+
178
+		if (! class_exists($message_type)) {
179
+			throw new EE_Error(
180
+				sprintf(
181
+					esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
182
+					$this->_mt_name
183
+				)
184
+			);
185
+		}
186
+
187
+		$this->_message_type = new $message_type();
188
+	}
189
+
190
+
191
+	/**
192
+	 * used to set the $_validators property
193
+	 *
194
+	 * @access private
195
+	 * @return void
196
+	 * @throws ReflectionException
197
+	 */
198
+	private function _set_validators()
199
+	{
200
+		// let's get all valid shortcodes from mt and message type
201
+		// (messenger will have its set in the _validator_config property for the messenger)
202
+		$mt_codes = $this->_message_type->get_valid_shortcodes();
203
+
204
+
205
+		// get messenger validator_config
206
+		$msgr_validator = $this->_messenger->get_validator_config();
207
+
208
+
209
+		// we only want the valid shortcodes for the given context!
210
+		$context  = $this->_context;
211
+		$mt_codes = $mt_codes[ $context ];
212
+
213
+		// in this first loop we're just getting all shortcode group indexes from the msgr_validator
214
+		// into a single array (so we can get the appropriate shortcode objects for the groups)
215
+		$shortcode_groups = $mt_codes;
216
+		$groups_per_field = array();
217
+
218
+		foreach ($msgr_validator as $field => $config) {
219
+			if (empty($config) || ! isset($config['shortcodes'])) {
220
+				continue;
221
+			}  //Nothing to see here.
222
+			$groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
+			$shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
224
+		}
225
+
226
+		$shortcode_groups = array_unique($shortcode_groups);
227
+
228
+		// okay now we've got our groups.
229
+		// Let's get the codes from the objects into an array indexed by group for easy retrieval later.
230
+		$codes_from_objs = array();
231
+
232
+		foreach ($shortcode_groups as $group) {
233
+			$ref       = ucwords(str_replace('_', ' ', $group));
234
+			$ref       = str_replace(' ', '_', $ref);
235
+			$classname = 'EE_' . $ref . '_Shortcodes';
236
+			if (class_exists($classname)) {
237
+				$a                       = new ReflectionClass($classname);
238
+				$obj                     = $a->newInstance();
239
+				$codes_from_objs[ $group ] = $obj->get_shortcodes();
240
+			}
241
+		}
242
+
243
+
244
+		// let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245
+		$final_mt_codes = array();
246
+		foreach ($mt_codes as $group) {
247
+			$final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
248
+		}
249
+
250
+		$mt_codes = $final_mt_codes;
251
+
252
+
253
+		// k now in this next loop we're going to loop through $msgr_validator again
254
+		// and setup the _validators property from the data we've setup so far.
255
+		foreach ($msgr_validator as $field => $config) {
256
+			// if required shortcode is not in our list of codes for the given field, then we skip this field.
257
+			$required = isset($config['required'])
258
+				? array_intersect($config['required'], array_keys($mt_codes))
259
+				: true;
260
+			if (empty($required)) {
261
+				continue;
262
+			}
263
+
264
+			if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
265
+				// If we have an override then we use it to indicate the codes we want.
266
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+					$this->_valid_shortcodes_modifier[ $context ][ $field ],
268
+					$codes_from_objs
269
+				);
270
+			} elseif (isset($groups_per_field[ $field ])) {
271
+				// if we have specific shortcodes for a field then we need to use them
272
+				$this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+					$groups_per_field[ $field ],
274
+					$codes_from_objs
275
+				);
276
+			} elseif (empty($config)) {
277
+				// if empty config then we're assuming we're just going to use the shortcodes from the message type
278
+				// context
279
+				$this->_validators[ $field ]['shortcodes'] = $mt_codes;
280
+			} elseif (isset($config['specific_shortcodes'])) {
281
+				// if we have specific shortcodes then we need to use them
282
+				$this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
283
+			} else {
284
+				// otherwise the shortcodes are what is set by the messenger for that field
285
+				foreach ($config['shortcodes'] as $group) {
286
+					$this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
+						? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
+						: $codes_from_objs[ $group ];
289
+				}
290
+			}
291
+
292
+			// now let's just make sure that any excluded specific shortcodes are removed.
293
+			$specific_excludes = $this->get_specific_shortcode_excludes();
294
+			if (isset($specific_excludes[ $field ])) {
295
+				foreach ($specific_excludes[ $field ] as $sex) {
296
+					if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
+						unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
298
+					}
299
+				}
300
+			}
301
+
302
+			// hey! don't forget to include the type if present!
303
+			$this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * This just returns the validators property that contains information
310
+	 * about the various shortcodes and their availability with each field
311
+	 *
312
+	 * @return array
313
+	 */
314
+	public function get_validators()
315
+	{
316
+		return $this->_validators;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This simply returns the specific shortcode_excludes property that is set.
322
+	 *
323
+	 * @since 4.5.0
324
+	 * @return array
325
+	 */
326
+	public function get_specific_shortcode_excludes()
327
+	{
328
+		// specific validator filter
329
+		$shortcode_excludes = apply_filters(
330
+			'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
331
+			$this->_specific_shortcode_excludes,
332
+			$this->_context
333
+		);
334
+		// global filter
335
+		return apply_filters(
336
+			'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes',
337
+			$shortcode_excludes,
338
+			$this->_context,
339
+			$this
340
+		);
341
+	}
342
+
343
+
344
+	/**
345
+	 * This is the main method that handles validation
346
+	 * What it does is loop through the _fields (the ones that get validated)
347
+	 * and checks them against the shortcodes array for the field and the 'type' indicated by the
348
+	 *
349
+	 * @access public
350
+	 * @return mixed (bool|array)  if errors present we return the array otherwise true
351
+	 */
352
+	public function validate()
353
+	{
354
+		// some defaults
355
+		$template_fields = $this->_messenger->get_template_fields();
356
+		// loop through the fields and check!
357
+		foreach ($this->_fields as $field => $value) {
358
+			$this->_errors[ $field ] = array();
359
+			$err_msg               = '';
360
+			$field_label           = '';
361
+			// if field is not present in the _validators array then we continue
362
+			if (! isset($this->_validators[ $field ])) {
363
+				unset($this->_errors[ $field ]);
364
+				continue;
365
+			}
366
+
367
+			// get the translated field label!
368
+			// first check if it's in the main fields list
369
+			if (isset($template_fields[ $field ])) {
370
+				if (empty($template_fields[ $field ])) {
371
+					$field_label = $field;
372
+				} else {
373
+					// most likely the field is found in the 'extra' array.
374
+					$field_label = $template_fields[ $field ]['label'];
375
+				}
376
+			}
377
+
378
+			// if field label is empty OR is equal to the current field
379
+			// then we need to loop through the 'extra' fields in the template_fields config (if present)
380
+			if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) {
381
+				foreach ($template_fields['extra'] as $main_field => $secondary_field) {
382
+					foreach ($secondary_field as $name => $values) {
383
+						if ($name === $field) {
384
+							$field_label = $values['label'];
385
+						}
386
+
387
+						// if we've got a 'main' secondary field, let's see if that matches what field we're on
388
+						// which means it contains the label for this field.
389
+						if ($name === 'main' && $main_field === $field_label) {
390
+							$field_label = $values['label'];
391
+						}
392
+					}
393
+				}
394
+			}
395
+
396
+			// field is present. Let's validate shortcodes first (but only if shortcodes present).
397
+			if (
398
+				isset($this->_validators[ $field ]['shortcodes'])
399
+				&& ! empty($this->_validators[ $field ]['shortcodes'])
400
+			) {
401
+				$invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
402
+				// if true then that means there is a returned error message
403
+				// that we'll need to add to the _errors array for this field.
404
+				if ($invalid_shortcodes) {
405
+					$v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
406
+					$err_msg = sprintf(
407
+						esc_html__(
408
+							'%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409
+							'event_espresso'
410
+						),
411
+						'<strong>' . $field_label . '</strong>',
412
+						$invalid_shortcodes,
413
+						'<p>',
414
+						'</p >'
415
+					);
416
+					$err_msg .= sprintf(
417
+						esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'),
418
+						implode(', ', $v_s),
419
+						'<strong>',
420
+						'</strong>'
421
+					);
422
+				}
423
+			}
424
+
425
+			// if there's a "type" to be validated then let's do that too.
426
+			if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
+				switch ($this->_validators[ $field ]['type']) {
428
+					case 'number':
429
+						if (! is_numeric($value)) {
430
+							$err_msg .= sprintf(
431
+								esc_html__(
432
+									'%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
433
+									'event_espresso'
434
+								),
435
+								$field_label,
436
+								$value,
437
+								'<p>',
438
+								'</p >'
439
+							);
440
+						}
441
+						break;
442
+					case 'email':
443
+						$valid_email = $this->_validate_email($value);
444
+						if (! $valid_email) {
445
+							$err_msg .= htmlentities(
446
+								sprintf(
447
+									esc_html__(
448
+										'The %1$s field has at least one string that is not a valid email address record.  Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.',
449
+										'event_espresso'
450
+									),
451
+									$field_label
452
+								)
453
+							);
454
+						}
455
+						break;
456
+					default:
457
+						break;
458
+				}
459
+			}
460
+
461
+			// if $err_msg isn't empty let's setup the _errors array for this field.
462
+			if (! empty($err_msg)) {
463
+				$this->_errors[ $field ]['msg'] = $err_msg;
464
+			} else {
465
+				unset($this->_errors[ $field ]);
466
+			}
467
+		}
468
+
469
+		// if we have ANY errors, then we want to make sure we return the values
470
+		// for ALL the fields so the user doesn't have to retype them all.
471
+		if (! empty($this->_errors)) {
472
+			foreach ($this->_fields as $field => $value) {
473
+				$this->_errors[ $field ]['value'] = stripslashes($value);
474
+			}
475
+		}
476
+
477
+		// return any errors or just TRUE if everything validates
478
+		return empty($this->_errors) ? true : $this->_errors;
479
+	}
480
+
481
+
482
+	/**
483
+	 * Reassembles and returns an array of valid shortcodes
484
+	 * given the array of groups and array of shortcodes indexed by group.
485
+	 *
486
+	 * @param  array $groups          array of shortcode groups that we want shortcodes for
487
+	 * @param  array $codes_from_objs All the codes available.
488
+	 * @return array                   an array of actual shortcodes (that will be used for validation).
489
+	 */
490
+	private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs)
491
+	{
492
+		$shortcodes = array();
493
+		foreach ($groups as $group) {
494
+			$shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
495
+		}
496
+		return $shortcodes;
497
+	}
498
+
499
+
500
+	/**
501
+	 * Validates a string against a list of accepted shortcodes
502
+	 * This function takes in an array of shortcodes
503
+	 * and makes sure that the given string ONLY contains shortcodes in that array.
504
+	 *
505
+	 * @param  string $value            string to evaluate
506
+	 * @param  array  $valid_shortcodes array of shortcodes that are acceptable.
507
+	 * @return mixed (bool|string)  return either a list of invalid shortcodes OR false if the shortcodes validate.
508
+	 */
509
+	protected function _invalid_shortcodes($value, $valid_shortcodes)
510
+	{
511
+		// first we need to go through the string and get the shortcodes in the string
512
+		preg_match_all('/(\[.+?\])/', $value, $matches);
513
+		$incoming_shortcodes = (array) $matches[0];
514
+
515
+		// get a diff of the shortcodes in the string vs the valid shortcodes
516
+		$diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes));
517
+
518
+		// we need to account for custom codes so let's loop through the diff and remove any of those type of codes
519
+		foreach ($diff as $ind => $code) {
520
+			if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) {
521
+				// strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522
+				$dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523
+				// does this exist in the $valid_shortcodes?  If so then unset.
524
+				if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
+					unset($diff[ $ind ]);
526
+				}
527
+			}
528
+		}
529
+
530
+		if (empty($diff)) {
531
+			return false;
532
+		} //there is no diff, we have no invalid shortcodes, so return
533
+
534
+		// made it here? then let's assemble the error message
535
+		$invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
+		$invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
537
+		return $invalid_shortcodes;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Validates an incoming string and makes sure we have valid emails in the string.
543
+	 *
544
+	 * @param  string $value incoming value to validate
545
+	 * @return bool        true if the string validates, false if it doesn't
546
+	 */
547
+	protected function _validate_email($value)
548
+	{
549
+		$validate = true;
550
+		$or_val   = $value;
551
+
552
+		// empty strings will validate because this is how a message template
553
+		// for a particular context can be "turned off" (if there is no email then no message)
554
+		if (empty($value)) {
555
+			return $validate;
556
+		}
557
+
558
+		// first determine if there ARE any shortcodes.
559
+		// If there are shortcodes and then later we find that there were no other valid emails
560
+		// but the field isn't empty...
561
+		// that means we've got extra commas that were left after stripping out shortcodes so probably still valid.
562
+		$has_shortcodes = preg_match('/(\[.+?\])/', $value);
563
+
564
+		// first we need to strip out all the shortcodes!
565
+		$value = preg_replace('/(\[.+?\])/', '', $value);
566
+
567
+		// if original value is not empty and new value is, then we've parsed out a shortcode
568
+		// and we now have an empty string which DOES validate.
569
+		// We also validate complete empty field for email because
570
+		// its possible that this message is being "turned off" for a particular context
571
+
572
+
573
+		if (! empty($or_val) && empty($value)) {
574
+			return $validate;
575
+		}
576
+
577
+		// trim any commas from beginning and end of string ( after whitespace trimmed );
578
+		$value = trim(trim($value), ',');
579
+
580
+
581
+		// next we need to split up the string if its comma delimited.
582
+		$emails = explode(',', $value);
583
+		$empty  = false; // used to indicate that there is an empty comma.
584
+		// now let's loop through the emails and do our checks
585
+		foreach ($emails as $email) {
586
+			if (empty($email)) {
587
+				$empty = true;
588
+				continue;
589
+			}
590
+
591
+			// trim whitespace
592
+			$email = trim($email);
593
+			// either its of type "[email protected]", or its of type "fname lname <[email protected]>"
594
+			if (is_email($email)) {
595
+				continue;
596
+			}
597
+			$matches  = array();
598
+			$validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false;
599
+			if ($validate && is_email($matches[2])) {
600
+				continue;
601
+			}
602
+			return false;
603
+		}
604
+
605
+		$validate = $empty && ! $has_shortcodes ? false : $validate;
606
+
607
+		return $validate;
608
+	}
609
+
610
+
611
+	/**
612
+	 * Magic getter
613
+	 * Using this to provide back compat with add-ons referencing deprecated properties.
614
+	 *
615
+	 * @param string $property Property being requested
616
+	 * @throws Exception
617
+	 * @return mixed
618
+	 */
619
+	public function __get($property)
620
+	{
621
+		$expected_properties_map = array(
622
+			/**
623
+			 * @deprecated 4.9.0
624
+			 */
625
+			'_MSGR'   => '_messenger',
626
+			/**
627
+			 * @deprecated 4.9.0
628
+			 */
629
+			'_MSGTYP' => '_message_type',
630
+		);
631
+
632
+		if (isset($expected_properties_map[ $property ])) {
633
+			return $this->{$expected_properties_map[ $property ]};
634
+		}
635
+
636
+		throw new Exception(
637
+			sprintf(
638
+				esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'),
639
+				$property,
640
+				get_class($this)
641
+			)
642
+		);
643
+	}
644 644
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
         // load messenger
158 158
         $messenger = ucwords(str_replace('_', ' ', $this->_m_name));
159 159
         $messenger = str_replace(' ', '_', $messenger);
160
-        $messenger = 'EE_' . $messenger . '_messenger';
160
+        $messenger = 'EE_'.$messenger.'_messenger';
161 161
 
162
-        if (! class_exists($messenger)) {
162
+        if ( ! class_exists($messenger)) {
163 163
             throw new EE_Error(
164 164
                 sprintf(
165 165
                     esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'),
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
         // load message type
174 174
         $message_type = ucwords(str_replace('_', ' ', $this->_mt_name));
175 175
         $message_type = str_replace(' ', '_', $message_type);
176
-        $message_type = 'EE_' . $message_type . '_message_type';
176
+        $message_type = 'EE_'.$message_type.'_message_type';
177 177
 
178
-        if (! class_exists($message_type)) {
178
+        if ( ! class_exists($message_type)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     esc_html__('There is no message type class for the given string (%s)', 'event_espresso'),
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
         // we only want the valid shortcodes for the given context!
210 210
         $context  = $this->_context;
211
-        $mt_codes = $mt_codes[ $context ];
211
+        $mt_codes = $mt_codes[$context];
212 212
 
213 213
         // in this first loop we're just getting all shortcode group indexes from the msgr_validator
214 214
         // into a single array (so we can get the appropriate shortcode objects for the groups)
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
             if (empty($config) || ! isset($config['shortcodes'])) {
220 220
                 continue;
221 221
             }  //Nothing to see here.
222
-            $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes);
223
-            $shortcode_groups         = array_merge($config['shortcodes'], $shortcode_groups);
222
+            $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes);
223
+            $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups);
224 224
         }
225 225
 
226 226
         $shortcode_groups = array_unique($shortcode_groups);
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
         foreach ($shortcode_groups as $group) {
233 233
             $ref       = ucwords(str_replace('_', ' ', $group));
234 234
             $ref       = str_replace(' ', '_', $ref);
235
-            $classname = 'EE_' . $ref . '_Shortcodes';
235
+            $classname = 'EE_'.$ref.'_Shortcodes';
236 236
             if (class_exists($classname)) {
237 237
                 $a                       = new ReflectionClass($classname);
238 238
                 $obj                     = $a->newInstance();
239
-                $codes_from_objs[ $group ] = $obj->get_shortcodes();
239
+                $codes_from_objs[$group] = $obj->get_shortcodes();
240 240
             }
241 241
         }
242 242
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique)
245 245
         $final_mt_codes = array();
246 246
         foreach ($mt_codes as $group) {
247
-            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]);
247
+            $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]);
248 248
         }
249 249
 
250 250
         $mt_codes = $final_mt_codes;
@@ -261,46 +261,46 @@  discard block
 block discarded – undo
261 261
                 continue;
262 262
             }
263 263
 
264
-            if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) {
264
+            if (isset($this->_valid_shortcodes_modifier[$context][$field])) {
265 265
                 // If we have an override then we use it to indicate the codes we want.
266
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
-                    $this->_valid_shortcodes_modifier[ $context ][ $field ],
266
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
267
+                    $this->_valid_shortcodes_modifier[$context][$field],
268 268
                     $codes_from_objs
269 269
                 );
270
-            } elseif (isset($groups_per_field[ $field ])) {
270
+            } elseif (isset($groups_per_field[$field])) {
271 271
                 // if we have specific shortcodes for a field then we need to use them
272
-                $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
-                    $groups_per_field[ $field ],
272
+                $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group(
273
+                    $groups_per_field[$field],
274 274
                     $codes_from_objs
275 275
                 );
276 276
             } elseif (empty($config)) {
277 277
                 // if empty config then we're assuming we're just going to use the shortcodes from the message type
278 278
                 // context
279
-                $this->_validators[ $field ]['shortcodes'] = $mt_codes;
279
+                $this->_validators[$field]['shortcodes'] = $mt_codes;
280 280
             } elseif (isset($config['specific_shortcodes'])) {
281 281
                 // if we have specific shortcodes then we need to use them
282
-                $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes'];
282
+                $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes'];
283 283
             } else {
284 284
                 // otherwise the shortcodes are what is set by the messenger for that field
285 285
                 foreach ($config['shortcodes'] as $group) {
286
-                    $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes'])
287
-                        ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ])
288
-                        : $codes_from_objs[ $group ];
286
+                    $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes'])
287
+                        ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group])
288
+                        : $codes_from_objs[$group];
289 289
                 }
290 290
             }
291 291
 
292 292
             // now let's just make sure that any excluded specific shortcodes are removed.
293 293
             $specific_excludes = $this->get_specific_shortcode_excludes();
294
-            if (isset($specific_excludes[ $field ])) {
295
-                foreach ($specific_excludes[ $field ] as $sex) {
296
-                    if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) {
297
-                        unset($this->_validators[ $field ]['shortcodes'][ $sex ]);
294
+            if (isset($specific_excludes[$field])) {
295
+                foreach ($specific_excludes[$field] as $sex) {
296
+                    if (isset($this->_validators[$field]['shortcodes'][$sex])) {
297
+                        unset($this->_validators[$field]['shortcodes'][$sex]);
298 298
                     }
299 299
                 }
300 300
             }
301 301
 
302 302
             // hey! don't forget to include the type if present!
303
-            $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null;
303
+            $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null;
304 304
         }
305 305
     }
306 306
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         // specific validator filter
329 329
         $shortcode_excludes = apply_filters(
330
-            'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;',
330
+            'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;',
331 331
             $this->_specific_shortcode_excludes,
332 332
             $this->_context
333 333
         );
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
         $template_fields = $this->_messenger->get_template_fields();
356 356
         // loop through the fields and check!
357 357
         foreach ($this->_fields as $field => $value) {
358
-            $this->_errors[ $field ] = array();
358
+            $this->_errors[$field] = array();
359 359
             $err_msg               = '';
360 360
             $field_label           = '';
361 361
             // if field is not present in the _validators array then we continue
362
-            if (! isset($this->_validators[ $field ])) {
363
-                unset($this->_errors[ $field ]);
362
+            if ( ! isset($this->_validators[$field])) {
363
+                unset($this->_errors[$field]);
364 364
                 continue;
365 365
             }
366 366
 
367 367
             // get the translated field label!
368 368
             // first check if it's in the main fields list
369
-            if (isset($template_fields[ $field ])) {
370
-                if (empty($template_fields[ $field ])) {
369
+            if (isset($template_fields[$field])) {
370
+                if (empty($template_fields[$field])) {
371 371
                     $field_label = $field;
372 372
                 } else {
373 373
                     // most likely the field is found in the 'extra' array.
374
-                    $field_label = $template_fields[ $field ]['label'];
374
+                    $field_label = $template_fields[$field]['label'];
375 375
                 }
376 376
             }
377 377
 
@@ -395,20 +395,20 @@  discard block
 block discarded – undo
395 395
 
396 396
             // field is present. Let's validate shortcodes first (but only if shortcodes present).
397 397
             if (
398
-                isset($this->_validators[ $field ]['shortcodes'])
399
-                && ! empty($this->_validators[ $field ]['shortcodes'])
398
+                isset($this->_validators[$field]['shortcodes'])
399
+                && ! empty($this->_validators[$field]['shortcodes'])
400 400
             ) {
401
-                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']);
401
+                $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']);
402 402
                 // if true then that means there is a returned error message
403 403
                 // that we'll need to add to the _errors array for this field.
404 404
                 if ($invalid_shortcodes) {
405
-                    $v_s     = array_keys($this->_validators[ $field ]['shortcodes']);
405
+                    $v_s     = array_keys($this->_validators[$field]['shortcodes']);
406 406
                     $err_msg = sprintf(
407 407
                         esc_html__(
408 408
                             '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s',
409 409
                             'event_espresso'
410 410
                         ),
411
-                        '<strong>' . $field_label . '</strong>',
411
+                        '<strong>'.$field_label.'</strong>',
412 412
                         $invalid_shortcodes,
413 413
                         '<p>',
414 414
                         '</p >'
@@ -423,10 +423,10 @@  discard block
 block discarded – undo
423 423
             }
424 424
 
425 425
             // if there's a "type" to be validated then let's do that too.
426
-            if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) {
427
-                switch ($this->_validators[ $field ]['type']) {
426
+            if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) {
427
+                switch ($this->_validators[$field]['type']) {
428 428
                     case 'number':
429
-                        if (! is_numeric($value)) {
429
+                        if ( ! is_numeric($value)) {
430 430
                             $err_msg .= sprintf(
431 431
                                 esc_html__(
432 432
                                     '%3$sThe %1$s field is supposed to be a number. The value given (%2$s)  is not.  Please double-check and make sure the field contains a number%4$s',
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
                         break;
442 442
                     case 'email':
443 443
                         $valid_email = $this->_validate_email($value);
444
-                        if (! $valid_email) {
444
+                        if ( ! $valid_email) {
445 445
                             $err_msg .= htmlentities(
446 446
                                 sprintf(
447 447
                                     esc_html__(
@@ -459,18 +459,18 @@  discard block
 block discarded – undo
459 459
             }
460 460
 
461 461
             // if $err_msg isn't empty let's setup the _errors array for this field.
462
-            if (! empty($err_msg)) {
463
-                $this->_errors[ $field ]['msg'] = $err_msg;
462
+            if ( ! empty($err_msg)) {
463
+                $this->_errors[$field]['msg'] = $err_msg;
464 464
             } else {
465
-                unset($this->_errors[ $field ]);
465
+                unset($this->_errors[$field]);
466 466
             }
467 467
         }
468 468
 
469 469
         // if we have ANY errors, then we want to make sure we return the values
470 470
         // for ALL the fields so the user doesn't have to retype them all.
471
-        if (! empty($this->_errors)) {
471
+        if ( ! empty($this->_errors)) {
472 472
             foreach ($this->_fields as $field => $value) {
473
-                $this->_errors[ $field ]['value'] = stripslashes($value);
473
+                $this->_errors[$field]['value'] = stripslashes($value);
474 474
             }
475 475
         }
476 476
 
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
     {
492 492
         $shortcodes = array();
493 493
         foreach ($groups as $group) {
494
-            $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]);
494
+            $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]);
495 495
         }
496 496
         return $shortcodes;
497 497
     }
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
                 // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] )
522 522
                 $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code);
523 523
                 // does this exist in the $valid_shortcodes?  If so then unset.
524
-                if (isset($valid_shortcodes[ $dynamic_sc ])) {
525
-                    unset($diff[ $ind ]);
524
+                if (isset($valid_shortcodes[$dynamic_sc])) {
525
+                    unset($diff[$ind]);
526 526
                 }
527 527
             }
528 528
         }
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 
534 534
         // made it here? then let's assemble the error message
535 535
         $invalid_shortcodes = implode('</strong>,<strong>', $diff);
536
-        $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>';
536
+        $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>';
537 537
         return $invalid_shortcodes;
538 538
     }
539 539
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         // its possible that this message is being "turned off" for a particular context
571 571
 
572 572
 
573
-        if (! empty($or_val) && empty($value)) {
573
+        if ( ! empty($or_val) && empty($value)) {
574 574
             return $validate;
575 575
         }
576 576
 
@@ -629,8 +629,8 @@  discard block
 block discarded – undo
629 629
             '_MSGTYP' => '_message_type',
630 630
         );
631 631
 
632
-        if (isset($expected_properties_map[ $property ])) {
633
-            return $this->{$expected_properties_map[ $property ]};
632
+        if (isset($expected_properties_map[$property])) {
633
+            return $this->{$expected_properties_map[$property]};
634 634
         }
635 635
 
636 636
         throw new Exception(
Please login to merge, or discard this patch.
core/db_models/fields/EE_Simple_HTML_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
 
12 12
 
13 13
 
14
-    /**
15
-     * removes all tags which a WP Post wouldn't allow in its content normally
16
-     *
17
-     * @param string $value
18
-     * @return string
19
-     */
20
-    public function prepare_for_set($value)
21
-    {
22
-        return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
-    }
14
+	/**
15
+	 * removes all tags which a WP Post wouldn't allow in its content normally
16
+	 *
17
+	 * @param string $value
18
+	 * @return string
19
+	 */
20
+	public function prepare_for_set($value)
21
+	{
22
+		return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags()));
23
+	}
24 24
 }
Please login to merge, or discard this patch.
core/db_classes/EE_WP_User.class.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      */
52 52
     public function wp_user_obj()
53 53
     {
54
-        if (! $this->_wp_user_obj) {
54
+        if ( ! $this->_wp_user_obj) {
55 55
             $this->_wp_user_obj = get_user_by('ID', $this->ID());
56 56
         }
57 57
         return $this->_wp_user_obj;
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -11,91 +11,91 @@
 block discarded – undo
11 11
 class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links
12 12
 {
13 13
 
14
-    /**
15
-     * @var WP_User
16
-     */
17
-    protected $_wp_user_obj;
14
+	/**
15
+	 * @var WP_User
16
+	 */
17
+	protected $_wp_user_obj;
18 18
 
19
-    /**
20
-     * @param array $props_n_values
21
-     * @return EE_WP_User|mixed
22
-     */
23
-    public static function new_instance($props_n_values = array())
24
-    {
25
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
-        return $has_object ? $has_object : new self($props_n_values);
27
-    }
19
+	/**
20
+	 * @param array $props_n_values
21
+	 * @return EE_WP_User|mixed
22
+	 */
23
+	public static function new_instance($props_n_values = array())
24
+	{
25
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
26
+		return $has_object ? $has_object : new self($props_n_values);
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * @param array $props_n_values
32
-     * @return EE_WP_User
33
-     */
34
-    public static function new_instance_from_db($props_n_values = array())
35
-    {
36
-        return new self($props_n_values, true);
37
-    }
30
+	/**
31
+	 * @param array $props_n_values
32
+	 * @return EE_WP_User
33
+	 */
34
+	public static function new_instance_from_db($props_n_values = array())
35
+	{
36
+		return new self($props_n_values, true);
37
+	}
38 38
 
39
-    /**
40
-     * Return a normal WP_User object (caches the object for future calls)
41
-     *
42
-     * @return WP_User
43
-     */
44
-    public function wp_user_obj()
45
-    {
46
-        if (! $this->_wp_user_obj) {
47
-            $this->_wp_user_obj = get_user_by('ID', $this->ID());
48
-        }
49
-        return $this->_wp_user_obj;
50
-    }
39
+	/**
40
+	 * Return a normal WP_User object (caches the object for future calls)
41
+	 *
42
+	 * @return WP_User
43
+	 */
44
+	public function wp_user_obj()
45
+	{
46
+		if (! $this->_wp_user_obj) {
47
+			$this->_wp_user_obj = get_user_by('ID', $this->ID());
48
+		}
49
+		return $this->_wp_user_obj;
50
+	}
51 51
 
52
-    /**
53
-     * Return the link to the admin details for the object.
54
-     *
55
-     * @return string
56
-     */
57
-    public function get_admin_details_link()
58
-    {
59
-        return $this->get_admin_edit_link();
60
-    }
52
+	/**
53
+	 * Return the link to the admin details for the object.
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function get_admin_details_link()
58
+	{
59
+		return $this->get_admin_edit_link();
60
+	}
61 61
 
62
-    /**
63
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
-     *
65
-     * @return string
66
-     */
67
-    public function get_admin_edit_link()
68
-    {
69
-        return esc_url(
70
-            add_query_arg(
71
-                'wp_http_referer',
72
-                urlencode(
73
-                    wp_unslash(
74
-                        $_SERVER['REQUEST_URI']
75
-                    )
76
-                ),
77
-                get_edit_user_link($this->ID())
78
-            )
79
-        );
80
-    }
62
+	/**
63
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
64
+	 *
65
+	 * @return string
66
+	 */
67
+	public function get_admin_edit_link()
68
+	{
69
+		return esc_url(
70
+			add_query_arg(
71
+				'wp_http_referer',
72
+				urlencode(
73
+					wp_unslash(
74
+						$_SERVER['REQUEST_URI']
75
+					)
76
+				),
77
+				get_edit_user_link($this->ID())
78
+			)
79
+		);
80
+	}
81 81
 
82
-    /**
83
-     * Returns the link to a settings page for the object.
84
-     *
85
-     * @return string
86
-     */
87
-    public function get_admin_settings_link()
88
-    {
89
-        return $this->get_admin_edit_link();
90
-    }
82
+	/**
83
+	 * Returns the link to a settings page for the object.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	public function get_admin_settings_link()
88
+	{
89
+		return $this->get_admin_edit_link();
90
+	}
91 91
 
92
-    /**
93
-     * Returns the link to the "overview" for the object (typically the "list table" view).
94
-     *
95
-     * @return string
96
-     */
97
-    public function get_admin_overview_link()
98
-    {
99
-        return admin_url('users.php');
100
-    }
92
+	/**
93
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
94
+	 *
95
+	 * @return string
96
+	 */
97
+	public function get_admin_overview_link()
98
+	{
99
+		return admin_url('users.php');
100
+	}
101 101
 }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
     /**
20 20
      * @param array $props_n_values
21
-     * @return EE_WP_User|mixed
21
+     * @return EE_Base_Class
22 22
      */
23 23
     public static function new_instance($props_n_values = array())
24 24
     {
Please login to merge, or discard this patch.
core/EE_Module_Request_Router.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * this method instantiates modules and calls the method that was defined when the route was registered
183 183
      *
184 184
      * @param string $module_name
185
-     * @return EED_Module|object|null
185
+     * @return null|EED_Module
186 186
      * @throws ReflectionException
187 187
      */
188 188
     public static function module_factory($module_name)
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 
254 254
     /**
255
-     * @param $current_route
255
+     * @param string $current_route
256 256
      * @return string
257 257
      */
258 258
     public function get_view($current_route)
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -15,255 +15,255 @@
 block discarded – undo
15 15
 final class EE_Module_Request_Router implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Request $request
20
-     */
21
-    private $request;
18
+	/**
19
+	 * @var EE_Request $request
20
+	 */
21
+	private $request;
22 22
 
23
-    /**
24
-     * @var array $_previous_routes
25
-     */
26
-    private static $_previous_routes = array();
23
+	/**
24
+	 * @var array $_previous_routes
25
+	 */
26
+	private static $_previous_routes = array();
27 27
 
28
-    /**
29
-     * @var WP_Query $WP_Query
30
-     */
31
-    public $WP_Query;
28
+	/**
29
+	 * @var WP_Query $WP_Query
30
+	 */
31
+	public $WP_Query;
32 32
 
33 33
 
34
-    /**
35
-     * EE_Module_Request_Router constructor.
36
-     *
37
-     * @param EE_Request $request
38
-     */
39
-    public function __construct(EE_Request $request)
40
-    {
41
-        $this->request = $request;
42
-    }
34
+	/**
35
+	 * EE_Module_Request_Router constructor.
36
+	 *
37
+	 * @param EE_Request $request
38
+	 */
39
+	public function __construct(EE_Request $request)
40
+	{
41
+		$this->request = $request;
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * on the first call  to this method, it checks the EE_Request_Handler for a "route"
47
-     * on subsequent calls to this method,
48
-     * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
49
-     * and checks if the last called route has any forwarding routes registered for it
50
-     *
51
-     * @param WP_Query $WP_Query
52
-     * @return NULL|string
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    public function get_route(WP_Query $WP_Query)
57
-    {
58
-        $this->WP_Query = $WP_Query;
59
-        // assume this if first route being called
60
-        $previous_route = false;
61
-        // but is it really ???
62
-        if (! empty(self::$_previous_routes)) {
63
-            // get last run route
64
-            $previous_routes = array_values(self::$_previous_routes);
65
-            $previous_route = array_pop($previous_routes);
66
-        }
67
-        //  has another route already been run ?
68
-        if ($previous_route) {
69
-            // check if  forwarding has been set
70
-            $current_route = $this->get_forward($previous_route);
71
-            try {
72
-                // check for recursive forwarding
73
-                if (isset(self::$_previous_routes[ $current_route ])) {
74
-                    throw new EE_Error(
75
-                        sprintf(
76
-                            __(
77
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
-                                'event_espresso'
79
-                            ),
80
-                            $current_route
81
-                        )
82
-                    );
83
-                }
84
-            } catch (EE_Error $e) {
85
-                $e->get_error();
86
-                return null;
87
-            }
88
-        } else {
89
-            // first route called
90
-            $current_route = null;
91
-            // grab all routes
92
-            $routes = EE_Config::get_routes();
93
-            foreach ($routes as $key => $route) {
94
-                // first determine if route key uses w?ldc*rds
95
-                $uses_wildcards = strpos($key, '?') !== false
96
-                                  || strpos($key, '*') !== false;
97
-                // check request for module route
98
-                $route_found = $uses_wildcards
99
-                    ? $this->request->matches($key)
100
-                    : $this->request->is_set($key);
101
-                if ($route_found) {
102
-                    $current_route = $uses_wildcards
103
-                        ? $this->request->getMatch($key)
104
-                        : $this->request->get($key);
105
-                    $current_route = sanitize_text_field($current_route);
106
-                    if ($current_route) {
107
-                        $current_route = array($key, $current_route);
108
-                        break;
109
-                    }
110
-                }
111
-            }
112
-        }
113
-        // sorry, but I can't read what you route !
114
-        if (empty($current_route)) {
115
-            return null;
116
-        }
117
-        // add route to previous routes array
118
-        self::$_previous_routes[] = $current_route;
119
-        return $current_route;
120
-    }
45
+	/**
46
+	 * on the first call  to this method, it checks the EE_Request_Handler for a "route"
47
+	 * on subsequent calls to this method,
48
+	 * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
49
+	 * and checks if the last called route has any forwarding routes registered for it
50
+	 *
51
+	 * @param WP_Query $WP_Query
52
+	 * @return NULL|string
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	public function get_route(WP_Query $WP_Query)
57
+	{
58
+		$this->WP_Query = $WP_Query;
59
+		// assume this if first route being called
60
+		$previous_route = false;
61
+		// but is it really ???
62
+		if (! empty(self::$_previous_routes)) {
63
+			// get last run route
64
+			$previous_routes = array_values(self::$_previous_routes);
65
+			$previous_route = array_pop($previous_routes);
66
+		}
67
+		//  has another route already been run ?
68
+		if ($previous_route) {
69
+			// check if  forwarding has been set
70
+			$current_route = $this->get_forward($previous_route);
71
+			try {
72
+				// check for recursive forwarding
73
+				if (isset(self::$_previous_routes[ $current_route ])) {
74
+					throw new EE_Error(
75
+						sprintf(
76
+							__(
77
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
+								'event_espresso'
79
+							),
80
+							$current_route
81
+						)
82
+					);
83
+				}
84
+			} catch (EE_Error $e) {
85
+				$e->get_error();
86
+				return null;
87
+			}
88
+		} else {
89
+			// first route called
90
+			$current_route = null;
91
+			// grab all routes
92
+			$routes = EE_Config::get_routes();
93
+			foreach ($routes as $key => $route) {
94
+				// first determine if route key uses w?ldc*rds
95
+				$uses_wildcards = strpos($key, '?') !== false
96
+								  || strpos($key, '*') !== false;
97
+				// check request for module route
98
+				$route_found = $uses_wildcards
99
+					? $this->request->matches($key)
100
+					: $this->request->is_set($key);
101
+				if ($route_found) {
102
+					$current_route = $uses_wildcards
103
+						? $this->request->getMatch($key)
104
+						: $this->request->get($key);
105
+					$current_route = sanitize_text_field($current_route);
106
+					if ($current_route) {
107
+						$current_route = array($key, $current_route);
108
+						break;
109
+					}
110
+				}
111
+			}
112
+		}
113
+		// sorry, but I can't read what you route !
114
+		if (empty($current_route)) {
115
+			return null;
116
+		}
117
+		// add route to previous routes array
118
+		self::$_previous_routes[] = $current_route;
119
+		return $current_route;
120
+	}
121 121
 
122 122
 
123
-    /**
124
-     * this method simply takes a valid route, and resolves what module class method the route points to
125
-     *
126
-     * @param string $key
127
-     * @param string $current_route
128
-     * @return mixed EED_Module | boolean
129
-     * @throws EE_Error
130
-     * @throws ReflectionException
131
-     */
132
-    public function resolve_route($key, $current_route)
133
-    {
134
-        // get module method that route has been mapped to
135
-        $module_method = EE_Config::get_route($current_route, $key);
136
-        // verify result was returned
137
-        if (empty($module_method)) {
138
-            $msg = sprintf(
139
-                __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
-                $current_route
141
-            );
142
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        // verify that result is an array
146
-        if (! is_array($module_method)) {
147
-            $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
-            return false;
150
-        }
151
-        // grab module name
152
-        $module_name = $module_method[0];
153
-        // verify that a class method was registered properly
154
-        if (! isset($module_method[1])) {
155
-            $msg = sprintf(
156
-                __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
-                $current_route
158
-            );
159
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
-            return false;
161
-        }
162
-        // grab method
163
-        $method = $module_method[1];
164
-        // verify that class exists
165
-        if (! class_exists($module_name)) {
166
-            $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
-            return false;
169
-        }
170
-        // verify that method exists
171
-        if (! method_exists($module_name, $method)) {
172
-            $msg = sprintf(
173
-                __('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
-                $method,
175
-                $current_route
176
-            );
177
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
-            return false;
179
-        }
180
-        // instantiate module and call route method
181
-        return $this->_module_router($module_name, $method);
182
-    }
123
+	/**
124
+	 * this method simply takes a valid route, and resolves what module class method the route points to
125
+	 *
126
+	 * @param string $key
127
+	 * @param string $current_route
128
+	 * @return mixed EED_Module | boolean
129
+	 * @throws EE_Error
130
+	 * @throws ReflectionException
131
+	 */
132
+	public function resolve_route($key, $current_route)
133
+	{
134
+		// get module method that route has been mapped to
135
+		$module_method = EE_Config::get_route($current_route, $key);
136
+		// verify result was returned
137
+		if (empty($module_method)) {
138
+			$msg = sprintf(
139
+				__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
+				$current_route
141
+			);
142
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		// verify that result is an array
146
+		if (! is_array($module_method)) {
147
+			$msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+			return false;
150
+		}
151
+		// grab module name
152
+		$module_name = $module_method[0];
153
+		// verify that a class method was registered properly
154
+		if (! isset($module_method[1])) {
155
+			$msg = sprintf(
156
+				__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
+				$current_route
158
+			);
159
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
+			return false;
161
+		}
162
+		// grab method
163
+		$method = $module_method[1];
164
+		// verify that class exists
165
+		if (! class_exists($module_name)) {
166
+			$msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
+			return false;
169
+		}
170
+		// verify that method exists
171
+		if (! method_exists($module_name, $method)) {
172
+			$msg = sprintf(
173
+				__('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
+				$method,
175
+				$current_route
176
+			);
177
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
+			return false;
179
+		}
180
+		// instantiate module and call route method
181
+		return $this->_module_router($module_name, $method);
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * this method instantiates modules and calls the method that was defined when the route was registered
187
-     *
188
-     * @param string $module_name
189
-     * @return EED_Module|object|null
190
-     * @throws ReflectionException
191
-     */
192
-    public static function module_factory($module_name)
193
-    {
194
-        if ($module_name === 'EED_Module') {
195
-            EE_Error::add_error(
196
-                sprintf(
197
-                    __(
198
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
199
-                        'event_espresso'
200
-                    ),
201
-                    $module_name
202
-                ),
203
-                __FILE__,
204
-                __FUNCTION__,
205
-                __LINE__
206
-            );
207
-            return null;
208
-        }
209
-        // instantiate module class
210
-        $module = new $module_name();
211
-        // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
213
-            EE_Error::add_error(
214
-                sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
-                __FILE__,
216
-                __FUNCTION__,
217
-                __LINE__
218
-            );
219
-            return null;
220
-        }
221
-        return $module;
222
-    }
185
+	/**
186
+	 * this method instantiates modules and calls the method that was defined when the route was registered
187
+	 *
188
+	 * @param string $module_name
189
+	 * @return EED_Module|object|null
190
+	 * @throws ReflectionException
191
+	 */
192
+	public static function module_factory($module_name)
193
+	{
194
+		if ($module_name === 'EED_Module') {
195
+			EE_Error::add_error(
196
+				sprintf(
197
+					__(
198
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
199
+						'event_espresso'
200
+					),
201
+					$module_name
202
+				),
203
+				__FILE__,
204
+				__FUNCTION__,
205
+				__LINE__
206
+			);
207
+			return null;
208
+		}
209
+		// instantiate module class
210
+		$module = new $module_name();
211
+		// ensure that class is actually a module
212
+		if (! $module instanceof EED_Module) {
213
+			EE_Error::add_error(
214
+				sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215
+				__FILE__,
216
+				__FUNCTION__,
217
+				__LINE__
218
+			);
219
+			return null;
220
+		}
221
+		return $module;
222
+	}
223 223
 
224 224
 
225
-    /**
226
-     * this method instantiates modules and calls the method that was defined when the route was registered
227
-     *
228
-     * @param string $module_name
229
-     * @param string $method
230
-     * @return EED_Module|null
231
-     * @throws EE_Error
232
-     * @throws ReflectionException
233
-     */
234
-    private function _module_router($module_name, $method)
235
-    {
236
-        // instantiate module class
237
-        $module = EE_Module_Request_Router::module_factory($module_name);
238
-        if ($module instanceof EED_Module) {
239
-            // and call whatever action the route was for
240
-            try {
241
-                call_user_func(array($module, $method), $this->WP_Query);
242
-            } catch (EE_Error $e) {
243
-                $e->get_error();
244
-                return null;
245
-            }
246
-        }
247
-        return $module;
248
-    }
225
+	/**
226
+	 * this method instantiates modules and calls the method that was defined when the route was registered
227
+	 *
228
+	 * @param string $module_name
229
+	 * @param string $method
230
+	 * @return EED_Module|null
231
+	 * @throws EE_Error
232
+	 * @throws ReflectionException
233
+	 */
234
+	private function _module_router($module_name, $method)
235
+	{
236
+		// instantiate module class
237
+		$module = EE_Module_Request_Router::module_factory($module_name);
238
+		if ($module instanceof EED_Module) {
239
+			// and call whatever action the route was for
240
+			try {
241
+				call_user_func(array($module, $method), $this->WP_Query);
242
+			} catch (EE_Error $e) {
243
+				$e->get_error();
244
+				return null;
245
+			}
246
+		}
247
+		return $module;
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param $current_route
253
-     * @return string
254
-     */
255
-    public function get_forward($current_route)
256
-    {
257
-        return EE_Config::get_forward($current_route);
258
-    }
251
+	/**
252
+	 * @param $current_route
253
+	 * @return string
254
+	 */
255
+	public function get_forward($current_route)
256
+	{
257
+		return EE_Config::get_forward($current_route);
258
+	}
259 259
 
260 260
 
261
-    /**
262
-     * @param $current_route
263
-     * @return string
264
-     */
265
-    public function get_view($current_route)
266
-    {
267
-        return EE_Config::get_view($current_route);
268
-    }
261
+	/**
262
+	 * @param $current_route
263
+	 * @return string
264
+	 */
265
+	public function get_view($current_route)
266
+	{
267
+		return EE_Config::get_view($current_route);
268
+	}
269 269
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         // assume this if first route being called
60 60
         $previous_route = false;
61 61
         // but is it really ???
62
-        if (! empty(self::$_previous_routes)) {
62
+        if ( ! empty(self::$_previous_routes)) {
63 63
             // get last run route
64 64
             $previous_routes = array_values(self::$_previous_routes);
65 65
             $previous_route = array_pop($previous_routes);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
             $current_route = $this->get_forward($previous_route);
71 71
             try {
72 72
                 // check for recursive forwarding
73
-                if (isset(self::$_previous_routes[ $current_route ])) {
73
+                if (isset(self::$_previous_routes[$current_route])) {
74 74
                     throw new EE_Error(
75 75
                         sprintf(
76 76
                             __(
@@ -143,38 +143,38 @@  discard block
 block discarded – undo
143 143
             return false;
144 144
         }
145 145
         // verify that result is an array
146
-        if (! is_array($module_method)) {
146
+        if ( ! is_array($module_method)) {
147 147
             $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
148
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
149 149
             return false;
150 150
         }
151 151
         // grab module name
152 152
         $module_name = $module_method[0];
153 153
         // verify that a class method was registered properly
154
-        if (! isset($module_method[1])) {
154
+        if ( ! isset($module_method[1])) {
155 155
             $msg = sprintf(
156 156
                 __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157 157
                 $current_route
158 158
             );
159
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
159
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
160 160
             return false;
161 161
         }
162 162
         // grab method
163 163
         $method = $module_method[1];
164 164
         // verify that class exists
165
-        if (! class_exists($module_name)) {
165
+        if ( ! class_exists($module_name)) {
166 166
             $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167 167
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168 168
             return false;
169 169
         }
170 170
         // verify that method exists
171
-        if (! method_exists($module_name, $method)) {
171
+        if ( ! method_exists($module_name, $method)) {
172 172
             $msg = sprintf(
173 173
                 __('The class method %s for the %s route is in invalid.', 'event_espresso'),
174 174
                 $method,
175 175
                 $current_route
176 176
             );
177
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
177
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
178 178
             return false;
179 179
         }
180 180
         // instantiate module and call route method
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         // instantiate module class
210 210
         $module = new $module_name();
211 211
         // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
212
+        if ( ! $module instanceof EED_Module) {
213 213
             EE_Error::add_error(
214 214
                 sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215 215
                 __FILE__,
Please login to merge, or discard this patch.