Completed
Branch FET-3467-waitlists (22afd9)
by
unknown
111:31 queued 100:32
created
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param EE_Line_Item $line_item
78 78
      * @param array        $options
79 79
      * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
80
+     * @return string
81 81
      * @throws EE_Error
82 82
      */
83 83
     public function display_line_item(
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * _event_row - basically a Heading row displayed once above each event's ticket rows
224 224
      *
225 225
      * @param EE_Line_Item $line_item
226
-     * @return mixed
226
+     * @return string
227 227
      */
228 228
     private function _event_row(EE_Line_Item $line_item)
229 229
     {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param EE_Line_Item $line_item
251 251
      * @param array        $options
252
-     * @return mixed
252
+     * @return string
253 253
      * @throws EE_Error
254 254
      */
255 255
     private function _ticket_row(EE_Line_Item $line_item, $options = array())
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      *
304 304
      * @param EE_Line_Item $line_item
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      * @throws EE_Error
308 308
      */
309 309
     private function _item_row(EE_Line_Item $line_item, $options = array())
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @param EE_Line_Item $line_item
364 364
      * @param array        $options
365 365
      * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
366
+     * @return string
367 367
      * @throws EE_Error
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      *
408 408
      * @param EE_Line_Item $line_item
409 409
      * @param array        $options
410
-     * @return mixed
410
+     * @return string
411 411
      * @throws EE_Error
412 412
      */
413 413
     private function _tax_row(EE_Line_Item $line_item, $options = array())
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      *
445 445
      * @param EE_Line_Item $line_item
446 446
      * @param string       $text
447
-     * @return mixed
447
+     * @return string
448 448
      * @throws EE_Error
449 449
      */
450 450
     private function _total_tax_row(EE_Line_Item $line_item, $text = '')
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
      * @param EE_Line_Item $line_item
484 484
      * @param string       $text
485 485
      * @param array        $options
486
-     * @return mixed
486
+     * @return string
487 487
      * @throws EE_Error
488 488
      */
489 489
     private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
      *
520 520
      * @param EE_Line_Item $line_item
521 521
      * @param string       $text
522
-     * @return mixed
522
+     * @return string
523 523
      * @throws EE_Error
524 524
      */
525 525
     private function _total_row(EE_Line_Item $line_item, $text = '')
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
      *
547 547
      * @param EE_Line_Item $line_item
548 548
      * @param array        $options
549
-     * @return mixed
549
+     * @return string
550 550
      * @throws EE_Error
551 551
      */
552 552
     private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
Please login to merge, or discard this patch.
Indentation   +603 added lines, -603 removed lines patch added patch discarded remove patch
@@ -16,609 +16,609 @@
 block discarded – undo
16 16
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18 18
 
19
-    /**
20
-     * array of events
21
-     *
22
-     * @type EE_Line_Item[] $_events
23
-     */
24
-    private $_events = array();
25
-
26
-    /**
27
-     * whether to display the taxes row or not
28
-     *
29
-     * @type bool $_show_taxes
30
-     */
31
-    private $_show_taxes = false;
32
-
33
-    /**
34
-     * html for any tax rows
35
-     *
36
-     * @type string $_show_taxes
37
-     */
38
-    private $_taxes_html = '';
39
-
40
-    /**
41
-     * total amount including tax we can bill for at this time
42
-     *
43
-     * @type float $_grand_total
44
-     */
45
-    private $_grand_total = 0.00;
46
-
47
-    /**
48
-     * total number of items being billed for
49
-     *
50
-     * @type int $_total_items
51
-     */
52
-    private $_total_items = 0;
53
-
54
-
55
-
56
-    /**
57
-     * @return float
58
-     */
59
-    public function grand_total()
60
-    {
61
-        return $this->_grand_total;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return int
68
-     */
69
-    public function total_items()
70
-    {
71
-        return $this->_total_items;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param EE_Line_Item $line_item
78
-     * @param array        $options
79
-     * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function display_line_item(
84
-        EE_Line_Item $line_item,
85
-        $options = array(),
86
-        EE_Line_Item $parent_line_item = null
87
-    ) {
88
-        $html = '';
89
-        // set some default options and merge with incoming
90
-        $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
92
-            'odd'       => false,
93
-        );
94
-        $options = array_merge($default_options, (array)$options);
95
-        switch ($line_item->type()) {
96
-            case EEM_Line_Item::type_line_item:
97
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
-                if ($line_item->OBJ_type() === 'Ticket') {
99
-                    // item row
100
-                    $html .= $this->_ticket_row($line_item, $options);
101
-                } else {
102
-                    // item row
103
-                    $html .= $this->_item_row($line_item, $options);
104
-                }
105
-                if (
106
-                apply_filters(
107
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
-                    true
109
-                )
110
-                ) {
111
-                    // got any kids?
112
-                    foreach ($line_item->children() as $child_line_item) {
113
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
114
-                    }
115
-                }
116
-                break;
117
-            case EEM_Line_Item::type_sub_line_item:
118
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
-                break;
120
-            case EEM_Line_Item::type_sub_total:
121
-                static $sub_total = 0;
122
-                $event_sub_total = 0;
123
-                $text = esc_html__('Sub-Total', 'event_espresso');
124
-                if ($line_item->OBJ_type() === 'Event') {
125
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
127
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
-                        // if event has default reg status of Not Approved, then don't display info on it
129
-                        if (
130
-                            $event instanceof EE_Event
131
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
-                        ) {
133
-                            $display_event = false;
134
-                            // unless there are registrations for it that are returning to pay
135
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
136
-                                foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
138
-                                        continue;
139
-                                    }
140
-                                    $display_event = $registration->event_ID() === $options['event_id']
141
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
-                                        ? true
143
-                                        : $display_event;
144
-                                }
145
-                            }
146
-                            if (! $display_event) {
147
-                                return '';
148
-                            }
149
-                        }
150
-                        $this->_events[$options['event_id']] = 0;
151
-                        $html .= $this->_event_row($line_item);
152
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
153
-                    }
154
-                }
155
-                $child_line_items = $line_item->children();
156
-                // loop thru children
157
-                foreach ($child_line_items as $child_line_item) {
158
-                    // recursively feed children back into this method
159
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
160
-                }
161
-                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
-                $sub_total += $event_sub_total;
163
-                if (
164
-                    (
165
-                        // event subtotals
166
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
-                    )
168
-                    || (
169
-                        // pre-tax subtotals
170
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
-                    )
172
-                ) {
173
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax:
178
-                if ($this->_show_taxes) {
179
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
180
-                }
181
-                break;
182
-            case EEM_Line_Item::type_tax_sub_total:
183
-                if ($this->_show_taxes) {
184
-                    $child_line_items = $line_item->children();
185
-                    // loop thru children
186
-                    foreach ($child_line_items as $child_line_item) {
187
-                        // recursively feed children back into this method
188
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
189
-                    }
190
-                    if (count($child_line_items) > 1) {
191
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
-                    }
193
-                }
194
-                break;
195
-            case EEM_Line_Item::type_total:
196
-                // get all child line items
197
-                $children = $line_item->children();
198
-                // loop thru all non-tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                // now loop thru  tax child line items
206
-                foreach ($children as $child_line_item) {
207
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
-                        // recursively feed children back into this method
209
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
210
-                    }
211
-                }
212
-                $html .= $this->_taxes_html;
213
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
-                break;
216
-        }
217
-        return $html;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
224
-     *
225
-     * @param EE_Line_Item $line_item
226
-     * @return mixed
227
-     */
228
-    private function _event_row(EE_Line_Item $line_item)
229
-    {
230
-        // start of row
231
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
-        // event name td
233
-        $html .= EEH_HTML::td(
234
-            EEH_HTML::strong($line_item->name()),
235
-            '',
236
-            'event-header',
237
-            '',
238
-            ' colspan="4"'
239
-        );
240
-        // end of row
241
-        $html .= EEH_HTML::trx();
242
-        return $html;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * _ticket_row
249
-     *
250
-     * @param EE_Line_Item $line_item
251
-     * @param array        $options
252
-     * @return mixed
253
-     * @throws EE_Error
254
-     */
255
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
-    {
257
-        // start of row
258
-        $row_class = $options['odd'] ? 'item odd' : 'item';
259
-        $html = EEH_HTML::tr('', '', $row_class);
260
-        // name && desc
261
-        $name_and_desc = apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
-            $line_item->name(),
264
-            $line_item
265
-        );
266
-        $name_and_desc .= apply_filters(
267
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
-            (
269
-                $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
-                    : ''
272
-            ),
273
-            $line_item,
274
-            $options
275
-        );
276
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
-        // name td
278
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
-            $name_and_desc, '', 'item_l');
280
-        // price td
281
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
-        // quantity td
283
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
-        $this->_total_items += $line_item->quantity();
285
-        // determine total for line item
286
-        $total = $line_item->total();
287
-        $this->_events[$options['event_id']] += $total;
288
-        // total td
289
-        $html .= EEH_HTML::td(
290
-            EEH_Template::format_currency($total, false, false),
291
-            '',
292
-            'item_r jst-rght'
293
-        );
294
-        // end of row
295
-        $html .= EEH_HTML::trx();
296
-        return $html;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * _item_row
303
-     *
304
-     * @param EE_Line_Item $line_item
305
-     * @param array        $options
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    private function _item_row(EE_Line_Item $line_item, $options = array())
310
-    {
311
-        // start of row
312
-        $row_class = $options['odd'] ? 'item odd' : 'item';
313
-        $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
-        // name && desc
316
-        $name_and_desc = apply_filters(
317
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
319
-            $line_item
320
-        );
321
-        $name_and_desc .= apply_filters(
322
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
-            (
324
-                $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
-                : ''
327
-            ),
328
-            $line_item,
329
-            $options
330
-        );
331
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
-        // name td
333
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
-        // price td
335
-        if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
-        } else {
338
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
-        }
340
-        // quantity td
341
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
-        //$total = $line_item->total() * $line_item->quantity();
343
-        $total = $line_item->total();
344
-        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
-            $this->_events[$options['event_id']] += $total;
346
-        }
347
-        // total td
348
-        $html .= EEH_HTML::td(
349
-            EEH_Template::format_currency($total, false, false),
350
-            '',
351
-            'item_r jst-rght'
352
-        );
353
-        // end of row
354
-        $html .= EEH_HTML::trx();
355
-        return $html;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * _sub_item_row
362
-     *
363
-     * @param EE_Line_Item $line_item
364
-     * @param array        $options
365
-     * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
367
-     * @throws EE_Error
368
-     */
369
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
-    {
371
-        // start of row
372
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
373
-        // name && desc
374
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
-                         . $line_item->name();
376
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
-                                                  . $line_item->desc()
378
-                                                  . '</span>' : '';
379
-        // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
-        // discount/surcharge td
383
-        if ($line_item->is_percent()) {
384
-            $html .= EEH_HTML::td(
385
-                EEH_Template::format_currency(
386
-                    $line_item->total() / $qty,
387
-                    false, false
388
-                ),
389
-                '', 'item_c jst-rght'
390
-            );
391
-        } else {
392
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
-        }
394
-        // no quantity td
395
-        $html .= EEH_HTML::td();
396
-        // no total td
397
-        $html .= EEH_HTML::td();
398
-        // end of row
399
-        $html .= EEH_HTML::trx();
400
-        return $html;
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * _tax_row
407
-     *
408
-     * @param EE_Line_Item $line_item
409
-     * @param array        $options
410
-     * @return mixed
411
-     * @throws EE_Error
412
-     */
413
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
414
-    {
415
-        // start of row
416
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
417
-        // name && desc
418
-        $name_and_desc = $line_item->name();
419
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
-        // name td
423
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
-            $name_and_desc, '', 'item_l sub-item');
425
-        // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
-        // empty td (price)
428
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
429
-        // total td
430
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
431
-            $line_item->total(), false, false),
432
-            '',
433
-            'item_r jst-rght'
434
-        );
435
-        // end of row
436
-        $html .= EEH_HTML::trx();
437
-        return $html;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * _total_row
444
-     *
445
-     * @param EE_Line_Item $line_item
446
-     * @param string       $text
447
-     * @return mixed
448
-     * @throws EE_Error
449
-     */
450
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
-    {
452
-        $html = '';
453
-        if ($line_item->total()) {
454
-            // start of row
455
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
456
-            // total td
457
-            $html .= EEH_HTML::td(
458
-                $text,
459
-                '',
460
-                'total_currency total jst-rght',
461
-                '',
462
-                ' colspan="2"'
463
-            );
464
-            // empty td (price)
465
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
466
-            // total td
467
-            $html .= EEH_HTML::td(
468
-                EEH_Template::format_currency($line_item->total(), false, false),
469
-                '',
470
-                'total jst-rght'
471
-            );
472
-            // end of row
473
-            $html .= EEH_HTML::trx();
474
-        }
475
-        return $html;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * _total_row
482
-     *
483
-     * @param EE_Line_Item $line_item
484
-     * @param string       $text
485
-     * @param array        $options
486
-     * @return mixed
487
-     * @throws EE_Error
488
-     */
489
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
-    {
491
-        $html = '';
492
-        if ($line_item->total()) {
493
-            // start of row
494
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
495
-            // total td
496
-            $html .= EEH_HTML::td(
497
-                $text,
498
-                '',
499
-                'total_currency total jst-rght',
500
-                '',
501
-                ' colspan="3"'
502
-            );
503
-            // total td
504
-            $html .= EEH_HTML::td(
505
-                EEH_Template::format_currency($options['sub_total'], false, false),
506
-                '',
507
-                'total jst-rght'
508
-            );
509
-            // end of row
510
-            $html .= EEH_HTML::trx();
511
-        }
512
-        return $html;
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * _total_row
519
-     *
520
-     * @param EE_Line_Item $line_item
521
-     * @param string       $text
522
-     * @return mixed
523
-     * @throws EE_Error
524
-     */
525
-    private function _total_row(EE_Line_Item $line_item, $text = '')
526
-    {
527
-        // start of row
528
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
-        // total td
530
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
-        // total td
532
-        $html .= EEH_HTML::td(
533
-            EEH_Template::format_currency($line_item->total(), false, false),
534
-            '',
535
-            'total jst-rght'
536
-        );
537
-        // end of row
538
-        $html .= EEH_HTML::trx();
539
-        return $html;
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * _payments_and_amount_owing_rows
546
-     *
547
-     * @param EE_Line_Item $line_item
548
-     * @param array        $options
549
-     * @return mixed
550
-     * @throws EE_Error
551
-     */
552
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
-    {
554
-        $html = '';
555
-        $owing = $line_item->total();
556
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
-        if ($transaction instanceof EE_Transaction) {
558
-            $registration_payments = array();
559
-            $registrations = ! empty($options['registrations'])
560
-                ? $options['registrations']
561
-                : $transaction->registrations();
562
-            foreach ($registrations as $registration) {
563
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
-                    $registration_payments += $registration->registration_payments();
565
-                }
566
-            }
567
-            if (! empty($registration_payments)) {
568
-                foreach ($registration_payments as $registration_payment) {
569
-                    if ($registration_payment instanceof EE_Registration_Payment) {
570
-                        $owing -= $registration_payment->amount();
571
-                        $payment = $registration_payment->payment();
572
-                        $payment_desc = '';
573
-                        if ($payment instanceof EE_Payment) {
574
-                            $payment_desc = sprintf(
575
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
-                                $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
-                                    : '',
579
-                                $payment->timestamp()
580
-                            );
581
-                        }
582
-                        // start of row
583
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
584
-                        // payment desc
585
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
-                        // total td
587
-                        $html .= EEH_HTML::td(
588
-                            EEH_Template::format_currency(
589
-                                $registration_payment->amount(),
590
-                                false,
591
-                                false
592
-                            ),
593
-                            '',
594
-                            'total jst-rght'
595
-                        );
596
-                        // end of row
597
-                        $html .= EEH_HTML::trx();
598
-                    }
599
-                }
600
-                if ($line_item->total()) {
601
-                    // start of row
602
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
603
-                    // total td
604
-                    $html .= EEH_HTML::td(
605
-                        esc_html__('Amount Owing', 'event_espresso'),
606
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
607
-                    );
608
-                    // total td
609
-                    $html .= EEH_HTML::td(
610
-                        EEH_Template::format_currency($owing, false, false),
611
-                        '',
612
-                        'total jst-rght'
613
-                    );
614
-                    // end of row
615
-                    $html .= EEH_HTML::trx();
616
-                }
617
-            }
618
-        }
619
-        $this->_grand_total = $owing;
620
-        return $html;
621
-    }
19
+	/**
20
+	 * array of events
21
+	 *
22
+	 * @type EE_Line_Item[] $_events
23
+	 */
24
+	private $_events = array();
25
+
26
+	/**
27
+	 * whether to display the taxes row or not
28
+	 *
29
+	 * @type bool $_show_taxes
30
+	 */
31
+	private $_show_taxes = false;
32
+
33
+	/**
34
+	 * html for any tax rows
35
+	 *
36
+	 * @type string $_show_taxes
37
+	 */
38
+	private $_taxes_html = '';
39
+
40
+	/**
41
+	 * total amount including tax we can bill for at this time
42
+	 *
43
+	 * @type float $_grand_total
44
+	 */
45
+	private $_grand_total = 0.00;
46
+
47
+	/**
48
+	 * total number of items being billed for
49
+	 *
50
+	 * @type int $_total_items
51
+	 */
52
+	private $_total_items = 0;
53
+
54
+
55
+
56
+	/**
57
+	 * @return float
58
+	 */
59
+	public function grand_total()
60
+	{
61
+		return $this->_grand_total;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return int
68
+	 */
69
+	public function total_items()
70
+	{
71
+		return $this->_total_items;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param EE_Line_Item $line_item
78
+	 * @param array        $options
79
+	 * @param EE_Line_Item $parent_line_item
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function display_line_item(
84
+		EE_Line_Item $line_item,
85
+		$options = array(),
86
+		EE_Line_Item $parent_line_item = null
87
+	) {
88
+		$html = '';
89
+		// set some default options and merge with incoming
90
+		$default_options = array(
91
+			'show_desc' => true,  // 	true 		false
92
+			'odd'       => false,
93
+		);
94
+		$options = array_merge($default_options, (array)$options);
95
+		switch ($line_item->type()) {
96
+			case EEM_Line_Item::type_line_item:
97
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
+				if ($line_item->OBJ_type() === 'Ticket') {
99
+					// item row
100
+					$html .= $this->_ticket_row($line_item, $options);
101
+				} else {
102
+					// item row
103
+					$html .= $this->_item_row($line_item, $options);
104
+				}
105
+				if (
106
+				apply_filters(
107
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
+					true
109
+				)
110
+				) {
111
+					// got any kids?
112
+					foreach ($line_item->children() as $child_line_item) {
113
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
114
+					}
115
+				}
116
+				break;
117
+			case EEM_Line_Item::type_sub_line_item:
118
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
+				break;
120
+			case EEM_Line_Item::type_sub_total:
121
+				static $sub_total = 0;
122
+				$event_sub_total = 0;
123
+				$text = esc_html__('Sub-Total', 'event_espresso');
124
+				if ($line_item->OBJ_type() === 'Event') {
125
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
126
+					if (! isset($this->_events[$options['event_id']])) {
127
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
+						// if event has default reg status of Not Approved, then don't display info on it
129
+						if (
130
+							$event instanceof EE_Event
131
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
+						) {
133
+							$display_event = false;
134
+							// unless there are registrations for it that are returning to pay
135
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
136
+								foreach ($options['registrations'] as $registration) {
137
+									if (! $registration instanceof EE_Registration) {
138
+										continue;
139
+									}
140
+									$display_event = $registration->event_ID() === $options['event_id']
141
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
+										? true
143
+										: $display_event;
144
+								}
145
+							}
146
+							if (! $display_event) {
147
+								return '';
148
+							}
149
+						}
150
+						$this->_events[$options['event_id']] = 0;
151
+						$html .= $this->_event_row($line_item);
152
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
153
+					}
154
+				}
155
+				$child_line_items = $line_item->children();
156
+				// loop thru children
157
+				foreach ($child_line_items as $child_line_item) {
158
+					// recursively feed children back into this method
159
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
160
+				}
161
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
+				$sub_total += $event_sub_total;
163
+				if (
164
+					(
165
+						// event subtotals
166
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
+					)
168
+					|| (
169
+						// pre-tax subtotals
170
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
+					)
172
+				) {
173
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
+					$html .= $this->_sub_total_row($line_item, $text, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax:
178
+				if ($this->_show_taxes) {
179
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
180
+				}
181
+				break;
182
+			case EEM_Line_Item::type_tax_sub_total:
183
+				if ($this->_show_taxes) {
184
+					$child_line_items = $line_item->children();
185
+					// loop thru children
186
+					foreach ($child_line_items as $child_line_item) {
187
+						// recursively feed children back into this method
188
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
189
+					}
190
+					if (count($child_line_items) > 1) {
191
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
+					}
193
+				}
194
+				break;
195
+			case EEM_Line_Item::type_total:
196
+				// get all child line items
197
+				$children = $line_item->children();
198
+				// loop thru all non-tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				// now loop thru  tax child line items
206
+				foreach ($children as $child_line_item) {
207
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
+						// recursively feed children back into this method
209
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
210
+					}
211
+				}
212
+				$html .= $this->_taxes_html;
213
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
+				break;
216
+		}
217
+		return $html;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
224
+	 *
225
+	 * @param EE_Line_Item $line_item
226
+	 * @return mixed
227
+	 */
228
+	private function _event_row(EE_Line_Item $line_item)
229
+	{
230
+		// start of row
231
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
+		// event name td
233
+		$html .= EEH_HTML::td(
234
+			EEH_HTML::strong($line_item->name()),
235
+			'',
236
+			'event-header',
237
+			'',
238
+			' colspan="4"'
239
+		);
240
+		// end of row
241
+		$html .= EEH_HTML::trx();
242
+		return $html;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * _ticket_row
249
+	 *
250
+	 * @param EE_Line_Item $line_item
251
+	 * @param array        $options
252
+	 * @return mixed
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
+	{
257
+		// start of row
258
+		$row_class = $options['odd'] ? 'item odd' : 'item';
259
+		$html = EEH_HTML::tr('', '', $row_class);
260
+		// name && desc
261
+		$name_and_desc = apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
+			$line_item->name(),
264
+			$line_item
265
+		);
266
+		$name_and_desc .= apply_filters(
267
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
+			(
269
+				$options['show_desc']
270
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
+					: ''
272
+			),
273
+			$line_item,
274
+			$options
275
+		);
276
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
+		// name td
278
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
+			$name_and_desc, '', 'item_l');
280
+		// price td
281
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
+		// quantity td
283
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
+		$this->_total_items += $line_item->quantity();
285
+		// determine total for line item
286
+		$total = $line_item->total();
287
+		$this->_events[$options['event_id']] += $total;
288
+		// total td
289
+		$html .= EEH_HTML::td(
290
+			EEH_Template::format_currency($total, false, false),
291
+			'',
292
+			'item_r jst-rght'
293
+		);
294
+		// end of row
295
+		$html .= EEH_HTML::trx();
296
+		return $html;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * _item_row
303
+	 *
304
+	 * @param EE_Line_Item $line_item
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	private function _item_row(EE_Line_Item $line_item, $options = array())
310
+	{
311
+		// start of row
312
+		$row_class = $options['odd'] ? 'item odd' : 'item';
313
+		$html = EEH_HTML::tr('', '', $row_class);
314
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
+		// name && desc
316
+		$name_and_desc = apply_filters(
317
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
+			$obj_name . $line_item->name(),
319
+			$line_item
320
+		);
321
+		$name_and_desc .= apply_filters(
322
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
+			(
324
+				$options['show_desc']
325
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
+				: ''
327
+			),
328
+			$line_item,
329
+			$options
330
+		);
331
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
+		// name td
333
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
+		// price td
335
+		if ($line_item->is_percent()) {
336
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
+		} else {
338
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
+		}
340
+		// quantity td
341
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
+		//$total = $line_item->total() * $line_item->quantity();
343
+		$total = $line_item->total();
344
+		if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
+			$this->_events[$options['event_id']] += $total;
346
+		}
347
+		// total td
348
+		$html .= EEH_HTML::td(
349
+			EEH_Template::format_currency($total, false, false),
350
+			'',
351
+			'item_r jst-rght'
352
+		);
353
+		// end of row
354
+		$html .= EEH_HTML::trx();
355
+		return $html;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * _sub_item_row
362
+	 *
363
+	 * @param EE_Line_Item $line_item
364
+	 * @param array        $options
365
+	 * @param EE_Line_Item $parent_line_item
366
+	 * @return mixed
367
+	 * @throws EE_Error
368
+	 */
369
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
+	{
371
+		// start of row
372
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
373
+		// name && desc
374
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
+						 . $line_item->name();
376
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
+												  . $line_item->desc()
378
+												  . '</span>' : '';
379
+		// name td
380
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
+		// discount/surcharge td
383
+		if ($line_item->is_percent()) {
384
+			$html .= EEH_HTML::td(
385
+				EEH_Template::format_currency(
386
+					$line_item->total() / $qty,
387
+					false, false
388
+				),
389
+				'', 'item_c jst-rght'
390
+			);
391
+		} else {
392
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
+		}
394
+		// no quantity td
395
+		$html .= EEH_HTML::td();
396
+		// no total td
397
+		$html .= EEH_HTML::td();
398
+		// end of row
399
+		$html .= EEH_HTML::trx();
400
+		return $html;
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * _tax_row
407
+	 *
408
+	 * @param EE_Line_Item $line_item
409
+	 * @param array        $options
410
+	 * @return mixed
411
+	 * @throws EE_Error
412
+	 */
413
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
414
+	{
415
+		// start of row
416
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
417
+		// name && desc
418
+		$name_and_desc = $line_item->name();
419
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
+		// name td
423
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
+			$name_and_desc, '', 'item_l sub-item');
425
+		// percent td
426
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
+		// empty td (price)
428
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
429
+		// total td
430
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
431
+			$line_item->total(), false, false),
432
+			'',
433
+			'item_r jst-rght'
434
+		);
435
+		// end of row
436
+		$html .= EEH_HTML::trx();
437
+		return $html;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * _total_row
444
+	 *
445
+	 * @param EE_Line_Item $line_item
446
+	 * @param string       $text
447
+	 * @return mixed
448
+	 * @throws EE_Error
449
+	 */
450
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
+	{
452
+		$html = '';
453
+		if ($line_item->total()) {
454
+			// start of row
455
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
456
+			// total td
457
+			$html .= EEH_HTML::td(
458
+				$text,
459
+				'',
460
+				'total_currency total jst-rght',
461
+				'',
462
+				' colspan="2"'
463
+			);
464
+			// empty td (price)
465
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
466
+			// total td
467
+			$html .= EEH_HTML::td(
468
+				EEH_Template::format_currency($line_item->total(), false, false),
469
+				'',
470
+				'total jst-rght'
471
+			);
472
+			// end of row
473
+			$html .= EEH_HTML::trx();
474
+		}
475
+		return $html;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * _total_row
482
+	 *
483
+	 * @param EE_Line_Item $line_item
484
+	 * @param string       $text
485
+	 * @param array        $options
486
+	 * @return mixed
487
+	 * @throws EE_Error
488
+	 */
489
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
+	{
491
+		$html = '';
492
+		if ($line_item->total()) {
493
+			// start of row
494
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
495
+			// total td
496
+			$html .= EEH_HTML::td(
497
+				$text,
498
+				'',
499
+				'total_currency total jst-rght',
500
+				'',
501
+				' colspan="3"'
502
+			);
503
+			// total td
504
+			$html .= EEH_HTML::td(
505
+				EEH_Template::format_currency($options['sub_total'], false, false),
506
+				'',
507
+				'total jst-rght'
508
+			);
509
+			// end of row
510
+			$html .= EEH_HTML::trx();
511
+		}
512
+		return $html;
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * _total_row
519
+	 *
520
+	 * @param EE_Line_Item $line_item
521
+	 * @param string       $text
522
+	 * @return mixed
523
+	 * @throws EE_Error
524
+	 */
525
+	private function _total_row(EE_Line_Item $line_item, $text = '')
526
+	{
527
+		// start of row
528
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
+		// total td
530
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
+		// total td
532
+		$html .= EEH_HTML::td(
533
+			EEH_Template::format_currency($line_item->total(), false, false),
534
+			'',
535
+			'total jst-rght'
536
+		);
537
+		// end of row
538
+		$html .= EEH_HTML::trx();
539
+		return $html;
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * _payments_and_amount_owing_rows
546
+	 *
547
+	 * @param EE_Line_Item $line_item
548
+	 * @param array        $options
549
+	 * @return mixed
550
+	 * @throws EE_Error
551
+	 */
552
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
+	{
554
+		$html = '';
555
+		$owing = $line_item->total();
556
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
+		if ($transaction instanceof EE_Transaction) {
558
+			$registration_payments = array();
559
+			$registrations = ! empty($options['registrations'])
560
+				? $options['registrations']
561
+				: $transaction->registrations();
562
+			foreach ($registrations as $registration) {
563
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
+					$registration_payments += $registration->registration_payments();
565
+				}
566
+			}
567
+			if (! empty($registration_payments)) {
568
+				foreach ($registration_payments as $registration_payment) {
569
+					if ($registration_payment instanceof EE_Registration_Payment) {
570
+						$owing -= $registration_payment->amount();
571
+						$payment = $registration_payment->payment();
572
+						$payment_desc = '';
573
+						if ($payment instanceof EE_Payment) {
574
+							$payment_desc = sprintf(
575
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
+								$payment->txn_id_chq_nmbr() !== ''
577
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
+									: '',
579
+								$payment->timestamp()
580
+							);
581
+						}
582
+						// start of row
583
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
584
+						// payment desc
585
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
+						// total td
587
+						$html .= EEH_HTML::td(
588
+							EEH_Template::format_currency(
589
+								$registration_payment->amount(),
590
+								false,
591
+								false
592
+							),
593
+							'',
594
+							'total jst-rght'
595
+						);
596
+						// end of row
597
+						$html .= EEH_HTML::trx();
598
+					}
599
+				}
600
+				if ($line_item->total()) {
601
+					// start of row
602
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
603
+					// total td
604
+					$html .= EEH_HTML::td(
605
+						esc_html__('Amount Owing', 'event_espresso'),
606
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
607
+					);
608
+					// total td
609
+					$html .= EEH_HTML::td(
610
+						EEH_Template::format_currency($owing, false, false),
611
+						'',
612
+						'total jst-rght'
613
+					);
614
+					// end of row
615
+					$html .= EEH_HTML::trx();
616
+				}
617
+			}
618
+		}
619
+		$this->_grand_total = $owing;
620
+		return $html;
621
+	}
622 622
 
623 623
 
624 624
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         $html = '';
89 89
         // set some default options and merge with incoming
90 90
         $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
91
+            'show_desc' => true, // 	true 		false
92 92
             'odd'       => false,
93 93
         );
94
-        $options = array_merge($default_options, (array)$options);
94
+        $options = array_merge($default_options, (array) $options);
95 95
         switch ($line_item->type()) {
96 96
             case EEM_Line_Item::type_line_item:
97 97
                 $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $text = esc_html__('Sub-Total', 'event_espresso');
124 124
                 if ($line_item->OBJ_type() === 'Event') {
125 125
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
126
+                    if ( ! isset($this->_events[$options['event_id']])) {
127 127
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128 128
                         // if event has default reg status of Not Approved, then don't display info on it
129 129
                         if (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             // unless there are registrations for it that are returning to pay
135 135
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
136 136
                                 foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
137
+                                    if ( ! $registration instanceof EE_Registration) {
138 138
                                         continue;
139 139
                                     }
140 140
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                         : $display_event;
144 144
                                 }
145 145
                             }
146
-                            if (! $display_event) {
146
+                            if ( ! $display_event) {
147 147
                                 return '';
148 148
                             }
149 149
                         }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268 268
             (
269 269
                 $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
270
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
271 271
                     : ''
272 272
             ),
273 273
             $line_item,
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         // start of row
312 312
         $row_class = $options['odd'] ? 'item odd' : 'item';
313 313
         $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
314
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
315 315
         // name && desc
316 316
         $name_and_desc = apply_filters(
317 317
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
318
+            $obj_name.$line_item->name(),
319 319
             $line_item
320 320
         );
321 321
         $name_and_desc .= apply_filters(
322 322
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323 323
             (
324 324
                 $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
325
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
326 326
                 : ''
327 327
             ),
328 328
             $line_item,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334 334
         // price td
335 335
         if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
336
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
337 337
         } else {
338 338
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339 339
         }
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
                                                   . $line_item->desc()
378 378
                                                   . '</span>' : '';
379 379
         // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
380
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
381 381
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382 382
         // discount/surcharge td
383 383
         if ($line_item->is_percent()) {
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
         // name && desc
418 418
         $name_and_desc = $line_item->name();
419 419
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
420
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
421
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
422 422
         // name td
423 423
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424 424
             $name_and_desc, '', 'item_l sub-item');
425 425
         // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
426
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
427 427
         // empty td (price)
428 428
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
429 429
         // total td
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                     $registration_payments += $registration->registration_payments();
565 565
                 }
566 566
             }
567
-            if (! empty($registration_payments)) {
567
+            if ( ! empty($registration_payments)) {
568 568
                 foreach ($registration_payments as $registration_payment) {
569 569
                     if ($registration_payment instanceof EE_Registration_Payment) {
570 570
                         $owing -= $registration_payment->amount();
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
                             $payment_desc = sprintf(
575 575
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576 576
                                 $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
577
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
578 578
                                     : '',
579 579
                                 $payment->timestamp()
580 580
                             );
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Non_Zero_Line_Item_Filter.class.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -19,102 +19,102 @@  discard block
 block discarded – undo
19 19
 class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base
20 20
 {
21 21
 
22
-    /**
23
-     * EE_Non_Zero_Line_Item_Filter constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-    }
28
-
29
-
30
-
31
-    /**
32
-     * Creates a duplicate of the line item tree, except only includes billable items
33
-     * and the portion of line items attributed to billable things
34
-     *
35
-     * @param EEI_Line_Item $line_item
36
-     * @return EEI_Line_Item
37
-     */
38
-    public function process(EEI_Line_Item $line_item)
39
-    {
40
-        $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
-            return null;
43
-        }
44
-        //if this is an event subtotal, we want to only include it if it
45
-        //has a non-zero total and at least one ticket line item child
46
-        if ($line_item->children()) {
47
-            $ticket_or_subtotals_with_tkt_children_count = 0;
48
-            foreach ($line_item->children() as $child_line_item) {
49
-                $code = $child_line_item->code();
50
-                $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
52
-                    $line_item->delete_child_line_item($code);
53
-                    continue;
54
-                }
55
-                if (
56
-                    (
57
-                        $child_line_item instanceof EEI_Line_Item
58
-                        && $child_line_item->type() === EEM_Line_Item::type_sub_total
59
-                    )
60
-                    || (
61
-                        $child_line_item instanceof EEI_Line_Item
62
-                        && $child_line_item->type() === EEM_Line_Item::type_line_item
63
-                        && $child_line_item->OBJ_type() === 'Ticket'
64
-                    )
65
-                ) {
66
-                    $ticket_or_subtotals_with_tkt_children_count++;
67
-                }
68
-            }
69
-            // if this is an event subtotal with NO ticket children
70
-            // we basically want to ignore it
71
-            return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
-                $ticket_or_subtotals_with_tkt_children_count);
73
-        }
74
-        return $non_zero_line_item;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Creates a new, unsaved line item, but if it's a ticket line item
81
-     * with a total of 0, or a subtotal of 0, returns null instead
82
-     *
83
-     * @param EEI_Line_Item $line_item
84
-     * @return EEI_Line_Item
85
-     */
86
-    protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
-    {
88
-        if (
89
-            $line_item->type() === EEM_Line_Item::type_line_item
90
-            && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
92
-        ) {
93
-            return null;
94
-        }
95
-        return $line_item;
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Creates a new, unsaved line item, but if it's a ticket line item
102
-     * with a total of 0, or a subtotal of 0, returns null instead
103
-     *
104
-     * @param EEI_Line_Item $line_item
105
-     * @param int           $ticket_children
106
-     * @return EEI_Line_Item
107
-     */
108
-    protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
-    {
110
-        if (
111
-            (int)$ticket_children === 0
112
-            && $line_item->type() === EEM_Line_Item::type_sub_total
113
-        ) {
114
-            return null;
115
-        }
116
-        return $line_item;
117
-    }
22
+	/**
23
+	 * EE_Non_Zero_Line_Item_Filter constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+	}
28
+
29
+
30
+
31
+	/**
32
+	 * Creates a duplicate of the line item tree, except only includes billable items
33
+	 * and the portion of line items attributed to billable things
34
+	 *
35
+	 * @param EEI_Line_Item $line_item
36
+	 * @return EEI_Line_Item
37
+	 */
38
+	public function process(EEI_Line_Item $line_item)
39
+	{
40
+		$non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
+		if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
+			return null;
43
+		}
44
+		//if this is an event subtotal, we want to only include it if it
45
+		//has a non-zero total and at least one ticket line item child
46
+		if ($line_item->children()) {
47
+			$ticket_or_subtotals_with_tkt_children_count = 0;
48
+			foreach ($line_item->children() as $child_line_item) {
49
+				$code = $child_line_item->code();
50
+				$child_line_item = $this->process($child_line_item);
51
+				if (! $child_line_item instanceof EEI_Line_Item) {
52
+					$line_item->delete_child_line_item($code);
53
+					continue;
54
+				}
55
+				if (
56
+					(
57
+						$child_line_item instanceof EEI_Line_Item
58
+						&& $child_line_item->type() === EEM_Line_Item::type_sub_total
59
+					)
60
+					|| (
61
+						$child_line_item instanceof EEI_Line_Item
62
+						&& $child_line_item->type() === EEM_Line_Item::type_line_item
63
+						&& $child_line_item->OBJ_type() === 'Ticket'
64
+					)
65
+				) {
66
+					$ticket_or_subtotals_with_tkt_children_count++;
67
+				}
68
+			}
69
+			// if this is an event subtotal with NO ticket children
70
+			// we basically want to ignore it
71
+			return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
+				$ticket_or_subtotals_with_tkt_children_count);
73
+		}
74
+		return $non_zero_line_item;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Creates a new, unsaved line item, but if it's a ticket line item
81
+	 * with a total of 0, or a subtotal of 0, returns null instead
82
+	 *
83
+	 * @param EEI_Line_Item $line_item
84
+	 * @return EEI_Line_Item
85
+	 */
86
+	protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
+	{
88
+		if (
89
+			$line_item->type() === EEM_Line_Item::type_line_item
90
+			&& $line_item->OBJ_type() === 'Ticket'
91
+			&& (int)$line_item->quantity() === 0
92
+		) {
93
+			return null;
94
+		}
95
+		return $line_item;
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Creates a new, unsaved line item, but if it's a ticket line item
102
+	 * with a total of 0, or a subtotal of 0, returns null instead
103
+	 *
104
+	 * @param EEI_Line_Item $line_item
105
+	 * @param int           $ticket_children
106
+	 * @return EEI_Line_Item
107
+	 */
108
+	protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
+	{
110
+		if (
111
+			(int)$ticket_children === 0
112
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
113
+		) {
114
+			return null;
115
+		}
116
+		return $line_item;
117
+	}
118 118
 
119 119
 
120 120
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public function process(EEI_Line_Item $line_item)
39 39
     {
40 40
         $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
41
+        if ( ! $non_zero_line_item instanceof EEI_Line_Item) {
42 42
             return null;
43 43
         }
44 44
         //if this is an event subtotal, we want to only include it if it
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             foreach ($line_item->children() as $child_line_item) {
49 49
                 $code = $child_line_item->code();
50 50
                 $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
51
+                if ( ! $child_line_item instanceof EEI_Line_Item) {
52 52
                     $line_item->delete_child_line_item($code);
53 53
                     continue;
54 54
                 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if (
89 89
             $line_item->type() === EEM_Line_Item::type_line_item
90 90
             && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
91
+            && (int) $line_item->quantity() === 0
92 92
         ) {
93 93
             return null;
94 94
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109 109
     {
110 110
         if (
111
-            (int)$ticket_children === 0
111
+            (int) $ticket_children === 0
112 112
             && $line_item->type() === EEM_Line_Item::type_sub_total
113 113
         ) {
114 114
             return null;
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
19 19
 {
20 20
 
21
-    /**
22
-     * array of line item codes and their corresponding quantities for registrations
23
-     *
24
-     * @type array $_line_item_registrations
25
-     */
26
-    protected $_line_item_registrations = array();
27
-
28
-    /**
29
-     * Just kept in case we want it someday. Currently unused
30
-     *
31
-     * @var EE_Registration[]
32
-     */
33
-    protected $_registrations = array();
34
-
35
-    /**
36
-     * @var EE_Registration
37
-     */
38
-    protected $_current_registration;
39
-
40
-    /**
41
-     * these reg statuses should NOT increment the line item quantity
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_closed_reg_statuses = array();
46
-
47
-
48
-
49
-    /**
50
-     * EE_Billable_Line_Item_Filter constructor.
51
-     *
52
-     * @param EE_Registration[] $registrations
53
-     * @throws EE_Error
54
-     */
55
-    public function __construct($registrations)
56
-    {
57
-        $this->_registrations = $registrations;
58
-        $this->_calculate_registrations_per_line_item_code($registrations);
59
-        // these reg statuses should NOT increment the line item quantity
60
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * sets the _line_item_registrations from the provided registrations
67
-     *
68
-     * @param EE_Registration[] $registrations
69
-     * @return void
70
-     * @throws EE_Error
71
-     */
72
-    protected function _calculate_registrations_per_line_item_code($registrations)
73
-    {
74
-        foreach ($registrations as $registration) {
75
-            $line_item_code = EEM_Line_Item::instance()->get_var(
76
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
-                    $registration,
78
-                    array('limit' => 1)
79
-                ),
80
-                'LIN_code'
81
-            );
82
-            if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
84
-                    $this->_line_item_registrations[$line_item_code] = array();
85
-                }
86
-                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Creates a duplicate of the line item tree, except only includes billable items
95
-     * and the portion of line items attributed to billable things
96
-     *
97
-     * @param EEI_Line_Item $line_item
98
-     * @return EEI_Line_Item
99
-     * @throws EE_Error
100
-     */
101
-    public function process(EEI_Line_Item $line_item)
102
-    {
103
-        $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
105
-            return $line_item;
106
-        }
107
-        //the original running total (taking ALL tickets into account)
108
-        $running_total_of_children = 0;
109
-        //the new running total (only taking the specified ticket quantities into account)
110
-        $running_total_of_children_under_consideration = 0;
111
-        // let's also track the quantity of tickets that pertain to the registrations
112
-        $total_child_ticket_quantity = 0;
113
-        foreach ($line_item->children() as $child_line_item) {
114
-            $original_li_total = $child_line_item->is_percent()
115
-                ? $running_total_of_children * $child_line_item->percent() / 100
116
-                : $child_line_item->unit_price() * $child_line_item->quantity();
117
-            $this->process($child_line_item);
118
-            // If this line item is a normal line item that isn't for a ticket,
119
-            // we want to modify its total (and unit price if not a percentage line item)
120
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
121
-            if (
122
-                $child_line_item->type() === EEM_Line_Item::type_line_item
123
-                && $child_line_item->OBJ_type() !== 'Ticket'
124
-            ) {
125
-                $percent_of_running_total = $running_total_of_children
126
-                    ? $original_li_total / $running_total_of_children
127
-                    : 0;
128
-                $child_line_item->set_total(
129
-                    $running_total_of_children_under_consideration * $percent_of_running_total
130
-                );
131
-                if (! $child_line_item->is_percent()) {
132
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
-                }
134
-            } else if (
135
-                //make sure this item's quantity and total matches its parent
136
-                $line_item->type() === EEM_Line_Item::type_line_item
137
-                && $line_item->OBJ_type() === 'Ticket'
138
-                // but not if it's a percentage modifier
139
-                && ! $child_line_item->is_percent()
140
-                && ! (
141
-                    // or a cancellation
142
-                    $child_line_item->is_cancelled()
143
-                    && ! (
144
-                        // unless it IS a cancellation and the current registration is cancelled
145
-                        $child_line_item->is_cancelled()
146
-                        && $this->_current_registration instanceof EE_Registration
147
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
-                    )
149
-                )
150
-            ) {
151
-                $child_line_item->set_quantity($line_item->quantity());
152
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
-            }
154
-            $running_total_of_children += $original_li_total;
155
-            $running_total_of_children_under_consideration += $child_line_item->total();
156
-            if ($child_line_item->OBJ_type() === 'Ticket') {
157
-                $total_child_ticket_quantity += $child_line_item->quantity();
158
-            }
159
-        }
160
-        $line_item->set_total($running_total_of_children_under_consideration);
161
-        if ($line_item->quantity()) {
162
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
-        } else {
164
-            $line_item->set_unit_price(0);
165
-        }
166
-        if ($line_item->OBJ_type() === 'Event') {
167
-            $line_item->set_quantity($total_child_ticket_quantity);
168
-        }
169
-        return $line_item;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Adjusts quantities for line items for tickets according to the registrations provided
176
-     * in the constructor
177
-     *
178
-     * @param EEI_Line_Item $line_item
179
-     * @return EEI_Line_Item
180
-     */
181
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
-    {
183
-        // is this a ticket ?
184
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
-            $this->_current_registration = null;
186
-            $quantity = 0;
187
-            // if this ticket is billable at this moment, then we should have a positive quantity
188
-            if (
189
-                isset($this->_line_item_registrations[$line_item->code()])
190
-                && is_array($this->_line_item_registrations[$line_item->code()])
191
-            ) {
192
-                // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
-                    if (
195
-                        $registration instanceof EE_Registration
196
-                    ) {
197
-                        $quantity++;
198
-                        $this->_current_registration = $registration;
199
-                    }
200
-                }
201
-            }
202
-            $line_item->set_quantity($quantity);
203
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
-        }
205
-        return $line_item;
206
-    }
21
+	/**
22
+	 * array of line item codes and their corresponding quantities for registrations
23
+	 *
24
+	 * @type array $_line_item_registrations
25
+	 */
26
+	protected $_line_item_registrations = array();
27
+
28
+	/**
29
+	 * Just kept in case we want it someday. Currently unused
30
+	 *
31
+	 * @var EE_Registration[]
32
+	 */
33
+	protected $_registrations = array();
34
+
35
+	/**
36
+	 * @var EE_Registration
37
+	 */
38
+	protected $_current_registration;
39
+
40
+	/**
41
+	 * these reg statuses should NOT increment the line item quantity
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_closed_reg_statuses = array();
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Billable_Line_Item_Filter constructor.
51
+	 *
52
+	 * @param EE_Registration[] $registrations
53
+	 * @throws EE_Error
54
+	 */
55
+	public function __construct($registrations)
56
+	{
57
+		$this->_registrations = $registrations;
58
+		$this->_calculate_registrations_per_line_item_code($registrations);
59
+		// these reg statuses should NOT increment the line item quantity
60
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * sets the _line_item_registrations from the provided registrations
67
+	 *
68
+	 * @param EE_Registration[] $registrations
69
+	 * @return void
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function _calculate_registrations_per_line_item_code($registrations)
73
+	{
74
+		foreach ($registrations as $registration) {
75
+			$line_item_code = EEM_Line_Item::instance()->get_var(
76
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
+					$registration,
78
+					array('limit' => 1)
79
+				),
80
+				'LIN_code'
81
+			);
82
+			if ($line_item_code) {
83
+				if (! isset($this->_line_item_registrations[$line_item_code])) {
84
+					$this->_line_item_registrations[$line_item_code] = array();
85
+				}
86
+				$this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Creates a duplicate of the line item tree, except only includes billable items
95
+	 * and the portion of line items attributed to billable things
96
+	 *
97
+	 * @param EEI_Line_Item $line_item
98
+	 * @return EEI_Line_Item
99
+	 * @throws EE_Error
100
+	 */
101
+	public function process(EEI_Line_Item $line_item)
102
+	{
103
+		$this->_adjust_line_item_quantity($line_item);
104
+		if (! $line_item->children()) {
105
+			return $line_item;
106
+		}
107
+		//the original running total (taking ALL tickets into account)
108
+		$running_total_of_children = 0;
109
+		//the new running total (only taking the specified ticket quantities into account)
110
+		$running_total_of_children_under_consideration = 0;
111
+		// let's also track the quantity of tickets that pertain to the registrations
112
+		$total_child_ticket_quantity = 0;
113
+		foreach ($line_item->children() as $child_line_item) {
114
+			$original_li_total = $child_line_item->is_percent()
115
+				? $running_total_of_children * $child_line_item->percent() / 100
116
+				: $child_line_item->unit_price() * $child_line_item->quantity();
117
+			$this->process($child_line_item);
118
+			// If this line item is a normal line item that isn't for a ticket,
119
+			// we want to modify its total (and unit price if not a percentage line item)
120
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
121
+			if (
122
+				$child_line_item->type() === EEM_Line_Item::type_line_item
123
+				&& $child_line_item->OBJ_type() !== 'Ticket'
124
+			) {
125
+				$percent_of_running_total = $running_total_of_children
126
+					? $original_li_total / $running_total_of_children
127
+					: 0;
128
+				$child_line_item->set_total(
129
+					$running_total_of_children_under_consideration * $percent_of_running_total
130
+				);
131
+				if (! $child_line_item->is_percent()) {
132
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
+				}
134
+			} else if (
135
+				//make sure this item's quantity and total matches its parent
136
+				$line_item->type() === EEM_Line_Item::type_line_item
137
+				&& $line_item->OBJ_type() === 'Ticket'
138
+				// but not if it's a percentage modifier
139
+				&& ! $child_line_item->is_percent()
140
+				&& ! (
141
+					// or a cancellation
142
+					$child_line_item->is_cancelled()
143
+					&& ! (
144
+						// unless it IS a cancellation and the current registration is cancelled
145
+						$child_line_item->is_cancelled()
146
+						&& $this->_current_registration instanceof EE_Registration
147
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
+					)
149
+				)
150
+			) {
151
+				$child_line_item->set_quantity($line_item->quantity());
152
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
+			}
154
+			$running_total_of_children += $original_li_total;
155
+			$running_total_of_children_under_consideration += $child_line_item->total();
156
+			if ($child_line_item->OBJ_type() === 'Ticket') {
157
+				$total_child_ticket_quantity += $child_line_item->quantity();
158
+			}
159
+		}
160
+		$line_item->set_total($running_total_of_children_under_consideration);
161
+		if ($line_item->quantity()) {
162
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
+		} else {
164
+			$line_item->set_unit_price(0);
165
+		}
166
+		if ($line_item->OBJ_type() === 'Event') {
167
+			$line_item->set_quantity($total_child_ticket_quantity);
168
+		}
169
+		return $line_item;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Adjusts quantities for line items for tickets according to the registrations provided
176
+	 * in the constructor
177
+	 *
178
+	 * @param EEI_Line_Item $line_item
179
+	 * @return EEI_Line_Item
180
+	 */
181
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
+	{
183
+		// is this a ticket ?
184
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
+			$this->_current_registration = null;
186
+			$quantity = 0;
187
+			// if this ticket is billable at this moment, then we should have a positive quantity
188
+			if (
189
+				isset($this->_line_item_registrations[$line_item->code()])
190
+				&& is_array($this->_line_item_registrations[$line_item->code()])
191
+			) {
192
+				// set quantity based on number of open registrations for this ticket
193
+				foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
+					if (
195
+						$registration instanceof EE_Registration
196
+					) {
197
+						$quantity++;
198
+						$this->_current_registration = $registration;
199
+					}
200
+				}
201
+			}
202
+			$line_item->set_quantity($quantity);
203
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
+		}
205
+		return $line_item;
206
+	}
207 207
 
208 208
 
209 209
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                 'LIN_code'
81 81
             );
82 82
             if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
83
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
84 84
                     $this->_line_item_registrations[$line_item_code] = array();
85 85
                 }
86 86
                 $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function process(EEI_Line_Item $line_item)
102 102
     {
103 103
         $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
104
+        if ( ! $line_item->children()) {
105 105
             return $line_item;
106 106
         }
107 107
         //the original running total (taking ALL tickets into account)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 $child_line_item->set_total(
129 129
                     $running_total_of_children_under_consideration * $percent_of_running_total
130 130
                 );
131
-                if (! $child_line_item->is_percent()) {
131
+                if ( ! $child_line_item->is_percent()) {
132 132
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133 133
                 }
134 134
             } else if (
Please login to merge, or discard this patch.
core/EE_Error.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     /**
74 74
      *    error_handler
75 75
      *
76
-     * @param $code
76
+     * @param integer $code
77 77
      * @param $message
78 78
      * @param $file
79 79
      * @param $line
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     /**
178 178
      * _format_error
179 179
      *
180
-     * @param $code
180
+     * @param string $code
181 181
      * @param $message
182 182
      * @param $file
183 183
      * @param $line
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
 
212 212
     /**
213
-     * @return void
213
+     * @return string|null
214 214
      * @throws EE_Error
215 215
      * @throws ReflectionException
216 216
      */
Please login to merge, or discard this patch.
Indentation   +1086 added lines, -1086 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 // if you're a dev and want to receive all errors via email
6 6
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
7 7
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
8
-    set_error_handler(array('EE_Error', 'error_handler'));
9
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
8
+	set_error_handler(array('EE_Error', 'error_handler'));
9
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
10 10
 }
11 11
 
12 12
 
@@ -23,259 +23,259 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     *    name of the file to log exceptions to
28
-     *
29
-     * @var string
30
-     */
31
-    private static $_exception_log_file = 'espresso_error_log.txt';
32
-
33
-    /**
34
-     *    stores details for all exception
35
-     *
36
-     * @var array
37
-     */
38
-    private static $_all_exceptions = array();
39
-
40
-    /**
41
-     *    tracks number of errors
42
-     *
43
-     * @var int
44
-     */
45
-    private static $_error_count = 0;
46
-
47
-    /**
48
-     *    has shutdown action been added ?
49
-     *
50
-     * @var array $_espresso_notices
51
-     */
52
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
-
54
-
55
-
56
-    /**
57
-     * @override default exception handling
58
-     * @param string         $message
59
-     * @param int            $code
60
-     * @param Exception|null $previous
61
-     */
62
-    public function __construct($message, $code = 0, Exception $previous = null)
63
-    {
64
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
-            parent::__construct($message, $code);
66
-        } else {
67
-            parent::__construct($message, $code, $previous);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    error_handler
75
-     *
76
-     * @param $code
77
-     * @param $message
78
-     * @param $file
79
-     * @param $line
80
-     * @return void
81
-     */
82
-    public static function error_handler($code, $message, $file, $line)
83
-    {
84
-        $type = EE_Error::error_type($code);
85
-        $site = site_url();
86
-        switch ($site) {
87
-            case 'http://ee4.eventespresso.com/' :
88
-            case 'http://ee4decaf.eventespresso.com/' :
89
-            case 'http://ee4hf.eventespresso.com/' :
90
-            case 'http://ee4a.eventespresso.com/' :
91
-            case 'http://ee4ad.eventespresso.com/' :
92
-            case 'http://ee4b.eventespresso.com/' :
93
-            case 'http://ee4bd.eventespresso.com/' :
94
-            case 'http://ee4d.eventespresso.com/' :
95
-            case 'http://ee4dd.eventespresso.com/' :
96
-                $to = '[email protected]';
97
-                break;
98
-            default :
99
-                $to = get_option('admin_email');
100
-        }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
103
-        if (function_exists('wp_mail')) {
104
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
-            wp_mail($to, $subject, $msg);
106
-        }
107
-        echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
-        echo '<br /></p></div>';
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     *    fatal_error_handler
164
-     *
165
-     * @return void
166
-     */
167
-    public static function fatal_error_handler()
168
-    {
169
-        $last_error = error_get_last();
170
-        if ($last_error['type'] === E_ERROR) {
171
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
-        }
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
-    /**
200
-     * set_content_type
201
-     *
202
-     * @param $content_type
203
-     * @return string
204
-     */
205
-    public static function set_content_type($content_type)
206
-    {
207
-        return 'text/html';
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @return void
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function get_error()
218
-    {
219
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
-            throw $this;
221
-        }
222
-        // get separate user and developer messages if they exist
223
-        $msg = explode('||', $this->getMessage());
224
-        $user_msg = $msg[0];
225
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
227
-        // add details to _all_exceptions array
228
-        $x_time = time();
229
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
233
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
-        self::$_error_count++;
237
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
238
-        $this->display_errors();
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     *    has_error
245
-     *
246
-     * @param bool   $check_stored
247
-     * @param string $type_to_check
248
-     * @return bool
249
-     */
250
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
251
-    {
252
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
253
-                     && ! empty(self::$_espresso_notices[$type_to_check])
254
-            ? true
255
-            : false;
256
-        if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
258
-            foreach ($notices as $type => $notice) {
259
-                if ($type === $type_to_check && $notice) {
260
-                    return true;
261
-                }
262
-            }
263
-        }
264
-        return $has_error;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    display_errors
271
-     *
272
-     * @echo   string
273
-     * @throws \ReflectionException
274
-     */
275
-    public function display_errors()
276
-    {
277
-        $trace_details = '';
278
-        $output = '
26
+	/**
27
+	 *    name of the file to log exceptions to
28
+	 *
29
+	 * @var string
30
+	 */
31
+	private static $_exception_log_file = 'espresso_error_log.txt';
32
+
33
+	/**
34
+	 *    stores details for all exception
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private static $_all_exceptions = array();
39
+
40
+	/**
41
+	 *    tracks number of errors
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private static $_error_count = 0;
46
+
47
+	/**
48
+	 *    has shutdown action been added ?
49
+	 *
50
+	 * @var array $_espresso_notices
51
+	 */
52
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
+
54
+
55
+
56
+	/**
57
+	 * @override default exception handling
58
+	 * @param string         $message
59
+	 * @param int            $code
60
+	 * @param Exception|null $previous
61
+	 */
62
+	public function __construct($message, $code = 0, Exception $previous = null)
63
+	{
64
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
+			parent::__construct($message, $code);
66
+		} else {
67
+			parent::__construct($message, $code, $previous);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    error_handler
75
+	 *
76
+	 * @param $code
77
+	 * @param $message
78
+	 * @param $file
79
+	 * @param $line
80
+	 * @return void
81
+	 */
82
+	public static function error_handler($code, $message, $file, $line)
83
+	{
84
+		$type = EE_Error::error_type($code);
85
+		$site = site_url();
86
+		switch ($site) {
87
+			case 'http://ee4.eventespresso.com/' :
88
+			case 'http://ee4decaf.eventespresso.com/' :
89
+			case 'http://ee4hf.eventespresso.com/' :
90
+			case 'http://ee4a.eventespresso.com/' :
91
+			case 'http://ee4ad.eventespresso.com/' :
92
+			case 'http://ee4b.eventespresso.com/' :
93
+			case 'http://ee4bd.eventespresso.com/' :
94
+			case 'http://ee4d.eventespresso.com/' :
95
+			case 'http://ee4dd.eventespresso.com/' :
96
+				$to = '[email protected]';
97
+				break;
98
+			default :
99
+				$to = get_option('admin_email');
100
+		}
101
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
103
+		if (function_exists('wp_mail')) {
104
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
+			wp_mail($to, $subject, $msg);
106
+		}
107
+		echo '<div id="message" class="espresso-notices error"><p>';
108
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+		echo '<br /></p></div>';
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 *    fatal_error_handler
164
+	 *
165
+	 * @return void
166
+	 */
167
+	public static function fatal_error_handler()
168
+	{
169
+		$last_error = error_get_last();
170
+		if ($last_error['type'] === E_ERROR) {
171
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
+		}
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
+	/**
200
+	 * set_content_type
201
+	 *
202
+	 * @param $content_type
203
+	 * @return string
204
+	 */
205
+	public static function set_content_type($content_type)
206
+	{
207
+		return 'text/html';
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @return void
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function get_error()
218
+	{
219
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
+			throw $this;
221
+		}
222
+		// get separate user and developer messages if they exist
223
+		$msg = explode('||', $this->getMessage());
224
+		$user_msg = $msg[0];
225
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
227
+		// add details to _all_exceptions array
228
+		$x_time = time();
229
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
233
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
+		self::$_error_count++;
237
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
238
+		$this->display_errors();
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 *    has_error
245
+	 *
246
+	 * @param bool   $check_stored
247
+	 * @param string $type_to_check
248
+	 * @return bool
249
+	 */
250
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
251
+	{
252
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
253
+					 && ! empty(self::$_espresso_notices[$type_to_check])
254
+			? true
255
+			: false;
256
+		if ($check_stored && ! $has_error) {
257
+			$notices = (array)get_option('ee_notices', array());
258
+			foreach ($notices as $type => $notice) {
259
+				if ($type === $type_to_check && $notice) {
260
+					return true;
261
+				}
262
+			}
263
+		}
264
+		return $has_error;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    display_errors
271
+	 *
272
+	 * @echo   string
273
+	 * @throws \ReflectionException
274
+	 */
275
+	public function display_errors()
276
+	{
277
+		$trace_details = '';
278
+		$output = '
279 279
 <style type="text/css">
280 280
 	#ee-error-message {
281 281
 		max-width:90% !important;
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
335
-            $output .= '
334
+		if (! WP_DEBUG) {
335
+			$output .= '
336 336
 	<p>';
337
-        }
338
-        // cycle thru errors
339
-        foreach (self::$_all_exceptions as $time => $ex) {
340
-            $error_code = '';
341
-            // process trace info
342
-            if (empty($ex['trace'])) {
343
-                $trace_details .= __('Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso');
345
-            } else {
346
-                $trace_details .= '
337
+		}
338
+		// cycle thru errors
339
+		foreach (self::$_all_exceptions as $time => $ex) {
340
+			$error_code = '';
341
+			// process trace info
342
+			if (empty($ex['trace'])) {
343
+				$trace_details .= __('Sorry, but no trace information was available for this exception.',
344
+					'event_espresso');
345
+			} else {
346
+				$trace_details .= '
347 347
 			<div id="ee-trace-details">
348 348
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
349 349
 				<tr>
@@ -353,38 +353,38 @@  discard block
 block discarded – undo
353 353
 					<th scope="col" align="left">Class</th>
354 354
 					<th scope="col" align="left">Method( arguments )</th>
355 355
 				</tr>';
356
-                $last_on_stack = count($ex['trace']) - 1;
357
-                // reverse array so that stack is in proper chronological order
358
-                $sorted_trace = array_reverse($ex['trace']);
359
-                foreach ($sorted_trace as $nmbr => $trace) {
360
-                    $file = isset($trace['file']) ? $trace['file'] : '';
361
-                    $class = isset($trace['class']) ? $trace['class'] : '';
362
-                    $type = isset($trace['type']) ? $trace['type'] : '';
363
-                    $function = isset($trace['function']) ? $trace['function'] : '';
364
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
-                    $line = isset($trace['line']) ? $trace['line'] : '';
366
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
367
-                    if (empty($file) && ! empty($class)) {
368
-                        $a = new ReflectionClass($class);
369
-                        $file = $a->getFileName();
370
-                        if (empty($line) && ! empty($function)) {
371
-                            $b = new ReflectionMethod($class, $function);
372
-                            $line = $b->getStartLine();
373
-                        }
374
-                    }
375
-                    if ($nmbr === $last_on_stack) {
376
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
377
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
378
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
379
-                    }
380
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
382
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
383
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
384
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
385
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
-                    $trace_details .= '
356
+				$last_on_stack = count($ex['trace']) - 1;
357
+				// reverse array so that stack is in proper chronological order
358
+				$sorted_trace = array_reverse($ex['trace']);
359
+				foreach ($sorted_trace as $nmbr => $trace) {
360
+					$file = isset($trace['file']) ? $trace['file'] : '';
361
+					$class = isset($trace['class']) ? $trace['class'] : '';
362
+					$type = isset($trace['type']) ? $trace['type'] : '';
363
+					$function = isset($trace['function']) ? $trace['function'] : '';
364
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
+					$line = isset($trace['line']) ? $trace['line'] : '';
366
+					$zebra = ($nmbr % 2) ? ' odd' : '';
367
+					if (empty($file) && ! empty($class)) {
368
+						$a = new ReflectionClass($class);
369
+						$file = $a->getFileName();
370
+						if (empty($line) && ! empty($function)) {
371
+							$b = new ReflectionMethod($class, $function);
372
+							$line = $b->getStartLine();
373
+						}
374
+					}
375
+					if ($nmbr === $last_on_stack) {
376
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
377
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
378
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
379
+					}
380
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
382
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
383
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
384
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
385
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
386
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
+					$trace_details .= '
388 388
 					<tr>
389 389
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390 390
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -392,670 +392,670 @@  discard block
 block discarded – undo
392 392
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393 393
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
394 394
 					</tr>';
395
-                }
396
-                $trace_details .= '
395
+				}
396
+				$trace_details .= '
397 397
 			 </table>
398 398
 			</div>';
399
-            }
400
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
-            // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
403
-                $output .= '<span class="ee-error-user-msg-spn">'
404
-                           . trim($ex['msg'])
405
-                           . '</span> &nbsp; <sup>'
406
-                           . $ex['code']
407
-                           . '</sup><br />';
408
-            } else {
409
-                // or helpful developer messages if debugging is on
410
-                $output .= '
399
+			}
400
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
+			// add generic non-identifying messages for non-privileged users
402
+			if (! WP_DEBUG) {
403
+				$output .= '<span class="ee-error-user-msg-spn">'
404
+						   . trim($ex['msg'])
405
+						   . '</span> &nbsp; <sup>'
406
+						   . $ex['code']
407
+						   . '</sup><br />';
408
+			} else {
409
+				// or helpful developer messages if debugging is on
410
+				$output .= '
411 411
 		<div class="ee-error-dev-msg-dv">
412 412
 			<p class="ee-error-dev-msg-pg">
413 413
 				<strong class="ee-error-dev-msg-str">An '
414
-                           . $ex['name']
415
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
-                           . $ex['code']
417
-                           . '</span><br />
414
+						   . $ex['name']
415
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
+						   . $ex['code']
417
+						   . '</span><br />
418 418
 				<span class="big-text">"'
419
-                           . trim($ex['msg'])
420
-                           . '"</span><br/>
419
+						   . trim($ex['msg'])
420
+						   . '"</span><br/>
421 421
 				<a id="display-ee-error-trace-'
422
-                           . self::$_error_count
423
-                           . $time
424
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
-                           . self::$_error_count
426
-                           . $time
427
-                           . '">
422
+						   . self::$_error_count
423
+						   . $time
424
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
+						   . self::$_error_count
426
+						   . $time
427
+						   . '">
428 428
 					'
429
-                           . __('click to view backtrace and class/method details', 'event_espresso')
430
-                           . '
429
+						   . __('click to view backtrace and class/method details', 'event_espresso')
430
+						   . '
431 431
 				</a><br />
432 432
 				<span class="small-text lt-grey-text">'
433
-                           . $ex['file']
434
-                           . ' &nbsp; ( line no: '
435
-                           . $ex['line']
436
-                           . ' )</span>
433
+						   . $ex['file']
434
+						   . ' &nbsp; ( line no: '
435
+						   . $ex['line']
436
+						   . ' )</span>
437 437
 			</p>
438 438
 			<div id="ee-error-trace-'
439
-                           . self::$_error_count
440
-                           . $time
441
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
439
+						   . self::$_error_count
440
+						   . $time
441
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443
-                           . $trace_details;
444
-                if (! empty($class)) {
445
-                    $output .= '
443
+						   . $trace_details;
444
+				if (! empty($class)) {
445
+					$output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449
-                    $a = new ReflectionClass($class);
450
-                    $output .= '
449
+					$a = new ReflectionClass($class);
450
+					$output .= '
451 451
 						<pre>' . $a . '</pre>
452 452
 					</div>
453 453
 				</div>';
454
-                }
455
-                $output .= '
454
+				}
455
+				$output .= '
456 456
 			</div>
457 457
 		</div>
458 458
 		<br />';
459
-            }
460
-            $this->write_to_error_log($time, $ex);
461
-        }
462
-        // remove last linebreak
463
-        $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
465
-            $output .= '
459
+			}
460
+			$this->write_to_error_log($time, $ex);
461
+		}
462
+		// remove last linebreak
463
+		$output = substr($output, 0, -6);
464
+		if (! WP_DEBUG) {
465
+			$output .= '
466 466
 	</p>';
467
-        }
468
-        $output .= '
467
+		}
468
+		$output .= '
469 469
 </div>';
470
-        $output .= self::_print_scripts(true);
471
-        if (defined('DOING_AJAX')) {
472
-            echo wp_json_encode(array('error' => $output));
473
-            exit();
474
-        }
475
-        echo $output;
476
-        die();
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     *    generate string from exception trace args
483
-     *
484
-     * @param array $arguments
485
-     * @param bool  $array
486
-     * @return string
487
-     */
488
-    private function _convert_args_to_string($arguments = array(), $array = false)
489
-    {
490
-        $arg_string = '';
491
-        if (! empty($arguments)) {
492
-            $args = array();
493
-            foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
495
-                    if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
497
-                    } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
-                    } elseif ($arg === null) {
500
-                        $args[] = ' NULL';
501
-                    } elseif (is_bool($arg)) {
502
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
503
-                    } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
505
-                    } elseif (is_resource($arg)) {
506
-                        $args[] = get_resource_type($arg);
507
-                    } else {
508
-                        $args[] = $arg;
509
-                    }
510
-                }
511
-            }
512
-            $arg_string = implode(', ', $args);
513
-        }
514
-        if ($array) {
515
-            $arg_string .= ' )';
516
-        }
517
-        return $arg_string;
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     *    add error message
524
-     *
525
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
-     *                            separate messages for user || dev
527
-     * @param        string $file the file that the error occurred in - just use __FILE__
528
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
-     * @param        string $line the line number where the error occurred - just use __LINE__
530
-     * @return        void
531
-     */
532
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
-    {
534
-        self::_add_notice('errors', $msg, $file, $func, $line);
535
-        self::$_error_count++;
536
-    }
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
-    /**
561
-     *    add success message
562
-     *
563
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
-     *                            separate messages for user || dev
565
-     * @param        string $file the file that the error occurred in - just use __FILE__
566
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
-     * @param        string $line the line number where the error occurred - just use __LINE__
568
-     * @return        void
569
-     */
570
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
-    {
572
-        self::_add_notice('success', $msg, $file, $func, $line);
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     *    add attention message
579
-     *
580
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
-     *                            separate messages for user || dev
582
-     * @param        string $file the file that the error occurred in - just use __FILE__
583
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
-     * @param        string $line the line number where the error occurred - just use __LINE__
585
-     * @return        void
586
-     */
587
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
-    {
589
-        self::_add_notice('attention', $msg, $file, $func, $line);
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     *    add success message
596
-     *
597
-     * @param        string $type whether the message is for a success or error notification
598
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
-     *                            separate messages for user || dev
600
-     * @param        string $file the file that the error occurred in - just use __FILE__
601
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
-     * @param        string $line the line number where the error occurred - just use __LINE__
603
-     * @return        void
604
-     */
605
-    private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
-    {
607
-        if (empty($msg)) {
608
-            EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
610
-                sprintf(
611
-                    __('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',
612
-                        'event_espresso'),
613
-                    $type,
614
-                    $file,
615
-                    $line
616
-                ),
617
-                EVENT_ESPRESSO_VERSION
618
-            );
619
-        }
620
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
-            EE_Error::doing_it_wrong(
622
-                'EE_Error::add_error()',
623
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
-                    'event_espresso'),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        // get separate user and developer messages if they exist
629
-        $msg = explode('||', $msg);
630
-        $user_msg = $msg[0];
631
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
-        /**
633
-         * Do an action so other code can be triggered when a notice is created
634
-         *
635
-         * @param string $type     can be 'errors', 'attention', or 'success'
636
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
637
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
638
-         * @param string $file     file where error was generated
639
-         * @param string $func     function where error was generated
640
-         * @param string $line     line where error was generated
641
-         */
642
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
644
-        // add notice if message exists
645
-        if (! empty($msg)) {
646
-            // get error code
647
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
648
-            if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
-            }
651
-            // add notice. Index by code if it's not blank
652
-            if ($notice_code) {
653
-                self::$_espresso_notices[$type][$notice_code] = $msg;
654
-            } else {
655
-                self::$_espresso_notices[$type][] = $msg;
656
-            }
657
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
-        }
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     *    in some case it may be necessary to overwrite the existing success messages
665
-     *
666
-     * @return        void
667
-     */
668
-    public static function overwrite_success()
669
-    {
670
-        self::$_espresso_notices['success'] = false;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     *    in some case it may be necessary to overwrite the existing attention messages
677
-     *
678
-     * @return        void
679
-     */
680
-    public static function overwrite_attention()
681
-    {
682
-        self::$_espresso_notices['attention'] = false;
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    in some case it may be necessary to overwrite the existing error messages
689
-     *
690
-     * @return        void
691
-     */
692
-    public static function overwrite_errors()
693
-    {
694
-        self::$_espresso_notices['errors'] = false;
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     *    reset_notices
701
-     *
702
-     * @return void
703
-     */
704
-    public static function reset_notices()
705
-    {
706
-        self::$_espresso_notices['success'] = false;
707
-        self::$_espresso_notices['attention'] = false;
708
-        self::$_espresso_notices['errors'] = false;
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     *    has_errors
715
-     *
716
-     * @return int
717
-     */
718
-    public static function has_notices()
719
-    {
720
-        $has_notices = 0;
721
-        // check for success messages
722
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
-            : $has_notices;
727
-        // check for error messages
728
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
-            : $has_notices;
730
-        return $has_notices;
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
-     *
738
-     * @since 4.9.0
739
-     * @return array
740
-     */
741
-    public static function get_vanilla_notices()
742
-    {
743
-        return array(
744
-            'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
-            'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
-                : array(),
747
-            'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     *    compile all error or success messages into one string
755
-     *
756
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
-     * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
-     * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
-     *                                          - ONLY do this just before redirecting
760
-     * @param        boolean $remove_empty      whether or not to unset empty messages
761
-     * @return        array
762
-     */
763
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
-    {
765
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
-        $success_messages = '';
767
-        $attention_messages = '';
768
-        $error_messages = '';
769
-        $print_scripts = false;
770
-        // either save notices to the db
771
-        if ($save_to_transient) {
772
-            update_option('ee_notices', self::$_espresso_notices);
773
-            return array();
774
-        }
775
-        // grab any notices that have been previously saved
776
-        if ($notices = get_option('ee_notices', false)) {
777
-            foreach ($notices as $type => $notice) {
778
-                if (is_array($notice) && ! empty($notice)) {
779
-                    // make sure that existing notice type is an array
780
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
-                                                      && ! empty(self::$_espresso_notices[$type])
782
-                        ? self::$_espresso_notices[$type] : array();
783
-                    // merge stored notices with any newly created ones
784
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
-                    $print_scripts = true;
786
-                }
787
-            }
788
-            // now clear any stored notices
789
-            update_option('ee_notices', false);
790
-        }
791
-        // check for success messages
792
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
-            // combine messages
794
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
-            $print_scripts = true;
796
-        }
797
-        // check for attention messages
798
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
-            // combine messages
800
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
-            $print_scripts = true;
802
-        }
803
-        // check for error messages
804
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
806
-                ? __('The following errors have occurred:<br />', 'event_espresso')
807
-                : __('An error has occurred:<br />', 'event_espresso');
808
-            // combine messages
809
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
-            $print_scripts = true;
811
-        }
812
-        self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
-        if ($format_output) {
814
-            $notices = '<div id="espresso-notices">';
815
-            $close = is_admin() ? ''
816
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
-            if ($success_messages !== '') {
818
-                $css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
-                //showMessage( $success_messages );
821
-                $notices .= '<div id="'
822
-                            . $css_id
823
-                            . '" class="espresso-notices '
824
-                            . $css_class
825
-                            . '" style="display:none;"><p>'
826
-                            . $success_messages
827
-                            . '</p>'
828
-                            . $close
829
-                            . '</div>';
830
-            }
831
-            if ($attention_messages !== '') {
832
-                $css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
-                //showMessage( $error_messages, TRUE );
835
-                $notices .= '<div id="'
836
-                            . $css_id
837
-                            . '" class="espresso-notices '
838
-                            . $css_class
839
-                            . '" style="display:none;"><p>'
840
-                            . $attention_messages
841
-                            . '</p>'
842
-                            . $close
843
-                            . '</div>';
844
-            }
845
-            if ($error_messages !== '') {
846
-                $css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
-                $css_class = is_admin() ? 'error' : 'error fade-away';
848
-                //showMessage( $error_messages, TRUE );
849
-                $notices .= '<div id="'
850
-                            . $css_id
851
-                            . '" class="espresso-notices '
852
-                            . $css_class
853
-                            . '" style="display:none;"><p>'
854
-                            . $error_messages
855
-                            . '</p>'
856
-                            . $close
857
-                            . '</div>';
858
-            }
859
-            $notices .= '</div>';
860
-        } else {
861
-            $notices = array(
862
-                'success'   => $success_messages,
863
-                'attention' => $attention_messages,
864
-                'errors'    => $error_messages,
865
-            );
866
-            if ($remove_empty) {
867
-                // remove empty notices
868
-                foreach ($notices as $type => $notice) {
869
-                    if (empty($notice)) {
870
-                        unset($notices[$type]);
871
-                    }
872
-                }
873
-            }
874
-        }
875
-        if ($print_scripts) {
876
-            self::_print_scripts();
877
-        }
878
-        return $notices;
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     *    add_persistent_admin_notice
885
-     *
886
-     * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
-     * @param        string $pan_message  the message to be stored persistently until dismissed
888
-     * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
-     * @return        void
890
-     */
891
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
-    {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
894
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
-            //maybe initialize persistent_admin_notices
896
-            if (empty($persistent_admin_notices)) {
897
-                add_option('ee_pers_admin_notices', array(), '', 'no');
898
-            }
899
-            $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
-                $persistent_admin_notices[$pan_name] = $pan_message;
902
-                update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
-            }
904
-        }
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     *    dismiss_persistent_admin_notice
911
-     *
912
-     * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
-     * @param bool          $purge
914
-     * @param bool          $return_immediately
915
-     * @return        void
916
-     */
917
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
-    {
919
-        $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
-            ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
922
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
-            // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
-            if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
-                // completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
-                if ($purge) {
927
-                    unset($persistent_admin_notices[$pan_name]);
928
-                } else {
929
-                    $persistent_admin_notices[$pan_name] = null;
930
-                }
931
-                if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
-                    EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
-                        'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
-                }
935
-            }
936
-        }
937
-        if ($return_immediately) {
938
-            return;
939
-        }
940
-        if (EE_Registry::instance()->REQ->ajax) {
941
-            // grab any notices and concatenate into string
942
-            echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
-            exit();
944
-        }
945
-        // save errors to a transient to be displayed on next request (after redirect)
946
-        EE_Error::get_notices(false, true);
947
-        $return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
-            ? EE_Registry::instance()->REQ->get('return_url') : '';
949
-        wp_safe_redirect(urldecode($return_url));
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * display_persistent_admin_notices
956
-     *
957
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
-     * @param  string $pan_message the message to be stored persistently until dismissed
959
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
960
-     * @return string
961
-     */
962
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
-    {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
965
-            $args = array(
966
-                'nag_notice'    => $pan_name,
967
-                'return_url'    => urlencode($return_url),
968
-                'ajax_url'      => WP_AJAX_URL,
969
-                'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
-                    'event_espresso'),
971
-            );
972
-            wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
-            return '
470
+		$output .= self::_print_scripts(true);
471
+		if (defined('DOING_AJAX')) {
472
+			echo wp_json_encode(array('error' => $output));
473
+			exit();
474
+		}
475
+		echo $output;
476
+		die();
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 *    generate string from exception trace args
483
+	 *
484
+	 * @param array $arguments
485
+	 * @param bool  $array
486
+	 * @return string
487
+	 */
488
+	private function _convert_args_to_string($arguments = array(), $array = false)
489
+	{
490
+		$arg_string = '';
491
+		if (! empty($arguments)) {
492
+			$args = array();
493
+			foreach ($arguments as $arg) {
494
+				if (! empty($arg)) {
495
+					if (is_string($arg)) {
496
+						$args[] = " '" . $arg . "'";
497
+					} elseif (is_array($arg)) {
498
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
+					} elseif ($arg === null) {
500
+						$args[] = ' NULL';
501
+					} elseif (is_bool($arg)) {
502
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
503
+					} elseif (is_object($arg)) {
504
+						$args[] = ' OBJECT ' . get_class($arg);
505
+					} elseif (is_resource($arg)) {
506
+						$args[] = get_resource_type($arg);
507
+					} else {
508
+						$args[] = $arg;
509
+					}
510
+				}
511
+			}
512
+			$arg_string = implode(', ', $args);
513
+		}
514
+		if ($array) {
515
+			$arg_string .= ' )';
516
+		}
517
+		return $arg_string;
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 *    add error message
524
+	 *
525
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
+	 *                            separate messages for user || dev
527
+	 * @param        string $file the file that the error occurred in - just use __FILE__
528
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
+	 * @param        string $line the line number where the error occurred - just use __LINE__
530
+	 * @return        void
531
+	 */
532
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
+	{
534
+		self::_add_notice('errors', $msg, $file, $func, $line);
535
+		self::$_error_count++;
536
+	}
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
+	/**
561
+	 *    add success message
562
+	 *
563
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
+	 *                            separate messages for user || dev
565
+	 * @param        string $file the file that the error occurred in - just use __FILE__
566
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
+	 * @param        string $line the line number where the error occurred - just use __LINE__
568
+	 * @return        void
569
+	 */
570
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
+	{
572
+		self::_add_notice('success', $msg, $file, $func, $line);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 *    add attention message
579
+	 *
580
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
+	 *                            separate messages for user || dev
582
+	 * @param        string $file the file that the error occurred in - just use __FILE__
583
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
+	 * @param        string $line the line number where the error occurred - just use __LINE__
585
+	 * @return        void
586
+	 */
587
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
+	{
589
+		self::_add_notice('attention', $msg, $file, $func, $line);
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 *    add success message
596
+	 *
597
+	 * @param        string $type whether the message is for a success or error notification
598
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
+	 *                            separate messages for user || dev
600
+	 * @param        string $file the file that the error occurred in - just use __FILE__
601
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
+	 * @param        string $line the line number where the error occurred - just use __LINE__
603
+	 * @return        void
604
+	 */
605
+	private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
+	{
607
+		if (empty($msg)) {
608
+			EE_Error::doing_it_wrong(
609
+				'EE_Error::add_' . $type . '()',
610
+				sprintf(
611
+					__('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',
612
+						'event_espresso'),
613
+					$type,
614
+					$file,
615
+					$line
616
+				),
617
+				EVENT_ESPRESSO_VERSION
618
+			);
619
+		}
620
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
+			EE_Error::doing_it_wrong(
622
+				'EE_Error::add_error()',
623
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
+					'event_espresso'),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		// get separate user and developer messages if they exist
629
+		$msg = explode('||', $msg);
630
+		$user_msg = $msg[0];
631
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
+		/**
633
+		 * Do an action so other code can be triggered when a notice is created
634
+		 *
635
+		 * @param string $type     can be 'errors', 'attention', or 'success'
636
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
637
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
638
+		 * @param string $file     file where error was generated
639
+		 * @param string $func     function where error was generated
640
+		 * @param string $line     line where error was generated
641
+		 */
642
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
644
+		// add notice if message exists
645
+		if (! empty($msg)) {
646
+			// get error code
647
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
648
+			if (WP_DEBUG && $type === 'errors') {
649
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
+			}
651
+			// add notice. Index by code if it's not blank
652
+			if ($notice_code) {
653
+				self::$_espresso_notices[$type][$notice_code] = $msg;
654
+			} else {
655
+				self::$_espresso_notices[$type][] = $msg;
656
+			}
657
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
+		}
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 *    in some case it may be necessary to overwrite the existing success messages
665
+	 *
666
+	 * @return        void
667
+	 */
668
+	public static function overwrite_success()
669
+	{
670
+		self::$_espresso_notices['success'] = false;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 *    in some case it may be necessary to overwrite the existing attention messages
677
+	 *
678
+	 * @return        void
679
+	 */
680
+	public static function overwrite_attention()
681
+	{
682
+		self::$_espresso_notices['attention'] = false;
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    in some case it may be necessary to overwrite the existing error messages
689
+	 *
690
+	 * @return        void
691
+	 */
692
+	public static function overwrite_errors()
693
+	{
694
+		self::$_espresso_notices['errors'] = false;
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 *    reset_notices
701
+	 *
702
+	 * @return void
703
+	 */
704
+	public static function reset_notices()
705
+	{
706
+		self::$_espresso_notices['success'] = false;
707
+		self::$_espresso_notices['attention'] = false;
708
+		self::$_espresso_notices['errors'] = false;
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 *    has_errors
715
+	 *
716
+	 * @return int
717
+	 */
718
+	public static function has_notices()
719
+	{
720
+		$has_notices = 0;
721
+		// check for success messages
722
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
+			: $has_notices;
727
+		// check for error messages
728
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
+			: $has_notices;
730
+		return $has_notices;
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
+	 *
738
+	 * @since 4.9.0
739
+	 * @return array
740
+	 */
741
+	public static function get_vanilla_notices()
742
+	{
743
+		return array(
744
+			'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
+				: array(),
747
+			'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 *    compile all error or success messages into one string
755
+	 *
756
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
+	 * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
+	 * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
+	 *                                          - ONLY do this just before redirecting
760
+	 * @param        boolean $remove_empty      whether or not to unset empty messages
761
+	 * @return        array
762
+	 */
763
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
+	{
765
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
+		$success_messages = '';
767
+		$attention_messages = '';
768
+		$error_messages = '';
769
+		$print_scripts = false;
770
+		// either save notices to the db
771
+		if ($save_to_transient) {
772
+			update_option('ee_notices', self::$_espresso_notices);
773
+			return array();
774
+		}
775
+		// grab any notices that have been previously saved
776
+		if ($notices = get_option('ee_notices', false)) {
777
+			foreach ($notices as $type => $notice) {
778
+				if (is_array($notice) && ! empty($notice)) {
779
+					// make sure that existing notice type is an array
780
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
+													  && ! empty(self::$_espresso_notices[$type])
782
+						? self::$_espresso_notices[$type] : array();
783
+					// merge stored notices with any newly created ones
784
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
+					$print_scripts = true;
786
+				}
787
+			}
788
+			// now clear any stored notices
789
+			update_option('ee_notices', false);
790
+		}
791
+		// check for success messages
792
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
+			// combine messages
794
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
+			$print_scripts = true;
796
+		}
797
+		// check for attention messages
798
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
+			// combine messages
800
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
+			$print_scripts = true;
802
+		}
803
+		// check for error messages
804
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
806
+				? __('The following errors have occurred:<br />', 'event_espresso')
807
+				: __('An error has occurred:<br />', 'event_espresso');
808
+			// combine messages
809
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
+			$print_scripts = true;
811
+		}
812
+		self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
+		if ($format_output) {
814
+			$notices = '<div id="espresso-notices">';
815
+			$close = is_admin() ? ''
816
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
+			if ($success_messages !== '') {
818
+				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
+				//showMessage( $success_messages );
821
+				$notices .= '<div id="'
822
+							. $css_id
823
+							. '" class="espresso-notices '
824
+							. $css_class
825
+							. '" style="display:none;"><p>'
826
+							. $success_messages
827
+							. '</p>'
828
+							. $close
829
+							. '</div>';
830
+			}
831
+			if ($attention_messages !== '') {
832
+				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
+				//showMessage( $error_messages, TRUE );
835
+				$notices .= '<div id="'
836
+							. $css_id
837
+							. '" class="espresso-notices '
838
+							. $css_class
839
+							. '" style="display:none;"><p>'
840
+							. $attention_messages
841
+							. '</p>'
842
+							. $close
843
+							. '</div>';
844
+			}
845
+			if ($error_messages !== '') {
846
+				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
+				$css_class = is_admin() ? 'error' : 'error fade-away';
848
+				//showMessage( $error_messages, TRUE );
849
+				$notices .= '<div id="'
850
+							. $css_id
851
+							. '" class="espresso-notices '
852
+							. $css_class
853
+							. '" style="display:none;"><p>'
854
+							. $error_messages
855
+							. '</p>'
856
+							. $close
857
+							. '</div>';
858
+			}
859
+			$notices .= '</div>';
860
+		} else {
861
+			$notices = array(
862
+				'success'   => $success_messages,
863
+				'attention' => $attention_messages,
864
+				'errors'    => $error_messages,
865
+			);
866
+			if ($remove_empty) {
867
+				// remove empty notices
868
+				foreach ($notices as $type => $notice) {
869
+					if (empty($notice)) {
870
+						unset($notices[$type]);
871
+					}
872
+				}
873
+			}
874
+		}
875
+		if ($print_scripts) {
876
+			self::_print_scripts();
877
+		}
878
+		return $notices;
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 *    add_persistent_admin_notice
885
+	 *
886
+	 * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
+	 * @param        string $pan_message  the message to be stored persistently until dismissed
888
+	 * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
+	 * @return        void
890
+	 */
891
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
+	{
893
+		if (! empty($pan_name) && ! empty($pan_message)) {
894
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
+			//maybe initialize persistent_admin_notices
896
+			if (empty($persistent_admin_notices)) {
897
+				add_option('ee_pers_admin_notices', array(), '', 'no');
898
+			}
899
+			$pan_name = sanitize_key($pan_name);
900
+			if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
+				$persistent_admin_notices[$pan_name] = $pan_message;
902
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
+			}
904
+		}
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 *    dismiss_persistent_admin_notice
911
+	 *
912
+	 * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
+	 * @param bool          $purge
914
+	 * @param bool          $return_immediately
915
+	 * @return        void
916
+	 */
917
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
+	{
919
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
+			? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
+		if (! empty($pan_name)) {
922
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
+			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
+				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
+				if ($purge) {
927
+					unset($persistent_admin_notices[$pan_name]);
928
+				} else {
929
+					$persistent_admin_notices[$pan_name] = null;
930
+				}
931
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
+						'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
+				}
935
+			}
936
+		}
937
+		if ($return_immediately) {
938
+			return;
939
+		}
940
+		if (EE_Registry::instance()->REQ->ajax) {
941
+			// grab any notices and concatenate into string
942
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
+			exit();
944
+		}
945
+		// save errors to a transient to be displayed on next request (after redirect)
946
+		EE_Error::get_notices(false, true);
947
+		$return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
+			? EE_Registry::instance()->REQ->get('return_url') : '';
949
+		wp_safe_redirect(urldecode($return_url));
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * display_persistent_admin_notices
956
+	 *
957
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
+	 * @param  string $pan_message the message to be stored persistently until dismissed
959
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
960
+	 * @return string
961
+	 */
962
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
+	{
964
+		if (! empty($pan_name) && ! empty($pan_message)) {
965
+			$args = array(
966
+				'nag_notice'    => $pan_name,
967
+				'return_url'    => urlencode($return_url),
968
+				'ajax_url'      => WP_AJAX_URL,
969
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
+					'event_espresso'),
971
+			);
972
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
+			return '
974 974
 			<div id="'
975
-                   . $pan_name
976
-                   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
975
+				   . $pan_name
976
+				   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
977 977
 				<p>'
978
-                   . $pan_message
979
-                   . '</p>
978
+				   . $pan_message
979
+				   . '</p>
980 980
 				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="'
981
-                   . $pan_name
982
-                   . '">
981
+				   . $pan_name
982
+				   . '">
983 983
 					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'
984
-                   . __('Dismiss', 'event_espresso')
985
-                   . '
984
+				   . __('Dismiss', 'event_espresso')
985
+				   . '
986 986
 				</a>
987 987
 				<div style="clear:both;"></div>
988 988
 			</div>';
989
-        }
990
-        return '';
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     *    get_persistent_admin_notices
997
-     *
998
-     * @param string $return_url
999
-     * @return string
1000
-     */
1001
-    public static function get_persistent_admin_notices($return_url = '')
1002
-    {
1003
-        $notices = '';
1004
-        // check for persistent admin notices
1005
-        //filter the list though so plugins can notify the admin in a different way if they want
1006
-        $persistent_admin_notices = apply_filters(
1007
-            'FHEE__EE_Error__get_persistent_admin_notices',
1008
-            get_option('ee_pers_admin_notices', false),
1009
-            'ee_pers_admin_notices',
1010
-            $return_url
1011
-        );
1012
-        if ($persistent_admin_notices) {
1013
-            // load scripts
1014
-            wp_register_script(
1015
-                'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
-                array('jquery'),
1018
-                EVENT_ESPRESSO_VERSION,
1019
-                true
1020
-            );
1021
-            wp_register_script(
1022
-                'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
-                array('espresso_core'),
1025
-                EVENT_ESPRESSO_VERSION,
1026
-                true
1027
-            );
1028
-            wp_enqueue_script('ee_error_js');
1029
-            // and display notices
1030
-            foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
-                $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
-            }
1033
-        }
1034
-        return $notices;
1035
-    }
1036
-
1037
-
1038
-
1039
-    /**
1040
-     * _print_scripts
1041
-     *
1042
-     * @param    bool $force_print
1043
-     * @return    string
1044
-     */
1045
-    private static function _print_scripts($force_print = false)
1046
-    {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1049
-                return '';
1050
-            }
1051
-            if (wp_script_is('ee_error_js', 'registered')) {
1052
-                add_filter('FHEE_load_css', '__return_true');
1053
-                add_filter('FHEE_load_js', '__return_true');
1054
-                wp_enqueue_script('ee_error_js');
1055
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
-            }
1057
-        } else {
1058
-            return '
989
+		}
990
+		return '';
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 *    get_persistent_admin_notices
997
+	 *
998
+	 * @param string $return_url
999
+	 * @return string
1000
+	 */
1001
+	public static function get_persistent_admin_notices($return_url = '')
1002
+	{
1003
+		$notices = '';
1004
+		// check for persistent admin notices
1005
+		//filter the list though so plugins can notify the admin in a different way if they want
1006
+		$persistent_admin_notices = apply_filters(
1007
+			'FHEE__EE_Error__get_persistent_admin_notices',
1008
+			get_option('ee_pers_admin_notices', false),
1009
+			'ee_pers_admin_notices',
1010
+			$return_url
1011
+		);
1012
+		if ($persistent_admin_notices) {
1013
+			// load scripts
1014
+			wp_register_script(
1015
+				'espresso_core',
1016
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
+				array('jquery'),
1018
+				EVENT_ESPRESSO_VERSION,
1019
+				true
1020
+			);
1021
+			wp_register_script(
1022
+				'ee_error_js',
1023
+				EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
+				array('espresso_core'),
1025
+				EVENT_ESPRESSO_VERSION,
1026
+				true
1027
+			);
1028
+			wp_enqueue_script('ee_error_js');
1029
+			// and display notices
1030
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
+			}
1033
+		}
1034
+		return $notices;
1035
+	}
1036
+
1037
+
1038
+
1039
+	/**
1040
+	 * _print_scripts
1041
+	 *
1042
+	 * @param    bool $force_print
1043
+	 * @return    string
1044
+	 */
1045
+	private static function _print_scripts($force_print = false)
1046
+	{
1047
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1049
+				return '';
1050
+			}
1051
+			if (wp_script_is('ee_error_js', 'registered')) {
1052
+				add_filter('FHEE_load_css', '__return_true');
1053
+				add_filter('FHEE_load_js', '__return_true');
1054
+				wp_enqueue_script('ee_error_js');
1055
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
+			}
1057
+		} else {
1058
+			return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061 1061
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1065,143 +1065,143 @@  discard block
 block discarded – undo
1065 1065
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066 1066
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1067 1067
 ';
1068
-        }
1069
-        return '';
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     *    enqueue_error_scripts
1076
-     *
1077
-     * @return        void
1078
-     */
1079
-    public static function enqueue_error_scripts()
1080
-    {
1081
-        self::_print_scripts();
1082
-    }
1083
-
1084
-
1085
-
1086
-    /**
1087
-     *    create error code from filepath, function name,
1088
-     *    and line number where exception or error was thrown
1089
-     *
1090
-     * @param string $file
1091
-     * @param string $func
1092
-     * @param string $line
1093
-     * @return string
1094
-     */
1095
-    public static function generate_error_code($file = '', $func = '', $line = '')
1096
-    {
1097
-        $file = explode('.', basename($file));
1098
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1101
-        return $error_code;
1102
-    }
1103
-
1104
-
1105
-
1106
-    /**
1107
-     *    write exception details to log file
1108
-     *
1109
-     * @param int   $time
1110
-     * @param array $ex
1111
-     * @param bool  $clear
1112
-     * @return void
1113
-     */
1114
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
-    {
1116
-        if (empty($ex)) {
1117
-            return;
1118
-        }
1119
-        if (! $time) {
1120
-            $time = time();
1121
-        }
1122
-        $exception_log = '----------------------------------------------------------------------------------------'
1123
-                         . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1131
-        $exception_log .= '----------------------------------------------------------------------------------------'
1132
-                          . PHP_EOL;
1133
-        try {
1134
-            EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
-            );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1139
-                //get existing log file and append new log info
1140
-                $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1143
-            }
1144
-            EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
-                $exception_log
1147
-            );
1148
-        } catch (EE_Error $e) {
1149
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
-                'event_espresso'), $e->getMessage()));
1151
-            return;
1152
-        }
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
-     * but the code execution is done in a manner that could lead to unexpected results
1161
-     * (i.e. running to early, or too late in WP or EE loading process).
1162
-     * A good test for knowing whether to use this method is:
1163
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
-     * 2. If this is loaded before something else, it won't break anything,
1166
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
-     *
1168
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
-     * @param string $function      The function that was called
1170
-     * @param string $message       A message explaining what has been done incorrectly
1171
-     * @param string $version       The version of Event Espresso where the error was added
1172
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1174
-     *                              but not have any notices appear until a later version. This allows developers
1175
-     *                              extra time to update their code before notices appear.
1176
-     * @param int    $error_type
1177
-     */
1178
-    public static function doing_it_wrong(
1179
-        $function,
1180
-        $message,
1181
-        $version,
1182
-        $applies_when = '',
1183
-        $error_type = null
1184
-    ) {
1185
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1186
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
-        }
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * Like get_notices, but returns an array of all the notices of the given type.
1194
-     *
1195
-     * @return array {
1196
-     * @type array $success   all the success messages
1197
-     * @type array $errors    all the error messages
1198
-     * @type array $attention all the attention messages
1199
-     * }
1200
-     */
1201
-    public static function get_raw_notices()
1202
-    {
1203
-        return self::$_espresso_notices;
1204
-    }
1068
+		}
1069
+		return '';
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 *    enqueue_error_scripts
1076
+	 *
1077
+	 * @return        void
1078
+	 */
1079
+	public static function enqueue_error_scripts()
1080
+	{
1081
+		self::_print_scripts();
1082
+	}
1083
+
1084
+
1085
+
1086
+	/**
1087
+	 *    create error code from filepath, function name,
1088
+	 *    and line number where exception or error was thrown
1089
+	 *
1090
+	 * @param string $file
1091
+	 * @param string $func
1092
+	 * @param string $line
1093
+	 * @return string
1094
+	 */
1095
+	public static function generate_error_code($file = '', $func = '', $line = '')
1096
+	{
1097
+		$file = explode('.', basename($file));
1098
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1099
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1100
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1101
+		return $error_code;
1102
+	}
1103
+
1104
+
1105
+
1106
+	/**
1107
+	 *    write exception details to log file
1108
+	 *
1109
+	 * @param int   $time
1110
+	 * @param array $ex
1111
+	 * @param bool  $clear
1112
+	 * @return void
1113
+	 */
1114
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
+	{
1116
+		if (empty($ex)) {
1117
+			return;
1118
+		}
1119
+		if (! $time) {
1120
+			$time = time();
1121
+		}
1122
+		$exception_log = '----------------------------------------------------------------------------------------'
1123
+						 . PHP_EOL;
1124
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1130
+		$exception_log .= $ex['string'] . PHP_EOL;
1131
+		$exception_log .= '----------------------------------------------------------------------------------------'
1132
+						  . PHP_EOL;
1133
+		try {
1134
+			EEH_File::ensure_file_exists_and_is_writable(
1135
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
+			);
1137
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
+			if (! $clear) {
1139
+				//get existing log file and append new log info
1140
+				$exception_log = EEH_File::get_file_contents(
1141
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
+				) . $exception_log;
1143
+			}
1144
+			EEH_File::write_to_file(
1145
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
+				$exception_log
1147
+			);
1148
+		} catch (EE_Error $e) {
1149
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
+				'event_espresso'), $e->getMessage()));
1151
+			return;
1152
+		}
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
+	 * but the code execution is done in a manner that could lead to unexpected results
1161
+	 * (i.e. running to early, or too late in WP or EE loading process).
1162
+	 * A good test for knowing whether to use this method is:
1163
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
+	 * 2. If this is loaded before something else, it won't break anything,
1166
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
+	 *
1168
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
+	 * @param string $function      The function that was called
1170
+	 * @param string $message       A message explaining what has been done incorrectly
1171
+	 * @param string $version       The version of Event Espresso where the error was added
1172
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1174
+	 *                              but not have any notices appear until a later version. This allows developers
1175
+	 *                              extra time to update their code before notices appear.
1176
+	 * @param int    $error_type
1177
+	 */
1178
+	public static function doing_it_wrong(
1179
+		$function,
1180
+		$message,
1181
+		$version,
1182
+		$applies_when = '',
1183
+		$error_type = null
1184
+	) {
1185
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1186
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
+		}
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * Like get_notices, but returns an array of all the notices of the given type.
1194
+	 *
1195
+	 * @return array {
1196
+	 * @type array $success   all the success messages
1197
+	 * @type array $errors    all the error messages
1198
+	 * @type array $attention all the attention messages
1199
+	 * }
1200
+	 */
1201
+	public static function get_raw_notices()
1202
+	{
1203
+		return self::$_espresso_notices;
1204
+	}
1205 1205
 
1206 1206
 
1207 1207
 
@@ -1217,27 +1217,27 @@  discard block
 block discarded – undo
1217 1217
  */
1218 1218
 function espresso_error_enqueue_scripts()
1219 1219
 {
1220
-    // js for error handling
1221
-    wp_register_script(
1222
-        'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
-        array('jquery'),
1225
-        EVENT_ESPRESSO_VERSION,
1226
-        false
1227
-    );
1228
-    wp_register_script(
1229
-        'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
-        array('espresso_core'),
1232
-        EVENT_ESPRESSO_VERSION,
1233
-        false
1234
-    );
1220
+	// js for error handling
1221
+	wp_register_script(
1222
+		'espresso_core',
1223
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
+		array('jquery'),
1225
+		EVENT_ESPRESSO_VERSION,
1226
+		false
1227
+	);
1228
+	wp_register_script(
1229
+		'ee_error_js',
1230
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
+		array('espresso_core'),
1232
+		EVENT_ESPRESSO_VERSION,
1233
+		false
1234
+	);
1235 1235
 }
1236 1236
 
1237 1237
 if (is_admin()) {
1238
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1238
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1239 1239
 } else {
1240
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1240
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1241 1241
 }
1242 1242
 
1243 1243
 
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
             default :
99 99
                 $to = get_option('admin_email');
100 100
         }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
101
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
102 102
         $msg = EE_Error::_format_error($type, $message, $file, $line);
103 103
         if (function_exists('wp_mail')) {
104 104
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105 105
             wp_mail($to, $subject, $msg);
106 106
         }
107 107
         echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
108
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
109 109
         echo '<br /></p></div>';
110 110
     }
111 111
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ? true
255 255
             : false;
256 256
         if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
257
+            $notices = (array) get_option('ee_notices', array());
258 258
             foreach ($notices as $type => $notice) {
259 259
                 if ($type === $type_to_check && $notice) {
260 260
                     return true;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
334
+        if ( ! WP_DEBUG) {
335 335
             $output .= '
336 336
 	<p>';
337 337
         }
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
384 384
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
385 385
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
386
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
387 387
                     $trace_details .= '
388 388
 					<tr>
389
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
391
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
392
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
389
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
390
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
391
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
392
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
393
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
394 394
 					</tr>';
395 395
                 }
396 396
                 $trace_details .= '
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401 401
             // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
402
+            if ( ! WP_DEBUG) {
403 403
                 $output .= '<span class="ee-error-user-msg-spn">'
404 404
                            . trim($ex['msg'])
405 405
                            . '</span> &nbsp; <sup>'
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443 443
                            . $trace_details;
444
-                if (! empty($class)) {
444
+                if ( ! empty($class)) {
445 445
                     $output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449 449
                     $a = new ReflectionClass($class);
450 450
                     $output .= '
451
-						<pre>' . $a . '</pre>
451
+						<pre>' . $a.'</pre>
452 452
 					</div>
453 453
 				</div>';
454 454
                 }
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
         // remove last linebreak
463 463
         $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
464
+        if ( ! WP_DEBUG) {
465 465
             $output .= '
466 466
 	</p>';
467 467
         }
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
     private function _convert_args_to_string($arguments = array(), $array = false)
489 489
     {
490 490
         $arg_string = '';
491
-        if (! empty($arguments)) {
491
+        if ( ! empty($arguments)) {
492 492
             $args = array();
493 493
             foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
494
+                if ( ! empty($arg)) {
495 495
                     if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
496
+                        $args[] = " '".$arg."'";
497 497
                     } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
498
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
499 499
                     } elseif ($arg === null) {
500 500
                         $args[] = ' NULL';
501 501
                     } elseif (is_bool($arg)) {
502 502
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
503 503
                     } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
504
+                        $args[] = ' OBJECT '.get_class($arg);
505 505
                     } elseif (is_resource($arg)) {
506 506
                         $args[] = get_resource_type($arg);
507 507
                     } else {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
     {
607 607
         if (empty($msg)) {
608 608
             EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
609
+                'EE_Error::add_'.$type.'()',
610 610
                 sprintf(
611 611
                     __('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',
612 612
                         'event_espresso'),
@@ -642,11 +642,11 @@  discard block
 block discarded – undo
642 642
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643 643
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
644 644
         // add notice if message exists
645
-        if (! empty($msg)) {
645
+        if ( ! empty($msg)) {
646 646
             // get error code
647 647
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
648 648
             if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
650 650
             }
651 651
             // add notice. Index by code if it's not blank
652 652
             if ($notice_code) {
@@ -890,14 +890,14 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892 892
     {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
893
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
894 894
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895 895
             //maybe initialize persistent_admin_notices
896 896
             if (empty($persistent_admin_notices)) {
897 897
                 add_option('ee_pers_admin_notices', array(), '', 'no');
898 898
             }
899 899
             $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
+            if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901 901
                 $persistent_admin_notices[$pan_name] = $pan_message;
902 902
                 update_option('ee_pers_admin_notices', $persistent_admin_notices);
903 903
             }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
     {
919 919
         $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920 920
             ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
921
+        if ( ! empty($pan_name)) {
922 922
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923 923
             // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924 924
             if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
      */
962 962
     public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963 963
     {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
964
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
965 965
             $args = array(
966 966
                 'nag_notice'    => $pan_name,
967 967
                 'return_url'    => urlencode($return_url),
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
             // load scripts
1014 1014
             wp_register_script(
1015 1015
                 'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1017 1017
                 array('jquery'),
1018 1018
                 EVENT_ESPRESSO_VERSION,
1019 1019
                 true
1020 1020
             );
1021 1021
             wp_register_script(
1022 1022
                 'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
+                EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1024 1024
                 array('espresso_core'),
1025 1025
                 EVENT_ESPRESSO_VERSION,
1026 1026
                 true
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      */
1045 1045
     private static function _print_scripts($force_print = false)
1046 1046
     {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048 1048
             if (wp_script_is('ee_error_js', 'enqueued')) {
1049 1049
                 return '';
1050 1050
             }
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
             return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1061
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1062 1062
 /* ]]> */
1063 1063
 </script>
1064
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1065
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1064
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1065
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1066
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1067 1067
 ';
1068 1068
         }
1069 1069
         return '';
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
     {
1097 1097
         $file = explode('.', basename($file));
1098 1098
         $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1099
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1100
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1101 1101
         return $error_code;
1102 1102
     }
1103 1103
 
@@ -1116,33 +1116,33 @@  discard block
 block discarded – undo
1116 1116
         if (empty($ex)) {
1117 1117
             return;
1118 1118
         }
1119
-        if (! $time) {
1119
+        if ( ! $time) {
1120 1120
             $time = time();
1121 1121
         }
1122 1122
         $exception_log = '----------------------------------------------------------------------------------------'
1123 1123
                          . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1124
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1125
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1126
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1127
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1128
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1129
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1130
+        $exception_log .= $ex['string'].PHP_EOL;
1131 1131
         $exception_log .= '----------------------------------------------------------------------------------------'
1132 1132
                           . PHP_EOL;
1133 1133
         try {
1134 1134
             EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1136 1136
             );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1137
+            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1138
+            if ( ! $clear) {
1139 1139
                 //get existing log file and append new log info
1140 1140
                 $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1141
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1142
+                ).$exception_log;
1143 1143
             }
1144 1144
             EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file,
1146 1146
                 $exception_log
1147 1147
             );
1148 1148
         } catch (EE_Error $e) {
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
     // js for error handling
1221 1221
     wp_register_script(
1222 1222
         'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1224 1224
         array('jquery'),
1225 1225
         EVENT_ESPRESSO_VERSION,
1226 1226
         false
1227 1227
     );
1228 1228
     wp_register_script(
1229 1229
         'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1231 1231
         array('espresso_core'),
1232 1232
         EVENT_ESPRESSO_VERSION,
1233 1233
         false
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.020');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.020');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/notices/NoticeConverterInterface.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,6 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
     /**
26 26
      * @param bool $throw_exceptions
27
+     * @return void
27 28
      */
28 29
     public function setThrowExceptions($throw_exceptions);
29 30
 
@@ -41,7 +42,7 @@  discard block
 block discarded – undo
41 42
     public function process(NoticesContainerInterface $notices);
42 43
 
43 44
     /**
44
-     * @return void;
45
+     * @return void
45 46
      */
46 47
     public function clearNotices();
47 48
 
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@
 block discarded – undo
17 17
 interface NoticeConverterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @return NoticesContainerInterface
22
-     */
23
-    public function getNotices();
24
-
25
-    /**
26
-     * @param bool $throw_exceptions
27
-     */
28
-    public function setThrowExceptions($throw_exceptions);
29
-
30
-    /**
31
-     * @return bool
32
-     */
33
-    public function getThrowExceptions();
34
-
35
-    /**
36
-     * Converts NoticesContainerInterface objects into other format
37
-     *
38
-     * @param NoticesContainerInterface $notices
39
-     * @return
40
-     */
41
-    public function process(NoticesContainerInterface $notices);
42
-
43
-    /**
44
-     * @return void;
45
-     */
46
-    public function clearNotices();
20
+	/**
21
+	 * @return NoticesContainerInterface
22
+	 */
23
+	public function getNotices();
24
+
25
+	/**
26
+	 * @param bool $throw_exceptions
27
+	 */
28
+	public function setThrowExceptions($throw_exceptions);
29
+
30
+	/**
31
+	 * @return bool
32
+	 */
33
+	public function getThrowExceptions();
34
+
35
+	/**
36
+	 * Converts NoticesContainerInterface objects into other format
37
+	 *
38
+	 * @param NoticesContainerInterface $notices
39
+	 * @return
40
+	 */
41
+	public function process(NoticesContainerInterface $notices);
42
+
43
+	/**
44
+	 * @return void;
45
+	 */
46
+	public function clearNotices();
47 47
 
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 1 patch
Indentation   +1428 added lines, -1428 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -24,470 +24,470 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var EE_CPT_Base
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var EE_CPT_Base
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        //}
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (
259
-                        is_array($box['callback'])
260
-                        && (
261
-                            $box['callback'][0] instanceof EE_Admin_Page
262
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
263
-                        )
264
-                    ) {
265
-                        $containers[] = $box['id'];
266
-                    }
267
-                }
268
-            }
269
-        }
270
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
271
-        //add hidden inputs container
272
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
273
-    }
274
-
275
-
276
-
277
-    protected function _load_autosave_scripts_styles()
278
-    {
279
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		//if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		//}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (
259
+						is_array($box['callback'])
260
+						&& (
261
+							$box['callback'][0] instanceof EE_Admin_Page
262
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
263
+						)
264
+					) {
265
+						$containers[] = $box['id'];
266
+					}
267
+				}
268
+			}
269
+		}
270
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
271
+		//add hidden inputs container
272
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
273
+	}
274
+
275
+
276
+
277
+	protected function _load_autosave_scripts_styles()
278
+	{
279
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
280 280
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
281 281
 
282
-        //filter _autosave_containers
283
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
284
-            $this->_autosave_containers, $this);
285
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
286
-            $containers, $this);
287
-
288
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
289
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
-
291
-        $unsaved_data_msg = array(
292
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
293
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
294
-            'inputChanged' => 0,
295
-        );
296
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
297
-    }
298
-
299
-
300
-
301
-    public function load_page_dependencies()
302
-    {
303
-        try {
304
-            $this->_load_page_dependencies();
305
-        } catch (EE_Error $e) {
306
-            $e->get_error();
307
-        }
308
-    }
309
-
310
-
311
-
312
-    /**
313
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
314
-     *
315
-     * @access protected
316
-     * @return void
317
-     */
318
-    protected function _load_page_dependencies()
319
-    {
320
-        //we only add stuff if this is a cpt_route!
321
-        if ( ! $this->_cpt_route) {
322
-            parent::_load_page_dependencies();
323
-            return;
324
-        }
325
-        // now let's do some automatic filters into the wp_system
326
-        // and we'll check to make sure the CHILD class
327
-        // automatically has the required methods in place.
328
-        // the following filters are for setting all the redirects
329
-        // on DEFAULT WP custom post type actions
330
-        // let's add a hidden input to the post-edit form
331
-        // so we know when we have to trigger our custom redirects!
332
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
333
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
334
-        // inject our Admin page nav tabs...
335
-        // let's make sure the nav tabs are set if they aren't already
336
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
337
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
338
-        // modify the post_updated messages array
339
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
340
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
341
-        // cpts use the same format for shortlinks as posts!
342
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
343
-        // This basically allows us to change the title of the "publish" metabox area
344
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
345
-        if ( ! empty($this->_labels['publishbox'])) {
346
-            $box_label = is_array($this->_labels['publishbox'])
347
-                         && isset($this->_labels['publishbox'][$this->_req_action])
348
-                    ? $this->_labels['publishbox'][$this->_req_action]
349
-                    : $this->_labels['publishbox'];
350
-            add_meta_box(
351
-                'submitdiv',
352
-                $box_label,
353
-                'post_submit_meta_box',
354
-                $this->_cpt_routes[$this->_req_action],
355
-                'side',
356
-                'core'
357
-            );
358
-        }
359
-        //let's add page_templates metabox if this cpt added support for it.
360
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
361
-            add_meta_box(
362
-                'page_templates',
363
-                __('Page Template', 'event_espresso'),
364
-                array($this, 'page_template_meta_box'),
365
-                $this->_cpt_routes[$this->_req_action],
366
-                'side',
367
-                'default'
368
-            );
369
-        }
370
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
371
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
372
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
373
-        }
374
-        //add preview button
375
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
376
-        //insert our own post_stati dropdown
377
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
378
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
379
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
380
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
381
-        }
382
-        // This allows for adding additional stuff after the title field on the wp post edit form.
383
-        // This is also before the wp_editor for post description field.
384
-        if (method_exists($this, 'edit_form_after_title')) {
385
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
386
-        }
387
-        /**
388
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
389
-         */
390
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
391
-        parent::_load_page_dependencies();
392
-        // notice we are ALSO going to load the pagenow hook set for this route
393
-        // (see _before_page_setup for the reset of the pagenow global ).
394
-        // This is for any plugins that are doing things properly
395
-        // and hooking into the load page hook for core wp cpt routes.
396
-        global $pagenow;
397
-        do_action('load-' . $pagenow);
398
-        $this->modify_current_screen();
399
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
400
-        //we route REALLY early.
401
-        try {
402
-            $this->_route_admin_request();
403
-        } catch (EE_Error $e) {
404
-            $e->get_error();
405
-        }
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
412
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
413
-     * route instead.
414
-     *
415
-     * @param string $good_protocol_url The escaped url.
416
-     * @param string $original_url      The original url.
417
-     * @param string $_context          The context sent to the esc_url method.
418
-     * @return string possibly a new url for our route.
419
-     */
420
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
421
-    {
422
-        $routes_to_match = array(
423
-            0 => array(
424
-                'edit.php?post_type=espresso_attendees',
425
-                'admin.php?page=espresso_registrations&action=contact_list',
426
-            ),
427
-            1 => array(
428
-                'edit.php?post_type=' . $this->_cpt_object->name,
429
-                'admin.php?page=' . $this->_cpt_object->name,
430
-            ),
431
-        );
432
-        foreach ($routes_to_match as $route_matches) {
433
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
434
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
435
-            }
436
-        }
437
-        return $good_protocol_url;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * Determine whether the current cpt supports page templates or not.
444
-     *
445
-     * @since %VER%
446
-     * @param string $cpt_name The cpt slug we're checking on.
447
-     * @return bool True supported, false not.
448
-     */
449
-    private function _supports_page_templates($cpt_name)
450
-    {
451
-
452
-        $cpt_args = EE_Register_CPTs::get_CPTs();
453
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
454
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
455
-
456
-        //if the installed version of WP is > 4.7 we do some additional checks.
457
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
458
-            $post_templates = wp_get_theme()->get_post_templates();
459
-            //if there are $post_templates for this cpt, then we return false for this method because
460
-            //that means we aren't going to load our page template manager and leave that up to the native
461
-            //cpt template manager.
462
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
463
-        }
464
-
465
-        return $cpt_has_support;
466
-    }
467
-
468
-
469
-    /**
470
-     * Callback for the page_templates metabox selector.
471
-     *
472
-     * @since %VER%
473
-     * @return void
474
-     */
475
-    public function page_template_meta_box()
476
-    {
477
-        global $post;
478
-        $template = '';
479
-
480
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
481
-            $page_template_count = count(get_page_templates());
482
-        } else {
483
-            $page_template_count = count(get_page_templates($post));
484
-        };
485
-
486
-        if ($page_template_count) {
487
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
488
-            $template      = ! empty($page_template) ? $page_template : '';
489
-        }
490
-        ?>
282
+		//filter _autosave_containers
283
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
284
+			$this->_autosave_containers, $this);
285
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
286
+			$containers, $this);
287
+
288
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
289
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
+
291
+		$unsaved_data_msg = array(
292
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
293
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
294
+			'inputChanged' => 0,
295
+		);
296
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
297
+	}
298
+
299
+
300
+
301
+	public function load_page_dependencies()
302
+	{
303
+		try {
304
+			$this->_load_page_dependencies();
305
+		} catch (EE_Error $e) {
306
+			$e->get_error();
307
+		}
308
+	}
309
+
310
+
311
+
312
+	/**
313
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
314
+	 *
315
+	 * @access protected
316
+	 * @return void
317
+	 */
318
+	protected function _load_page_dependencies()
319
+	{
320
+		//we only add stuff if this is a cpt_route!
321
+		if ( ! $this->_cpt_route) {
322
+			parent::_load_page_dependencies();
323
+			return;
324
+		}
325
+		// now let's do some automatic filters into the wp_system
326
+		// and we'll check to make sure the CHILD class
327
+		// automatically has the required methods in place.
328
+		// the following filters are for setting all the redirects
329
+		// on DEFAULT WP custom post type actions
330
+		// let's add a hidden input to the post-edit form
331
+		// so we know when we have to trigger our custom redirects!
332
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
333
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
334
+		// inject our Admin page nav tabs...
335
+		// let's make sure the nav tabs are set if they aren't already
336
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
337
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
338
+		// modify the post_updated messages array
339
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
340
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
341
+		// cpts use the same format for shortlinks as posts!
342
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
343
+		// This basically allows us to change the title of the "publish" metabox area
344
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
345
+		if ( ! empty($this->_labels['publishbox'])) {
346
+			$box_label = is_array($this->_labels['publishbox'])
347
+						 && isset($this->_labels['publishbox'][$this->_req_action])
348
+					? $this->_labels['publishbox'][$this->_req_action]
349
+					: $this->_labels['publishbox'];
350
+			add_meta_box(
351
+				'submitdiv',
352
+				$box_label,
353
+				'post_submit_meta_box',
354
+				$this->_cpt_routes[$this->_req_action],
355
+				'side',
356
+				'core'
357
+			);
358
+		}
359
+		//let's add page_templates metabox if this cpt added support for it.
360
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
361
+			add_meta_box(
362
+				'page_templates',
363
+				__('Page Template', 'event_espresso'),
364
+				array($this, 'page_template_meta_box'),
365
+				$this->_cpt_routes[$this->_req_action],
366
+				'side',
367
+				'default'
368
+			);
369
+		}
370
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
371
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
372
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
373
+		}
374
+		//add preview button
375
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
376
+		//insert our own post_stati dropdown
377
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
378
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
379
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
380
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
381
+		}
382
+		// This allows for adding additional stuff after the title field on the wp post edit form.
383
+		// This is also before the wp_editor for post description field.
384
+		if (method_exists($this, 'edit_form_after_title')) {
385
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
386
+		}
387
+		/**
388
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
389
+		 */
390
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
391
+		parent::_load_page_dependencies();
392
+		// notice we are ALSO going to load the pagenow hook set for this route
393
+		// (see _before_page_setup for the reset of the pagenow global ).
394
+		// This is for any plugins that are doing things properly
395
+		// and hooking into the load page hook for core wp cpt routes.
396
+		global $pagenow;
397
+		do_action('load-' . $pagenow);
398
+		$this->modify_current_screen();
399
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
400
+		//we route REALLY early.
401
+		try {
402
+			$this->_route_admin_request();
403
+		} catch (EE_Error $e) {
404
+			$e->get_error();
405
+		}
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
412
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
413
+	 * route instead.
414
+	 *
415
+	 * @param string $good_protocol_url The escaped url.
416
+	 * @param string $original_url      The original url.
417
+	 * @param string $_context          The context sent to the esc_url method.
418
+	 * @return string possibly a new url for our route.
419
+	 */
420
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
421
+	{
422
+		$routes_to_match = array(
423
+			0 => array(
424
+				'edit.php?post_type=espresso_attendees',
425
+				'admin.php?page=espresso_registrations&action=contact_list',
426
+			),
427
+			1 => array(
428
+				'edit.php?post_type=' . $this->_cpt_object->name,
429
+				'admin.php?page=' . $this->_cpt_object->name,
430
+			),
431
+		);
432
+		foreach ($routes_to_match as $route_matches) {
433
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
434
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
435
+			}
436
+		}
437
+		return $good_protocol_url;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * Determine whether the current cpt supports page templates or not.
444
+	 *
445
+	 * @since %VER%
446
+	 * @param string $cpt_name The cpt slug we're checking on.
447
+	 * @return bool True supported, false not.
448
+	 */
449
+	private function _supports_page_templates($cpt_name)
450
+	{
451
+
452
+		$cpt_args = EE_Register_CPTs::get_CPTs();
453
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
454
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
455
+
456
+		//if the installed version of WP is > 4.7 we do some additional checks.
457
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
458
+			$post_templates = wp_get_theme()->get_post_templates();
459
+			//if there are $post_templates for this cpt, then we return false for this method because
460
+			//that means we aren't going to load our page template manager and leave that up to the native
461
+			//cpt template manager.
462
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
463
+		}
464
+
465
+		return $cpt_has_support;
466
+	}
467
+
468
+
469
+	/**
470
+	 * Callback for the page_templates metabox selector.
471
+	 *
472
+	 * @since %VER%
473
+	 * @return void
474
+	 */
475
+	public function page_template_meta_box()
476
+	{
477
+		global $post;
478
+		$template = '';
479
+
480
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
481
+			$page_template_count = count(get_page_templates());
482
+		} else {
483
+			$page_template_count = count(get_page_templates($post));
484
+		};
485
+
486
+		if ($page_template_count) {
487
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
488
+			$template      = ! empty($page_template) ? $page_template : '';
489
+		}
490
+		?>
491 491
         <p><strong><?php _e('Template') ?></strong></p>
492 492
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
493 493
             name="page_template" id="page_template">
@@ -495,452 +495,452 @@  discard block
 block discarded – undo
495 495
         <?php page_template_dropdown($template); ?>
496 496
     </select>
497 497
         <?php
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
504
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
505
-     *
506
-     * @param  string $return    the current html
507
-     * @param  int    $id        the post id for the page
508
-     * @param  string $new_title What the title is
509
-     * @param  string $new_slug  what the slug is
510
-     * @return string            The new html string for the permalink area
511
-     */
512
-    public function preview_button_html($return, $id, $new_title, $new_slug)
513
-    {
514
-        $post = get_post($id);
515
-        if ('publish' !== get_post_status($post)) {
516
-            //include shims for the `get_preview_post_link` function
517
-            require_once( EE_CORE . 'wordpress-shims.php' );
518
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
519
-                       . get_preview_post_link($id)
520
-                       . '" class="button button-small">'
521
-                       . __('Preview', 'event_espresso')
522
-                       . '</a></span>'
523
-                       . "\n";
524
-        }
525
-        return $return;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * add our custom post stati dropdown on the wp post page for this cpt
532
-     *
533
-     * @return void
534
-     */
535
-    public function custom_post_stati_dropdown()
536
-    {
537
-
538
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
539
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
540
-            ? $statuses[$this->_cpt_model_obj->status()]
541
-            : '';
542
-        $template_args    = array(
543
-            'cur_status'            => $this->_cpt_model_obj->status(),
544
-            'statuses'              => $statuses,
545
-            'cur_status_label'      => $cur_status_label,
546
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
547
-        );
548
-        //we'll add a trash post status (WP doesn't add one for some reason)
549
-        if ($this->_cpt_model_obj->status() === 'trash') {
550
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
551
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
552
-            $template_args['statuses']         = $statuses;
553
-        }
554
-
555
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
556
-        EEH_Template::display_template($template, $template_args);
557
-    }
558
-
559
-
560
-
561
-    public function setup_autosave_hooks()
562
-    {
563
-        $this->_set_autosave_containers();
564
-        $this->_load_autosave_scripts_styles();
565
-    }
566
-
567
-
568
-
569
-    /**
570
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
571
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
572
-     * for the nonce in here, but then this method looks for two things:
573
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
574
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
575
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
576
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
577
-     * template args.
578
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
579
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
580
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
581
-     *    $this->_template_args['data']['items'] = array(
582
-     *        'event-datetime-ids' => '1,2,3';
583
-     *    );
584
-     *    Keep in mind the following things:
585
-     *    - "where" index is for the input with the id as that string.
586
-     *    - "what" index is what will be used for the value of that input.
587
-     *
588
-     * @return void
589
-     */
590
-    public function do_extra_autosave_stuff()
591
-    {
592
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
593
-        $nonce = isset($this->_req_data['autosavenonce'])
594
-                ? $this->_req_data['autosavenonce']
595
-                : null;
596
-        $this->_verify_nonce($nonce, 'autosave');
597
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
598
-        if ( ! defined('DOING_AUTOSAVE')) {
599
-            define('DOING_AUTOSAVE', true);
600
-        }
601
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
602
-        $autosave = "_ee_autosave_{$this->_current_view}";
603
-        if (method_exists($this, $autosave)) {
604
-            $this->$autosave();
605
-        } else {
606
-            $this->_template_args['success'] = true;
607
-        }
608
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
609
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
610
-        //now let's return json
611
-        $this->_return_json();
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
-     *
621
-     * @access protected
622
-     * @throws EE_Error
623
-     * @return void
624
-     */
625
-    protected function _extend_page_config_for_cpt()
626
-    {
627
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
-            return;
630
-        }
631
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
-        if ( ! empty($this->_cpt_object)) {
633
-            $this->_page_routes = array_merge(array(
634
-                'create_new' => '_create_new_cpt_item',
635
-                'edit'       => '_edit_cpt_item',
636
-            ), $this->_page_routes);
637
-            $this->_page_config = array_merge(array(
638
-                'create_new' => array(
639
-                    'nav'           => array(
640
-                        'label' => $this->_cpt_object->labels->add_new_item,
641
-                        'order' => 5,
642
-                    ),
643
-                    'require_nonce' => false,
644
-                ),
645
-                'edit'       => array(
646
-                    'nav'           => array(
647
-                        'label'      => $this->_cpt_object->labels->edit_item,
648
-                        'order'      => 5,
649
-                        'persistent' => false,
650
-                        'url'        => '',
651
-                    ),
652
-                    'require_nonce' => false,
653
-                ),
654
-            ),
655
-                $this->_page_config
656
-            );
657
-        }
658
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
659
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
660
-            return;
661
-        }
662
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
663
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
664
-        if (empty($this->_cpt_object)) {
665
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
666
-                $this->page_slug, $this->_req_action, get_class($this));
667
-            throw new EE_Error($msg);
668
-        }
669
-        if ($this->_cpt_route) {
670
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
671
-            $this->_set_model_object($id);
672
-        }
673
-    }
674
-
675
-
676
-
677
-    /**
678
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
679
-     *
680
-     * @access protected
681
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
682
-     * @param bool $ignore_route_check
683
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
684
-     * @throws EE_Error
685
-     */
686
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
687
-    {
688
-        $model = null;
689
-        if (
690
-            empty($this->_cpt_model_names)
691
-            || (
692
-                ! $ignore_route_check
693
-                && ! isset($this->_cpt_routes[$this->_req_action])
694
-            ) || (
695
-                $this->_cpt_model_obj instanceof EE_CPT_Base
696
-                && $this->_cpt_model_obj->ID() === $id
697
-            )
698
-        ) {
699
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
700
-            return;
701
-        }
702
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
703
-        if ($ignore_route_check) {
704
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
705
-            $post_type   = get_post_type($id);
706
-            if (isset($model_names[$post_type])) {
707
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
708
-            }
709
-        } else {
710
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
711
-        }
712
-        if ($model instanceof EEM_Base) {
713
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
714
-        }
715
-        do_action(
716
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
717
-            $this->_cpt_model_obj,
718
-            $req_type
719
-        );
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     * admin_init_global
726
-     * This runs all the code that we want executed within the WP admin_init hook.
727
-     * This method executes for ALL EE Admin pages.
728
-     *
729
-     * @access public
730
-     * @return void
731
-     */
732
-    public function admin_init_global()
733
-    {
734
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
735
-        //its possible this is a new save so let's catch that instead
736
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
737
-        $post_type = $post ? $post->post_type : false;
738
-        $current_route = isset($this->_req_data['current_route'])
739
-            ? $this->_req_data['current_route']
740
-            : 'shouldneverwork';
741
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
742
-            ? $this->_cpt_routes[$current_route]
743
-            : '';
744
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
745
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
746
-        if ($post_type === $route_to_check) {
747
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
748
-            //catch trashed wp redirect
749
-            add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
750
-        }
751
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
752
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
753
-        if ( ! empty($revision)) {
754
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
755
-            //doing a restore?
756
-            if ( ! empty($action) && $action === 'restore') {
757
-                //get post for revision
758
-                $rev_post = get_post($revision);
759
-                $rev_parent = get_post($rev_post->post_parent);
760
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
761
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
762
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
763
-                    //restores of revisions
764
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
765
-                }
766
-            }
767
-        }
768
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
769
-        if ($post_type && $post_type === $route_to_check) {
770
-            //$post_id, $post
771
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
772
-            //$post_id
773
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
774
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
775
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
776
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
777
-        }
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     * Callback for the WordPress trashed_post hook.
784
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
785
-     *
786
-     * @param int $post_id
787
-     * @throws \EE_Error
788
-     */
789
-    public function before_trash_cpt_item($post_id)
790
-    {
791
-        $this->_set_model_object($post_id, true, 'trash');
792
-        //if our cpt object isn't existent then get out immediately.
793
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
794
-            return;
795
-        }
796
-        $this->trash_cpt_item($post_id);
797
-    }
798
-
799
-
800
-
801
-    /**
802
-     * Callback for the WordPress untrashed_post hook.
803
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
804
-     *
805
-     * @param $post_id
806
-     * @throws \EE_Error
807
-     */
808
-    public function before_restore_cpt_item($post_id)
809
-    {
810
-        $this->_set_model_object($post_id, true, 'restore');
811
-        //if our cpt object isn't existent then get out immediately.
812
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
813
-            return;
814
-        }
815
-        $this->restore_cpt_item($post_id);
816
-    }
817
-
818
-
819
-
820
-    /**
821
-     * Callback for the WordPress after_delete_post hook.
822
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
823
-     *
824
-     * @param $post_id
825
-     * @throws \EE_Error
826
-     */
827
-    public function before_delete_cpt_item($post_id)
828
-    {
829
-        $this->_set_model_object($post_id, true, 'delete');
830
-        //if our cpt object isn't existent then get out immediately.
831
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
832
-            return;
833
-        }
834
-        $this->delete_cpt_item($post_id);
835
-    }
836
-
837
-
838
-
839
-    /**
840
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
841
-     * accordingly.
842
-     *
843
-     * @access public
844
-     * @throws EE_Error
845
-     * @return void
846
-     */
847
-    public function verify_cpt_object()
848
-    {
849
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
850
-        // verify event object
851
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
852
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
853
-                    'event_espresso'), $label));
854
-        }
855
-        //if auto-draft then throw an error
856
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
857
-            EE_Error::overwrite_errors();
858
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
859
-                    $label), __FILE__, __FUNCTION__, __LINE__);
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * admin_footer_scripts_global
867
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
868
-     * will apply on ALL EE_Admin pages.
869
-     *
870
-     * @access public
871
-     * @return void
872
-     */
873
-    public function admin_footer_scripts_global()
874
-    {
875
-        $this->_add_admin_page_ajax_loading_img();
876
-        $this->_add_admin_page_overlay();
877
-    }
878
-
879
-
880
-
881
-    /**
882
-     * add in any global scripts for cpt routes
883
-     *
884
-     * @return void
885
-     */
886
-    public function load_global_scripts_styles()
887
-    {
888
-        parent::load_global_scripts_styles();
889
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
890
-            //setup custom post status object for localize script but only if we've got a cpt object
891
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
892
-            if ( ! empty($statuses)) {
893
-                //get ALL statuses!
894
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
895
-                //setup object
896
-                $ee_cpt_statuses = array();
897
-                foreach ($statuses as $status => $label) {
898
-                    $ee_cpt_statuses[$status] = array(
899
-                        'label'      => $label,
900
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
901
-                    );
902
-                }
903
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
904
-            }
905
-        }
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
912
-     * insert/updates
913
-     *
914
-     * @param  int     $post_id ID of post being updated
915
-     * @param  WP_Post $post    Post object from WP
916
-     * @param  bool    $update  Whether this is an update or a new save.
917
-     * @return void
918
-     * @throws \EE_Error
919
-     */
920
-    public function insert_update($post_id, $post, $update)
921
-    {
922
-        //make sure that if this is a revision OR trash action that we don't do any updates!
923
-        if (
924
-            isset($this->_req_data['action'])
925
-            && (
926
-                $this->_req_data['action'] === 'restore'
927
-                || $this->_req_data['action'] === 'trash'
928
-            )
929
-        ) {
930
-            return;
931
-        }
932
-        $this->_set_model_object($post_id, true, 'insert_update');
933
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
934
-        if ($update
935
-            && (
936
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
937
-                || $this->_cpt_model_obj->ID() !== $post_id
938
-            )
939
-        ) {
940
-            return;
941
-        }
942
-        //check for autosave and update our req_data property accordingly.
943
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
504
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
505
+	 *
506
+	 * @param  string $return    the current html
507
+	 * @param  int    $id        the post id for the page
508
+	 * @param  string $new_title What the title is
509
+	 * @param  string $new_slug  what the slug is
510
+	 * @return string            The new html string for the permalink area
511
+	 */
512
+	public function preview_button_html($return, $id, $new_title, $new_slug)
513
+	{
514
+		$post = get_post($id);
515
+		if ('publish' !== get_post_status($post)) {
516
+			//include shims for the `get_preview_post_link` function
517
+			require_once( EE_CORE . 'wordpress-shims.php' );
518
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
519
+					   . get_preview_post_link($id)
520
+					   . '" class="button button-small">'
521
+					   . __('Preview', 'event_espresso')
522
+					   . '</a></span>'
523
+					   . "\n";
524
+		}
525
+		return $return;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * add our custom post stati dropdown on the wp post page for this cpt
532
+	 *
533
+	 * @return void
534
+	 */
535
+	public function custom_post_stati_dropdown()
536
+	{
537
+
538
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
539
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
540
+			? $statuses[$this->_cpt_model_obj->status()]
541
+			: '';
542
+		$template_args    = array(
543
+			'cur_status'            => $this->_cpt_model_obj->status(),
544
+			'statuses'              => $statuses,
545
+			'cur_status_label'      => $cur_status_label,
546
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
547
+		);
548
+		//we'll add a trash post status (WP doesn't add one for some reason)
549
+		if ($this->_cpt_model_obj->status() === 'trash') {
550
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
551
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
552
+			$template_args['statuses']         = $statuses;
553
+		}
554
+
555
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
556
+		EEH_Template::display_template($template, $template_args);
557
+	}
558
+
559
+
560
+
561
+	public function setup_autosave_hooks()
562
+	{
563
+		$this->_set_autosave_containers();
564
+		$this->_load_autosave_scripts_styles();
565
+	}
566
+
567
+
568
+
569
+	/**
570
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
571
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
572
+	 * for the nonce in here, but then this method looks for two things:
573
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
574
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
575
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
576
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
577
+	 * template args.
578
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
579
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
580
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
581
+	 *    $this->_template_args['data']['items'] = array(
582
+	 *        'event-datetime-ids' => '1,2,3';
583
+	 *    );
584
+	 *    Keep in mind the following things:
585
+	 *    - "where" index is for the input with the id as that string.
586
+	 *    - "what" index is what will be used for the value of that input.
587
+	 *
588
+	 * @return void
589
+	 */
590
+	public function do_extra_autosave_stuff()
591
+	{
592
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
593
+		$nonce = isset($this->_req_data['autosavenonce'])
594
+				? $this->_req_data['autosavenonce']
595
+				: null;
596
+		$this->_verify_nonce($nonce, 'autosave');
597
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
598
+		if ( ! defined('DOING_AUTOSAVE')) {
599
+			define('DOING_AUTOSAVE', true);
600
+		}
601
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
602
+		$autosave = "_ee_autosave_{$this->_current_view}";
603
+		if (method_exists($this, $autosave)) {
604
+			$this->$autosave();
605
+		} else {
606
+			$this->_template_args['success'] = true;
607
+		}
608
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
609
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
610
+		//now let's return json
611
+		$this->_return_json();
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
+	 *
621
+	 * @access protected
622
+	 * @throws EE_Error
623
+	 * @return void
624
+	 */
625
+	protected function _extend_page_config_for_cpt()
626
+	{
627
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
+			return;
630
+		}
631
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
+		if ( ! empty($this->_cpt_object)) {
633
+			$this->_page_routes = array_merge(array(
634
+				'create_new' => '_create_new_cpt_item',
635
+				'edit'       => '_edit_cpt_item',
636
+			), $this->_page_routes);
637
+			$this->_page_config = array_merge(array(
638
+				'create_new' => array(
639
+					'nav'           => array(
640
+						'label' => $this->_cpt_object->labels->add_new_item,
641
+						'order' => 5,
642
+					),
643
+					'require_nonce' => false,
644
+				),
645
+				'edit'       => array(
646
+					'nav'           => array(
647
+						'label'      => $this->_cpt_object->labels->edit_item,
648
+						'order'      => 5,
649
+						'persistent' => false,
650
+						'url'        => '',
651
+					),
652
+					'require_nonce' => false,
653
+				),
654
+			),
655
+				$this->_page_config
656
+			);
657
+		}
658
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
659
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
660
+			return;
661
+		}
662
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
663
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
664
+		if (empty($this->_cpt_object)) {
665
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
666
+				$this->page_slug, $this->_req_action, get_class($this));
667
+			throw new EE_Error($msg);
668
+		}
669
+		if ($this->_cpt_route) {
670
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
671
+			$this->_set_model_object($id);
672
+		}
673
+	}
674
+
675
+
676
+
677
+	/**
678
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
679
+	 *
680
+	 * @access protected
681
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
682
+	 * @param bool $ignore_route_check
683
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
684
+	 * @throws EE_Error
685
+	 */
686
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
687
+	{
688
+		$model = null;
689
+		if (
690
+			empty($this->_cpt_model_names)
691
+			|| (
692
+				! $ignore_route_check
693
+				&& ! isset($this->_cpt_routes[$this->_req_action])
694
+			) || (
695
+				$this->_cpt_model_obj instanceof EE_CPT_Base
696
+				&& $this->_cpt_model_obj->ID() === $id
697
+			)
698
+		) {
699
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
700
+			return;
701
+		}
702
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
703
+		if ($ignore_route_check) {
704
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
705
+			$post_type   = get_post_type($id);
706
+			if (isset($model_names[$post_type])) {
707
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
708
+			}
709
+		} else {
710
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
711
+		}
712
+		if ($model instanceof EEM_Base) {
713
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
714
+		}
715
+		do_action(
716
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
717
+			$this->_cpt_model_obj,
718
+			$req_type
719
+		);
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 * admin_init_global
726
+	 * This runs all the code that we want executed within the WP admin_init hook.
727
+	 * This method executes for ALL EE Admin pages.
728
+	 *
729
+	 * @access public
730
+	 * @return void
731
+	 */
732
+	public function admin_init_global()
733
+	{
734
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
735
+		//its possible this is a new save so let's catch that instead
736
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
737
+		$post_type = $post ? $post->post_type : false;
738
+		$current_route = isset($this->_req_data['current_route'])
739
+			? $this->_req_data['current_route']
740
+			: 'shouldneverwork';
741
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
742
+			? $this->_cpt_routes[$current_route]
743
+			: '';
744
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
745
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
746
+		if ($post_type === $route_to_check) {
747
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
748
+			//catch trashed wp redirect
749
+			add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
750
+		}
751
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
752
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
753
+		if ( ! empty($revision)) {
754
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
755
+			//doing a restore?
756
+			if ( ! empty($action) && $action === 'restore') {
757
+				//get post for revision
758
+				$rev_post = get_post($revision);
759
+				$rev_parent = get_post($rev_post->post_parent);
760
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
761
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
762
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
763
+					//restores of revisions
764
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
765
+				}
766
+			}
767
+		}
768
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
769
+		if ($post_type && $post_type === $route_to_check) {
770
+			//$post_id, $post
771
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
772
+			//$post_id
773
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
774
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
775
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
776
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
777
+		}
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 * Callback for the WordPress trashed_post hook.
784
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
785
+	 *
786
+	 * @param int $post_id
787
+	 * @throws \EE_Error
788
+	 */
789
+	public function before_trash_cpt_item($post_id)
790
+	{
791
+		$this->_set_model_object($post_id, true, 'trash');
792
+		//if our cpt object isn't existent then get out immediately.
793
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
794
+			return;
795
+		}
796
+		$this->trash_cpt_item($post_id);
797
+	}
798
+
799
+
800
+
801
+	/**
802
+	 * Callback for the WordPress untrashed_post hook.
803
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
804
+	 *
805
+	 * @param $post_id
806
+	 * @throws \EE_Error
807
+	 */
808
+	public function before_restore_cpt_item($post_id)
809
+	{
810
+		$this->_set_model_object($post_id, true, 'restore');
811
+		//if our cpt object isn't existent then get out immediately.
812
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
813
+			return;
814
+		}
815
+		$this->restore_cpt_item($post_id);
816
+	}
817
+
818
+
819
+
820
+	/**
821
+	 * Callback for the WordPress after_delete_post hook.
822
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
823
+	 *
824
+	 * @param $post_id
825
+	 * @throws \EE_Error
826
+	 */
827
+	public function before_delete_cpt_item($post_id)
828
+	{
829
+		$this->_set_model_object($post_id, true, 'delete');
830
+		//if our cpt object isn't existent then get out immediately.
831
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
832
+			return;
833
+		}
834
+		$this->delete_cpt_item($post_id);
835
+	}
836
+
837
+
838
+
839
+	/**
840
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
841
+	 * accordingly.
842
+	 *
843
+	 * @access public
844
+	 * @throws EE_Error
845
+	 * @return void
846
+	 */
847
+	public function verify_cpt_object()
848
+	{
849
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
850
+		// verify event object
851
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
852
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
853
+					'event_espresso'), $label));
854
+		}
855
+		//if auto-draft then throw an error
856
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
857
+			EE_Error::overwrite_errors();
858
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
859
+					$label), __FILE__, __FUNCTION__, __LINE__);
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * admin_footer_scripts_global
867
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
868
+	 * will apply on ALL EE_Admin pages.
869
+	 *
870
+	 * @access public
871
+	 * @return void
872
+	 */
873
+	public function admin_footer_scripts_global()
874
+	{
875
+		$this->_add_admin_page_ajax_loading_img();
876
+		$this->_add_admin_page_overlay();
877
+	}
878
+
879
+
880
+
881
+	/**
882
+	 * add in any global scripts for cpt routes
883
+	 *
884
+	 * @return void
885
+	 */
886
+	public function load_global_scripts_styles()
887
+	{
888
+		parent::load_global_scripts_styles();
889
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
890
+			//setup custom post status object for localize script but only if we've got a cpt object
891
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
892
+			if ( ! empty($statuses)) {
893
+				//get ALL statuses!
894
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
895
+				//setup object
896
+				$ee_cpt_statuses = array();
897
+				foreach ($statuses as $status => $label) {
898
+					$ee_cpt_statuses[$status] = array(
899
+						'label'      => $label,
900
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
901
+					);
902
+				}
903
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
904
+			}
905
+		}
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
912
+	 * insert/updates
913
+	 *
914
+	 * @param  int     $post_id ID of post being updated
915
+	 * @param  WP_Post $post    Post object from WP
916
+	 * @param  bool    $update  Whether this is an update or a new save.
917
+	 * @return void
918
+	 * @throws \EE_Error
919
+	 */
920
+	public function insert_update($post_id, $post, $update)
921
+	{
922
+		//make sure that if this is a revision OR trash action that we don't do any updates!
923
+		if (
924
+			isset($this->_req_data['action'])
925
+			&& (
926
+				$this->_req_data['action'] === 'restore'
927
+				|| $this->_req_data['action'] === 'trash'
928
+			)
929
+		) {
930
+			return;
931
+		}
932
+		$this->_set_model_object($post_id, true, 'insert_update');
933
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
934
+		if ($update
935
+			&& (
936
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
937
+				|| $this->_cpt_model_obj->ID() !== $post_id
938
+			)
939
+		) {
940
+			return;
941
+		}
942
+		//check for autosave and update our req_data property accordingly.
943
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
944 944
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
945 945
 
946 946
                 foreach ( (array) $values as $key => $value ) {
@@ -950,536 +950,536 @@  discard block
 block discarded – undo
950 950
 
951 951
         }/**/ //TODO reactivate after autosave is implemented in 4.2
952 952
 
953
-        //take care of updating any selected page_template IF this cpt supports it.
954
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
955
-            //wp version aware.
956
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
957
-                $page_templates = wp_get_theme()->get_page_templates();
958
-            } else {
959
-                $post->page_template = $this->_req_data['page_template'];
960
-                $page_templates      = wp_get_theme()->get_page_templates($post);
961
-            }
962
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
963
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
964
-            } else {
965
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
966
-            }
967
-        }
968
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
969
-            return;
970
-        } //TODO we'll remove this after reimplementing autosave in 4.2
971
-        $this->_insert_update_cpt_item($post_id, $post);
972
-    }
973
-
974
-
975
-
976
-    /**
977
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
978
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
979
-     * so we don't have to check for our CPT.
980
-     *
981
-     * @param  int $post_id ID of the post
982
-     * @return void
983
-     */
984
-    public function dont_permanently_delete_ee_cpts($post_id)
985
-    {
986
-        //only do this if we're actually processing one of our CPTs
987
-        //if our cpt object isn't existent then get out immediately.
988
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
989
-            return;
990
-        }
991
-        delete_post_meta($post_id, '_wp_trash_meta_status');
992
-        delete_post_meta($post_id, '_wp_trash_meta_time');
993
-        //our cpts may have comments so let's take care of that too
994
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
995
-    }
996
-
997
-
998
-
999
-    /**
1000
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1001
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1002
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1003
-     *
1004
-     * @param  int $post_id     ID of cpt item
1005
-     * @param  int $revision_id ID of revision being restored
1006
-     * @return void
1007
-     */
1008
-    public function restore_revision($post_id, $revision_id)
1009
-    {
1010
-        $this->_restore_cpt_item($post_id, $revision_id);
1011
-        //global action
1012
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1013
-        //class specific action so you can limit hooking into a specific page.
1014
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1015
-    }
1016
-
1017
-
1018
-
1019
-    /**
1020
-     * @see restore_revision() for details
1021
-     * @param  int $post_id     ID of cpt item
1022
-     * @param  int $revision_id ID of revision for item
1023
-     * @return void
1024
-     */
1025
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1026
-
1027
-
1028
-
1029
-    /**
1030
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1031
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1032
-     * To fix we have to reset the current_screen using the page_slug
1033
-     * (which is identical - or should be - to our registered_post_type id.)
1034
-     * Also, since the core WP file loads the admin_header.php for WP
1035
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1036
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1037
-     *
1038
-     * @return void
1039
-     */
1040
-    public function modify_current_screen()
1041
-    {
1042
-        //ONLY do this if the current page_route IS a cpt route
1043
-        if ( ! $this->_cpt_route) {
1044
-            return;
1045
-        }
1046
-        //routing things REALLY early b/c this is a cpt admin page
1047
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1048
-        $this->_current_screen       = get_current_screen();
1049
-        $this->_current_screen->base = 'event-espresso';
1050
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1051
-        /*try {
953
+		//take care of updating any selected page_template IF this cpt supports it.
954
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
955
+			//wp version aware.
956
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
957
+				$page_templates = wp_get_theme()->get_page_templates();
958
+			} else {
959
+				$post->page_template = $this->_req_data['page_template'];
960
+				$page_templates      = wp_get_theme()->get_page_templates($post);
961
+			}
962
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
963
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
964
+			} else {
965
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
966
+			}
967
+		}
968
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
969
+			return;
970
+		} //TODO we'll remove this after reimplementing autosave in 4.2
971
+		$this->_insert_update_cpt_item($post_id, $post);
972
+	}
973
+
974
+
975
+
976
+	/**
977
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
978
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
979
+	 * so we don't have to check for our CPT.
980
+	 *
981
+	 * @param  int $post_id ID of the post
982
+	 * @return void
983
+	 */
984
+	public function dont_permanently_delete_ee_cpts($post_id)
985
+	{
986
+		//only do this if we're actually processing one of our CPTs
987
+		//if our cpt object isn't existent then get out immediately.
988
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
989
+			return;
990
+		}
991
+		delete_post_meta($post_id, '_wp_trash_meta_status');
992
+		delete_post_meta($post_id, '_wp_trash_meta_time');
993
+		//our cpts may have comments so let's take care of that too
994
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
995
+	}
996
+
997
+
998
+
999
+	/**
1000
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1001
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1002
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1003
+	 *
1004
+	 * @param  int $post_id     ID of cpt item
1005
+	 * @param  int $revision_id ID of revision being restored
1006
+	 * @return void
1007
+	 */
1008
+	public function restore_revision($post_id, $revision_id)
1009
+	{
1010
+		$this->_restore_cpt_item($post_id, $revision_id);
1011
+		//global action
1012
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1013
+		//class specific action so you can limit hooking into a specific page.
1014
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1015
+	}
1016
+
1017
+
1018
+
1019
+	/**
1020
+	 * @see restore_revision() for details
1021
+	 * @param  int $post_id     ID of cpt item
1022
+	 * @param  int $revision_id ID of revision for item
1023
+	 * @return void
1024
+	 */
1025
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1026
+
1027
+
1028
+
1029
+	/**
1030
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1031
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1032
+	 * To fix we have to reset the current_screen using the page_slug
1033
+	 * (which is identical - or should be - to our registered_post_type id.)
1034
+	 * Also, since the core WP file loads the admin_header.php for WP
1035
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1036
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1037
+	 *
1038
+	 * @return void
1039
+	 */
1040
+	public function modify_current_screen()
1041
+	{
1042
+		//ONLY do this if the current page_route IS a cpt route
1043
+		if ( ! $this->_cpt_route) {
1044
+			return;
1045
+		}
1046
+		//routing things REALLY early b/c this is a cpt admin page
1047
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1048
+		$this->_current_screen       = get_current_screen();
1049
+		$this->_current_screen->base = 'event-espresso';
1050
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1051
+		/*try {
1052 1052
             $this->_route_admin_request();
1053 1053
         } catch ( EE_Error $e ) {
1054 1054
             $e->get_error();
1055 1055
         }/**/
1056
-    }
1057
-
1058
-
1059
-
1060
-    /**
1061
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1062
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1063
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1064
-     * default to be.
1065
-     *
1066
-     * @param string $title The new title (or existing if there is no editor_title defined)
1067
-     * @return string
1068
-     */
1069
-    public function add_custom_editor_default_title($title)
1070
-    {
1071
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1072
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1073
-            : $title;
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1080
-     *
1081
-     * @param string $shortlink   The already generated shortlink
1082
-     * @param int    $id          Post ID for this item
1083
-     * @param string $context     The context for the link
1084
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1085
-     * @return string
1086
-     */
1087
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1088
-    {
1089
-        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1090
-            $post = get_post($id);
1091
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1092
-                $shortlink = home_url('?p=' . $post->ID);
1093
-            }
1094
-        }
1095
-        return $shortlink;
1096
-    }
1097
-
1098
-
1099
-
1100
-    /**
1101
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1102
-     * already run in modify_current_screen())
1103
-     *
1104
-     * @return void
1105
-     */
1106
-    public function route_admin_request()
1107
-    {
1108
-        if ($this->_cpt_route) {
1109
-            return;
1110
-        }
1111
-        try {
1112
-            $this->_route_admin_request();
1113
-        } catch (EE_Error $e) {
1114
-            $e->get_error();
1115
-        }
1116
-    }
1117
-
1118
-
1119
-
1120
-    /**
1121
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1122
-     *
1123
-     * @return void
1124
-     */
1125
-    public function cpt_post_form_hidden_input()
1126
-    {
1127
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1128
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1129
-        echo '<div id="ee-cpt-hidden-inputs">';
1130
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1131
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1132
-        echo '</div>';
1133
-    }
1134
-
1135
-
1136
-
1137
-    /**
1138
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1139
-     *
1140
-     * @param  string $location Original location url
1141
-     * @param  int    $status   Status for http header
1142
-     * @return string           new (or original) url to redirect to.
1143
-     */
1144
-    public function revision_redirect($location, $status)
1145
-    {
1146
-        //get revision
1147
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1148
-        //can't do anything without revision so let's get out if not present
1149
-        if (empty($rev_id)) {
1150
-            return $location;
1151
-        }
1152
-        //get rev_post_data
1153
-        $rev = get_post($rev_id);
1154
-        $admin_url = $this->_admin_base_url;
1155
-        $query_args = array(
1156
-            'action'   => 'edit',
1157
-            'post'     => $rev->post_parent,
1158
-            'revision' => $rev_id,
1159
-            'message'  => 5,
1160
-        );
1161
-        $this->_process_notices($query_args, true);
1162
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1169
-     *
1170
-     * @param  string $link    the original generated link
1171
-     * @param  int    $id      post id
1172
-     * @param  string $context optional, defaults to display.  How to write the '&'
1173
-     * @return string          the link
1174
-     */
1175
-    public function modify_edit_post_link($link, $id, $context)
1176
-    {
1177
-        $post = get_post($id);
1178
-        if ( ! isset($this->_req_data['action'])
1179
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1180
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1181
-        ) {
1182
-            return $link;
1183
-        }
1184
-        $query_args = array(
1185
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1186
-                ? $this->_cpt_edit_routes[$post->post_type]
1187
-                : 'edit',
1188
-            'post'   => $id,
1189
-        );
1190
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1191
-    }
1192
-
1193
-
1194
-
1195
-    /**
1196
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1197
-     * our routes.
1198
-     *
1199
-     * @param  string $delete_link  original delete link
1200
-     * @param  int    $post_id      id of cpt object
1201
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1202
-     * @return string               new delete link
1203
-     */
1204
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1205
-    {
1206
-        $post = get_post($post_id);
1207
-        if ( ! isset($this->_req_data['action'])
1208
-             || (isset($this->_cpt_routes[$this->_req_data['action']])
1209
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1210
-        ) {
1211
-            return $delete_link;
1212
-        }
1213
-        return add_query_arg(array('current_route' => 'trash'), $delete_link);
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1220
-     * route
1221
-     *
1222
-     * @param  string $location url
1223
-     * @param  string $status   status
1224
-     * @return string           url to redirect to
1225
-     */
1226
-    public function cpt_trash_post_location_redirect($location, $status)
1227
-    {
1228
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1229
-            return $location;
1230
-        }
1231
-
1232
-        $post              = get_post($this->_req_data['post']);
1233
-        $query_args        = array('action' => 'default');
1234
-        $this->_cpt_object = get_post_type_object($post->post_type);
1235
-        EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1236
-        $this->_process_notices($query_args, true);
1237
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1238
-    }
1239
-
1240
-
1241
-
1242
-    /**
1243
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1244
-     * so that we can hijack the default redirect locations for wp custom post types
1245
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1246
-     *
1247
-     * @param  string $location This is the incoming currently set redirect location
1248
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1249
-     * @return string           the new location to redirect to
1250
-     */
1251
-    public function cpt_post_location_redirect($location, $post_id)
1252
-    {
1253
-        //we DO have a match so let's setup the url
1254
-        //we have to get the post to determine our route
1255
-        $post       = get_post($post_id);
1256
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1257
-        //shared query_args
1258
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1259
-        $admin_url  = $this->_admin_base_url;
1260
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1261
-            $status = get_post_status($post_id);
1262
-            if (isset($this->_req_data['publish'])) {
1263
-                switch ($status) {
1264
-                    case 'pending':
1265
-                        $message = 8;
1266
-                        break;
1267
-                    case 'future':
1268
-                        $message = 9;
1269
-                        break;
1270
-                    default:
1271
-                        $message = 6;
1272
-                }
1273
-            } else {
1274
-                $message = 'draft' === $status ? 10 : 1;
1275
-            }
1276
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1277
-            $message = 2;
1278
-            //			$append = '#postcustom';
1279
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1280
-            $message = 3;
1281
-            //			$append = '#postcustom';
1282
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1283
-            $message = 7;
1284
-        } else {
1285
-            $message = 4;
1286
-        }
1287
-        //change the message if the post type is not viewable on the frontend
1288
-        $this->_cpt_object = get_post_type_object($post->post_type);
1289
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1290
-        $query_args = array_merge(array('message' => $message), $query_args);
1291
-        $this->_process_notices($query_args, true);
1292
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1293
-    }
1294
-
1295
-
1296
-
1297
-    /**
1298
-     * This method is called to inject nav tabs on core WP cpt pages
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function inject_nav_tabs()
1304
-    {
1305
-        //can we hijack and insert the nav_tabs?
1306
-        $nav_tabs = $this->_get_main_nav_tabs();
1307
-        //first close off existing form tag
1308
-        $html = '>';
1309
-        $html .= $nav_tabs;
1310
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1311
-        $html .= '<span></span';
1312
-        echo $html;
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * This just sets up the post update messages when an update form is loaded
1319
-     *
1320
-     * @access public
1321
-     * @param  array $messages the original messages array
1322
-     * @return array           the new messages array
1323
-     */
1324
-    public function post_update_messages($messages)
1325
-    {
1326
-        global $post;
1327
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1328
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1329
-        //		$post_type = $post ? $post->post_type : false;
1330
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1056
+	}
1057
+
1058
+
1059
+
1060
+	/**
1061
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1062
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1063
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1064
+	 * default to be.
1065
+	 *
1066
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1067
+	 * @return string
1068
+	 */
1069
+	public function add_custom_editor_default_title($title)
1070
+	{
1071
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1072
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1073
+			: $title;
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1080
+	 *
1081
+	 * @param string $shortlink   The already generated shortlink
1082
+	 * @param int    $id          Post ID for this item
1083
+	 * @param string $context     The context for the link
1084
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1085
+	 * @return string
1086
+	 */
1087
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1088
+	{
1089
+		if ( ! empty($id) && get_option('permalink_structure') !== '') {
1090
+			$post = get_post($id);
1091
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1092
+				$shortlink = home_url('?p=' . $post->ID);
1093
+			}
1094
+		}
1095
+		return $shortlink;
1096
+	}
1097
+
1098
+
1099
+
1100
+	/**
1101
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1102
+	 * already run in modify_current_screen())
1103
+	 *
1104
+	 * @return void
1105
+	 */
1106
+	public function route_admin_request()
1107
+	{
1108
+		if ($this->_cpt_route) {
1109
+			return;
1110
+		}
1111
+		try {
1112
+			$this->_route_admin_request();
1113
+		} catch (EE_Error $e) {
1114
+			$e->get_error();
1115
+		}
1116
+	}
1117
+
1118
+
1119
+
1120
+	/**
1121
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1122
+	 *
1123
+	 * @return void
1124
+	 */
1125
+	public function cpt_post_form_hidden_input()
1126
+	{
1127
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1128
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1129
+		echo '<div id="ee-cpt-hidden-inputs">';
1130
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1131
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1132
+		echo '</div>';
1133
+	}
1134
+
1135
+
1136
+
1137
+	/**
1138
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1139
+	 *
1140
+	 * @param  string $location Original location url
1141
+	 * @param  int    $status   Status for http header
1142
+	 * @return string           new (or original) url to redirect to.
1143
+	 */
1144
+	public function revision_redirect($location, $status)
1145
+	{
1146
+		//get revision
1147
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1148
+		//can't do anything without revision so let's get out if not present
1149
+		if (empty($rev_id)) {
1150
+			return $location;
1151
+		}
1152
+		//get rev_post_data
1153
+		$rev = get_post($rev_id);
1154
+		$admin_url = $this->_admin_base_url;
1155
+		$query_args = array(
1156
+			'action'   => 'edit',
1157
+			'post'     => $rev->post_parent,
1158
+			'revision' => $rev_id,
1159
+			'message'  => 5,
1160
+		);
1161
+		$this->_process_notices($query_args, true);
1162
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1169
+	 *
1170
+	 * @param  string $link    the original generated link
1171
+	 * @param  int    $id      post id
1172
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1173
+	 * @return string          the link
1174
+	 */
1175
+	public function modify_edit_post_link($link, $id, $context)
1176
+	{
1177
+		$post = get_post($id);
1178
+		if ( ! isset($this->_req_data['action'])
1179
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1180
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1181
+		) {
1182
+			return $link;
1183
+		}
1184
+		$query_args = array(
1185
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1186
+				? $this->_cpt_edit_routes[$post->post_type]
1187
+				: 'edit',
1188
+			'post'   => $id,
1189
+		);
1190
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1191
+	}
1192
+
1193
+
1194
+
1195
+	/**
1196
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1197
+	 * our routes.
1198
+	 *
1199
+	 * @param  string $delete_link  original delete link
1200
+	 * @param  int    $post_id      id of cpt object
1201
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1202
+	 * @return string               new delete link
1203
+	 */
1204
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1205
+	{
1206
+		$post = get_post($post_id);
1207
+		if ( ! isset($this->_req_data['action'])
1208
+			 || (isset($this->_cpt_routes[$this->_req_data['action']])
1209
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1210
+		) {
1211
+			return $delete_link;
1212
+		}
1213
+		return add_query_arg(array('current_route' => 'trash'), $delete_link);
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1220
+	 * route
1221
+	 *
1222
+	 * @param  string $location url
1223
+	 * @param  string $status   status
1224
+	 * @return string           url to redirect to
1225
+	 */
1226
+	public function cpt_trash_post_location_redirect($location, $status)
1227
+	{
1228
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1229
+			return $location;
1230
+		}
1231
+
1232
+		$post              = get_post($this->_req_data['post']);
1233
+		$query_args        = array('action' => 'default');
1234
+		$this->_cpt_object = get_post_type_object($post->post_type);
1235
+		EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1236
+		$this->_process_notices($query_args, true);
1237
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1238
+	}
1239
+
1240
+
1241
+
1242
+	/**
1243
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1244
+	 * so that we can hijack the default redirect locations for wp custom post types
1245
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1246
+	 *
1247
+	 * @param  string $location This is the incoming currently set redirect location
1248
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1249
+	 * @return string           the new location to redirect to
1250
+	 */
1251
+	public function cpt_post_location_redirect($location, $post_id)
1252
+	{
1253
+		//we DO have a match so let's setup the url
1254
+		//we have to get the post to determine our route
1255
+		$post       = get_post($post_id);
1256
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1257
+		//shared query_args
1258
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1259
+		$admin_url  = $this->_admin_base_url;
1260
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1261
+			$status = get_post_status($post_id);
1262
+			if (isset($this->_req_data['publish'])) {
1263
+				switch ($status) {
1264
+					case 'pending':
1265
+						$message = 8;
1266
+						break;
1267
+					case 'future':
1268
+						$message = 9;
1269
+						break;
1270
+					default:
1271
+						$message = 6;
1272
+				}
1273
+			} else {
1274
+				$message = 'draft' === $status ? 10 : 1;
1275
+			}
1276
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1277
+			$message = 2;
1278
+			//			$append = '#postcustom';
1279
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1280
+			$message = 3;
1281
+			//			$append = '#postcustom';
1282
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1283
+			$message = 7;
1284
+		} else {
1285
+			$message = 4;
1286
+		}
1287
+		//change the message if the post type is not viewable on the frontend
1288
+		$this->_cpt_object = get_post_type_object($post->post_type);
1289
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1290
+		$query_args = array_merge(array('message' => $message), $query_args);
1291
+		$this->_process_notices($query_args, true);
1292
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1293
+	}
1294
+
1295
+
1296
+
1297
+	/**
1298
+	 * This method is called to inject nav tabs on core WP cpt pages
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function inject_nav_tabs()
1304
+	{
1305
+		//can we hijack and insert the nav_tabs?
1306
+		$nav_tabs = $this->_get_main_nav_tabs();
1307
+		//first close off existing form tag
1308
+		$html = '>';
1309
+		$html .= $nav_tabs;
1310
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1311
+		$html .= '<span></span';
1312
+		echo $html;
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * This just sets up the post update messages when an update form is loaded
1319
+	 *
1320
+	 * @access public
1321
+	 * @param  array $messages the original messages array
1322
+	 * @return array           the new messages array
1323
+	 */
1324
+	public function post_update_messages($messages)
1325
+	{
1326
+		global $post;
1327
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1328
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1329
+		//		$post_type = $post ? $post->post_type : false;
1330
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1331 1331
 
1332 1332
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1333
-        $messages[$post->post_type] = array(
1334
-            0 => '', //Unused. Messages start at index 1.
1335
-            1 => sprintf(
1336
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1337
-                $this->_cpt_object->labels->singular_name,
1338
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1339
-                '</a>'
1340
-            ),
1341
-            2 => __('Custom field updated'),
1342
-            3 => __('Custom field deleted.'),
1343
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1344
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1345
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1346
-                : false,
1347
-            6 => sprintf(
1348
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1349
-                $this->_cpt_object->labels->singular_name,
1350
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1351
-                '</a>'
1352
-            ),
1353
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1354
-            8 => sprintf(
1355
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1356
-                $this->_cpt_object->labels->singular_name,
1357
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1358
-                '</a>'
1359
-            ),
1360
-            9 => sprintf(
1361
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1362
-                $this->_cpt_object->labels->singular_name,
1363
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1364
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1365
-                '</a>'
1366
-            ),
1367
-            10 => sprintf(
1368
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1369
-                $this->_cpt_object->labels->singular_name,
1370
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1371
-                '</a>'
1372
-            ),
1373
-        );
1374
-        return $messages;
1375
-    }
1376
-
1377
-
1378
-
1379
-    /**
1380
-     * default method for the 'create_new' route for cpt admin pages.
1381
-     * For reference what to include in here, see wp-admin/post-new.php
1382
-     *
1383
-     * @access  protected
1384
-     * @return void
1385
-     */
1386
-    protected function _create_new_cpt_item()
1387
-    {
1388
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1389
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1390
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1391
-        $post_type_object = $this->_cpt_object;
1392
-        $title            = $post_type_object->labels->add_new_item;
1393
-        $editing          = true;
1394
-        wp_enqueue_script('autosave');
1395
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1396
-        $post_ID = $post->ID;
1397
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1398
-        //modify the default editor title field with default title.
1399
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1400
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1401
-    }
1402
-
1403
-
1404
-
1405
-    public function add_new_admin_page_global()
1406
-    {
1407
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1408
-        ?>
1333
+		$messages[$post->post_type] = array(
1334
+			0 => '', //Unused. Messages start at index 1.
1335
+			1 => sprintf(
1336
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1337
+				$this->_cpt_object->labels->singular_name,
1338
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1339
+				'</a>'
1340
+			),
1341
+			2 => __('Custom field updated'),
1342
+			3 => __('Custom field deleted.'),
1343
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1344
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1345
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1346
+				: false,
1347
+			6 => sprintf(
1348
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1349
+				$this->_cpt_object->labels->singular_name,
1350
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1351
+				'</a>'
1352
+			),
1353
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1354
+			8 => sprintf(
1355
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1356
+				$this->_cpt_object->labels->singular_name,
1357
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1358
+				'</a>'
1359
+			),
1360
+			9 => sprintf(
1361
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1362
+				$this->_cpt_object->labels->singular_name,
1363
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1364
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1365
+				'</a>'
1366
+			),
1367
+			10 => sprintf(
1368
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1369
+				$this->_cpt_object->labels->singular_name,
1370
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1371
+				'</a>'
1372
+			),
1373
+		);
1374
+		return $messages;
1375
+	}
1376
+
1377
+
1378
+
1379
+	/**
1380
+	 * default method for the 'create_new' route for cpt admin pages.
1381
+	 * For reference what to include in here, see wp-admin/post-new.php
1382
+	 *
1383
+	 * @access  protected
1384
+	 * @return void
1385
+	 */
1386
+	protected function _create_new_cpt_item()
1387
+	{
1388
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1389
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1390
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1391
+		$post_type_object = $this->_cpt_object;
1392
+		$title            = $post_type_object->labels->add_new_item;
1393
+		$editing          = true;
1394
+		wp_enqueue_script('autosave');
1395
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1396
+		$post_ID = $post->ID;
1397
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1398
+		//modify the default editor title field with default title.
1399
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1400
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1401
+	}
1402
+
1403
+
1404
+
1405
+	public function add_new_admin_page_global()
1406
+	{
1407
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1408
+		?>
1409 1409
         <script type="text/javascript">
1410 1410
             adminpage = '<?php echo $admin_page; ?>';
1411 1411
         </script>
1412 1412
         <?php
1413
-    }
1414
-
1415
-
1416
-
1417
-    /**
1418
-     * default method for the 'edit' route for cpt admin pages
1419
-     * For reference on what to put in here, refer to wp-admin/post.php
1420
-     *
1421
-     * @access protected
1422
-     * @return string   template for edit cpt form
1423
-     */
1424
-    protected function _edit_cpt_item()
1425
-    {
1426
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1427
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1428
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1429
-        if (empty ($post)) {
1430
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1431
-        }
1432
-        if ( ! empty($_GET['get-post-lock'])) {
1433
-            wp_set_post_lock($post_id);
1434
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1435
-            exit();
1436
-        }
1437
-
1438
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1439
-        $editing          = true;
1440
-        $post_ID          = $post_id;
1441
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1442
-        $post_type_object = $this->_cpt_object;
1443
-
1444
-        if ( ! wp_check_post_lock($post->ID)) {
1445
-            $active_post_lock = wp_set_post_lock($post->ID);
1446
-            //wp_enqueue_script('autosave');
1447
-        }
1448
-        $title = $this->_cpt_object->labels->edit_item;
1449
-        add_action('admin_footer', '_admin_notice_post_locked');
1450
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1451
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1452
-        ) {
1453
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1454
-                'create_new', $this);
1455
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1456
-                'action' => $create_new_action,
1457
-                'page'   => $this->page_slug,
1458
-            ), 'admin.php');
1459
-        }
1460
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1461
-            wp_enqueue_script('admin-comments');
1462
-            enqueue_comment_hotkeys_js();
1463
-        }
1464
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1465
-        //modify the default editor title field with default title.
1466
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1467
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1468
-    }
1469
-
1470
-
1471
-
1472
-    /**
1473
-     * some getters
1474
-     */
1475
-    /**
1476
-     * This returns the protected _cpt_model_obj property
1477
-     *
1478
-     * @return EE_CPT_Base
1479
-     */
1480
-    public function get_cpt_model_obj()
1481
-    {
1482
-        return $this->_cpt_model_obj;
1483
-    }
1413
+	}
1414
+
1415
+
1416
+
1417
+	/**
1418
+	 * default method for the 'edit' route for cpt admin pages
1419
+	 * For reference on what to put in here, refer to wp-admin/post.php
1420
+	 *
1421
+	 * @access protected
1422
+	 * @return string   template for edit cpt form
1423
+	 */
1424
+	protected function _edit_cpt_item()
1425
+	{
1426
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1427
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1428
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1429
+		if (empty ($post)) {
1430
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1431
+		}
1432
+		if ( ! empty($_GET['get-post-lock'])) {
1433
+			wp_set_post_lock($post_id);
1434
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1435
+			exit();
1436
+		}
1437
+
1438
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1439
+		$editing          = true;
1440
+		$post_ID          = $post_id;
1441
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1442
+		$post_type_object = $this->_cpt_object;
1443
+
1444
+		if ( ! wp_check_post_lock($post->ID)) {
1445
+			$active_post_lock = wp_set_post_lock($post->ID);
1446
+			//wp_enqueue_script('autosave');
1447
+		}
1448
+		$title = $this->_cpt_object->labels->edit_item;
1449
+		add_action('admin_footer', '_admin_notice_post_locked');
1450
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1451
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1452
+		) {
1453
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1454
+				'create_new', $this);
1455
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1456
+				'action' => $create_new_action,
1457
+				'page'   => $this->page_slug,
1458
+			), 'admin.php');
1459
+		}
1460
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1461
+			wp_enqueue_script('admin-comments');
1462
+			enqueue_comment_hotkeys_js();
1463
+		}
1464
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1465
+		//modify the default editor title field with default title.
1466
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1467
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1468
+	}
1469
+
1470
+
1471
+
1472
+	/**
1473
+	 * some getters
1474
+	 */
1475
+	/**
1476
+	 * This returns the protected _cpt_model_obj property
1477
+	 *
1478
+	 * @return EE_CPT_Base
1479
+	 */
1480
+	public function get_cpt_model_obj()
1481
+	{
1482
+		return $this->_cpt_model_obj;
1483
+	}
1484 1484
 
