Completed
Branch fix/kses-10 (1ed7f7)
by
unknown
12:47 queued 10:35
created
core/helpers/EEH_Line_Item.helper.php 2 patches
Indentation   +2053 added lines, -2053 removed lines patch added patch discarded remove patch
@@ -22,2057 +22,2057 @@
 block discarded – undo
22 22
 class EEH_Line_Item
23 23
 {
24 24
 
25
-    /**
26
-     * Adds a simple item (unrelated to any other model object) to the provided PARENT line item.
27
-     * Does NOT automatically re-calculate the line item totals or update the related transaction.
28
-     * You should call recalculate_total_including_taxes() on the grant total line item after this
29
-     * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
30
-     * to keep the registration final prices in-sync with the transaction's total.
31
-     *
32
-     * @param EE_Line_Item $parent_line_item
33
-     * @param string       $name
34
-     * @param float        $unit_price
35
-     * @param string       $description
36
-     * @param int          $quantity
37
-     * @param boolean      $taxable
38
-     * @param boolean      $code if set to a value, ensures there is only one line item with that code
39
-     * @return boolean success
40
-     * @throws EE_Error
41
-     * @throws InvalidArgumentException
42
-     * @throws InvalidDataTypeException
43
-     * @throws InvalidInterfaceException
44
-     * @throws ReflectionException
45
-     */
46
-    public static function add_unrelated_item(
47
-        EE_Line_Item $parent_line_item,
48
-        $name,
49
-        $unit_price,
50
-        $description = '',
51
-        $quantity = 1,
52
-        $taxable = false,
53
-        $code = null
54
-    ) {
55
-        $items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
56
-        $line_item = EE_Line_Item::new_instance(array(
57
-            'LIN_name'       => $name,
58
-            'LIN_desc'       => $description,
59
-            'LIN_unit_price' => $unit_price,
60
-            'LIN_quantity'   => $quantity,
61
-            'LIN_percent'    => null,
62
-            'LIN_is_taxable' => $taxable,
63
-            'LIN_order'      => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
64
-            'LIN_total'      => (float) $unit_price * (int) $quantity,
65
-            'LIN_type'       => EEM_Line_Item::type_line_item,
66
-            'LIN_code'       => $code,
67
-        ));
68
-        $line_item = apply_filters(
69
-            'FHEE__EEH_Line_Item__add_unrelated_item__line_item',
70
-            $line_item,
71
-            $parent_line_item
72
-        );
73
-        return self::add_item($parent_line_item, $line_item);
74
-    }
75
-
76
-
77
-    /**
78
-     * Adds a simple item ( unrelated to any other model object) to the total line item,
79
-     * in the correct spot in the line item tree. Does not automatically
80
-     * re-calculate the line item totals, nor update the related transaction, nor upgrade the transaction's
81
-     * registrations' final prices (which should probably change because of this).
82
-     * You should call recalculate_total_including_taxes() on the grand total line item, then
83
-     * update the transaction's total, and EE_Registration_Processor::update_registration_final_prices()
84
-     * after using this, to keep the registration final prices in-sync with the transaction's total.
85
-     *
86
-     * @param EE_Line_Item $parent_line_item
87
-     * @param string       $name
88
-     * @param float        $percentage_amount
89
-     * @param string       $description
90
-     * @param boolean      $taxable
91
-     * @return boolean success
92
-     * @throws EE_Error
93
-     */
94
-    public static function add_percentage_based_item(
95
-        EE_Line_Item $parent_line_item,
96
-        $name,
97
-        $percentage_amount,
98
-        $description = '',
99
-        $taxable = false
100
-    ) {
101
-        $line_item = EE_Line_Item::new_instance(array(
102
-            'LIN_name'       => $name,
103
-            'LIN_desc'       => $description,
104
-            'LIN_unit_price' => 0,
105
-            'LIN_percent'    => $percentage_amount,
106
-            'LIN_quantity'   => 1,
107
-            'LIN_is_taxable' => $taxable,
108
-            'LIN_total'      => (float) ($percentage_amount * ($parent_line_item->total() / 100)),
109
-            'LIN_type'       => EEM_Line_Item::type_line_item,
110
-            'LIN_parent'     => $parent_line_item->ID(),
111
-        ));
112
-        $line_item = apply_filters(
113
-            'FHEE__EEH_Line_Item__add_percentage_based_item__line_item',
114
-            $line_item
115
-        );
116
-        return $parent_line_item->add_child_line_item($line_item, false);
117
-    }
118
-
119
-
120
-    /**
121
-     * Returns the new line item created by adding a purchase of the ticket
122
-     * ensures that ticket line item is saved, and that cart total has been recalculated.
123
-     * If this ticket has already been purchased, just increments its count.
124
-     * Automatically re-calculates the line item totals and updates the related transaction. But
125
-     * DOES NOT automatically upgrade the transaction's registrations' final prices (which
126
-     * should probably change because of this).
127
-     * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
128
-     * after using this, to keep the registration final prices in-sync with the transaction's total.
129
-     *
130
-     * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total
131
-     * @param EE_Ticket    $ticket
132
-     * @param int          $qty
133
-     * @return EE_Line_Item
134
-     * @throws EE_Error
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidInterfaceException
138
-     * @throws ReflectionException
139
-     */
140
-    public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1)
141
-    {
142
-        if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
143
-            throw new EE_Error(
144
-                sprintf(
145
-                    esc_html__(
146
-                        'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.',
147
-                        'event_espresso'
148
-                    ),
149
-                    $ticket->ID(),
150
-                    $total_line_item->ID()
151
-                )
152
-            );
153
-        }
154
-        // either increment the qty for an existing ticket
155
-        $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
156
-        // or add a new one
157
-        if (! $line_item instanceof EE_Line_Item) {
158
-            $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
159
-        }
160
-        $total_line_item->recalculate_total_including_taxes();
161
-        return $line_item;
162
-    }
163
-
164
-
165
-    /**
166
-     * Returns the new line item created by adding a purchase of the ticket
167
-     *
168
-     * @param EE_Line_Item $total_line_item
169
-     * @param EE_Ticket    $ticket
170
-     * @param int          $qty
171
-     * @return EE_Line_Item
172
-     * @throws EE_Error
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws ReflectionException
177
-     */
178
-    public static function increment_ticket_qty_if_already_in_cart(
179
-        EE_Line_Item $total_line_item,
180
-        EE_Ticket $ticket,
181
-        $qty = 1
182
-    ) {
183
-        $line_item = null;
184
-        if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
185
-            $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
186
-            foreach ((array) $ticket_line_items as $ticket_line_item) {
187
-                if (
188
-                    $ticket_line_item instanceof EE_Line_Item
189
-                    && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID()
190
-                ) {
191
-                    $line_item = $ticket_line_item;
192
-                    break;
193
-                }
194
-            }
195
-        }
196
-        if ($line_item instanceof EE_Line_Item) {
197
-            EEH_Line_Item::increment_quantity($line_item, $qty);
198
-            return $line_item;
199
-        }
200
-        return null;
201
-    }
202
-
203
-
204
-    /**
205
-     * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected).
206
-     * Does NOT save or recalculate other line items totals
207
-     *
208
-     * @param EE_Line_Item $line_item
209
-     * @param int          $qty
210
-     * @return void
211
-     * @throws EE_Error
212
-     * @throws InvalidArgumentException
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     * @throws ReflectionException
216
-     */
217
-    public static function increment_quantity(EE_Line_Item $line_item, $qty = 1)
218
-    {
219
-        if (! $line_item->is_percent()) {
220
-            $qty += $line_item->quantity();
221
-            $line_item->set_quantity($qty);
222
-            $line_item->set_total($line_item->unit_price() * $qty);
223
-            $line_item->save();
224
-        }
225
-        foreach ($line_item->children() as $child) {
226
-            if ($child->is_sub_line_item()) {
227
-                EEH_Line_Item::update_quantity($child, $qty);
228
-            }
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected).
235
-     * Does NOT save or recalculate other line items totals
236
-     *
237
-     * @param EE_Line_Item $line_item
238
-     * @param int          $qty
239
-     * @return void
240
-     * @throws EE_Error
241
-     * @throws InvalidArgumentException
242
-     * @throws InvalidDataTypeException
243
-     * @throws InvalidInterfaceException
244
-     * @throws ReflectionException
245
-     */
246
-    public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1)
247
-    {
248
-        if (! $line_item->is_percent()) {
249
-            $qty = $line_item->quantity() - $qty;
250
-            $qty = max($qty, 0);
251
-            $line_item->set_quantity($qty);
252
-            $line_item->set_total($line_item->unit_price() * $qty);
253
-            $line_item->save();
254
-        }
255
-        foreach ($line_item->children() as $child) {
256
-            if ($child->is_sub_line_item()) {
257
-                EEH_Line_Item::update_quantity($child, $qty);
258
-            }
259
-        }
260
-    }
261
-
262
-
263
-    /**
264
-     * Updates the line item and its children's quantities to the specified number.
265
-     * Does NOT save them or recalculate totals.
266
-     *
267
-     * @param EE_Line_Item $line_item
268
-     * @param int          $new_quantity
269
-     * @throws EE_Error
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     * @throws ReflectionException
274
-     */
275
-    public static function update_quantity(EE_Line_Item $line_item, $new_quantity)
276
-    {
277
-        if (! $line_item->is_percent()) {
278
-            $line_item->set_quantity($new_quantity);
279
-            $line_item->set_total($line_item->unit_price() * $new_quantity);
280
-            $line_item->save();
281
-        }
282
-        foreach ($line_item->children() as $child) {
283
-            if ($child->is_sub_line_item()) {
284
-                EEH_Line_Item::update_quantity($child, $new_quantity);
285
-            }
286
-        }
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns the new line item created by adding a purchase of the ticket
292
-     *
293
-     * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
294
-     * @param EE_Ticket    $ticket
295
-     * @param int          $qty
296
-     * @return EE_Line_Item
297
-     * @throws EE_Error
298
-     * @throws InvalidArgumentException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     * @throws ReflectionException
302
-     */
303
-    public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1)
304
-    {
305
-        $datetimes = $ticket->datetimes();
306
-        $first_datetime = reset($datetimes);
307
-        $first_datetime_name = esc_html__('Event', 'event_espresso');
308
-        if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) {
309
-            $first_datetime_name = $first_datetime->event()->name();
310
-        }
311
-        $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
312
-        // get event subtotal line
313
-        $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
314
-        // add $ticket to cart
315
-        $line_item = EE_Line_Item::new_instance(array(
316
-            'LIN_name'       => $ticket->name(),
317
-            'LIN_desc'       => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
318
-            'LIN_unit_price' => $ticket->price(),
319
-            'LIN_quantity'   => $qty,
320
-            'LIN_is_taxable' => $ticket->taxable(),
321
-            'LIN_order'      => count($events_sub_total->children()),
322
-            'LIN_total'      => $ticket->price() * $qty,
323
-            'LIN_type'       => EEM_Line_Item::type_line_item,
324
-            'OBJ_ID'         => $ticket->ID(),
325
-            'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_TICKET,
326
-        ));
327
-        $line_item = apply_filters(
328
-            'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
329
-            $line_item
330
-        );
331
-        $events_sub_total->add_child_line_item($line_item);
332
-        // now add the sub-line items
333
-        $running_total_for_ticket = 0;
334
-        foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
335
-            $sign = $price->is_discount() ? -1 : 1;
336
-            $price_total = $price->is_percent()
337
-                ? $running_total_for_ticket * $price->amount() / 100
338
-                : $price->amount() * $qty;
339
-            $sub_line_item = EE_Line_Item::new_instance(array(
340
-                'LIN_name'       => $price->name(),
341
-                'LIN_desc'       => $price->desc(),
342
-                'LIN_quantity'   => $price->is_percent() ? null : $qty,
343
-                'LIN_is_taxable' => false,
344
-                'LIN_order'      => $price->order(),
345
-                'LIN_total'      => $sign * $price_total,
346
-                'LIN_type'       => EEM_Line_Item::type_sub_line_item,
347
-                'OBJ_ID'         => $price->ID(),
348
-                'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_PRICE,
349
-            ));
350
-            $sub_line_item = apply_filters(
351
-                'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
352
-                $sub_line_item
353
-            );
354
-            if ($price->is_percent()) {
355
-                $sub_line_item->set_percent($sign * $price->amount());
356
-            } else {
357
-                $sub_line_item->set_unit_price($sign * $price->amount());
358
-            }
359
-            $running_total_for_ticket += $price_total;
360
-            $line_item->add_child_line_item($sub_line_item);
361
-        }
362
-        return $line_item;
363
-    }
364
-
365
-
366
-    /**
367
-     * Adds the specified item under the pre-tax-sub-total line item. Automatically
368
-     * re-calculates the line item totals and updates the related transaction. But
369
-     * DOES NOT automatically upgrade the transaction's registrations' final prices (which
370
-     * should probably change because of this).
371
-     * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
372
-     * after using this, to keep the registration final prices in-sync with the transaction's total.
373
-     *
374
-     * @param EE_Line_Item $total_line_item
375
-     * @param EE_Line_Item $item to be added
376
-     * @return boolean
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     * @throws InvalidDataTypeException
380
-     * @throws InvalidInterfaceException
381
-     * @throws ReflectionException
382
-     */
383
-    public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item)
384
-    {
385
-        $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
386
-        if ($pre_tax_subtotal instanceof EE_Line_Item) {
387
-            $success = $pre_tax_subtotal->add_child_line_item($item);
388
-        } else {
389
-            return false;
390
-        }
391
-        $total_line_item->recalculate_total_including_taxes();
392
-        return $success;
393
-    }
394
-
395
-
396
-    /**
397
-     * cancels an existing ticket line item,
398
-     * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item.
399
-     * ALL totals and subtotals will NEED TO BE UPDATED after performing this action
400
-     *
401
-     * @param EE_Line_Item $ticket_line_item
402
-     * @param int          $qty
403
-     * @return bool success
404
-     * @throws EE_Error
405
-     * @throws InvalidArgumentException
406
-     * @throws InvalidDataTypeException
407
-     * @throws InvalidInterfaceException
408
-     * @throws ReflectionException
409
-     */
410
-    public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1)
411
-    {
412
-        // validate incoming line_item
413
-        if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) {
414
-            throw new EE_Error(
415
-                sprintf(
416
-                    esc_html__(
417
-                        'The supplied line item must have an Object Type of "Ticket", not %1$s.',
418
-                        'event_espresso'
419
-                    ),
420
-                    $ticket_line_item->type()
421
-                )
422
-            );
423
-        }
424
-        if ($ticket_line_item->quantity() < $qty) {
425
-            throw new EE_Error(
426
-                sprintf(
427
-                    esc_html__(
428
-                        'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.',
429
-                        'event_espresso'
430
-                    ),
431
-                    $qty,
432
-                    $ticket_line_item->quantity()
433
-                )
434
-            );
435
-        }
436
-        // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this
437
-        $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty);
438
-        foreach ($ticket_line_item->children() as $child_line_item) {
439
-            if (
440
-                $child_line_item->is_sub_line_item()
441
-                && ! $child_line_item->is_percent()
442
-                && ! $child_line_item->is_cancellation()
443
-            ) {
444
-                $child_line_item->set_quantity($child_line_item->quantity() - $qty);
445
-            }
446
-        }
447
-        // get cancellation sub line item
448
-        $cancellation_line_item = EEH_Line_Item::get_descendants_of_type(
449
-            $ticket_line_item,
450
-            EEM_Line_Item::type_cancellation
451
-        );
452
-        $cancellation_line_item = reset($cancellation_line_item);
453
-        // verify that this ticket was indeed previously cancelled
454
-        if ($cancellation_line_item instanceof EE_Line_Item) {
455
-            // increment cancelled quantity
456
-            $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty);
457
-        } else {
458
-            // create cancellation sub line item
459
-            $cancellation_line_item = EE_Line_Item::new_instance(array(
460
-                'LIN_name'       => esc_html__('Cancellation', 'event_espresso'),
461
-                'LIN_desc'       => sprintf(
462
-                    esc_html_x(
463
-                        'Cancelled %1$s : %2$s',
464
-                        'Cancelled Ticket Name : 2015-01-01 11:11',
465
-                        'event_espresso'
466
-                    ),
467
-                    $ticket_line_item->name(),
468
-                    current_time(get_option('date_format') . ' ' . get_option('time_format'))
469
-                ),
470
-                'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
471
-                'LIN_quantity'   => $qty,
472
-                'LIN_is_taxable' => $ticket_line_item->is_taxable(),
473
-                'LIN_order'      => count($ticket_line_item->children()),
474
-                'LIN_total'      => 0, // $ticket_line_item->unit_price()
475
-                'LIN_type'       => EEM_Line_Item::type_cancellation,
476
-            ));
477
-            $ticket_line_item->add_child_line_item($cancellation_line_item);
478
-        }
479
-        if ($ticket_line_item->save_this_and_descendants() > 0) {
480
-            // decrement parent line item quantity
481
-            $event_line_item = $ticket_line_item->parent();
482
-            if (
483
-                $event_line_item instanceof EE_Line_Item
484
-                && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
485
-            ) {
486
-                $event_line_item->set_quantity($event_line_item->quantity() - $qty);
487
-                $event_line_item->save();
488
-            }
489
-            EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
490
-            return true;
491
-        }
492
-        return false;
493
-    }
494
-
495
-
496
-    /**
497
-     * reinstates (un-cancels?) a previously canceled ticket line item,
498
-     * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item.
499
-     * ALL totals and subtotals will NEED TO BE UPDATED after performing this action
500
-     *
501
-     * @param EE_Line_Item $ticket_line_item
502
-     * @param int          $qty
503
-     * @return bool success
504
-     * @throws EE_Error
505
-     * @throws InvalidArgumentException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidInterfaceException
508
-     * @throws ReflectionException
509
-     */
510
-    public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1)
511
-    {
512
-        // validate incoming line_item
513
-        if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) {
514
-            throw new EE_Error(
515
-                sprintf(
516
-                    esc_html__(
517
-                        'The supplied line item must have an Object Type of "Ticket", not %1$s.',
518
-                        'event_espresso'
519
-                    ),
520
-                    $ticket_line_item->type()
521
-                )
522
-            );
523
-        }
524
-        // get cancellation sub line item
525
-        $cancellation_line_item = EEH_Line_Item::get_descendants_of_type(
526
-            $ticket_line_item,
527
-            EEM_Line_Item::type_cancellation
528
-        );
529
-        $cancellation_line_item = reset($cancellation_line_item);
530
-        // verify that this ticket was indeed previously cancelled
531
-        if (! $cancellation_line_item instanceof EE_Line_Item) {
532
-            return false;
533
-        }
534
-        if ($cancellation_line_item->quantity() > $qty) {
535
-            // decrement cancelled quantity
536
-            $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
537
-        } elseif ($cancellation_line_item->quantity() === $qty) {
538
-            // decrement cancelled quantity in case anyone still has the object kicking around
539
-            $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
540
-            // delete because quantity will end up as 0
541
-            $cancellation_line_item->delete();
542
-            // and attempt to destroy the object,
543
-            // even though PHP won't actually destroy it until it needs the memory
544
-            unset($cancellation_line_item);
545
-        } else {
546
-            // what ?!?! negative quantity ?!?!
547
-            throw new EE_Error(
548
-                sprintf(
549
-                    esc_html__(
550
-                        'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
551
-                        'event_espresso'
552
-                    ),
553
-                    $qty,
554
-                    $cancellation_line_item->quantity()
555
-                )
556
-            );
557
-        }
558
-        // increment ticket quantity
559
-        $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty);
560
-        if ($ticket_line_item->save_this_and_descendants() > 0) {
561
-            // increment parent line item quantity
562
-            $event_line_item = $ticket_line_item->parent();
563
-            if (
564
-                $event_line_item instanceof EE_Line_Item
565
-                && $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
566
-            ) {
567
-                $event_line_item->set_quantity($event_line_item->quantity() + $qty);
568
-            }
569
-            EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
570
-            return true;
571
-        }
572
-        return false;
573
-    }
574
-
575
-
576
-    /**
577
-     * calls EEH_Line_Item::find_transaction_grand_total_for_line_item()
578
-     * then EE_Line_Item::recalculate_total_including_taxes() on the result
579
-     *
580
-     * @param EE_Line_Item $line_item
581
-     * @return float
582
-     * @throws EE_Error
583
-     * @throws InvalidArgumentException
584
-     * @throws InvalidDataTypeException
585
-     * @throws InvalidInterfaceException
586
-     * @throws ReflectionException
587
-     */
588
-    public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item)
589
-    {
590
-        $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item);
591
-        return $grand_total_line_item->recalculate_total_including_taxes();
592
-    }
593
-
594
-
595
-    /**
596
-     * Gets the line item which contains the subtotal of all the items
597
-     *
598
-     * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
599
-     * @return EE_Line_Item
600
-     * @throws EE_Error
601
-     * @throws InvalidArgumentException
602
-     * @throws InvalidDataTypeException
603
-     * @throws InvalidInterfaceException
604
-     * @throws ReflectionException
605
-     */
606
-    public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item)
607
-    {
608
-        $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
609
-        return $pre_tax_subtotal instanceof EE_Line_Item
610
-            ? $pre_tax_subtotal
611
-            : self::create_pre_tax_subtotal($total_line_item);
612
-    }
613
-
614
-
615
-    /**
616
-     * Gets the line item for the taxes subtotal
617
-     *
618
-     * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
619
-     * @return EE_Line_Item
620
-     * @throws EE_Error
621
-     * @throws InvalidArgumentException
622
-     * @throws InvalidDataTypeException
623
-     * @throws InvalidInterfaceException
624
-     * @throws ReflectionException
625
-     */
626
-    public static function get_taxes_subtotal(EE_Line_Item $total_line_item)
627
-    {
628
-        $taxes = $total_line_item->get_child_line_item('taxes');
629
-        return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
630
-    }
631
-
632
-
633
-    /**
634
-     * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object
635
-     *
636
-     * @param EE_Line_Item   $line_item
637
-     * @param EE_Transaction $transaction
638
-     * @return void
639
-     * @throws EE_Error
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidDataTypeException
642
-     * @throws InvalidInterfaceException
643
-     * @throws ReflectionException
644
-     */
645
-    public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null)
646
-    {
647
-        if ($transaction) {
648
-            /** @type EEM_Transaction $EEM_Transaction */
649
-            $EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
650
-            $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction);
651
-            $line_item->set_TXN_ID($TXN_ID);
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * Creates a new default total line item for the transaction,
658
-     * and its tickets subtotal and taxes subtotal line items (and adds the
659
-     * existing taxes as children of the taxes subtotal line item)
660
-     *
661
-     * @param EE_Transaction $transaction
662
-     * @return EE_Line_Item of type total
663
-     * @throws EE_Error
664
-     * @throws InvalidArgumentException
665
-     * @throws InvalidDataTypeException
666
-     * @throws InvalidInterfaceException
667
-     * @throws ReflectionException
668
-     */
669
-    public static function create_total_line_item($transaction = null)
670
-    {
671
-        $total_line_item = EE_Line_Item::new_instance(array(
672
-            'LIN_code' => 'total',
673
-            'LIN_name' => esc_html__('Grand Total', 'event_espresso'),
674
-            'LIN_type' => EEM_Line_Item::type_total,
675
-            'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION,
676
-        ));
677
-        $total_line_item = apply_filters(
678
-            'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
679
-            $total_line_item
680
-        );
681
-        self::set_TXN_ID($total_line_item, $transaction);
682
-        self::create_pre_tax_subtotal($total_line_item, $transaction);
683
-        self::create_taxes_subtotal($total_line_item, $transaction);
684
-        return $total_line_item;
685
-    }
686
-
687
-
688
-    /**
689
-     * Creates a default items subtotal line item
690
-     *
691
-     * @param EE_Line_Item   $total_line_item
692
-     * @param EE_Transaction $transaction
693
-     * @return EE_Line_Item
694
-     * @throws EE_Error
695
-     * @throws InvalidArgumentException
696
-     * @throws InvalidDataTypeException
697
-     * @throws InvalidInterfaceException
698
-     * @throws ReflectionException
699
-     */
700
-    protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null)
701
-    {
702
-        $pre_tax_line_item = EE_Line_Item::new_instance(array(
703
-            'LIN_code' => 'pre-tax-subtotal',
704
-            'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'),
705
-            'LIN_type' => EEM_Line_Item::type_sub_total,
706
-        ));
707
-        $pre_tax_line_item = apply_filters(
708
-            'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
709
-            $pre_tax_line_item
710
-        );
711
-        self::set_TXN_ID($pre_tax_line_item, $transaction);
712
-        $total_line_item->add_child_line_item($pre_tax_line_item);
713
-        self::create_event_subtotal($pre_tax_line_item, $transaction);
714
-        return $pre_tax_line_item;
715
-    }
716
-
717
-
718
-    /**
719
-     * Creates a line item for the taxes subtotal and finds all the tax prices
720
-     * and applies taxes to it
721
-     *
722
-     * @param EE_Line_Item   $total_line_item of type EEM_Line_Item::type_total
723
-     * @param EE_Transaction $transaction
724
-     * @return EE_Line_Item
725
-     * @throws EE_Error
726
-     * @throws InvalidArgumentException
727
-     * @throws InvalidDataTypeException
728
-     * @throws InvalidInterfaceException
729
-     * @throws ReflectionException
730
-     */
731
-    protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null)
732
-    {
733
-        $tax_line_item = EE_Line_Item::new_instance(array(
734
-            'LIN_code'  => 'taxes',
735
-            'LIN_name'  => esc_html__('Taxes', 'event_espresso'),
736
-            'LIN_type'  => EEM_Line_Item::type_tax_sub_total,
737
-            'LIN_order' => 1000,// this should always come last
738
-        ));
739
-        $tax_line_item = apply_filters(
740
-            'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
741
-            $tax_line_item
742
-        );
743
-        self::set_TXN_ID($tax_line_item, $transaction);
744
-        $total_line_item->add_child_line_item($tax_line_item);
745
-        // and lastly, add the actual taxes
746
-        self::apply_taxes($total_line_item);
747
-        return $tax_line_item;
748
-    }
749
-
750
-
751
-    /**
752
-     * Creates a default items subtotal line item
753
-     *
754
-     * @param EE_Line_Item   $pre_tax_line_item
755
-     * @param EE_Transaction $transaction
756
-     * @param EE_Event       $event
757
-     * @return EE_Line_Item
758
-     * @throws EE_Error
759
-     * @throws InvalidArgumentException
760
-     * @throws InvalidDataTypeException
761
-     * @throws InvalidInterfaceException
762
-     * @throws ReflectionException
763
-     */
764
-    public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null)
765
-    {
766
-        $event_line_item = EE_Line_Item::new_instance(array(
767
-            'LIN_code' => self::get_event_code($event),
768
-            'LIN_name' => self::get_event_name($event),
769
-            'LIN_desc' => self::get_event_desc($event),
770
-            'LIN_type' => EEM_Line_Item::type_sub_total,
771
-            'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT,
772
-            'OBJ_ID'   => $event instanceof EE_Event ? $event->ID() : 0,
773
-        ));
774
-        $event_line_item = apply_filters(
775
-            'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
776
-            $event_line_item
777
-        );
778
-        self::set_TXN_ID($event_line_item, $transaction);
779
-        $pre_tax_line_item->add_child_line_item($event_line_item);
780
-        return $event_line_item;
781
-    }
782
-
783
-
784
-    /**
785
-     * Gets what the event ticket's code SHOULD be
786
-     *
787
-     * @param EE_Event $event
788
-     * @return string
789
-     * @throws EE_Error
790
-     */
791
-    public static function get_event_code($event)
792
-    {
793
-        return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0');
794
-    }
795
-
796
-
797
-    /**
798
-     * Gets the event name
799
-     *
800
-     * @param EE_Event $event
801
-     * @return string
802
-     * @throws EE_Error
803
-     */
804
-    public static function get_event_name($event)
805
-    {
806
-        return $event instanceof EE_Event
807
-            ? mb_substr($event->name(), 0, 245)
808
-            : esc_html__('Event', 'event_espresso');
809
-    }
810
-
811
-
812
-    /**
813
-     * Gets the event excerpt
814
-     *
815
-     * @param EE_Event $event
816
-     * @return string
817
-     * @throws EE_Error
818
-     */
819
-    public static function get_event_desc($event)
820
-    {
821
-        return $event instanceof EE_Event ? $event->short_description() : '';
822
-    }
823
-
824
-
825
-    /**
826
-     * Given the grand total line item and a ticket, finds the event sub-total
827
-     * line item the ticket's purchase should be added onto
828
-     *
829
-     * @access public
830
-     * @param EE_Line_Item $grand_total the grand total line item
831
-     * @param EE_Ticket    $ticket
832
-     * @return EE_Line_Item
833
-     * @throws EE_Error
834
-     * @throws InvalidArgumentException
835
-     * @throws InvalidDataTypeException
836
-     * @throws InvalidInterfaceException
837
-     * @throws ReflectionException
838
-     */
839
-    public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket)
840
-    {
841
-        $first_datetime = $ticket->first_datetime();
842
-        if (! $first_datetime instanceof EE_Datetime) {
843
-            throw new EE_Error(
844
-                sprintf(
845
-                    esc_html__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'),
846
-                    $ticket->ID()
847
-                )
848
-            );
849
-        }
850
-        $event = $first_datetime->event();
851
-        if (! $event instanceof EE_Event) {
852
-            throw new EE_Error(
853
-                sprintf(
854
-                    esc_html__(
855
-                        'The supplied ticket (ID %d) has no event data associated with it.',
856
-                        'event_espresso'
857
-                    ),
858
-                    $ticket->ID()
859
-                )
860
-            );
861
-        }
862
-        $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
863
-        if (! $events_sub_total instanceof EE_Line_Item) {
864
-            throw new EE_Error(
865
-                sprintf(
866
-                    esc_html__(
867
-                        'There is no events sub-total for ticket %s on total line item %d',
868
-                        'event_espresso'
869
-                    ),
870
-                    $ticket->ID(),
871
-                    $grand_total->ID()
872
-                )
873
-            );
874
-        }
875
-        return $events_sub_total;
876
-    }
877
-
878
-
879
-    /**
880
-     * Gets the event line item
881
-     *
882
-     * @param EE_Line_Item $grand_total
883
-     * @param EE_Event     $event
884
-     * @return EE_Line_Item for the event subtotal which is a child of $grand_total
885
-     * @throws EE_Error
886
-     * @throws InvalidArgumentException
887
-     * @throws InvalidDataTypeException
888
-     * @throws InvalidInterfaceException
889
-     * @throws ReflectionException
890
-     */
891
-    public static function get_event_line_item(EE_Line_Item $grand_total, $event)
892
-    {
893
-        /** @type EE_Event $event */
894
-        $event = EEM_Event::instance()->ensure_is_obj($event, true);
895
-        $event_line_item = null;
896
-        $found = false;
897
-        foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
898
-            // default event subtotal, we should only ever find this the first time this method is called
899
-            if (! $event_line_item->OBJ_ID()) {
900
-                // let's use this! but first... set the event details
901
-                EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
902
-                $found = true;
903
-                break;
904
-            }
905
-            if ($event_line_item->OBJ_ID() === $event->ID()) {
906
-                // found existing line item for this event in the cart, so break out of loop and use this one
907
-                $found = true;
908
-                break;
909
-            }
910
-        }
911
-        if (! $found) {
912
-            // there is no event sub-total yet, so add it
913
-            $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
914
-            // create a new "event" subtotal below that
915
-            $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
916
-            // and set the event details
917
-            EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
918
-        }
919
-        return $event_line_item;
920
-    }
921
-
922
-
923
-    /**
924
-     * Creates a default items subtotal line item
925
-     *
926
-     * @param EE_Line_Item   $event_line_item
927
-     * @param EE_Event       $event
928
-     * @param EE_Transaction $transaction
929
-     * @return void
930
-     * @throws EE_Error
931
-     * @throws InvalidArgumentException
932
-     * @throws InvalidDataTypeException
933
-     * @throws InvalidInterfaceException
934
-     * @throws ReflectionException
935
-     */
936
-    public static function set_event_subtotal_details(
937
-        EE_Line_Item $event_line_item,
938
-        EE_Event $event,
939
-        $transaction = null
940
-    ) {
941
-        if ($event instanceof EE_Event) {
942
-            $event_line_item->set_code(self::get_event_code($event));
943
-            $event_line_item->set_name(self::get_event_name($event));
944
-            $event_line_item->set_desc(self::get_event_desc($event));
945
-            $event_line_item->set_OBJ_ID($event->ID());
946
-        }
947
-        self::set_TXN_ID($event_line_item, $transaction);
948
-    }
949
-
950
-
951
-    /**
952
-     * Finds what taxes should apply, adds them as tax line items under the taxes sub-total,
953
-     * and recalculates the taxes sub-total and the grand total. Resets the taxes, so
954
-     * any old taxes are removed
955
-     *
956
-     * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
957
-     * @param bool         $update_txn_status
958
-     * @return bool
959
-     * @throws EE_Error
960
-     * @throws InvalidArgumentException
961
-     * @throws InvalidDataTypeException
962
-     * @throws InvalidInterfaceException
963
-     * @throws ReflectionException
964
-     * @throws RuntimeException
965
-     */
966
-    public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false)
967
-    {
968
-        /** @type EEM_Price $EEM_Price */
969
-        $EEM_Price = EE_Registry::instance()->load_model('Price');
970
-        // get array of taxes via Price Model
971
-        $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
972
-        ksort($ordered_taxes);
973
-        $taxes_line_item = self::get_taxes_subtotal($total_line_item);
974
-        // just to be safe, remove its old tax line items
975
-        $deleted = $taxes_line_item->delete_children_line_items();
976
-        $updates = false;
977
-        // loop thru taxes
978
-        foreach ($ordered_taxes as $order => $taxes) {
979
-            foreach ($taxes as $tax) {
980
-                if ($tax instanceof EE_Price) {
981
-                    $tax_line_item = EE_Line_Item::new_instance(
982
-                        array(
983
-                            'LIN_name'       => $tax->name(),
984
-                            'LIN_desc'       => $tax->desc(),
985
-                            'LIN_percent'    => $tax->amount(),
986
-                            'LIN_is_taxable' => false,
987
-                            'LIN_order'      => $order,
988
-                            'LIN_total'      => 0,
989
-                            'LIN_type'       => EEM_Line_Item::type_tax,
990
-                            'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_PRICE,
991
-                            'OBJ_ID'         => $tax->ID(),
992
-                        )
993
-                    );
994
-                    $tax_line_item = apply_filters(
995
-                        'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
996
-                        $tax_line_item
997
-                    );
998
-                    $updates = $taxes_line_item->add_child_line_item($tax_line_item) ?
999
-                        true :
1000
-                        $updates;
1001
-                }
1002
-            }
1003
-        }
1004
-        // only recalculate totals if something changed
1005
-        if ($deleted || $updates) {
1006
-            $total_line_item->recalculate_total_including_taxes($update_txn_status);
1007
-            return true;
1008
-        }
1009
-        return false;
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     * Ensures that taxes have been applied to the order, if not applies them.
1015
-     * Returns the total amount of tax
1016
-     *
1017
-     * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
1018
-     * @return float
1019
-     * @throws EE_Error
1020
-     * @throws InvalidArgumentException
1021
-     * @throws InvalidDataTypeException
1022
-     * @throws InvalidInterfaceException
1023
-     * @throws ReflectionException
1024
-     */
1025
-    public static function ensure_taxes_applied($total_line_item)
1026
-    {
1027
-        $taxes_subtotal = self::get_taxes_subtotal($total_line_item);
1028
-        if (! $taxes_subtotal->children()) {
1029
-            self::apply_taxes($total_line_item);
1030
-        }
1031
-        return $taxes_subtotal->total();
1032
-    }
1033
-
1034
-
1035
-    /**
1036
-     * Deletes ALL children of the passed line item
1037
-     *
1038
-     * @param EE_Line_Item $parent_line_item
1039
-     * @return bool
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    public static function delete_all_child_items(EE_Line_Item $parent_line_item)
1047
-    {
1048
-        $deleted = 0;
1049
-        foreach ($parent_line_item->children() as $child_line_item) {
1050
-            if ($child_line_item instanceof EE_Line_Item) {
1051
-                $deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
1052
-                if ($child_line_item->ID()) {
1053
-                    $child_line_item->delete();
1054
-                    unset($child_line_item);
1055
-                } else {
1056
-                    $parent_line_item->delete_child_line_item($child_line_item->code());
1057
-                }
1058
-                $deleted++;
1059
-            }
1060
-        }
1061
-        return $deleted;
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * Deletes the line items as indicated by the line item code(s) provided,
1067
-     * regardless of where they're found in the line item tree. Automatically
1068
-     * re-calculates the line item totals and updates the related transaction. But
1069
-     * DOES NOT automatically upgrade the transaction's registrations' final prices (which
1070
-     * should probably change because of this).
1071
-     * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
1072
-     * after using this, to keep the registration final prices in-sync with the transaction's total.
1073
-     *
1074
-     * @param EE_Line_Item      $total_line_item of type EEM_Line_Item::type_total
1075
-     * @param array|bool|string $line_item_codes
1076
-     * @return int number of items successfully removed
1077
-     * @throws EE_Error
1078
-     */
1079
-    public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false)
1080
-    {
1081
-
1082
-        if ($total_line_item->type() !== EEM_Line_Item::type_total) {
1083
-            EE_Error::doing_it_wrong(
1084
-                'EEH_Line_Item::delete_items',
1085
-                esc_html__(
1086
-                    'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly',
1087
-                    'event_espresso'
1088
-                ),
1089
-                '4.6.18'
1090
-            );
1091
-        }
1092
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1093
-
1094
-        // check if only a single line_item_id was passed
1095
-        if (! empty($line_item_codes) && ! is_array($line_item_codes)) {
1096
-            // place single line_item_id in an array to appear as multiple line_item_ids
1097
-            $line_item_codes = array($line_item_codes);
1098
-        }
1099
-        $removals = 0;
1100
-        // cycle thru line_item_ids
1101
-        foreach ($line_item_codes as $line_item_id) {
1102
-            $removals += $total_line_item->delete_child_line_item($line_item_id);
1103
-        }
1104
-
1105
-        if ($removals > 0) {
1106
-            $total_line_item->recalculate_taxes_and_tax_total();
1107
-            return $removals;
1108
-        } else {
1109
-            return false;
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * Overwrites the previous tax by clearing out the old taxes, and creates a new
1116
-     * tax and updates the total line item accordingly
1117
-     *
1118
-     * @param EE_Line_Item $total_line_item
1119
-     * @param float        $amount
1120
-     * @param string       $name
1121
-     * @param string       $description
1122
-     * @param string       $code
1123
-     * @param boolean      $add_to_existing_line_item
1124
-     *                          if true, and a duplicate line item with the same code is found,
1125
-     *                          $amount will be added onto it; otherwise will simply set the taxes to match $amount
1126
-     * @return EE_Line_Item the new tax line item created
1127
-     * @throws EE_Error
1128
-     * @throws InvalidArgumentException
1129
-     * @throws InvalidDataTypeException
1130
-     * @throws InvalidInterfaceException
1131
-     * @throws ReflectionException
1132
-     */
1133
-    public static function set_total_tax_to(
1134
-        EE_Line_Item $total_line_item,
1135
-        $amount,
1136
-        $name = null,
1137
-        $description = null,
1138
-        $code = null,
1139
-        $add_to_existing_line_item = false
1140
-    ) {
1141
-        $tax_subtotal = self::get_taxes_subtotal($total_line_item);
1142
-        $taxable_total = $total_line_item->taxable_total();
1143
-
1144
-        if ($add_to_existing_line_item) {
1145
-            $new_tax = $tax_subtotal->get_child_line_item($code);
1146
-            EEM_Line_Item::instance()->delete(
1147
-                array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))
1148
-            );
1149
-        } else {
1150
-            $new_tax = null;
1151
-            $tax_subtotal->delete_children_line_items();
1152
-        }
1153
-        if ($new_tax) {
1154
-            $new_tax->set_total($new_tax->total() + $amount);
1155
-            $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0);
1156
-        } else {
1157
-            // no existing tax item. Create it
1158
-            $new_tax = EE_Line_Item::new_instance(array(
1159
-                'TXN_ID'      => $total_line_item->TXN_ID(),
1160
-                'LIN_name'    => $name ? $name : esc_html__('Tax', 'event_espresso'),
1161
-                'LIN_desc'    => $description ? $description : '',
1162
-                'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
1163
-                'LIN_total'   => $amount,
1164
-                'LIN_parent'  => $tax_subtotal->ID(),
1165
-                'LIN_type'    => EEM_Line_Item::type_tax,
1166
-                'LIN_code'    => $code,
1167
-            ));
1168
-        }
1169
-
1170
-        $new_tax = apply_filters(
1171
-            'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal',
1172
-            $new_tax,
1173
-            $total_line_item
1174
-        );
1175
-        $new_tax->save();
1176
-        $tax_subtotal->set_total($new_tax->total());
1177
-        $tax_subtotal->save();
1178
-        $total_line_item->recalculate_total_including_taxes();
1179
-        return $new_tax;
1180
-    }
1181
-
1182
-
1183
-    /**
1184
-     * Makes all the line items which are children of $line_item taxable (or not).
1185
-     * Does NOT save the line items
1186
-     *
1187
-     * @param EE_Line_Item $line_item
1188
-     * @param boolean      $taxable
1189
-     * @param string       $code_substring_for_whitelist if this string is part of the line item's code
1190
-     *                                                   it will be whitelisted (ie, except from becoming taxable)
1191
-     * @throws EE_Error
1192
-     */
1193
-    public static function set_line_items_taxable(
1194
-        EE_Line_Item $line_item,
1195
-        $taxable = true,
1196
-        $code_substring_for_whitelist = null
1197
-    ) {
1198
-        $whitelisted = false;
1199
-        if ($code_substring_for_whitelist !== null) {
1200
-            $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false;
1201
-        }
1202
-        if (! $whitelisted && $line_item->is_line_item()) {
1203
-            $line_item->set_is_taxable($taxable);
1204
-        }
1205
-        foreach ($line_item->children() as $child_line_item) {
1206
-            EEH_Line_Item::set_line_items_taxable(
1207
-                $child_line_item,
1208
-                $taxable,
1209
-                $code_substring_for_whitelist
1210
-            );
1211
-        }
1212
-    }
1213
-
1214
-
1215
-    /**
1216
-     * Gets all descendants that are event subtotals
1217
-     *
1218
-     * @uses  EEH_Line_Item::get_subtotals_of_object_type()
1219
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1220
-     * @return EE_Line_Item[]
1221
-     * @throws EE_Error
1222
-     */
1223
-    public static function get_event_subtotals(EE_Line_Item $parent_line_item)
1224
-    {
1225
-        return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT);
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * Gets all descendants subtotals that match the supplied object type
1231
-     *
1232
-     * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1233
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1234
-     * @param string       $obj_type
1235
-     * @return EE_Line_Item[]
1236
-     * @throws EE_Error
1237
-     */
1238
-    public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '')
1239
-    {
1240
-        return self::_get_descendants_by_type_and_object_type(
1241
-            $parent_line_item,
1242
-            EEM_Line_Item::type_sub_total,
1243
-            $obj_type
1244
-        );
1245
-    }
1246
-
1247
-
1248
-    /**
1249
-     * Gets all descendants that are tickets
1250
-     *
1251
-     * @uses  EEH_Line_Item::get_line_items_of_object_type()
1252
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1253
-     * @return EE_Line_Item[]
1254
-     * @throws EE_Error
1255
-     */
1256
-    public static function get_ticket_line_items(EE_Line_Item $parent_line_item)
1257
-    {
1258
-        return self::get_line_items_of_object_type(
1259
-            $parent_line_item,
1260
-            EEM_Line_Item::OBJ_TYPE_TICKET
1261
-        );
1262
-    }
1263
-
1264
-
1265
-    /**
1266
-     * Gets all descendants subtotals that match the supplied object type
1267
-     *
1268
-     * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1269
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1270
-     * @param string       $obj_type
1271
-     * @return EE_Line_Item[]
1272
-     * @throws EE_Error
1273
-     */
1274
-    public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '')
1275
-    {
1276
-        return self::_get_descendants_by_type_and_object_type(
1277
-            $parent_line_item,
1278
-            EEM_Line_Item::type_line_item,
1279
-            $obj_type
1280
-        );
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax'
1286
-     *
1287
-     * @uses  EEH_Line_Item::get_descendants_of_type()
1288
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1289
-     * @return EE_Line_Item[]
1290
-     * @throws EE_Error
1291
-     */
1292
-    public static function get_tax_descendants(EE_Line_Item $parent_line_item)
1293
-    {
1294
-        return EEH_Line_Item::get_descendants_of_type(
1295
-            $parent_line_item,
1296
-            EEM_Line_Item::type_tax
1297
-        );
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     * Gets all the real items purchased which are children of this item
1303
-     *
1304
-     * @uses  EEH_Line_Item::get_descendants_of_type()
1305
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1306
-     * @return EE_Line_Item[]
1307
-     * @throws EE_Error
1308
-     */
1309
-    public static function get_line_item_descendants(EE_Line_Item $parent_line_item)
1310
-    {
1311
-        return EEH_Line_Item::get_descendants_of_type(
1312
-            $parent_line_item,
1313
-            EEM_Line_Item::type_line_item
1314
-        );
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * Gets all descendants of supplied line item that match the supplied line item type
1320
-     *
1321
-     * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1322
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1323
-     * @param string       $line_item_type   one of the EEM_Line_Item constants
1324
-     * @return EE_Line_Item[]
1325
-     * @throws EE_Error
1326
-     */
1327
-    public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type)
1328
-    {
1329
-        return self::_get_descendants_by_type_and_object_type(
1330
-            $parent_line_item,
1331
-            $line_item_type,
1332
-            null
1333
-        );
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type
1339
-     * as well
1340
-     *
1341
-     * @param EE_Line_Item  $parent_line_item - the line item to find descendants of
1342
-     * @param string        $line_item_type   one of the EEM_Line_Item constants
1343
-     * @param string | NULL $obj_type         object model class name (minus prefix) or NULL to ignore object type when
1344
-     *                                        searching
1345
-     * @return EE_Line_Item[]
1346
-     * @throws EE_Error
1347
-     */
1348
-    protected static function _get_descendants_by_type_and_object_type(
1349
-        EE_Line_Item $parent_line_item,
1350
-        $line_item_type,
1351
-        $obj_type = null
1352
-    ) {
1353
-        $objects = array();
1354
-        foreach ($parent_line_item->children() as $child_line_item) {
1355
-            if ($child_line_item instanceof EE_Line_Item) {
1356
-                if (
1357
-                    $child_line_item->type() === $line_item_type
1358
-                    && (
1359
-                        $child_line_item->OBJ_type() === $obj_type || $obj_type === null
1360
-                    )
1361
-                ) {
1362
-                    $objects[] = $child_line_item;
1363
-                } else {
1364
-                    // go-through-all-its children looking for more matches
1365
-                    $objects = array_merge(
1366
-                        $objects,
1367
-                        self::_get_descendants_by_type_and_object_type(
1368
-                            $child_line_item,
1369
-                            $line_item_type,
1370
-                            $obj_type
1371
-                        )
1372
-                    );
1373
-                }
1374
-            }
1375
-        }
1376
-        return $objects;
1377
-    }
1378
-
1379
-
1380
-    /**
1381
-     * Gets all descendants subtotals that match the supplied object type
1382
-     *
1383
-     * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1384
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1385
-     * @param string       $OBJ_type         object type (like Event)
1386
-     * @param array        $OBJ_IDs          array of OBJ_IDs
1387
-     * @return EE_Line_Item[]
1388
-     * @throws EE_Error
1389
-     */
1390
-    public static function get_line_items_by_object_type_and_IDs(
1391
-        EE_Line_Item $parent_line_item,
1392
-        $OBJ_type = '',
1393
-        $OBJ_IDs = array()
1394
-    ) {
1395
-        return self::_get_descendants_by_object_type_and_object_ID(
1396
-            $parent_line_item,
1397
-            $OBJ_type,
1398
-            $OBJ_IDs
1399
-        );
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type
1405
-     * as well
1406
-     *
1407
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1408
-     * @param string       $OBJ_type         object type (like Event)
1409
-     * @param array        $OBJ_IDs          array of OBJ_IDs
1410
-     * @return EE_Line_Item[]
1411
-     * @throws EE_Error
1412
-     */
1413
-    protected static function _get_descendants_by_object_type_and_object_ID(
1414
-        EE_Line_Item $parent_line_item,
1415
-        $OBJ_type,
1416
-        $OBJ_IDs
1417
-    ) {
1418
-        $objects = array();
1419
-        foreach ($parent_line_item->children() as $child_line_item) {
1420
-            if ($child_line_item instanceof EE_Line_Item) {
1421
-                if (
1422
-                    $child_line_item->OBJ_type() === $OBJ_type
1423
-                    && is_array($OBJ_IDs)
1424
-                    && in_array($child_line_item->OBJ_ID(), $OBJ_IDs)
1425
-                ) {
1426
-                    $objects[] = $child_line_item;
1427
-                } else {
1428
-                    // go-through-all-its children looking for more matches
1429
-                    $objects = array_merge(
1430
-                        $objects,
1431
-                        self::_get_descendants_by_object_type_and_object_ID(
1432
-                            $child_line_item,
1433
-                            $OBJ_type,
1434
-                            $OBJ_IDs
1435
-                        )
1436
-                    );
1437
-                }
1438
-            }
1439
-        }
1440
-        return $objects;
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * Uses a breadth-first-search in order to find the nearest descendant of
1446
-     * the specified type and returns it, else NULL
1447
-     *
1448
-     * @uses  EEH_Line_Item::_get_nearest_descendant()
1449
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1450
-     * @param string       $type             like one of the EEM_Line_Item::type_*
1451
-     * @return EE_Line_Item
1452
-     * @throws EE_Error
1453
-     * @throws InvalidArgumentException
1454
-     * @throws InvalidDataTypeException
1455
-     * @throws InvalidInterfaceException
1456
-     * @throws ReflectionException
1457
-     */
1458
-    public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type)
1459
-    {
1460
-        return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
1461
-    }
1462
-
1463
-
1464
-    /**
1465
-     * Uses a breadth-first-search in order to find the nearest descendant
1466
-     * having the specified LIN_code and returns it, else NULL
1467
-     *
1468
-     * @uses  EEH_Line_Item::_get_nearest_descendant()
1469
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1470
-     * @param string       $code             any value used for LIN_code
1471
-     * @return EE_Line_Item
1472
-     * @throws EE_Error
1473
-     * @throws InvalidArgumentException
1474
-     * @throws InvalidDataTypeException
1475
-     * @throws InvalidInterfaceException
1476
-     * @throws ReflectionException
1477
-     */
1478
-    public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code)
1479
-    {
1480
-        return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
1481
-    }
1482
-
1483
-
1484
-    /**
1485
-     * Uses a breadth-first-search in order to find the nearest descendant
1486
-     * having the specified LIN_code and returns it, else NULL
1487
-     *
1488
-     * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1489
-     * @param string       $search_field     name of EE_Line_Item property
1490
-     * @param string       $value            any value stored in $search_field
1491
-     * @return EE_Line_Item
1492
-     * @throws EE_Error
1493
-     * @throws InvalidArgumentException
1494
-     * @throws InvalidDataTypeException
1495
-     * @throws InvalidInterfaceException
1496
-     * @throws ReflectionException
1497
-     */
1498
-    protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value)
1499
-    {
1500
-        foreach ($parent_line_item->children() as $child) {
1501
-            if ($child->get($search_field) == $value) {
1502
-                return $child;
1503
-            }
1504
-        }
1505
-        foreach ($parent_line_item->children() as $child) {
1506
-            $descendant_found = self::_get_nearest_descendant(
1507
-                $child,
1508
-                $search_field,
1509
-                $value
1510
-            );
1511
-            if ($descendant_found) {
1512
-                return $descendant_found;
1513
-            }
1514
-        }
1515
-        return null;
1516
-    }
1517
-
1518
-
1519
-    /**
1520
-     * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction,
1521
-     * else recursively walks up the line item tree until a parent of type total is found,
1522
-     *
1523
-     * @param EE_Line_Item $line_item
1524
-     * @return EE_Line_Item
1525
-     * @throws EE_Error
1526
-     */
1527
-    public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item)
1528
-    {
1529
-        if ($line_item->TXN_ID()) {
1530
-            $total_line_item = $line_item->transaction()->total_line_item(false);
1531
-            if ($total_line_item instanceof EE_Line_Item) {
1532
-                return $total_line_item;
1533
-            }
1534
-        } else {
1535
-            $line_item_parent = $line_item->parent();
1536
-            if ($line_item_parent instanceof EE_Line_Item) {
1537
-                if ($line_item_parent->is_total()) {
1538
-                    return $line_item_parent;
1539
-                }
1540
-                return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent);
1541
-            }
1542
-        }
1543
-        throw new EE_Error(
1544
-            sprintf(
1545
-                esc_html__(
1546
-                    'A valid grand total for line item %1$d was not found.',
1547
-                    'event_espresso'
1548
-                ),
1549
-                $line_item->ID()
1550
-            )
1551
-        );
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     * Prints out a representation of the line item tree
1557
-     *
1558
-     * @param EE_Line_Item $line_item
1559
-     * @param int          $indentation
1560
-     * @return void
1561
-     * @throws EE_Error
1562
-     */
1563
-    public static function visualize(EE_Line_Item $line_item, $indentation = 0)
1564
-    {
1565
-        echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1566
-        if (! $indentation) {
1567
-            echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1568
-        }
1569
-        for ($i = 0; $i < $indentation; $i++) {
1570
-            echo '. ';
1571
-        }
1572
-        $breakdown = '';
1573
-        if ($line_item->is_line_item()) {
1574
-            if ($line_item->is_percent()) {
1575
-                $breakdown = "{$line_item->percent()}%";
1576
-            } else {
1577
-                $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1578
-            }
1579
-        }
1580
-        echo wp_kses($line_item->name(), AllowedTags::getAllowedTags());
1581
-        echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ";
1582
-        echo '$' . (string) $line_item->total();
1583
-        if ($breakdown) {
1584
-            echo " ( {$breakdown} )";
1585
-        }
1586
-        if ($line_item->is_taxable()) {
1587
-            echo '  * taxable';
1588
-        }
1589
-        if ($line_item->children()) {
1590
-            foreach ($line_item->children() as $child) {
1591
-                self::visualize($child, $indentation + 1);
1592
-            }
1593
-        }
1594
-    }
1595
-
1596
-
1597
-    /**
1598
-     * Calculates the registration's final price, taking into account that they
1599
-     * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes,
1600
-     * and receive a portion of any transaction-wide discounts.
1601
-     * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount
1602
-     * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get
1603
-     * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50
1604
-     * and brent's final price should be $5.50.
1605
-     * In order to do this, we basically need to traverse the line item tree calculating
1606
-     * the running totals (just as if we were recalculating the total), but when we identify
1607
-     * regular line items, we need to keep track of their share of the grand total.
1608
-     * Also, we need to keep track of the TAXABLE total for each ticket purchase, so
1609
-     * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total"
1610
-     * when there are non-taxable items; otherwise they would be the same)
1611
-     *
1612
-     * @param EE_Line_Item $line_item
1613
-     * @param array        $billable_ticket_quantities  array of EE_Ticket IDs and their corresponding quantity that
1614
-     *                                                  can be included in price calculations at this moment
1615
-     * @return array        keys are line items for tickets IDs and values are their share of the running total,
1616
-     *                                                  plus the key 'total', and 'taxable' which also has keys of all
1617
-     *                                                  the ticket IDs.
1618
-     *                                                  Eg array(
1619
-     *                                                      12 => 4.3
1620
-     *                                                      23 => 8.0
1621
-     *                                                      'total' => 16.6,
1622
-     *                                                      'taxable' => array(
1623
-     *                                                          12 => 10,
1624
-     *                                                          23 => 4
1625
-     *                                                      ).
1626
-     *                                                  So to find which registrations have which final price, we need
1627
-     *                                                  to find which line item is theirs, which can be done with
1628
-     *                                                  `EEM_Line_Item::instance()->get_line_item_for_registration(
1629
-     *                                                  $registration );`
1630
-     * @throws EE_Error
1631
-     * @throws InvalidArgumentException
1632
-     * @throws InvalidDataTypeException
1633
-     * @throws InvalidInterfaceException
1634
-     * @throws ReflectionException
1635
-     */
1636
-    public static function calculate_reg_final_prices_per_line_item(
1637
-        EE_Line_Item $line_item,
1638
-        $billable_ticket_quantities = array()
1639
-    ) {
1640
-        $running_totals = [
1641
-            'total'   => 0,
1642
-            'taxable' => ['total' => 0]
1643
-        ];
1644
-        foreach ($line_item->children() as $child_line_item) {
1645
-            switch ($child_line_item->type()) {
1646
-                case EEM_Line_Item::type_sub_total:
1647
-                    $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1648
-                        $child_line_item,
1649
-                        $billable_ticket_quantities
1650
-                    );
1651
-                    // combine arrays but preserve numeric keys
1652
-                    $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1653
-                    $running_totals['total'] += $running_totals_from_subtotal['total'];
1654
-                    $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1655
-                    break;
1656
-
1657
-                case EEM_Line_Item::type_tax_sub_total:
1658
-                    // find how much the taxes percentage is
1659
-                    if ($child_line_item->percent() !== 0) {
1660
-                        $tax_percent_decimal = $child_line_item->percent() / 100;
1661
-                    } else {
1662
-                        $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1663
-                    }
1664
-                    // and apply to all the taxable totals, and add to the pretax totals
1665
-                    foreach ($running_totals as $line_item_id => $this_running_total) {
1666
-                        // "total" and "taxable" array key is an exception
1667
-                        if ($line_item_id === 'taxable') {
1668
-                            continue;
1669
-                        }
1670
-                        $taxable_total = $running_totals['taxable'][ $line_item_id ];
1671
-                        $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal);
1672
-                    }
1673
-                    break;
1674
-
1675
-                case EEM_Line_Item::type_line_item:
1676
-                    // ticket line items or ????
1677
-                    if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) {
1678
-                        // kk it's a ticket
1679
-                        if (isset($running_totals[ $child_line_item->ID() ])) {
1680
-                            // huh? that shouldn't happen.
1681
-                            $running_totals['total'] += $child_line_item->total();
1682
-                        } else {
1683
-                            // its not in our running totals yet. great.
1684
-                            if ($child_line_item->is_taxable()) {
1685
-                                $taxable_amount = $child_line_item->unit_price();
1686
-                            } else {
1687
-                                $taxable_amount = 0;
1688
-                            }
1689
-                            // are we only calculating totals for some tickets?
1690
-                            if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) {
1691
-                                $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1692
-                                $running_totals[ $child_line_item->ID() ] = $quantity
1693
-                                    ? $child_line_item->unit_price()
1694
-                                    : 0;
1695
-                                $running_totals['taxable'][ $child_line_item->ID() ] = $quantity
1696
-                                    ? $taxable_amount
1697
-                                    : 0;
1698
-                            } else {
1699
-                                $quantity = $child_line_item->quantity();
1700
-                                $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1701
-                                $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount;
1702
-                            }
1703
-                            $running_totals['taxable']['total'] += $taxable_amount * $quantity;
1704
-                            $running_totals['total'] += $child_line_item->unit_price() * $quantity;
1705
-                        }
1706
-                    } else {
1707
-                        // it's some other type of item added to the cart
1708
-                        // it should affect the running totals
1709
-                        // basically we want to convert it into a PERCENT modifier. Because
1710
-                        // more clearly affect all registration's final price equally
1711
-                        $line_items_percent_of_running_total = $running_totals['total'] > 0
1712
-                            ? ($child_line_item->total() / $running_totals['total']) + 1
1713
-                            : 1;
1714
-                        foreach ($running_totals as $line_item_id => $this_running_total) {
1715
-                            // the "taxable" array key is an exception
1716
-                            if ($line_item_id === 'taxable') {
1717
-                                continue;
1718
-                            }
1719
-                            // update the running totals
1720
-                            // yes this actually even works for the running grand total!
1721
-                            $running_totals[ $line_item_id ] =
1722
-                                $line_items_percent_of_running_total * $this_running_total;
1723
-
1724
-                            if ($child_line_item->is_taxable()) {
1725
-                                $running_totals['taxable'][ $line_item_id ] =
1726
-                                    $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ];
1727
-                            }
1728
-                        }
1729
-                    }
1730
-                    break;
1731
-            }
1732
-        }
1733
-        return $running_totals;
1734
-    }
1735
-
1736
-
1737
-    /**
1738
-     * @param EE_Line_Item $total_line_item
1739
-     * @param EE_Line_Item $ticket_line_item
1740
-     * @return float | null
1741
-     * @throws EE_Error
1742
-     * @throws InvalidArgumentException
1743
-     * @throws InvalidDataTypeException
1744
-     * @throws InvalidInterfaceException
1745
-     * @throws OutOfRangeException
1746
-     * @throws ReflectionException
1747
-     */
1748
-    public static function calculate_final_price_for_ticket_line_item(
1749
-        EE_Line_Item $total_line_item,
1750
-        EE_Line_Item $ticket_line_item
1751
-    ) {
1752
-        static $final_prices_per_ticket_line_item = array();
1753
-        if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[ $total_line_item->ID() ])) {
1754
-            $final_prices_per_ticket_line_item[ $total_line_item->ID() ] = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1755
-                $total_line_item
1756
-            );
1757
-        }
1758
-        // ok now find this new registration's final price
1759
-        if (isset($final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ])) {
1760
-            return $final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ];
1761
-        }
1762
-        $message = sprintf(
1763
-            esc_html__(
1764
-                'The final price for the ticket line item (ID:%1$d) could not be calculated.',
1765
-                'event_espresso'
1766
-            ),
1767
-            $ticket_line_item->ID()
1768
-        );
1769
-        if (WP_DEBUG) {
1770
-            $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true);
1771
-            throw new OutOfRangeException($message);
1772
-        }
1773
-        EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
1774
-        return null;
1775
-    }
1776
-
1777
-
1778
-    /**
1779
-     * Creates a duplicate of the line item tree, except only includes billable items
1780
-     * and the portion of line items attributed to billable things
1781
-     *
1782
-     * @param EE_Line_Item      $line_item
1783
-     * @param EE_Registration[] $registrations
1784
-     * @return EE_Line_Item
1785
-     * @throws EE_Error
1786
-     * @throws InvalidArgumentException
1787
-     * @throws InvalidDataTypeException
1788
-     * @throws InvalidInterfaceException
1789
-     * @throws ReflectionException
1790
-     */
1791
-    public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations)
1792
-    {
1793
-        $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1794
-        foreach ($line_item->children() as $child_li) {
1795
-            $copy_li->add_child_line_item(
1796
-                EEH_Line_Item::billable_line_item_tree($child_li, $registrations)
1797
-            );
1798
-        }
1799
-        // if this is the grand total line item, make sure the totals all add up
1800
-        // (we could have duplicated this logic AS we copied the line items, but
1801
-        // it seems DRYer this way)
1802
-        if ($copy_li->type() === EEM_Line_Item::type_total) {
1803
-            $copy_li->recalculate_total_including_taxes();
1804
-        }
1805
-        return $copy_li;
1806
-    }
1807
-
1808
-
1809
-    /**
1810
-     * Creates a new, unsaved line item from $line_item that factors in the
1811
-     * number of billable registrations on $registrations.
1812
-     *
1813
-     * @param EE_Line_Item      $line_item
1814
-     * @param EE_Registration[] $registrations
1815
-     * @return EE_Line_Item
1816
-     * @throws EE_Error
1817
-     * @throws InvalidArgumentException
1818
-     * @throws InvalidDataTypeException
1819
-     * @throws InvalidInterfaceException
1820
-     * @throws ReflectionException
1821
-     */
1822
-    public static function billable_line_item(EE_Line_Item $line_item, $registrations)
1823
-    {
1824
-        $new_li_fields = $line_item->model_field_array();
1825
-        if (
1826
-            $line_item->type() === EEM_Line_Item::type_line_item &&
1827
-            $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1828
-        ) {
1829
-            $count = 0;
1830
-            foreach ($registrations as $registration) {
1831
-                if (
1832
-                    $line_item->OBJ_ID() === $registration->ticket_ID() &&
1833
-                    in_array(
1834
-                        $registration->status_ID(),
1835
-                        EEM_Registration::reg_statuses_that_allow_payment(),
1836
-                        true
1837
-                    )
1838
-                ) {
1839
-                    $count++;
1840
-                }
1841
-            }
1842
-            $new_li_fields['LIN_quantity'] = $count;
1843
-        }
1844
-        // don't set the total. We'll leave that up to the code that calculates it
1845
-        unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']);
1846
-        return EE_Line_Item::new_instance($new_li_fields);
1847
-    }
1848
-
1849
-
1850
-    /**
1851
-     * Returns a modified line item tree where all the subtotals which have a total of 0
1852
-     * are removed, and line items with a quantity of 0
1853
-     *
1854
-     * @param EE_Line_Item $line_item |null
1855
-     * @return EE_Line_Item|null
1856
-     * @throws EE_Error
1857
-     * @throws InvalidArgumentException
1858
-     * @throws InvalidDataTypeException
1859
-     * @throws InvalidInterfaceException
1860
-     * @throws ReflectionException
1861
-     */
1862
-    public static function non_empty_line_items(EE_Line_Item $line_item)
1863
-    {
1864
-        $copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1865
-        if ($copied_li === null) {
1866
-            return null;
1867
-        }
1868
-        // if this is an event subtotal, we want to only include it if it
1869
-        // has a non-zero total and at least one ticket line item child
1870
-        $ticket_children = 0;
1871
-        foreach ($line_item->children() as $child_li) {
1872
-            $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1873
-            if ($child_li_copy !== null) {
1874
-                $copied_li->add_child_line_item($child_li_copy);
1875
-                if (
1876
-                    $child_li_copy->type() === EEM_Line_Item::type_line_item &&
1877
-                    $child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1878
-                ) {
1879
-                    $ticket_children++;
1880
-                }
1881
-            }
1882
-        }
1883
-        // if this is an event subtotal with NO ticket children
1884
-        // we basically want to ignore it
1885
-        if (
1886
-            $ticket_children === 0
1887
-            && $line_item->type() === EEM_Line_Item::type_sub_total
1888
-            && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
1889
-            && $line_item->total() === 0
1890
-        ) {
1891
-            return null;
1892
-        }
1893
-        return $copied_li;
1894
-    }
1895
-
1896
-
1897
-    /**
1898
-     * Creates a new, unsaved line item, but if it's a ticket line item
1899
-     * with a total of 0, or a subtotal of 0, returns null instead
1900
-     *
1901
-     * @param EE_Line_Item $line_item
1902
-     * @return EE_Line_Item
1903
-     * @throws EE_Error
1904
-     * @throws InvalidArgumentException
1905
-     * @throws InvalidDataTypeException
1906
-     * @throws InvalidInterfaceException
1907
-     * @throws ReflectionException
1908
-     */
1909
-    public static function non_empty_line_item(EE_Line_Item $line_item)
1910
-    {
1911
-        if (
1912
-            $line_item->type() === EEM_Line_Item::type_line_item
1913
-            && $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1914
-            && $line_item->quantity() === 0
1915
-        ) {
1916
-            return null;
1917
-        }
1918
-        $new_li_fields = $line_item->model_field_array();
1919
-        // don't set the total. We'll leave that up to the code that calculates it
1920
-        unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']);
1921
-        return EE_Line_Item::new_instance($new_li_fields);
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * Cycles through all of the ticket line items for the supplied total line item
1927
-     * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket
1928
-     *
1929
-     * @param EE_Line_Item $total_line_item
1930
-     * @since 4.9.79.p
1931
-     * @throws EE_Error
1932
-     * @throws InvalidArgumentException
1933
-     * @throws InvalidDataTypeException
1934
-     * @throws InvalidInterfaceException
1935
-     * @throws ReflectionException
1936
-     */
1937
-    public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item)
1938
-    {
1939
-        $ticket_line_items = self::get_ticket_line_items($total_line_item);
1940
-        foreach ($ticket_line_items as $ticket_line_item) {
1941
-            if (
1942
-                $ticket_line_item instanceof EE_Line_Item
1943
-                && $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1944
-            ) {
1945
-                $ticket = $ticket_line_item->ticket();
1946
-                if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) {
1947
-                    $ticket_line_item->set_is_taxable($ticket->taxable());
1948
-                    $ticket_line_item->save();
1949
-                }
1950
-            }
1951
-        }
1952
-    }
1953
-
1954
-
1955
-
1956
-    /**************************************** @DEPRECATED METHODS *************************************** */
1957
-    /**
1958
-     * @deprecated
1959
-     * @param EE_Line_Item $total_line_item
1960
-     * @return EE_Line_Item
1961
-     * @throws EE_Error
1962
-     * @throws InvalidArgumentException
1963
-     * @throws InvalidDataTypeException
1964
-     * @throws InvalidInterfaceException
1965
-     * @throws ReflectionException
1966
-     */
1967
-    public static function get_items_subtotal(EE_Line_Item $total_line_item)
1968
-    {
1969
-        EE_Error::doing_it_wrong(
1970
-            'EEH_Line_Item::get_items_subtotal()',
1971
-            sprintf(
1972
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
1973
-                'EEH_Line_Item::get_pre_tax_subtotal()'
1974
-            ),
1975
-            '4.6.0'
1976
-        );
1977
-        return self::get_pre_tax_subtotal($total_line_item);
1978
-    }
1979
-
1980
-
1981
-    /**
1982
-     * @deprecated
1983
-     * @param EE_Transaction $transaction
1984
-     * @return EE_Line_Item
1985
-     * @throws EE_Error
1986
-     * @throws InvalidArgumentException
1987
-     * @throws InvalidDataTypeException
1988
-     * @throws InvalidInterfaceException
1989
-     * @throws ReflectionException
1990
-     */
1991
-    public static function create_default_total_line_item($transaction = null)
1992
-    {
1993
-        EE_Error::doing_it_wrong(
1994
-            'EEH_Line_Item::create_default_total_line_item()',
1995
-            sprintf(
1996
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
1997
-                'EEH_Line_Item::create_total_line_item()'
1998
-            ),
1999
-            '4.6.0'
2000
-        );
2001
-        return self::create_total_line_item($transaction);
2002
-    }
2003
-
2004
-
2005
-    /**
2006
-     * @deprecated
2007
-     * @param EE_Line_Item   $total_line_item
2008
-     * @param EE_Transaction $transaction
2009
-     * @return EE_Line_Item
2010
-     * @throws EE_Error
2011
-     * @throws InvalidArgumentException
2012
-     * @throws InvalidDataTypeException
2013
-     * @throws InvalidInterfaceException
2014
-     * @throws ReflectionException
2015
-     */
2016
-    public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2017
-    {
2018
-        EE_Error::doing_it_wrong(
2019
-            'EEH_Line_Item::create_default_tickets_subtotal()',
2020
-            sprintf(
2021
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
2022
-                'EEH_Line_Item::create_pre_tax_subtotal()'
2023
-            ),
2024
-            '4.6.0'
2025
-        );
2026
-        return self::create_pre_tax_subtotal($total_line_item, $transaction);
2027
-    }
2028
-
2029
-
2030
-    /**
2031
-     * @deprecated
2032
-     * @param EE_Line_Item   $total_line_item
2033
-     * @param EE_Transaction $transaction
2034
-     * @return EE_Line_Item
2035
-     * @throws EE_Error
2036
-     * @throws InvalidArgumentException
2037
-     * @throws InvalidDataTypeException
2038
-     * @throws InvalidInterfaceException
2039
-     * @throws ReflectionException
2040
-     */
2041
-    public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2042
-    {
2043
-        EE_Error::doing_it_wrong(
2044
-            'EEH_Line_Item::create_default_taxes_subtotal()',
2045
-            sprintf(
2046
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
2047
-                'EEH_Line_Item::create_taxes_subtotal()'
2048
-            ),
2049
-            '4.6.0'
2050
-        );
2051
-        return self::create_taxes_subtotal($total_line_item, $transaction);
2052
-    }
2053
-
2054
-
2055
-    /**
2056
-     * @deprecated
2057
-     * @param EE_Line_Item   $total_line_item
2058
-     * @param EE_Transaction $transaction
2059
-     * @return EE_Line_Item
2060
-     * @throws EE_Error
2061
-     * @throws InvalidArgumentException
2062
-     * @throws InvalidDataTypeException
2063
-     * @throws InvalidInterfaceException
2064
-     * @throws ReflectionException
2065
-     */
2066
-    public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2067
-    {
2068
-        EE_Error::doing_it_wrong(
2069
-            'EEH_Line_Item::create_default_event_subtotal()',
2070
-            sprintf(
2071
-                esc_html__('Method replaced with %1$s', 'event_espresso'),
2072
-                'EEH_Line_Item::create_event_subtotal()'
2073
-            ),
2074
-            '4.6.0'
2075
-        );
2076
-        return self::create_event_subtotal($total_line_item, $transaction);
2077
-    }
25
+	/**
26
+	 * Adds a simple item (unrelated to any other model object) to the provided PARENT line item.
27
+	 * Does NOT automatically re-calculate the line item totals or update the related transaction.
28
+	 * You should call recalculate_total_including_taxes() on the grant total line item after this
29
+	 * to update the subtotals, and EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
30
+	 * to keep the registration final prices in-sync with the transaction's total.
31
+	 *
32
+	 * @param EE_Line_Item $parent_line_item
33
+	 * @param string       $name
34
+	 * @param float        $unit_price
35
+	 * @param string       $description
36
+	 * @param int          $quantity
37
+	 * @param boolean      $taxable
38
+	 * @param boolean      $code if set to a value, ensures there is only one line item with that code
39
+	 * @return boolean success
40
+	 * @throws EE_Error
41
+	 * @throws InvalidArgumentException
42
+	 * @throws InvalidDataTypeException
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws ReflectionException
45
+	 */
46
+	public static function add_unrelated_item(
47
+		EE_Line_Item $parent_line_item,
48
+		$name,
49
+		$unit_price,
50
+		$description = '',
51
+		$quantity = 1,
52
+		$taxable = false,
53
+		$code = null
54
+	) {
55
+		$items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
56
+		$line_item = EE_Line_Item::new_instance(array(
57
+			'LIN_name'       => $name,
58
+			'LIN_desc'       => $description,
59
+			'LIN_unit_price' => $unit_price,
60
+			'LIN_quantity'   => $quantity,
61
+			'LIN_percent'    => null,
62
+			'LIN_is_taxable' => $taxable,
63
+			'LIN_order'      => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
64
+			'LIN_total'      => (float) $unit_price * (int) $quantity,
65
+			'LIN_type'       => EEM_Line_Item::type_line_item,
66
+			'LIN_code'       => $code,
67
+		));
68
+		$line_item = apply_filters(
69
+			'FHEE__EEH_Line_Item__add_unrelated_item__line_item',
70
+			$line_item,
71
+			$parent_line_item
72
+		);
73
+		return self::add_item($parent_line_item, $line_item);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Adds a simple item ( unrelated to any other model object) to the total line item,
79
+	 * in the correct spot in the line item tree. Does not automatically
80
+	 * re-calculate the line item totals, nor update the related transaction, nor upgrade the transaction's
81
+	 * registrations' final prices (which should probably change because of this).
82
+	 * You should call recalculate_total_including_taxes() on the grand total line item, then
83
+	 * update the transaction's total, and EE_Registration_Processor::update_registration_final_prices()
84
+	 * after using this, to keep the registration final prices in-sync with the transaction's total.
85
+	 *
86
+	 * @param EE_Line_Item $parent_line_item
87
+	 * @param string       $name
88
+	 * @param float        $percentage_amount
89
+	 * @param string       $description
90
+	 * @param boolean      $taxable
91
+	 * @return boolean success
92
+	 * @throws EE_Error
93
+	 */
94
+	public static function add_percentage_based_item(
95
+		EE_Line_Item $parent_line_item,
96
+		$name,
97
+		$percentage_amount,
98
+		$description = '',
99
+		$taxable = false
100
+	) {
101
+		$line_item = EE_Line_Item::new_instance(array(
102
+			'LIN_name'       => $name,
103
+			'LIN_desc'       => $description,
104
+			'LIN_unit_price' => 0,
105
+			'LIN_percent'    => $percentage_amount,
106
+			'LIN_quantity'   => 1,
107
+			'LIN_is_taxable' => $taxable,
108
+			'LIN_total'      => (float) ($percentage_amount * ($parent_line_item->total() / 100)),
109
+			'LIN_type'       => EEM_Line_Item::type_line_item,
110
+			'LIN_parent'     => $parent_line_item->ID(),
111
+		));
112
+		$line_item = apply_filters(
113
+			'FHEE__EEH_Line_Item__add_percentage_based_item__line_item',
114
+			$line_item
115
+		);
116
+		return $parent_line_item->add_child_line_item($line_item, false);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Returns the new line item created by adding a purchase of the ticket
122
+	 * ensures that ticket line item is saved, and that cart total has been recalculated.
123
+	 * If this ticket has already been purchased, just increments its count.
124
+	 * Automatically re-calculates the line item totals and updates the related transaction. But
125
+	 * DOES NOT automatically upgrade the transaction's registrations' final prices (which
126
+	 * should probably change because of this).
127
+	 * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
128
+	 * after using this, to keep the registration final prices in-sync with the transaction's total.
129
+	 *
130
+	 * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total
131
+	 * @param EE_Ticket    $ticket
132
+	 * @param int          $qty
133
+	 * @return EE_Line_Item
134
+	 * @throws EE_Error
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidInterfaceException
138
+	 * @throws ReflectionException
139
+	 */
140
+	public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1)
141
+	{
142
+		if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
143
+			throw new EE_Error(
144
+				sprintf(
145
+					esc_html__(
146
+						'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.',
147
+						'event_espresso'
148
+					),
149
+					$ticket->ID(),
150
+					$total_line_item->ID()
151
+				)
152
+			);
153
+		}
154
+		// either increment the qty for an existing ticket
155
+		$line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
156
+		// or add a new one
157
+		if (! $line_item instanceof EE_Line_Item) {
158
+			$line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
159
+		}
160
+		$total_line_item->recalculate_total_including_taxes();
161
+		return $line_item;
162
+	}
163
+
164
+
165
+	/**
166
+	 * Returns the new line item created by adding a purchase of the ticket
167
+	 *
168
+	 * @param EE_Line_Item $total_line_item
169
+	 * @param EE_Ticket    $ticket
170
+	 * @param int          $qty
171
+	 * @return EE_Line_Item
172
+	 * @throws EE_Error
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws ReflectionException
177
+	 */
178
+	public static function increment_ticket_qty_if_already_in_cart(
179
+		EE_Line_Item $total_line_item,
180
+		EE_Ticket $ticket,
181
+		$qty = 1
182
+	) {
183
+		$line_item = null;
184
+		if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
185
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
186
+			foreach ((array) $ticket_line_items as $ticket_line_item) {
187
+				if (
188
+					$ticket_line_item instanceof EE_Line_Item
189
+					&& (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID()
190
+				) {
191
+					$line_item = $ticket_line_item;
192
+					break;
193
+				}
194
+			}
195
+		}
196
+		if ($line_item instanceof EE_Line_Item) {
197
+			EEH_Line_Item::increment_quantity($line_item, $qty);
198
+			return $line_item;
199
+		}
200
+		return null;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected).
206
+	 * Does NOT save or recalculate other line items totals
207
+	 *
208
+	 * @param EE_Line_Item $line_item
209
+	 * @param int          $qty
210
+	 * @return void
211
+	 * @throws EE_Error
212
+	 * @throws InvalidArgumentException
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 * @throws ReflectionException
216
+	 */
217
+	public static function increment_quantity(EE_Line_Item $line_item, $qty = 1)
218
+	{
219
+		if (! $line_item->is_percent()) {
220
+			$qty += $line_item->quantity();
221
+			$line_item->set_quantity($qty);
222
+			$line_item->set_total($line_item->unit_price() * $qty);
223
+			$line_item->save();
224
+		}
225
+		foreach ($line_item->children() as $child) {
226
+			if ($child->is_sub_line_item()) {
227
+				EEH_Line_Item::update_quantity($child, $qty);
228
+			}
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * Decrements the line item and all its children's quantity by $qty (but percent line items are unaffected).
235
+	 * Does NOT save or recalculate other line items totals
236
+	 *
237
+	 * @param EE_Line_Item $line_item
238
+	 * @param int          $qty
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 * @throws InvalidArgumentException
242
+	 * @throws InvalidDataTypeException
243
+	 * @throws InvalidInterfaceException
244
+	 * @throws ReflectionException
245
+	 */
246
+	public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1)
247
+	{
248
+		if (! $line_item->is_percent()) {
249
+			$qty = $line_item->quantity() - $qty;
250
+			$qty = max($qty, 0);
251
+			$line_item->set_quantity($qty);
252
+			$line_item->set_total($line_item->unit_price() * $qty);
253
+			$line_item->save();
254
+		}
255
+		foreach ($line_item->children() as $child) {
256
+			if ($child->is_sub_line_item()) {
257
+				EEH_Line_Item::update_quantity($child, $qty);
258
+			}
259
+		}
260
+	}
261
+
262
+
263
+	/**
264
+	 * Updates the line item and its children's quantities to the specified number.
265
+	 * Does NOT save them or recalculate totals.
266
+	 *
267
+	 * @param EE_Line_Item $line_item
268
+	 * @param int          $new_quantity
269
+	 * @throws EE_Error
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 * @throws ReflectionException
274
+	 */
275
+	public static function update_quantity(EE_Line_Item $line_item, $new_quantity)
276
+	{
277
+		if (! $line_item->is_percent()) {
278
+			$line_item->set_quantity($new_quantity);
279
+			$line_item->set_total($line_item->unit_price() * $new_quantity);
280
+			$line_item->save();
281
+		}
282
+		foreach ($line_item->children() as $child) {
283
+			if ($child->is_sub_line_item()) {
284
+				EEH_Line_Item::update_quantity($child, $new_quantity);
285
+			}
286
+		}
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns the new line item created by adding a purchase of the ticket
292
+	 *
293
+	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
294
+	 * @param EE_Ticket    $ticket
295
+	 * @param int          $qty
296
+	 * @return EE_Line_Item
297
+	 * @throws EE_Error
298
+	 * @throws InvalidArgumentException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 * @throws ReflectionException
302
+	 */
303
+	public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1)
304
+	{
305
+		$datetimes = $ticket->datetimes();
306
+		$first_datetime = reset($datetimes);
307
+		$first_datetime_name = esc_html__('Event', 'event_espresso');
308
+		if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) {
309
+			$first_datetime_name = $first_datetime->event()->name();
310
+		}
311
+		$event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
312
+		// get event subtotal line
313
+		$events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
314
+		// add $ticket to cart
315
+		$line_item = EE_Line_Item::new_instance(array(
316
+			'LIN_name'       => $ticket->name(),
317
+			'LIN_desc'       => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
318
+			'LIN_unit_price' => $ticket->price(),
319
+			'LIN_quantity'   => $qty,
320
+			'LIN_is_taxable' => $ticket->taxable(),
321
+			'LIN_order'      => count($events_sub_total->children()),
322
+			'LIN_total'      => $ticket->price() * $qty,
323
+			'LIN_type'       => EEM_Line_Item::type_line_item,
324
+			'OBJ_ID'         => $ticket->ID(),
325
+			'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_TICKET,
326
+		));
327
+		$line_item = apply_filters(
328
+			'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
329
+			$line_item
330
+		);
331
+		$events_sub_total->add_child_line_item($line_item);
332
+		// now add the sub-line items
333
+		$running_total_for_ticket = 0;
334
+		foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
335
+			$sign = $price->is_discount() ? -1 : 1;
336
+			$price_total = $price->is_percent()
337
+				? $running_total_for_ticket * $price->amount() / 100
338
+				: $price->amount() * $qty;
339
+			$sub_line_item = EE_Line_Item::new_instance(array(
340
+				'LIN_name'       => $price->name(),
341
+				'LIN_desc'       => $price->desc(),
342
+				'LIN_quantity'   => $price->is_percent() ? null : $qty,
343
+				'LIN_is_taxable' => false,
344
+				'LIN_order'      => $price->order(),
345
+				'LIN_total'      => $sign * $price_total,
346
+				'LIN_type'       => EEM_Line_Item::type_sub_line_item,
347
+				'OBJ_ID'         => $price->ID(),
348
+				'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_PRICE,
349
+			));
350
+			$sub_line_item = apply_filters(
351
+				'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
352
+				$sub_line_item
353
+			);
354
+			if ($price->is_percent()) {
355
+				$sub_line_item->set_percent($sign * $price->amount());
356
+			} else {
357
+				$sub_line_item->set_unit_price($sign * $price->amount());
358
+			}
359
+			$running_total_for_ticket += $price_total;
360
+			$line_item->add_child_line_item($sub_line_item);
361
+		}
362
+		return $line_item;
363
+	}
364
+
365
+
366
+	/**
367
+	 * Adds the specified item under the pre-tax-sub-total line item. Automatically
368
+	 * re-calculates the line item totals and updates the related transaction. But
369
+	 * DOES NOT automatically upgrade the transaction's registrations' final prices (which
370
+	 * should probably change because of this).
371
+	 * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
372
+	 * after using this, to keep the registration final prices in-sync with the transaction's total.
373
+	 *
374
+	 * @param EE_Line_Item $total_line_item
375
+	 * @param EE_Line_Item $item to be added
376
+	 * @return boolean
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 * @throws InvalidDataTypeException
380
+	 * @throws InvalidInterfaceException
381
+	 * @throws ReflectionException
382
+	 */
383
+	public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item)
384
+	{
385
+		$pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
386
+		if ($pre_tax_subtotal instanceof EE_Line_Item) {
387
+			$success = $pre_tax_subtotal->add_child_line_item($item);
388
+		} else {
389
+			return false;
390
+		}
391
+		$total_line_item->recalculate_total_including_taxes();
392
+		return $success;
393
+	}
394
+
395
+
396
+	/**
397
+	 * cancels an existing ticket line item,
398
+	 * by decrementing it's quantity by 1 and adding a new "type_cancellation" sub-line-item.
399
+	 * ALL totals and subtotals will NEED TO BE UPDATED after performing this action
400
+	 *
401
+	 * @param EE_Line_Item $ticket_line_item
402
+	 * @param int          $qty
403
+	 * @return bool success
404
+	 * @throws EE_Error
405
+	 * @throws InvalidArgumentException
406
+	 * @throws InvalidDataTypeException
407
+	 * @throws InvalidInterfaceException
408
+	 * @throws ReflectionException
409
+	 */
410
+	public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1)
411
+	{
412
+		// validate incoming line_item
413
+		if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) {
414
+			throw new EE_Error(
415
+				sprintf(
416
+					esc_html__(
417
+						'The supplied line item must have an Object Type of "Ticket", not %1$s.',
418
+						'event_espresso'
419
+					),
420
+					$ticket_line_item->type()
421
+				)
422
+			);
423
+		}
424
+		if ($ticket_line_item->quantity() < $qty) {
425
+			throw new EE_Error(
426
+				sprintf(
427
+					esc_html__(
428
+						'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.',
429
+						'event_espresso'
430
+					),
431
+					$qty,
432
+					$ticket_line_item->quantity()
433
+				)
434
+			);
435
+		}
436
+		// decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this
437
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty);
438
+		foreach ($ticket_line_item->children() as $child_line_item) {
439
+			if (
440
+				$child_line_item->is_sub_line_item()
441
+				&& ! $child_line_item->is_percent()
442
+				&& ! $child_line_item->is_cancellation()
443
+			) {
444
+				$child_line_item->set_quantity($child_line_item->quantity() - $qty);
445
+			}
446
+		}
447
+		// get cancellation sub line item
448
+		$cancellation_line_item = EEH_Line_Item::get_descendants_of_type(
449
+			$ticket_line_item,
450
+			EEM_Line_Item::type_cancellation
451
+		);
452
+		$cancellation_line_item = reset($cancellation_line_item);
453
+		// verify that this ticket was indeed previously cancelled
454
+		if ($cancellation_line_item instanceof EE_Line_Item) {
455
+			// increment cancelled quantity
456
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty);
457
+		} else {
458
+			// create cancellation sub line item
459
+			$cancellation_line_item = EE_Line_Item::new_instance(array(
460
+				'LIN_name'       => esc_html__('Cancellation', 'event_espresso'),
461
+				'LIN_desc'       => sprintf(
462
+					esc_html_x(
463
+						'Cancelled %1$s : %2$s',
464
+						'Cancelled Ticket Name : 2015-01-01 11:11',
465
+						'event_espresso'
466
+					),
467
+					$ticket_line_item->name(),
468
+					current_time(get_option('date_format') . ' ' . get_option('time_format'))
469
+				),
470
+				'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
471
+				'LIN_quantity'   => $qty,
472
+				'LIN_is_taxable' => $ticket_line_item->is_taxable(),
473
+				'LIN_order'      => count($ticket_line_item->children()),
474
+				'LIN_total'      => 0, // $ticket_line_item->unit_price()
475
+				'LIN_type'       => EEM_Line_Item::type_cancellation,
476
+			));
477
+			$ticket_line_item->add_child_line_item($cancellation_line_item);
478
+		}
479
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
480
+			// decrement parent line item quantity
481
+			$event_line_item = $ticket_line_item->parent();
482
+			if (
483
+				$event_line_item instanceof EE_Line_Item
484
+				&& $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
485
+			) {
486
+				$event_line_item->set_quantity($event_line_item->quantity() - $qty);
487
+				$event_line_item->save();
488
+			}
489
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
490
+			return true;
491
+		}
492
+		return false;
493
+	}
494
+
495
+
496
+	/**
497
+	 * reinstates (un-cancels?) a previously canceled ticket line item,
498
+	 * by incrementing it's quantity by 1, and decrementing it's "type_cancellation" sub-line-item.
499
+	 * ALL totals and subtotals will NEED TO BE UPDATED after performing this action
500
+	 *
501
+	 * @param EE_Line_Item $ticket_line_item
502
+	 * @param int          $qty
503
+	 * @return bool success
504
+	 * @throws EE_Error
505
+	 * @throws InvalidArgumentException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidInterfaceException
508
+	 * @throws ReflectionException
509
+	 */
510
+	public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1)
511
+	{
512
+		// validate incoming line_item
513
+		if ($ticket_line_item->OBJ_type() !== EEM_Line_Item::OBJ_TYPE_TICKET) {
514
+			throw new EE_Error(
515
+				sprintf(
516
+					esc_html__(
517
+						'The supplied line item must have an Object Type of "Ticket", not %1$s.',
518
+						'event_espresso'
519
+					),
520
+					$ticket_line_item->type()
521
+				)
522
+			);
523
+		}
524
+		// get cancellation sub line item
525
+		$cancellation_line_item = EEH_Line_Item::get_descendants_of_type(
526
+			$ticket_line_item,
527
+			EEM_Line_Item::type_cancellation
528
+		);
529
+		$cancellation_line_item = reset($cancellation_line_item);
530
+		// verify that this ticket was indeed previously cancelled
531
+		if (! $cancellation_line_item instanceof EE_Line_Item) {
532
+			return false;
533
+		}
534
+		if ($cancellation_line_item->quantity() > $qty) {
535
+			// decrement cancelled quantity
536
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
537
+		} elseif ($cancellation_line_item->quantity() === $qty) {
538
+			// decrement cancelled quantity in case anyone still has the object kicking around
539
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
540
+			// delete because quantity will end up as 0
541
+			$cancellation_line_item->delete();
542
+			// and attempt to destroy the object,
543
+			// even though PHP won't actually destroy it until it needs the memory
544
+			unset($cancellation_line_item);
545
+		} else {
546
+			// what ?!?! negative quantity ?!?!
547
+			throw new EE_Error(
548
+				sprintf(
549
+					esc_html__(
550
+						'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
551
+						'event_espresso'
552
+					),
553
+					$qty,
554
+					$cancellation_line_item->quantity()
555
+				)
556
+			);
557
+		}
558
+		// increment ticket quantity
559
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty);
560
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
561
+			// increment parent line item quantity
562
+			$event_line_item = $ticket_line_item->parent();
563
+			if (
564
+				$event_line_item instanceof EE_Line_Item
565
+				&& $event_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
566
+			) {
567
+				$event_line_item->set_quantity($event_line_item->quantity() + $qty);
568
+			}
569
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
570
+			return true;
571
+		}
572
+		return false;
573
+	}
574
+
575
+
576
+	/**
577
+	 * calls EEH_Line_Item::find_transaction_grand_total_for_line_item()
578
+	 * then EE_Line_Item::recalculate_total_including_taxes() on the result
579
+	 *
580
+	 * @param EE_Line_Item $line_item
581
+	 * @return float
582
+	 * @throws EE_Error
583
+	 * @throws InvalidArgumentException
584
+	 * @throws InvalidDataTypeException
585
+	 * @throws InvalidInterfaceException
586
+	 * @throws ReflectionException
587
+	 */
588
+	public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item)
589
+	{
590
+		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item);
591
+		return $grand_total_line_item->recalculate_total_including_taxes();
592
+	}
593
+
594
+
595
+	/**
596
+	 * Gets the line item which contains the subtotal of all the items
597
+	 *
598
+	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
599
+	 * @return EE_Line_Item
600
+	 * @throws EE_Error
601
+	 * @throws InvalidArgumentException
602
+	 * @throws InvalidDataTypeException
603
+	 * @throws InvalidInterfaceException
604
+	 * @throws ReflectionException
605
+	 */
606
+	public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item)
607
+	{
608
+		$pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
609
+		return $pre_tax_subtotal instanceof EE_Line_Item
610
+			? $pre_tax_subtotal
611
+			: self::create_pre_tax_subtotal($total_line_item);
612
+	}
613
+
614
+
615
+	/**
616
+	 * Gets the line item for the taxes subtotal
617
+	 *
618
+	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
619
+	 * @return EE_Line_Item
620
+	 * @throws EE_Error
621
+	 * @throws InvalidArgumentException
622
+	 * @throws InvalidDataTypeException
623
+	 * @throws InvalidInterfaceException
624
+	 * @throws ReflectionException
625
+	 */
626
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item)
627
+	{
628
+		$taxes = $total_line_item->get_child_line_item('taxes');
629
+		return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
630
+	}
631
+
632
+
633
+	/**
634
+	 * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object
635
+	 *
636
+	 * @param EE_Line_Item   $line_item
637
+	 * @param EE_Transaction $transaction
638
+	 * @return void
639
+	 * @throws EE_Error
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidDataTypeException
642
+	 * @throws InvalidInterfaceException
643
+	 * @throws ReflectionException
644
+	 */
645
+	public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = null)
646
+	{
647
+		if ($transaction) {
648
+			/** @type EEM_Transaction $EEM_Transaction */
649
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
650
+			$TXN_ID = $EEM_Transaction->ensure_is_ID($transaction);
651
+			$line_item->set_TXN_ID($TXN_ID);
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * Creates a new default total line item for the transaction,
658
+	 * and its tickets subtotal and taxes subtotal line items (and adds the
659
+	 * existing taxes as children of the taxes subtotal line item)
660
+	 *
661
+	 * @param EE_Transaction $transaction
662
+	 * @return EE_Line_Item of type total
663
+	 * @throws EE_Error
664
+	 * @throws InvalidArgumentException
665
+	 * @throws InvalidDataTypeException
666
+	 * @throws InvalidInterfaceException
667
+	 * @throws ReflectionException
668
+	 */
669
+	public static function create_total_line_item($transaction = null)
670
+	{
671
+		$total_line_item = EE_Line_Item::new_instance(array(
672
+			'LIN_code' => 'total',
673
+			'LIN_name' => esc_html__('Grand Total', 'event_espresso'),
674
+			'LIN_type' => EEM_Line_Item::type_total,
675
+			'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TRANSACTION,
676
+		));
677
+		$total_line_item = apply_filters(
678
+			'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
679
+			$total_line_item
680
+		);
681
+		self::set_TXN_ID($total_line_item, $transaction);
682
+		self::create_pre_tax_subtotal($total_line_item, $transaction);
683
+		self::create_taxes_subtotal($total_line_item, $transaction);
684
+		return $total_line_item;
685
+	}
686
+
687
+
688
+	/**
689
+	 * Creates a default items subtotal line item
690
+	 *
691
+	 * @param EE_Line_Item   $total_line_item
692
+	 * @param EE_Transaction $transaction
693
+	 * @return EE_Line_Item
694
+	 * @throws EE_Error
695
+	 * @throws InvalidArgumentException
696
+	 * @throws InvalidDataTypeException
697
+	 * @throws InvalidInterfaceException
698
+	 * @throws ReflectionException
699
+	 */
700
+	protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = null)
701
+	{
702
+		$pre_tax_line_item = EE_Line_Item::new_instance(array(
703
+			'LIN_code' => 'pre-tax-subtotal',
704
+			'LIN_name' => esc_html__('Pre-Tax Subtotal', 'event_espresso'),
705
+			'LIN_type' => EEM_Line_Item::type_sub_total,
706
+		));
707
+		$pre_tax_line_item = apply_filters(
708
+			'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
709
+			$pre_tax_line_item
710
+		);
711
+		self::set_TXN_ID($pre_tax_line_item, $transaction);
712
+		$total_line_item->add_child_line_item($pre_tax_line_item);
713
+		self::create_event_subtotal($pre_tax_line_item, $transaction);
714
+		return $pre_tax_line_item;
715
+	}
716
+
717
+
718
+	/**
719
+	 * Creates a line item for the taxes subtotal and finds all the tax prices
720
+	 * and applies taxes to it
721
+	 *
722
+	 * @param EE_Line_Item   $total_line_item of type EEM_Line_Item::type_total
723
+	 * @param EE_Transaction $transaction
724
+	 * @return EE_Line_Item
725
+	 * @throws EE_Error
726
+	 * @throws InvalidArgumentException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws InvalidInterfaceException
729
+	 * @throws ReflectionException
730
+	 */
731
+	protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null)
732
+	{
733
+		$tax_line_item = EE_Line_Item::new_instance(array(
734
+			'LIN_code'  => 'taxes',
735
+			'LIN_name'  => esc_html__('Taxes', 'event_espresso'),
736
+			'LIN_type'  => EEM_Line_Item::type_tax_sub_total,
737
+			'LIN_order' => 1000,// this should always come last
738
+		));
739
+		$tax_line_item = apply_filters(
740
+			'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
741
+			$tax_line_item
742
+		);
743
+		self::set_TXN_ID($tax_line_item, $transaction);
744
+		$total_line_item->add_child_line_item($tax_line_item);
745
+		// and lastly, add the actual taxes
746
+		self::apply_taxes($total_line_item);
747
+		return $tax_line_item;
748
+	}
749
+
750
+
751
+	/**
752
+	 * Creates a default items subtotal line item
753
+	 *
754
+	 * @param EE_Line_Item   $pre_tax_line_item
755
+	 * @param EE_Transaction $transaction
756
+	 * @param EE_Event       $event
757
+	 * @return EE_Line_Item
758
+	 * @throws EE_Error
759
+	 * @throws InvalidArgumentException
760
+	 * @throws InvalidDataTypeException
761
+	 * @throws InvalidInterfaceException
762
+	 * @throws ReflectionException
763
+	 */
764
+	public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = null, $event = null)
765
+	{
766
+		$event_line_item = EE_Line_Item::new_instance(array(
767
+			'LIN_code' => self::get_event_code($event),
768
+			'LIN_name' => self::get_event_name($event),
769
+			'LIN_desc' => self::get_event_desc($event),
770
+			'LIN_type' => EEM_Line_Item::type_sub_total,
771
+			'OBJ_type' => EEM_Line_Item::OBJ_TYPE_EVENT,
772
+			'OBJ_ID'   => $event instanceof EE_Event ? $event->ID() : 0,
773
+		));
774
+		$event_line_item = apply_filters(
775
+			'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
776
+			$event_line_item
777
+		);
778
+		self::set_TXN_ID($event_line_item, $transaction);
779
+		$pre_tax_line_item->add_child_line_item($event_line_item);
780
+		return $event_line_item;
781
+	}
782
+
783
+
784
+	/**
785
+	 * Gets what the event ticket's code SHOULD be
786
+	 *
787
+	 * @param EE_Event $event
788
+	 * @return string
789
+	 * @throws EE_Error
790
+	 */
791
+	public static function get_event_code($event)
792
+	{
793
+		return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0');
794
+	}
795
+
796
+
797
+	/**
798
+	 * Gets the event name
799
+	 *
800
+	 * @param EE_Event $event
801
+	 * @return string
802
+	 * @throws EE_Error
803
+	 */
804
+	public static function get_event_name($event)
805
+	{
806
+		return $event instanceof EE_Event
807
+			? mb_substr($event->name(), 0, 245)
808
+			: esc_html__('Event', 'event_espresso');
809
+	}
810
+
811
+
812
+	/**
813
+	 * Gets the event excerpt
814
+	 *
815
+	 * @param EE_Event $event
816
+	 * @return string
817
+	 * @throws EE_Error
818
+	 */
819
+	public static function get_event_desc($event)
820
+	{
821
+		return $event instanceof EE_Event ? $event->short_description() : '';
822
+	}
823
+
824
+
825
+	/**
826
+	 * Given the grand total line item and a ticket, finds the event sub-total
827
+	 * line item the ticket's purchase should be added onto
828
+	 *
829
+	 * @access public
830
+	 * @param EE_Line_Item $grand_total the grand total line item
831
+	 * @param EE_Ticket    $ticket
832
+	 * @return EE_Line_Item
833
+	 * @throws EE_Error
834
+	 * @throws InvalidArgumentException
835
+	 * @throws InvalidDataTypeException
836
+	 * @throws InvalidInterfaceException
837
+	 * @throws ReflectionException
838
+	 */
839
+	public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket)
840
+	{
841
+		$first_datetime = $ticket->first_datetime();
842
+		if (! $first_datetime instanceof EE_Datetime) {
843
+			throw new EE_Error(
844
+				sprintf(
845
+					esc_html__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'),
846
+					$ticket->ID()
847
+				)
848
+			);
849
+		}
850
+		$event = $first_datetime->event();
851
+		if (! $event instanceof EE_Event) {
852
+			throw new EE_Error(
853
+				sprintf(
854
+					esc_html__(
855
+						'The supplied ticket (ID %d) has no event data associated with it.',
856
+						'event_espresso'
857
+					),
858
+					$ticket->ID()
859
+				)
860
+			);
861
+		}
862
+		$events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
863
+		if (! $events_sub_total instanceof EE_Line_Item) {
864
+			throw new EE_Error(
865
+				sprintf(
866
+					esc_html__(
867
+						'There is no events sub-total for ticket %s on total line item %d',
868
+						'event_espresso'
869
+					),
870
+					$ticket->ID(),
871
+					$grand_total->ID()
872
+				)
873
+			);
874
+		}
875
+		return $events_sub_total;
876
+	}
877
+
878
+
879
+	/**
880
+	 * Gets the event line item
881
+	 *
882
+	 * @param EE_Line_Item $grand_total
883
+	 * @param EE_Event     $event
884
+	 * @return EE_Line_Item for the event subtotal which is a child of $grand_total
885
+	 * @throws EE_Error
886
+	 * @throws InvalidArgumentException
887
+	 * @throws InvalidDataTypeException
888
+	 * @throws InvalidInterfaceException
889
+	 * @throws ReflectionException
890
+	 */
891
+	public static function get_event_line_item(EE_Line_Item $grand_total, $event)
892
+	{
893
+		/** @type EE_Event $event */
894
+		$event = EEM_Event::instance()->ensure_is_obj($event, true);
895
+		$event_line_item = null;
896
+		$found = false;
897
+		foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
898
+			// default event subtotal, we should only ever find this the first time this method is called
899
+			if (! $event_line_item->OBJ_ID()) {
900
+				// let's use this! but first... set the event details
901
+				EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
902
+				$found = true;
903
+				break;
904
+			}
905
+			if ($event_line_item->OBJ_ID() === $event->ID()) {
906
+				// found existing line item for this event in the cart, so break out of loop and use this one
907
+				$found = true;
908
+				break;
909
+			}
910
+		}
911
+		if (! $found) {
912
+			// there is no event sub-total yet, so add it
913
+			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
914
+			// create a new "event" subtotal below that
915
+			$event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
916
+			// and set the event details
917
+			EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
918
+		}
919
+		return $event_line_item;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Creates a default items subtotal line item
925
+	 *
926
+	 * @param EE_Line_Item   $event_line_item
927
+	 * @param EE_Event       $event
928
+	 * @param EE_Transaction $transaction
929
+	 * @return void
930
+	 * @throws EE_Error
931
+	 * @throws InvalidArgumentException
932
+	 * @throws InvalidDataTypeException
933
+	 * @throws InvalidInterfaceException
934
+	 * @throws ReflectionException
935
+	 */
936
+	public static function set_event_subtotal_details(
937
+		EE_Line_Item $event_line_item,
938
+		EE_Event $event,
939
+		$transaction = null
940
+	) {
941
+		if ($event instanceof EE_Event) {
942
+			$event_line_item->set_code(self::get_event_code($event));
943
+			$event_line_item->set_name(self::get_event_name($event));
944
+			$event_line_item->set_desc(self::get_event_desc($event));
945
+			$event_line_item->set_OBJ_ID($event->ID());
946
+		}
947
+		self::set_TXN_ID($event_line_item, $transaction);
948
+	}
949
+
950
+
951
+	/**
952
+	 * Finds what taxes should apply, adds them as tax line items under the taxes sub-total,
953
+	 * and recalculates the taxes sub-total and the grand total. Resets the taxes, so
954
+	 * any old taxes are removed
955
+	 *
956
+	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
957
+	 * @param bool         $update_txn_status
958
+	 * @return bool
959
+	 * @throws EE_Error
960
+	 * @throws InvalidArgumentException
961
+	 * @throws InvalidDataTypeException
962
+	 * @throws InvalidInterfaceException
963
+	 * @throws ReflectionException
964
+	 * @throws RuntimeException
965
+	 */
966
+	public static function apply_taxes(EE_Line_Item $total_line_item, $update_txn_status = false)
967
+	{
968
+		/** @type EEM_Price $EEM_Price */
969
+		$EEM_Price = EE_Registry::instance()->load_model('Price');
970
+		// get array of taxes via Price Model
971
+		$ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
972
+		ksort($ordered_taxes);
973
+		$taxes_line_item = self::get_taxes_subtotal($total_line_item);
974
+		// just to be safe, remove its old tax line items
975
+		$deleted = $taxes_line_item->delete_children_line_items();
976
+		$updates = false;
977
+		// loop thru taxes
978
+		foreach ($ordered_taxes as $order => $taxes) {
979
+			foreach ($taxes as $tax) {
980
+				if ($tax instanceof EE_Price) {
981
+					$tax_line_item = EE_Line_Item::new_instance(
982
+						array(
983
+							'LIN_name'       => $tax->name(),
984
+							'LIN_desc'       => $tax->desc(),
985
+							'LIN_percent'    => $tax->amount(),
986
+							'LIN_is_taxable' => false,
987
+							'LIN_order'      => $order,
988
+							'LIN_total'      => 0,
989
+							'LIN_type'       => EEM_Line_Item::type_tax,
990
+							'OBJ_type'       => EEM_Line_Item::OBJ_TYPE_PRICE,
991
+							'OBJ_ID'         => $tax->ID(),
992
+						)
993
+					);
994
+					$tax_line_item = apply_filters(
995
+						'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
996
+						$tax_line_item
997
+					);
998
+					$updates = $taxes_line_item->add_child_line_item($tax_line_item) ?
999
+						true :
1000
+						$updates;
1001
+				}
1002
+			}
1003
+		}
1004
+		// only recalculate totals if something changed
1005
+		if ($deleted || $updates) {
1006
+			$total_line_item->recalculate_total_including_taxes($update_txn_status);
1007
+			return true;
1008
+		}
1009
+		return false;
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 * Ensures that taxes have been applied to the order, if not applies them.
1015
+	 * Returns the total amount of tax
1016
+	 *
1017
+	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
1018
+	 * @return float
1019
+	 * @throws EE_Error
1020
+	 * @throws InvalidArgumentException
1021
+	 * @throws InvalidDataTypeException
1022
+	 * @throws InvalidInterfaceException
1023
+	 * @throws ReflectionException
1024
+	 */
1025
+	public static function ensure_taxes_applied($total_line_item)
1026
+	{
1027
+		$taxes_subtotal = self::get_taxes_subtotal($total_line_item);
1028
+		if (! $taxes_subtotal->children()) {
1029
+			self::apply_taxes($total_line_item);
1030
+		}
1031
+		return $taxes_subtotal->total();
1032
+	}
1033
+
1034
+
1035
+	/**
1036
+	 * Deletes ALL children of the passed line item
1037
+	 *
1038
+	 * @param EE_Line_Item $parent_line_item
1039
+	 * @return bool
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	public static function delete_all_child_items(EE_Line_Item $parent_line_item)
1047
+	{
1048
+		$deleted = 0;
1049
+		foreach ($parent_line_item->children() as $child_line_item) {
1050
+			if ($child_line_item instanceof EE_Line_Item) {
1051
+				$deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
1052
+				if ($child_line_item->ID()) {
1053
+					$child_line_item->delete();
1054
+					unset($child_line_item);
1055
+				} else {
1056
+					$parent_line_item->delete_child_line_item($child_line_item->code());
1057
+				}
1058
+				$deleted++;
1059
+			}
1060
+		}
1061
+		return $deleted;
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * Deletes the line items as indicated by the line item code(s) provided,
1067
+	 * regardless of where they're found in the line item tree. Automatically
1068
+	 * re-calculates the line item totals and updates the related transaction. But
1069
+	 * DOES NOT automatically upgrade the transaction's registrations' final prices (which
1070
+	 * should probably change because of this).
1071
+	 * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item()
1072
+	 * after using this, to keep the registration final prices in-sync with the transaction's total.
1073
+	 *
1074
+	 * @param EE_Line_Item      $total_line_item of type EEM_Line_Item::type_total
1075
+	 * @param array|bool|string $line_item_codes
1076
+	 * @return int number of items successfully removed
1077
+	 * @throws EE_Error
1078
+	 */
1079
+	public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = false)
1080
+	{
1081
+
1082
+		if ($total_line_item->type() !== EEM_Line_Item::type_total) {
1083
+			EE_Error::doing_it_wrong(
1084
+				'EEH_Line_Item::delete_items',
1085
+				esc_html__(
1086
+					'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly',
1087
+					'event_espresso'
1088
+				),
1089
+				'4.6.18'
1090
+			);
1091
+		}
1092
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1093
+
1094
+		// check if only a single line_item_id was passed
1095
+		if (! empty($line_item_codes) && ! is_array($line_item_codes)) {
1096
+			// place single line_item_id in an array to appear as multiple line_item_ids
1097
+			$line_item_codes = array($line_item_codes);
1098
+		}
1099
+		$removals = 0;
1100
+		// cycle thru line_item_ids
1101
+		foreach ($line_item_codes as $line_item_id) {
1102
+			$removals += $total_line_item->delete_child_line_item($line_item_id);
1103
+		}
1104
+
1105
+		if ($removals > 0) {
1106
+			$total_line_item->recalculate_taxes_and_tax_total();
1107
+			return $removals;
1108
+		} else {
1109
+			return false;
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * Overwrites the previous tax by clearing out the old taxes, and creates a new
1116
+	 * tax and updates the total line item accordingly
1117
+	 *
1118
+	 * @param EE_Line_Item $total_line_item
1119
+	 * @param float        $amount
1120
+	 * @param string       $name
1121
+	 * @param string       $description
1122
+	 * @param string       $code
1123
+	 * @param boolean      $add_to_existing_line_item
1124
+	 *                          if true, and a duplicate line item with the same code is found,
1125
+	 *                          $amount will be added onto it; otherwise will simply set the taxes to match $amount
1126
+	 * @return EE_Line_Item the new tax line item created
1127
+	 * @throws EE_Error
1128
+	 * @throws InvalidArgumentException
1129
+	 * @throws InvalidDataTypeException
1130
+	 * @throws InvalidInterfaceException
1131
+	 * @throws ReflectionException
1132
+	 */
1133
+	public static function set_total_tax_to(
1134
+		EE_Line_Item $total_line_item,
1135
+		$amount,
1136
+		$name = null,
1137
+		$description = null,
1138
+		$code = null,
1139
+		$add_to_existing_line_item = false
1140
+	) {
1141
+		$tax_subtotal = self::get_taxes_subtotal($total_line_item);
1142
+		$taxable_total = $total_line_item->taxable_total();
1143
+
1144
+		if ($add_to_existing_line_item) {
1145
+			$new_tax = $tax_subtotal->get_child_line_item($code);
1146
+			EEM_Line_Item::instance()->delete(
1147
+				array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))
1148
+			);
1149
+		} else {
1150
+			$new_tax = null;
1151
+			$tax_subtotal->delete_children_line_items();
1152
+		}
1153
+		if ($new_tax) {
1154
+			$new_tax->set_total($new_tax->total() + $amount);
1155
+			$new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0);
1156
+		} else {
1157
+			// no existing tax item. Create it
1158
+			$new_tax = EE_Line_Item::new_instance(array(
1159
+				'TXN_ID'      => $total_line_item->TXN_ID(),
1160
+				'LIN_name'    => $name ? $name : esc_html__('Tax', 'event_espresso'),
1161
+				'LIN_desc'    => $description ? $description : '',
1162
+				'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
1163
+				'LIN_total'   => $amount,
1164
+				'LIN_parent'  => $tax_subtotal->ID(),
1165
+				'LIN_type'    => EEM_Line_Item::type_tax,
1166
+				'LIN_code'    => $code,
1167
+			));
1168
+		}
1169
+
1170
+		$new_tax = apply_filters(
1171
+			'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal',
1172
+			$new_tax,
1173
+			$total_line_item
1174
+		);
1175
+		$new_tax->save();
1176
+		$tax_subtotal->set_total($new_tax->total());
1177
+		$tax_subtotal->save();
1178
+		$total_line_item->recalculate_total_including_taxes();
1179
+		return $new_tax;
1180
+	}
1181
+
1182
+
1183
+	/**
1184
+	 * Makes all the line items which are children of $line_item taxable (or not).
1185
+	 * Does NOT save the line items
1186
+	 *
1187
+	 * @param EE_Line_Item $line_item
1188
+	 * @param boolean      $taxable
1189
+	 * @param string       $code_substring_for_whitelist if this string is part of the line item's code
1190
+	 *                                                   it will be whitelisted (ie, except from becoming taxable)
1191
+	 * @throws EE_Error
1192
+	 */
1193
+	public static function set_line_items_taxable(
1194
+		EE_Line_Item $line_item,
1195
+		$taxable = true,
1196
+		$code_substring_for_whitelist = null
1197
+	) {
1198
+		$whitelisted = false;
1199
+		if ($code_substring_for_whitelist !== null) {
1200
+			$whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false;
1201
+		}
1202
+		if (! $whitelisted && $line_item->is_line_item()) {
1203
+			$line_item->set_is_taxable($taxable);
1204
+		}
1205
+		foreach ($line_item->children() as $child_line_item) {
1206
+			EEH_Line_Item::set_line_items_taxable(
1207
+				$child_line_item,
1208
+				$taxable,
1209
+				$code_substring_for_whitelist
1210
+			);
1211
+		}
1212
+	}
1213
+
1214
+
1215
+	/**
1216
+	 * Gets all descendants that are event subtotals
1217
+	 *
1218
+	 * @uses  EEH_Line_Item::get_subtotals_of_object_type()
1219
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1220
+	 * @return EE_Line_Item[]
1221
+	 * @throws EE_Error
1222
+	 */
1223
+	public static function get_event_subtotals(EE_Line_Item $parent_line_item)
1224
+	{
1225
+		return self::get_subtotals_of_object_type($parent_line_item, EEM_Line_Item::OBJ_TYPE_EVENT);
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * Gets all descendants subtotals that match the supplied object type
1231
+	 *
1232
+	 * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1233
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1234
+	 * @param string       $obj_type
1235
+	 * @return EE_Line_Item[]
1236
+	 * @throws EE_Error
1237
+	 */
1238
+	public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '')
1239
+	{
1240
+		return self::_get_descendants_by_type_and_object_type(
1241
+			$parent_line_item,
1242
+			EEM_Line_Item::type_sub_total,
1243
+			$obj_type
1244
+		);
1245
+	}
1246
+
1247
+
1248
+	/**
1249
+	 * Gets all descendants that are tickets
1250
+	 *
1251
+	 * @uses  EEH_Line_Item::get_line_items_of_object_type()
1252
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1253
+	 * @return EE_Line_Item[]
1254
+	 * @throws EE_Error
1255
+	 */
1256
+	public static function get_ticket_line_items(EE_Line_Item $parent_line_item)
1257
+	{
1258
+		return self::get_line_items_of_object_type(
1259
+			$parent_line_item,
1260
+			EEM_Line_Item::OBJ_TYPE_TICKET
1261
+		);
1262
+	}
1263
+
1264
+
1265
+	/**
1266
+	 * Gets all descendants subtotals that match the supplied object type
1267
+	 *
1268
+	 * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1269
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1270
+	 * @param string       $obj_type
1271
+	 * @return EE_Line_Item[]
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '')
1275
+	{
1276
+		return self::_get_descendants_by_type_and_object_type(
1277
+			$parent_line_item,
1278
+			EEM_Line_Item::type_line_item,
1279
+			$obj_type
1280
+		);
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax'
1286
+	 *
1287
+	 * @uses  EEH_Line_Item::get_descendants_of_type()
1288
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1289
+	 * @return EE_Line_Item[]
1290
+	 * @throws EE_Error
1291
+	 */
1292
+	public static function get_tax_descendants(EE_Line_Item $parent_line_item)
1293
+	{
1294
+		return EEH_Line_Item::get_descendants_of_type(
1295
+			$parent_line_item,
1296
+			EEM_Line_Item::type_tax
1297
+		);
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 * Gets all the real items purchased which are children of this item
1303
+	 *
1304
+	 * @uses  EEH_Line_Item::get_descendants_of_type()
1305
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1306
+	 * @return EE_Line_Item[]
1307
+	 * @throws EE_Error
1308
+	 */
1309
+	public static function get_line_item_descendants(EE_Line_Item $parent_line_item)
1310
+	{
1311
+		return EEH_Line_Item::get_descendants_of_type(
1312
+			$parent_line_item,
1313
+			EEM_Line_Item::type_line_item
1314
+		);
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * Gets all descendants of supplied line item that match the supplied line item type
1320
+	 *
1321
+	 * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1322
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1323
+	 * @param string       $line_item_type   one of the EEM_Line_Item constants
1324
+	 * @return EE_Line_Item[]
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type)
1328
+	{
1329
+		return self::_get_descendants_by_type_and_object_type(
1330
+			$parent_line_item,
1331
+			$line_item_type,
1332
+			null
1333
+		);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type
1339
+	 * as well
1340
+	 *
1341
+	 * @param EE_Line_Item  $parent_line_item - the line item to find descendants of
1342
+	 * @param string        $line_item_type   one of the EEM_Line_Item constants
1343
+	 * @param string | NULL $obj_type         object model class name (minus prefix) or NULL to ignore object type when
1344
+	 *                                        searching
1345
+	 * @return EE_Line_Item[]
1346
+	 * @throws EE_Error
1347
+	 */
1348
+	protected static function _get_descendants_by_type_and_object_type(
1349
+		EE_Line_Item $parent_line_item,
1350
+		$line_item_type,
1351
+		$obj_type = null
1352
+	) {
1353
+		$objects = array();
1354
+		foreach ($parent_line_item->children() as $child_line_item) {
1355
+			if ($child_line_item instanceof EE_Line_Item) {
1356
+				if (
1357
+					$child_line_item->type() === $line_item_type
1358
+					&& (
1359
+						$child_line_item->OBJ_type() === $obj_type || $obj_type === null
1360
+					)
1361
+				) {
1362
+					$objects[] = $child_line_item;
1363
+				} else {
1364
+					// go-through-all-its children looking for more matches
1365
+					$objects = array_merge(
1366
+						$objects,
1367
+						self::_get_descendants_by_type_and_object_type(
1368
+							$child_line_item,
1369
+							$line_item_type,
1370
+							$obj_type
1371
+						)
1372
+					);
1373
+				}
1374
+			}
1375
+		}
1376
+		return $objects;
1377
+	}
1378
+
1379
+
1380
+	/**
1381
+	 * Gets all descendants subtotals that match the supplied object type
1382
+	 *
1383
+	 * @uses  EEH_Line_Item::_get_descendants_by_type_and_object_type()
1384
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1385
+	 * @param string       $OBJ_type         object type (like Event)
1386
+	 * @param array        $OBJ_IDs          array of OBJ_IDs
1387
+	 * @return EE_Line_Item[]
1388
+	 * @throws EE_Error
1389
+	 */
1390
+	public static function get_line_items_by_object_type_and_IDs(
1391
+		EE_Line_Item $parent_line_item,
1392
+		$OBJ_type = '',
1393
+		$OBJ_IDs = array()
1394
+	) {
1395
+		return self::_get_descendants_by_object_type_and_object_ID(
1396
+			$parent_line_item,
1397
+			$OBJ_type,
1398
+			$OBJ_IDs
1399
+		);
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type
1405
+	 * as well
1406
+	 *
1407
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1408
+	 * @param string       $OBJ_type         object type (like Event)
1409
+	 * @param array        $OBJ_IDs          array of OBJ_IDs
1410
+	 * @return EE_Line_Item[]
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	protected static function _get_descendants_by_object_type_and_object_ID(
1414
+		EE_Line_Item $parent_line_item,
1415
+		$OBJ_type,
1416
+		$OBJ_IDs
1417
+	) {
1418
+		$objects = array();
1419
+		foreach ($parent_line_item->children() as $child_line_item) {
1420
+			if ($child_line_item instanceof EE_Line_Item) {
1421
+				if (
1422
+					$child_line_item->OBJ_type() === $OBJ_type
1423
+					&& is_array($OBJ_IDs)
1424
+					&& in_array($child_line_item->OBJ_ID(), $OBJ_IDs)
1425
+				) {
1426
+					$objects[] = $child_line_item;
1427
+				} else {
1428
+					// go-through-all-its children looking for more matches
1429
+					$objects = array_merge(
1430
+						$objects,
1431
+						self::_get_descendants_by_object_type_and_object_ID(
1432
+							$child_line_item,
1433
+							$OBJ_type,
1434
+							$OBJ_IDs
1435
+						)
1436
+					);
1437
+				}
1438
+			}
1439
+		}
1440
+		return $objects;
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * Uses a breadth-first-search in order to find the nearest descendant of
1446
+	 * the specified type and returns it, else NULL
1447
+	 *
1448
+	 * @uses  EEH_Line_Item::_get_nearest_descendant()
1449
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1450
+	 * @param string       $type             like one of the EEM_Line_Item::type_*
1451
+	 * @return EE_Line_Item
1452
+	 * @throws EE_Error
1453
+	 * @throws InvalidArgumentException
1454
+	 * @throws InvalidDataTypeException
1455
+	 * @throws InvalidInterfaceException
1456
+	 * @throws ReflectionException
1457
+	 */
1458
+	public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type)
1459
+	{
1460
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
1461
+	}
1462
+
1463
+
1464
+	/**
1465
+	 * Uses a breadth-first-search in order to find the nearest descendant
1466
+	 * having the specified LIN_code and returns it, else NULL
1467
+	 *
1468
+	 * @uses  EEH_Line_Item::_get_nearest_descendant()
1469
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1470
+	 * @param string       $code             any value used for LIN_code
1471
+	 * @return EE_Line_Item
1472
+	 * @throws EE_Error
1473
+	 * @throws InvalidArgumentException
1474
+	 * @throws InvalidDataTypeException
1475
+	 * @throws InvalidInterfaceException
1476
+	 * @throws ReflectionException
1477
+	 */
1478
+	public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code)
1479
+	{
1480
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
1481
+	}
1482
+
1483
+
1484
+	/**
1485
+	 * Uses a breadth-first-search in order to find the nearest descendant
1486
+	 * having the specified LIN_code and returns it, else NULL
1487
+	 *
1488
+	 * @param EE_Line_Item $parent_line_item - the line item to find descendants of
1489
+	 * @param string       $search_field     name of EE_Line_Item property
1490
+	 * @param string       $value            any value stored in $search_field
1491
+	 * @return EE_Line_Item
1492
+	 * @throws EE_Error
1493
+	 * @throws InvalidArgumentException
1494
+	 * @throws InvalidDataTypeException
1495
+	 * @throws InvalidInterfaceException
1496
+	 * @throws ReflectionException
1497
+	 */
1498
+	protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value)
1499
+	{
1500
+		foreach ($parent_line_item->children() as $child) {
1501
+			if ($child->get($search_field) == $value) {
1502
+				return $child;
1503
+			}
1504
+		}
1505
+		foreach ($parent_line_item->children() as $child) {
1506
+			$descendant_found = self::_get_nearest_descendant(
1507
+				$child,
1508
+				$search_field,
1509
+				$value
1510
+			);
1511
+			if ($descendant_found) {
1512
+				return $descendant_found;
1513
+			}
1514
+		}
1515
+		return null;
1516
+	}
1517
+
1518
+
1519
+	/**
1520
+	 * if passed line item has a TXN ID, uses that to jump directly to the grand total line item for the transaction,
1521
+	 * else recursively walks up the line item tree until a parent of type total is found,
1522
+	 *
1523
+	 * @param EE_Line_Item $line_item
1524
+	 * @return EE_Line_Item
1525
+	 * @throws EE_Error
1526
+	 */
1527
+	public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item)
1528
+	{
1529
+		if ($line_item->TXN_ID()) {
1530
+			$total_line_item = $line_item->transaction()->total_line_item(false);
1531
+			if ($total_line_item instanceof EE_Line_Item) {
1532
+				return $total_line_item;
1533
+			}
1534
+		} else {
1535
+			$line_item_parent = $line_item->parent();
1536
+			if ($line_item_parent instanceof EE_Line_Item) {
1537
+				if ($line_item_parent->is_total()) {
1538
+					return $line_item_parent;
1539
+				}
1540
+				return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent);
1541
+			}
1542
+		}
1543
+		throw new EE_Error(
1544
+			sprintf(
1545
+				esc_html__(
1546
+					'A valid grand total for line item %1$d was not found.',
1547
+					'event_espresso'
1548
+				),
1549
+				$line_item->ID()
1550
+			)
1551
+		);
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 * Prints out a representation of the line item tree
1557
+	 *
1558
+	 * @param EE_Line_Item $line_item
1559
+	 * @param int          $indentation
1560
+	 * @return void
1561
+	 * @throws EE_Error
1562
+	 */
1563
+	public static function visualize(EE_Line_Item $line_item, $indentation = 0)
1564
+	{
1565
+		echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1566
+		if (! $indentation) {
1567
+			echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1568
+		}
1569
+		for ($i = 0; $i < $indentation; $i++) {
1570
+			echo '. ';
1571
+		}
1572
+		$breakdown = '';
1573
+		if ($line_item->is_line_item()) {
1574
+			if ($line_item->is_percent()) {
1575
+				$breakdown = "{$line_item->percent()}%";
1576
+			} else {
1577
+				$breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1578
+			}
1579
+		}
1580
+		echo wp_kses($line_item->name(), AllowedTags::getAllowedTags());
1581
+		echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ";
1582
+		echo '$' . (string) $line_item->total();
1583
+		if ($breakdown) {
1584
+			echo " ( {$breakdown} )";
1585
+		}
1586
+		if ($line_item->is_taxable()) {
1587
+			echo '  * taxable';
1588
+		}
1589
+		if ($line_item->children()) {
1590
+			foreach ($line_item->children() as $child) {
1591
+				self::visualize($child, $indentation + 1);
1592
+			}
1593
+		}
1594
+	}
1595
+
1596
+
1597
+	/**
1598
+	 * Calculates the registration's final price, taking into account that they
1599
+	 * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes,
1600
+	 * and receive a portion of any transaction-wide discounts.
1601
+	 * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount
1602
+	 * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get
1603
+	 * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50
1604
+	 * and brent's final price should be $5.50.
1605
+	 * In order to do this, we basically need to traverse the line item tree calculating
1606
+	 * the running totals (just as if we were recalculating the total), but when we identify
1607
+	 * regular line items, we need to keep track of their share of the grand total.
1608
+	 * Also, we need to keep track of the TAXABLE total for each ticket purchase, so
1609
+	 * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total"
1610
+	 * when there are non-taxable items; otherwise they would be the same)
1611
+	 *
1612
+	 * @param EE_Line_Item $line_item
1613
+	 * @param array        $billable_ticket_quantities  array of EE_Ticket IDs and their corresponding quantity that
1614
+	 *                                                  can be included in price calculations at this moment
1615
+	 * @return array        keys are line items for tickets IDs and values are their share of the running total,
1616
+	 *                                                  plus the key 'total', and 'taxable' which also has keys of all
1617
+	 *                                                  the ticket IDs.
1618
+	 *                                                  Eg array(
1619
+	 *                                                      12 => 4.3
1620
+	 *                                                      23 => 8.0
1621
+	 *                                                      'total' => 16.6,
1622
+	 *                                                      'taxable' => array(
1623
+	 *                                                          12 => 10,
1624
+	 *                                                          23 => 4
1625
+	 *                                                      ).
1626
+	 *                                                  So to find which registrations have which final price, we need
1627
+	 *                                                  to find which line item is theirs, which can be done with
1628
+	 *                                                  `EEM_Line_Item::instance()->get_line_item_for_registration(
1629
+	 *                                                  $registration );`
1630
+	 * @throws EE_Error
1631
+	 * @throws InvalidArgumentException
1632
+	 * @throws InvalidDataTypeException
1633
+	 * @throws InvalidInterfaceException
1634
+	 * @throws ReflectionException
1635
+	 */
1636
+	public static function calculate_reg_final_prices_per_line_item(
1637
+		EE_Line_Item $line_item,
1638
+		$billable_ticket_quantities = array()
1639
+	) {
1640
+		$running_totals = [
1641
+			'total'   => 0,
1642
+			'taxable' => ['total' => 0]
1643
+		];
1644
+		foreach ($line_item->children() as $child_line_item) {
1645
+			switch ($child_line_item->type()) {
1646
+				case EEM_Line_Item::type_sub_total:
1647
+					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1648
+						$child_line_item,
1649
+						$billable_ticket_quantities
1650
+					);
1651
+					// combine arrays but preserve numeric keys
1652
+					$running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1653
+					$running_totals['total'] += $running_totals_from_subtotal['total'];
1654
+					$running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1655
+					break;
1656
+
1657
+				case EEM_Line_Item::type_tax_sub_total:
1658
+					// find how much the taxes percentage is
1659
+					if ($child_line_item->percent() !== 0) {
1660
+						$tax_percent_decimal = $child_line_item->percent() / 100;
1661
+					} else {
1662
+						$tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1663
+					}
1664
+					// and apply to all the taxable totals, and add to the pretax totals
1665
+					foreach ($running_totals as $line_item_id => $this_running_total) {
1666
+						// "total" and "taxable" array key is an exception
1667
+						if ($line_item_id === 'taxable') {
1668
+							continue;
1669
+						}
1670
+						$taxable_total = $running_totals['taxable'][ $line_item_id ];
1671
+						$running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal);
1672
+					}
1673
+					break;
1674
+
1675
+				case EEM_Line_Item::type_line_item:
1676
+					// ticket line items or ????
1677
+					if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) {
1678
+						// kk it's a ticket
1679
+						if (isset($running_totals[ $child_line_item->ID() ])) {
1680
+							// huh? that shouldn't happen.
1681
+							$running_totals['total'] += $child_line_item->total();
1682
+						} else {
1683
+							// its not in our running totals yet. great.
1684
+							if ($child_line_item->is_taxable()) {
1685
+								$taxable_amount = $child_line_item->unit_price();
1686
+							} else {
1687
+								$taxable_amount = 0;
1688
+							}
1689
+							// are we only calculating totals for some tickets?
1690
+							if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) {
1691
+								$quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1692
+								$running_totals[ $child_line_item->ID() ] = $quantity
1693
+									? $child_line_item->unit_price()
1694
+									: 0;
1695
+								$running_totals['taxable'][ $child_line_item->ID() ] = $quantity
1696
+									? $taxable_amount
1697
+									: 0;
1698
+							} else {
1699
+								$quantity = $child_line_item->quantity();
1700
+								$running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1701
+								$running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount;
1702
+							}
1703
+							$running_totals['taxable']['total'] += $taxable_amount * $quantity;
1704
+							$running_totals['total'] += $child_line_item->unit_price() * $quantity;
1705
+						}
1706
+					} else {
1707
+						// it's some other type of item added to the cart
1708
+						// it should affect the running totals
1709
+						// basically we want to convert it into a PERCENT modifier. Because
1710
+						// more clearly affect all registration's final price equally
1711
+						$line_items_percent_of_running_total = $running_totals['total'] > 0
1712
+							? ($child_line_item->total() / $running_totals['total']) + 1
1713
+							: 1;
1714
+						foreach ($running_totals as $line_item_id => $this_running_total) {
1715
+							// the "taxable" array key is an exception
1716
+							if ($line_item_id === 'taxable') {
1717
+								continue;
1718
+							}
1719
+							// update the running totals
1720
+							// yes this actually even works for the running grand total!
1721
+							$running_totals[ $line_item_id ] =
1722
+								$line_items_percent_of_running_total * $this_running_total;
1723
+
1724
+							if ($child_line_item->is_taxable()) {
1725
+								$running_totals['taxable'][ $line_item_id ] =
1726
+									$line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ];
1727
+							}
1728
+						}
1729
+					}
1730
+					break;
1731
+			}
1732
+		}
1733
+		return $running_totals;
1734
+	}
1735
+
1736
+
1737
+	/**
1738
+	 * @param EE_Line_Item $total_line_item
1739
+	 * @param EE_Line_Item $ticket_line_item
1740
+	 * @return float | null
1741
+	 * @throws EE_Error
1742
+	 * @throws InvalidArgumentException
1743
+	 * @throws InvalidDataTypeException
1744
+	 * @throws InvalidInterfaceException
1745
+	 * @throws OutOfRangeException
1746
+	 * @throws ReflectionException
1747
+	 */
1748
+	public static function calculate_final_price_for_ticket_line_item(
1749
+		EE_Line_Item $total_line_item,
1750
+		EE_Line_Item $ticket_line_item
1751
+	) {
1752
+		static $final_prices_per_ticket_line_item = array();
1753
+		if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[ $total_line_item->ID() ])) {
1754
+			$final_prices_per_ticket_line_item[ $total_line_item->ID() ] = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1755
+				$total_line_item
1756
+			);
1757
+		}
1758
+		// ok now find this new registration's final price
1759
+		if (isset($final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ])) {
1760
+			return $final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ];
1761
+		}
1762
+		$message = sprintf(
1763
+			esc_html__(
1764
+				'The final price for the ticket line item (ID:%1$d) could not be calculated.',
1765
+				'event_espresso'
1766
+			),
1767
+			$ticket_line_item->ID()
1768
+		);
1769
+		if (WP_DEBUG) {
1770
+			$message .= '<br>' . print_r($final_prices_per_ticket_line_item, true);
1771
+			throw new OutOfRangeException($message);
1772
+		}
1773
+		EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
1774
+		return null;
1775
+	}
1776
+
1777
+
1778
+	/**
1779
+	 * Creates a duplicate of the line item tree, except only includes billable items
1780
+	 * and the portion of line items attributed to billable things
1781
+	 *
1782
+	 * @param EE_Line_Item      $line_item
1783
+	 * @param EE_Registration[] $registrations
1784
+	 * @return EE_Line_Item
1785
+	 * @throws EE_Error
1786
+	 * @throws InvalidArgumentException
1787
+	 * @throws InvalidDataTypeException
1788
+	 * @throws InvalidInterfaceException
1789
+	 * @throws ReflectionException
1790
+	 */
1791
+	public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations)
1792
+	{
1793
+		$copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1794
+		foreach ($line_item->children() as $child_li) {
1795
+			$copy_li->add_child_line_item(
1796
+				EEH_Line_Item::billable_line_item_tree($child_li, $registrations)
1797
+			);
1798
+		}
1799
+		// if this is the grand total line item, make sure the totals all add up
1800
+		// (we could have duplicated this logic AS we copied the line items, but
1801
+		// it seems DRYer this way)
1802
+		if ($copy_li->type() === EEM_Line_Item::type_total) {
1803
+			$copy_li->recalculate_total_including_taxes();
1804
+		}
1805
+		return $copy_li;
1806
+	}
1807
+
1808
+
1809
+	/**
1810
+	 * Creates a new, unsaved line item from $line_item that factors in the
1811
+	 * number of billable registrations on $registrations.
1812
+	 *
1813
+	 * @param EE_Line_Item      $line_item
1814
+	 * @param EE_Registration[] $registrations
1815
+	 * @return EE_Line_Item
1816
+	 * @throws EE_Error
1817
+	 * @throws InvalidArgumentException
1818
+	 * @throws InvalidDataTypeException
1819
+	 * @throws InvalidInterfaceException
1820
+	 * @throws ReflectionException
1821
+	 */
1822
+	public static function billable_line_item(EE_Line_Item $line_item, $registrations)
1823
+	{
1824
+		$new_li_fields = $line_item->model_field_array();
1825
+		if (
1826
+			$line_item->type() === EEM_Line_Item::type_line_item &&
1827
+			$line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1828
+		) {
1829
+			$count = 0;
1830
+			foreach ($registrations as $registration) {
1831
+				if (
1832
+					$line_item->OBJ_ID() === $registration->ticket_ID() &&
1833
+					in_array(
1834
+						$registration->status_ID(),
1835
+						EEM_Registration::reg_statuses_that_allow_payment(),
1836
+						true
1837
+					)
1838
+				) {
1839
+					$count++;
1840
+				}
1841
+			}
1842
+			$new_li_fields['LIN_quantity'] = $count;
1843
+		}
1844
+		// don't set the total. We'll leave that up to the code that calculates it
1845
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']);
1846
+		return EE_Line_Item::new_instance($new_li_fields);
1847
+	}
1848
+
1849
+
1850
+	/**
1851
+	 * Returns a modified line item tree where all the subtotals which have a total of 0
1852
+	 * are removed, and line items with a quantity of 0
1853
+	 *
1854
+	 * @param EE_Line_Item $line_item |null
1855
+	 * @return EE_Line_Item|null
1856
+	 * @throws EE_Error
1857
+	 * @throws InvalidArgumentException
1858
+	 * @throws InvalidDataTypeException
1859
+	 * @throws InvalidInterfaceException
1860
+	 * @throws ReflectionException
1861
+	 */
1862
+	public static function non_empty_line_items(EE_Line_Item $line_item)
1863
+	{
1864
+		$copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1865
+		if ($copied_li === null) {
1866
+			return null;
1867
+		}
1868
+		// if this is an event subtotal, we want to only include it if it
1869
+		// has a non-zero total and at least one ticket line item child
1870
+		$ticket_children = 0;
1871
+		foreach ($line_item->children() as $child_li) {
1872
+			$child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1873
+			if ($child_li_copy !== null) {
1874
+				$copied_li->add_child_line_item($child_li_copy);
1875
+				if (
1876
+					$child_li_copy->type() === EEM_Line_Item::type_line_item &&
1877
+					$child_li_copy->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1878
+				) {
1879
+					$ticket_children++;
1880
+				}
1881
+			}
1882
+		}
1883
+		// if this is an event subtotal with NO ticket children
1884
+		// we basically want to ignore it
1885
+		if (
1886
+			$ticket_children === 0
1887
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
1888
+			&& $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_EVENT
1889
+			&& $line_item->total() === 0
1890
+		) {
1891
+			return null;
1892
+		}
1893
+		return $copied_li;
1894
+	}
1895
+
1896
+
1897
+	/**
1898
+	 * Creates a new, unsaved line item, but if it's a ticket line item
1899
+	 * with a total of 0, or a subtotal of 0, returns null instead
1900
+	 *
1901
+	 * @param EE_Line_Item $line_item
1902
+	 * @return EE_Line_Item
1903
+	 * @throws EE_Error
1904
+	 * @throws InvalidArgumentException
1905
+	 * @throws InvalidDataTypeException
1906
+	 * @throws InvalidInterfaceException
1907
+	 * @throws ReflectionException
1908
+	 */
1909
+	public static function non_empty_line_item(EE_Line_Item $line_item)
1910
+	{
1911
+		if (
1912
+			$line_item->type() === EEM_Line_Item::type_line_item
1913
+			&& $line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1914
+			&& $line_item->quantity() === 0
1915
+		) {
1916
+			return null;
1917
+		}
1918
+		$new_li_fields = $line_item->model_field_array();
1919
+		// don't set the total. We'll leave that up to the code that calculates it
1920
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']);
1921
+		return EE_Line_Item::new_instance($new_li_fields);
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * Cycles through all of the ticket line items for the supplied total line item
1927
+	 * and ensures that the line item's "is_taxable" field matches that of its corresponding ticket
1928
+	 *
1929
+	 * @param EE_Line_Item $total_line_item
1930
+	 * @since 4.9.79.p
1931
+	 * @throws EE_Error
1932
+	 * @throws InvalidArgumentException
1933
+	 * @throws InvalidDataTypeException
1934
+	 * @throws InvalidInterfaceException
1935
+	 * @throws ReflectionException
1936
+	 */
1937
+	public static function resetIsTaxableForTickets(EE_Line_Item $total_line_item)
1938
+	{
1939
+		$ticket_line_items = self::get_ticket_line_items($total_line_item);
1940
+		foreach ($ticket_line_items as $ticket_line_item) {
1941
+			if (
1942
+				$ticket_line_item instanceof EE_Line_Item
1943
+				&& $ticket_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET
1944
+			) {
1945
+				$ticket = $ticket_line_item->ticket();
1946
+				if ($ticket instanceof EE_Ticket && $ticket->taxable() !== $ticket_line_item->is_taxable()) {
1947
+					$ticket_line_item->set_is_taxable($ticket->taxable());
1948
+					$ticket_line_item->save();
1949
+				}
1950
+			}
1951
+		}
1952
+	}
1953
+
1954
+
1955
+
1956
+	/**************************************** @DEPRECATED METHODS *************************************** */
1957
+	/**
1958
+	 * @deprecated
1959
+	 * @param EE_Line_Item $total_line_item
1960
+	 * @return EE_Line_Item
1961
+	 * @throws EE_Error
1962
+	 * @throws InvalidArgumentException
1963
+	 * @throws InvalidDataTypeException
1964
+	 * @throws InvalidInterfaceException
1965
+	 * @throws ReflectionException
1966
+	 */
1967
+	public static function get_items_subtotal(EE_Line_Item $total_line_item)
1968
+	{
1969
+		EE_Error::doing_it_wrong(
1970
+			'EEH_Line_Item::get_items_subtotal()',
1971
+			sprintf(
1972
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
1973
+				'EEH_Line_Item::get_pre_tax_subtotal()'
1974
+			),
1975
+			'4.6.0'
1976
+		);
1977
+		return self::get_pre_tax_subtotal($total_line_item);
1978
+	}
1979
+
1980
+
1981
+	/**
1982
+	 * @deprecated
1983
+	 * @param EE_Transaction $transaction
1984
+	 * @return EE_Line_Item
1985
+	 * @throws EE_Error
1986
+	 * @throws InvalidArgumentException
1987
+	 * @throws InvalidDataTypeException
1988
+	 * @throws InvalidInterfaceException
1989
+	 * @throws ReflectionException
1990
+	 */
1991
+	public static function create_default_total_line_item($transaction = null)
1992
+	{
1993
+		EE_Error::doing_it_wrong(
1994
+			'EEH_Line_Item::create_default_total_line_item()',
1995
+			sprintf(
1996
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
1997
+				'EEH_Line_Item::create_total_line_item()'
1998
+			),
1999
+			'4.6.0'
2000
+		);
2001
+		return self::create_total_line_item($transaction);
2002
+	}
2003
+
2004
+
2005
+	/**
2006
+	 * @deprecated
2007
+	 * @param EE_Line_Item   $total_line_item
2008
+	 * @param EE_Transaction $transaction
2009
+	 * @return EE_Line_Item
2010
+	 * @throws EE_Error
2011
+	 * @throws InvalidArgumentException
2012
+	 * @throws InvalidDataTypeException
2013
+	 * @throws InvalidInterfaceException
2014
+	 * @throws ReflectionException
2015
+	 */
2016
+	public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2017
+	{
2018
+		EE_Error::doing_it_wrong(
2019
+			'EEH_Line_Item::create_default_tickets_subtotal()',
2020
+			sprintf(
2021
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
2022
+				'EEH_Line_Item::create_pre_tax_subtotal()'
2023
+			),
2024
+			'4.6.0'
2025
+		);
2026
+		return self::create_pre_tax_subtotal($total_line_item, $transaction);
2027
+	}
2028
+
2029
+
2030
+	/**
2031
+	 * @deprecated
2032
+	 * @param EE_Line_Item   $total_line_item
2033
+	 * @param EE_Transaction $transaction
2034
+	 * @return EE_Line_Item
2035
+	 * @throws EE_Error
2036
+	 * @throws InvalidArgumentException
2037
+	 * @throws InvalidDataTypeException
2038
+	 * @throws InvalidInterfaceException
2039
+	 * @throws ReflectionException
2040
+	 */
2041
+	public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2042
+	{
2043
+		EE_Error::doing_it_wrong(
2044
+			'EEH_Line_Item::create_default_taxes_subtotal()',
2045
+			sprintf(
2046
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
2047
+				'EEH_Line_Item::create_taxes_subtotal()'
2048
+			),
2049
+			'4.6.0'
2050
+		);
2051
+		return self::create_taxes_subtotal($total_line_item, $transaction);
2052
+	}
2053
+
2054
+
2055
+	/**
2056
+	 * @deprecated
2057
+	 * @param EE_Line_Item   $total_line_item
2058
+	 * @param EE_Transaction $transaction
2059
+	 * @return EE_Line_Item
2060
+	 * @throws EE_Error
2061
+	 * @throws InvalidArgumentException
2062
+	 * @throws InvalidDataTypeException
2063
+	 * @throws InvalidInterfaceException
2064
+	 * @throws ReflectionException
2065
+	 */
2066
+	public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = null)
2067
+	{
2068
+		EE_Error::doing_it_wrong(
2069
+			'EEH_Line_Item::create_default_event_subtotal()',
2070
+			sprintf(
2071
+				esc_html__('Method replaced with %1$s', 'event_espresso'),
2072
+				'EEH_Line_Item::create_event_subtotal()'
2073
+			),
2074
+			'4.6.0'
2075
+		);
2076
+		return self::create_event_subtotal($total_line_item, $transaction);
2077
+	}
2078 2078
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1)
141 141
     {
142
-        if (! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
142
+        if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
143 143
             throw new EE_Error(
144 144
                 sprintf(
145 145
                     esc_html__(
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         // either increment the qty for an existing ticket
155 155
         $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
156 156
         // or add a new one
157
-        if (! $line_item instanceof EE_Line_Item) {
157
+        if ( ! $line_item instanceof EE_Line_Item) {
158 158
             $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
159 159
         }
160 160
         $total_line_item->recalculate_total_including_taxes();
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      */
217 217
     public static function increment_quantity(EE_Line_Item $line_item, $qty = 1)
218 218
     {
219
-        if (! $line_item->is_percent()) {
219
+        if ( ! $line_item->is_percent()) {
220 220
             $qty += $line_item->quantity();
221 221
             $line_item->set_quantity($qty);
222 222
             $line_item->set_total($line_item->unit_price() * $qty);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1)
247 247
     {
248
-        if (! $line_item->is_percent()) {
248
+        if ( ! $line_item->is_percent()) {
249 249
             $qty = $line_item->quantity() - $qty;
250 250
             $qty = max($qty, 0);
251 251
             $line_item->set_quantity($qty);
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public static function update_quantity(EE_Line_Item $line_item, $new_quantity)
276 276
     {
277
-        if (! $line_item->is_percent()) {
277
+        if ( ! $line_item->is_percent()) {
278 278
             $line_item->set_quantity($new_quantity);
279 279
             $line_item->set_total($line_item->unit_price() * $new_quantity);
280 280
             $line_item->save();
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         // add $ticket to cart
315 315
         $line_item = EE_Line_Item::new_instance(array(
316 316
             'LIN_name'       => $ticket->name(),
317
-            'LIN_desc'       => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
317
+            'LIN_desc'       => $ticket->description() !== '' ? $ticket->description().' '.$event : $event,
318 318
             'LIN_unit_price' => $ticket->price(),
319 319
             'LIN_quantity'   => $qty,
320 320
             'LIN_is_taxable' => $ticket->taxable(),
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
                         'event_espresso'
466 466
                     ),
467 467
                     $ticket_line_item->name(),
468
-                    current_time(get_option('date_format') . ' ' . get_option('time_format'))
468
+                    current_time(get_option('date_format').' '.get_option('time_format'))
469 469
                 ),
470 470
                 'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
471 471
                 'LIN_quantity'   => $qty,
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
         );
529 529
         $cancellation_line_item = reset($cancellation_line_item);
530 530
         // verify that this ticket was indeed previously cancelled
531
-        if (! $cancellation_line_item instanceof EE_Line_Item) {
531
+        if ( ! $cancellation_line_item instanceof EE_Line_Item) {
532 532
             return false;
533 533
         }
534 534
         if ($cancellation_line_item->quantity() > $qty) {
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             'LIN_code'  => 'taxes',
735 735
             'LIN_name'  => esc_html__('Taxes', 'event_espresso'),
736 736
             'LIN_type'  => EEM_Line_Item::type_tax_sub_total,
737
-            'LIN_order' => 1000,// this should always come last
737
+            'LIN_order' => 1000, // this should always come last
738 738
         ));
739 739
         $tax_line_item = apply_filters(
740 740
             'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
      */
791 791
     public static function get_event_code($event)
792 792
     {
793
-        return 'event-' . ($event instanceof EE_Event ? $event->ID() : '0');
793
+        return 'event-'.($event instanceof EE_Event ? $event->ID() : '0');
794 794
     }
795 795
 
796 796
 
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
     public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket)
840 840
     {
841 841
         $first_datetime = $ticket->first_datetime();
842
-        if (! $first_datetime instanceof EE_Datetime) {
842
+        if ( ! $first_datetime instanceof EE_Datetime) {
843 843
             throw new EE_Error(
844 844
                 sprintf(
845 845
                     esc_html__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'),
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
             );
849 849
         }
850 850
         $event = $first_datetime->event();
851
-        if (! $event instanceof EE_Event) {
851
+        if ( ! $event instanceof EE_Event) {
852 852
             throw new EE_Error(
853 853
                 sprintf(
854 854
                     esc_html__(
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
             );
861 861
         }
862 862
         $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
863
-        if (! $events_sub_total instanceof EE_Line_Item) {
863
+        if ( ! $events_sub_total instanceof EE_Line_Item) {
864 864
             throw new EE_Error(
865 865
                 sprintf(
866 866
                     esc_html__(
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
         $found = false;
897 897
         foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
898 898
             // default event subtotal, we should only ever find this the first time this method is called
899
-            if (! $event_line_item->OBJ_ID()) {
899
+            if ( ! $event_line_item->OBJ_ID()) {
900 900
                 // let's use this! but first... set the event details
901 901
                 EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
902 902
                 $found = true;
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
                 break;
909 909
             }
910 910
         }
911
-        if (! $found) {
911
+        if ( ! $found) {
912 912
             // there is no event sub-total yet, so add it
913 913
             $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
914 914
             // create a new "event" subtotal below that
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
     public static function ensure_taxes_applied($total_line_item)
1026 1026
     {
1027 1027
         $taxes_subtotal = self::get_taxes_subtotal($total_line_item);
1028
-        if (! $taxes_subtotal->children()) {
1028
+        if ( ! $taxes_subtotal->children()) {
1029 1029
             self::apply_taxes($total_line_item);
1030 1030
         }
1031 1031
         return $taxes_subtotal->total();
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1093 1093
 
1094 1094
         // check if only a single line_item_id was passed
1095
-        if (! empty($line_item_codes) && ! is_array($line_item_codes)) {
1095
+        if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) {
1096 1096
             // place single line_item_id in an array to appear as multiple line_item_ids
1097 1097
             $line_item_codes = array($line_item_codes);
1098 1098
         }
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
         if ($code_substring_for_whitelist !== null) {
1200 1200
             $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false;
1201 1201
         }
1202
-        if (! $whitelisted && $line_item->is_line_item()) {
1202
+        if ( ! $whitelisted && $line_item->is_line_item()) {
1203 1203
             $line_item->set_is_taxable($taxable);
1204 1204
         }
1205 1205
         foreach ($line_item->children() as $child_line_item) {
@@ -1563,7 +1563,7 @@  discard block
 block discarded – undo
1563 1563
     public static function visualize(EE_Line_Item $line_item, $indentation = 0)
1564 1564
     {
1565 1565
         echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1566
-        if (! $indentation) {
1566
+        if ( ! $indentation) {
1567 1567
             echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1568 1568
         }
1569 1569
         for ($i = 0; $i < $indentation; $i++) {
@@ -1574,12 +1574,12 @@  discard block
 block discarded – undo
1574 1574
             if ($line_item->is_percent()) {
1575 1575
                 $breakdown = "{$line_item->percent()}%";
1576 1576
             } else {
1577
-                $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1577
+                $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}";
1578 1578
             }
1579 1579
         }
1580 1580
         echo wp_kses($line_item->name(), AllowedTags::getAllowedTags());
1581 1581
         echo " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ";
1582
-        echo '$' . (string) $line_item->total();
1582
+        echo '$'.(string) $line_item->total();
1583 1583
         if ($breakdown) {
1584 1584
             echo " ( {$breakdown} )";
1585 1585
         }
@@ -1667,8 +1667,8 @@  discard block
 block discarded – undo
1667 1667
                         if ($line_item_id === 'taxable') {
1668 1668
                             continue;
1669 1669
                         }
1670
-                        $taxable_total = $running_totals['taxable'][ $line_item_id ];
1671
-                        $running_totals[ $line_item_id ] += ($taxable_total * $tax_percent_decimal);
1670
+                        $taxable_total = $running_totals['taxable'][$line_item_id];
1671
+                        $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal);
1672 1672
                     }
1673 1673
                     break;
1674 1674
 
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
                     // ticket line items or ????
1677 1677
                     if ($child_line_item->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) {
1678 1678
                         // kk it's a ticket
1679
-                        if (isset($running_totals[ $child_line_item->ID() ])) {
1679
+                        if (isset($running_totals[$child_line_item->ID()])) {
1680 1680
                             // huh? that shouldn't happen.
1681 1681
                             $running_totals['total'] += $child_line_item->total();
1682 1682
                         } else {
@@ -1687,18 +1687,18 @@  discard block
 block discarded – undo
1687 1687
                                 $taxable_amount = 0;
1688 1688
                             }
1689 1689
                             // are we only calculating totals for some tickets?
1690
-                            if (isset($billable_ticket_quantities[ $child_line_item->OBJ_ID() ])) {
1691
-                                $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1692
-                                $running_totals[ $child_line_item->ID() ] = $quantity
1690
+                            if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
1691
+                                $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
1692
+                                $running_totals[$child_line_item->ID()] = $quantity
1693 1693
                                     ? $child_line_item->unit_price()
1694 1694
                                     : 0;
1695
-                                $running_totals['taxable'][ $child_line_item->ID() ] = $quantity
1695
+                                $running_totals['taxable'][$child_line_item->ID()] = $quantity
1696 1696
                                     ? $taxable_amount
1697 1697
                                     : 0;
1698 1698
                             } else {
1699 1699
                                 $quantity = $child_line_item->quantity();
1700
-                                $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1701
-                                $running_totals['taxable'][ $child_line_item->ID() ] = $taxable_amount;
1700
+                                $running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
1701
+                                $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
1702 1702
                             }
1703 1703
                             $running_totals['taxable']['total'] += $taxable_amount * $quantity;
1704 1704
                             $running_totals['total'] += $child_line_item->unit_price() * $quantity;
@@ -1718,12 +1718,12 @@  discard block
 block discarded – undo
1718 1718
                             }
1719 1719
                             // update the running totals
1720 1720
                             // yes this actually even works for the running grand total!
1721
-                            $running_totals[ $line_item_id ] =
1721
+                            $running_totals[$line_item_id] =
1722 1722
                                 $line_items_percent_of_running_total * $this_running_total;
1723 1723
 
1724 1724
                             if ($child_line_item->is_taxable()) {
1725
-                                $running_totals['taxable'][ $line_item_id ] =
1726
-                                    $line_items_percent_of_running_total * $running_totals['taxable'][ $line_item_id ];
1725
+                                $running_totals['taxable'][$line_item_id] =
1726
+                                    $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
1727 1727
                             }
1728 1728
                         }
1729 1729
                     }
@@ -1750,14 +1750,14 @@  discard block
 block discarded – undo
1750 1750
         EE_Line_Item $ticket_line_item
1751 1751
     ) {
1752 1752
         static $final_prices_per_ticket_line_item = array();
1753
-        if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[ $total_line_item->ID() ])) {
1754
-            $final_prices_per_ticket_line_item[ $total_line_item->ID() ] = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1753
+        if (empty($final_prices_per_ticket_line_item) || empty($final_prices_per_ticket_line_item[$total_line_item->ID()])) {
1754
+            $final_prices_per_ticket_line_item[$total_line_item->ID()] = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1755 1755
                 $total_line_item
1756 1756
             );
1757 1757
         }
1758 1758
         // ok now find this new registration's final price
1759
-        if (isset($final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ])) {
1760
-            return $final_prices_per_ticket_line_item[ $total_line_item->ID() ][ $ticket_line_item->ID() ];
1759
+        if (isset($final_prices_per_ticket_line_item[$total_line_item->ID()][$ticket_line_item->ID()])) {
1760
+            return $final_prices_per_ticket_line_item[$total_line_item->ID()][$ticket_line_item->ID()];
1761 1761
         }
1762 1762
         $message = sprintf(
1763 1763
             esc_html__(
@@ -1767,7 +1767,7 @@  discard block
 block discarded – undo
1767 1767
             $ticket_line_item->ID()
1768 1768
         );
1769 1769
         if (WP_DEBUG) {
1770
-            $message .= '<br>' . print_r($final_prices_per_ticket_line_item, true);
1770
+            $message .= '<br>'.print_r($final_prices_per_ticket_line_item, true);
1771 1771
             throw new OutOfRangeException($message);
1772 1772
         }
1773 1773
         EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 1 patch
Indentation   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -16,673 +16,673 @@  discard block
 block discarded – undo
16 16
 class EEH_Debug_Tools
17 17
 {
18 18
 
19
-    /**
20
-     *    instance of the EEH_Autoloader object
21
-     *
22
-     * @var    $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $_memory_usage_points = array();
31
-
32
-
33
-
34
-    /**
35
-     * @singleton method used to instantiate class object
36
-     * @access    public
37
-     * @return EEH_Debug_Tools
38
-     */
39
-    public static function instance()
40
-    {
41
-        // check if class object is instantiated, and instantiated properly
42
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
-            self::$_instance = new self();
44
-        }
45
-        return self::$_instance;
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * private class constructor
52
-     */
53
-    private function __construct()
54
-    {
55
-        // load Kint PHP debugging library
56
-        if (
57
-            defined('EE_LOAD_KINT')
58
-            && ! class_exists('Kint')
59
-            && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')
60
-        ) {
61
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
62
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
63
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
64
-            // so we've moved it to our test folder so that it is not included with production releases
65
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
66
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
67
-        }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[ $tag ] = $wp_filter[ $tag ];
134
-            if (! is_array($hook[ $tag ])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . esc_html($tag) . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>esc_html($tag_name)</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo esc_html($priority);
148
-                foreach ($function as $name => $properties) {
149
-                    $name = esc_html($name);
150
-                    echo "\t$name<br />";
151
-                }
152
-            }
153
-        }
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    registered_filter_callbacks
160
-     *
161
-     * @param string $hook_name
162
-     * @return array
163
-     */
164
-    public static function registered_filter_callbacks($hook_name = '')
165
-    {
166
-        $filters = array();
167
-        global $wp_filter;
168
-        if (isset($wp_filter[ $hook_name ])) {
169
-            $filters[ $hook_name ] = array();
170
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
171
-                $filters[ $hook_name ][ $priority ] = array();
172
-                foreach ($callbacks as $callback) {
173
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
174
-                }
175
-            }
176
-        }
177
-        return $filters;
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *    captures plugin activation errors for debugging
184
-     *
185
-     * @return void
186
-     * @throws EE_Error
187
-     */
188
-    public static function ee_plugin_activation_errors()
189
-    {
190
-        if (WP_DEBUG) {
191
-            $activation_errors = ob_get_contents();
192
-            if (! empty($activation_errors)) {
193
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
194
-            }
195
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
196
-            if (class_exists('EEH_File')) {
197
-                try {
198
-                    EEH_File::ensure_file_exists_and_is_writable(
199
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
200
-                    );
201
-                    EEH_File::write_to_file(
202
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
203
-                        $activation_errors
204
-                    );
205
-                } catch (EE_Error $e) {
206
-                    EE_Error::add_error(
207
-                        sprintf(
208
-                            esc_html__(
209
-                                'The Event Espresso activation errors file could not be setup because: %s',
210
-                                'event_espresso'
211
-                            ),
212
-                            $e->getMessage()
213
-                        ),
214
-                        __FILE__,
215
-                        __FUNCTION__,
216
-                        __LINE__
217
-                    );
218
-                }
219
-            } else {
220
-                // old school attempt
221
-                file_put_contents(
222
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
223
-                    $activation_errors
224
-                );
225
-            }
226
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
227
-            update_option('ee_plugin_activation_errors', $activation_errors);
228
-        }
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
235
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
236
-     * or we want to make sure they use something the right way.
237
-     *
238
-     * @access public
239
-     * @param string $function      The function that was called
240
-     * @param string $message       A message explaining what has been done incorrectly
241
-     * @param string $version       The version of Event Espresso where the error was added
242
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
243
-     *                              for a deprecated function. This allows deprecation to occur during one version,
244
-     *                              but not have any notices appear until a later version. This allows developers
245
-     *                              extra time to update their code before notices appear.
246
-     * @param int    $error_type
247
-     * @uses   trigger_error()
248
-     */
249
-    public function doing_it_wrong(
250
-        $function,
251
-        $message,
252
-        $version,
253
-        $applies_when = '',
254
-        $error_type = null
255
-    ) {
256
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
257
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
258
-        // because we swapped the parameter order around for the last two params,
259
-        // let's verify that some third party isn't still passing an error type value for the third param
260
-        if (is_int($applies_when)) {
261
-            $error_type = $applies_when;
262
-            $applies_when = espresso_version();
263
-        }
264
-        // if not displaying notices yet, then just leave
265
-        if (version_compare(espresso_version(), $applies_when, '<')) {
266
-            return;
267
-        }
268
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
269
-        $version = $version === null
270
-            ? ''
271
-            : sprintf(
272
-                esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
273
-                $version
274
-            );
275
-        $error_message = sprintf(
276
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
277
-            $function,
278
-            '<strong>',
279
-            '</strong>',
280
-            $message,
281
-            $version
282
-        );
283
-        // don't trigger error if doing ajax,
284
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
285
-        if (defined('DOING_AJAX') && DOING_AJAX) {
286
-            $error_message .= ' ' . esc_html__(
287
-                'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
288
-                'event_espresso'
289
-            );
290
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
291
-            $error_message .= '<ul><li>';
292
-            $error_message .= implode('</li><li>', $request->requestParams());
293
-            $error_message .= '</ul>';
294
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
295
-            // now we set this on the transient so it shows up on the next request.
296
-            EE_Error::get_notices(false, true);
297
-        } else {
298
-            trigger_error($error_message, $error_type);
299
-        }
300
-    }
301
-
302
-
303
-
304
-
305
-    /**
306
-     * Logger helpers
307
-     */
308
-    /**
309
-     * debug
310
-     *
311
-     * @param string $class
312
-     * @param string $func
313
-     * @param string $line
314
-     * @param array  $info
315
-     * @param bool   $display_request
316
-     * @param string $debug_index
317
-     * @param string $debug_key
318
-     */
319
-    public static function log(
320
-        $class = '',
321
-        $func = '',
322
-        $line = '',
323
-        $info = array(),
324
-        $display_request = false,
325
-        $debug_index = '',
326
-        $debug_key = 'EE_DEBUG_SPCO'
327
-    ) {
328
-        if (WP_DEBUG) {
329
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
330
-            $debug_data = get_option($debug_key, array());
331
-            $default_data = array(
332
-                $class => $func . '() : ' . $line,
333
-            );
334
-            // don't serialize objects
335
-            $info = self::strip_objects($info);
336
-            $index = ! empty($debug_index) ? $debug_index : 0;
337
-            if (! isset($debug_data[ $index ])) {
338
-                $debug_data[ $index ] = array();
339
-            }
340
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
341
-            update_option($debug_key, $debug_data);
342
-        }
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * strip_objects
349
-     *
350
-     * @param array $info
351
-     * @return array
352
-     */
353
-    public static function strip_objects($info = array())
354
-    {
355
-        foreach ($info as $key => $value) {
356
-            if (is_array($value)) {
357
-                $info[ $key ] = self::strip_objects($value);
358
-            } elseif (is_object($value)) {
359
-                $object_class = get_class($value);
360
-                $info[ $object_class ] = array();
361
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
362
-                if (method_exists($value, 'ID')) {
363
-                    $info[ $object_class ]['ID'] = $value->ID();
364
-                }
365
-                if (method_exists($value, 'status')) {
366
-                    $info[ $object_class ]['status'] = $value->status();
367
-                } elseif (method_exists($value, 'status_ID')) {
368
-                    $info[ $object_class ]['status'] = $value->status_ID();
369
-                }
370
-                unset($info[ $key ]);
371
-            }
372
-        }
373
-        return (array) $info;
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * @param mixed      $var
380
-     * @param string     $var_name
381
-     * @param string     $file
382
-     * @param int|string $line
383
-     * @param int|string $heading_tag
384
-     * @param bool       $die
385
-     * @param string     $margin
386
-     */
387
-    public static function printv(
388
-        $var,
389
-        $var_name = '',
390
-        $file = '',
391
-        $line = '',
392
-        $heading_tag = 5,
393
-        $die = false,
394
-        $margin = ''
395
-    ) {
396
-        $var_name = ! $var_name ? 'string' : $var_name;
397
-        $var_name = ucwords(str_replace('$', '', $var_name));
398
-        $is_method = method_exists($var_name, $var);
399
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
400
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
401
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
402
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
403
-        $result .= $is_method
404
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
405
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
406
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
407
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
408
-        if ($die) {
409
-            die($result);
410
-        }
411
-        echo wp_kses($result, AllowedTags::getWithFormTags());
412
-    }
413
-
414
-
415
-    protected static function headingTag($heading_tag)
416
-    {
417
-        $heading_tag = absint($heading_tag);
418
-        return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
419
-    }
420
-
421
-    protected static function headingSpacer($heading_tag)
422
-    {
423
-        return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
424
-            ? self::lineBreak()
425
-            : '';
426
-    }
427
-
428
-
429
-    protected static function lineBreak()
430
-    {
431
-        return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n";
432
-    }
433
-
434
-
435
-    protected static function plainOutput()
436
-    {
437
-        return defined('EE_TESTS_DIR')
438
-               || (defined('DOING_AJAX') && DOING_AJAX)
439
-               || (
440
-                   isset($_SERVER['REQUEST_URI'])
441
-                   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
442
-               );
443
-    }
444
-
445
-
446
-    /**
447
-     * @param string $var_name
448
-     * @param string $heading_tag
449
-     * @param string $margin
450
-     * @param int    $line
451
-     * @return string
452
-     */
453
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
454
-    {
455
-        if (EEH_Debug_Tools::plainOutput()) {
456
-            $heading = '';
457
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
458
-                $heading .= self::lineBreak();
459
-            }
460
-            $heading .= self::lineBreak() . "{$line}) {$var_name}";
461
-            return $heading;
462
-        }
463
-        $margin = "25px 0 0 {$margin}";
464
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
465
-    }
466
-
467
-
468
-
469
-    /**
470
-     * @param string $heading_tag
471
-     * @return string
472
-     */
473
-    protected static function headingX($heading_tag = 'h5')
474
-    {
475
-        if (EEH_Debug_Tools::plainOutput()) {
476
-            return '';
477
-        }
478
-        return '</' . $heading_tag . '>';
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * @param string $content
485
-     * @return string
486
-     */
487
-    protected static function grey_span($content = '')
488
-    {
489
-        if (EEH_Debug_Tools::plainOutput()) {
490
-            return $content;
491
-        }
492
-        return '<span style="color:#999">' . $content . '</span>';
493
-    }
494
-
495
-
496
-
497
-    /**
498
-     * @param string $file
499
-     * @param int    $line
500
-     * @return string
501
-     */
502
-    protected static function file_and_line($file, $line, $heading_tag)
503
-    {
504
-        if ($file === '' || $line === '') {
505
-            return '';
506
-        }
507
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
508
-        if (EEH_Debug_Tools::plainOutput()) {
509
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
510
-                return " ({$file})";
511
-            }
512
-            return '';
513
-        }
514
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
515
-               . $file
516
-               . '<br />line no: '
517
-               . $line
518
-               . '</span>';
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * @param string $content
525
-     * @return string
526
-     */
527
-    protected static function orange_span($content = '')
528
-    {
529
-        if (EEH_Debug_Tools::plainOutput()) {
530
-            return $content;
531
-        }
532
-        return '<span style="color:#E76700">' . $content . '</span>';
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * @param mixed $var
539
-     * @return string
540
-     */
541
-    protected static function pre_span($var)
542
-    {
543
-        ob_start();
544
-        var_dump($var);
545
-        $var = ob_get_clean();
546
-        if (EEH_Debug_Tools::plainOutput()) {
547
-            return str_replace("\n", '', $var);
548
-        }
549
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * @param mixed      $var
556
-     * @param string     $var_name
557
-     * @param string     $file
558
-     * @param int|string $line
559
-     * @param int|string $heading_tag
560
-     * @param bool       $die
561
-     */
562
-    public static function printr(
563
-        $var,
564
-        $var_name = '',
565
-        $file = '',
566
-        $line = '',
567
-        $heading_tag = 5,
568
-        $die = false
569
-    ) {
570
-        // return;
571
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
572
-        $margin = is_admin() ? ' 180px' : '0';
573
-        if (is_string($var)) {
574
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
575
-            return;
576
-        }
577
-        if (is_object($var)) {
578
-            $var_name = ! $var_name ? 'object' : $var_name;
579
-        } elseif (is_array($var)) {
580
-            $var_name = ! $var_name ? 'array' : $var_name;
581
-        } elseif (is_numeric($var)) {
582
-            $var_name = ! $var_name ? 'numeric' : $var_name;
583
-        } elseif ($var === null) {
584
-            $var_name = ! $var_name ? 'null' : $var_name;
585
-        }
586
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
587
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
588
-        $result = EEH_Debug_Tools::headingSpacer($heading_tag);
589
-        $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
590
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
591
-            EEH_Debug_Tools::pre_span($var)
592
-        );
593
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
594
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
595
-        if ($die) {
596
-            die($result);
597
-        }
598
-        echo wp_kses($result, AllowedTags::getWithFormTags());
599
-    }
600
-
601
-
602
-
603
-    /******************** deprecated ********************/
604
-
605
-
606
-
607
-    /**
608
-     * @deprecated 4.9.39.rc.034
609
-     */
610
-    public function reset_times()
611
-    {
612
-        Benchmark::resetTimes();
613
-    }
614
-
615
-
616
-
617
-    /**
618
-     * @deprecated 4.9.39.rc.034
619
-     * @param null $timer_name
620
-     */
621
-    public function start_timer($timer_name = null)
622
-    {
623
-        Benchmark::startTimer($timer_name);
624
-    }
625
-
626
-
627
-
628
-    /**
629
-     * @deprecated 4.9.39.rc.034
630
-     * @param string $timer_name
631
-     */
632
-    public function stop_timer($timer_name = '')
633
-    {
634
-        Benchmark::stopTimer($timer_name);
635
-    }
636
-
637
-
638
-
639
-    /**
640
-     * @deprecated 4.9.39.rc.034
641
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
642
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
643
-     * @return void
644
-     */
645
-    public function measure_memory($label, $output_now = false)
646
-    {
647
-        Benchmark::measureMemory($label, $output_now);
648
-    }
649
-
650
-
651
-
652
-    /**
653
-     * @deprecated 4.9.39.rc.034
654
-     * @param int $size
655
-     * @return string
656
-     */
657
-    public function convert($size)
658
-    {
659
-        return Benchmark::convert($size);
660
-    }
661
-
662
-
663
-
664
-    /**
665
-     * @deprecated 4.9.39.rc.034
666
-     * @param bool $output_now
667
-     * @return string
668
-     */
669
-    public function show_times($output_now = true)
670
-    {
671
-        return Benchmark::displayResults($output_now);
672
-    }
673
-
674
-
675
-
676
-    /**
677
-     * @deprecated 4.9.39.rc.034
678
-     * @param string $timer_name
679
-     * @param float  $total_time
680
-     * @return string
681
-     */
682
-    public function format_time($timer_name, $total_time)
683
-    {
684
-        return Benchmark::formatTime($timer_name, $total_time);
685
-    }
19
+	/**
20
+	 *    instance of the EEH_Autoloader object
21
+	 *
22
+	 * @var    $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $_memory_usage_points = array();
31
+
32
+
33
+
34
+	/**
35
+	 * @singleton method used to instantiate class object
36
+	 * @access    public
37
+	 * @return EEH_Debug_Tools
38
+	 */
39
+	public static function instance()
40
+	{
41
+		// check if class object is instantiated, and instantiated properly
42
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+			self::$_instance = new self();
44
+		}
45
+		return self::$_instance;
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * private class constructor
52
+	 */
53
+	private function __construct()
54
+	{
55
+		// load Kint PHP debugging library
56
+		if (
57
+			defined('EE_LOAD_KINT')
58
+			&& ! class_exists('Kint')
59
+			&& file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')
60
+		) {
61
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
62
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
63
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
64
+			// so we've moved it to our test folder so that it is not included with production releases
65
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
66
+			require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
67
+		}
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[ $tag ] = $wp_filter[ $tag ];
134
+			if (! is_array($hook[ $tag ])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . esc_html($tag) . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>esc_html($tag_name)</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo esc_html($priority);
148
+				foreach ($function as $name => $properties) {
149
+					$name = esc_html($name);
150
+					echo "\t$name<br />";
151
+				}
152
+			}
153
+		}
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    registered_filter_callbacks
160
+	 *
161
+	 * @param string $hook_name
162
+	 * @return array
163
+	 */
164
+	public static function registered_filter_callbacks($hook_name = '')
165
+	{
166
+		$filters = array();
167
+		global $wp_filter;
168
+		if (isset($wp_filter[ $hook_name ])) {
169
+			$filters[ $hook_name ] = array();
170
+			foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
171
+				$filters[ $hook_name ][ $priority ] = array();
172
+				foreach ($callbacks as $callback) {
173
+					$filters[ $hook_name ][ $priority ][] = $callback['function'];
174
+				}
175
+			}
176
+		}
177
+		return $filters;
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *    captures plugin activation errors for debugging
184
+	 *
185
+	 * @return void
186
+	 * @throws EE_Error
187
+	 */
188
+	public static function ee_plugin_activation_errors()
189
+	{
190
+		if (WP_DEBUG) {
191
+			$activation_errors = ob_get_contents();
192
+			if (! empty($activation_errors)) {
193
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
194
+			}
195
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
196
+			if (class_exists('EEH_File')) {
197
+				try {
198
+					EEH_File::ensure_file_exists_and_is_writable(
199
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
200
+					);
201
+					EEH_File::write_to_file(
202
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
203
+						$activation_errors
204
+					);
205
+				} catch (EE_Error $e) {
206
+					EE_Error::add_error(
207
+						sprintf(
208
+							esc_html__(
209
+								'The Event Espresso activation errors file could not be setup because: %s',
210
+								'event_espresso'
211
+							),
212
+							$e->getMessage()
213
+						),
214
+						__FILE__,
215
+						__FUNCTION__,
216
+						__LINE__
217
+					);
218
+				}
219
+			} else {
220
+				// old school attempt
221
+				file_put_contents(
222
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
223
+					$activation_errors
224
+				);
225
+			}
226
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
227
+			update_option('ee_plugin_activation_errors', $activation_errors);
228
+		}
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
235
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
236
+	 * or we want to make sure they use something the right way.
237
+	 *
238
+	 * @access public
239
+	 * @param string $function      The function that was called
240
+	 * @param string $message       A message explaining what has been done incorrectly
241
+	 * @param string $version       The version of Event Espresso where the error was added
242
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
243
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
244
+	 *                              but not have any notices appear until a later version. This allows developers
245
+	 *                              extra time to update their code before notices appear.
246
+	 * @param int    $error_type
247
+	 * @uses   trigger_error()
248
+	 */
249
+	public function doing_it_wrong(
250
+		$function,
251
+		$message,
252
+		$version,
253
+		$applies_when = '',
254
+		$error_type = null
255
+	) {
256
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
257
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
258
+		// because we swapped the parameter order around for the last two params,
259
+		// let's verify that some third party isn't still passing an error type value for the third param
260
+		if (is_int($applies_when)) {
261
+			$error_type = $applies_when;
262
+			$applies_when = espresso_version();
263
+		}
264
+		// if not displaying notices yet, then just leave
265
+		if (version_compare(espresso_version(), $applies_when, '<')) {
266
+			return;
267
+		}
268
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
269
+		$version = $version === null
270
+			? ''
271
+			: sprintf(
272
+				esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
273
+				$version
274
+			);
275
+		$error_message = sprintf(
276
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
277
+			$function,
278
+			'<strong>',
279
+			'</strong>',
280
+			$message,
281
+			$version
282
+		);
283
+		// don't trigger error if doing ajax,
284
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
285
+		if (defined('DOING_AJAX') && DOING_AJAX) {
286
+			$error_message .= ' ' . esc_html__(
287
+				'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
288
+				'event_espresso'
289
+			);
290
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
291
+			$error_message .= '<ul><li>';
292
+			$error_message .= implode('</li><li>', $request->requestParams());
293
+			$error_message .= '</ul>';
294
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
295
+			// now we set this on the transient so it shows up on the next request.
296
+			EE_Error::get_notices(false, true);
297
+		} else {
298
+			trigger_error($error_message, $error_type);
299
+		}
300
+	}
301
+
302
+
303
+
304
+
305
+	/**
306
+	 * Logger helpers
307
+	 */
308
+	/**
309
+	 * debug
310
+	 *
311
+	 * @param string $class
312
+	 * @param string $func
313
+	 * @param string $line
314
+	 * @param array  $info
315
+	 * @param bool   $display_request
316
+	 * @param string $debug_index
317
+	 * @param string $debug_key
318
+	 */
319
+	public static function log(
320
+		$class = '',
321
+		$func = '',
322
+		$line = '',
323
+		$info = array(),
324
+		$display_request = false,
325
+		$debug_index = '',
326
+		$debug_key = 'EE_DEBUG_SPCO'
327
+	) {
328
+		if (WP_DEBUG) {
329
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
330
+			$debug_data = get_option($debug_key, array());
331
+			$default_data = array(
332
+				$class => $func . '() : ' . $line,
333
+			);
334
+			// don't serialize objects
335
+			$info = self::strip_objects($info);
336
+			$index = ! empty($debug_index) ? $debug_index : 0;
337
+			if (! isset($debug_data[ $index ])) {
338
+				$debug_data[ $index ] = array();
339
+			}
340
+			$debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
341
+			update_option($debug_key, $debug_data);
342
+		}
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * strip_objects
349
+	 *
350
+	 * @param array $info
351
+	 * @return array
352
+	 */
353
+	public static function strip_objects($info = array())
354
+	{
355
+		foreach ($info as $key => $value) {
356
+			if (is_array($value)) {
357
+				$info[ $key ] = self::strip_objects($value);
358
+			} elseif (is_object($value)) {
359
+				$object_class = get_class($value);
360
+				$info[ $object_class ] = array();
361
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
362
+				if (method_exists($value, 'ID')) {
363
+					$info[ $object_class ]['ID'] = $value->ID();
364
+				}
365
+				if (method_exists($value, 'status')) {
366
+					$info[ $object_class ]['status'] = $value->status();
367
+				} elseif (method_exists($value, 'status_ID')) {
368
+					$info[ $object_class ]['status'] = $value->status_ID();
369
+				}
370
+				unset($info[ $key ]);
371
+			}
372
+		}
373
+		return (array) $info;
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * @param mixed      $var
380
+	 * @param string     $var_name
381
+	 * @param string     $file
382
+	 * @param int|string $line
383
+	 * @param int|string $heading_tag
384
+	 * @param bool       $die
385
+	 * @param string     $margin
386
+	 */
387
+	public static function printv(
388
+		$var,
389
+		$var_name = '',
390
+		$file = '',
391
+		$line = '',
392
+		$heading_tag = 5,
393
+		$die = false,
394
+		$margin = ''
395
+	) {
396
+		$var_name = ! $var_name ? 'string' : $var_name;
397
+		$var_name = ucwords(str_replace('$', '', $var_name));
398
+		$is_method = method_exists($var_name, $var);
399
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
400
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
401
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
402
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
403
+		$result .= $is_method
404
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
405
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
406
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
407
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
408
+		if ($die) {
409
+			die($result);
410
+		}
411
+		echo wp_kses($result, AllowedTags::getWithFormTags());
412
+	}
413
+
414
+
415
+	protected static function headingTag($heading_tag)
416
+	{
417
+		$heading_tag = absint($heading_tag);
418
+		return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
419
+	}
420
+
421
+	protected static function headingSpacer($heading_tag)
422
+	{
423
+		return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
424
+			? self::lineBreak()
425
+			: '';
426
+	}
427
+
428
+
429
+	protected static function lineBreak()
430
+	{
431
+		return defined('DOING_AJAX') && DOING_AJAX ? '<br />' : "\n";
432
+	}
433
+
434
+
435
+	protected static function plainOutput()
436
+	{
437
+		return defined('EE_TESTS_DIR')
438
+			   || (defined('DOING_AJAX') && DOING_AJAX)
439
+			   || (
440
+				   isset($_SERVER['REQUEST_URI'])
441
+				   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
442
+			   );
443
+	}
444
+
445
+
446
+	/**
447
+	 * @param string $var_name
448
+	 * @param string $heading_tag
449
+	 * @param string $margin
450
+	 * @param int    $line
451
+	 * @return string
452
+	 */
453
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
454
+	{
455
+		if (EEH_Debug_Tools::plainOutput()) {
456
+			$heading = '';
457
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
458
+				$heading .= self::lineBreak();
459
+			}
460
+			$heading .= self::lineBreak() . "{$line}) {$var_name}";
461
+			return $heading;
462
+		}
463
+		$margin = "25px 0 0 {$margin}";
464
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
465
+	}
466
+
467
+
468
+
469
+	/**
470
+	 * @param string $heading_tag
471
+	 * @return string
472
+	 */
473
+	protected static function headingX($heading_tag = 'h5')
474
+	{
475
+		if (EEH_Debug_Tools::plainOutput()) {
476
+			return '';
477
+		}
478
+		return '</' . $heading_tag . '>';
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * @param string $content
485
+	 * @return string
486
+	 */
487
+	protected static function grey_span($content = '')
488
+	{
489
+		if (EEH_Debug_Tools::plainOutput()) {
490
+			return $content;
491
+		}
492
+		return '<span style="color:#999">' . $content . '</span>';
493
+	}
494
+
495
+
496
+
497
+	/**
498
+	 * @param string $file
499
+	 * @param int    $line
500
+	 * @return string
501
+	 */
502
+	protected static function file_and_line($file, $line, $heading_tag)
503
+	{
504
+		if ($file === '' || $line === '') {
505
+			return '';
506
+		}
507
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
508
+		if (EEH_Debug_Tools::plainOutput()) {
509
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
510
+				return " ({$file})";
511
+			}
512
+			return '';
513
+		}
514
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
515
+			   . $file
516
+			   . '<br />line no: '
517
+			   . $line
518
+			   . '</span>';
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * @param string $content
525
+	 * @return string
526
+	 */
527
+	protected static function orange_span($content = '')
528
+	{
529
+		if (EEH_Debug_Tools::plainOutput()) {
530
+			return $content;
531
+		}
532
+		return '<span style="color:#E76700">' . $content . '</span>';
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * @param mixed $var
539
+	 * @return string
540
+	 */
541
+	protected static function pre_span($var)
542
+	{
543
+		ob_start();
544
+		var_dump($var);
545
+		$var = ob_get_clean();
546
+		if (EEH_Debug_Tools::plainOutput()) {
547
+			return str_replace("\n", '', $var);
548
+		}
549
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * @param mixed      $var
556
+	 * @param string     $var_name
557
+	 * @param string     $file
558
+	 * @param int|string $line
559
+	 * @param int|string $heading_tag
560
+	 * @param bool       $die
561
+	 */
562
+	public static function printr(
563
+		$var,
564
+		$var_name = '',
565
+		$file = '',
566
+		$line = '',
567
+		$heading_tag = 5,
568
+		$die = false
569
+	) {
570
+		// return;
571
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
572
+		$margin = is_admin() ? ' 180px' : '0';
573
+		if (is_string($var)) {
574
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
575
+			return;
576
+		}
577
+		if (is_object($var)) {
578
+			$var_name = ! $var_name ? 'object' : $var_name;
579
+		} elseif (is_array($var)) {
580
+			$var_name = ! $var_name ? 'array' : $var_name;
581
+		} elseif (is_numeric($var)) {
582
+			$var_name = ! $var_name ? 'numeric' : $var_name;
583
+		} elseif ($var === null) {
584
+			$var_name = ! $var_name ? 'null' : $var_name;
585
+		}
586
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
587
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
588
+		$result = EEH_Debug_Tools::headingSpacer($heading_tag);
589
+		$result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
590
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
591
+			EEH_Debug_Tools::pre_span($var)
592
+		);
593
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
594
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
595
+		if ($die) {
596
+			die($result);
597
+		}
598
+		echo wp_kses($result, AllowedTags::getWithFormTags());
599
+	}
600
+
601
+
602
+
603
+	/******************** deprecated ********************/
604
+
605
+
606
+
607
+	/**
608
+	 * @deprecated 4.9.39.rc.034
609
+	 */
610
+	public function reset_times()
611
+	{
612
+		Benchmark::resetTimes();
613
+	}
614
+
615
+
616
+
617
+	/**
618
+	 * @deprecated 4.9.39.rc.034
619
+	 * @param null $timer_name
620
+	 */
621
+	public function start_timer($timer_name = null)
622
+	{
623
+		Benchmark::startTimer($timer_name);
624
+	}
625
+
626
+
627
+
628
+	/**
629
+	 * @deprecated 4.9.39.rc.034
630
+	 * @param string $timer_name
631
+	 */
632
+	public function stop_timer($timer_name = '')
633
+	{
634
+		Benchmark::stopTimer($timer_name);
635
+	}
636
+
637
+
638
+
639
+	/**
640
+	 * @deprecated 4.9.39.rc.034
641
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
642
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
643
+	 * @return void
644
+	 */
645
+	public function measure_memory($label, $output_now = false)
646
+	{
647
+		Benchmark::measureMemory($label, $output_now);
648
+	}
649
+
650
+
651
+
652
+	/**
653
+	 * @deprecated 4.9.39.rc.034
654
+	 * @param int $size
655
+	 * @return string
656
+	 */
657
+	public function convert($size)
658
+	{
659
+		return Benchmark::convert($size);
660
+	}
661
+
662
+
663
+
664
+	/**
665
+	 * @deprecated 4.9.39.rc.034
666
+	 * @param bool $output_now
667
+	 * @return string
668
+	 */
669
+	public function show_times($output_now = true)
670
+	{
671
+		return Benchmark::displayResults($output_now);
672
+	}
673
+
674
+
675
+
676
+	/**
677
+	 * @deprecated 4.9.39.rc.034
678
+	 * @param string $timer_name
679
+	 * @param float  $total_time
680
+	 * @return string
681
+	 */
682
+	public function format_time($timer_name, $total_time)
683
+	{
684
+		return Benchmark::formatTime($timer_name, $total_time);
685
+	}
686 686
 }
687 687
 
688 688
 
@@ -692,31 +692,31 @@  discard block
 block discarded – undo
692 692
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
693 693
  */
694 694
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
695
-    function dump_wp_query()
696
-    {
697
-        global $wp_query;
698
-        d($wp_query);
699
-    }
695
+	function dump_wp_query()
696
+	{
697
+		global $wp_query;
698
+		d($wp_query);
699
+	}
700 700
 }
701 701
 /**
702 702
  * borrowed from Kint Debugger
703 703
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
704 704
  */
705 705
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
706
-    function dump_wp()
707
-    {
708
-        global $wp;
709
-        d($wp);
710
-    }
706
+	function dump_wp()
707
+	{
708
+		global $wp;
709
+		d($wp);
710
+	}
711 711
 }
712 712
 /**
713 713
  * borrowed from Kint Debugger
714 714
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
715 715
  */
716 716
 if (class_exists('Kint') && ! function_exists('dump_post')) {
717
-    function dump_post()
718
-    {
719
-        global $post;
720
-        d($post);
721
-    }
717
+	function dump_post()
718
+	{
719
+		global $post;
720
+		d($post);
721
+	}
722 722
 }
Please login to merge, or discard this patch.
core/exceptions/ExceptionStackTraceDisplay.php 2 patches
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -20,159 +20,159 @@  discard block
 block discarded – undo
20 20
 class ExceptionStackTraceDisplay
21 21
 {
22 22
 
23
-    /**
24
-     * @var   string
25
-     * @since 4.10.24.p
26
-     */
27
-    private $class_name = '';
23
+	/**
24
+	 * @var   string
25
+	 * @since 4.10.24.p
26
+	 */
27
+	private $class_name = '';
28 28
 
29
-    /**
30
-     * @var   string
31
-     * @since 4.10.24.p
32
-     */
33
-    private $error_code = '';
29
+	/**
30
+	 * @var   string
31
+	 * @since 4.10.24.p
32
+	 */
33
+	private $error_code = '';
34 34
 
35 35
 
36
-    /**
37
-     * @param Exception $exception
38
-     * @throws Exception
39
-     */
40
-    public function __construct(Exception $exception)
41
-    {
42
-        if (WP_DEBUG && ! defined('EE_TESTS_DIR')) {
43
-            $this->displayException($exception);
44
-        } else {
45
-            throw $exception;
46
-        }
47
-    }
36
+	/**
37
+	 * @param Exception $exception
38
+	 * @throws Exception
39
+	 */
40
+	public function __construct(Exception $exception)
41
+	{
42
+		if (WP_DEBUG && ! defined('EE_TESTS_DIR')) {
43
+			$this->displayException($exception);
44
+		} else {
45
+			throw $exception;
46
+		}
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * @access protected
52
-     * @param Exception $exception
53
-     * @throws ReflectionException
54
-     */
55
-    protected function displayException(Exception $exception)
56
-    {
57
-        // get separate user and developer messages if they exist
58
-        $msg = explode('||', $exception->getMessage());
59
-        $user_msg = $msg[0];
60
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
61
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
62
-        // process trace info
63
-        $trace_details = $this->traceDetails($exception);
64
-        $code          = $exception->getCode() ?: $this->error_code;
65
-        // add helpful developer messages if debugging is on
66
-        // or generic non-identifying messages for non-privileged users
67
-        $error_message = WP_DEBUG
68
-            ? $this->developerError($exception, $msg, $code, $trace_details)
69
-            : $this->genericError($msg, $code);
70
-        // start gathering output
71
-        $output = '
50
+	/**
51
+	 * @access protected
52
+	 * @param Exception $exception
53
+	 * @throws ReflectionException
54
+	 */
55
+	protected function displayException(Exception $exception)
56
+	{
57
+		// get separate user and developer messages if they exist
58
+		$msg = explode('||', $exception->getMessage());
59
+		$user_msg = $msg[0];
60
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
61
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
62
+		// process trace info
63
+		$trace_details = $this->traceDetails($exception);
64
+		$code          = $exception->getCode() ?: $this->error_code;
65
+		// add helpful developer messages if debugging is on
66
+		// or generic non-identifying messages for non-privileged users
67
+		$error_message = WP_DEBUG
68
+			? $this->developerError($exception, $msg, $code, $trace_details)
69
+			: $this->genericError($msg, $code);
70
+		// start gathering output
71
+		$output = '
72 72
 <div id="ee-error-message" class="error">
73 73
     ' . $error_message . '
74 74
 </div>';
75
-        $styles = $this->exceptionStyles();
76
-        $scripts = $this->printScripts(true);
77
-        if (defined('DOING_AJAX')) {
78
-            echo wp_json_encode(array('error' => $styles . $output . $scripts));
79
-            exit();
80
-        }
81
-        echo $styles, wp_kses($output, AllowedTags::getWithFormTags()), $scripts;
82
-    }
75
+		$styles = $this->exceptionStyles();
76
+		$scripts = $this->printScripts(true);
77
+		if (defined('DOING_AJAX')) {
78
+			echo wp_json_encode(array('error' => $styles . $output . $scripts));
79
+			exit();
80
+		}
81
+		echo $styles, wp_kses($output, AllowedTags::getWithFormTags()), $scripts;
82
+	}
83 83
 
84 84
 
85
-    private function genericError($msg, $code)
86
-    {
87
-        return '
85
+	private function genericError($msg, $code)
86
+	{
87
+		return '
88 88
     <p>
89 89
         <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> &nbsp; <sup>' . $code . '</sup>
90 90
     </p>';
91
-    }
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * @throws ReflectionException
96
-     */
97
-    private function developerError(Exception $exception, $msg, $code, $trace_details)
98
-    {
99
-        $time = time();
100
-        return '
94
+	/**
95
+	 * @throws ReflectionException
96
+	 */
97
+	private function developerError(Exception $exception, $msg, $code, $trace_details)
98
+	{
99
+		$time = time();
100
+		return '
101 101
 	<div class="ee-error-dev-msg-dv">
102 102
 		<p class="ee-error-dev-msg-pg">
103 103
 		    '
104
-            . sprintf(
105
-                esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
106
-                '<strong class="ee-error-dev-msg-str">',
107
-                get_class($exception),
108
-                '</strong>  &nbsp; <span>',
109
-                $code . '</span>'
110
-            )
111
-            . '<br />
104
+			. sprintf(
105
+				esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
106
+				'<strong class="ee-error-dev-msg-str">',
107
+				get_class($exception),
108
+				'</strong>  &nbsp; <span>',
109
+				$code . '</span>'
110
+			)
111
+			. '<br />
112 112
             <span class="big-text">"' . trim($msg) . '"</span><br/>
113 113
             <a id="display-ee-error-trace-1'
114
-               . $time
115
-               . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
116
-               . $time
117
-               . '">
114
+			   . $time
115
+			   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
116
+			   . $time
117
+			   . '">
118 118
                 ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . '
119 119
             </a><br />
120 120
             '
121
-            . $exception->getFile()
122
-            . sprintf(
123
-                esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'),
124
-                ' &nbsp; <span class="small-text lt-grey-text">',
125
-                $exception->getLine(),
126
-                '</span>'
127
-            )
128
-            . '
121
+			. $exception->getFile()
122
+			. sprintf(
123
+				esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'),
124
+				' &nbsp; <span class="small-text lt-grey-text">',
125
+				$exception->getLine(),
126
+				'</span>'
127
+			)
128
+			. '
129 129
         </p>
130 130
         <div id="ee-error-trace-1'
131
-               . $time
132
-               . '-dv" class="ee-error-trace-dv" style="display: none;">
131
+			   . $time
132
+			   . '-dv" class="ee-error-trace-dv" style="display: none;">
133 133
             '
134
-               . $trace_details
135
-               . $this->classDetails() . '
134
+			   . $trace_details
135
+			   . $this->classDetails() . '
136 136
         </div>
137 137
     </div>';
138
-    }
138
+	}
139 139
 
140 140
 
141
-    /**
142
-     * @throws ReflectionException
143
-     */
144
-    private function classDetails()
145
-    {
146
-        if (empty($this->class_name)) {
147
-            return '';
148
-        }
149
-        $a = new ReflectionClass($this->class_name);
150
-        return '
141
+	/**
142
+	 * @throws ReflectionException
143
+	 */
144
+	private function classDetails()
145
+	{
146
+		if (empty($this->class_name)) {
147
+			return '';
148
+		}
149
+		$a = new ReflectionClass($this->class_name);
150
+		return '
151 151
             <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
152 152
                 <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
153 153
                     <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3>
154 154
                     <pre>' . $a . '</pre>
155 155
                 </div>
156 156
             </div>';
157
-    }
157
+	}
158 158
 
159
-    /**
160
-     * @param Exception $exception
161
-     * @return string
162
-     * @throws ReflectionException
163
-     * @since 4.10.24.p
164
-     */
165
-    private function traceDetails(Exception $exception)
166
-    {
167
-        $trace = $exception->getTrace();
168
-        if (empty($trace)) {
169
-            return esc_html__(
170
-                'Sorry, but no trace information was available for this exception.',
171
-                'event_espresso'
172
-            );
173
-        }
159
+	/**
160
+	 * @param Exception $exception
161
+	 * @return string
162
+	 * @throws ReflectionException
163
+	 * @since 4.10.24.p
164
+	 */
165
+	private function traceDetails(Exception $exception)
166
+	{
167
+		$trace = $exception->getTrace();
168
+		if (empty($trace)) {
169
+			return esc_html__(
170
+				'Sorry, but no trace information was available for this exception.',
171
+				'event_espresso'
172
+			);
173
+		}
174 174
 
175
-        $trace_details = '
175
+		$trace_details = '
176 176
         <div id="ee-trace-details">
177 177
             <table>
178 178
                 <tr>
@@ -181,160 +181,160 @@  discard block
 block discarded – undo
181 181
                     <th scope="col" class="ee-align-left" style="width:40%;">File</th>
182 182
                     <th scope="col" class="ee-align-left">
183 183
                     ' . esc_html__('Class', 'event_espresso')
184
-                              . '->'
185
-                              . esc_html__('Method( arguments )', 'event_espresso') . '
184
+							  . '->'
185
+							  . esc_html__('Method( arguments )', 'event_espresso') . '
186 186
                     </th>
187 187
                 </tr>';
188
-        $last_on_stack = count($trace) - 1;
189
-        // reverse array so that stack is in proper chronological order
190
-        $sorted_trace = array_reverse($trace);
191
-        foreach ($sorted_trace as $nmbr => $trace) {
192
-            $this->class_name = isset($trace['class']) ? $trace['class'] : '';
193
-            $file     = isset($trace['file']) ? $trace['file'] : '';
194
-            $type     = isset($trace['type']) ? $trace['type'] : '';
195
-            $function = isset($trace['function']) ? $trace['function'] : '';
196
-            $args     = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
197
-            $args     = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
198
-            $line     = isset($trace['line']) ? $trace['line'] : '';
199
-            if (empty($file) && ! empty($this->class_name)) {
200
-                $a    = new ReflectionClass($this->class_name);
201
-                $file = $a->getFileName();
202
-                if (empty($line) && ! empty($function)) {
203
-                    try {
204
-                        // if $function is a closure, this throws an exception
205
-                        $b    = new ReflectionMethod($this->class_name, $function);
206
-                        $line = $b->getStartLine();
207
-                    } catch (Exception $closure_exception) {
208
-                        $line = 'unknown';
209
-                    }
210
-                }
211
-            }
212
-            if ($nmbr === $last_on_stack) {
213
-                $file       = $exception->getFile() ?: $file;
214
-                $line       = $exception->getLine() ?: $line;
215
-                $this->error_code = $this->generate_error_code($file, $trace['function'], $line);
216
-            }
217
-            $file          = EEH_File::standardise_directory_separators($file);
218
-            $nmbr          = ! empty($nmbr) ? $nmbr : '&nbsp;';
219
-            $line          = ! empty($line) ? $line : '&nbsp;';
220
-            $file          = ! empty($file) ? $file : '&nbsp;';
221
-            $type          = ! empty($type) ? $type : '';
222
-            $function      = ! empty($function) ? $function : '';
223
-            $args          = ! empty($args) ? '( ' . $args . ' )' : '()';
224
-            $trace_details .= '
188
+		$last_on_stack = count($trace) - 1;
189
+		// reverse array so that stack is in proper chronological order
190
+		$sorted_trace = array_reverse($trace);
191
+		foreach ($sorted_trace as $nmbr => $trace) {
192
+			$this->class_name = isset($trace['class']) ? $trace['class'] : '';
193
+			$file     = isset($trace['file']) ? $trace['file'] : '';
194
+			$type     = isset($trace['type']) ? $trace['type'] : '';
195
+			$function = isset($trace['function']) ? $trace['function'] : '';
196
+			$args     = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
197
+			$args     = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
198
+			$line     = isset($trace['line']) ? $trace['line'] : '';
199
+			if (empty($file) && ! empty($this->class_name)) {
200
+				$a    = new ReflectionClass($this->class_name);
201
+				$file = $a->getFileName();
202
+				if (empty($line) && ! empty($function)) {
203
+					try {
204
+						// if $function is a closure, this throws an exception
205
+						$b    = new ReflectionMethod($this->class_name, $function);
206
+						$line = $b->getStartLine();
207
+					} catch (Exception $closure_exception) {
208
+						$line = 'unknown';
209
+					}
210
+				}
211
+			}
212
+			if ($nmbr === $last_on_stack) {
213
+				$file       = $exception->getFile() ?: $file;
214
+				$line       = $exception->getLine() ?: $line;
215
+				$this->error_code = $this->generate_error_code($file, $trace['function'], $line);
216
+			}
217
+			$file          = EEH_File::standardise_directory_separators($file);
218
+			$nmbr          = ! empty($nmbr) ? $nmbr : '&nbsp;';
219
+			$line          = ! empty($line) ? $line : '&nbsp;';
220
+			$file          = ! empty($file) ? $file : '&nbsp;';
221
+			$type          = ! empty($type) ? $type : '';
222
+			$function      = ! empty($function) ? $function : '';
223
+			$args          = ! empty($args) ? '( ' . $args . ' )' : '()';
224
+			$trace_details .= '
225 225
                 <tr>
226 226
                     <td class="ee-align-right">' . $nmbr . '</td>
227 227
                     <td class="ee-align-right">' . $line . '</td>
228 228
                     <td class="ee-align-left">' . $file . '</td>
229 229
                     <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td>
230 230
                 </tr>';
231
-        }
232
-        $trace_details .= '
231
+		}
232
+		$trace_details .= '
233 233
             </table>
234 234
         </div>';
235
-        return $trace_details;
236
-    }
235
+		return $trace_details;
236
+	}
237 237
 
238 238
 
239
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
240
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
239
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
240
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
241 241
 
242
-    /**
243
-     * generate string from exception trace args
244
-     *
245
-     * @param array $arguments
246
-     * @param int   $indent
247
-     * @param bool  $array
248
-     * @return string
249
-     */
250
-    private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false)
251
-    {
252
-        $args = array();
253
-        $args_count = count($arguments);
254
-        if ($args_count > 2) {
255
-            $indent++;
256
-            $args[] = '<br />';
257
-        }
258
-        $x = 0;
259
-        foreach ($arguments as $arg) {
260
-            $x++;
261
-            for ($i = 0; $i < $indent; $i++) {
262
-                $args[] = ' &nbsp;&nbsp; ';
263
-            }
264
-            if (is_string($arg)) {
265
-                if (! $array && strlen($arg) > 75) {
266
-                    $args[] = '<br />';
267
-                    for ($i = 0; $i <= $indent; $i++) {
268
-                        $args[] = ' &nbsp;&nbsp; ';
269
-                    }
270
-                    $args[] = "'" . $arg . "'<br />";
271
-                } else {
272
-                    $args[] = " '" . $arg . "'";
273
-                }
274
-            } elseif (is_array($arg)) {
275
-                $arg_count = count($arg);
276
-                if ($arg_count > 2) {
277
-                    $indent++;
278
-                    $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
279
-                    $indent--;
280
-                } elseif ($arg_count === 0) {
281
-                    $args[] = ' array()';
282
-                } else {
283
-                    $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
284
-                }
285
-            } elseif ($arg === null) {
286
-                $args[] = ' null';
287
-            } elseif (is_bool($arg)) {
288
-                $args[] = $arg ? ' true' : ' false';
289
-            } elseif (is_object($arg)) {
290
-                $args[] = get_class($arg);
291
-            } elseif (is_resource($arg)) {
292
-                $args[] = get_resource_type($arg);
293
-            } else {
294
-                $args[] = $arg;
295
-            }
296
-            if ($x === $args_count) {
297
-                if ($args_count > 2) {
298
-                    $args[] = '<br />';
299
-                    $indent--;
300
-                    for ($i = 1; $i < $indent; $i++) {
301
-                        $args[] = ' &nbsp;&nbsp; ';
302
-                    }
303
-                }
304
-            } else {
305
-                $args[] = $args_count > 2 ? ',<br />' : ', ';
306
-            }
307
-        }
308
-        return implode('', $args);
309
-    }
242
+	/**
243
+	 * generate string from exception trace args
244
+	 *
245
+	 * @param array $arguments
246
+	 * @param int   $indent
247
+	 * @param bool  $array
248
+	 * @return string
249
+	 */
250
+	private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false)
251
+	{
252
+		$args = array();
253
+		$args_count = count($arguments);
254
+		if ($args_count > 2) {
255
+			$indent++;
256
+			$args[] = '<br />';
257
+		}
258
+		$x = 0;
259
+		foreach ($arguments as $arg) {
260
+			$x++;
261
+			for ($i = 0; $i < $indent; $i++) {
262
+				$args[] = ' &nbsp;&nbsp; ';
263
+			}
264
+			if (is_string($arg)) {
265
+				if (! $array && strlen($arg) > 75) {
266
+					$args[] = '<br />';
267
+					for ($i = 0; $i <= $indent; $i++) {
268
+						$args[] = ' &nbsp;&nbsp; ';
269
+					}
270
+					$args[] = "'" . $arg . "'<br />";
271
+				} else {
272
+					$args[] = " '" . $arg . "'";
273
+				}
274
+			} elseif (is_array($arg)) {
275
+				$arg_count = count($arg);
276
+				if ($arg_count > 2) {
277
+					$indent++;
278
+					$args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
279
+					$indent--;
280
+				} elseif ($arg_count === 0) {
281
+					$args[] = ' array()';
282
+				} else {
283
+					$args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
284
+				}
285
+			} elseif ($arg === null) {
286
+				$args[] = ' null';
287
+			} elseif (is_bool($arg)) {
288
+				$args[] = $arg ? ' true' : ' false';
289
+			} elseif (is_object($arg)) {
290
+				$args[] = get_class($arg);
291
+			} elseif (is_resource($arg)) {
292
+				$args[] = get_resource_type($arg);
293
+			} else {
294
+				$args[] = $arg;
295
+			}
296
+			if ($x === $args_count) {
297
+				if ($args_count > 2) {
298
+					$args[] = '<br />';
299
+					$indent--;
300
+					for ($i = 1; $i < $indent; $i++) {
301
+						$args[] = ' &nbsp;&nbsp; ';
302
+					}
303
+				}
304
+			} else {
305
+				$args[] = $args_count > 2 ? ',<br />' : ', ';
306
+			}
307
+		}
308
+		return implode('', $args);
309
+	}
310 310
 
311 311
 
312
-    /**
313
-     * create error code from filepath, function name,
314
-     * and line number where exception or error was thrown
315
-     *
316
-     * @access protected
317
-     * @param string $file
318
-     * @param string $func
319
-     * @param string $line
320
-     * @return string
321
-     */
322
-    protected function generate_error_code($file = '', $func = '', $line = '')
323
-    {
324
-        $file_bits = explode('.', basename($file));
325
-        $error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
326
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
327
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
328
-        return $error_code;
329
-    }
312
+	/**
313
+	 * create error code from filepath, function name,
314
+	 * and line number where exception or error was thrown
315
+	 *
316
+	 * @access protected
317
+	 * @param string $file
318
+	 * @param string $func
319
+	 * @param string $line
320
+	 * @return string
321
+	 */
322
+	protected function generate_error_code($file = '', $func = '', $line = '')
323
+	{
324
+		$file_bits = explode('.', basename($file));
325
+		$error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
326
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
327
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
328
+		return $error_code;
329
+	}
330 330
 
331 331
 
332
-    /**
333
-     * @return string
334
-     */
335
-    private function exceptionStyles()
336
-    {
337
-        return '
332
+	/**
333
+	 * @return string
334
+	 */
335
+	private function exceptionStyles()
336
+	{
337
+		return '
338 338
 <style media="screen">
339 339
 	#ee-error-message {
340 340
 		max-width:90% !important;
@@ -392,34 +392,34 @@  discard block
 block discarded – undo
392 392
 		color: #999;
393 393
 	}
394 394
 </style>';
395
-    }
395
+	}
396 396
 
397 397
 
398
-    /**
399
-     * _print_scripts
400
-     *
401
-     * @param bool $force_print
402
-     * @return string
403
-     */
404
-    private function printScripts($force_print = false)
405
-    {
406
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
407
-            //  if script is already enqueued then we can just get out
408
-            if (wp_script_is('ee_error_js')) {
409
-                return '';
410
-            }
411
-            if (wp_script_is('ee_error_js', 'registered')) {
412
-                wp_enqueue_style('espresso_default');
413
-                wp_enqueue_style('espresso_custom_css');
414
-                wp_enqueue_script('ee_error_js');
415
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
416
-                return '';
417
-            }
418
-        }
419
-        $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js');
420
-        $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version());
421
-        $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version());
422
-        return '
398
+	/**
399
+	 * _print_scripts
400
+	 *
401
+	 * @param bool $force_print
402
+	 * @return string
403
+	 */
404
+	private function printScripts($force_print = false)
405
+	{
406
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
407
+			//  if script is already enqueued then we can just get out
408
+			if (wp_script_is('ee_error_js')) {
409
+				return '';
410
+			}
411
+			if (wp_script_is('ee_error_js', 'registered')) {
412
+				wp_enqueue_style('espresso_default');
413
+				wp_enqueue_style('espresso_custom_css');
414
+				wp_enqueue_script('ee_error_js');
415
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
416
+				return '';
417
+			}
418
+		}
419
+		$jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js');
420
+		$core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version());
421
+		$ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version());
422
+		return '
423 423
 <script>
424 424
 /* <![CDATA[ */
425 425
 const ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -429,5 +429,5 @@  discard block
 block discarded – undo
429 429
 <script src="' . $core . '" type="text/javascript" ></script>
430 430
 <script src="' . $ee_error . '" type="text/javascript" ></script>
431 431
 ';
432
-    }
432
+	}
433 433
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
         // start gathering output
71 71
         $output = '
72 72
 <div id="ee-error-message" class="error">
73
-    ' . $error_message . '
73
+    ' . $error_message.'
74 74
 </div>';
75 75
         $styles = $this->exceptionStyles();
76 76
         $scripts = $this->printScripts(true);
77 77
         if (defined('DOING_AJAX')) {
78
-            echo wp_json_encode(array('error' => $styles . $output . $scripts));
78
+            echo wp_json_encode(array('error' => $styles.$output.$scripts));
79 79
             exit();
80 80
         }
81 81
         echo $styles, wp_kses($output, AllowedTags::getWithFormTags()), $scripts;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         return '
88 88
     <p>
89
-        <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> &nbsp; <sup>' . $code . '</sup>
89
+        <span class="ee-error-user-msg-spn">' . trim($msg).'</span> &nbsp; <sup>'.$code.'</sup>
90 90
     </p>';
91 91
     }
92 92
 
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
                 '<strong class="ee-error-dev-msg-str">',
107 107
                 get_class($exception),
108 108
                 '</strong>  &nbsp; <span>',
109
-                $code . '</span>'
109
+                $code.'</span>'
110 110
             )
111 111
             . '<br />
112
-            <span class="big-text">"' . trim($msg) . '"</span><br/>
112
+            <span class="big-text">"' . trim($msg).'"</span><br/>
113 113
             <a id="display-ee-error-trace-1'
114 114
                . $time
115 115
                . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
116 116
                . $time
117 117
                . '">
118
-                ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . '
118
+                ' . esc_html__('click to view backtrace and class/method details', 'event_espresso').'
119 119
             </a><br />
120 120
             '
121 121
             . $exception->getFile()
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                . '-dv" class="ee-error-trace-dv" style="display: none;">
133 133
             '
134 134
                . $trace_details
135
-               . $this->classDetails() . '
135
+               . $this->classDetails().'
136 136
         </div>
137 137
     </div>';
138 138
     }
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
         return '
151 151
             <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
152 152
                 <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
153
-                    <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3>
154
-                    <pre>' . $a . '</pre>
153
+                    <h3>' . esc_html__('Class Details', 'event_espresso').'</h3>
154
+                    <pre>' . $a.'</pre>
155 155
                 </div>
156 156
             </div>';
157 157
     }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                     <th scope="col" class="ee-align-left">
183 183
                     ' . esc_html__('Class', 'event_espresso')
184 184
                               . '->'
185
-                              . esc_html__('Method( arguments )', 'event_espresso') . '
185
+                              . esc_html__('Method( arguments )', 'event_espresso').'
186 186
                     </th>
187 187
                 </tr>';
188 188
         $last_on_stack = count($trace) - 1;
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
             $type     = isset($trace['type']) ? $trace['type'] : '';
195 195
             $function = isset($trace['function']) ? $trace['function'] : '';
196 196
             $args     = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
197
-            $args     = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
197
+            $args     = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args;
198 198
             $line     = isset($trace['line']) ? $trace['line'] : '';
199 199
             if (empty($file) && ! empty($this->class_name)) {
200 200
                 $a    = new ReflectionClass($this->class_name);
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
             $file          = ! empty($file) ? $file : '&nbsp;';
221 221
             $type          = ! empty($type) ? $type : '';
222 222
             $function      = ! empty($function) ? $function : '';
223
-            $args          = ! empty($args) ? '( ' . $args . ' )' : '()';
223
+            $args          = ! empty($args) ? '( '.$args.' )' : '()';
224 224
             $trace_details .= '
225 225
                 <tr>
226
-                    <td class="ee-align-right">' . $nmbr . '</td>
227
-                    <td class="ee-align-right">' . $line . '</td>
228
-                    <td class="ee-align-left">' . $file . '</td>
229
-                    <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td>
226
+                    <td class="ee-align-right">' . $nmbr.'</td>
227
+                    <td class="ee-align-right">' . $line.'</td>
228
+                    <td class="ee-align-left">' . $file.'</td>
229
+                    <td class="ee-align-left">' . $this->class_name.$type.$function.$args.'</td>
230 230
                 </tr>';
231 231
         }
232 232
         $trace_details .= '
@@ -262,25 +262,25 @@  discard block
 block discarded – undo
262 262
                 $args[] = ' &nbsp;&nbsp; ';
263 263
             }
264 264
             if (is_string($arg)) {
265
-                if (! $array && strlen($arg) > 75) {
265
+                if ( ! $array && strlen($arg) > 75) {
266 266
                     $args[] = '<br />';
267 267
                     for ($i = 0; $i <= $indent; $i++) {
268 268
                         $args[] = ' &nbsp;&nbsp; ';
269 269
                     }
270
-                    $args[] = "'" . $arg . "'<br />";
270
+                    $args[] = "'".$arg."'<br />";
271 271
                 } else {
272
-                    $args[] = " '" . $arg . "'";
272
+                    $args[] = " '".$arg."'";
273 273
                 }
274 274
             } elseif (is_array($arg)) {
275 275
                 $arg_count = count($arg);
276 276
                 if ($arg_count > 2) {
277 277
                     $indent++;
278
-                    $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
278
+                    $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')';
279 279
                     $indent--;
280 280
                 } elseif ($arg_count === 0) {
281 281
                     $args[] = ' array()';
282 282
                 } else {
283
-                    $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
283
+                    $args[] = ' array( '.$this->_convert_args_to_string($arg).' )';
284 284
                 }
285 285
             } elseif ($arg === null) {
286 286
                 $args[] = ' null';
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
     {
324 324
         $file_bits = explode('.', basename($file));
325 325
         $error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
326
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
327
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
326
+        $error_code .= ! empty($func) ? ' - '.$func : '';
327
+        $error_code .= ! empty($line) ? ' - '.$line : '';
328 328
         return $error_code;
329 329
     }
330 330
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
      */
404 404
     private function printScripts($force_print = false)
405 405
     {
406
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
406
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
407 407
             //  if script is already enqueued then we can just get out
408 408
             if (wp_script_is('ee_error_js')) {
409 409
                 return '';
@@ -416,18 +416,18 @@  discard block
 block discarded – undo
416 416
                 return '';
417 417
             }
418 418
         }
419
-        $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js');
420
-        $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version());
421
-        $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version());
419
+        $jquery = esc_url_raw(includes_url().'js/jquery/jquery.js');
420
+        $core = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.espresso_version());
421
+        $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js?ver='.espresso_version());
422 422
         return '
423 423
 <script>
424 424
 /* <![CDATA[ */
425
-const ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
425
+const ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
426 426
 /* ]]> */
427 427
 </script>
428
-<script src="' . $jquery . '" type="text/javascript" ></script>
429
-<script src="' . $core . '" type="text/javascript" ></script>
430
-<script src="' . $ee_error . '" type="text/javascript" ></script>
428
+<script src="' . $jquery.'" type="text/javascript" ></script>
429
+<script src="' . $core.'" type="text/javascript" ></script>
430
+<script src="' . $ee_error.'" type="text/javascript" ></script>
431 431
 ';
432 432
     }
433 433
 }
Please login to merge, or discard this patch.
core/EE_Error.core.php 2 patches
Indentation   +1127 added lines, -1127 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 // if you're a dev and want to receive all errors via email
13 13
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
14 14
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
15
-    set_error_handler(array('EE_Error', 'error_handler'));
16
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
15
+	set_error_handler(array('EE_Error', 'error_handler'));
16
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
17 17
 }
18 18
 
19 19
 
@@ -27,251 +27,251 @@  discard block
 block discarded – undo
27 27
 class EE_Error extends Exception
28 28
 {
29 29
 
30
-    const OPTIONS_KEY_NOTICES = 'ee_notices';
31
-
32
-
33
-    /**
34
-     * name of the file to log exceptions to
35
-     *
36
-     * @var string
37
-     */
38
-    private static $_exception_log_file = 'espresso_error_log.txt';
39
-
40
-    /**
41
-     *    stores details for all exception
42
-     *
43
-     * @var array
44
-     */
45
-    private static $_all_exceptions = array();
46
-
47
-    /**
48
-     *    tracks number of errors
49
-     *
50
-     * @var int
51
-     */
52
-    private static $_error_count = 0;
53
-
54
-    /**
55
-     * @var array $_espresso_notices
56
-     */
57
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
-
59
-
60
-    /**
61
-     * @override default exception handling
62
-     * @param string         $message
63
-     * @param int            $code
64
-     * @param Exception|null $previous
65
-     */
66
-    public function __construct($message, $code = 0, Exception $previous = null)
67
-    {
68
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
69
-            parent::__construct($message, $code);
70
-        } else {
71
-            parent::__construct($message, $code, $previous);
72
-        }
73
-    }
74
-
75
-
76
-    /**
77
-     *    error_handler
78
-     *
79
-     * @param $code
80
-     * @param $message
81
-     * @param $file
82
-     * @param $line
83
-     * @return void
84
-     */
85
-    public static function error_handler($code, $message, $file, $line)
86
-    {
87
-        $type = EE_Error::error_type($code);
88
-        $site = site_url();
89
-        switch ($site) {
90
-            case 'http://ee4.eventespresso.com/':
91
-            case 'http://ee4decaf.eventespresso.com/':
92
-            case 'http://ee4hf.eventespresso.com/':
93
-            case 'http://ee4a.eventespresso.com/':
94
-            case 'http://ee4ad.eventespresso.com/':
95
-            case 'http://ee4b.eventespresso.com/':
96
-            case 'http://ee4bd.eventespresso.com/':
97
-            case 'http://ee4d.eventespresso.com/':
98
-            case 'http://ee4dd.eventespresso.com/':
99
-                $to = '[email protected]';
100
-                break;
101
-            default:
102
-                $to = get_option('admin_email');
103
-        }
104
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
106
-        if (function_exists('wp_mail')) {
107
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
-            wp_mail($to, $subject, $msg);
109
-        }
110
-        echo '<div id="message" class="espresso-notices error"><p>';
111
-        echo wp_kses($type . ': ' . $message . '<br />' . $file . ' line ' . $line, AllowedTags::getWithFormTags());
112
-        echo '<br /></p></div>';
113
-    }
114
-
115
-
116
-    /**
117
-     * error_type
118
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
119
-     *
120
-     * @param $code
121
-     * @return string
122
-     */
123
-    public static function error_type($code)
124
-    {
125
-        switch ($code) {
126
-            case E_ERROR: // 1 //
127
-                return 'E_ERROR';
128
-            case E_WARNING: // 2 //
129
-                return 'E_WARNING';
130
-            case E_PARSE: // 4 //
131
-                return 'E_PARSE';
132
-            case E_NOTICE: // 8 //
133
-                return 'E_NOTICE';
134
-            case E_CORE_ERROR: // 16 //
135
-                return 'E_CORE_ERROR';
136
-            case E_CORE_WARNING: // 32 //
137
-                return 'E_CORE_WARNING';
138
-            case E_COMPILE_ERROR: // 64 //
139
-                return 'E_COMPILE_ERROR';
140
-            case E_COMPILE_WARNING: // 128 //
141
-                return 'E_COMPILE_WARNING';
142
-            case E_USER_ERROR: // 256 //
143
-                return 'E_USER_ERROR';
144
-            case E_USER_WARNING: // 512 //
145
-                return 'E_USER_WARNING';
146
-            case E_USER_NOTICE: // 1024 //
147
-                return 'E_USER_NOTICE';
148
-            case E_STRICT: // 2048 //
149
-                return 'E_STRICT';
150
-            case E_RECOVERABLE_ERROR: // 4096 //
151
-                return 'E_RECOVERABLE_ERROR';
152
-            case E_DEPRECATED: // 8192 //
153
-                return 'E_DEPRECATED';
154
-            case E_USER_DEPRECATED: // 16384 //
155
-                return 'E_USER_DEPRECATED';
156
-            case E_ALL: // 16384 //
157
-                return 'E_ALL';
158
-        }
159
-        return '';
160
-    }
161
-
162
-
163
-    /**
164
-     *    fatal_error_handler
165
-     *
166
-     * @return void
167
-     */
168
-    public static function fatal_error_handler()
169
-    {
170
-        $last_error = error_get_last();
171
-        if ($last_error['type'] === E_ERROR) {
172
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
173
-        }
174
-    }
175
-
176
-
177
-    /**
178
-     * _format_error
179
-     *
180
-     * @param $code
181
-     * @param $message
182
-     * @param $file
183
-     * @param $line
184
-     * @return string
185
-     */
186
-    private static function _format_error($code, $message, $file, $line)
187
-    {
188
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
-        $html .= '</tbody></table>';
194
-        return $html;
195
-    }
196
-
197
-
198
-    /**
199
-     * set_content_type
200
-     *
201
-     * @param $content_type
202
-     * @return string
203
-     */
204
-    public static function set_content_type($content_type)
205
-    {
206
-        return 'text/html';
207
-    }
208
-
209
-
210
-    /**
211
-     * @return void
212
-     * @throws EE_Error
213
-     * @throws ReflectionException
214
-     */
215
-    public function get_error()
216
-    {
217
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
218
-            throw $this;
219
-        }
220
-        // get separate user and developer messages if they exist
221
-        $msg = explode('||', $this->getMessage());
222
-        $user_msg = $msg[0];
223
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
224
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
225
-        // add details to _all_exceptions array
226
-        $x_time = time();
227
-        self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
228
-        self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
229
-        self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
230
-        self::$_all_exceptions[ $x_time ]['msg'] = $msg;
231
-        self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
232
-        self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
233
-        self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
234
-        self::$_error_count++;
235
-        // add_action( 'shutdown', array( $this, 'display_errors' ));
236
-        $this->display_errors();
237
-    }
238
-
239
-
240
-    /**
241
-     * @param bool   $check_stored
242
-     * @param string $type_to_check
243
-     * @return bool
244
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
245
-     * @throws \InvalidArgumentException
246
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     */
249
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
250
-    {
251
-        $has_error = isset(self::$_espresso_notices[ $type_to_check ])
252
-                     && ! empty(self::$_espresso_notices[ $type_to_check ])
253
-            ? true
254
-            : false;
255
-        if ($check_stored && ! $has_error) {
256
-            $notices = EE_Error::getStoredNotices();
257
-            foreach ($notices as $type => $notice) {
258
-                if ($type === $type_to_check && $notice) {
259
-                    return true;
260
-                }
261
-            }
262
-        }
263
-        return $has_error;
264
-    }
265
-
266
-
267
-    /**
268
-     * @echo string
269
-     * @throws \ReflectionException
270
-     */
271
-    public function display_errors()
272
-    {
273
-        $trace_details = '';
274
-        $output = '
30
+	const OPTIONS_KEY_NOTICES = 'ee_notices';
31
+
32
+
33
+	/**
34
+	 * name of the file to log exceptions to
35
+	 *
36
+	 * @var string
37
+	 */
38
+	private static $_exception_log_file = 'espresso_error_log.txt';
39
+
40
+	/**
41
+	 *    stores details for all exception
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private static $_all_exceptions = array();
46
+
47
+	/**
48
+	 *    tracks number of errors
49
+	 *
50
+	 * @var int
51
+	 */
52
+	private static $_error_count = 0;
53
+
54
+	/**
55
+	 * @var array $_espresso_notices
56
+	 */
57
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
+
59
+
60
+	/**
61
+	 * @override default exception handling
62
+	 * @param string         $message
63
+	 * @param int            $code
64
+	 * @param Exception|null $previous
65
+	 */
66
+	public function __construct($message, $code = 0, Exception $previous = null)
67
+	{
68
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
69
+			parent::__construct($message, $code);
70
+		} else {
71
+			parent::__construct($message, $code, $previous);
72
+		}
73
+	}
74
+
75
+
76
+	/**
77
+	 *    error_handler
78
+	 *
79
+	 * @param $code
80
+	 * @param $message
81
+	 * @param $file
82
+	 * @param $line
83
+	 * @return void
84
+	 */
85
+	public static function error_handler($code, $message, $file, $line)
86
+	{
87
+		$type = EE_Error::error_type($code);
88
+		$site = site_url();
89
+		switch ($site) {
90
+			case 'http://ee4.eventespresso.com/':
91
+			case 'http://ee4decaf.eventespresso.com/':
92
+			case 'http://ee4hf.eventespresso.com/':
93
+			case 'http://ee4a.eventespresso.com/':
94
+			case 'http://ee4ad.eventespresso.com/':
95
+			case 'http://ee4b.eventespresso.com/':
96
+			case 'http://ee4bd.eventespresso.com/':
97
+			case 'http://ee4d.eventespresso.com/':
98
+			case 'http://ee4dd.eventespresso.com/':
99
+				$to = '[email protected]';
100
+				break;
101
+			default:
102
+				$to = get_option('admin_email');
103
+		}
104
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
106
+		if (function_exists('wp_mail')) {
107
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108
+			wp_mail($to, $subject, $msg);
109
+		}
110
+		echo '<div id="message" class="espresso-notices error"><p>';
111
+		echo wp_kses($type . ': ' . $message . '<br />' . $file . ' line ' . $line, AllowedTags::getWithFormTags());
112
+		echo '<br /></p></div>';
113
+	}
114
+
115
+
116
+	/**
117
+	 * error_type
118
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
119
+	 *
120
+	 * @param $code
121
+	 * @return string
122
+	 */
123
+	public static function error_type($code)
124
+	{
125
+		switch ($code) {
126
+			case E_ERROR: // 1 //
127
+				return 'E_ERROR';
128
+			case E_WARNING: // 2 //
129
+				return 'E_WARNING';
130
+			case E_PARSE: // 4 //
131
+				return 'E_PARSE';
132
+			case E_NOTICE: // 8 //
133
+				return 'E_NOTICE';
134
+			case E_CORE_ERROR: // 16 //
135
+				return 'E_CORE_ERROR';
136
+			case E_CORE_WARNING: // 32 //
137
+				return 'E_CORE_WARNING';
138
+			case E_COMPILE_ERROR: // 64 //
139
+				return 'E_COMPILE_ERROR';
140
+			case E_COMPILE_WARNING: // 128 //
141
+				return 'E_COMPILE_WARNING';
142
+			case E_USER_ERROR: // 256 //
143
+				return 'E_USER_ERROR';
144
+			case E_USER_WARNING: // 512 //
145
+				return 'E_USER_WARNING';
146
+			case E_USER_NOTICE: // 1024 //
147
+				return 'E_USER_NOTICE';
148
+			case E_STRICT: // 2048 //
149
+				return 'E_STRICT';
150
+			case E_RECOVERABLE_ERROR: // 4096 //
151
+				return 'E_RECOVERABLE_ERROR';
152
+			case E_DEPRECATED: // 8192 //
153
+				return 'E_DEPRECATED';
154
+			case E_USER_DEPRECATED: // 16384 //
155
+				return 'E_USER_DEPRECATED';
156
+			case E_ALL: // 16384 //
157
+				return 'E_ALL';
158
+		}
159
+		return '';
160
+	}
161
+
162
+
163
+	/**
164
+	 *    fatal_error_handler
165
+	 *
166
+	 * @return void
167
+	 */
168
+	public static function fatal_error_handler()
169
+	{
170
+		$last_error = error_get_last();
171
+		if ($last_error['type'] === E_ERROR) {
172
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
173
+		}
174
+	}
175
+
176
+
177
+	/**
178
+	 * _format_error
179
+	 *
180
+	 * @param $code
181
+	 * @param $message
182
+	 * @param $file
183
+	 * @param $line
184
+	 * @return string
185
+	 */
186
+	private static function _format_error($code, $message, $file, $line)
187
+	{
188
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
+		$html .= '</tbody></table>';
194
+		return $html;
195
+	}
196
+
197
+
198
+	/**
199
+	 * set_content_type
200
+	 *
201
+	 * @param $content_type
202
+	 * @return string
203
+	 */
204
+	public static function set_content_type($content_type)
205
+	{
206
+		return 'text/html';
207
+	}
208
+
209
+
210
+	/**
211
+	 * @return void
212
+	 * @throws EE_Error
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function get_error()
216
+	{
217
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
218
+			throw $this;
219
+		}
220
+		// get separate user and developer messages if they exist
221
+		$msg = explode('||', $this->getMessage());
222
+		$user_msg = $msg[0];
223
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
224
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
225
+		// add details to _all_exceptions array
226
+		$x_time = time();
227
+		self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
228
+		self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
229
+		self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
230
+		self::$_all_exceptions[ $x_time ]['msg'] = $msg;
231
+		self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
232
+		self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
233
+		self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
234
+		self::$_error_count++;
235
+		// add_action( 'shutdown', array( $this, 'display_errors' ));
236
+		$this->display_errors();
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param bool   $check_stored
242
+	 * @param string $type_to_check
243
+	 * @return bool
244
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
245
+	 * @throws \InvalidArgumentException
246
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 */
249
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
250
+	{
251
+		$has_error = isset(self::$_espresso_notices[ $type_to_check ])
252
+					 && ! empty(self::$_espresso_notices[ $type_to_check ])
253
+			? true
254
+			: false;
255
+		if ($check_stored && ! $has_error) {
256
+			$notices = EE_Error::getStoredNotices();
257
+			foreach ($notices as $type => $notice) {
258
+				if ($type === $type_to_check && $notice) {
259
+					return true;
260
+				}
261
+			}
262
+		}
263
+		return $has_error;
264
+	}
265
+
266
+
267
+	/**
268
+	 * @echo string
269
+	 * @throws \ReflectionException
270
+	 */
271
+	public function display_errors()
272
+	{
273
+		$trace_details = '';
274
+		$output = '
275 275
 <style type="text/css">
276 276
 	#ee-error-message {
277 277
 		max-width:90% !important;
@@ -327,21 +327,21 @@  discard block
 block discarded – undo
327 327
 	}
328 328
 </style>
329 329
 <div id="ee-error-message" class="error">';
330
-        if (! WP_DEBUG) {
331
-            $output .= '
330
+		if (! WP_DEBUG) {
331
+			$output .= '
332 332
 	<p>';
333
-        }
334
-        // cycle thru errors
335
-        foreach (self::$_all_exceptions as $time => $ex) {
336
-            $error_code = '';
337
-            // process trace info
338
-            if (empty($ex['trace'])) {
339
-                $trace_details .= esc_html__(
340
-                    'Sorry, but no trace information was available for this exception.',
341
-                    'event_espresso'
342
-                );
343
-            } else {
344
-                $trace_details .= '
333
+		}
334
+		// cycle thru errors
335
+		foreach (self::$_all_exceptions as $time => $ex) {
336
+			$error_code = '';
337
+			// process trace info
338
+			if (empty($ex['trace'])) {
339
+				$trace_details .= esc_html__(
340
+					'Sorry, but no trace information was available for this exception.',
341
+					'event_espresso'
342
+				);
343
+			} else {
344
+				$trace_details .= '
345 345
 			<div id="ee-trace-details">
346 346
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
347 347
 				<tr>
@@ -351,43 +351,43 @@  discard block
 block discarded – undo
351 351
 					<th scope="col" align="left">Class</th>
352 352
 					<th scope="col" align="left">Method( arguments )</th>
353 353
 				</tr>';
354
-                $last_on_stack = count($ex['trace']) - 1;
355
-                // reverse array so that stack is in proper chronological order
356
-                $sorted_trace = array_reverse($ex['trace']);
357
-                foreach ($sorted_trace as $nmbr => $trace) {
358
-                    $file = isset($trace['file']) ? $trace['file'] : '';
359
-                    $class = isset($trace['class']) ? $trace['class'] : '';
360
-                    $type = isset($trace['type']) ? $trace['type'] : '';
361
-                    $function = isset($trace['function']) ? $trace['function'] : '';
362
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
363
-                    $line = isset($trace['line']) ? $trace['line'] : '';
364
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
365
-                    if (empty($file) && ! empty($class)) {
366
-                        $a = new ReflectionClass($class);
367
-                        $file = $a->getFileName();
368
-                        if (empty($line) && ! empty($function)) {
369
-                            try {
370
-                                // if $function is a closure, this throws an exception
371
-                                $b = new ReflectionMethod($class, $function);
372
-                                $line = $b->getStartLine();
373
-                            } catch (Exception $closure_exception) {
374
-                                $line = 'unknown';
375
-                            }
376
-                        }
377
-                    }
378
-                    if ($nmbr === $last_on_stack) {
379
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
380
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
381
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
382
-                    }
383
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
384
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
385
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
386
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
387
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
388
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
389
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
390
-                    $trace_details .= '
354
+				$last_on_stack = count($ex['trace']) - 1;
355
+				// reverse array so that stack is in proper chronological order
356
+				$sorted_trace = array_reverse($ex['trace']);
357
+				foreach ($sorted_trace as $nmbr => $trace) {
358
+					$file = isset($trace['file']) ? $trace['file'] : '';
359
+					$class = isset($trace['class']) ? $trace['class'] : '';
360
+					$type = isset($trace['type']) ? $trace['type'] : '';
361
+					$function = isset($trace['function']) ? $trace['function'] : '';
362
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
363
+					$line = isset($trace['line']) ? $trace['line'] : '';
364
+					$zebra = ($nmbr % 2) ? ' odd' : '';
365
+					if (empty($file) && ! empty($class)) {
366
+						$a = new ReflectionClass($class);
367
+						$file = $a->getFileName();
368
+						if (empty($line) && ! empty($function)) {
369
+							try {
370
+								// if $function is a closure, this throws an exception
371
+								$b = new ReflectionMethod($class, $function);
372
+								$line = $b->getStartLine();
373
+							} catch (Exception $closure_exception) {
374
+								$line = 'unknown';
375
+							}
376
+						}
377
+					}
378
+					if ($nmbr === $last_on_stack) {
379
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
380
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
381
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
382
+					}
383
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
384
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
385
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
386
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
387
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
388
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
389
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
390
+					$trace_details .= '
391 391
 					<tr>
392 392
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
393 393
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -395,628 +395,628 @@  discard block
 block discarded – undo
395 395
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
396 396
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
397 397
 					</tr>';
398
-                }
399
-                $trace_details .= '
398
+				}
399
+				$trace_details .= '
400 400
 			 </table>
401 401
 			</div>';
402
-            }
403
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
404
-            // add generic non-identifying messages for non-privileged users
405
-            if (! WP_DEBUG) {
406
-                $output .= '<span class="ee-error-user-msg-spn">'
407
-                           . trim($ex['msg'])
408
-                           . '</span> &nbsp; <sup>'
409
-                           . $ex['code']
410
-                           . '</sup><br />';
411
-            } else {
412
-                // or helpful developer messages if debugging is on
413
-                $output .= '
402
+			}
403
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
404
+			// add generic non-identifying messages for non-privileged users
405
+			if (! WP_DEBUG) {
406
+				$output .= '<span class="ee-error-user-msg-spn">'
407
+						   . trim($ex['msg'])
408
+						   . '</span> &nbsp; <sup>'
409
+						   . $ex['code']
410
+						   . '</sup><br />';
411
+			} else {
412
+				// or helpful developer messages if debugging is on
413
+				$output .= '
414 414
 		<div class="ee-error-dev-msg-dv">
415 415
 			<p class="ee-error-dev-msg-pg">
416 416
 				<strong class="ee-error-dev-msg-str">An '
417
-                           . $ex['name']
418
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
419
-                           . $ex['code']
420
-                           . '</span><br />
417
+						   . $ex['name']
418
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
419
+						   . $ex['code']
420
+						   . '</span><br />
421 421
 				<span class="big-text">"'
422
-                           . trim($ex['msg'])
423
-                           . '"</span><br/>
422
+						   . trim($ex['msg'])
423
+						   . '"</span><br/>
424 424
 				<a id="display-ee-error-trace-'
425
-                           . self::$_error_count
426
-                           . $time
427
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
428
-                           . self::$_error_count
429
-                           . $time
430
-                           . '">
425
+						   . self::$_error_count
426
+						   . $time
427
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
428
+						   . self::$_error_count
429
+						   . $time
430
+						   . '">
431 431
 					'
432
-                           . esc_html__('click to view backtrace and class/method details', 'event_espresso')
433
-                           . '
432
+						   . esc_html__('click to view backtrace and class/method details', 'event_espresso')
433
+						   . '
434 434
 				</a><br />
435 435
 				<span class="small-text lt-grey-text">'
436
-                           . $ex['file']
437
-                           . ' &nbsp; ( line no: '
438
-                           . $ex['line']
439
-                           . ' )</span>
436
+						   . $ex['file']
437
+						   . ' &nbsp; ( line no: '
438
+						   . $ex['line']
439
+						   . ' )</span>
440 440
 			</p>
441 441
 			<div id="ee-error-trace-'
442
-                           . self::$_error_count
443
-                           . $time
444
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
442
+						   . self::$_error_count
443
+						   . $time
444
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
445 445
 				'
446
-                           . $trace_details;
447
-                if (! empty($class)) {
448
-                    $output .= '
446
+						   . $trace_details;
447
+				if (! empty($class)) {
448
+					$output .= '
449 449
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
450 450
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
451 451
 						<h3>Class Details</h3>';
452
-                    $a = new ReflectionClass($class);
453
-                    $output .= '
452
+					$a = new ReflectionClass($class);
453
+					$output .= '
454 454
 						<pre>' . $a . '</pre>
455 455
 					</div>
456 456
 				</div>';
457
-                }
458
-                $output .= '
457
+				}
458
+				$output .= '
459 459
 			</div>
460 460
 		</div>
461 461
 		<br />';
462
-            }
463
-            $this->write_to_error_log($time, $ex);
464
-        }
465
-        // remove last linebreak
466
-        $output = substr($output, 0, -6);
467
-        if (! WP_DEBUG) {
468
-            $output .= '
462
+			}
463
+			$this->write_to_error_log($time, $ex);
464
+		}
465
+		// remove last linebreak
466
+		$output = substr($output, 0, -6);
467
+		if (! WP_DEBUG) {
468
+			$output .= '
469 469
 	</p>';
470
-        }
471
-        $output .= '
470
+		}
471
+		$output .= '
472 472
 </div>';
473
-        $output .= self::_print_scripts(true);
474
-        if (defined('DOING_AJAX')) {
475
-            echo wp_json_encode(array('error' => $output));
476
-            exit();
477
-        }
478
-        echo $output;
479
-        die();
480
-    }
481
-
482
-
483
-    /**
484
-     *    generate string from exception trace args
485
-     *
486
-     * @param array $arguments
487
-     * @param bool  $array
488
-     * @return string
489
-     */
490
-    private function _convert_args_to_string($arguments = array(), $array = false)
491
-    {
492
-        $arg_string = '';
493
-        if (! empty($arguments)) {
494
-            $args = array();
495
-            foreach ($arguments as $arg) {
496
-                if (! empty($arg)) {
497
-                    if (is_string($arg)) {
498
-                        $args[] = " '" . $arg . "'";
499
-                    } elseif (is_array($arg)) {
500
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
501
-                    } elseif ($arg === null) {
502
-                        $args[] = ' NULL';
503
-                    } elseif (is_bool($arg)) {
504
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
505
-                    } elseif (is_object($arg)) {
506
-                        $args[] = ' OBJECT ' . get_class($arg);
507
-                    } elseif (is_resource($arg)) {
508
-                        $args[] = get_resource_type($arg);
509
-                    } else {
510
-                        $args[] = $arg;
511
-                    }
512
-                }
513
-            }
514
-            $arg_string = implode(', ', $args);
515
-        }
516
-        if ($array) {
517
-            $arg_string .= ' )';
518
-        }
519
-        return $arg_string;
520
-    }
521
-
522
-
523
-    /**
524
-     *    add error message
525
-     *
526
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
527
-     *                            separate messages for user || dev
528
-     * @param        string $file the file that the error occurred in - just use __FILE__
529
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
530
-     * @param        string $line the line number where the error occurred - just use __LINE__
531
-     * @return        void
532
-     */
533
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
534
-    {
535
-        self::_add_notice('errors', $msg, $file, $func, $line);
536
-        self::$_error_count++;
537
-    }
538
-
539
-
540
-    /**
541
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
-     * adds an error
543
-     *
544
-     * @param string $msg
545
-     * @param string $file
546
-     * @param string $func
547
-     * @param string $line
548
-     * @throws EE_Error
549
-     */
550
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
-    {
552
-        if (WP_DEBUG) {
553
-            throw new EE_Error($msg);
554
-        }
555
-        EE_Error::add_error($msg, $file, $func, $line);
556
-    }
557
-
558
-
559
-    /**
560
-     *    add success message
561
-     *
562
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
563
-     *                            separate messages for user || dev
564
-     * @param        string $file the file that the error occurred in - just use __FILE__
565
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
566
-     * @param        string $line the line number where the error occurred - just use __LINE__
567
-     * @return        void
568
-     */
569
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
570
-    {
571
-        self::_add_notice('success', $msg, $file, $func, $line);
572
-    }
573
-
574
-
575
-    /**
576
-     *    add attention message
577
-     *
578
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
579
-     *                            separate messages for user || dev
580
-     * @param        string $file the file that the error occurred in - just use __FILE__
581
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
582
-     * @param        string $line the line number where the error occurred - just use __LINE__
583
-     * @return        void
584
-     */
585
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
586
-    {
587
-        self::_add_notice('attention', $msg, $file, $func, $line);
588
-    }
589
-
590
-
591
-    /**
592
-     * @param string $type whether the message is for a success or error notification
593
-     * @param string $msg  the message to display to users or developers
594
-     *                     - adding a double pipe || (OR) creates separate messages for user || dev
595
-     * @param string $file the file that the error occurred in - just use __FILE__
596
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
597
-     * @param string $line the line number where the error occurred - just use __LINE__
598
-     * @return void
599
-     */
600
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
601
-    {
602
-        if (empty($msg)) {
603
-            EE_Error::doing_it_wrong(
604
-                'EE_Error::add_' . $type . '()',
605
-                sprintf(
606
-                    esc_html__(
607
-                        'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
608
-                        'event_espresso'
609
-                    ),
610
-                    $type,
611
-                    $file,
612
-                    $line
613
-                ),
614
-                EVENT_ESPRESSO_VERSION
615
-            );
616
-        }
617
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
618
-            EE_Error::doing_it_wrong(
619
-                'EE_Error::add_error()',
620
-                esc_html__(
621
-                    'You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
622
-                    'event_espresso'
623
-                ),
624
-                EVENT_ESPRESSO_VERSION
625
-            );
626
-        }
627
-        // get separate user and developer messages if they exist
628
-        $msg = explode('||', $msg);
629
-        $user_msg = $msg[0];
630
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
631
-        /**
632
-         * Do an action so other code can be triggered when a notice is created
633
-         *
634
-         * @param string $type     can be 'errors', 'attention', or 'success'
635
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
636
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
637
-         * @param string $file     file where error was generated
638
-         * @param string $func     function where error was generated
639
-         * @param string $line     line where error was generated
640
-         */
641
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
642
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
643
-        // add notice if message exists
644
-        if (! empty($msg)) {
645
-            // get error code
646
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
647
-            if (WP_DEBUG && $type === 'errors') {
648
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
-            }
650
-            // add notice. Index by code if it's not blank
651
-            if ($notice_code) {
652
-                self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
653
-            } else {
654
-                self::$_espresso_notices[ $type ][] = $msg;
655
-            }
656
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
657
-        }
658
-    }
659
-
660
-
661
-    /**
662
-     * in some case it may be necessary to overwrite the existing success messages
663
-     *
664
-     * @return        void
665
-     */
666
-    public static function overwrite_success()
667
-    {
668
-        self::$_espresso_notices['success'] = false;
669
-    }
670
-
671
-
672
-    /**
673
-     * in some case it may be necessary to overwrite the existing attention messages
674
-     *
675
-     * @return void
676
-     */
677
-    public static function overwrite_attention()
678
-    {
679
-        self::$_espresso_notices['attention'] = false;
680
-    }
681
-
682
-
683
-    /**
684
-     * in some case it may be necessary to overwrite the existing error messages
685
-     *
686
-     * @return void
687
-     */
688
-    public static function overwrite_errors()
689
-    {
690
-        self::$_espresso_notices['errors'] = false;
691
-    }
692
-
693
-
694
-    /**
695
-     * @return void
696
-     */
697
-    public static function reset_notices()
698
-    {
699
-        self::$_espresso_notices['success'] = false;
700
-        self::$_espresso_notices['attention'] = false;
701
-        self::$_espresso_notices['errors'] = false;
702
-    }
703
-
704
-
705
-    /**
706
-     * @return int
707
-     */
708
-    public static function has_notices()
709
-    {
710
-        $has_notices = 0;
711
-        // check for success messages
712
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
713
-            ? 3
714
-            : $has_notices;
715
-        // check for attention messages
716
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
717
-            ? 2
718
-            : $has_notices;
719
-        // check for error messages
720
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
721
-            ? 1
722
-            : $has_notices;
723
-        return $has_notices;
724
-    }
725
-
726
-
727
-    /**
728
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
729
-     *
730
-     * @since 4.9.0
731
-     * @return array
732
-     */
733
-    public static function get_vanilla_notices()
734
-    {
735
-        return array(
736
-            'success'   => isset(self::$_espresso_notices['success'])
737
-                ? self::$_espresso_notices['success']
738
-                : array(),
739
-            'attention' => isset(self::$_espresso_notices['attention'])
740
-                ? self::$_espresso_notices['attention']
741
-                : array(),
742
-            'errors'    => isset(self::$_espresso_notices['errors'])
743
-                ? self::$_espresso_notices['errors']
744
-                : array(),
745
-        );
746
-    }
747
-
748
-
749
-    /**
750
-     * @return array
751
-     * @throws InvalidArgumentException
752
-     * @throws InvalidDataTypeException
753
-     * @throws InvalidInterfaceException
754
-     */
755
-    public static function getStoredNotices()
756
-    {
757
-        if ($user_id = get_current_user_id()) {
758
-            // get notices for logged in user
759
-            $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
760
-            return is_array($notices) ? $notices : array();
761
-        }
762
-        if (EE_Session::isLoadedAndActive()) {
763
-            // get notices for user currently engaged in a session
764
-            $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
765
-            return is_array($session_data) ? $session_data : array();
766
-        }
767
-        // get global notices and hope they apply to the current site visitor
768
-        $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
769
-        return is_array($notices) ? $notices : array();
770
-    }
771
-
772
-
773
-    /**
774
-     * @param array $notices
775
-     * @return bool
776
-     * @throws InvalidArgumentException
777
-     * @throws InvalidDataTypeException
778
-     * @throws InvalidInterfaceException
779
-     */
780
-    public static function storeNotices(array $notices)
781
-    {
782
-        if ($user_id = get_current_user_id()) {
783
-            // store notices for logged in user
784
-            return (bool) update_user_option(
785
-                $user_id,
786
-                EE_Error::OPTIONS_KEY_NOTICES,
787
-                $notices
788
-            );
789
-        }
790
-        if (EE_Session::isLoadedAndActive()) {
791
-            // store notices for user currently engaged in a session
792
-            return EE_Session::instance()->set_session_data(
793
-                array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
794
-            );
795
-        }
796
-        // store global notices and hope they apply to the same site visitor on the next request
797
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
798
-    }
799
-
800
-
801
-    /**
802
-     * @return bool|TRUE
803
-     * @throws InvalidArgumentException
804
-     * @throws InvalidDataTypeException
805
-     * @throws InvalidInterfaceException
806
-     */
807
-    public static function clearNotices()
808
-    {
809
-        if ($user_id = get_current_user_id()) {
810
-            // clear notices for logged in user
811
-            return (bool) update_user_option(
812
-                $user_id,
813
-                EE_Error::OPTIONS_KEY_NOTICES,
814
-                array()
815
-            );
816
-        }
817
-        if (EE_Session::isLoadedAndActive()) {
818
-            // clear notices for user currently engaged in a session
819
-            return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
820
-        }
821
-        // clear global notices and hope none belonged to some for some other site visitor
822
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
823
-    }
824
-
825
-
826
-    /**
827
-     * saves notices to the db for retrieval on next request
828
-     *
829
-     * @return void
830
-     * @throws InvalidArgumentException
831
-     * @throws InvalidDataTypeException
832
-     * @throws InvalidInterfaceException
833
-     */
834
-    public static function stashNoticesBeforeRedirect()
835
-    {
836
-        EE_Error::get_notices(false, true);
837
-    }
838
-
839
-
840
-    /**
841
-     * compile all error or success messages into one string
842
-     *
843
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
844
-     * @param boolean $format_output            whether or not to format the messages for display in the WP admin
845
-     * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
846
-     *                                          - ONLY do this just before redirecting
847
-     * @param boolean $remove_empty             whether or not to unset empty messages
848
-     * @return array
849
-     * @throws InvalidArgumentException
850
-     * @throws InvalidDataTypeException
851
-     * @throws InvalidInterfaceException
852
-     */
853
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
854
-    {
855
-        $success_messages = '';
856
-        $attention_messages = '';
857
-        $error_messages = '';
858
-        /** @var RequestInterface $request */
859
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
860
-        // either save notices to the db
861
-        if ($save_to_transient || $request->requestParamIsSet('activate-selected')) {
862
-            self::$_espresso_notices = array_merge(
863
-                EE_Error::getStoredNotices(),
864
-                self::$_espresso_notices
865
-            );
866
-            EE_Error::storeNotices(self::$_espresso_notices);
867
-            return array();
868
-        }
869
-        $print_scripts = EE_Error::combineExistingAndNewNotices();
870
-        // check for success messages
871
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
872
-            // combine messages
873
-            $success_messages .= implode('<br />', self::$_espresso_notices['success']);
874
-            $print_scripts = true;
875
-        }
876
-        // check for attention messages
877
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
878
-            // combine messages
879
-            $attention_messages .= implode('<br />', self::$_espresso_notices['attention']);
880
-            $print_scripts = true;
881
-        }
882
-        // check for error messages
883
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
884
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
885
-                ? esc_html__('The following errors have occurred:', 'event_espresso')
886
-                : esc_html__('An error has occurred:', 'event_espresso');
887
-            // combine messages
888
-            $error_messages .= '<br />' . implode('<br />', self::$_espresso_notices['errors']);
889
-            $print_scripts = true;
890
-        }
891
-        if ($format_output) {
892
-            $notices = EE_Error::formatNoticesOutput(
893
-                $success_messages,
894
-                $attention_messages,
895
-                $error_messages
896
-            );
897
-        } else {
898
-            $notices = array(
899
-                'success'   => $success_messages,
900
-                'attention' => $attention_messages,
901
-                'errors'    => $error_messages,
902
-            );
903
-            if ($remove_empty) {
904
-                // remove empty notices
905
-                foreach ($notices as $type => $notice) {
906
-                    if (empty($notice)) {
907
-                        unset($notices[ $type ]);
908
-                    }
909
-                }
910
-            }
911
-        }
912
-        if ($print_scripts) {
913
-            self::_print_scripts();
914
-        }
915
-        return $notices;
916
-    }
917
-
918
-
919
-    /**
920
-     * @return bool
921
-     * @throws InvalidArgumentException
922
-     * @throws InvalidDataTypeException
923
-     * @throws InvalidInterfaceException
924
-     */
925
-    private static function combineExistingAndNewNotices()
926
-    {
927
-        $print_scripts = false;
928
-        // grab any notices that have been previously saved
929
-        $notices = EE_Error::getStoredNotices();
930
-        if (! empty($notices)) {
931
-            foreach ($notices as $type => $notice) {
932
-                if (is_array($notice) && ! empty($notice)) {
933
-                    // make sure that existing notice type is an array
934
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
935
-                                                        && ! empty(self::$_espresso_notices[ $type ])
936
-                        ? self::$_espresso_notices[ $type ]
937
-                        : array();
938
-                    // add newly created notices to existing ones
939
-                    self::$_espresso_notices[ $type ] += $notice;
940
-                    $print_scripts = true;
941
-                }
942
-            }
943
-            // now clear any stored notices
944
-            EE_Error::clearNotices();
945
-        }
946
-        return $print_scripts;
947
-    }
948
-
949
-
950
-    /**
951
-     * @param string $success_messages
952
-     * @param string $attention_messages
953
-     * @param string $error_messages
954
-     * @return string
955
-     */
956
-    private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
957
-    {
958
-        $notices = '<div id="espresso-notices">';
959
-        $close = is_admin()
960
-            ? ''
961
-            : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
962
-        if ($success_messages !== '') {
963
-            $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
964
-            $css_class = is_admin() ? 'updated fade' : 'success fade-away';
965
-            // showMessage( $success_messages );
966
-            $notices .= '<div id="' . $css_id . '" '
967
-                        . 'class="espresso-notices ' . $css_class . '" '
968
-                        . 'style="display:none;">'
969
-                        . '<p>' . $success_messages . '</p>'
970
-                        . $close
971
-                        . '</div>';
972
-        }
973
-        if ($attention_messages !== '') {
974
-            $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
975
-            $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
976
-            // showMessage( $error_messages, TRUE );
977
-            $notices .= '<div id="' . $css_id . '" '
978
-                        . 'class="espresso-notices ' . $css_class . '" '
979
-                        . 'style="display:none;">'
980
-                        . '<p>' . $attention_messages . '</p>'
981
-                        . $close
982
-                        . '</div>';
983
-        }
984
-        if ($error_messages !== '') {
985
-            $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
986
-            $css_class = is_admin() ? 'error' : 'error fade-away';
987
-            // showMessage( $error_messages, TRUE );
988
-            $notices .= '<div id="' . $css_id . '" '
989
-                        . 'class="espresso-notices ' . $css_class . '" '
990
-                        . 'style="display:none;">'
991
-                        . '<p>' . $error_messages . '</p>'
992
-                        . $close
993
-                        . '</div>';
994
-        }
995
-        $notices .= '</div>';
996
-        return $notices;
997
-    }
998
-
999
-
1000
-    /**
1001
-     * _print_scripts
1002
-     *
1003
-     * @param    bool $force_print
1004
-     * @return    string
1005
-     */
1006
-    private static function _print_scripts($force_print = false)
1007
-    {
1008
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1009
-            if (wp_script_is('ee_error_js', 'registered')) {
1010
-                wp_enqueue_style('espresso_default');
1011
-                wp_enqueue_style('espresso_custom_css');
1012
-                wp_enqueue_script('ee_error_js');
1013
-            }
1014
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1015
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1016
-                return '';
1017
-            }
1018
-        } else {
1019
-            return '
473
+		$output .= self::_print_scripts(true);
474
+		if (defined('DOING_AJAX')) {
475
+			echo wp_json_encode(array('error' => $output));
476
+			exit();
477
+		}
478
+		echo $output;
479
+		die();
480
+	}
481
+
482
+
483
+	/**
484
+	 *    generate string from exception trace args
485
+	 *
486
+	 * @param array $arguments
487
+	 * @param bool  $array
488
+	 * @return string
489
+	 */
490
+	private function _convert_args_to_string($arguments = array(), $array = false)
491
+	{
492
+		$arg_string = '';
493
+		if (! empty($arguments)) {
494
+			$args = array();
495
+			foreach ($arguments as $arg) {
496
+				if (! empty($arg)) {
497
+					if (is_string($arg)) {
498
+						$args[] = " '" . $arg . "'";
499
+					} elseif (is_array($arg)) {
500
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
501
+					} elseif ($arg === null) {
502
+						$args[] = ' NULL';
503
+					} elseif (is_bool($arg)) {
504
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
505
+					} elseif (is_object($arg)) {
506
+						$args[] = ' OBJECT ' . get_class($arg);
507
+					} elseif (is_resource($arg)) {
508
+						$args[] = get_resource_type($arg);
509
+					} else {
510
+						$args[] = $arg;
511
+					}
512
+				}
513
+			}
514
+			$arg_string = implode(', ', $args);
515
+		}
516
+		if ($array) {
517
+			$arg_string .= ' )';
518
+		}
519
+		return $arg_string;
520
+	}
521
+
522
+
523
+	/**
524
+	 *    add error message
525
+	 *
526
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
527
+	 *                            separate messages for user || dev
528
+	 * @param        string $file the file that the error occurred in - just use __FILE__
529
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
530
+	 * @param        string $line the line number where the error occurred - just use __LINE__
531
+	 * @return        void
532
+	 */
533
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
534
+	{
535
+		self::_add_notice('errors', $msg, $file, $func, $line);
536
+		self::$_error_count++;
537
+	}
538
+
539
+
540
+	/**
541
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
+	 * adds an error
543
+	 *
544
+	 * @param string $msg
545
+	 * @param string $file
546
+	 * @param string $func
547
+	 * @param string $line
548
+	 * @throws EE_Error
549
+	 */
550
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
+	{
552
+		if (WP_DEBUG) {
553
+			throw new EE_Error($msg);
554
+		}
555
+		EE_Error::add_error($msg, $file, $func, $line);
556
+	}
557
+
558
+
559
+	/**
560
+	 *    add success message
561
+	 *
562
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
563
+	 *                            separate messages for user || dev
564
+	 * @param        string $file the file that the error occurred in - just use __FILE__
565
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
566
+	 * @param        string $line the line number where the error occurred - just use __LINE__
567
+	 * @return        void
568
+	 */
569
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
570
+	{
571
+		self::_add_notice('success', $msg, $file, $func, $line);
572
+	}
573
+
574
+
575
+	/**
576
+	 *    add attention message
577
+	 *
578
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
579
+	 *                            separate messages for user || dev
580
+	 * @param        string $file the file that the error occurred in - just use __FILE__
581
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
582
+	 * @param        string $line the line number where the error occurred - just use __LINE__
583
+	 * @return        void
584
+	 */
585
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
586
+	{
587
+		self::_add_notice('attention', $msg, $file, $func, $line);
588
+	}
589
+
590
+
591
+	/**
592
+	 * @param string $type whether the message is for a success or error notification
593
+	 * @param string $msg  the message to display to users or developers
594
+	 *                     - adding a double pipe || (OR) creates separate messages for user || dev
595
+	 * @param string $file the file that the error occurred in - just use __FILE__
596
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
597
+	 * @param string $line the line number where the error occurred - just use __LINE__
598
+	 * @return void
599
+	 */
600
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
601
+	{
602
+		if (empty($msg)) {
603
+			EE_Error::doing_it_wrong(
604
+				'EE_Error::add_' . $type . '()',
605
+				sprintf(
606
+					esc_html__(
607
+						'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
608
+						'event_espresso'
609
+					),
610
+					$type,
611
+					$file,
612
+					$line
613
+				),
614
+				EVENT_ESPRESSO_VERSION
615
+			);
616
+		}
617
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
618
+			EE_Error::doing_it_wrong(
619
+				'EE_Error::add_error()',
620
+				esc_html__(
621
+					'You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
622
+					'event_espresso'
623
+				),
624
+				EVENT_ESPRESSO_VERSION
625
+			);
626
+		}
627
+		// get separate user and developer messages if they exist
628
+		$msg = explode('||', $msg);
629
+		$user_msg = $msg[0];
630
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
631
+		/**
632
+		 * Do an action so other code can be triggered when a notice is created
633
+		 *
634
+		 * @param string $type     can be 'errors', 'attention', or 'success'
635
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
636
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
637
+		 * @param string $file     file where error was generated
638
+		 * @param string $func     function where error was generated
639
+		 * @param string $line     line where error was generated
640
+		 */
641
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
642
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
643
+		// add notice if message exists
644
+		if (! empty($msg)) {
645
+			// get error code
646
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
647
+			if (WP_DEBUG && $type === 'errors') {
648
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
+			}
650
+			// add notice. Index by code if it's not blank
651
+			if ($notice_code) {
652
+				self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
653
+			} else {
654
+				self::$_espresso_notices[ $type ][] = $msg;
655
+			}
656
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
657
+		}
658
+	}
659
+
660
+
661
+	/**
662
+	 * in some case it may be necessary to overwrite the existing success messages
663
+	 *
664
+	 * @return        void
665
+	 */
666
+	public static function overwrite_success()
667
+	{
668
+		self::$_espresso_notices['success'] = false;
669
+	}
670
+
671
+
672
+	/**
673
+	 * in some case it may be necessary to overwrite the existing attention messages
674
+	 *
675
+	 * @return void
676
+	 */
677
+	public static function overwrite_attention()
678
+	{
679
+		self::$_espresso_notices['attention'] = false;
680
+	}
681
+
682
+
683
+	/**
684
+	 * in some case it may be necessary to overwrite the existing error messages
685
+	 *
686
+	 * @return void
687
+	 */
688
+	public static function overwrite_errors()
689
+	{
690
+		self::$_espresso_notices['errors'] = false;
691
+	}
692
+
693
+
694
+	/**
695
+	 * @return void
696
+	 */
697
+	public static function reset_notices()
698
+	{
699
+		self::$_espresso_notices['success'] = false;
700
+		self::$_espresso_notices['attention'] = false;
701
+		self::$_espresso_notices['errors'] = false;
702
+	}
703
+
704
+
705
+	/**
706
+	 * @return int
707
+	 */
708
+	public static function has_notices()
709
+	{
710
+		$has_notices = 0;
711
+		// check for success messages
712
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
713
+			? 3
714
+			: $has_notices;
715
+		// check for attention messages
716
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
717
+			? 2
718
+			: $has_notices;
719
+		// check for error messages
720
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
721
+			? 1
722
+			: $has_notices;
723
+		return $has_notices;
724
+	}
725
+
726
+
727
+	/**
728
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
729
+	 *
730
+	 * @since 4.9.0
731
+	 * @return array
732
+	 */
733
+	public static function get_vanilla_notices()
734
+	{
735
+		return array(
736
+			'success'   => isset(self::$_espresso_notices['success'])
737
+				? self::$_espresso_notices['success']
738
+				: array(),
739
+			'attention' => isset(self::$_espresso_notices['attention'])
740
+				? self::$_espresso_notices['attention']
741
+				: array(),
742
+			'errors'    => isset(self::$_espresso_notices['errors'])
743
+				? self::$_espresso_notices['errors']
744
+				: array(),
745
+		);
746
+	}
747
+
748
+
749
+	/**
750
+	 * @return array
751
+	 * @throws InvalidArgumentException
752
+	 * @throws InvalidDataTypeException
753
+	 * @throws InvalidInterfaceException
754
+	 */
755
+	public static function getStoredNotices()
756
+	{
757
+		if ($user_id = get_current_user_id()) {
758
+			// get notices for logged in user
759
+			$notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
760
+			return is_array($notices) ? $notices : array();
761
+		}
762
+		if (EE_Session::isLoadedAndActive()) {
763
+			// get notices for user currently engaged in a session
764
+			$session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
765
+			return is_array($session_data) ? $session_data : array();
766
+		}
767
+		// get global notices and hope they apply to the current site visitor
768
+		$notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
769
+		return is_array($notices) ? $notices : array();
770
+	}
771
+
772
+
773
+	/**
774
+	 * @param array $notices
775
+	 * @return bool
776
+	 * @throws InvalidArgumentException
777
+	 * @throws InvalidDataTypeException
778
+	 * @throws InvalidInterfaceException
779
+	 */
780
+	public static function storeNotices(array $notices)
781
+	{
782
+		if ($user_id = get_current_user_id()) {
783
+			// store notices for logged in user
784
+			return (bool) update_user_option(
785
+				$user_id,
786
+				EE_Error::OPTIONS_KEY_NOTICES,
787
+				$notices
788
+			);
789
+		}
790
+		if (EE_Session::isLoadedAndActive()) {
791
+			// store notices for user currently engaged in a session
792
+			return EE_Session::instance()->set_session_data(
793
+				array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
794
+			);
795
+		}
796
+		// store global notices and hope they apply to the same site visitor on the next request
797
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
798
+	}
799
+
800
+
801
+	/**
802
+	 * @return bool|TRUE
803
+	 * @throws InvalidArgumentException
804
+	 * @throws InvalidDataTypeException
805
+	 * @throws InvalidInterfaceException
806
+	 */
807
+	public static function clearNotices()
808
+	{
809
+		if ($user_id = get_current_user_id()) {
810
+			// clear notices for logged in user
811
+			return (bool) update_user_option(
812
+				$user_id,
813
+				EE_Error::OPTIONS_KEY_NOTICES,
814
+				array()
815
+			);
816
+		}
817
+		if (EE_Session::isLoadedAndActive()) {
818
+			// clear notices for user currently engaged in a session
819
+			return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
820
+		}
821
+		// clear global notices and hope none belonged to some for some other site visitor
822
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
823
+	}
824
+
825
+
826
+	/**
827
+	 * saves notices to the db for retrieval on next request
828
+	 *
829
+	 * @return void
830
+	 * @throws InvalidArgumentException
831
+	 * @throws InvalidDataTypeException
832
+	 * @throws InvalidInterfaceException
833
+	 */
834
+	public static function stashNoticesBeforeRedirect()
835
+	{
836
+		EE_Error::get_notices(false, true);
837
+	}
838
+
839
+
840
+	/**
841
+	 * compile all error or success messages into one string
842
+	 *
843
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
844
+	 * @param boolean $format_output            whether or not to format the messages for display in the WP admin
845
+	 * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
846
+	 *                                          - ONLY do this just before redirecting
847
+	 * @param boolean $remove_empty             whether or not to unset empty messages
848
+	 * @return array
849
+	 * @throws InvalidArgumentException
850
+	 * @throws InvalidDataTypeException
851
+	 * @throws InvalidInterfaceException
852
+	 */
853
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
854
+	{
855
+		$success_messages = '';
856
+		$attention_messages = '';
857
+		$error_messages = '';
858
+		/** @var RequestInterface $request */
859
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
860
+		// either save notices to the db
861
+		if ($save_to_transient || $request->requestParamIsSet('activate-selected')) {
862
+			self::$_espresso_notices = array_merge(
863
+				EE_Error::getStoredNotices(),
864
+				self::$_espresso_notices
865
+			);
866
+			EE_Error::storeNotices(self::$_espresso_notices);
867
+			return array();
868
+		}
869
+		$print_scripts = EE_Error::combineExistingAndNewNotices();
870
+		// check for success messages
871
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
872
+			// combine messages
873
+			$success_messages .= implode('<br />', self::$_espresso_notices['success']);
874
+			$print_scripts = true;
875
+		}
876
+		// check for attention messages
877
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
878
+			// combine messages
879
+			$attention_messages .= implode('<br />', self::$_espresso_notices['attention']);
880
+			$print_scripts = true;
881
+		}
882
+		// check for error messages
883
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
884
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
885
+				? esc_html__('The following errors have occurred:', 'event_espresso')
886
+				: esc_html__('An error has occurred:', 'event_espresso');
887
+			// combine messages
888
+			$error_messages .= '<br />' . implode('<br />', self::$_espresso_notices['errors']);
889
+			$print_scripts = true;
890
+		}
891
+		if ($format_output) {
892
+			$notices = EE_Error::formatNoticesOutput(
893
+				$success_messages,
894
+				$attention_messages,
895
+				$error_messages
896
+			);
897
+		} else {
898
+			$notices = array(
899
+				'success'   => $success_messages,
900
+				'attention' => $attention_messages,
901
+				'errors'    => $error_messages,
902
+			);
903
+			if ($remove_empty) {
904
+				// remove empty notices
905
+				foreach ($notices as $type => $notice) {
906
+					if (empty($notice)) {
907
+						unset($notices[ $type ]);
908
+					}
909
+				}
910
+			}
911
+		}
912
+		if ($print_scripts) {
913
+			self::_print_scripts();
914
+		}
915
+		return $notices;
916
+	}
917
+
918
+
919
+	/**
920
+	 * @return bool
921
+	 * @throws InvalidArgumentException
922
+	 * @throws InvalidDataTypeException
923
+	 * @throws InvalidInterfaceException
924
+	 */
925
+	private static function combineExistingAndNewNotices()
926
+	{
927
+		$print_scripts = false;
928
+		// grab any notices that have been previously saved
929
+		$notices = EE_Error::getStoredNotices();
930
+		if (! empty($notices)) {
931
+			foreach ($notices as $type => $notice) {
932
+				if (is_array($notice) && ! empty($notice)) {
933
+					// make sure that existing notice type is an array
934
+					self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
935
+														&& ! empty(self::$_espresso_notices[ $type ])
936
+						? self::$_espresso_notices[ $type ]
937
+						: array();
938
+					// add newly created notices to existing ones
939
+					self::$_espresso_notices[ $type ] += $notice;
940
+					$print_scripts = true;
941
+				}
942
+			}
943
+			// now clear any stored notices
944
+			EE_Error::clearNotices();
945
+		}
946
+		return $print_scripts;
947
+	}
948
+
949
+
950
+	/**
951
+	 * @param string $success_messages
952
+	 * @param string $attention_messages
953
+	 * @param string $error_messages
954
+	 * @return string
955
+	 */
956
+	private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
957
+	{
958
+		$notices = '<div id="espresso-notices">';
959
+		$close = is_admin()
960
+			? ''
961
+			: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
962
+		if ($success_messages !== '') {
963
+			$css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
964
+			$css_class = is_admin() ? 'updated fade' : 'success fade-away';
965
+			// showMessage( $success_messages );
966
+			$notices .= '<div id="' . $css_id . '" '
967
+						. 'class="espresso-notices ' . $css_class . '" '
968
+						. 'style="display:none;">'
969
+						. '<p>' . $success_messages . '</p>'
970
+						. $close
971
+						. '</div>';
972
+		}
973
+		if ($attention_messages !== '') {
974
+			$css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
975
+			$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
976
+			// showMessage( $error_messages, TRUE );
977
+			$notices .= '<div id="' . $css_id . '" '
978
+						. 'class="espresso-notices ' . $css_class . '" '
979
+						. 'style="display:none;">'
980
+						. '<p>' . $attention_messages . '</p>'
981
+						. $close
982
+						. '</div>';
983
+		}
984
+		if ($error_messages !== '') {
985
+			$css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
986
+			$css_class = is_admin() ? 'error' : 'error fade-away';
987
+			// showMessage( $error_messages, TRUE );
988
+			$notices .= '<div id="' . $css_id . '" '
989
+						. 'class="espresso-notices ' . $css_class . '" '
990
+						. 'style="display:none;">'
991
+						. '<p>' . $error_messages . '</p>'
992
+						. $close
993
+						. '</div>';
994
+		}
995
+		$notices .= '</div>';
996
+		return $notices;
997
+	}
998
+
999
+
1000
+	/**
1001
+	 * _print_scripts
1002
+	 *
1003
+	 * @param    bool $force_print
1004
+	 * @return    string
1005
+	 */
1006
+	private static function _print_scripts($force_print = false)
1007
+	{
1008
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1009
+			if (wp_script_is('ee_error_js', 'registered')) {
1010
+				wp_enqueue_style('espresso_default');
1011
+				wp_enqueue_style('espresso_custom_css');
1012
+				wp_enqueue_script('ee_error_js');
1013
+			}
1014
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1015
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1016
+				return '';
1017
+			}
1018
+		} else {
1019
+			return '
1020 1020
 <script>
1021 1021
 /* <![CDATA[ */
1022 1022
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1026,221 +1026,221 @@  discard block
 block discarded – undo
1026 1026
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1027 1027
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1028 1028
 ';
1029
-        }
1030
-        return '';
1031
-    }
1032
-
1033
-
1034
-    /**
1035
-     * @return void
1036
-     */
1037
-    public static function enqueue_error_scripts()
1038
-    {
1039
-        self::_print_scripts();
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     * create error code from filepath, function name,
1045
-     * and line number where exception or error was thrown
1046
-     *
1047
-     * @param string $file
1048
-     * @param string $func
1049
-     * @param string $line
1050
-     * @return string
1051
-     */
1052
-    public static function generate_error_code($file = '', $func = '', $line = '')
1053
-    {
1054
-        $file = explode('.', basename($file));
1055
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1056
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1057
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1058
-        return $error_code;
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * write exception details to log file
1064
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1065
-     *
1066
-     * @param int   $time
1067
-     * @param array $ex
1068
-     * @param bool  $clear
1069
-     * @return void
1070
-     */
1071
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1072
-    {
1073
-        if (empty($ex)) {
1074
-            return;
1075
-        }
1076
-        if (! $time) {
1077
-            $time = time();
1078
-        }
1079
-        $exception_log = '----------------------------------------------------------------------------------------'
1080
-                         . PHP_EOL;
1081
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1082
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1083
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1084
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1085
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1086
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1087
-        $exception_log .= $ex['string'] . PHP_EOL;
1088
-        $exception_log .= '----------------------------------------------------------------------------------------'
1089
-                          . PHP_EOL;
1090
-        try {
1091
-            error_log($exception_log);
1092
-        } catch (EE_Error $e) {
1093
-            EE_Error::add_error(
1094
-                sprintf(
1095
-                    esc_html__(
1096
-                        'Event Espresso error logging could not be setup because: %s',
1097
-                        'event_espresso'
1098
-                    ),
1099
-                    $e->getMessage()
1100
-                )
1101
-            );
1102
-        }
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1108
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1109
-     * but the code execution is done in a manner that could lead to unexpected results
1110
-     * (i.e. running to early, or too late in WP or EE loading process).
1111
-     * A good test for knowing whether to use this method is:
1112
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1113
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1114
-     * 2. If this is loaded before something else, it won't break anything,
1115
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1116
-     *
1117
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1118
-     * @param string $function      The function that was called
1119
-     * @param string $message       A message explaining what has been done incorrectly
1120
-     * @param string $version       The version of Event Espresso where the error was added
1121
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1122
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1123
-     *                              but not have any notices appear until a later version. This allows developers
1124
-     *                              extra time to update their code before notices appear.
1125
-     * @param int    $error_type
1126
-     */
1127
-    public static function doing_it_wrong(
1128
-        $function,
1129
-        $message,
1130
-        $version,
1131
-        $applies_when = '',
1132
-        $error_type = null
1133
-    ) {
1134
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1135
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1136
-        }
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Like get_notices, but returns an array of all the notices of the given type.
1142
-     *
1143
-     * @return array {
1144
-     * @type array $success   all the success messages
1145
-     * @type array $errors    all the error messages
1146
-     * @type array $attention all the attention messages
1147
-     * }
1148
-     */
1149
-    public static function get_raw_notices()
1150
-    {
1151
-        return self::$_espresso_notices;
1152
-    }
1153
-
1154
-
1155
-    /**
1156
-     * @deprecated 4.9.27
1157
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1158
-     * @param string $pan_message  the message to be stored persistently until dismissed
1159
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1160
-     * @return void
1161
-     * @throws InvalidDataTypeException
1162
-     */
1163
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1164
-    {
1165
-        new PersistentAdminNotice(
1166
-            $pan_name,
1167
-            $pan_message,
1168
-            $force_update
1169
-        );
1170
-        EE_Error::doing_it_wrong(
1171
-            __METHOD__,
1172
-            sprintf(
1173
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1174
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1175
-            ),
1176
-            '4.9.27'
1177
-        );
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * @deprecated 4.9.27
1183
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1184
-     * @param bool   $purge
1185
-     * @param bool   $return
1186
-     * @throws DomainException
1187
-     * @throws InvalidInterfaceException
1188
-     * @throws InvalidDataTypeException
1189
-     * @throws ServiceNotFoundException
1190
-     * @throws InvalidArgumentException
1191
-     */
1192
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1193
-    {
1194
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1195
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1196
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1197
-        );
1198
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1199
-        EE_Error::doing_it_wrong(
1200
-            __METHOD__,
1201
-            sprintf(
1202
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1203
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1204
-            ),
1205
-            '4.9.27'
1206
-        );
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * @deprecated 4.9.27
1212
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1213
-     * @param  string $pan_message the message to be stored persistently until dismissed
1214
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1215
-     */
1216
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1217
-    {
1218
-        EE_Error::doing_it_wrong(
1219
-            __METHOD__,
1220
-            sprintf(
1221
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1222
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1223
-            ),
1224
-            '4.9.27'
1225
-        );
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * @deprecated 4.9.27
1231
-     * @param string $return_url
1232
-     */
1233
-    public static function get_persistent_admin_notices($return_url = '')
1234
-    {
1235
-        EE_Error::doing_it_wrong(
1236
-            __METHOD__,
1237
-            sprintf(
1238
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1239
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1240
-            ),
1241
-            '4.9.27'
1242
-        );
1243
-    }
1029
+		}
1030
+		return '';
1031
+	}
1032
+
1033
+
1034
+	/**
1035
+	 * @return void
1036
+	 */
1037
+	public static function enqueue_error_scripts()
1038
+	{
1039
+		self::_print_scripts();
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 * create error code from filepath, function name,
1045
+	 * and line number where exception or error was thrown
1046
+	 *
1047
+	 * @param string $file
1048
+	 * @param string $func
1049
+	 * @param string $line
1050
+	 * @return string
1051
+	 */
1052
+	public static function generate_error_code($file = '', $func = '', $line = '')
1053
+	{
1054
+		$file = explode('.', basename($file));
1055
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1056
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1057
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1058
+		return $error_code;
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * write exception details to log file
1064
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1065
+	 *
1066
+	 * @param int   $time
1067
+	 * @param array $ex
1068
+	 * @param bool  $clear
1069
+	 * @return void
1070
+	 */
1071
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1072
+	{
1073
+		if (empty($ex)) {
1074
+			return;
1075
+		}
1076
+		if (! $time) {
1077
+			$time = time();
1078
+		}
1079
+		$exception_log = '----------------------------------------------------------------------------------------'
1080
+						 . PHP_EOL;
1081
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1082
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1083
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1084
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1085
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1086
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1087
+		$exception_log .= $ex['string'] . PHP_EOL;
1088
+		$exception_log .= '----------------------------------------------------------------------------------------'
1089
+						  . PHP_EOL;
1090
+		try {
1091
+			error_log($exception_log);
1092
+		} catch (EE_Error $e) {
1093
+			EE_Error::add_error(
1094
+				sprintf(
1095
+					esc_html__(
1096
+						'Event Espresso error logging could not be setup because: %s',
1097
+						'event_espresso'
1098
+					),
1099
+					$e->getMessage()
1100
+				)
1101
+			);
1102
+		}
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1108
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1109
+	 * but the code execution is done in a manner that could lead to unexpected results
1110
+	 * (i.e. running to early, or too late in WP or EE loading process).
1111
+	 * A good test for knowing whether to use this method is:
1112
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1113
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1114
+	 * 2. If this is loaded before something else, it won't break anything,
1115
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1116
+	 *
1117
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1118
+	 * @param string $function      The function that was called
1119
+	 * @param string $message       A message explaining what has been done incorrectly
1120
+	 * @param string $version       The version of Event Espresso where the error was added
1121
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1122
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1123
+	 *                              but not have any notices appear until a later version. This allows developers
1124
+	 *                              extra time to update their code before notices appear.
1125
+	 * @param int    $error_type
1126
+	 */
1127
+	public static function doing_it_wrong(
1128
+		$function,
1129
+		$message,
1130
+		$version,
1131
+		$applies_when = '',
1132
+		$error_type = null
1133
+	) {
1134
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1135
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Like get_notices, but returns an array of all the notices of the given type.
1142
+	 *
1143
+	 * @return array {
1144
+	 * @type array $success   all the success messages
1145
+	 * @type array $errors    all the error messages
1146
+	 * @type array $attention all the attention messages
1147
+	 * }
1148
+	 */
1149
+	public static function get_raw_notices()
1150
+	{
1151
+		return self::$_espresso_notices;
1152
+	}
1153
+
1154
+
1155
+	/**
1156
+	 * @deprecated 4.9.27
1157
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1158
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1159
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1160
+	 * @return void
1161
+	 * @throws InvalidDataTypeException
1162
+	 */
1163
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1164
+	{
1165
+		new PersistentAdminNotice(
1166
+			$pan_name,
1167
+			$pan_message,
1168
+			$force_update
1169
+		);
1170
+		EE_Error::doing_it_wrong(
1171
+			__METHOD__,
1172
+			sprintf(
1173
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1174
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1175
+			),
1176
+			'4.9.27'
1177
+		);
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * @deprecated 4.9.27
1183
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1184
+	 * @param bool   $purge
1185
+	 * @param bool   $return
1186
+	 * @throws DomainException
1187
+	 * @throws InvalidInterfaceException
1188
+	 * @throws InvalidDataTypeException
1189
+	 * @throws ServiceNotFoundException
1190
+	 * @throws InvalidArgumentException
1191
+	 */
1192
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1193
+	{
1194
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1195
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1196
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1197
+		);
1198
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1199
+		EE_Error::doing_it_wrong(
1200
+			__METHOD__,
1201
+			sprintf(
1202
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1203
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1204
+			),
1205
+			'4.9.27'
1206
+		);
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * @deprecated 4.9.27
1212
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1213
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1214
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1215
+	 */
1216
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1217
+	{
1218
+		EE_Error::doing_it_wrong(
1219
+			__METHOD__,
1220
+			sprintf(
1221
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1222
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1223
+			),
1224
+			'4.9.27'
1225
+		);
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * @deprecated 4.9.27
1231
+	 * @param string $return_url
1232
+	 */
1233
+	public static function get_persistent_admin_notices($return_url = '')
1234
+	{
1235
+		EE_Error::doing_it_wrong(
1236
+			__METHOD__,
1237
+			sprintf(
1238
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1239
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1240
+			),
1241
+			'4.9.27'
1242
+		);
1243
+	}
1244 1244
 }
1245 1245
 
1246 1246
 // end of Class EE_Exceptions
@@ -1253,26 +1253,26 @@  discard block
 block discarded – undo
1253 1253
  */
1254 1254
 function espresso_error_enqueue_scripts()
1255 1255
 {
1256
-    // js for error handling
1257
-    wp_register_script(
1258
-        'espresso_core',
1259
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1260
-        array('jquery'),
1261
-        EVENT_ESPRESSO_VERSION
1262
-    );
1263
-    wp_register_script(
1264
-        'ee_error_js',
1265
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1266
-        array('espresso_core'),
1267
-        EVENT_ESPRESSO_VERSION
1268
-    );
1269
-    wp_localize_script('ee_error_js', 'ee_settings', ['wp_debug' => WP_DEBUG]);
1256
+	// js for error handling
1257
+	wp_register_script(
1258
+		'espresso_core',
1259
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1260
+		array('jquery'),
1261
+		EVENT_ESPRESSO_VERSION
1262
+	);
1263
+	wp_register_script(
1264
+		'ee_error_js',
1265
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1266
+		array('espresso_core'),
1267
+		EVENT_ESPRESSO_VERSION
1268
+	);
1269
+	wp_localize_script('ee_error_js', 'ee_settings', ['wp_debug' => WP_DEBUG]);
1270 1270
 }
1271 1271
 
1272 1272
 if (is_admin()) {
1273
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1273
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1274 1274
 } else {
1275
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1275
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1276 1276
 }
1277 1277
 
1278 1278
 
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
             default:
102 102
                 $to = get_option('admin_email');
103 103
         }
104
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
104
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
105 105
         $msg = EE_Error::_format_error($type, $message, $file, $line);
106 106
         if (function_exists('wp_mail')) {
107 107
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
108 108
             wp_mail($to, $subject, $msg);
109 109
         }
110 110
         echo '<div id="message" class="espresso-notices error"><p>';
111
-        echo wp_kses($type . ': ' . $message . '<br />' . $file . ' line ' . $line, AllowedTags::getWithFormTags());
111
+        echo wp_kses($type.': '.$message.'<br />'.$file.' line '.$line, AllowedTags::getWithFormTags());
112 112
         echo '<br /></p></div>';
113 113
     }
114 114
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
225 225
         // add details to _all_exceptions array
226 226
         $x_time = time();
227
-        self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
228
-        self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
229
-        self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
230
-        self::$_all_exceptions[ $x_time ]['msg'] = $msg;
231
-        self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
232
-        self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
233
-        self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
227
+        self::$_all_exceptions[$x_time]['name'] = get_class($this);
228
+        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
229
+        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
230
+        self::$_all_exceptions[$x_time]['msg'] = $msg;
231
+        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
232
+        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
233
+        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
234 234
         self::$_error_count++;
235 235
         // add_action( 'shutdown', array( $this, 'display_errors' ));
236 236
         $this->display_errors();
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public static function has_error($check_stored = false, $type_to_check = 'errors')
250 250
     {
251
-        $has_error = isset(self::$_espresso_notices[ $type_to_check ])
252
-                     && ! empty(self::$_espresso_notices[ $type_to_check ])
251
+        $has_error = isset(self::$_espresso_notices[$type_to_check])
252
+                     && ! empty(self::$_espresso_notices[$type_to_check])
253 253
             ? true
254 254
             : false;
255 255
         if ($check_stored && ! $has_error) {
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	}
328 328
 </style>
329 329
 <div id="ee-error-message" class="error">';
330
-        if (! WP_DEBUG) {
330
+        if ( ! WP_DEBUG) {
331 331
             $output .= '
332 332
 	<p>';
333 333
         }
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
387 387
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
388 388
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
389
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
389
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
390 390
                     $trace_details .= '
391 391
 					<tr>
392
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
393
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
394
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
395
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
396
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
392
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
393
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
394
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
395
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
396
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
397 397
 					</tr>';
398 398
                 }
399 399
                 $trace_details .= '
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
             }
403 403
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
404 404
             // add generic non-identifying messages for non-privileged users
405
-            if (! WP_DEBUG) {
405
+            if ( ! WP_DEBUG) {
406 406
                 $output .= '<span class="ee-error-user-msg-spn">'
407 407
                            . trim($ex['msg'])
408 408
                            . '</span> &nbsp; <sup>'
@@ -444,14 +444,14 @@  discard block
 block discarded – undo
444 444
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
445 445
 				'
446 446
                            . $trace_details;
447
-                if (! empty($class)) {
447
+                if ( ! empty($class)) {
448 448
                     $output .= '
449 449
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
450 450
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
451 451
 						<h3>Class Details</h3>';
452 452
                     $a = new ReflectionClass($class);
453 453
                     $output .= '
454
-						<pre>' . $a . '</pre>
454
+						<pre>' . $a.'</pre>
455 455
 					</div>
456 456
 				</div>';
457 457
                 }
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
         }
465 465
         // remove last linebreak
466 466
         $output = substr($output, 0, -6);
467
-        if (! WP_DEBUG) {
467
+        if ( ! WP_DEBUG) {
468 468
             $output .= '
469 469
 	</p>';
470 470
         }
@@ -490,20 +490,20 @@  discard block
 block discarded – undo
490 490
     private function _convert_args_to_string($arguments = array(), $array = false)
491 491
     {
492 492
         $arg_string = '';
493
-        if (! empty($arguments)) {
493
+        if ( ! empty($arguments)) {
494 494
             $args = array();
495 495
             foreach ($arguments as $arg) {
496
-                if (! empty($arg)) {
496
+                if ( ! empty($arg)) {
497 497
                     if (is_string($arg)) {
498
-                        $args[] = " '" . $arg . "'";
498
+                        $args[] = " '".$arg."'";
499 499
                     } elseif (is_array($arg)) {
500
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
500
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
501 501
                     } elseif ($arg === null) {
502 502
                         $args[] = ' NULL';
503 503
                     } elseif (is_bool($arg)) {
504 504
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
505 505
                     } elseif (is_object($arg)) {
506
-                        $args[] = ' OBJECT ' . get_class($arg);
506
+                        $args[] = ' OBJECT '.get_class($arg);
507 507
                     } elseif (is_resource($arg)) {
508 508
                         $args[] = get_resource_type($arg);
509 509
                     } else {
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
     {
602 602
         if (empty($msg)) {
603 603
             EE_Error::doing_it_wrong(
604
-                'EE_Error::add_' . $type . '()',
604
+                'EE_Error::add_'.$type.'()',
605 605
                 sprintf(
606 606
                     esc_html__(
607 607
                         'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
@@ -641,17 +641,17 @@  discard block
 block discarded – undo
641 641
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
642 642
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
643 643
         // add notice if message exists
644
-        if (! empty($msg)) {
644
+        if ( ! empty($msg)) {
645 645
             // get error code
646 646
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
647 647
             if (WP_DEBUG && $type === 'errors') {
648
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
648
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
649 649
             }
650 650
             // add notice. Index by code if it's not blank
651 651
             if ($notice_code) {
652
-                self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
652
+                self::$_espresso_notices[$type][$notice_code] = $msg;
653 653
             } else {
654
-                self::$_espresso_notices[ $type ][] = $msg;
654
+                self::$_espresso_notices[$type][] = $msg;
655 655
             }
656 656
             add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
657 657
         }
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
                 ? esc_html__('The following errors have occurred:', 'event_espresso')
886 886
                 : esc_html__('An error has occurred:', 'event_espresso');
887 887
             // combine messages
888
-            $error_messages .= '<br />' . implode('<br />', self::$_espresso_notices['errors']);
888
+            $error_messages .= '<br />'.implode('<br />', self::$_espresso_notices['errors']);
889 889
             $print_scripts = true;
890 890
         }
891 891
         if ($format_output) {
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
                 // remove empty notices
905 905
                 foreach ($notices as $type => $notice) {
906 906
                     if (empty($notice)) {
907
-                        unset($notices[ $type ]);
907
+                        unset($notices[$type]);
908 908
                     }
909 909
                 }
910 910
             }
@@ -927,16 +927,16 @@  discard block
 block discarded – undo
927 927
         $print_scripts = false;
928 928
         // grab any notices that have been previously saved
929 929
         $notices = EE_Error::getStoredNotices();
930
-        if (! empty($notices)) {
930
+        if ( ! empty($notices)) {
931 931
             foreach ($notices as $type => $notice) {
932 932
                 if (is_array($notice) && ! empty($notice)) {
933 933
                     // make sure that existing notice type is an array
934
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
935
-                                                        && ! empty(self::$_espresso_notices[ $type ])
936
-                        ? self::$_espresso_notices[ $type ]
934
+                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
935
+                                                        && ! empty(self::$_espresso_notices[$type])
936
+                        ? self::$_espresso_notices[$type]
937 937
                         : array();
938 938
                     // add newly created notices to existing ones
939
-                    self::$_espresso_notices[ $type ] += $notice;
939
+                    self::$_espresso_notices[$type] += $notice;
940 940
                     $print_scripts = true;
941 941
                 }
942 942
             }
@@ -963,10 +963,10 @@  discard block
 block discarded – undo
963 963
             $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
964 964
             $css_class = is_admin() ? 'updated fade' : 'success fade-away';
965 965
             // showMessage( $success_messages );
966
-            $notices .= '<div id="' . $css_id . '" '
967
-                        . 'class="espresso-notices ' . $css_class . '" '
966
+            $notices .= '<div id="'.$css_id.'" '
967
+                        . 'class="espresso-notices '.$css_class.'" '
968 968
                         . 'style="display:none;">'
969
-                        . '<p>' . $success_messages . '</p>'
969
+                        . '<p>'.$success_messages.'</p>'
970 970
                         . $close
971 971
                         . '</div>';
972 972
         }
@@ -974,10 +974,10 @@  discard block
 block discarded – undo
974 974
             $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
975 975
             $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
976 976
             // showMessage( $error_messages, TRUE );
977
-            $notices .= '<div id="' . $css_id . '" '
978
-                        . 'class="espresso-notices ' . $css_class . '" '
977
+            $notices .= '<div id="'.$css_id.'" '
978
+                        . 'class="espresso-notices '.$css_class.'" '
979 979
                         . 'style="display:none;">'
980
-                        . '<p>' . $attention_messages . '</p>'
980
+                        . '<p>'.$attention_messages.'</p>'
981 981
                         . $close
982 982
                         . '</div>';
983 983
         }
@@ -985,10 +985,10 @@  discard block
 block discarded – undo
985 985
             $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
986 986
             $css_class = is_admin() ? 'error' : 'error fade-away';
987 987
             // showMessage( $error_messages, TRUE );
988
-            $notices .= '<div id="' . $css_id . '" '
989
-                        . 'class="espresso-notices ' . $css_class . '" '
988
+            $notices .= '<div id="'.$css_id.'" '
989
+                        . 'class="espresso-notices '.$css_class.'" '
990 990
                         . 'style="display:none;">'
991
-                        . '<p>' . $error_messages . '</p>'
991
+                        . '<p>'.$error_messages.'</p>'
992 992
                         . $close
993 993
                         . '</div>';
994 994
         }
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
      */
1006 1006
     private static function _print_scripts($force_print = false)
1007 1007
     {
1008
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1008
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1009 1009
             if (wp_script_is('ee_error_js', 'registered')) {
1010 1010
                 wp_enqueue_style('espresso_default');
1011 1011
                 wp_enqueue_style('espresso_custom_css');
@@ -1019,12 +1019,12 @@  discard block
 block discarded – undo
1019 1019
             return '
1020 1020
 <script>
1021 1021
 /* <![CDATA[ */
1022
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1022
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1023 1023
 /* ]]> */
1024 1024
 </script>
1025
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1026
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1027
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1025
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1026
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1027
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1028 1028
 ';
1029 1029
         }
1030 1030
         return '';
@@ -1053,8 +1053,8 @@  discard block
 block discarded – undo
1053 1053
     {
1054 1054
         $file = explode('.', basename($file));
1055 1055
         $error_code = ! empty($file[0]) ? $file[0] : '';
1056
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1057
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1056
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1057
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1058 1058
         return $error_code;
1059 1059
     }
1060 1060
 
@@ -1073,18 +1073,18 @@  discard block
 block discarded – undo
1073 1073
         if (empty($ex)) {
1074 1074
             return;
1075 1075
         }
1076
-        if (! $time) {
1076
+        if ( ! $time) {
1077 1077
             $time = time();
1078 1078
         }
1079 1079
         $exception_log = '----------------------------------------------------------------------------------------'
1080 1080
                          . PHP_EOL;
1081
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1082
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1083
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1084
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1085
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1086
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1087
-        $exception_log .= $ex['string'] . PHP_EOL;
1081
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1082
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1083
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1084
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1085
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1086
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1087
+        $exception_log .= $ex['string'].PHP_EOL;
1088 1088
         $exception_log .= '----------------------------------------------------------------------------------------'
1089 1089
                           . PHP_EOL;
1090 1090
         try {
@@ -1256,13 +1256,13 @@  discard block
 block discarded – undo
1256 1256
     // js for error handling
1257 1257
     wp_register_script(
1258 1258
         'espresso_core',
1259
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1259
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1260 1260
         array('jquery'),
1261 1261
         EVENT_ESPRESSO_VERSION
1262 1262
     );
1263 1263
     wp_register_script(
1264 1264
         'ee_error_js',
1265
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1265
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1266 1266
         array('espresso_core'),
1267 1267
         EVENT_ESPRESSO_VERSION
1268 1268
     );
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/templates/import_page.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <div class="import-area">
2 2
     <div class="important-notice">
3 3
         <?php esc_html_e(
4
-            'The import feature has been disabled because of bugs. It is expected to be put back in place soon.',
5
-            'event_espresso'
6
-        ); ?>
4
+			'The import feature has been disabled because of bugs. It is expected to be put back in place soon.',
5
+			'event_espresso'
6
+		); ?>
7 7
     </div>
8 8
     <?php // echo wp_kses($form, \EventEspresso\core\services\request\sanitizers\AllowedTags::getWithFormTags()); ?>
9 9
 </div>
Please login to merge, or discard this patch.
modules/ical/EED_Ical.module.php 2 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -15,235 +15,235 @@
 block discarded – undo
15 15
 class EED_Ical extends EED_Module
16 16
 {
17 17
 
18
-    const iCal_datetime_format = 'Ymd\THis\Z';
19
-
20
-
21
-    /**
22
-     * @return EED_Ical|EED_Module
23
-     * @throws EE_Error
24
-     * @throws ReflectionException
25
-     */
26
-    public static function instance()
27
-    {
28
-        return parent::get_instance(__CLASS__);
29
-    }
30
-
31
-
32
-    /**
33
-     *    set_hooks - for hooking into EE Core, other modules, etc
34
-     *
35
-     * @return    void
36
-     */
37
-    public static function set_hooks()
38
-    {
39
-        // create download buttons
40
-        add_filter(
41
-            'FHEE__espresso_list_of_event_dates__datetime_html',
42
-            ['EED_Ical', 'generate_add_to_iCal_button'],
43
-            10,
44
-            2
45
-        );
46
-        // process ics download request
47
-        EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
48
-    }
49
-
50
-
51
-    /**
52
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
53
-     *
54
-     * @return    void
55
-     */
56
-    public static function set_hooks_admin()
57
-    {
58
-    }
59
-
60
-
61
-    /**
62
-     *    run - initial module setup
63
-     *
64
-     * @param WP $WP
65
-     * @return    void
66
-     */
67
-    public function run($WP)
68
-    {
69
-    }
70
-
71
-
72
-    /**
73
-     * @param $html
74
-     * @param $datetime
75
-     * @return string
76
-     * @throws EE_Error
77
-     * @throws ReflectionException
78
-     */
79
-    public static function generate_add_to_iCal_button($html, $datetime)
80
-    {
81
-        // first verify a proper datetime object has been received
82
-        if ($datetime instanceof EE_Datetime) {
83
-            // set whether a link or submit button is shown
84
-            $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
85
-            // generate a link to the route we registered in set_hooks()
86
-            $URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
87
-            $URL = esc_url_Raw($URL);
88
-            // what type ?
89
-            switch ($iCal_type) {
90
-                // submit buttons appear as buttons and are very compatible with a theme's style
91
-                case 'submit':
92
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
93
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
94
-                    $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
95
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
96
-                    $html .= '</form>';
97
-                    break;
98
-                // buttons are just links that have been styled to appear as buttons,
99
-                // but may not be blend with a theme as well as submit buttons
100
-                case 'button':
101
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
102
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
103
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
104
-                    $html .= '</a>';
105
-                    break;
106
-                // links are just links that use the calendar dashicon
107
-                case 'icon':
108
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
109
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
110
-                    $html .= ' <span class="dashicons dashicons-calendar"></span>';
111
-                    $html .= '</a>';
112
-                    break;
113
-            }
114
-        }
115
-        return $html;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return void
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public static function download_ics_file()
125
-    {
126
-        $request = self::getRequest();
127
-        if ($request->requestParamIsSet('ics_id')) {
128
-            $DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
129
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
130
-            if ($datetime instanceof EE_Datetime) {
131
-                // get related event, venues, and event categories
132
-                $event = $datetime->event();
133
-                if ($event instanceof EE_Event) {
134
-                    // get related category Term object and it's name
135
-                    $category = $event->first_event_category();
136
-                    if ($category instanceof EE_Term) {
137
-                        $category = $category->name();
138
-                    }
139
-                    $location = '';
140
-                    // get first related venue and convert to CSV string
141
-                    $venue = $event->venues(['limit' => 1]);
142
-                    if (is_array($venue) && ! empty($venue)) {
143
-                        $venue = array_shift($venue);
144
-                        if ($venue instanceof EE_Venue) {
145
-                            $location = espresso_venue_raw_address('inline', $venue->ID(), false);
146
-                        }
147
-                    }
148
-
149
-                    // Generate filename
150
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
151
-
152
-                    // Check the datetime status has not been cancelled and set the ics value accordingly
153
-                    $status = $datetime->get_active_status();
154
-                    $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
155
-
156
-                    // Create array of ics details, escape strings, convert timestamps to ics format, etc
157
-                    $ics_data = [
158
-                        'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
159
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
160
-                        'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
161
-                        'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
162
-                        'LOCATION'       => $location,
163
-                        'SUMMARY'        => $event->name(),
164
-                        'DESCRIPTION'    => wp_strip_all_tags($event->description()),
165
-                        'STATUS'         => $status,
166
-                        'CATEGORIES'     => $category,
167
-                        'URL;VALUE=URI'  => get_permalink($event->ID()),
168
-                        'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
169
-                        'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
170
-                    ];
171
-
172
-                    // Filter the values used within the ics output.
173
-                    // NOTE - all values within ics_data will be escaped automatically.
174
-                    $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
175
-
176
-                    // Escape all ics data
177
-                    foreach ($ics_data as $key => $value) {
178
-                        // Description is escaped differently from all all values
179
-                        if ($key === 'DESCRIPTION') {
180
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
181
-                        } else {
182
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
183
-                        }
184
-                    }
185
-
186
-                    // Pull the organizer name from ics_data and remove it from the array.
187
-                    $organizer_name = isset($ics_data['ORGANIZER_NAME'])
188
-                        ? $ics_data['ORGANIZER_NAME']
189
-                        : '';
190
-                    unset($ics_data['ORGANIZER_NAME']);
191
-
192
-                    // set headers
193
-                    header('Content-type: text/calendar; charset=utf-8');
194
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
195
-                    header('Cache-Control: private, max-age=0, must-revalidate');
196
-                    header('Pragma: public');
197
-                    header('Content-Type: application/octet-stream');
198
-                    header('Content-Type: application/force-download');
199
-                    header('Cache-Control: no-cache, must-revalidate');
200
-                    header('Content-Transfer-Encoding: binary');
201
-                    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
202
-                    ini_set('zlib.output_compression', '0');
203
-                    // echo the output
204
-                    echo "BEGIN:VCALENDAR\r\n";
205
-                    echo "VERSION:2.0\r\n";
206
-                    echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
207
-                    echo "CALSCALE:GREGORIAN\r\n";
208
-                    echo "BEGIN:VEVENT\r\n";
209
-
210
-                    // Output all remaining values from ics_data.
211
-                    foreach ($ics_data as $key => $value) {
212
-                        echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
213
-                    }
214
-
215
-                    echo "END:VEVENT\r\n";
216
-                    echo "END:VCALENDAR\r\n";
217
-                }
218
-            }
219
-        }
220
-        die();
221
-    }
222
-
223
-
224
-    /**
225
-     *    _escape_ICal_data
226
-     *
227
-     * @param string $string
228
-     * @return    string
229
-     */
230
-    private static function _escape_ICal_data($string = '')
231
-    {
232
-        return preg_replace('/([\,;])/', '\\\$1', $string);
233
-    }
234
-
235
-
236
-    /**
237
-     *    _escape_ICal_description
238
-     *
239
-     * @param string $description
240
-     * @return    string
241
-     */
242
-    private static function _escape_ICal_description($description = '')
243
-    {
244
-        // Escape special chars within the description
245
-        $description = EED_Ical::_escape_ICal_data($description);
246
-        // Remove line breaks and output in iCal format
247
-        return str_replace(["\r\n", "\n"], '\n', $description);
248
-    }
18
+	const iCal_datetime_format = 'Ymd\THis\Z';
19
+
20
+
21
+	/**
22
+	 * @return EED_Ical|EED_Module
23
+	 * @throws EE_Error
24
+	 * @throws ReflectionException
25
+	 */
26
+	public static function instance()
27
+	{
28
+		return parent::get_instance(__CLASS__);
29
+	}
30
+
31
+
32
+	/**
33
+	 *    set_hooks - for hooking into EE Core, other modules, etc
34
+	 *
35
+	 * @return    void
36
+	 */
37
+	public static function set_hooks()
38
+	{
39
+		// create download buttons
40
+		add_filter(
41
+			'FHEE__espresso_list_of_event_dates__datetime_html',
42
+			['EED_Ical', 'generate_add_to_iCal_button'],
43
+			10,
44
+			2
45
+		);
46
+		// process ics download request
47
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
48
+	}
49
+
50
+
51
+	/**
52
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
53
+	 *
54
+	 * @return    void
55
+	 */
56
+	public static function set_hooks_admin()
57
+	{
58
+	}
59
+
60
+
61
+	/**
62
+	 *    run - initial module setup
63
+	 *
64
+	 * @param WP $WP
65
+	 * @return    void
66
+	 */
67
+	public function run($WP)
68
+	{
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param $html
74
+	 * @param $datetime
75
+	 * @return string
76
+	 * @throws EE_Error
77
+	 * @throws ReflectionException
78
+	 */
79
+	public static function generate_add_to_iCal_button($html, $datetime)
80
+	{
81
+		// first verify a proper datetime object has been received
82
+		if ($datetime instanceof EE_Datetime) {
83
+			// set whether a link or submit button is shown
84
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
85
+			// generate a link to the route we registered in set_hooks()
86
+			$URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url());
87
+			$URL = esc_url_Raw($URL);
88
+			// what type ?
89
+			switch ($iCal_type) {
90
+				// submit buttons appear as buttons and are very compatible with a theme's style
91
+				case 'submit':
92
+					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
93
+					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
94
+					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
95
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
96
+					$html .= '</form>';
97
+					break;
98
+				// buttons are just links that have been styled to appear as buttons,
99
+				// but may not be blend with a theme as well as submit buttons
100
+				case 'button':
101
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
102
+					$html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
103
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
104
+					$html .= '</a>';
105
+					break;
106
+				// links are just links that use the calendar dashicon
107
+				case 'icon':
108
+					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
109
+					$html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
110
+					$html .= ' <span class="dashicons dashicons-calendar"></span>';
111
+					$html .= '</a>';
112
+					break;
113
+			}
114
+		}
115
+		return $html;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return void
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public static function download_ics_file()
125
+	{
126
+		$request = self::getRequest();
127
+		if ($request->requestParamIsSet('ics_id')) {
128
+			$DTT_ID   = $request->getRequestParam('ics_id', 0, 'int');
129
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
130
+			if ($datetime instanceof EE_Datetime) {
131
+				// get related event, venues, and event categories
132
+				$event = $datetime->event();
133
+				if ($event instanceof EE_Event) {
134
+					// get related category Term object and it's name
135
+					$category = $event->first_event_category();
136
+					if ($category instanceof EE_Term) {
137
+						$category = $category->name();
138
+					}
139
+					$location = '';
140
+					// get first related venue and convert to CSV string
141
+					$venue = $event->venues(['limit' => 1]);
142
+					if (is_array($venue) && ! empty($venue)) {
143
+						$venue = array_shift($venue);
144
+						if ($venue instanceof EE_Venue) {
145
+							$location = espresso_venue_raw_address('inline', $venue->ID(), false);
146
+						}
147
+					}
148
+
149
+					// Generate filename
150
+					$filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
151
+
152
+					// Check the datetime status has not been cancelled and set the ics value accordingly
153
+					$status = $datetime->get_active_status();
154
+					$status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED';
155
+
156
+					// Create array of ics details, escape strings, convert timestamps to ics format, etc
157
+					$ics_data = [
158
+						'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
159
+						'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
160
+						'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
161
+						'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
162
+						'LOCATION'       => $location,
163
+						'SUMMARY'        => $event->name(),
164
+						'DESCRIPTION'    => wp_strip_all_tags($event->description()),
165
+						'STATUS'         => $status,
166
+						'CATEGORIES'     => $category,
167
+						'URL;VALUE=URI'  => get_permalink($event->ID()),
168
+						'DTSTART'        => date(EED_Ical::iCal_datetime_format, $datetime->start()),
169
+						'DTEND'          => date(EED_Ical::iCal_datetime_format, $datetime->end()),
170
+					];
171
+
172
+					// Filter the values used within the ics output.
173
+					// NOTE - all values within ics_data will be escaped automatically.
174
+					$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
175
+
176
+					// Escape all ics data
177
+					foreach ($ics_data as $key => $value) {
178
+						// Description is escaped differently from all all values
179
+						if ($key === 'DESCRIPTION') {
180
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
181
+						} else {
182
+							$ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
183
+						}
184
+					}
185
+
186
+					// Pull the organizer name from ics_data and remove it from the array.
187
+					$organizer_name = isset($ics_data['ORGANIZER_NAME'])
188
+						? $ics_data['ORGANIZER_NAME']
189
+						: '';
190
+					unset($ics_data['ORGANIZER_NAME']);
191
+
192
+					// set headers
193
+					header('Content-type: text/calendar; charset=utf-8');
194
+					header('Content-Disposition: attachment; filename="' . $filename . '"');
195
+					header('Cache-Control: private, max-age=0, must-revalidate');
196
+					header('Pragma: public');
197
+					header('Content-Type: application/octet-stream');
198
+					header('Content-Type: application/force-download');
199
+					header('Cache-Control: no-cache, must-revalidate');
200
+					header('Content-Transfer-Encoding: binary');
201
+					header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
202
+					ini_set('zlib.output_compression', '0');
203
+					// echo the output
204
+					echo "BEGIN:VCALENDAR\r\n";
205
+					echo "VERSION:2.0\r\n";
206
+					echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n";
207
+					echo "CALSCALE:GREGORIAN\r\n";
208
+					echo "BEGIN:VEVENT\r\n";
209
+
210
+					// Output all remaining values from ics_data.
211
+					foreach ($ics_data as $key => $value) {
212
+						echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
213
+					}
214
+
215
+					echo "END:VEVENT\r\n";
216
+					echo "END:VCALENDAR\r\n";
217
+				}
218
+			}
219
+		}
220
+		die();
221
+	}
222
+
223
+
224
+	/**
225
+	 *    _escape_ICal_data
226
+	 *
227
+	 * @param string $string
228
+	 * @return    string
229
+	 */
230
+	private static function _escape_ICal_data($string = '')
231
+	{
232
+		return preg_replace('/([\,;])/', '\\\$1', $string);
233
+	}
234
+
235
+
236
+	/**
237
+	 *    _escape_ICal_description
238
+	 *
239
+	 * @param string $description
240
+	 * @return    string
241
+	 */
242
+	private static function _escape_ICal_description($description = '')
243
+	{
244
+		// Escape special chars within the description
245
+		$description = EED_Ical::_escape_ICal_data($description);
246
+		// Remove line breaks and output in iCal format
247
+		return str_replace(["\r\n", "\n"], '\n', $description);
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -89,24 +89,24 @@  discard block
 block discarded – undo
89 89
             switch ($iCal_type) {
90 90
                 // submit buttons appear as buttons and are very compatible with a theme's style
91 91
                 case 'submit':
92
-                    $html .= '<form id="download-iCal-frm-' . $datetime->ID();
93
-                    $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
92
+                    $html .= '<form id="download-iCal-frm-'.$datetime->ID();
93
+                    $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
94 94
                     $html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
95
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>';
95
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'"/>';
96 96
                     $html .= '</form>';
97 97
                     break;
98 98
                 // buttons are just links that have been styled to appear as buttons,
99 99
                 // but may not be blend with a theme as well as submit buttons
100 100
                 case 'button':
101
-                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
102
-                    $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
101
+                    $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
102
+                    $html .= '" title="'.esc_html__('Add to iCal Calendar', 'event_espresso').'">';
103 103
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
104 104
                     $html .= '</a>';
105 105
                     break;
106 106
                 // links are just links that use the calendar dashicon
107 107
                 case 'icon':
108
-                    $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
109
-                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">';
108
+                    $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
109
+                    $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'">';
110 110
                     $html .= ' <span class="dashicons dashicons-calendar"></span>';
111 111
                     $html .= '</a>';
112 112
                     break;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                     }
148 148
 
149 149
                     // Generate filename
150
-                    $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics';
150
+                    $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
151 151
 
152 152
                     // Check the datetime status has not been cancelled and set the ics value accordingly
153 153
                     $status = $datetime->get_active_status();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                     // Create array of ics details, escape strings, convert timestamps to ics format, etc
157 157
                     $ics_data = [
158 158
                         'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
159
-                        'UID'            => md5($event->name() . $event->ID() . $datetime->ID()),
159
+                        'UID'            => md5($event->name().$event->ID().$datetime->ID()),
160 160
                         'ORGANIZER'      => EE_Registry::instance()->CFG->organization->email,
161 161
                         'DTSTAMP'        => date(EED_Ical::iCal_datetime_format),
162 162
                         'LOCATION'       => $location,
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
                     foreach ($ics_data as $key => $value) {
178 178
                         // Description is escaped differently from all all values
179 179
                         if ($key === 'DESCRIPTION') {
180
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
180
+                            $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
181 181
                         } else {
182
-                            $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value);
182
+                            $ics_data[$key] = EED_Ical::_escape_ICal_data($value);
183 183
                         }
184 184
                     }
185 185
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
                     // set headers
193 193
                     header('Content-type: text/calendar; charset=utf-8');
194
-                    header('Content-Disposition: attachment; filename="' . $filename . '"');
194
+                    header('Content-Disposition: attachment; filename="'.$filename.'"');
195 195
                     header('Cache-Control: private, max-age=0, must-revalidate');
196 196
                     header('Pragma: public');
197 197
                     header('Content-Type: application/octet-stream');
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
                     // Output all remaining values from ics_data.
211 211
                     foreach ($ics_data as $key => $value) {
212
-                        echo wp_kses($key . ':' . $value, AllowedTags::getAllowedTags()) . "\r\n";
212
+                        echo wp_kses($key.':'.$value, AllowedTags::getAllowedTags())."\r\n";
213 213
                     }
214 214
 
215 215
                     echo "END:VEVENT\r\n";
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/templates/invoice_body.template.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
         </thead>
77 77
         <tbody>
78 78
         <?php
79
-        /**
80
-         * Recursive function for traversing all the sub-items of each line item
81
-         * and displaying them in the table
82
-         *
83
-         * @param EE_Line_Item $line_item
84
-         * @param boolean      $odd for indicating whether to style this line item as an 'odd' or 'even'
85
-         */
86
-        function ee_invoice_display_line_item(EE_Line_Item $line_item, $show_line_item_description, $odd = false)
87
-        {
88
-            switch ($line_item->type()) {
89
-                case EEM_Line_Item::type_total:
90
-                    foreach ($line_item->children() as $child_line_item) {
91
-                        ee_invoice_display_line_item($child_line_item, $show_line_item_description);
92
-                    } ?>
79
+		/**
80
+		 * Recursive function for traversing all the sub-items of each line item
81
+		 * and displaying them in the table
82
+		 *
83
+		 * @param EE_Line_Item $line_item
84
+		 * @param boolean      $odd for indicating whether to style this line item as an 'odd' or 'even'
85
+		 */
86
+		function ee_invoice_display_line_item(EE_Line_Item $line_item, $show_line_item_description, $odd = false)
87
+		{
88
+			switch ($line_item->type()) {
89
+				case EEM_Line_Item::type_total:
90
+					foreach ($line_item->children() as $child_line_item) {
91
+						ee_invoice_display_line_item($child_line_item, $show_line_item_description);
92
+					} ?>
93 93
                     <tr>
94 94
                         <td colspan="<?php echo ($show_line_item_description ? 5 : 4) ?>">
95 95
                             <hr>
@@ -101,50 +101,50 @@  discard block
 block discarded – undo
101 101
                         <td class="total"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
102 102
                     </tr>
103 103
                     <?php
104
-                    break;
104
+					break;
105 105
 
106 106
 
107
-                case EEM_Line_Item::type_sub_total:
108
-                    foreach ($line_item->children() as $child_line_item) {
109
-                        // $odd = !$odd;
110
-                        ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
111
-                    } ?>
107
+				case EEM_Line_Item::type_sub_total:
108
+					foreach ($line_item->children() as $child_line_item) {
109
+						// $odd = !$odd;
110
+						ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
111
+					} ?>
112 112
                     <tr class="total_tr odd">
113 113
                         <td colspan="<?php echo ($show_line_item_description ? 2 : 1) ?>">&nbsp;</td>
114 114
                         <td colspan="2" class="total" id="total_currency">
115 115
                             <?php esc_html_e(
116
-                                'Sub-Total',
117
-                                'event_espresso'
118
-                            ); ?></td>
116
+								'Sub-Total',
117
+								'event_espresso'
118
+							); ?></td>
119 119
                         <td class="total"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
120 120
                     </tr>
121 121
                     <?php
122
-                    break;
122
+					break;
123 123
 
124 124
 
125
-                case EEM_Line_Item::type_tax_sub_total:
126
-                    foreach ($line_item->children() as $child_line_item) {
127
-                        $odd = ! $odd;
128
-                        ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
129
-                    } ?>
125
+				case EEM_Line_Item::type_tax_sub_total:
126
+					foreach ($line_item->children() as $child_line_item) {
127
+						$odd = ! $odd;
128
+						ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
129
+					} ?>
130 130
                     <tr class="total_tr odd">
131 131
                         <td colspan="<?php echo ($show_line_item_description ? 2 : 1) ?>">&nbsp;</td>
132 132
                         <td colspan="2" class="total" id="total_currency">
133 133
                             <?php esc_html_e(
134
-                                'Tax Total',
135
-                                'event_espresso'
136
-                            ); ?></td>
134
+								'Tax Total',
135
+								'event_espresso'
136
+							); ?></td>
137 137
                         <td class="total"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
138 138
                     </tr>
139 139
                     <?php
140
-                    break;
140
+					break;
141 141
 
142 142
 
143
-                case EEM_Line_Item::type_line_item:
144
-                    $subitems = $line_item->children();
145
-                    $has_subitems = count($subitems) > 1;
146
-                    if ($has_subitems) {
147
-                        ?>
143
+				case EEM_Line_Item::type_line_item:
144
+					$subitems = $line_item->children();
145
+					$has_subitems = count($subitems) > 1;
146
+					if ($has_subitems) {
147
+						?>
148 148
                         <tr class="item <?php echo ($odd ? 'odd' : ''); ?>">
149 149
                             <td class="item_l"><?php echo esc_html($line_item->name()) ?></td>
150 150
                             <?php if ($show_line_item_description) { ?>
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
                             <td class="item_c"><?php echo esc_html($line_item->unit_price_no_code()) ?></td>
156 156
 
157 157
                             <td class="item_r"> <?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags());
158
-                                echo ($line_item->is_taxable() ? '*' : ''); ?> </td>
158
+								echo ($line_item->is_taxable() ? '*' : ''); ?> </td>
159 159
                             <?php // <td class="item_l"><?php  $datetimes_strings = array(); foreach($datetimes as $datetime){ $datetimes_strings[]= $datetime->start_date_and_time();} echo implode(", ",$datetimes_strings);
160
-                            ?>
160
+							?>
161 161
                         </tr>
162 162
                         <?php
163
-                        if ($has_subitems) {
164
-                            foreach ($line_item->children() as $child_line_item) {
165
-                                ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
166
-                            }
167
-                        }
168
-                    } else {// no subitems - just show this line item
169
-                        ?>
163
+						if ($has_subitems) {
164
+							foreach ($line_item->children() as $child_line_item) {
165
+								ee_invoice_display_line_item($child_line_item, $show_line_item_description, $odd);
166
+							}
167
+						}
168
+					} else {// no subitems - just show this line item
169
+						?>
170 170
                         <tr class="item <?php echo ($odd ? 'odd' : ''); ?>">
171 171
                             <td class="item_l"><?php echo esc_html($line_item->name()); ?></td>
172 172
                             <?php if ($show_line_item_description) { ?>
@@ -175,15 +175,15 @@  discard block
 block discarded – undo
175 175
                             <td class="item_l"><?php echo esc_html($line_item->quantity()); ?></td>
176 176
                             <td class="item_c"><?php echo wp_kses($line_item->unit_price_no_code(), AllowedTags::getAllowedTags()); ?></td>
177 177
                             <td class="item_r"> <?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags());
178
-                                echo ($line_item->is_taxable() ? '*' : ''); ?> </td>
178
+								echo ($line_item->is_taxable() ? '*' : ''); ?> </td>
179 179
                             <?php // <td class="item_l"><?php  $datetimes_strings = array(); foreach($datetimes as $datetime){ $datetimes_strings[]= $datetime->start_date_and_time();} echo implode(", ",$datetimes_strings);
180
-                            ?>
180
+							?>
181 181
                         </tr>
182 182
                     <?php }
183 183
 
184
-                    break;
185
-                case EEM_Line_Item::type_sub_line_item:
186
-                    ?>
184
+					break;
185
+				case EEM_Line_Item::type_sub_line_item:
186
+					?>
187 187
                     <tr class="item subitem-row">
188 188
                         <td class="item_l subitem"><?php echo esc_html($line_item->name()); ?></td>
189 189
                         <?php if ($show_line_item_description) { ?>
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
                         <td class="item_r"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
200 200
                     </tr>
201 201
                     <?php
202
-                    break;
203
-                case EEM_Line_Item::type_tax:
204
-                    ?>
202
+					break;
203
+				case EEM_Line_Item::type_tax:
204
+					?>
205 205
                     <tr class="item sub-item tax-total">
206 206
                     <td class="item_l"><?php echo esc_html($line_item->name()); ?></td>
207 207
                     <?php if ($show_line_item_description) { ?>
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
 
212 212
                     <td class="item_r"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
213 213
                     </tr><?php
214
-                    break;
215
-            }
216
-        }
214
+					break;
215
+			}
216
+		}
217 217
 
218
-        $c = false;
219
-        /* @var $transaction EE_Transaction */
220
-        $total_line_item = $transaction->total_line_item();
221
-        ee_invoice_display_line_item($total_line_item, $show_line_item_description);
222
-        ?>
218
+		$c = false;
219
+		/* @var $transaction EE_Transaction */
220
+		$total_line_item = $transaction->total_line_item();
221
+		ee_invoice_display_line_item($total_line_item, $show_line_item_description);
222
+		?>
223 223
         </tbody>
224 224
 
225 225
     </table>
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
         </thead>
239 239
         <tbody>
240 240
         <?php
241
-        $c = false;
242
-        if (! empty($payments)) {
243
-            foreach ($payments as $payment) {
244
-                /* @var $payment EE_Payment */
245
-                ?>
241
+		$c = false;
242
+		if (! empty($payments)) {
243
+			foreach ($payments as $payment) {
244
+				/* @var $payment EE_Payment */
245
+				?>
246 246
                 <tr class='item <?php echo(($c = ! $c) ? ' odd' : '') ?>'>
247 247
                     <td><?php $payment->e('PAY_gateway') ?></td>
248 248
                     <td><?php echo esc_html($payment->timestamp('D M j, Y')); ?></td>
@@ -252,17 +252,17 @@  discard block
 block discarded – undo
252 252
                     <td class='item_r'><?php echo EEH_Template::format_currency($payment->amount()); ?></td>
253 253
                 </tr>
254 254
             <?php }
255
-        } else {
256
-            ?>
255
+		} else {
256
+			?>
257 257
             <tr class='item'>
258 258
                 <td class='aln-cntr' colspan=6>
259 259
                     <?php esc_html_e(
260
-                        "No approved payments have been received",
261
-                        'event_espresso'
262
-                    ) ?></td>
260
+						"No approved payments have been received",
261
+						'event_espresso'
262
+					) ?></td>
263 263
             </tr>
264 264
         <?php }
265
-        ?>
265
+		?>
266 266
         </tbody>
267 267
         <tfoot>
268 268
         <tr class='total_tr'>
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/templates/receipt_body.template.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
             <h3 class="section-title event-name">
65 65
                 <img class="icon" src="<?php echo EE_IMAGES_URL . 'calendar_year-24x24.png'; ?>">
66 66
                 <?php
67
-                esc_html_e(
68
-                    "Event Name:",
69
-                    "event_espresso"
70
-                ) ?>
67
+				esc_html_e(
68
+					"Event Name:",
69
+					"event_espresso"
70
+				) ?>
71 71
                 <span class="plain-text"><?php echo wp_kses($event->name(), AllowedTags::getAllowedTags()); ?></span>
72 72
                 <span class="small-text link">
73 73
                 [ <a href='<?php echo esc_url_raw($event->get_permalink()) ?>'><?php esc_html_e('view', 'event_espresso'); ?></a> ]
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
             <?php } ?>
79 79
             <ul class="tickets-per-event">
80 80
                 <?php
81
-                foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
82
-                    $ticket       = $line_item->ticket();
83
-                    $taxable_html = $ticket->taxable()
84
-                            ? '*'
85
-                            : '';
86
-                    $subitems     = $line_item->children();
87
-                    $ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
88
-                    ?>
81
+				foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
82
+					$ticket       = $line_item->ticket();
83
+					$taxable_html = $ticket->taxable()
84
+							? '*'
85
+							: '';
86
+					$subitems     = $line_item->children();
87
+					$ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
88
+					?>
89 89
                     <li class="event-ticket">
90 90
                         <div class="ticket-details">
91 91
                             <table class="invoice-amount">
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
                                     <th class="name-column"><?php esc_html_e("Ticket", "event_espresso"); ?></th>
95 95
                                     <th colspan="2" class="desc-column">
96 96
                                         <?php
97
-                                        esc_html_e(
98
-                                            "Description",
99
-                                            "event_espresso"
100
-                                        ); ?></th>
97
+										esc_html_e(
98
+											"Description",
99
+											"event_espresso"
100
+										); ?></th>
101 101
                                     <th class="number-column item_c"><?php esc_html_e("Quantity", "event_espresso"); ?></th>
102 102
                                     <th class="number-column item_c"><?php esc_html_e("Price", "event_espresso"); ?></th>
103 103
                                     <th class="number-column item_r"><?php esc_html_e("Total", "event_espresso"); ?></th>
@@ -105,20 +105,20 @@  discard block
 block discarded – undo
105 105
                                 </thead>
106 106
                                 <tbody>
107 107
                                 <?php
108
-                                if (count($subitems) < 2) { ?>
108
+								if (count($subitems) < 2) { ?>
109 109
                                     <tr class="item">
110 110
                                         <td><?php echo esc_html($line_item->name() . $taxable_html); ?></td>
111 111
                                         <td colspan="2">
112 112
                                             <?php echo esc_html($line_item->desc()); ?>
113 113
                                             <p class="ticket-note">
114 114
                                                 <?php
115
-                                                echo sprintf(
116
-                                                    esc_html__(
117
-                                                        'This ticket can be used once at %s of the dates/times below.',
118
-                                                        'event_espresso'
119
-                                                    ),
120
-                                                    $ticket_uses
121
-                                                ); ?>
115
+												echo sprintf(
116
+													esc_html__(
117
+														'This ticket can be used once at %s of the dates/times below.',
118
+														'event_espresso'
119
+													),
120
+													$ticket_uses
121
+												); ?>
122 122
                                             </p>
123 123
                                         </td>
124 124
                                         <td class="item_c"><?php echo esc_html($line_item->quantity()); ?></td>
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                                         <td class="item_r"><?php echo wp_kses($line_item->total_no_code(), AllowedTags::getAllowedTags());  ?></td>
127 127
                                     </tr>
128 128
                                     <?php
129
-                                } else { ?>
129
+								} else { ?>
130 130
                                     <tr class="item">
131 131
                                         <td class="aln-left">
132 132
                                             <?php echo esc_html($line_item->name() . $taxable_html); ?>
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
                                         <td colspan="2"><?php echo esc_html($line_item->desc()); ?>
135 135
                                             <p class="ticket-note">
136 136
                                                 <?php
137
-                                                echo sprintf(
138
-                                                    esc_html__(
139
-                                                        'This ticket can be used once at %s of the dates/times below.',
140
-                                                        'event_espresso'
141
-                                                    ),
142
-                                                    $ticket_uses
143
-                                                ); ?>
137
+												echo sprintf(
138
+													esc_html__(
139
+														'This ticket can be used once at %s of the dates/times below.',
140
+														'event_espresso'
141
+													),
142
+													$ticket_uses
143
+												); ?>
144 144
                                             </p>
145 145
                                         </td>
146 146
                                         <td class="item_c">
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
                                         </td>
155 155
                                     </tr>
156 156
                                     <?php
157
-                                    foreach ($subitems as $sub_line_item) {
158
-                                        $is_percent = $sub_line_item->is_percent(); ?>
157
+									foreach ($subitems as $sub_line_item) {
158
+										$is_percent = $sub_line_item->is_percent(); ?>
159 159
                                         <tr class="subitem-row">
160 160
                                             <td class="subitem">
161 161
                                                 <?php echo esc_html($sub_line_item->name()); ?>
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
                                             <td class="item_c">
167 167
                                             </td>
168 168
                                             <td class="item_c"><?php
169
-                                                echo ($is_percent
170
-                                                    ? $sub_line_item->percent() . "%"
171
-                                                    : $sub_line_item->unit_price_no_code()); ?>
169
+												echo ($is_percent
170
+													? $sub_line_item->percent() . "%"
171
+													: $sub_line_item->unit_price_no_code()); ?>
172 172
                                             </td>
173 173
                                             <td class="item_r"><?php echo wp_kses($sub_line_item->total_no_code(), AllowedTags::getAllowedTags()); ?></td>
174 174
                                         </tr>
175 175
                                         <?php
176
-                                    } ?>
176
+									} ?>
177 177
                                     <tr class="total_tr odd">
178 178
                                         <td colspan="4"></td>
179 179
                                         <td class="total" nowrap="nowrap">
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
                                         </td>
185 185
                                     </tr>
186 186
                                     <?php
187
-                                } ?>
187
+								} ?>
188 188
                                 </tbody>
189 189
                             </table>
190 190
 
@@ -195,49 +195,49 @@  discard block
 block discarded – undo
195 195
                                     <h4 class="sub-section-title no-bottom-margin">
196 196
                                         <img class="icon" src="<?php echo esc_url_raw(EE_IMAGES_URL . 'clock-16x16.png'); ?>">
197 197
                                         <?php
198
-                                        echo _n(
199
-                                            "Date/Time:",
200
-                                            "Dates/Times:",
201
-                                            count($ticket->datetimes()),
202
-                                            "event_espresso"
203
-                                        ); ?></h4>
198
+										echo _n(
199
+											"Date/Time:",
200
+											"Dates/Times:",
201
+											count($ticket->datetimes()),
202
+											"event_espresso"
203
+										); ?></h4>
204 204
                                     <ul class="event-dates">
205 205
                                         <?php
206
-                                        foreach ($ticket->datetimes_ordered() as $datetime) {
207
-                                            /* @var $datetime EE_Datetime */ ?>
206
+										foreach ($ticket->datetimes_ordered() as $datetime) {
207
+											/* @var $datetime EE_Datetime */ ?>
208 208
                                             <li><?php
209
-                                                echo ($datetime->name()
210
-                                                    ? '<b>' . esc_html($datetime->name()) . ' </b>'
211
-                                                    : '');
212
-                                                echo sprintf(
213
-                                                    esc_html__("%s - %s (%s)", "event_espresso"),
214
-                                                    $datetime->start_date_and_time(),
215
-                                                    $datetime->end_date_and_time(),
216
-                                                    $datetime->get_timezone()
217
-                                                );
218
-                                                echo ($datetime->description()
219
-                                                    ? '<p class="ticket-note">' . wp_kses($datetime->description(), AllowedTags::getAllowedTags()) . '</p>'
220
-                                                    : ''); ?></li>
209
+												echo ($datetime->name()
210
+													? '<b>' . esc_html($datetime->name()) . ' </b>'
211
+													: '');
212
+												echo sprintf(
213
+													esc_html__("%s - %s (%s)", "event_espresso"),
214
+													$datetime->start_date_and_time(),
215
+													$datetime->end_date_and_time(),
216
+													$datetime->get_timezone()
217
+												);
218
+												echo ($datetime->description()
219
+													? '<p class="ticket-note">' . wp_kses($datetime->description(), AllowedTags::getAllowedTags()) . '</p>'
220
+													: ''); ?></li>
221 221
                                             <?php
222
-                                        } ?>
222
+										} ?>
223 223
                                     </ul>
224 224
                                 </div>
225 225
                                 <?php
226
-                                if ($event->venues()) { ?>
226
+								if ($event->venues()) { ?>
227 227
                                     <div class="ticket-place-details">
228 228
                                         <h4 class="sub-section-title no-bottom-margin">
229 229
                                             <img class="icon" src="<?php
230
-                                            echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>">
230
+											echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>">
231 231
                                             <?php
232
-                                            echo _n(
233
-                                                "Venue:",
234
-                                                "Venues:",
235
-                                                count($event->venues()),
236
-                                                "event_espresso"
237
-                                            ); ?></h4>
232
+											echo _n(
233
+												"Venue:",
234
+												"Venues:",
235
+												count($event->venues()),
236
+												"event_espresso"
237
+											); ?></h4>
238 238
                                         <ul class="event-venues">
239 239
                                             <?php
240
-                                            foreach ($event->venues() as $venue) { ?>
240
+											foreach ($event->venues() as $venue) { ?>
241 241
                                                 <li><?php echo esc_html($venue->name()) ?>
242 242
                                                     <span class="small-text">
243 243
                                                 [
@@ -248,18 +248,18 @@  discard block
 block discarded – undo
248 248
                                             </span>
249 249
                                                 </li>
250 250
                                                 <?php
251
-                                            } ?>
251
+											} ?>
252 252
                                         </ul>
253 253
                                     </div>
254 254
                                     <?php
255
-                                } ?>
255
+								} ?>
256 256
                             </div>
257 257
                             <div class="ticket-registrations-area">
258 258
                                 <h4 class="sub-section-title">
259 259
                                     <img class="icon" src="<?php
260
-                                    echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>">
260
+									echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>">
261 261
                                     <?php
262
-                                    echo esc_html__("Registration Details", "event_espresso"); ?>
262
+									echo esc_html__("Registration Details", "event_espresso"); ?>
263 263
                                     <span class="small-text link">[
264 264
                                 <a class="print_button noPrint" href="<?php echo esc_url_raw($edit_reg_info_url); ?>">
265 265
                                     <?php esc_html_e('edit', 'event_espresso'); ?>
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
                                 </h4>
270 270
                                 <ul class="ticket-registrations-list">
271 271
                                     <?php
272
-                                    foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
273
-                                        /* @var $registration EE_Registration */
274
-                                        $attendee = $registration->attendee();
275
-                                        $answers  = $registration->answers(
276
-                                            ['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
277
-                                        ); ?>
272
+									foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
273
+										/* @var $registration EE_Registration */
274
+										$attendee = $registration->attendee();
275
+										$answers  = $registration->answers(
276
+											['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
277
+										); ?>
278 278
                                         <li class="ticket-registration">
279 279
                                             <table class="registration-details">
280 280
                                                 <tr class="odd">
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
                                                     </td>
290 290
                                                 </tr>
291 291
                                                 <?php
292
-                                                foreach ($event->question_groups() as $question_group) { ?>
292
+												foreach ($event->question_groups() as $question_group) { ?>
293 293
                                                     <tr>
294 294
                                                         <th>
295 295
                                                             <?php $question_group->e('QSG_name'); ?>
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
                                                         <td></td>
298 298
                                                     </tr>
299 299
                                                     <?php $has_personal_info = false;
300
-                                                    foreach ($question_group->questions() as $question) {
301
-                                                        if (in_array($question->system_ID(), $questions_to_skip)) {
302
-                                                            $has_personal_info = true;
303
-                                                            continue;
304
-                                                        }
305
-                                                        ?>
300
+													foreach ($question_group->questions() as $question) {
301
+														if (in_array($question->system_ID(), $questions_to_skip)) {
302
+															$has_personal_info = true;
303
+															continue;
304
+														}
305
+														?>
306 306
                                                         <tr>
307 307
                                                             <th>
308 308
                                                                 <?php echo wp_kses($question->display_text(), AllowedTags::getAllowedTags()); ?>
@@ -312,26 +312,26 @@  discard block
 block discarded – undo
312 312
                                                             </td>
313 313
                                                         </tr>
314 314
                                                     <?php }
315
-                                                    if ($has_personal_info) { ?>
315
+													if ($has_personal_info) { ?>
316 316
                                                         <tr>
317 317
                                                             <th><?php esc_html_e('Attendee', 'event_espresso'); ?></th>
318 318
                                                             <td>
319 319
                                                                 <?php
320
-                                                                echo sprintf(
321
-                                                                    esc_html__('%s (%s)', "event_espresso"),
322
-                                                                    esc_html($attendee->full_name()),
323
-                                                                    sanitize_email($attendee->email())
324
-                                                                ) ?>
320
+																echo sprintf(
321
+																	esc_html__('%s (%s)', "event_espresso"),
322
+																	esc_html($attendee->full_name()),
323
+																	sanitize_email($attendee->email())
324
+																) ?>
325 325
                                                             </td>
326 326
                                                         </tr>
327 327
                                                         <?php
328
-                                                    }
329
-                                                }
330
-                                                ?>
328
+													}
329
+												}
330
+												?>
331 331
                                             </table>
332 332
                                         </li>
333 333
                                         <?php
334
-                                    } ?>
334
+									} ?>
335 335
                                 </ul>
336 336
                             </div>
337 337
                         </div>
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
     <div class="grand-total-dv">
376 376
         <h2 class="grand-total">
377 377
             <?php
378
-            printf(
379
-                esc_html__("Grand Total: %s", "event_espresso"),
380
-                EEH_Template::format_currency($total_cost)
381
-            ); ?>
378
+			printf(
379
+				esc_html__("Grand Total: %s", "event_espresso"),
380
+				EEH_Template::format_currency($total_cost)
381
+			); ?>
382 382
         </h2>
383 383
     </div>
384 384
     <div class="payment-dv">
@@ -397,13 +397,13 @@  discard block
 block discarded – undo
397 397
             </thead>
398 398
             <tbody>
399 399
             <?php
400
-            $c = false;
401
-            if (! empty($payments)) {
402
-                foreach ($payments as $payment) {
403
-                    /* @var $payment EE_Payment */ ?>
400
+			$c = false;
401
+			if (! empty($payments)) {
402
+				foreach ($payments as $payment) {
403
+					/* @var $payment EE_Payment */ ?>
404 404
                     <tr class='item <?php echo(($c = ! $c)
405
-                        ? ' odd'
406
-                        : '') ?>'>
405
+						? ' odd'
406
+						: '') ?>'>
407 407
                         <td><?php $payment->e('PAY_gateway') ?></td>
408 408
                         <td><?php echo esc_html($payment->timestamp()); ?></td>
409 409
                         <td><?php $payment->e('PAY_txn_id_chq_nmbr') ?></td>
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
                         <td class='item_r'><?php echo wp_kses($payment->amount_no_code(), AllowedTags::getAllowedTags()); ?></td>
413 413
                     </tr>
414 414
                 <?php }
415
-            } else { ?>
415
+			} else { ?>
416 416
                 <tr class='item'>
417 417
                     <td class='aln-cntr' colspan="6">
418 418
                         <?php
419
-                        esc_html_e(
420
-                            "No approved payments have been received.",
421
-                            'event_espresso'
422
-                        ) ?>
419
+						esc_html_e(
420
+							"No approved payments have been received.",
421
+							'event_espresso'
422
+						) ?>
423 423
                     </td>
424 424
                 </tr>
425 425
             <?php } ?>
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
             <?php if ($venues_for_events) { ?>
456 456
             <h2>
457 457
                 <?php
458
-                echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
458
+				echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
459 459
             </h2>
460 460
             <table class="venue-list">
461 461
                 <?php foreach ($venues_for_events as $venue) { ?>
Please login to merge, or discard this patch.