1485 1485
 }
Please login to merge, or discard this patch.
core/services/notices/ConvertNoticesToEeErrors.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -19,56 +19,56 @@
 block discarded – undo
19 19
 class ConvertNoticesToEeErrors extends NoticeConverter
20 20
 {
21 21
 
22
-    /**
23
-     * Converts Notice objects into EE_Error notifications
24
-     *
25
-     * @param NoticesContainerInterface $notices
26
-     * @throws EE_Error
27
-     */
28
-    public function process(NoticesContainerInterface $notices)
29
-    {
30
-        $this->setNotices($notices);
31
-        $notices = $this->getNotices();
32
-        if ($notices->hasAttention()) {
33
-            foreach ($notices->getAttention() as $notice) {
34
-                EE_Error::add_attention(
35
-                    $notice->message(),
36
-                    $notice->file(),
37
-                    $notice->func(),
38
-                    $notice->line()
39
-                );
40
-            }
41
-        }
42
-        if ($notices->hasError()) {
43
-            $error_string = esc_html__('The following errors occurred:', 'event_espresso');
44
-            foreach ($notices->getError() as $notice) {
45
-                if ($this->getThrowExceptions()) {
46
-                    $error_string .= '<br />' . $notice->message();
47
-                } else {
48
-                    EE_Error::add_error(
49
-                        $notice->message(),
50
-                        $notice->file(),
51
-                        $notice->func(),
52
-                        $notice->line()
53
-                    );
54
-                }
55
-            }
56
-            if ($this->getThrowExceptions()) {
57
-                throw new EE_Error($error_string);
58
-            }
59
-        }
60
-        if ($notices->hasSuccess()) {
61
-            foreach ($notices->getSuccess() as $notice) {
62
-                EE_Error::add_success(
63
-                    $notice->message(),
64
-                    $notice->file(),
65
-                    $notice->func(),
66
-                    $notice->line()
67
-                );
68
-            }
69
-        }
70
-        $this->clearNotices();
71
-    }
22
+	/**
23
+	 * Converts Notice objects into EE_Error notifications
24
+	 *
25
+	 * @param NoticesContainerInterface $notices
26
+	 * @throws EE_Error
27
+	 */
28
+	public function process(NoticesContainerInterface $notices)
29
+	{
30
+		$this->setNotices($notices);
31
+		$notices = $this->getNotices();
32
+		if ($notices->hasAttention()) {
33
+			foreach ($notices->getAttention() as $notice) {
34
+				EE_Error::add_attention(
35
+					$notice->message(),
36
+					$notice->file(),
37
+					$notice->func(),
38
+					$notice->line()
39
+				);
40
+			}
41
+		}
42
+		if ($notices->hasError()) {
43
+			$error_string = esc_html__('The following errors occurred:', 'event_espresso');
44
+			foreach ($notices->getError() as $notice) {
45
+				if ($this->getThrowExceptions()) {
46
+					$error_string .= '<br />' . $notice->message();
47
+				} else {
48
+					EE_Error::add_error(
49
+						$notice->message(),
50
+						$notice->file(),
51
+						$notice->func(),
52
+						$notice->line()
53
+					);
54
+				}
55
+			}
56
+			if ($this->getThrowExceptions()) {
57
+				throw new EE_Error($error_string);
58
+			}
59
+		}
60
+		if ($notices->hasSuccess()) {
61
+			foreach ($notices->getSuccess() as $notice) {
62
+				EE_Error::add_success(
63
+					$notice->message(),
64
+					$notice->file(),
65
+					$notice->func(),
66
+					$notice->line()
67
+				);
68
+			}
69
+		}
70
+		$this->clearNotices();
71
+	}
72 72
 
73 73
 
74 74
 }
Please login to merge, or discard this patch.
core/services/notices/NoticeConverter.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -17,79 +17,79 @@
 block discarded – undo
17 17
 abstract class NoticeConverter implements NoticeConverterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var NoticesContainerInterface $notices
22
-     */
23
-    private $notices;
20
+	/**
21
+	 * @var NoticesContainerInterface $notices
22
+	 */
23
+	private $notices;
24 24
 
25
-    /**
26
-     * if set to true, then errors will be thrown as exceptions
27
-     *
28
-     * @var boolean $throw_exceptions
29
-     */
30
-    private $throw_exceptions;
25
+	/**
26
+	 * if set to true, then errors will be thrown as exceptions
27
+	 *
28
+	 * @var boolean $throw_exceptions
29
+	 */
30
+	private $throw_exceptions;
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * NoticeConverter constructor.
36
-     *
37
-     * @param bool                      $throw_exceptions
38
-     */
39
-    public function __construct($throw_exceptions = false)
40
-    {
41
-        $this->throw_exceptions = $throw_exceptions;
42
-    }
34
+	/**
35
+	 * NoticeConverter constructor.
36
+	 *
37
+	 * @param bool                      $throw_exceptions
38
+	 */
39
+	public function __construct($throw_exceptions = false)
40
+	{
41
+		$this->throw_exceptions = $throw_exceptions;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * @return NoticesContainerInterface
48
-     */
49
-    public function getNotices()
50
-    {
51
-        return $this->notices;
52
-    }
46
+	/**
47
+	 * @return NoticesContainerInterface
48
+	 */
49
+	public function getNotices()
50
+	{
51
+		return $this->notices;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param NoticesContainerInterface $notices
58
-     */
59
-    protected function setNotices(NoticesContainerInterface $notices)
60
-    {
61
-        $this->notices = $notices;
62
-    }
56
+	/**
57
+	 * @param NoticesContainerInterface $notices
58
+	 */
59
+	protected function setNotices(NoticesContainerInterface $notices)
60
+	{
61
+		$this->notices = $notices;
62
+	}
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * @return bool
68
-     */
69
-    public function getThrowExceptions()
70
-    {
71
-        return $this->throw_exceptions;
72
-    }
66
+	/**
67
+	 * @return bool
68
+	 */
69
+	public function getThrowExceptions()
70
+	{
71
+		return $this->throw_exceptions;
72
+	}
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     * @param bool $throw_exceptions
78
-     */
79
-    public function setThrowExceptions($throw_exceptions)
80
-    {
81
-        $this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
-    }
76
+	/**
77
+	 * @param bool $throw_exceptions
78
+	 */
79
+	public function setThrowExceptions($throw_exceptions)
80
+	{
81
+		$this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
+	}
83 83
 
84 84
 
85 85
 
86
-    /**
87
-     * @return void;
88
-     */
89
-    public function clearNotices()
90
-    {
91
-        $this->notices = null;
92
-    }
86
+	/**
87
+	 * @return void;
88
+	 */
89
+	public function clearNotices()
90
+	{
91
+		$this->notices = null;
92
+	}
93 93
 
94 94
 
95 95
 }
Please login to merge, or discard this patch.