Completed
Branch FET-10785-ee-system-loader (5e11a8)
by
unknown
102:59 queued 90:22
created
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Indentation   +606 added lines, -606 removed lines patch added patch discarded remove patch
@@ -16,612 +16,612 @@
 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
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
-            return '';
373
-        }
374
-        // start of row
375
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
376
-        // name && desc
377
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
-                         . $line_item->name();
379
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
-                                                  . $line_item->desc()
381
-                                                  . '</span>' : '';
382
-        // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
-        // discount/surcharge td
386
-        if ($line_item->is_percent()) {
387
-            $html .= EEH_HTML::td(
388
-                EEH_Template::format_currency(
389
-                    $line_item->total() / $qty,
390
-                    false, false
391
-                ),
392
-                '', 'item_c jst-rght'
393
-            );
394
-        } else {
395
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
-        }
397
-        // no quantity td
398
-        $html .= EEH_HTML::td();
399
-        // no total td
400
-        $html .= EEH_HTML::td();
401
-        // end of row
402
-        $html .= EEH_HTML::trx();
403
-        return $html;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * _tax_row
410
-     *
411
-     * @param EE_Line_Item $line_item
412
-     * @param array        $options
413
-     * @return mixed
414
-     * @throws EE_Error
415
-     */
416
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
417
-    {
418
-        // start of row
419
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
420
-        // name && desc
421
-        $name_and_desc = $line_item->name();
422
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
-        // name td
426
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
-            $name_and_desc, '', 'item_l sub-item');
428
-        // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
-        // empty td (price)
431
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
432
-        // total td
433
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
434
-            $line_item->total(), false, false),
435
-            '',
436
-            'item_r jst-rght'
437
-        );
438
-        // end of row
439
-        $html .= EEH_HTML::trx();
440
-        return $html;
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * _total_row
447
-     *
448
-     * @param EE_Line_Item $line_item
449
-     * @param string       $text
450
-     * @return mixed
451
-     * @throws EE_Error
452
-     */
453
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
-    {
455
-        $html = '';
456
-        if ($line_item->total()) {
457
-            // start of row
458
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
459
-            // total td
460
-            $html .= EEH_HTML::td(
461
-                $text,
462
-                '',
463
-                'total_currency total jst-rght',
464
-                '',
465
-                ' colspan="2"'
466
-            );
467
-            // empty td (price)
468
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
469
-            // total td
470
-            $html .= EEH_HTML::td(
471
-                EEH_Template::format_currency($line_item->total(), false, false),
472
-                '',
473
-                'total jst-rght'
474
-            );
475
-            // end of row
476
-            $html .= EEH_HTML::trx();
477
-        }
478
-        return $html;
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * _total_row
485
-     *
486
-     * @param EE_Line_Item $line_item
487
-     * @param string       $text
488
-     * @param array        $options
489
-     * @return mixed
490
-     * @throws EE_Error
491
-     */
492
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
-    {
494
-        $html = '';
495
-        if ($line_item->total()) {
496
-            // start of row
497
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
498
-            // total td
499
-            $html .= EEH_HTML::td(
500
-                $text,
501
-                '',
502
-                'total_currency total jst-rght',
503
-                '',
504
-                ' colspan="3"'
505
-            );
506
-            // total td
507
-            $html .= EEH_HTML::td(
508
-                EEH_Template::format_currency($options['sub_total'], false, false),
509
-                '',
510
-                'total jst-rght'
511
-            );
512
-            // end of row
513
-            $html .= EEH_HTML::trx();
514
-        }
515
-        return $html;
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * _total_row
522
-     *
523
-     * @param EE_Line_Item $line_item
524
-     * @param string       $text
525
-     * @return mixed
526
-     * @throws EE_Error
527
-     */
528
-    private function _total_row(EE_Line_Item $line_item, $text = '')
529
-    {
530
-        // start of row
531
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
-        // total td
533
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
-        // total td
535
-        $html .= EEH_HTML::td(
536
-            EEH_Template::format_currency($line_item->total(), false, false),
537
-            '',
538
-            'total jst-rght'
539
-        );
540
-        // end of row
541
-        $html .= EEH_HTML::trx();
542
-        return $html;
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * _payments_and_amount_owing_rows
549
-     *
550
-     * @param EE_Line_Item $line_item
551
-     * @param array        $options
552
-     * @return mixed
553
-     * @throws EE_Error
554
-     */
555
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
-    {
557
-        $html = '';
558
-        $owing = $line_item->total();
559
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
-        if ($transaction instanceof EE_Transaction) {
561
-            $registration_payments = array();
562
-            $registrations = ! empty($options['registrations'])
563
-                ? $options['registrations']
564
-                : $transaction->registrations();
565
-            foreach ($registrations as $registration) {
566
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
-                    $registration_payments += $registration->registration_payments();
568
-                }
569
-            }
570
-            if (! empty($registration_payments)) {
571
-                foreach ($registration_payments as $registration_payment) {
572
-                    if ($registration_payment instanceof EE_Registration_Payment) {
573
-                        $owing -= $registration_payment->amount();
574
-                        $payment = $registration_payment->payment();
575
-                        $payment_desc = '';
576
-                        if ($payment instanceof EE_Payment) {
577
-                            $payment_desc = sprintf(
578
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
-                                $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
-                                    : '',
582
-                                $payment->timestamp()
583
-                            );
584
-                        }
585
-                        // start of row
586
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
587
-                        // payment desc
588
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
-                        // total td
590
-                        $html .= EEH_HTML::td(
591
-                            EEH_Template::format_currency(
592
-                                $registration_payment->amount(),
593
-                                false,
594
-                                false
595
-                            ),
596
-                            '',
597
-                            'total jst-rght'
598
-                        );
599
-                        // end of row
600
-                        $html .= EEH_HTML::trx();
601
-                    }
602
-                }
603
-                if ($line_item->total()) {
604
-                    // start of row
605
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
606
-                    // total td
607
-                    $html .= EEH_HTML::td(
608
-                        esc_html__('Amount Owing', 'event_espresso'),
609
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
610
-                    );
611
-                    // total td
612
-                    $html .= EEH_HTML::td(
613
-                        EEH_Template::format_currency($owing, false, false),
614
-                        '',
615
-                        'total jst-rght'
616
-                    );
617
-                    // end of row
618
-                    $html .= EEH_HTML::trx();
619
-                }
620
-            }
621
-        }
622
-        $this->_grand_total = $owing;
623
-        return $html;
624
-    }
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
+		if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
+			return '';
373
+		}
374
+		// start of row
375
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
376
+		// name && desc
377
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
+						 . $line_item->name();
379
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
+												  . $line_item->desc()
381
+												  . '</span>' : '';
382
+		// name td
383
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
+		// discount/surcharge td
386
+		if ($line_item->is_percent()) {
387
+			$html .= EEH_HTML::td(
388
+				EEH_Template::format_currency(
389
+					$line_item->total() / $qty,
390
+					false, false
391
+				),
392
+				'', 'item_c jst-rght'
393
+			);
394
+		} else {
395
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
+		}
397
+		// no quantity td
398
+		$html .= EEH_HTML::td();
399
+		// no total td
400
+		$html .= EEH_HTML::td();
401
+		// end of row
402
+		$html .= EEH_HTML::trx();
403
+		return $html;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * _tax_row
410
+	 *
411
+	 * @param EE_Line_Item $line_item
412
+	 * @param array        $options
413
+	 * @return mixed
414
+	 * @throws EE_Error
415
+	 */
416
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
417
+	{
418
+		// start of row
419
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
420
+		// name && desc
421
+		$name_and_desc = $line_item->name();
422
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
+		// name td
426
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
+			$name_and_desc, '', 'item_l sub-item');
428
+		// percent td
429
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
+		// empty td (price)
431
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
432
+		// total td
433
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
434
+			$line_item->total(), false, false),
435
+			'',
436
+			'item_r jst-rght'
437
+		);
438
+		// end of row
439
+		$html .= EEH_HTML::trx();
440
+		return $html;
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * _total_row
447
+	 *
448
+	 * @param EE_Line_Item $line_item
449
+	 * @param string       $text
450
+	 * @return mixed
451
+	 * @throws EE_Error
452
+	 */
453
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
+	{
455
+		$html = '';
456
+		if ($line_item->total()) {
457
+			// start of row
458
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
459
+			// total td
460
+			$html .= EEH_HTML::td(
461
+				$text,
462
+				'',
463
+				'total_currency total jst-rght',
464
+				'',
465
+				' colspan="2"'
466
+			);
467
+			// empty td (price)
468
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
469
+			// total td
470
+			$html .= EEH_HTML::td(
471
+				EEH_Template::format_currency($line_item->total(), false, false),
472
+				'',
473
+				'total jst-rght'
474
+			);
475
+			// end of row
476
+			$html .= EEH_HTML::trx();
477
+		}
478
+		return $html;
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * _total_row
485
+	 *
486
+	 * @param EE_Line_Item $line_item
487
+	 * @param string       $text
488
+	 * @param array        $options
489
+	 * @return mixed
490
+	 * @throws EE_Error
491
+	 */
492
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
+	{
494
+		$html = '';
495
+		if ($line_item->total()) {
496
+			// start of row
497
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
498
+			// total td
499
+			$html .= EEH_HTML::td(
500
+				$text,
501
+				'',
502
+				'total_currency total jst-rght',
503
+				'',
504
+				' colspan="3"'
505
+			);
506
+			// total td
507
+			$html .= EEH_HTML::td(
508
+				EEH_Template::format_currency($options['sub_total'], false, false),
509
+				'',
510
+				'total jst-rght'
511
+			);
512
+			// end of row
513
+			$html .= EEH_HTML::trx();
514
+		}
515
+		return $html;
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * _total_row
522
+	 *
523
+	 * @param EE_Line_Item $line_item
524
+	 * @param string       $text
525
+	 * @return mixed
526
+	 * @throws EE_Error
527
+	 */
528
+	private function _total_row(EE_Line_Item $line_item, $text = '')
529
+	{
530
+		// start of row
531
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
+		// total td
533
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
+		// total td
535
+		$html .= EEH_HTML::td(
536
+			EEH_Template::format_currency($line_item->total(), false, false),
537
+			'',
538
+			'total jst-rght'
539
+		);
540
+		// end of row
541
+		$html .= EEH_HTML::trx();
542
+		return $html;
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * _payments_and_amount_owing_rows
549
+	 *
550
+	 * @param EE_Line_Item $line_item
551
+	 * @param array        $options
552
+	 * @return mixed
553
+	 * @throws EE_Error
554
+	 */
555
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
+	{
557
+		$html = '';
558
+		$owing = $line_item->total();
559
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
+		if ($transaction instanceof EE_Transaction) {
561
+			$registration_payments = array();
562
+			$registrations = ! empty($options['registrations'])
563
+				? $options['registrations']
564
+				: $transaction->registrations();
565
+			foreach ($registrations as $registration) {
566
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
+					$registration_payments += $registration->registration_payments();
568
+				}
569
+			}
570
+			if (! empty($registration_payments)) {
571
+				foreach ($registration_payments as $registration_payment) {
572
+					if ($registration_payment instanceof EE_Registration_Payment) {
573
+						$owing -= $registration_payment->amount();
574
+						$payment = $registration_payment->payment();
575
+						$payment_desc = '';
576
+						if ($payment instanceof EE_Payment) {
577
+							$payment_desc = sprintf(
578
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
+								$payment->txn_id_chq_nmbr() !== ''
580
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
+									: '',
582
+								$payment->timestamp()
583
+							);
584
+						}
585
+						// start of row
586
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
587
+						// payment desc
588
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
+						// total td
590
+						$html .= EEH_HTML::td(
591
+							EEH_Template::format_currency(
592
+								$registration_payment->amount(),
593
+								false,
594
+								false
595
+							),
596
+							'',
597
+							'total jst-rght'
598
+						);
599
+						// end of row
600
+						$html .= EEH_HTML::trx();
601
+					}
602
+				}
603
+				if ($line_item->total()) {
604
+					// start of row
605
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
606
+					// total td
607
+					$html .= EEH_HTML::td(
608
+						esc_html__('Amount Owing', 'event_espresso'),
609
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
610
+					);
611
+					// total td
612
+					$html .= EEH_HTML::td(
613
+						EEH_Template::format_currency($owing, false, false),
614
+						'',
615
+						'total jst-rght'
616
+					);
617
+					// end of row
618
+					$html .= EEH_HTML::trx();
619
+				}
620
+			}
621
+		}
622
+		$this->_grand_total = $owing;
623
+		return $html;
624
+	}
625 625
 
626 626
 
627 627
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 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
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370 370
     {
371
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
371
+        if ($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372 372
             return '';
373 373
         }
374 374
         // start of row
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
                                                   . $line_item->desc()
381 381
                                                   . '</span>' : '';
382 382
         // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
383
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
384 384
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385 385
         // discount/surcharge td
386 386
         if ($line_item->is_percent()) {
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
         // name && desc
421 421
         $name_and_desc = $line_item->name();
422 422
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
423
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
424
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
425 425
         // name td
426 426
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427 427
             $name_and_desc, '', 'item_l sub-item');
428 428
         // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
429
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
430 430
         // empty td (price)
431 431
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
432 432
         // total td
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                     $registration_payments += $registration->registration_payments();
568 568
                 }
569 569
             }
570
-            if (! empty($registration_payments)) {
570
+            if ( ! empty($registration_payments)) {
571 571
                 foreach ($registration_payments as $registration_payment) {
572 572
                     if ($registration_payment instanceof EE_Registration_Payment) {
573 573
                         $owing -= $registration_payment->amount();
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
                             $payment_desc = sprintf(
578 578
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579 579
                                 $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
580
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
581 581
                                     : '',
582 582
                                 $payment->timestamp()
583 583
                             );
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1374 added lines, -1374 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,445 +24,445 @@  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 object
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 object
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 = null;
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  object $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 (is_array($box['callback'])
259
-                        && ($box['callback'][0] instanceof EE_Admin_Page
260
-                            || $box['callback'][0] instanceof EE_Admin_Hooks)
261
-                    ) {
262
-                        $containers[] = $box['id'];
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
-        //add hidden inputs container
269
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
-    }
271
-
272
-
273
-
274
-    protected function _load_autosave_scripts_styles()
275
-    {
276
-        /*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 = null;
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  object $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 (is_array($box['callback'])
259
+						&& ($box['callback'][0] instanceof EE_Admin_Page
260
+							|| $box['callback'][0] instanceof EE_Admin_Hooks)
261
+					) {
262
+						$containers[] = $box['id'];
263
+					}
264
+				}
265
+			}
266
+		}
267
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
+		//add hidden inputs container
269
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
+	}
271
+
272
+
273
+
274
+	protected function _load_autosave_scripts_styles()
275
+	{
276
+		/*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 );
277 277
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
278 278
 
279
-        //filter _autosave_containers
280
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
-            $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
-            $containers, $this);
284
-
285
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
-
288
-        $unsaved_data_msg = array(
289
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
291
-            'inputChanged' => 0,
292
-        );
293
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
-    }
295
-
296
-
297
-
298
-    public function load_page_dependencies()
299
-    {
300
-        try {
301
-            $this->_load_page_dependencies();
302
-        } catch (EE_Error $e) {
303
-            $e->get_error();
304
-        }
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
-     *
312
-     * @access protected
313
-     * @return void
314
-     */
315
-    protected function _load_page_dependencies()
316
-    {
317
-        //we only add stuff if this is a cpt_route!
318
-        if ( ! $this->_cpt_route) {
319
-            parent::_load_page_dependencies();
320
-            return;
321
-        }
322
-        //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
-        //the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
-        //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
-        //inject our Admin page nav tabs...
327
-        //let's make sure the nav tabs are set if they aren't already
328
-        //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
-        //modify the post_updated messages array
331
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
-        //add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
-        //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
-        if ( ! empty($this->_labels['publishbox'])) {
336
-            $box_label = is_array($this->_labels['publishbox'])
337
-                         && isset($this->_labels['publishbox'][$this->_req_action])
338
-                ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
-            remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
-                'side', 'core');
341
-            add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
-                'side', 'core');
343
-        }
344
-        //let's add page_templates metabox if this cpt added support for it.
345
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
-            add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
-                array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
-        }
349
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
351
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
-        }
353
-        //add preview button
354
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
-        //insert our own post_stati dropdown
356
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
358
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
-        }
361
-        //This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
-        if (method_exists($this, 'edit_form_after_title')) {
363
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
-        }
365
-        /**
366
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
-         */
368
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
-        parent::_load_page_dependencies();
370
-        //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
-        global $pagenow;
372
-        do_action('load-' . $pagenow);
373
-        $this->modify_current_screen();
374
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
-        //we route REALLY early.
376
-        try {
377
-            $this->_route_admin_request();
378
-        } catch (EE_Error $e) {
379
-            $e->get_error();
380
-        }
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
-     * route instead.
389
-     *
390
-     * @param string $good_protocol_url The escaped url.
391
-     * @param string $original_url      The original url.
392
-     * @param string $_context          The context sendt to the esc_url method.
393
-     * @return string possibly a new url for our route.
394
-     */
395
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
-    {
397
-        $routes_to_match = array(
398
-            0 => array(
399
-                'edit.php?post_type=espresso_attendees',
400
-                'admin.php?page=espresso_registrations&action=contact_list',
401
-            ),
402
-            1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
405
-            ),
406
-        );
407
-        foreach ($routes_to_match as $route_matches) {
408
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
-            }
411
-        }
412
-        return $good_protocol_url;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Determine whether the current cpt supports page templates or not.
419
-     *
420
-     * @since %VER%
421
-     * @param string $cpt_name The cpt slug we're checking on.
422
-     * @return bool True supported, false not.
423
-     */
424
-    private function _supports_page_templates($cpt_name)
425
-    {
426
-
427
-        $cpt_args = EE_Register_CPTs::get_CPTs();
428
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
430
-
431
-        //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
-            $post_templates = wp_get_theme()->get_post_templates();
434
-            //if there are $post_templates for this cpt, then we return false for this method because
435
-            //that means we aren't going to load our page template manager and leave that up to the native
436
-            //cpt template manager.
437
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
-        }
439
-
440
-        return $cpt_has_support;
441
-    }
442
-
443
-
444
-    /**
445
-     * Callback for the page_templates metabox selector.
446
-     *
447
-     * @since %VER%
448
-     * @return string html
449
-     */
450
-    public function page_template_meta_box()
451
-    {
452
-        global $post;
453
-        $template = '';
454
-
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
-            $page_template_count = count(get_page_templates());
457
-        } else {
458
-            $page_template_count = count(get_page_templates($post));
459
-        };
460
-
461
-        if ($page_template_count) {
462
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
-            $template      = ! empty($page_template) ? $page_template : '';
464
-        }
465
-        ?>
279
+		//filter _autosave_containers
280
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
+			$this->_autosave_containers, $this);
282
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
+			$containers, $this);
284
+
285
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
+
288
+		$unsaved_data_msg = array(
289
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
291
+			'inputChanged' => 0,
292
+		);
293
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
+	}
295
+
296
+
297
+
298
+	public function load_page_dependencies()
299
+	{
300
+		try {
301
+			$this->_load_page_dependencies();
302
+		} catch (EE_Error $e) {
303
+			$e->get_error();
304
+		}
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
+	 *
312
+	 * @access protected
313
+	 * @return void
314
+	 */
315
+	protected function _load_page_dependencies()
316
+	{
317
+		//we only add stuff if this is a cpt_route!
318
+		if ( ! $this->_cpt_route) {
319
+			parent::_load_page_dependencies();
320
+			return;
321
+		}
322
+		//now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
+		//the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
+		//let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
+		//inject our Admin page nav tabs...
327
+		//let's make sure the nav tabs are set if they aren't already
328
+		//if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
+		//modify the post_updated messages array
331
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
+		//add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
+		//This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
+		if ( ! empty($this->_labels['publishbox'])) {
336
+			$box_label = is_array($this->_labels['publishbox'])
337
+						 && isset($this->_labels['publishbox'][$this->_req_action])
338
+				? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
+			remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
+				'side', 'core');
341
+			add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
+				'side', 'core');
343
+		}
344
+		//let's add page_templates metabox if this cpt added support for it.
345
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
+			add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
+				array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
+		}
349
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
351
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
+		}
353
+		//add preview button
354
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
+		//insert our own post_stati dropdown
356
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
358
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
+		}
361
+		//This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
+		if (method_exists($this, 'edit_form_after_title')) {
363
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
+		}
365
+		/**
366
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
+		 */
368
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
+		parent::_load_page_dependencies();
370
+		//notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
+		global $pagenow;
372
+		do_action('load-' . $pagenow);
373
+		$this->modify_current_screen();
374
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
+		//we route REALLY early.
376
+		try {
377
+			$this->_route_admin_request();
378
+		} catch (EE_Error $e) {
379
+			$e->get_error();
380
+		}
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
+	 * route instead.
389
+	 *
390
+	 * @param string $good_protocol_url The escaped url.
391
+	 * @param string $original_url      The original url.
392
+	 * @param string $_context          The context sendt to the esc_url method.
393
+	 * @return string possibly a new url for our route.
394
+	 */
395
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
+	{
397
+		$routes_to_match = array(
398
+			0 => array(
399
+				'edit.php?post_type=espresso_attendees',
400
+				'admin.php?page=espresso_registrations&action=contact_list',
401
+			),
402
+			1 => array(
403
+				'edit.php?post_type=' . $this->_cpt_object->name,
404
+				'admin.php?page=' . $this->_cpt_object->name,
405
+			),
406
+		);
407
+		foreach ($routes_to_match as $route_matches) {
408
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
+			}
411
+		}
412
+		return $good_protocol_url;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Determine whether the current cpt supports page templates or not.
419
+	 *
420
+	 * @since %VER%
421
+	 * @param string $cpt_name The cpt slug we're checking on.
422
+	 * @return bool True supported, false not.
423
+	 */
424
+	private function _supports_page_templates($cpt_name)
425
+	{
426
+
427
+		$cpt_args = EE_Register_CPTs::get_CPTs();
428
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
430
+
431
+		//if the installed version of WP is > 4.7 we do some additional checks.
432
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
+			$post_templates = wp_get_theme()->get_post_templates();
434
+			//if there are $post_templates for this cpt, then we return false for this method because
435
+			//that means we aren't going to load our page template manager and leave that up to the native
436
+			//cpt template manager.
437
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
+		}
439
+
440
+		return $cpt_has_support;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Callback for the page_templates metabox selector.
446
+	 *
447
+	 * @since %VER%
448
+	 * @return string html
449
+	 */
450
+	public function page_template_meta_box()
451
+	{
452
+		global $post;
453
+		$template = '';
454
+
455
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
+			$page_template_count = count(get_page_templates());
457
+		} else {
458
+			$page_template_count = count(get_page_templates($post));
459
+		};
460
+
461
+		if ($page_template_count) {
462
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
+			$template      = ! empty($page_template) ? $page_template : '';
464
+		}
465
+		?>
466 466
         <p><strong><?php _e('Template') ?></strong></p>
467 467
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
468 468
             name="page_template" id="page_template">
@@ -470,435 +470,435 @@  discard block
 block discarded – undo
470 470
         <?php page_template_dropdown($template); ?>
471 471
     </select>
472 472
         <?php
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
479
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
-     *
481
-     * @param  string $return    the current html
482
-     * @param  int    $id        the post id for the page
483
-     * @param  string $new_title What the title is
484
-     * @param  string $new_slug  what the slug is
485
-     * @return string            The new html string for the permalink area
486
-     */
487
-    public function preview_button_html($return, $id, $new_title, $new_slug)
488
-    {
489
-        $post = get_post($id);
490
-        if ('publish' != get_post_status($post)) {
491
-            //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
493
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
-                       . get_preview_post_link($id)
495
-                       . '" class="button button-small">'
496
-                       . __('Preview', 'event_espresso')
497
-                       . '</a></span>'
498
-                       . "\n";
499
-        }
500
-        return $return;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * add our custom post stati dropdown on the wp post page for this cpt
507
-     *
508
-     * @return string html for dropdown
509
-     */
510
-    public function custom_post_stati_dropdown()
511
-    {
512
-
513
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
-            ? $statuses[$this->_cpt_model_obj->status()]
516
-            : '';
517
-        $template_args    = array(
518
-            'cur_status'            => $this->_cpt_model_obj->status(),
519
-            'statuses'              => $statuses,
520
-            'cur_status_label'      => $cur_status_label,
521
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
-        );
523
-        //we'll add a trash post status (WP doesn't add one for some reason)
524
-        if ($this->_cpt_model_obj->status() == 'trash') {
525
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
527
-            $template_args['statuses']         = $statuses;
528
-        }
529
-
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
-        EEH_Template::display_template($template, $template_args);
532
-    }
533
-
534
-
535
-
536
-    public function setup_autosave_hooks()
537
-    {
538
-        $this->_set_autosave_containers();
539
-        $this->_load_autosave_scripts_styles();
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
-     * for the nonce in here, but then this method looks for two things:
548
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
-     * template args.
553
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
-     *    $this->_template_args['data']['items'] = array(
557
-     *        'event-datetime-ids' => '1,2,3';
558
-     *    );
559
-     *    Keep in mind the following things:
560
-     *    - "where" index is for the input with the id as that string.
561
-     *    - "what" index is what will be used for the value of that input.
562
-     *
563
-     * @return void
564
-     */
565
-    public function do_extra_autosave_stuff()
566
-    {
567
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
568
-        $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
-        $this->_verify_nonce($nonce, 'autosave');
570
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
-        if ( ! defined('DOING_AUTOSAVE')) {
572
-            define('DOING_AUTOSAVE', true);
573
-        }
574
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
-        } else {
578
-            $this->_template_args['success'] = true;
579
-        }
580
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
-        //now let's return json
583
-        $this->_return_json();
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
-     *
593
-     * @access protected
594
-     * @throws EE_Error
595
-     * @return void
596
-     */
597
-    protected function _extend_page_config_for_cpt()
598
-    {
599
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
-        if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
-            return;
602
-        }
603
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
-        if ( ! empty($this->_cpt_object)) {
605
-            $this->_page_routes = array_merge(array(
606
-                'create_new' => '_create_new_cpt_item',
607
-                'edit'       => '_edit_cpt_item',
608
-            ), $this->_page_routes);
609
-            $this->_page_config = array_merge(array(
610
-                'create_new' => array(
611
-                    'nav'           => array(
612
-                        'label' => $this->_cpt_object->labels->add_new_item,
613
-                        'order' => 5,
614
-                    ),
615
-                    'require_nonce' => false,
616
-                ),
617
-                'edit'       => array(
618
-                    'nav'           => array(
619
-                        'label'      => $this->_cpt_object->labels->edit_item,
620
-                        'order'      => 5,
621
-                        'persistent' => false,
622
-                        'url'        => '',
623
-                    ),
624
-                    'require_nonce' => false,
625
-                ),
626
-            ),
627
-                $this->_page_config
628
-            );
629
-        }
630
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
631
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
-            return;
633
-        }
634
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
-        if (empty($this->_cpt_object)) {
637
-            $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).'),
638
-                $this->page_slug, $this->_req_action, get_class($this));
639
-            throw new EE_Error($msg);
640
-        }
641
-        if ($this->_cpt_route) {
642
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
-            $this->_set_model_object($id);
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
-     *
652
-     * @access protected
653
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
-     * @param bool $ignore_route_check
655
-     */
656
-    protected function _set_model_object($id = null, $ignore_route_check = false)
657
-    {
658
-        $model = null;
659
-        if (
660
-            empty($this->_cpt_model_names)
661
-            || (
662
-                ! $ignore_route_check
663
-                && ! isset($this->_cpt_routes[$this->_req_action])
664
-            ) || (
665
-                $this->_cpt_model_obj instanceof EE_CPT_Base
666
-                && $this->_cpt_model_obj->ID() === $id
667
-            )
668
-        ) {
669
-            //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.
670
-            return;
671
-        }
672
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
-        if ($ignore_route_check) {
674
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
675
-            $post_type   = get_post_type($id);
676
-            if (isset($model_names[$post_type])) {
677
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
-            }
679
-        } else {
680
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
-        }
682
-        if ($model instanceof EEM_Base) {
683
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
-        }
685
-        do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * admin_init_global
692
-     * This runs all the code that we want executed within the WP admin_init hook.
693
-     * This method executes for ALL EE Admin pages.
694
-     *
695
-     * @access public
696
-     * @return void
697
-     */
698
-    public function admin_init_global()
699
-    {
700
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
-        //its possible this is a new save so let's catch that instead
702
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
-        $post_type = $post ? $post->post_type : false;
704
-        $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
-            : 'shouldneverwork';
706
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
-            : '';
708
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
-        if ($post_type === $route_to_check) {
711
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
-        }
713
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
-        if ( ! empty($revision)) {
716
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
-            //doing a restore?
718
-            if ( ! empty($action) && $action == 'restore') {
719
-                //get post for revision
720
-                $rev_post = get_post($revision);
721
-                $rev_parent = get_post($rev_post->post_parent);
722
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
-                if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
-                    //restores of revisions
726
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
-                }
728
-            }
729
-        }
730
-        //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!
731
-        if ($post_type && $post_type === $route_to_check) {
732
-            //$post_id, $post
733
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
734
-            //$post_id
735
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
-        }
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * Callback for the WordPress trashed_post hook.
746
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
-     *
748
-     * @param int $post_id
749
-     */
750
-    public function before_trash_cpt_item($post_id)
751
-    {
752
-        $this->_set_model_object($post_id, true);
753
-        //if our cpt object isn't existent then get out immediately.
754
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
-            return;
756
-        }
757
-        $this->trash_cpt_item($post_id);
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * Callback for the WordPress untrashed_post hook.
764
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
765
-     *
766
-     * @param $post_id
767
-     */
768
-    public function before_restore_cpt_item($post_id)
769
-    {
770
-        $this->_set_model_object($post_id, true);
771
-        //if our cpt object isn't existent then get out immediately.
772
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
-            return;
774
-        }
775
-        $this->restore_cpt_item($post_id);
776
-    }
777
-
778
-
779
-
780
-    /**
781
-     * Callback for the WordPress after_delete_post hook.
782
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
-     *
784
-     * @param $post_id
785
-     */
786
-    public function before_delete_cpt_item($post_id)
787
-    {
788
-        $this->_set_model_object($post_id, true);
789
-        //if our cpt object isn't existent then get out immediately.
790
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
-            return;
792
-        }
793
-        $this->delete_cpt_item($post_id);
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
-     * accordingly.
801
-     *
802
-     * @access public
803
-     * @throws EE_Error
804
-     * @return void
805
-     */
806
-    public function verify_cpt_object()
807
-    {
808
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
-        // verify event object
810
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
-            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',
812
-                'event_espresso'), $label));
813
-        }
814
-        //if auto-draft then throw an error
815
-        if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
-            EE_Error::overwrite_errors();
817
-            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.'),
818
-                $label), __FILE__, __FUNCTION__, __LINE__);
819
-        }
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * admin_footer_scripts_global
826
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
-     * will apply on ALL EE_Admin pages.
828
-     *
829
-     * @access public
830
-     * @return void
831
-     */
832
-    public function admin_footer_scripts_global()
833
-    {
834
-        $this->_add_admin_page_ajax_loading_img();
835
-        $this->_add_admin_page_overlay();
836
-    }
837
-
838
-
839
-
840
-    /**
841
-     * add in any global scripts for cpt routes
842
-     *
843
-     * @return void
844
-     */
845
-    public function load_global_scripts_styles()
846
-    {
847
-        parent::load_global_scripts_styles();
848
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
-            //setup custom post status object for localize script but only if we've got a cpt object
850
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
-            if ( ! empty($statuses)) {
852
-                //get ALL statuses!
853
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
-                //setup object
855
-                $ee_cpt_statuses = array();
856
-                foreach ($statuses as $status => $label) {
857
-                    $ee_cpt_statuses[$status] = array(
858
-                        'label'      => $label,
859
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
-                    );
861
-                }
862
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
-            }
864
-        }
865
-    }
866
-
867
-
868
-
869
-    /**
870
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
-     * insert/updates
872
-     *
873
-     * @param  int     $post_id ID of post being updated
874
-     * @param  WP_Post $post    Post object from WP
875
-     * @param  bool    $update  Whether this is an update or a new save.
876
-     * @return void
877
-     */
878
-    public function insert_update($post_id, $post, $update)
879
-    {
880
-        //make sure that if this is a revision OR trash action that we don't do any updates!
881
-        if (
882
-            isset($this->_req_data['action'])
883
-            && (
884
-                $this->_req_data['action'] == 'restore'
885
-                || $this->_req_data['action'] == 'trash'
886
-            )
887
-        ) {
888
-            return;
889
-        }
890
-        $this->_set_model_object($post_id, true);
891
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
-        if ($update
893
-            && (
894
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
895
-                || $this->_cpt_model_obj->ID() !== $post_id
896
-            )
897
-        ) {
898
-            return;
899
-        }
900
-        //check for autosave and update our req_data property accordingly.
901
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
479
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
+	 *
481
+	 * @param  string $return    the current html
482
+	 * @param  int    $id        the post id for the page
483
+	 * @param  string $new_title What the title is
484
+	 * @param  string $new_slug  what the slug is
485
+	 * @return string            The new html string for the permalink area
486
+	 */
487
+	public function preview_button_html($return, $id, $new_title, $new_slug)
488
+	{
489
+		$post = get_post($id);
490
+		if ('publish' != get_post_status($post)) {
491
+			//include shims for the `get_preview_post_link` function
492
+			require_once( EE_CORE . 'wordpress-shims.php' );
493
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
+					   . get_preview_post_link($id)
495
+					   . '" class="button button-small">'
496
+					   . __('Preview', 'event_espresso')
497
+					   . '</a></span>'
498
+					   . "\n";
499
+		}
500
+		return $return;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * add our custom post stati dropdown on the wp post page for this cpt
507
+	 *
508
+	 * @return string html for dropdown
509
+	 */
510
+	public function custom_post_stati_dropdown()
511
+	{
512
+
513
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
+			? $statuses[$this->_cpt_model_obj->status()]
516
+			: '';
517
+		$template_args    = array(
518
+			'cur_status'            => $this->_cpt_model_obj->status(),
519
+			'statuses'              => $statuses,
520
+			'cur_status_label'      => $cur_status_label,
521
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
+		);
523
+		//we'll add a trash post status (WP doesn't add one for some reason)
524
+		if ($this->_cpt_model_obj->status() == 'trash') {
525
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
527
+			$template_args['statuses']         = $statuses;
528
+		}
529
+
530
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
+		EEH_Template::display_template($template, $template_args);
532
+	}
533
+
534
+
535
+
536
+	public function setup_autosave_hooks()
537
+	{
538
+		$this->_set_autosave_containers();
539
+		$this->_load_autosave_scripts_styles();
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
+	 * for the nonce in here, but then this method looks for two things:
548
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
+	 * template args.
553
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
+	 *    $this->_template_args['data']['items'] = array(
557
+	 *        'event-datetime-ids' => '1,2,3';
558
+	 *    );
559
+	 *    Keep in mind the following things:
560
+	 *    - "where" index is for the input with the id as that string.
561
+	 *    - "what" index is what will be used for the value of that input.
562
+	 *
563
+	 * @return void
564
+	 */
565
+	public function do_extra_autosave_stuff()
566
+	{
567
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
568
+		$nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
+		$this->_verify_nonce($nonce, 'autosave');
570
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
+		if ( ! defined('DOING_AUTOSAVE')) {
572
+			define('DOING_AUTOSAVE', true);
573
+		}
574
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
575
+		if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
+			call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
+		} else {
578
+			$this->_template_args['success'] = true;
579
+		}
580
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
+		//now let's return json
583
+		$this->_return_json();
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
+	 *
593
+	 * @access protected
594
+	 * @throws EE_Error
595
+	 * @return void
596
+	 */
597
+	protected function _extend_page_config_for_cpt()
598
+	{
599
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
+		if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
+			return;
602
+		}
603
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
+		if ( ! empty($this->_cpt_object)) {
605
+			$this->_page_routes = array_merge(array(
606
+				'create_new' => '_create_new_cpt_item',
607
+				'edit'       => '_edit_cpt_item',
608
+			), $this->_page_routes);
609
+			$this->_page_config = array_merge(array(
610
+				'create_new' => array(
611
+					'nav'           => array(
612
+						'label' => $this->_cpt_object->labels->add_new_item,
613
+						'order' => 5,
614
+					),
615
+					'require_nonce' => false,
616
+				),
617
+				'edit'       => array(
618
+					'nav'           => array(
619
+						'label'      => $this->_cpt_object->labels->edit_item,
620
+						'order'      => 5,
621
+						'persistent' => false,
622
+						'url'        => '',
623
+					),
624
+					'require_nonce' => false,
625
+				),
626
+			),
627
+				$this->_page_config
628
+			);
629
+		}
630
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
631
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
+			return;
633
+		}
634
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
+		if (empty($this->_cpt_object)) {
637
+			$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).'),
638
+				$this->page_slug, $this->_req_action, get_class($this));
639
+			throw new EE_Error($msg);
640
+		}
641
+		if ($this->_cpt_route) {
642
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
+			$this->_set_model_object($id);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
+	 *
652
+	 * @access protected
653
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
+	 * @param bool $ignore_route_check
655
+	 */
656
+	protected function _set_model_object($id = null, $ignore_route_check = false)
657
+	{
658
+		$model = null;
659
+		if (
660
+			empty($this->_cpt_model_names)
661
+			|| (
662
+				! $ignore_route_check
663
+				&& ! isset($this->_cpt_routes[$this->_req_action])
664
+			) || (
665
+				$this->_cpt_model_obj instanceof EE_CPT_Base
666
+				&& $this->_cpt_model_obj->ID() === $id
667
+			)
668
+		) {
669
+			//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.
670
+			return;
671
+		}
672
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
+		if ($ignore_route_check) {
674
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
675
+			$post_type   = get_post_type($id);
676
+			if (isset($model_names[$post_type])) {
677
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
+			}
679
+		} else {
680
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
+		}
682
+		if ($model instanceof EEM_Base) {
683
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
+		}
685
+		do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * admin_init_global
692
+	 * This runs all the code that we want executed within the WP admin_init hook.
693
+	 * This method executes for ALL EE Admin pages.
694
+	 *
695
+	 * @access public
696
+	 * @return void
697
+	 */
698
+	public function admin_init_global()
699
+	{
700
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
+		//its possible this is a new save so let's catch that instead
702
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
+		$post_type = $post ? $post->post_type : false;
704
+		$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
+			: 'shouldneverwork';
706
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
+			: '';
708
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
+		if ($post_type === $route_to_check) {
711
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
+		}
713
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
+		if ( ! empty($revision)) {
716
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
+			//doing a restore?
718
+			if ( ! empty($action) && $action == 'restore') {
719
+				//get post for revision
720
+				$rev_post = get_post($revision);
721
+				$rev_parent = get_post($rev_post->post_parent);
722
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
+				if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
+					//restores of revisions
726
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
+				}
728
+			}
729
+		}
730
+		//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!
731
+		if ($post_type && $post_type === $route_to_check) {
732
+			//$post_id, $post
733
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
734
+			//$post_id
735
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
+		}
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * Callback for the WordPress trashed_post hook.
746
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
+	 *
748
+	 * @param int $post_id
749
+	 */
750
+	public function before_trash_cpt_item($post_id)
751
+	{
752
+		$this->_set_model_object($post_id, true);
753
+		//if our cpt object isn't existent then get out immediately.
754
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
+			return;
756
+		}
757
+		$this->trash_cpt_item($post_id);
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * Callback for the WordPress untrashed_post hook.
764
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
765
+	 *
766
+	 * @param $post_id
767
+	 */
768
+	public function before_restore_cpt_item($post_id)
769
+	{
770
+		$this->_set_model_object($post_id, true);
771
+		//if our cpt object isn't existent then get out immediately.
772
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
+			return;
774
+		}
775
+		$this->restore_cpt_item($post_id);
776
+	}
777
+
778
+
779
+
780
+	/**
781
+	 * Callback for the WordPress after_delete_post hook.
782
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
+	 *
784
+	 * @param $post_id
785
+	 */
786
+	public function before_delete_cpt_item($post_id)
787
+	{
788
+		$this->_set_model_object($post_id, true);
789
+		//if our cpt object isn't existent then get out immediately.
790
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
+			return;
792
+		}
793
+		$this->delete_cpt_item($post_id);
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
+	 * accordingly.
801
+	 *
802
+	 * @access public
803
+	 * @throws EE_Error
804
+	 * @return void
805
+	 */
806
+	public function verify_cpt_object()
807
+	{
808
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
+		// verify event object
810
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
+			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',
812
+				'event_espresso'), $label));
813
+		}
814
+		//if auto-draft then throw an error
815
+		if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
+			EE_Error::overwrite_errors();
817
+			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.'),
818
+				$label), __FILE__, __FUNCTION__, __LINE__);
819
+		}
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * admin_footer_scripts_global
826
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
+	 * will apply on ALL EE_Admin pages.
828
+	 *
829
+	 * @access public
830
+	 * @return void
831
+	 */
832
+	public function admin_footer_scripts_global()
833
+	{
834
+		$this->_add_admin_page_ajax_loading_img();
835
+		$this->_add_admin_page_overlay();
836
+	}
837
+
838
+
839
+
840
+	/**
841
+	 * add in any global scripts for cpt routes
842
+	 *
843
+	 * @return void
844
+	 */
845
+	public function load_global_scripts_styles()
846
+	{
847
+		parent::load_global_scripts_styles();
848
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
+			//setup custom post status object for localize script but only if we've got a cpt object
850
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
+			if ( ! empty($statuses)) {
852
+				//get ALL statuses!
853
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
+				//setup object
855
+				$ee_cpt_statuses = array();
856
+				foreach ($statuses as $status => $label) {
857
+					$ee_cpt_statuses[$status] = array(
858
+						'label'      => $label,
859
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
+					);
861
+				}
862
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
+			}
864
+		}
865
+	}
866
+
867
+
868
+
869
+	/**
870
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
+	 * insert/updates
872
+	 *
873
+	 * @param  int     $post_id ID of post being updated
874
+	 * @param  WP_Post $post    Post object from WP
875
+	 * @param  bool    $update  Whether this is an update or a new save.
876
+	 * @return void
877
+	 */
878
+	public function insert_update($post_id, $post, $update)
879
+	{
880
+		//make sure that if this is a revision OR trash action that we don't do any updates!
881
+		if (
882
+			isset($this->_req_data['action'])
883
+			&& (
884
+				$this->_req_data['action'] == 'restore'
885
+				|| $this->_req_data['action'] == 'trash'
886
+			)
887
+		) {
888
+			return;
889
+		}
890
+		$this->_set_model_object($post_id, true);
891
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
+		if ($update
893
+			&& (
894
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
895
+				|| $this->_cpt_model_obj->ID() !== $post_id
896
+			)
897
+		) {
898
+			return;
899
+		}
900
+		//check for autosave and update our req_data property accordingly.
901
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
902 902
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
903 903
 
904 904
                 foreach ( (array) $values as $key => $value ) {
@@ -908,524 +908,524 @@  discard block
 block discarded – undo
908 908
 
909 909
         }/**/ //TODO reactivate after autosave is implemented in 4.2
910 910
 
911
-        //take care of updating any selected page_template IF this cpt supports it.
912
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
-            //wp version aware.
914
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
-                $page_templates = wp_get_theme()->get_page_templates();
916
-            } else {
917
-                $post->page_template = $this->_req_data['page_template'];
918
-                $page_templates      = wp_get_theme()->get_page_templates($post);
919
-            }
920
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
-            } else {
923
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
-            }
925
-        }
926
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
-            return;
928
-        } //TODO we'll remove this after reimplementing autosave in 4.2
929
-        $this->_insert_update_cpt_item($post_id, $post);
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
-     * so we don't have to check for our CPT.
938
-     *
939
-     * @param  int $post_id ID of the post
940
-     * @return void
941
-     */
942
-    public function dont_permanently_delete_ee_cpts($post_id)
943
-    {
944
-        //only do this if we're actually processing one of our CPTs
945
-        //if our cpt object isn't existent then get out immediately.
946
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
-            return;
948
-        }
949
-        delete_post_meta($post_id, '_wp_trash_meta_status');
950
-        delete_post_meta($post_id, '_wp_trash_meta_time');
951
-        //our cpts may have comments so let's take care of that too
952
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
-     * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
-     *
962
-     * @param  int $post_id     ID of cpt item
963
-     * @param  int $revision_id ID of revision being restored
964
-     * @return void
965
-     */
966
-    public function restore_revision($post_id, $revision_id)
967
-    {
968
-        $this->_restore_cpt_item($post_id, $revision_id);
969
-        //global action
970
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
-        //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * @see restore_revision() for details
979
-     * @param  int $post_id     ID of cpt item
980
-     * @param  int $revision_id ID of revision for item
981
-     * @return void
982
-     */
983
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
984
-
985
-
986
-
987
-    /**
988
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
-     * To fix we have to reset the current_screen using the page_slug
991
-     * (which is identical - or should be - to our registered_post_type id.)
992
-     * Also, since the core WP file loads the admin_header.php for WP
993
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
-     *
996
-     * @return void
997
-     */
998
-    public function modify_current_screen()
999
-    {
1000
-        //ONLY do this if the current page_route IS a cpt route
1001
-        if ( ! $this->_cpt_route) {
1002
-            return;
1003
-        }
1004
-        //routing things REALLY early b/c this is a cpt admin page
1005
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
-        $this->_current_screen       = get_current_screen();
1007
-        $this->_current_screen->base = 'event-espresso';
1008
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
-        /*try {
911
+		//take care of updating any selected page_template IF this cpt supports it.
912
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
+			//wp version aware.
914
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
+				$page_templates = wp_get_theme()->get_page_templates();
916
+			} else {
917
+				$post->page_template = $this->_req_data['page_template'];
918
+				$page_templates      = wp_get_theme()->get_page_templates($post);
919
+			}
920
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
+			} else {
923
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
+			}
925
+		}
926
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
+			return;
928
+		} //TODO we'll remove this after reimplementing autosave in 4.2
929
+		$this->_insert_update_cpt_item($post_id, $post);
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
+	 * so we don't have to check for our CPT.
938
+	 *
939
+	 * @param  int $post_id ID of the post
940
+	 * @return void
941
+	 */
942
+	public function dont_permanently_delete_ee_cpts($post_id)
943
+	{
944
+		//only do this if we're actually processing one of our CPTs
945
+		//if our cpt object isn't existent then get out immediately.
946
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
+			return;
948
+		}
949
+		delete_post_meta($post_id, '_wp_trash_meta_status');
950
+		delete_post_meta($post_id, '_wp_trash_meta_time');
951
+		//our cpts may have comments so let's take care of that too
952
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
+	 * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
+	 *
962
+	 * @param  int $post_id     ID of cpt item
963
+	 * @param  int $revision_id ID of revision being restored
964
+	 * @return void
965
+	 */
966
+	public function restore_revision($post_id, $revision_id)
967
+	{
968
+		$this->_restore_cpt_item($post_id, $revision_id);
969
+		//global action
970
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
+		//class specific action so you can limit hooking into a specific page.
972
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * @see restore_revision() for details
979
+	 * @param  int $post_id     ID of cpt item
980
+	 * @param  int $revision_id ID of revision for item
981
+	 * @return void
982
+	 */
983
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
984
+
985
+
986
+
987
+	/**
988
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
+	 * To fix we have to reset the current_screen using the page_slug
991
+	 * (which is identical - or should be - to our registered_post_type id.)
992
+	 * Also, since the core WP file loads the admin_header.php for WP
993
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
+	 *
996
+	 * @return void
997
+	 */
998
+	public function modify_current_screen()
999
+	{
1000
+		//ONLY do this if the current page_route IS a cpt route
1001
+		if ( ! $this->_cpt_route) {
1002
+			return;
1003
+		}
1004
+		//routing things REALLY early b/c this is a cpt admin page
1005
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
+		$this->_current_screen       = get_current_screen();
1007
+		$this->_current_screen->base = 'event-espresso';
1008
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
+		/*try {
1010 1010
             $this->_route_admin_request();
1011 1011
         } catch ( EE_Error $e ) {
1012 1012
             $e->get_error();
1013 1013
         }/**/
1014
-    }
1015
-
1016
-
1017
-
1018
-    /**
1019
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
-     * default to be.
1023
-     *
1024
-     * @param string $title The new title (or existing if there is no editor_title defined)
1025
-     * @return string
1026
-     */
1027
-    public function add_custom_editor_default_title($title)
1028
-    {
1029
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
-            : $title;
1032
-    }
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
-     *
1039
-     * @param string $shortlink   The already generated shortlink
1040
-     * @param int    $id          Post ID for this item
1041
-     * @param string $context     The context for the link
1042
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
-     * @return string
1044
-     */
1045
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
-    {
1047
-        if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
-            $post = get_post($id);
1049
-            if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1051
-            }
1052
-        }
1053
-        return $shortlink;
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
-     * already run in modify_current_screen())
1061
-     *
1062
-     * @return void
1063
-     */
1064
-    public function route_admin_request()
1065
-    {
1066
-        if ($this->_cpt_route) {
1067
-            return;
1068
-        }
1069
-        try {
1070
-            $this->_route_admin_request();
1071
-        } catch (EE_Error $e) {
1072
-            $e->get_error();
1073
-        }
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
-     *
1081
-     * @return string html
1082
-     */
1083
-    public function cpt_post_form_hidden_input()
1084
-    {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
-        echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
-        echo '</div>';
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
-     *
1098
-     * @param  string $location Original location url
1099
-     * @param  int    $status   Status for http header
1100
-     * @return string           new (or original) url to redirect to.
1101
-     */
1102
-    public function revision_redirect($location, $status)
1103
-    {
1104
-        //get revision
1105
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
-        //can't do anything without revision so let's get out if not present
1107
-        if (empty($rev_id)) {
1108
-            return $location;
1109
-        }
1110
-        //get rev_post_data
1111
-        $rev = get_post($rev_id);
1112
-        $admin_url = $this->_admin_base_url;
1113
-        $query_args = array(
1114
-            'action'   => 'edit',
1115
-            'post'     => $rev->post_parent,
1116
-            'revision' => $rev_id,
1117
-            'message'  => 5,
1118
-        );
1119
-        $this->_process_notices($query_args, true);
1120
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1121
-    }
1122
-
1123
-
1124
-
1125
-    /**
1126
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
-     *
1128
-     * @param  string $link    the original generated link
1129
-     * @param  int    $id      post id
1130
-     * @param  string $context optional, defaults to display.  How to write the '&'
1131
-     * @return string          the link
1132
-     */
1133
-    public function modify_edit_post_link($link, $id, $context)
1134
-    {
1135
-        $post = get_post($id);
1136
-        if ( ! isset($this->_req_data['action'])
1137
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
-        ) {
1140
-            return $link;
1141
-        }
1142
-        $query_args = array(
1143
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
-                ? $this->_cpt_edit_routes[$post->post_type]
1145
-                : 'edit',
1146
-            'post'   => $id,
1147
-        );
1148
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
-    }
1150
-
1151
-
1152
-    /**
1153
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
-     * our routes.
1155
-     *
1156
-     * @param  string $delete_link  original delete link
1157
-     * @param  int    $post_id      id of cpt object
1158
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
-     * @return string new delete link
1160
-     * @throws EE_Error
1161
-     */
1162
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
-    {
1164
-        $post = get_post($post_id);
1165
-        if (! isset($this->_req_data['action'], $this->_req_data['post'])
1166
-             || (isset($this->_cpt_routes[$this->_req_data['action']])
1167
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168
-        ) {
1169
-            return $delete_link;
1170
-        }
1171
-        $this->_set_model_object($this->_req_data['post'], true);
1172
-        //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174
-
1175
-        return EE_Admin_Page::add_query_args_and_nonce(
1176
-            array(
1177
-                'page' => $this->_req_data['page'],
1178
-                'action' => $action,
1179
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1180
-                    => $this->_req_data['post']
1181
-            ),
1182
-            admin_url()
1183
-        );
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1190
-     * so that we can hijack the default redirect locations for wp custom post types
1191
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1192
-     *
1193
-     * @param  string $location This is the incoming currently set redirect location
1194
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1195
-     * @return string           the new location to redirect to
1196
-     */
1197
-    public function cpt_post_location_redirect($location, $post_id)
1198
-    {
1199
-        //we DO have a match so let's setup the url
1200
-        //we have to get the post to determine our route
1201
-        $post       = get_post($post_id);
1202
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1203
-        //shared query_args
1204
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1205
-        $admin_url  = $this->_admin_base_url;
1206
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1207
-            $status = get_post_status($post_id);
1208
-            if (isset($this->_req_data['publish'])) {
1209
-                switch ($status) {
1210
-                    case 'pending':
1211
-                        $message = 8;
1212
-                        break;
1213
-                    case 'future':
1214
-                        $message = 9;
1215
-                        break;
1216
-                    default:
1217
-                        $message = 6;
1218
-                }
1219
-            } else {
1220
-                $message = 'draft' == $status ? 10 : 1;
1221
-            }
1222
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1223
-            $message = 2;
1224
-            //			$append = '#postcustom';
1225
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1226
-            $message = 3;
1227
-            //			$append = '#postcustom';
1228
-        } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1229
-            $message = 7;
1230
-        } else {
1231
-            $message = 4;
1232
-        }
1233
-        //change the message if the post type is not viewable on the frontend
1234
-        $this->_cpt_object = get_post_type_object($post->post_type);
1235
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1236
-        $query_args = array_merge(array('message' => $message), $query_args);
1237
-        $this->_process_notices($query_args, true);
1238
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1239
-    }
1240
-
1241
-
1242
-
1243
-    /**
1244
-     * This method is called to inject nav tabs on core WP cpt pages
1245
-     *
1246
-     * @access public
1247
-     * @return string html
1248
-     */
1249
-    public function inject_nav_tabs()
1250
-    {
1251
-        //can we hijack and insert the nav_tabs?
1252
-        $nav_tabs = $this->_get_main_nav_tabs();
1253
-        //first close off existing form tag
1254
-        $html = '>';
1255
-        $html .= $nav_tabs;
1256
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1257
-        $html .= '<span></span';
1258
-        echo $html;
1259
-    }
1260
-
1261
-
1262
-
1263
-    /**
1264
-     * This just sets up the post update messages when an update form is loaded
1265
-     *
1266
-     * @access public
1267
-     * @param  array $messages the original messages array
1268
-     * @return array           the new messages array
1269
-     */
1270
-    public function post_update_messages($messages)
1271
-    {
1272
-        global $post;
1273
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1274
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1275
-        //		$post_type = $post ? $post->post_type : false;
1276
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1014
+	}
1015
+
1016
+
1017
+
1018
+	/**
1019
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
+	 * default to be.
1023
+	 *
1024
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1025
+	 * @return string
1026
+	 */
1027
+	public function add_custom_editor_default_title($title)
1028
+	{
1029
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
+			: $title;
1032
+	}
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
+	 *
1039
+	 * @param string $shortlink   The already generated shortlink
1040
+	 * @param int    $id          Post ID for this item
1041
+	 * @param string $context     The context for the link
1042
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
+	 * @return string
1044
+	 */
1045
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
+	{
1047
+		if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
+			$post = get_post($id);
1049
+			if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
+				$shortlink = home_url('?p=' . $post->ID);
1051
+			}
1052
+		}
1053
+		return $shortlink;
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
+	 * already run in modify_current_screen())
1061
+	 *
1062
+	 * @return void
1063
+	 */
1064
+	public function route_admin_request()
1065
+	{
1066
+		if ($this->_cpt_route) {
1067
+			return;
1068
+		}
1069
+		try {
1070
+			$this->_route_admin_request();
1071
+		} catch (EE_Error $e) {
1072
+			$e->get_error();
1073
+		}
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
+	 *
1081
+	 * @return string html
1082
+	 */
1083
+	public function cpt_post_form_hidden_input()
1084
+	{
1085
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
+		echo '<div id="ee-cpt-hidden-inputs">';
1088
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
+		echo '</div>';
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
+	 *
1098
+	 * @param  string $location Original location url
1099
+	 * @param  int    $status   Status for http header
1100
+	 * @return string           new (or original) url to redirect to.
1101
+	 */
1102
+	public function revision_redirect($location, $status)
1103
+	{
1104
+		//get revision
1105
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
+		//can't do anything without revision so let's get out if not present
1107
+		if (empty($rev_id)) {
1108
+			return $location;
1109
+		}
1110
+		//get rev_post_data
1111
+		$rev = get_post($rev_id);
1112
+		$admin_url = $this->_admin_base_url;
1113
+		$query_args = array(
1114
+			'action'   => 'edit',
1115
+			'post'     => $rev->post_parent,
1116
+			'revision' => $rev_id,
1117
+			'message'  => 5,
1118
+		);
1119
+		$this->_process_notices($query_args, true);
1120
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1121
+	}
1122
+
1123
+
1124
+
1125
+	/**
1126
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
+	 *
1128
+	 * @param  string $link    the original generated link
1129
+	 * @param  int    $id      post id
1130
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1131
+	 * @return string          the link
1132
+	 */
1133
+	public function modify_edit_post_link($link, $id, $context)
1134
+	{
1135
+		$post = get_post($id);
1136
+		if ( ! isset($this->_req_data['action'])
1137
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
+		) {
1140
+			return $link;
1141
+		}
1142
+		$query_args = array(
1143
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
+				? $this->_cpt_edit_routes[$post->post_type]
1145
+				: 'edit',
1146
+			'post'   => $id,
1147
+		);
1148
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
+	}
1150
+
1151
+
1152
+	/**
1153
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
+	 * our routes.
1155
+	 *
1156
+	 * @param  string $delete_link  original delete link
1157
+	 * @param  int    $post_id      id of cpt object
1158
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
+	 * @return string new delete link
1160
+	 * @throws EE_Error
1161
+	 */
1162
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
+	{
1164
+		$post = get_post($post_id);
1165
+		if (! isset($this->_req_data['action'], $this->_req_data['post'])
1166
+			 || (isset($this->_cpt_routes[$this->_req_data['action']])
1167
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168
+		) {
1169
+			return $delete_link;
1170
+		}
1171
+		$this->_set_model_object($this->_req_data['post'], true);
1172
+		//returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174
+
1175
+		return EE_Admin_Page::add_query_args_and_nonce(
1176
+			array(
1177
+				'page' => $this->_req_data['page'],
1178
+				'action' => $action,
1179
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1180
+					=> $this->_req_data['post']
1181
+			),
1182
+			admin_url()
1183
+		);
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1190
+	 * so that we can hijack the default redirect locations for wp custom post types
1191
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1192
+	 *
1193
+	 * @param  string $location This is the incoming currently set redirect location
1194
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1195
+	 * @return string           the new location to redirect to
1196
+	 */
1197
+	public function cpt_post_location_redirect($location, $post_id)
1198
+	{
1199
+		//we DO have a match so let's setup the url
1200
+		//we have to get the post to determine our route
1201
+		$post       = get_post($post_id);
1202
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1203
+		//shared query_args
1204
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1205
+		$admin_url  = $this->_admin_base_url;
1206
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1207
+			$status = get_post_status($post_id);
1208
+			if (isset($this->_req_data['publish'])) {
1209
+				switch ($status) {
1210
+					case 'pending':
1211
+						$message = 8;
1212
+						break;
1213
+					case 'future':
1214
+						$message = 9;
1215
+						break;
1216
+					default:
1217
+						$message = 6;
1218
+				}
1219
+			} else {
1220
+				$message = 'draft' == $status ? 10 : 1;
1221
+			}
1222
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1223
+			$message = 2;
1224
+			//			$append = '#postcustom';
1225
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1226
+			$message = 3;
1227
+			//			$append = '#postcustom';
1228
+		} elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1229
+			$message = 7;
1230
+		} else {
1231
+			$message = 4;
1232
+		}
1233
+		//change the message if the post type is not viewable on the frontend
1234
+		$this->_cpt_object = get_post_type_object($post->post_type);
1235
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1236
+		$query_args = array_merge(array('message' => $message), $query_args);
1237
+		$this->_process_notices($query_args, true);
1238
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1239
+	}
1240
+
1241
+
1242
+
1243
+	/**
1244
+	 * This method is called to inject nav tabs on core WP cpt pages
1245
+	 *
1246
+	 * @access public
1247
+	 * @return string html
1248
+	 */
1249
+	public function inject_nav_tabs()
1250
+	{
1251
+		//can we hijack and insert the nav_tabs?
1252
+		$nav_tabs = $this->_get_main_nav_tabs();
1253
+		//first close off existing form tag
1254
+		$html = '>';
1255
+		$html .= $nav_tabs;
1256
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1257
+		$html .= '<span></span';
1258
+		echo $html;
1259
+	}
1260
+
1261
+
1262
+
1263
+	/**
1264
+	 * This just sets up the post update messages when an update form is loaded
1265
+	 *
1266
+	 * @access public
1267
+	 * @param  array $messages the original messages array
1268
+	 * @return array           the new messages array
1269
+	 */
1270
+	public function post_update_messages($messages)
1271
+	{
1272
+		global $post;
1273
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1274
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1275
+		//		$post_type = $post ? $post->post_type : false;
1276
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1277 1277
 
1278 1278
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1279
-        $messages[$post->post_type] = array(
1280
-            0 => '', //Unused. Messages start at index 1.
1281
-            1 => sprintf(
1282
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283
-                $this->_cpt_object->labels->singular_name,
1284
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1285
-                '</a>'
1286
-            ),
1287
-            2 => __('Custom field updated'),
1288
-            3 => __('Custom field deleted.'),
1289
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1292
-                : false,
1293
-            6 => sprintf(
1294
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295
-                $this->_cpt_object->labels->singular_name,
1296
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1297
-                '</a>'
1298
-            ),
1299
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300
-            8 => sprintf(
1301
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302
-                $this->_cpt_object->labels->singular_name,
1303
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1304
-                '</a>'
1305
-            ),
1306
-            9 => sprintf(
1307
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308
-                $this->_cpt_object->labels->singular_name,
1309
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1311
-                '</a>'
1312
-            ),
1313
-            10 => sprintf(
1314
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315
-                $this->_cpt_object->labels->singular_name,
1316
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317
-                '</a>'
1318
-            ),
1319
-        );
1320
-        return $messages;
1321
-    }
1322
-
1323
-
1324
-
1325
-    /**
1326
-     * default method for the 'create_new' route for cpt admin pages.
1327
-     * For reference what to include in here, see wp-admin/post-new.php
1328
-     *
1329
-     * @access  protected
1330
-     * @return string template for add new cpt form
1331
-     */
1332
-    protected function _create_new_cpt_item()
1333
-    {
1334
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1335
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1336
-        $post_type_object = $this->_cpt_object;
1337
-        $title            = $post_type_object->labels->add_new_item;
1338
-        $editing          = true;
1339
-        wp_enqueue_script('autosave');
1340
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1341
-        $post_ID = $post->ID;
1342
-        $is_IE   = $is_IE;
1343
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344
-        //modify the default editor title field with default title.
1345
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1347
-    }
1348
-
1349
-
1350
-
1351
-    public function add_new_admin_page_global()
1352
-    {
1353
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1354
-        ?>
1279
+		$messages[$post->post_type] = array(
1280
+			0 => '', //Unused. Messages start at index 1.
1281
+			1 => sprintf(
1282
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283
+				$this->_cpt_object->labels->singular_name,
1284
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1285
+				'</a>'
1286
+			),
1287
+			2 => __('Custom field updated'),
1288
+			3 => __('Custom field deleted.'),
1289
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1292
+				: false,
1293
+			6 => sprintf(
1294
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295
+				$this->_cpt_object->labels->singular_name,
1296
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1297
+				'</a>'
1298
+			),
1299
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300
+			8 => sprintf(
1301
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302
+				$this->_cpt_object->labels->singular_name,
1303
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1304
+				'</a>'
1305
+			),
1306
+			9 => sprintf(
1307
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308
+				$this->_cpt_object->labels->singular_name,
1309
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1311
+				'</a>'
1312
+			),
1313
+			10 => sprintf(
1314
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315
+				$this->_cpt_object->labels->singular_name,
1316
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317
+				'</a>'
1318
+			),
1319
+		);
1320
+		return $messages;
1321
+	}
1322
+
1323
+
1324
+
1325
+	/**
1326
+	 * default method for the 'create_new' route for cpt admin pages.
1327
+	 * For reference what to include in here, see wp-admin/post-new.php
1328
+	 *
1329
+	 * @access  protected
1330
+	 * @return string template for add new cpt form
1331
+	 */
1332
+	protected function _create_new_cpt_item()
1333
+	{
1334
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1335
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1336
+		$post_type_object = $this->_cpt_object;
1337
+		$title            = $post_type_object->labels->add_new_item;
1338
+		$editing          = true;
1339
+		wp_enqueue_script('autosave');
1340
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1341
+		$post_ID = $post->ID;
1342
+		$is_IE   = $is_IE;
1343
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344
+		//modify the default editor title field with default title.
1345
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1347
+	}
1348
+
1349
+
1350
+
1351
+	public function add_new_admin_page_global()
1352
+	{
1353
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1354
+		?>
1355 1355
         <script type="text/javascript">
1356 1356
             adminpage = '<?php echo $admin_page; ?>';
1357 1357
         </script>
1358 1358
         <?php
1359
-    }
1360
-
1361
-
1362
-
1363
-    /**
1364
-     * default method for the 'edit' route for cpt admin pages
1365
-     * For reference on what to put in here, refer to wp-admin/post.php
1366
-     *
1367
-     * @access protected
1368
-     * @return string   template for edit cpt form
1369
-     */
1370
-    protected function _edit_cpt_item()
1371
-    {
1372
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1373
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1374
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1375
-        if (empty ($post)) {
1376
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1377
-        }
1378
-        if ( ! empty($_GET['get-post-lock'])) {
1379
-            wp_set_post_lock($post_id);
1380
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1381
-            exit();
1382
-        }
1383
-
1384
-        // template vars
1385
-        $editing          = true;
1386
-        $post_ID          = $post_id;
1387
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1388
-        $post_type_object = $this->_cpt_object;
1389
-
1390
-        if ( ! wp_check_post_lock($post->ID)) {
1391
-            $active_post_lock = wp_set_post_lock($post->ID);
1392
-            //wp_enqueue_script('autosave');
1393
-        }
1394
-        $title = $this->_cpt_object->labels->edit_item;
1395
-        add_action('admin_footer', '_admin_notice_post_locked');
1396
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1397
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1398
-        ) {
1399
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1400
-                'create_new', $this);
1401
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1402
-                'action' => $create_new_action,
1403
-                'page'   => $this->page_slug,
1404
-            ), 'admin.php');
1405
-        }
1406
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1407
-            wp_enqueue_script('admin-comments');
1408
-            enqueue_comment_hotkeys_js();
1409
-        }
1410
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411
-        //modify the default editor title field with default title.
1412
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1414
-    }
1415
-
1416
-
1417
-
1418
-    /**
1419
-     * some getters
1420
-     */
1421
-    /**
1422
-     * This returns the protected _cpt_model_obj property
1423
-     *
1424
-     * @return EE_CPT_Base
1425
-     */
1426
-    public function get_cpt_model_obj()
1427
-    {
1428
-        return $this->_cpt_model_obj;
1429
-    }
1359
+	}
1360
+
1361
+
1362
+
1363
+	/**
1364
+	 * default method for the 'edit' route for cpt admin pages
1365
+	 * For reference on what to put in here, refer to wp-admin/post.php
1366
+	 *
1367
+	 * @access protected
1368
+	 * @return string   template for edit cpt form
1369
+	 */
1370
+	protected function _edit_cpt_item()
1371
+	{
1372
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1373
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1374
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1375
+		if (empty ($post)) {
1376
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1377
+		}
1378
+		if ( ! empty($_GET['get-post-lock'])) {
1379
+			wp_set_post_lock($post_id);
1380
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1381
+			exit();
1382
+		}
1383
+
1384
+		// template vars
1385
+		$editing          = true;
1386
+		$post_ID          = $post_id;
1387
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1388
+		$post_type_object = $this->_cpt_object;
1389
+
1390
+		if ( ! wp_check_post_lock($post->ID)) {
1391
+			$active_post_lock = wp_set_post_lock($post->ID);
1392
+			//wp_enqueue_script('autosave');
1393
+		}
1394
+		$title = $this->_cpt_object->labels->edit_item;
1395
+		add_action('admin_footer', '_admin_notice_post_locked');
1396
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1397
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1398
+		) {
1399
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1400
+				'create_new', $this);
1401
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1402
+				'action' => $create_new_action,
1403
+				'page'   => $this->page_slug,
1404
+			), 'admin.php');
1405
+		}
1406
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1407
+			wp_enqueue_script('admin-comments');
1408
+			enqueue_comment_hotkeys_js();
1409
+		}
1410
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411
+		//modify the default editor title field with default title.
1412
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1414
+	}
1415
+
1416
+
1417
+
1418
+	/**
1419
+	 * some getters
1420
+	 */
1421
+	/**
1422
+	 * This returns the protected _cpt_model_obj property
1423
+	 *
1424
+	 * @return EE_CPT_Base
1425
+	 */
1426
+	public function get_cpt_model_obj()
1427
+	{
1428
+		return $this->_cpt_model_obj;
1429
+	}
1430 1430
 
1431 1431
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         //filter _autosave_containers
280 280
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281 281
             $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
282
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
283 283
             $containers, $this);
284 284
 
285 285
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         parent::_load_page_dependencies();
370 370
         //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371 371
         global $pagenow;
372
-        do_action('load-' . $pagenow);
372
+        do_action('load-'.$pagenow);
373 373
         $this->modify_current_screen();
374 374
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375 375
         //we route REALLY early.
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
                 'admin.php?page=espresso_registrations&action=contact_list',
401 401
             ),
402 402
             1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
403
+                'edit.php?post_type='.$this->_cpt_object->name,
404
+                'admin.php?page='.$this->_cpt_object->name,
405 405
             ),
406 406
         );
407 407
         foreach ($routes_to_match as $route_matches) {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $cpt_has_support = ! empty($cpt_args['page_templates']);
430 430
 
431 431
         //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
432
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
433 433
             $post_templates = wp_get_theme()->get_post_templates();
434 434
             //if there are $post_templates for this cpt, then we return false for this method because
435 435
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         global $post;
453 453
         $template = '';
454 454
 
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
455
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
456 456
             $page_template_count = count(get_page_templates());
457 457
         } else {
458 458
             $page_template_count = count(get_page_templates($post));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $post = get_post($id);
490 490
         if ('publish' != get_post_status($post)) {
491 491
             //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
492
+            require_once(EE_CORE.'wordpress-shims.php');
493 493
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494 494
                        . get_preview_post_link($id)
495 495
                        . '" class="button button-small">'
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $template_args['statuses']         = $statuses;
528 528
         }
529 529
 
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
530
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
531 531
         EEH_Template::display_template($template, $template_args);
532 532
     }
533 533
 
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
             define('DOING_AUTOSAVE', true);
573 573
         }
574 574
         //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
575
+        if (method_exists($this, '_ee_autosave_'.$this->_current_view)) {
576
+            call_user_func(array($this, '_ee_autosave_'.$this->_current_view));
577 577
         } else {
578 578
             $this->_template_args['success'] = true;
579 579
         }
580 580
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
581
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
582 582
         //now let's return json
583 583
         $this->_return_json();
584 584
     }
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
         //global action
970 970
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971 971
         //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
972
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
973 973
     }
974 974
 
975 975
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
         if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048 1048
             $post = get_post($id);
1049 1049
             if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1050
+                $shortlink = home_url('?p='.$post->ID);
1051 1051
             }
1052 1052
         }
1053 1053
         return $shortlink;
@@ -1082,11 +1082,11 @@  discard block
 block discarded – undo
1082 1082
      */
1083 1083
     public function cpt_post_form_hidden_input()
1084 1084
     {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1085
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1086 1086
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087 1087
         echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1088
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1089
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1090 1090
         echo '</div>';
1091 1091
     }
1092 1092
 
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
     public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163 1163
     {
1164 1164
         $post = get_post($post_id);
1165
-        if (! isset($this->_req_data['action'], $this->_req_data['post'])
1165
+        if ( ! isset($this->_req_data['action'], $this->_req_data['post'])
1166 1166
              || (isset($this->_cpt_routes[$this->_req_data['action']])
1167 1167
                  && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168 1168
         ) {
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
         }
1171 1171
         $this->_set_model_object($this->_req_data['post'], true);
1172 1172
         //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1173
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174 1174
 
1175 1175
         return EE_Admin_Page::add_query_args_and_nonce(
1176 1176
             array(
@@ -1281,39 +1281,39 @@  discard block
 block discarded – undo
1281 1281
             1 => sprintf(
1282 1282
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283 1283
                 $this->_cpt_object->labels->singular_name,
1284
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1284
+                '<a href="'.esc_url(get_permalink($id)).'">',
1285 1285
                 '</a>'
1286 1286
             ),
1287 1287
             2 => __('Custom field updated'),
1288 1288
             3 => __('Custom field deleted.'),
1289 1289
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290 1290
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1291
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1292 1292
                 : false,
1293 1293
             6 => sprintf(
1294 1294
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295 1295
                 $this->_cpt_object->labels->singular_name,
1296
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1296
+                '<a href="'.esc_url(get_permalink($id)).'">',
1297 1297
                 '</a>'
1298 1298
             ),
1299 1299
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300 1300
             8 => sprintf(
1301 1301
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302 1302
                 $this->_cpt_object->labels->singular_name,
1303
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1303
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1304 1304
                 '</a>'
1305 1305
             ),
1306 1306
             9 => sprintf(
1307 1307
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308 1308
                 $this->_cpt_object->labels->singular_name,
1309
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1309
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1310
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1311 1311
                 '</a>'
1312 1312
             ),
1313 1313
             10 => sprintf(
1314 1314
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315 1315
                 $this->_cpt_object->labels->singular_name,
1316
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1316
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317 1317
                 '</a>'
1318 1318
             ),
1319 1319
         );
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344 1344
         //modify the default editor title field with default title.
1345 1345
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1346
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1347 1347
     }
1348 1348
 
1349 1349
 
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411 1411
         //modify the default editor title field with default title.
1412 1412
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1413
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1414 1414
     }
1415 1415
 
1416 1416
 
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.43.rc.007');
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.43.rc.007');
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/EE_System.core.php 2 patches
Indentation   +1573 added lines, -1573 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -20,1578 +20,1578 @@  discard block
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    /**
24
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
25
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
26
-     */
27
-    const req_type_normal = 0;
28
-
29
-    /**
30
-     * Indicates this is a brand new installation of EE so we should install
31
-     * tables and default data etc
32
-     */
33
-    const req_type_new_activation = 1;
34
-
35
-    /**
36
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
37
-     * and we just exited maintenance mode). We MUST check the database is setup properly
38
-     * and that default data is setup too
39
-     */
40
-    const req_type_reactivation = 2;
41
-
42
-    /**
43
-     * indicates that EE has been upgraded since its previous request.
44
-     * We may have data migration scripts to call and will want to trigger maintenance mode
45
-     */
46
-    const req_type_upgrade = 3;
47
-
48
-    /**
49
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
50
-     */
51
-    const req_type_downgrade = 4;
52
-
53
-    /**
54
-     * @deprecated since version 4.6.0.dev.006
55
-     * Now whenever a new_activation is detected the request type is still just
56
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
57
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
58
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
59
-     * (Specifically, when the migration manager indicates migrations are finished
60
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
61
-     */
62
-    const req_type_activation_but_not_installed = 5;
63
-
64
-    /**
65
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
66
-     */
67
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
68
-
69
-
70
-    /**
71
-     * @var EE_System $_instance
72
-     */
73
-    private static $_instance;
74
-
75
-    /**
76
-     * @var EE_Registry $registry
77
-     */
78
-    private $registry;
79
-
80
-    /**
81
-     * @var LoaderInterface $loader
82
-     */
83
-    private $loader;
84
-
85
-    /**
86
-     * @var EE_Capabilities $capabilities
87
-     */
88
-    private $capabilities;
89
-
90
-    /**
91
-     * @var EE_Request $request
92
-     */
93
-    private $request;
94
-
95
-    /**
96
-     * @var EE_Maintenance_Mode $maintenance_mode
97
-     */
98
-    private $maintenance_mode;
99
-
100
-    /**
101
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
102
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
103
-     *
104
-     * @var int
105
-     */
106
-    private $_req_type;
107
-
108
-    /**
109
-     * Whether or not there was a non-micro version change in EE core version during this request
110
-     *
111
-     * @var boolean
112
-     */
113
-    private $_major_version_change = false;
114
-
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param EE_Registry|null         $registry
120
-     * @param LoaderInterface|null     $loader
121
-     * @param EE_Capabilities|null     $capabilities
122
-     * @param EE_Request|null          $request
123
-     * @param EE_Maintenance_Mode|null $maintenance_mode
124
-     * @return EE_System
125
-     */
126
-    public static function instance(
127
-        EE_Registry $registry = null,
128
-        LoaderInterface $loader = null,
129
-        EE_Capabilities $capabilities = null,
130
-        EE_Request $request = null,
131
-        EE_Maintenance_Mode $maintenance_mode = null
132
-    ) {
133
-        // check if class object is instantiated
134
-        if (! self::$_instance instanceof EE_System) {
135
-            self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
136
-        }
137
-        return self::$_instance;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * resets the instance and returns it
144
-     *
145
-     * @return EE_System
146
-     */
147
-    public static function reset()
148
-    {
149
-        self::$_instance->_req_type = null;
150
-        //make sure none of the old hooks are left hanging around
151
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
152
-        //we need to reset the migration manager in order for it to detect DMSs properly
153
-        EE_Data_Migration_Manager::reset();
154
-        self::instance()->detect_activations_or_upgrades();
155
-        self::instance()->perform_activations_upgrades_and_migrations();
156
-        return self::instance();
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * sets hooks for running rest of system
163
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
164
-     * starting EE Addons from any other point may lead to problems
165
-     *
166
-     * @param EE_Registry         $registry
167
-     * @param LoaderInterface     $loader
168
-     * @param EE_Capabilities     $capabilities
169
-     * @param EE_Request          $request
170
-     * @param EE_Maintenance_Mode $maintenance_mode
171
-     */
172
-    private function __construct(
173
-        EE_Registry $registry,
174
-        LoaderInterface $loader,
175
-        EE_Capabilities $capabilities,
176
-        EE_Request $request,
177
-        EE_Maintenance_Mode $maintenance_mode
178
-    ) {
179
-        $this->registry = $registry;
180
-        $this->loader = $loader;
181
-        $this->capabilities = $capabilities;
182
-        $this->request = $request;
183
-        $this->maintenance_mode = $maintenance_mode;
184
-        do_action('AHEE__EE_System__construct__begin', $this);
185
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
186
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
187
-        // when an ee addon is activated, we want to call the core hook(s) again
188
-        // because the newly-activated addon didn't get a chance to run at all
189
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
190
-        // detect whether install or upgrade
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
193
-            3
194
-        );
195
-        // load EE_Config, EE_Textdomain, etc
196
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
197
-        // load EE_Config, EE_Textdomain, etc
198
-        add_action(
199
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
200
-            array($this, 'register_shortcodes_modules_and_widgets'), 7
201
-        );
202
-        // you wanna get going? I wanna get going... let's get going!
203
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
204
-        //other housekeeping
205
-        //exclude EE critical pages from wp_list_pages
206
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
207
-        // ALL EE Addons should use the following hook point to attach their initial setup too
208
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
209
-        do_action('AHEE__EE_System__construct__complete', $this);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * load_espresso_addons
216
-     * allow addons to load first so that they can set hooks for running DMS's, etc
217
-     * this is hooked into both:
218
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
219
-     *        which runs during the WP 'plugins_loaded' action at priority 5
220
-     *    and the WP 'activate_plugin' hook point
221
-     *
222
-     * @access public
223
-     * @return void
224
-     * @throws EE_Error
225
-     */
226
-    public function load_espresso_addons()
227
-    {
228
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
229
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
230
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
231
-        //caps need to be initialized on every request so that capability maps are set.
232
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
233
-        $this->capabilities->init_caps();
234
-        do_action('AHEE__EE_System__load_espresso_addons');
235
-        //if the WP API basic auth plugin isn't already loaded, load it now.
236
-        //We want it for mobile apps. Just include the entire plugin
237
-        //also, don't load the basic auth when a plugin is getting activated, because
238
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
239
-        //and causes a fatal error
240
-        if (
241
-            ! (
242
-                isset($_GET['activate'])
243
-                && $_GET['activate'] === 'true'
244
-            )
245
-            && ! function_exists('json_basic_auth_handler')
246
-            && ! function_exists('json_basic_auth_error')
247
-            && ! (
248
-                isset($_GET['action'])
249
-                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
250
-            )
251
-        ) {
252
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
253
-        }
254
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * detect_activations_or_upgrades
261
-     * Checks for activation or upgrade of core first;
262
-     * then also checks if any registered addons have been activated or upgraded
263
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
264
-     * which runs during the WP 'plugins_loaded' action at priority 3
265
-     *
266
-     * @access public
267
-     * @return void
268
-     */
269
-    public function detect_activations_or_upgrades()
270
-    {
271
-        //first off: let's make sure to handle core
272
-        $this->detect_if_activation_or_upgrade();
273
-        foreach ($this->registry->addons as $addon) {
274
-            if ($addon instanceof EE_Addon) {
275
-                //detect teh request type for that addon
276
-                $addon->detect_activation_or_upgrade();
277
-            }
278
-        }
279
-    }
280
-
281
-
282
-
283
-    /**
284
-     * detect_if_activation_or_upgrade
285
-     * Takes care of detecting whether this is a brand new install or code upgrade,
286
-     * and either setting up the DB or setting up maintenance mode etc.
287
-     *
288
-     * @access public
289
-     * @return void
290
-     */
291
-    public function detect_if_activation_or_upgrade()
292
-    {
293
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
294
-        // check if db has been updated, or if its a brand-new installation
295
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
296
-        $request_type = $this->detect_req_type($espresso_db_update);
297
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
298
-        switch ($request_type) {
299
-            case EE_System::req_type_new_activation:
300
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
301
-                $this->_handle_core_version_change($espresso_db_update);
302
-                break;
303
-            case EE_System::req_type_reactivation:
304
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
305
-                $this->_handle_core_version_change($espresso_db_update);
306
-                break;
307
-            case EE_System::req_type_upgrade:
308
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
309
-                //migrations may be required now that we've upgraded
310
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
311
-                $this->_handle_core_version_change($espresso_db_update);
312
-                //				echo "done upgrade";die;
313
-                break;
314
-            case EE_System::req_type_downgrade:
315
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
316
-                //its possible migrations are no longer required
317
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
318
-                $this->_handle_core_version_change($espresso_db_update);
319
-                break;
320
-            case EE_System::req_type_normal:
321
-            default:
322
-                //				$this->_maybe_redirect_to_ee_about();
323
-                break;
324
-        }
325
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
326
-    }
327
-
328
-
329
-
330
-    /**
331
-     * Updates the list of installed versions and sets hooks for
332
-     * initializing the database later during the request
333
-     *
334
-     * @param array $espresso_db_update
335
-     */
336
-    private function _handle_core_version_change($espresso_db_update)
337
-    {
338
-        $this->update_list_of_installed_versions($espresso_db_update);
339
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
340
-        add_action(
341
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
342
-            array($this, 'initialize_db_if_no_migrations_required')
343
-        );
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
350
-     * information about what versions of EE have been installed and activated,
351
-     * NOT necessarily the state of the database
352
-     *
353
-     * @param null $espresso_db_update
354
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
355
-     *           from the options table
356
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
357
-     */
358
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359
-    {
360
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
-        if (! $espresso_db_update) {
362
-            $espresso_db_update = get_option('espresso_db_update');
363
-        }
364
-        // check that option is an array
365
-        if (! is_array($espresso_db_update)) {
366
-            // if option is FALSE, then it never existed
367
-            if ($espresso_db_update === false) {
368
-                // make $espresso_db_update an array and save option with autoload OFF
369
-                $espresso_db_update = array();
370
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
371
-            } else {
372
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
373
-                $espresso_db_update = array($espresso_db_update => array());
374
-                update_option('espresso_db_update', $espresso_db_update);
375
-            }
376
-        } else {
377
-            $corrected_db_update = array();
378
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
379
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
380
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
381
-                    //the key is an int, and the value IS NOT an array
382
-                    //so it must be numerically-indexed, where values are versions installed...
383
-                    //fix it!
384
-                    $version_string = $should_be_array;
385
-                    $corrected_db_update[$version_string] = array('unknown-date');
386
-                } else {
387
-                    //ok it checks out
388
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
389
-                }
390
-            }
391
-            $espresso_db_update = $corrected_db_update;
392
-            update_option('espresso_db_update', $espresso_db_update);
393
-        }
394
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
395
-        return $espresso_db_update;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Does the traditional work of setting up the plugin's database and adding default data.
402
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
403
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
404
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
405
-     * so that it will be done when migrations are finished
406
-     *
407
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
408
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
409
-     *                                       This is a resource-intensive job
410
-     *                                       so we prefer to only do it when necessary
411
-     * @return void
412
-     * @throws EE_Error
413
-     */
414
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
415
-    {
416
-        $request_type = $this->detect_req_type();
417
-        //only initialize system if we're not in maintenance mode.
418
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
419
-            update_option('ee_flush_rewrite_rules', true);
420
-            if ($verify_schema) {
421
-                EEH_Activation::initialize_db_and_folders();
422
-            }
423
-            EEH_Activation::initialize_db_content();
424
-            EEH_Activation::system_initialization();
425
-            if ($initialize_addons_too) {
426
-                $this->initialize_addons();
427
-            }
428
-        } else {
429
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
430
-        }
431
-        if ($request_type === EE_System::req_type_new_activation
432
-            || $request_type === EE_System::req_type_reactivation
433
-            || (
434
-                $request_type === EE_System::req_type_upgrade
435
-                && $this->is_major_version_change()
436
-            )
437
-        ) {
438
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
439
-        }
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * Initializes the db for all registered addons
446
-     *
447
-     * @throws EE_Error
448
-     */
449
-    public function initialize_addons()
450
-    {
451
-        //foreach registered addon, make sure its db is up-to-date too
452
-        foreach ($this->registry->addons as $addon) {
453
-            if ($addon instanceof EE_Addon) {
454
-                $addon->initialize_db_if_no_migrations_required();
455
-            }
456
-        }
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
463
-     *
464
-     * @param    array  $version_history
465
-     * @param    string $current_version_to_add version to be added to the version history
466
-     * @return    boolean success as to whether or not this option was changed
467
-     */
468
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469
-    {
470
-        if (! $version_history) {
471
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
472
-        }
473
-        if ($current_version_to_add === null) {
474
-            $current_version_to_add = espresso_version();
475
-        }
476
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
477
-        // re-save
478
-        return update_option('espresso_db_update', $version_history);
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * Detects if the current version indicated in the has existed in the list of
485
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
486
-     *
487
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
488
-     *                                  If not supplied, fetches it from the options table.
489
-     *                                  Also, caches its result so later parts of the code can also know whether
490
-     *                                  there's been an update or not. This way we can add the current version to
491
-     *                                  espresso_db_update, but still know if this is a new install or not
492
-     * @return int one of the constants on EE_System::req_type_
493
-     */
494
-    public function detect_req_type($espresso_db_update = null)
495
-    {
496
-        if ($this->_req_type === null) {
497
-            $espresso_db_update = ! empty($espresso_db_update)
498
-                ? $espresso_db_update
499
-                : $this->fix_espresso_db_upgrade_option();
500
-            $this->_req_type = self::detect_req_type_given_activation_history(
501
-                $espresso_db_update,
502
-                'ee_espresso_activation', espresso_version()
503
-            );
504
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
505
-        }
506
-        return $this->_req_type;
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * Returns whether or not there was a non-micro version change (ie, change in either
513
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
514
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
515
-     *
516
-     * @param $activation_history
517
-     * @return bool
518
-     */
519
-    private function _detect_major_version_change($activation_history)
520
-    {
521
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
522
-        $previous_version_parts = explode('.', $previous_version);
523
-        $current_version_parts = explode('.', espresso_version());
524
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
525
-               && ($previous_version_parts[0] !== $current_version_parts[0]
526
-                   || $previous_version_parts[1] !== $current_version_parts[1]
527
-               );
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     * Returns true if either the major or minor version of EE changed during this request.
534
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
535
-     *
536
-     * @return bool
537
-     */
538
-    public function is_major_version_change()
539
-    {
540
-        return $this->_major_version_change;
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
547
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
548
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
549
-     * just activated to (for core that will always be espresso_version())
550
-     *
551
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
552
-     *                                                 ee plugin. for core that's 'espresso_db_update'
553
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
554
-     *                                                 indicate that this plugin was just activated
555
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
556
-     *                                                 espresso_version())
557
-     * @return int one of the constants on EE_System::req_type_*
558
-     */
559
-    public static function detect_req_type_given_activation_history(
560
-        $activation_history_for_addon,
561
-        $activation_indicator_option_name,
562
-        $version_to_upgrade_to
563
-    ) {
564
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
565
-        if ($activation_history_for_addon) {
566
-            //it exists, so this isn't a completely new install
567
-            //check if this version already in that list of previously installed versions
568
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569
-                //it a version we haven't seen before
570
-                if ($version_is_higher === 1) {
571
-                    $req_type = EE_System::req_type_upgrade;
572
-                } else {
573
-                    $req_type = EE_System::req_type_downgrade;
574
-                }
575
-                delete_option($activation_indicator_option_name);
576
-            } else {
577
-                // its not an update. maybe a reactivation?
578
-                if (get_option($activation_indicator_option_name, false)) {
579
-                    if ($version_is_higher === -1) {
580
-                        $req_type = EE_System::req_type_downgrade;
581
-                    } else if ($version_is_higher === 0) {
582
-                        //we've seen this version before, but it's an activation. must be a reactivation
583
-                        $req_type = EE_System::req_type_reactivation;
584
-                    } else {//$version_is_higher === 1
585
-                        $req_type = EE_System::req_type_upgrade;
586
-                    }
587
-                    delete_option($activation_indicator_option_name);
588
-                } else {
589
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
590
-                    if ($version_is_higher === -1) {
591
-                        $req_type = EE_System::req_type_downgrade;
592
-                    } else if ($version_is_higher === 0) {
593
-                        //we've seen this version before and it's not an activation. its normal request
594
-                        $req_type = EE_System::req_type_normal;
595
-                    } else {//$version_is_higher === 1
596
-                        $req_type = EE_System::req_type_upgrade;
597
-                    }
598
-                }
599
-            }
600
-        } else {
601
-            //brand new install
602
-            $req_type = EE_System::req_type_new_activation;
603
-            delete_option($activation_indicator_option_name);
604
-        }
605
-        return $req_type;
606
-    }
607
-
608
-
609
-
610
-    /**
611
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
612
-     * the $activation_history_for_addon
613
-     *
614
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
615
-     *                                             sometimes containing 'unknown-date'
616
-     * @param string $version_to_upgrade_to        (current version)
617
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
618
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
619
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
620
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
621
-     */
622
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
623
-    {
624
-        //find the most recently-activated version
625
-        $most_recently_active_version =
626
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
627
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * Gets the most recently active version listed in the activation history,
634
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
635
-     *
636
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
637
-     *                                   sometimes containing 'unknown-date'
638
-     * @return string
639
-     */
640
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
641
-    {
642
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
643
-        $most_recently_active_version = '0.0.0.dev.000';
644
-        if (is_array($activation_history)) {
645
-            foreach ($activation_history as $version => $times_activated) {
646
-                //check there is a record of when this version was activated. Otherwise,
647
-                //mark it as unknown
648
-                if (! $times_activated) {
649
-                    $times_activated = array('unknown-date');
650
-                }
651
-                if (is_string($times_activated)) {
652
-                    $times_activated = array($times_activated);
653
-                }
654
-                foreach ($times_activated as $an_activation) {
655
-                    if ($an_activation !== 'unknown-date'
656
-                        && $an_activation
657
-                           > $most_recently_active_version_activation
658
-                    ) {
659
-                        $most_recently_active_version = $version;
660
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
661
-                            ? '1970-01-01 00:00:00'
662
-                            : $an_activation;
663
-                    }
664
-                }
665
-            }
666
-        }
667
-        return $most_recently_active_version;
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * This redirects to the about EE page after activation
674
-     *
675
-     * @return void
676
-     */
677
-    public function redirect_to_about_ee()
678
-    {
679
-        $notices = EE_Error::get_notices(false);
680
-        //if current user is an admin and it's not an ajax or rest request
681
-        if (
682
-            ! (defined('DOING_AJAX') && DOING_AJAX)
683
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
684
-            && ! isset($notices['errors'])
685
-            && apply_filters(
686
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
687
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
688
-            )
689
-        ) {
690
-            $query_params = array('page' => 'espresso_about');
691
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
692
-                $query_params['new_activation'] = true;
693
-            }
694
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
695
-                $query_params['reactivation'] = true;
696
-            }
697
-            $url = add_query_arg($query_params, admin_url('admin.php'));
698
-            wp_safe_redirect($url);
699
-            exit();
700
-        }
701
-    }
702
-
703
-
704
-
705
-    /**
706
-     * load_core_configuration
707
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
708
-     * which runs during the WP 'plugins_loaded' action at priority 5
709
-     *
710
-     * @return void
711
-     * @throws ReflectionException
712
-     */
713
-    public function load_core_configuration()
714
-    {
715
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
716
-        $this->loader->getShared('EE_Load_Textdomain');
717
-        //load textdomain
718
-        EE_Load_Textdomain::load_textdomain();
719
-        // load and setup EE_Config and EE_Network_Config
720
-        $config = $this->loader->getShared('EE_Config');
721
-        $this->loader->getShared('EE_Network_Config');
722
-        // setup autoloaders
723
-        // enable logging?
724
-        if ($config->admin->use_full_logging) {
725
-            $this->loader->getShared('EE_Log');
726
-        }
727
-        // check for activation errors
728
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
729
-        if ($activation_errors) {
730
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
731
-            update_option('ee_plugin_activation_errors', false);
732
-        }
733
-        // get model names
734
-        $this->_parse_model_names();
735
-        //load caf stuff a chance to play during the activation process too.
736
-        $this->_maybe_brew_regular();
737
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
738
-    }
739
-
740
-
741
-
742
-    /**
743
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
744
-     *
745
-     * @return void
746
-     * @throws ReflectionException
747
-     */
748
-    private function _parse_model_names()
749
-    {
750
-        //get all the files in the EE_MODELS folder that end in .model.php
751
-        $models = glob(EE_MODELS . '*.model.php');
752
-        $model_names = array();
753
-        $non_abstract_db_models = array();
754
-        foreach ($models as $model) {
755
-            // get model classname
756
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
757
-            $short_name = str_replace('EEM_', '', $classname);
758
-            $reflectionClass = new ReflectionClass($classname);
759
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
760
-                $non_abstract_db_models[$short_name] = $classname;
761
-            }
762
-            $model_names[$short_name] = $classname;
763
-        }
764
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
765
-        $this->registry->non_abstract_db_models = apply_filters(
766
-            'FHEE__EE_System__parse_implemented_model_names',
767
-            $non_abstract_db_models
768
-        );
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
775
-     * that need to be setup before our EE_System launches.
776
-     *
777
-     * @return void
778
-     */
779
-    private function _maybe_brew_regular()
780
-    {
781
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
782
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * register_shortcodes_modules_and_widgets
790
-     * generate lists of shortcodes and modules, then verify paths and classes
791
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
792
-     * which runs during the WP 'plugins_loaded' action at priority 7
793
-     *
794
-     * @access public
795
-     * @return void
796
-     */
797
-    public function register_shortcodes_modules_and_widgets()
798
-    {
799
-        try {
800
-            // load, register, and add shortcodes the new way
801
-            new ShortcodesManager(
802
-            // and the old way, but we'll put it under control of the new system
803
-                EE_Config::getLegacyShortcodesManager()
804
-            );
805
-        } catch (Exception $exception) {
806
-            new ExceptionStackTraceDisplay($exception);
807
-        }
808
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
809
-        // check for addons using old hookpoint
810
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
811
-            $this->_incompatible_addon_error();
812
-        }
813
-    }
814
-
815
-
816
-
817
-    /**
818
-     * _incompatible_addon_error
819
-     *
820
-     * @access public
821
-     * @return void
822
-     */
823
-    private function _incompatible_addon_error()
824
-    {
825
-        // get array of classes hooking into here
826
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
827
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
828
-        );
829
-        if (! empty($class_names)) {
830
-            $msg = __(
831
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
832
-                'event_espresso'
833
-            );
834
-            $msg .= '<ul>';
835
-            foreach ($class_names as $class_name) {
836
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
837
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
838
-                        $class_name
839
-                    ) . '</b></li>';
840
-            }
841
-            $msg .= '</ul>';
842
-            $msg .= __(
843
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
844
-                'event_espresso'
845
-            );
846
-            // save list of incompatible addons to wp-options for later use
847
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
848
-            if (is_admin()) {
849
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
850
-            }
851
-        }
852
-    }
853
-
854
-
855
-
856
-    /**
857
-     * brew_espresso
858
-     * begins the process of setting hooks for initializing EE in the correct order
859
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
860
-     * which runs during the WP 'plugins_loaded' action at priority 9
861
-     *
862
-     * @return void
863
-     */
864
-    public function brew_espresso()
865
-    {
866
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
867
-        // load some final core systems
868
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
869
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
870
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
871
-        add_action('init', array($this, 'load_controllers'), 7);
872
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
873
-        add_action('init', array($this, 'initialize'), 10);
874
-        add_action('init', array($this, 'initialize_last'), 100);
875
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
876
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
877
-            // pew pew pew
878
-            $this->loader->getShared('EE_PUE');
879
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
880
-        }
881
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
882
-    }
883
-
884
-
885
-
886
-    /**
887
-     *    set_hooks_for_core
888
-     *
889
-     * @access public
890
-     * @return    void
891
-     */
892
-    public function set_hooks_for_core()
893
-    {
894
-        $this->_deactivate_incompatible_addons();
895
-        do_action('AHEE__EE_System__set_hooks_for_core');
896
-    }
897
-
898
-
899
-
900
-    /**
901
-     * Using the information gathered in EE_System::_incompatible_addon_error,
902
-     * deactivates any addons considered incompatible with the current version of EE
903
-     */
904
-    private function _deactivate_incompatible_addons()
905
-    {
906
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
907
-        if (! empty($incompatible_addons)) {
908
-            $active_plugins = get_option('active_plugins', array());
909
-            foreach ($active_plugins as $active_plugin) {
910
-                foreach ($incompatible_addons as $incompatible_addon) {
911
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
912
-                        unset($_GET['activate']);
913
-                        espresso_deactivate_plugin($active_plugin);
914
-                    }
915
-                }
916
-            }
917
-        }
918
-    }
919
-
920
-
921
-
922
-    /**
923
-     *    perform_activations_upgrades_and_migrations
924
-     *
925
-     * @access public
926
-     * @return    void
927
-     */
928
-    public function perform_activations_upgrades_and_migrations()
929
-    {
930
-        //first check if we had previously attempted to setup EE's directories but failed
931
-        if (EEH_Activation::upload_directories_incomplete()) {
932
-            EEH_Activation::create_upload_directories();
933
-        }
934
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     *    load_CPTs_and_session
941
-     *
942
-     * @access public
943
-     * @return    void
944
-     */
945
-    public function load_CPTs_and_session()
946
-    {
947
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
948
-        // register Custom Post Types
949
-        $this->loader->getShared('EE_Register_CPTs');
950
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
951
-    }
952
-
953
-
954
-
955
-    /**
956
-     * load_controllers
957
-     * this is the best place to load any additional controllers that needs access to EE core.
958
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
959
-     * time
960
-     *
961
-     * @access public
962
-     * @return void
963
-     */
964
-    public function load_controllers()
965
-    {
966
-        do_action('AHEE__EE_System__load_controllers__start');
967
-        // let's get it started
968
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
969
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
970
-            $this->loader->getShared('EE_Front_Controller');
971
-        } else if (! EE_FRONT_AJAX) {
972
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
973
-            $this->loader->getShared('EE_Admin');
974
-        }
975
-        do_action('AHEE__EE_System__load_controllers__complete');
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * core_loaded_and_ready
982
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
983
-     *
984
-     * @access public
985
-     * @return void
986
-     */
987
-    public function core_loaded_and_ready()
988
-    {
989
-        $this->registry->load_core('Session');
990
-        do_action('AHEE__EE_System__core_loaded_and_ready');
991
-        // load_espresso_template_tags
992
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
993
-            require_once(EE_PUBLIC . 'template_tags.php');
994
-        }
995
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
996
-        $this->loader->getShared('EE_Session');
997
-        $this->loader->getShared('EventEspresso\core\services\assets\Registry');
998
-        wp_enqueue_script('espresso_core');
999
-    }
1000
-
1001
-
1002
-
1003
-    /**
1004
-     * initialize
1005
-     * this is the best place to begin initializing client code
1006
-     *
1007
-     * @access public
1008
-     * @return void
1009
-     */
1010
-    public function initialize()
1011
-    {
1012
-        do_action('AHEE__EE_System__initialize');
1013
-    }
1014
-
1015
-
1016
-
1017
-    /**
1018
-     * initialize_last
1019
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
1020
-     * initialize has done so
1021
-     *
1022
-     * @access public
1023
-     * @return void
1024
-     */
1025
-    public function initialize_last()
1026
-    {
1027
-        do_action('AHEE__EE_System__initialize_last');
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     * set_hooks_for_shortcodes_modules_and_addons
1034
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
1035
-     * this happens at the very beginning of the wp_loaded hookpoint
1036
-     *
1037
-     * @access public
1038
-     * @return void
1039
-     */
1040
-    public function set_hooks_for_shortcodes_modules_and_addons()
1041
-    {
1042
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
1043
-    }
1044
-
1045
-
1046
-
1047
-    /**
1048
-     * do_not_cache
1049
-     * sets no cache headers and defines no cache constants for WP plugins
1050
-     *
1051
-     * @access public
1052
-     * @return void
1053
-     */
1054
-    public static function do_not_cache()
1055
-    {
1056
-        // set no cache constants
1057
-        if (! defined('DONOTCACHEPAGE')) {
1058
-            define('DONOTCACHEPAGE', true);
1059
-        }
1060
-        if (! defined('DONOTCACHCEOBJECT')) {
1061
-            define('DONOTCACHCEOBJECT', true);
1062
-        }
1063
-        if (! defined('DONOTCACHEDB')) {
1064
-            define('DONOTCACHEDB', true);
1065
-        }
1066
-        // add no cache headers
1067
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1068
-        // plus a little extra for nginx and Google Chrome
1069
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1070
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1071
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1072
-    }
1073
-
1074
-
1075
-
1076
-    /**
1077
-     *    extra_nocache_headers
1078
-     *
1079
-     * @access    public
1080
-     * @param $headers
1081
-     * @return    array
1082
-     */
1083
-    public static function extra_nocache_headers($headers)
1084
-    {
1085
-        // for NGINX
1086
-        $headers['X-Accel-Expires'] = 0;
1087
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1088
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1089
-        return $headers;
1090
-    }
1091
-
1092
-
1093
-
1094
-    /**
1095
-     *    nocache_headers
1096
-     *
1097
-     * @access    public
1098
-     * @return    void
1099
-     */
1100
-    public static function nocache_headers()
1101
-    {
1102
-        nocache_headers();
1103
-    }
1104
-
1105
-
1106
-
1107
-    /**
1108
-     *    espresso_toolbar_items
1109
-     *
1110
-     * @access public
1111
-     * @param  WP_Admin_Bar $admin_bar
1112
-     * @return void
1113
-     */
1114
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1115
-    {
1116
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1117
-        if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1118
-            || defined('DOING_AJAX')
1119
-            || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1120
-        ) {
1121
-            return;
1122
-        }
1123
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1124
-        $menu_class = 'espresso_menu_item_class';
1125
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1126
-        //because they're only defined in each of their respective constructors
1127
-        //and this might be a frontend request, in which case they aren't available
1128
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1129
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1130
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1131
-        //Top Level
1132
-        $admin_bar->add_menu(
1133
-            array(
1134
-                'id'    => 'espresso-toolbar',
1135
-                'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1136
-                           . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1137
-                           . '</span>',
1138
-                'href'  => $events_admin_url,
1139
-                'meta'  => array(
1140
-                    'title' => __('Event Espresso', 'event_espresso'),
1141
-                    'class' => $menu_class . 'first',
1142
-                ),
1143
-            )
1144
-        );
1145
-        //Events
1146
-        if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1147
-            $admin_bar->add_menu(
1148
-                array(
1149
-                    'id'     => 'espresso-toolbar-events',
1150
-                    'parent' => 'espresso-toolbar',
1151
-                    'title'  => __('Events', 'event_espresso'),
1152
-                    'href'   => $events_admin_url,
1153
-                    'meta'   => array(
1154
-                        'title'  => __('Events', 'event_espresso'),
1155
-                        'target' => '',
1156
-                        'class'  => $menu_class,
1157
-                    ),
1158
-                )
1159
-            );
1160
-        }
1161
-        if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1162
-            //Events Add New
1163
-            $admin_bar->add_menu(
1164
-                array(
1165
-                    'id'     => 'espresso-toolbar-events-new',
1166
-                    'parent' => 'espresso-toolbar-events',
1167
-                    'title'  => __('Add New', 'event_espresso'),
1168
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1169
-                    'meta'   => array(
1170
-                        'title'  => __('Add New', 'event_espresso'),
1171
-                        'target' => '',
1172
-                        'class'  => $menu_class,
1173
-                    ),
1174
-                )
1175
-            );
1176
-        }
1177
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1178
-            //Current post
1179
-            global $post;
1180
-            if ($this->capabilities->current_user_can(
1181
-                'ee_edit_event',
1182
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID
1183
-            )
1184
-            ) {
1185
-                //Events Edit Current Event
1186
-                $admin_bar->add_menu(
1187
-                    array(
1188
-                        'id'     => 'espresso-toolbar-events-edit',
1189
-                        'parent' => 'espresso-toolbar-events',
1190
-                        'title'  => __('Edit Event', 'event_espresso'),
1191
-                        'href'   => EEH_URL::add_query_args_and_nonce(
1192
-                            array('action' => 'edit', 'post' => $post->ID),
1193
-                            $events_admin_url
1194
-                        ),
1195
-                        'meta'   => array(
1196
-                            'title'  => __('Edit Event', 'event_espresso'),
1197
-                            'target' => '',
1198
-                            'class'  => $menu_class,
1199
-                        ),
1200
-                    )
1201
-                );
1202
-            }
1203
-        }
1204
-        //Events View
1205
-        if ($this->capabilities->current_user_can(
1206
-            'ee_read_events',
1207
-            'ee_admin_bar_menu_espresso-toolbar-events-view'
1208
-        )
1209
-        ) {
1210
-            $admin_bar->add_menu(
1211
-                array(
1212
-                    'id'     => 'espresso-toolbar-events-view',
1213
-                    'parent' => 'espresso-toolbar-events',
1214
-                    'title'  => __('View', 'event_espresso'),
1215
-                    'href'   => $events_admin_url,
1216
-                    'meta'   => array(
1217
-                        'title'  => __('View', 'event_espresso'),
1218
-                        'target' => '',
1219
-                        'class'  => $menu_class,
1220
-                    ),
1221
-                )
1222
-            );
1223
-        }
1224
-        if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1225
-            //Events View All
1226
-            $admin_bar->add_menu(
1227
-                array(
1228
-                    'id'     => 'espresso-toolbar-events-all',
1229
-                    'parent' => 'espresso-toolbar-events-view',
1230
-                    'title'  => __('All', 'event_espresso'),
1231
-                    'href'   => $events_admin_url,
1232
-                    'meta'   => array(
1233
-                        'title'  => __('All', 'event_espresso'),
1234
-                        'target' => '',
1235
-                        'class'  => $menu_class,
1236
-                    ),
1237
-                )
1238
-            );
1239
-        }
1240
-        if ($this->capabilities->current_user_can(
1241
-            'ee_read_events',
1242
-            'ee_admin_bar_menu_espresso-toolbar-events-today'
1243
-        )
1244
-        ) {
1245
-            //Events View Today
1246
-            $admin_bar->add_menu(
1247
-                array(
1248
-                    'id'     => 'espresso-toolbar-events-today',
1249
-                    'parent' => 'espresso-toolbar-events-view',
1250
-                    'title'  => __('Today', 'event_espresso'),
1251
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1252
-                        array('action' => 'default', 'status' => 'today'),
1253
-                        $events_admin_url
1254
-                    ),
1255
-                    'meta'   => array(
1256
-                        'title'  => __('Today', 'event_espresso'),
1257
-                        'target' => '',
1258
-                        'class'  => $menu_class,
1259
-                    ),
1260
-                )
1261
-            );
1262
-        }
1263
-        if ($this->capabilities->current_user_can(
1264
-            'ee_read_events',
1265
-            'ee_admin_bar_menu_espresso-toolbar-events-month'
1266
-        )
1267
-        ) {
1268
-            //Events View This Month
1269
-            $admin_bar->add_menu(
1270
-                array(
1271
-                    'id'     => 'espresso-toolbar-events-month',
1272
-                    'parent' => 'espresso-toolbar-events-view',
1273
-                    'title'  => __('This Month', 'event_espresso'),
1274
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1275
-                        array('action' => 'default', 'status' => 'month'),
1276
-                        $events_admin_url
1277
-                    ),
1278
-                    'meta'   => array(
1279
-                        'title'  => __('This Month', 'event_espresso'),
1280
-                        'target' => '',
1281
-                        'class'  => $menu_class,
1282
-                    ),
1283
-                )
1284
-            );
1285
-        }
1286
-        //Registration Overview
1287
-        if ($this->capabilities->current_user_can(
1288
-            'ee_read_registrations',
1289
-            'ee_admin_bar_menu_espresso-toolbar-registrations'
1290
-        )
1291
-        ) {
1292
-            $admin_bar->add_menu(
1293
-                array(
1294
-                    'id'     => 'espresso-toolbar-registrations',
1295
-                    'parent' => 'espresso-toolbar',
1296
-                    'title'  => __('Registrations', 'event_espresso'),
1297
-                    'href'   => $reg_admin_url,
1298
-                    'meta'   => array(
1299
-                        'title'  => __('Registrations', 'event_espresso'),
1300
-                        'target' => '',
1301
-                        'class'  => $menu_class,
1302
-                    ),
1303
-                )
1304
-            );
1305
-        }
1306
-        //Registration Overview Today
1307
-        if ($this->capabilities->current_user_can(
1308
-            'ee_read_registrations',
1309
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today'
1310
-        )
1311
-        ) {
1312
-            $admin_bar->add_menu(
1313
-                array(
1314
-                    'id'     => 'espresso-toolbar-registrations-today',
1315
-                    'parent' => 'espresso-toolbar-registrations',
1316
-                    'title'  => __('Today', 'event_espresso'),
1317
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1318
-                        array('action' => 'default', 'status' => 'today'),
1319
-                        $reg_admin_url
1320
-                    ),
1321
-                    'meta'   => array(
1322
-                        'title'  => __('Today', 'event_espresso'),
1323
-                        'target' => '',
1324
-                        'class'  => $menu_class,
1325
-                    ),
1326
-                )
1327
-            );
1328
-        }
1329
-        //Registration Overview Today Completed
1330
-        if ($this->capabilities->current_user_can(
1331
-            'ee_read_registrations',
1332
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
1333
-        )
1334
-        ) {
1335
-            $admin_bar->add_menu(
1336
-                array(
1337
-                    'id'     => 'espresso-toolbar-registrations-today-approved',
1338
-                    'parent' => 'espresso-toolbar-registrations-today',
1339
-                    'title'  => __('Approved', 'event_espresso'),
1340
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1341
-                        array(
1342
-                            'action'      => 'default',
1343
-                            'status'      => 'today',
1344
-                            '_reg_status' => EEM_Registration::status_id_approved,
1345
-                        ), $reg_admin_url
1346
-                    ),
1347
-                    'meta'   => array(
1348
-                        'title'  => __('Approved', 'event_espresso'),
1349
-                        'target' => '',
1350
-                        'class'  => $menu_class,
1351
-                    ),
1352
-                )
1353
-            );
1354
-        }
1355
-        //Registration Overview Today Pending\
1356
-        if ($this->capabilities->current_user_can(
1357
-            'ee_read_registrations',
1358
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
1359
-        )
1360
-        ) {
1361
-            $admin_bar->add_menu(
1362
-                array(
1363
-                    'id'     => 'espresso-toolbar-registrations-today-pending',
1364
-                    'parent' => 'espresso-toolbar-registrations-today',
1365
-                    'title'  => __('Pending', 'event_espresso'),
1366
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1367
-                        array(
1368
-                            'action'     => 'default',
1369
-                            'status'     => 'today',
1370
-                            'reg_status' => EEM_Registration::status_id_pending_payment,
1371
-                        ), $reg_admin_url
1372
-                    ),
1373
-                    'meta'   => array(
1374
-                        'title'  => __('Pending Payment', 'event_espresso'),
1375
-                        'target' => '',
1376
-                        'class'  => $menu_class,
1377
-                    ),
1378
-                )
1379
-            );
1380
-        }
1381
-        //Registration Overview Today Incomplete
1382
-        if ($this->capabilities->current_user_can(
1383
-            'ee_read_registrations',
1384
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
1385
-        )
1386
-        ) {
1387
-            $admin_bar->add_menu(
1388
-                array(
1389
-                    'id'     => 'espresso-toolbar-registrations-today-not-approved',
1390
-                    'parent' => 'espresso-toolbar-registrations-today',
1391
-                    'title'  => __('Not Approved', 'event_espresso'),
1392
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1393
-                        array(
1394
-                            'action'      => 'default',
1395
-                            'status'      => 'today',
1396
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
1397
-                        ), $reg_admin_url
1398
-                    ),
1399
-                    'meta'   => array(
1400
-                        'title'  => __('Not Approved', 'event_espresso'),
1401
-                        'target' => '',
1402
-                        'class'  => $menu_class,
1403
-                    ),
1404
-                )
1405
-            );
1406
-        }
1407
-        //Registration Overview Today Incomplete
1408
-        if ($this->capabilities->current_user_can(
1409
-            'ee_read_registrations',
1410
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
1411
-        )
1412
-        ) {
1413
-            $admin_bar->add_menu(
1414
-                array(
1415
-                    'id'     => 'espresso-toolbar-registrations-today-cancelled',
1416
-                    'parent' => 'espresso-toolbar-registrations-today',
1417
-                    'title'  => __('Cancelled', 'event_espresso'),
1418
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1419
-                        array(
1420
-                            'action'      => 'default',
1421
-                            'status'      => 'today',
1422
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
1423
-                        ), $reg_admin_url
1424
-                    ),
1425
-                    'meta'   => array(
1426
-                        'title'  => __('Cancelled', 'event_espresso'),
1427
-                        'target' => '',
1428
-                        'class'  => $menu_class,
1429
-                    ),
1430
-                )
1431
-            );
1432
-        }
1433
-        //Registration Overview This Month
1434
-        if ($this->capabilities->current_user_can(
1435
-            'ee_read_registrations',
1436
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month'
1437
-        )
1438
-        ) {
1439
-            $admin_bar->add_menu(
1440
-                array(
1441
-                    'id'     => 'espresso-toolbar-registrations-month',
1442
-                    'parent' => 'espresso-toolbar-registrations',
1443
-                    'title'  => __('This Month', 'event_espresso'),
1444
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1445
-                        array('action' => 'default', 'status' => 'month'),
1446
-                        $reg_admin_url
1447
-                    ),
1448
-                    'meta'   => array(
1449
-                        'title'  => __('This Month', 'event_espresso'),
1450
-                        'target' => '',
1451
-                        'class'  => $menu_class,
1452
-                    ),
1453
-                )
1454
-            );
1455
-        }
1456
-        //Registration Overview This Month Approved
1457
-        if ($this->capabilities->current_user_can(
1458
-            'ee_read_registrations',
1459
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
1460
-        )
1461
-        ) {
1462
-            $admin_bar->add_menu(
1463
-                array(
1464
-                    'id'     => 'espresso-toolbar-registrations-month-approved',
1465
-                    'parent' => 'espresso-toolbar-registrations-month',
1466
-                    'title'  => __('Approved', 'event_espresso'),
1467
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1468
-                        array(
1469
-                            'action'      => 'default',
1470
-                            'status'      => 'month',
1471
-                            '_reg_status' => EEM_Registration::status_id_approved,
1472
-                        ), $reg_admin_url
1473
-                    ),
1474
-                    'meta'   => array(
1475
-                        'title'  => __('Approved', 'event_espresso'),
1476
-                        'target' => '',
1477
-                        'class'  => $menu_class,
1478
-                    ),
1479
-                )
1480
-            );
1481
-        }
1482
-        //Registration Overview This Month Pending
1483
-        if ($this->capabilities->current_user_can(
1484
-            'ee_read_registrations',
1485
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
1486
-        )
1487
-        ) {
1488
-            $admin_bar->add_menu(
1489
-                array(
1490
-                    'id'     => 'espresso-toolbar-registrations-month-pending',
1491
-                    'parent' => 'espresso-toolbar-registrations-month',
1492
-                    'title'  => __('Pending', 'event_espresso'),
1493
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1494
-                        array(
1495
-                            'action'      => 'default',
1496
-                            'status'      => 'month',
1497
-                            '_reg_status' => EEM_Registration::status_id_pending_payment,
1498
-                        ), $reg_admin_url
1499
-                    ),
1500
-                    'meta'   => array(
1501
-                        'title'  => __('Pending', 'event_espresso'),
1502
-                        'target' => '',
1503
-                        'class'  => $menu_class,
1504
-                    ),
1505
-                )
1506
-            );
1507
-        }
1508
-        //Registration Overview This Month Not Approved
1509
-        if ($this->capabilities->current_user_can(
1510
-            'ee_read_registrations',
1511
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
1512
-        )
1513
-        ) {
1514
-            $admin_bar->add_menu(
1515
-                array(
1516
-                    'id'     => 'espresso-toolbar-registrations-month-not-approved',
1517
-                    'parent' => 'espresso-toolbar-registrations-month',
1518
-                    'title'  => __('Not Approved', 'event_espresso'),
1519
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1520
-                        array(
1521
-                            'action'      => 'default',
1522
-                            'status'      => 'month',
1523
-                            '_reg_status' => EEM_Registration::status_id_not_approved,
1524
-                        ), $reg_admin_url
1525
-                    ),
1526
-                    'meta'   => array(
1527
-                        'title'  => __('Not Approved', 'event_espresso'),
1528
-                        'target' => '',
1529
-                        'class'  => $menu_class,
1530
-                    ),
1531
-                )
1532
-            );
1533
-        }
1534
-        //Registration Overview This Month Cancelled
1535
-        if ($this->capabilities->current_user_can(
1536
-            'ee_read_registrations',
1537
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
1538
-        )
1539
-        ) {
1540
-            $admin_bar->add_menu(
1541
-                array(
1542
-                    'id'     => 'espresso-toolbar-registrations-month-cancelled',
1543
-                    'parent' => 'espresso-toolbar-registrations-month',
1544
-                    'title'  => __('Cancelled', 'event_espresso'),
1545
-                    'href'   => EEH_URL::add_query_args_and_nonce(
1546
-                        array(
1547
-                            'action'      => 'default',
1548
-                            'status'      => 'month',
1549
-                            '_reg_status' => EEM_Registration::status_id_cancelled,
1550
-                        ), $reg_admin_url
1551
-                    ),
1552
-                    'meta'   => array(
1553
-                        'title'  => __('Cancelled', 'event_espresso'),
1554
-                        'target' => '',
1555
-                        'class'  => $menu_class,
1556
-                    ),
1557
-                )
1558
-            );
1559
-        }
1560
-        //Extensions & Services
1561
-        if ($this->capabilities->current_user_can(
1562
-            'ee_read_ee',
1563
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
1564
-        )
1565
-        ) {
1566
-            $admin_bar->add_menu(
1567
-                array(
1568
-                    'id'     => 'espresso-toolbar-extensions-and-services',
1569
-                    'parent' => 'espresso-toolbar',
1570
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1571
-                    'href'   => $extensions_admin_url,
1572
-                    'meta'   => array(
1573
-                        'title'  => __('Extensions & Services', 'event_espresso'),
1574
-                        'target' => '',
1575
-                        'class'  => $menu_class,
1576
-                    ),
1577
-                )
1578
-            );
1579
-        }
1580
-    }
1581
-
1582
-
1583
-
1584
-    /**
1585
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1586
-     * never returned with the function.
1587
-     *
1588
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1589
-     * @return array
1590
-     */
1591
-    public function remove_pages_from_wp_list_pages($exclude_array)
1592
-    {
1593
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1594
-    }
23
+	/**
24
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
25
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
26
+	 */
27
+	const req_type_normal = 0;
28
+
29
+	/**
30
+	 * Indicates this is a brand new installation of EE so we should install
31
+	 * tables and default data etc
32
+	 */
33
+	const req_type_new_activation = 1;
34
+
35
+	/**
36
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
37
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
38
+	 * and that default data is setup too
39
+	 */
40
+	const req_type_reactivation = 2;
41
+
42
+	/**
43
+	 * indicates that EE has been upgraded since its previous request.
44
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
45
+	 */
46
+	const req_type_upgrade = 3;
47
+
48
+	/**
49
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
50
+	 */
51
+	const req_type_downgrade = 4;
52
+
53
+	/**
54
+	 * @deprecated since version 4.6.0.dev.006
55
+	 * Now whenever a new_activation is detected the request type is still just
56
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
57
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
58
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
59
+	 * (Specifically, when the migration manager indicates migrations are finished
60
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
61
+	 */
62
+	const req_type_activation_but_not_installed = 5;
63
+
64
+	/**
65
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
66
+	 */
67
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
68
+
69
+
70
+	/**
71
+	 * @var EE_System $_instance
72
+	 */
73
+	private static $_instance;
74
+
75
+	/**
76
+	 * @var EE_Registry $registry
77
+	 */
78
+	private $registry;
79
+
80
+	/**
81
+	 * @var LoaderInterface $loader
82
+	 */
83
+	private $loader;
84
+
85
+	/**
86
+	 * @var EE_Capabilities $capabilities
87
+	 */
88
+	private $capabilities;
89
+
90
+	/**
91
+	 * @var EE_Request $request
92
+	 */
93
+	private $request;
94
+
95
+	/**
96
+	 * @var EE_Maintenance_Mode $maintenance_mode
97
+	 */
98
+	private $maintenance_mode;
99
+
100
+	/**
101
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
102
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
103
+	 *
104
+	 * @var int
105
+	 */
106
+	private $_req_type;
107
+
108
+	/**
109
+	 * Whether or not there was a non-micro version change in EE core version during this request
110
+	 *
111
+	 * @var boolean
112
+	 */
113
+	private $_major_version_change = false;
114
+
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param EE_Registry|null         $registry
120
+	 * @param LoaderInterface|null     $loader
121
+	 * @param EE_Capabilities|null     $capabilities
122
+	 * @param EE_Request|null          $request
123
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
124
+	 * @return EE_System
125
+	 */
126
+	public static function instance(
127
+		EE_Registry $registry = null,
128
+		LoaderInterface $loader = null,
129
+		EE_Capabilities $capabilities = null,
130
+		EE_Request $request = null,
131
+		EE_Maintenance_Mode $maintenance_mode = null
132
+	) {
133
+		// check if class object is instantiated
134
+		if (! self::$_instance instanceof EE_System) {
135
+			self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
136
+		}
137
+		return self::$_instance;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * resets the instance and returns it
144
+	 *
145
+	 * @return EE_System
146
+	 */
147
+	public static function reset()
148
+	{
149
+		self::$_instance->_req_type = null;
150
+		//make sure none of the old hooks are left hanging around
151
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
152
+		//we need to reset the migration manager in order for it to detect DMSs properly
153
+		EE_Data_Migration_Manager::reset();
154
+		self::instance()->detect_activations_or_upgrades();
155
+		self::instance()->perform_activations_upgrades_and_migrations();
156
+		return self::instance();
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * sets hooks for running rest of system
163
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
164
+	 * starting EE Addons from any other point may lead to problems
165
+	 *
166
+	 * @param EE_Registry         $registry
167
+	 * @param LoaderInterface     $loader
168
+	 * @param EE_Capabilities     $capabilities
169
+	 * @param EE_Request          $request
170
+	 * @param EE_Maintenance_Mode $maintenance_mode
171
+	 */
172
+	private function __construct(
173
+		EE_Registry $registry,
174
+		LoaderInterface $loader,
175
+		EE_Capabilities $capabilities,
176
+		EE_Request $request,
177
+		EE_Maintenance_Mode $maintenance_mode
178
+	) {
179
+		$this->registry = $registry;
180
+		$this->loader = $loader;
181
+		$this->capabilities = $capabilities;
182
+		$this->request = $request;
183
+		$this->maintenance_mode = $maintenance_mode;
184
+		do_action('AHEE__EE_System__construct__begin', $this);
185
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
186
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
187
+		// when an ee addon is activated, we want to call the core hook(s) again
188
+		// because the newly-activated addon didn't get a chance to run at all
189
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
190
+		// detect whether install or upgrade
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
193
+			3
194
+		);
195
+		// load EE_Config, EE_Textdomain, etc
196
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
197
+		// load EE_Config, EE_Textdomain, etc
198
+		add_action(
199
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
200
+			array($this, 'register_shortcodes_modules_and_widgets'), 7
201
+		);
202
+		// you wanna get going? I wanna get going... let's get going!
203
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
204
+		//other housekeeping
205
+		//exclude EE critical pages from wp_list_pages
206
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
207
+		// ALL EE Addons should use the following hook point to attach their initial setup too
208
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
209
+		do_action('AHEE__EE_System__construct__complete', $this);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * load_espresso_addons
216
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
217
+	 * this is hooked into both:
218
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
219
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
220
+	 *    and the WP 'activate_plugin' hook point
221
+	 *
222
+	 * @access public
223
+	 * @return void
224
+	 * @throws EE_Error
225
+	 */
226
+	public function load_espresso_addons()
227
+	{
228
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
229
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
230
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
231
+		//caps need to be initialized on every request so that capability maps are set.
232
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
233
+		$this->capabilities->init_caps();
234
+		do_action('AHEE__EE_System__load_espresso_addons');
235
+		//if the WP API basic auth plugin isn't already loaded, load it now.
236
+		//We want it for mobile apps. Just include the entire plugin
237
+		//also, don't load the basic auth when a plugin is getting activated, because
238
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
239
+		//and causes a fatal error
240
+		if (
241
+			! (
242
+				isset($_GET['activate'])
243
+				&& $_GET['activate'] === 'true'
244
+			)
245
+			&& ! function_exists('json_basic_auth_handler')
246
+			&& ! function_exists('json_basic_auth_error')
247
+			&& ! (
248
+				isset($_GET['action'])
249
+				&& in_array($_GET['action'], array('activate', 'activate-selected'), true)
250
+			)
251
+		) {
252
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
253
+		}
254
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * detect_activations_or_upgrades
261
+	 * Checks for activation or upgrade of core first;
262
+	 * then also checks if any registered addons have been activated or upgraded
263
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
264
+	 * which runs during the WP 'plugins_loaded' action at priority 3
265
+	 *
266
+	 * @access public
267
+	 * @return void
268
+	 */
269
+	public function detect_activations_or_upgrades()
270
+	{
271
+		//first off: let's make sure to handle core
272
+		$this->detect_if_activation_or_upgrade();
273
+		foreach ($this->registry->addons as $addon) {
274
+			if ($addon instanceof EE_Addon) {
275
+				//detect teh request type for that addon
276
+				$addon->detect_activation_or_upgrade();
277
+			}
278
+		}
279
+	}
280
+
281
+
282
+
283
+	/**
284
+	 * detect_if_activation_or_upgrade
285
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
286
+	 * and either setting up the DB or setting up maintenance mode etc.
287
+	 *
288
+	 * @access public
289
+	 * @return void
290
+	 */
291
+	public function detect_if_activation_or_upgrade()
292
+	{
293
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
294
+		// check if db has been updated, or if its a brand-new installation
295
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
296
+		$request_type = $this->detect_req_type($espresso_db_update);
297
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
298
+		switch ($request_type) {
299
+			case EE_System::req_type_new_activation:
300
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
301
+				$this->_handle_core_version_change($espresso_db_update);
302
+				break;
303
+			case EE_System::req_type_reactivation:
304
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
305
+				$this->_handle_core_version_change($espresso_db_update);
306
+				break;
307
+			case EE_System::req_type_upgrade:
308
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
309
+				//migrations may be required now that we've upgraded
310
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
311
+				$this->_handle_core_version_change($espresso_db_update);
312
+				//				echo "done upgrade";die;
313
+				break;
314
+			case EE_System::req_type_downgrade:
315
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
316
+				//its possible migrations are no longer required
317
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
318
+				$this->_handle_core_version_change($espresso_db_update);
319
+				break;
320
+			case EE_System::req_type_normal:
321
+			default:
322
+				//				$this->_maybe_redirect_to_ee_about();
323
+				break;
324
+		}
325
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
326
+	}
327
+
328
+
329
+
330
+	/**
331
+	 * Updates the list of installed versions and sets hooks for
332
+	 * initializing the database later during the request
333
+	 *
334
+	 * @param array $espresso_db_update
335
+	 */
336
+	private function _handle_core_version_change($espresso_db_update)
337
+	{
338
+		$this->update_list_of_installed_versions($espresso_db_update);
339
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
340
+		add_action(
341
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
342
+			array($this, 'initialize_db_if_no_migrations_required')
343
+		);
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
350
+	 * information about what versions of EE have been installed and activated,
351
+	 * NOT necessarily the state of the database
352
+	 *
353
+	 * @param null $espresso_db_update
354
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
355
+	 *           from the options table
356
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
357
+	 */
358
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359
+	{
360
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
+		if (! $espresso_db_update) {
362
+			$espresso_db_update = get_option('espresso_db_update');
363
+		}
364
+		// check that option is an array
365
+		if (! is_array($espresso_db_update)) {
366
+			// if option is FALSE, then it never existed
367
+			if ($espresso_db_update === false) {
368
+				// make $espresso_db_update an array and save option with autoload OFF
369
+				$espresso_db_update = array();
370
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
371
+			} else {
372
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
373
+				$espresso_db_update = array($espresso_db_update => array());
374
+				update_option('espresso_db_update', $espresso_db_update);
375
+			}
376
+		} else {
377
+			$corrected_db_update = array();
378
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
379
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
380
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
381
+					//the key is an int, and the value IS NOT an array
382
+					//so it must be numerically-indexed, where values are versions installed...
383
+					//fix it!
384
+					$version_string = $should_be_array;
385
+					$corrected_db_update[$version_string] = array('unknown-date');
386
+				} else {
387
+					//ok it checks out
388
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
389
+				}
390
+			}
391
+			$espresso_db_update = $corrected_db_update;
392
+			update_option('espresso_db_update', $espresso_db_update);
393
+		}
394
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
395
+		return $espresso_db_update;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Does the traditional work of setting up the plugin's database and adding default data.
402
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
403
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
404
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
405
+	 * so that it will be done when migrations are finished
406
+	 *
407
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
408
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
409
+	 *                                       This is a resource-intensive job
410
+	 *                                       so we prefer to only do it when necessary
411
+	 * @return void
412
+	 * @throws EE_Error
413
+	 */
414
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
415
+	{
416
+		$request_type = $this->detect_req_type();
417
+		//only initialize system if we're not in maintenance mode.
418
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
419
+			update_option('ee_flush_rewrite_rules', true);
420
+			if ($verify_schema) {
421
+				EEH_Activation::initialize_db_and_folders();
422
+			}
423
+			EEH_Activation::initialize_db_content();
424
+			EEH_Activation::system_initialization();
425
+			if ($initialize_addons_too) {
426
+				$this->initialize_addons();
427
+			}
428
+		} else {
429
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
430
+		}
431
+		if ($request_type === EE_System::req_type_new_activation
432
+			|| $request_type === EE_System::req_type_reactivation
433
+			|| (
434
+				$request_type === EE_System::req_type_upgrade
435
+				&& $this->is_major_version_change()
436
+			)
437
+		) {
438
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
439
+		}
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * Initializes the db for all registered addons
446
+	 *
447
+	 * @throws EE_Error
448
+	 */
449
+	public function initialize_addons()
450
+	{
451
+		//foreach registered addon, make sure its db is up-to-date too
452
+		foreach ($this->registry->addons as $addon) {
453
+			if ($addon instanceof EE_Addon) {
454
+				$addon->initialize_db_if_no_migrations_required();
455
+			}
456
+		}
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
463
+	 *
464
+	 * @param    array  $version_history
465
+	 * @param    string $current_version_to_add version to be added to the version history
466
+	 * @return    boolean success as to whether or not this option was changed
467
+	 */
468
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469
+	{
470
+		if (! $version_history) {
471
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
472
+		}
473
+		if ($current_version_to_add === null) {
474
+			$current_version_to_add = espresso_version();
475
+		}
476
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
477
+		// re-save
478
+		return update_option('espresso_db_update', $version_history);
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * Detects if the current version indicated in the has existed in the list of
485
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
486
+	 *
487
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
488
+	 *                                  If not supplied, fetches it from the options table.
489
+	 *                                  Also, caches its result so later parts of the code can also know whether
490
+	 *                                  there's been an update or not. This way we can add the current version to
491
+	 *                                  espresso_db_update, but still know if this is a new install or not
492
+	 * @return int one of the constants on EE_System::req_type_
493
+	 */
494
+	public function detect_req_type($espresso_db_update = null)
495
+	{
496
+		if ($this->_req_type === null) {
497
+			$espresso_db_update = ! empty($espresso_db_update)
498
+				? $espresso_db_update
499
+				: $this->fix_espresso_db_upgrade_option();
500
+			$this->_req_type = self::detect_req_type_given_activation_history(
501
+				$espresso_db_update,
502
+				'ee_espresso_activation', espresso_version()
503
+			);
504
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
505
+		}
506
+		return $this->_req_type;
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * Returns whether or not there was a non-micro version change (ie, change in either
513
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
514
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
515
+	 *
516
+	 * @param $activation_history
517
+	 * @return bool
518
+	 */
519
+	private function _detect_major_version_change($activation_history)
520
+	{
521
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
522
+		$previous_version_parts = explode('.', $previous_version);
523
+		$current_version_parts = explode('.', espresso_version());
524
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
525
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
526
+				   || $previous_version_parts[1] !== $current_version_parts[1]
527
+			   );
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 * Returns true if either the major or minor version of EE changed during this request.
534
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
535
+	 *
536
+	 * @return bool
537
+	 */
538
+	public function is_major_version_change()
539
+	{
540
+		return $this->_major_version_change;
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
547
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
548
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
549
+	 * just activated to (for core that will always be espresso_version())
550
+	 *
551
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
552
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
553
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
554
+	 *                                                 indicate that this plugin was just activated
555
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
556
+	 *                                                 espresso_version())
557
+	 * @return int one of the constants on EE_System::req_type_*
558
+	 */
559
+	public static function detect_req_type_given_activation_history(
560
+		$activation_history_for_addon,
561
+		$activation_indicator_option_name,
562
+		$version_to_upgrade_to
563
+	) {
564
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
565
+		if ($activation_history_for_addon) {
566
+			//it exists, so this isn't a completely new install
567
+			//check if this version already in that list of previously installed versions
568
+			if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569
+				//it a version we haven't seen before
570
+				if ($version_is_higher === 1) {
571
+					$req_type = EE_System::req_type_upgrade;
572
+				} else {
573
+					$req_type = EE_System::req_type_downgrade;
574
+				}
575
+				delete_option($activation_indicator_option_name);
576
+			} else {
577
+				// its not an update. maybe a reactivation?
578
+				if (get_option($activation_indicator_option_name, false)) {
579
+					if ($version_is_higher === -1) {
580
+						$req_type = EE_System::req_type_downgrade;
581
+					} else if ($version_is_higher === 0) {
582
+						//we've seen this version before, but it's an activation. must be a reactivation
583
+						$req_type = EE_System::req_type_reactivation;
584
+					} else {//$version_is_higher === 1
585
+						$req_type = EE_System::req_type_upgrade;
586
+					}
587
+					delete_option($activation_indicator_option_name);
588
+				} else {
589
+					//we've seen this version before and the activation indicate doesn't show it was just activated
590
+					if ($version_is_higher === -1) {
591
+						$req_type = EE_System::req_type_downgrade;
592
+					} else if ($version_is_higher === 0) {
593
+						//we've seen this version before and it's not an activation. its normal request
594
+						$req_type = EE_System::req_type_normal;
595
+					} else {//$version_is_higher === 1
596
+						$req_type = EE_System::req_type_upgrade;
597
+					}
598
+				}
599
+			}
600
+		} else {
601
+			//brand new install
602
+			$req_type = EE_System::req_type_new_activation;
603
+			delete_option($activation_indicator_option_name);
604
+		}
605
+		return $req_type;
606
+	}
607
+
608
+
609
+
610
+	/**
611
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
612
+	 * the $activation_history_for_addon
613
+	 *
614
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
615
+	 *                                             sometimes containing 'unknown-date'
616
+	 * @param string $version_to_upgrade_to        (current version)
617
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
618
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
619
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
620
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
621
+	 */
622
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
623
+	{
624
+		//find the most recently-activated version
625
+		$most_recently_active_version =
626
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
627
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * Gets the most recently active version listed in the activation history,
634
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
635
+	 *
636
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
637
+	 *                                   sometimes containing 'unknown-date'
638
+	 * @return string
639
+	 */
640
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
641
+	{
642
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
643
+		$most_recently_active_version = '0.0.0.dev.000';
644
+		if (is_array($activation_history)) {
645
+			foreach ($activation_history as $version => $times_activated) {
646
+				//check there is a record of when this version was activated. Otherwise,
647
+				//mark it as unknown
648
+				if (! $times_activated) {
649
+					$times_activated = array('unknown-date');
650
+				}
651
+				if (is_string($times_activated)) {
652
+					$times_activated = array($times_activated);
653
+				}
654
+				foreach ($times_activated as $an_activation) {
655
+					if ($an_activation !== 'unknown-date'
656
+						&& $an_activation
657
+						   > $most_recently_active_version_activation
658
+					) {
659
+						$most_recently_active_version = $version;
660
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
661
+							? '1970-01-01 00:00:00'
662
+							: $an_activation;
663
+					}
664
+				}
665
+			}
666
+		}
667
+		return $most_recently_active_version;
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * This redirects to the about EE page after activation
674
+	 *
675
+	 * @return void
676
+	 */
677
+	public function redirect_to_about_ee()
678
+	{
679
+		$notices = EE_Error::get_notices(false);
680
+		//if current user is an admin and it's not an ajax or rest request
681
+		if (
682
+			! (defined('DOING_AJAX') && DOING_AJAX)
683
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
684
+			&& ! isset($notices['errors'])
685
+			&& apply_filters(
686
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
687
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
688
+			)
689
+		) {
690
+			$query_params = array('page' => 'espresso_about');
691
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
692
+				$query_params['new_activation'] = true;
693
+			}
694
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
695
+				$query_params['reactivation'] = true;
696
+			}
697
+			$url = add_query_arg($query_params, admin_url('admin.php'));
698
+			wp_safe_redirect($url);
699
+			exit();
700
+		}
701
+	}
702
+
703
+
704
+
705
+	/**
706
+	 * load_core_configuration
707
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
708
+	 * which runs during the WP 'plugins_loaded' action at priority 5
709
+	 *
710
+	 * @return void
711
+	 * @throws ReflectionException
712
+	 */
713
+	public function load_core_configuration()
714
+	{
715
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
716
+		$this->loader->getShared('EE_Load_Textdomain');
717
+		//load textdomain
718
+		EE_Load_Textdomain::load_textdomain();
719
+		// load and setup EE_Config and EE_Network_Config
720
+		$config = $this->loader->getShared('EE_Config');
721
+		$this->loader->getShared('EE_Network_Config');
722
+		// setup autoloaders
723
+		// enable logging?
724
+		if ($config->admin->use_full_logging) {
725
+			$this->loader->getShared('EE_Log');
726
+		}
727
+		// check for activation errors
728
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
729
+		if ($activation_errors) {
730
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
731
+			update_option('ee_plugin_activation_errors', false);
732
+		}
733
+		// get model names
734
+		$this->_parse_model_names();
735
+		//load caf stuff a chance to play during the activation process too.
736
+		$this->_maybe_brew_regular();
737
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
738
+	}
739
+
740
+
741
+
742
+	/**
743
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
744
+	 *
745
+	 * @return void
746
+	 * @throws ReflectionException
747
+	 */
748
+	private function _parse_model_names()
749
+	{
750
+		//get all the files in the EE_MODELS folder that end in .model.php
751
+		$models = glob(EE_MODELS . '*.model.php');
752
+		$model_names = array();
753
+		$non_abstract_db_models = array();
754
+		foreach ($models as $model) {
755
+			// get model classname
756
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
757
+			$short_name = str_replace('EEM_', '', $classname);
758
+			$reflectionClass = new ReflectionClass($classname);
759
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
760
+				$non_abstract_db_models[$short_name] = $classname;
761
+			}
762
+			$model_names[$short_name] = $classname;
763
+		}
764
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
765
+		$this->registry->non_abstract_db_models = apply_filters(
766
+			'FHEE__EE_System__parse_implemented_model_names',
767
+			$non_abstract_db_models
768
+		);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
775
+	 * that need to be setup before our EE_System launches.
776
+	 *
777
+	 * @return void
778
+	 */
779
+	private function _maybe_brew_regular()
780
+	{
781
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
782
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * register_shortcodes_modules_and_widgets
790
+	 * generate lists of shortcodes and modules, then verify paths and classes
791
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
792
+	 * which runs during the WP 'plugins_loaded' action at priority 7
793
+	 *
794
+	 * @access public
795
+	 * @return void
796
+	 */
797
+	public function register_shortcodes_modules_and_widgets()
798
+	{
799
+		try {
800
+			// load, register, and add shortcodes the new way
801
+			new ShortcodesManager(
802
+			// and the old way, but we'll put it under control of the new system
803
+				EE_Config::getLegacyShortcodesManager()
804
+			);
805
+		} catch (Exception $exception) {
806
+			new ExceptionStackTraceDisplay($exception);
807
+		}
808
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
809
+		// check for addons using old hookpoint
810
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
811
+			$this->_incompatible_addon_error();
812
+		}
813
+	}
814
+
815
+
816
+
817
+	/**
818
+	 * _incompatible_addon_error
819
+	 *
820
+	 * @access public
821
+	 * @return void
822
+	 */
823
+	private function _incompatible_addon_error()
824
+	{
825
+		// get array of classes hooking into here
826
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
827
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
828
+		);
829
+		if (! empty($class_names)) {
830
+			$msg = __(
831
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
832
+				'event_espresso'
833
+			);
834
+			$msg .= '<ul>';
835
+			foreach ($class_names as $class_name) {
836
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
837
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
838
+						$class_name
839
+					) . '</b></li>';
840
+			}
841
+			$msg .= '</ul>';
842
+			$msg .= __(
843
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
844
+				'event_espresso'
845
+			);
846
+			// save list of incompatible addons to wp-options for later use
847
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
848
+			if (is_admin()) {
849
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
850
+			}
851
+		}
852
+	}
853
+
854
+
855
+
856
+	/**
857
+	 * brew_espresso
858
+	 * begins the process of setting hooks for initializing EE in the correct order
859
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
860
+	 * which runs during the WP 'plugins_loaded' action at priority 9
861
+	 *
862
+	 * @return void
863
+	 */
864
+	public function brew_espresso()
865
+	{
866
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
867
+		// load some final core systems
868
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
869
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
870
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
871
+		add_action('init', array($this, 'load_controllers'), 7);
872
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
873
+		add_action('init', array($this, 'initialize'), 10);
874
+		add_action('init', array($this, 'initialize_last'), 100);
875
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
876
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
877
+			// pew pew pew
878
+			$this->loader->getShared('EE_PUE');
879
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
880
+		}
881
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
882
+	}
883
+
884
+
885
+
886
+	/**
887
+	 *    set_hooks_for_core
888
+	 *
889
+	 * @access public
890
+	 * @return    void
891
+	 */
892
+	public function set_hooks_for_core()
893
+	{
894
+		$this->_deactivate_incompatible_addons();
895
+		do_action('AHEE__EE_System__set_hooks_for_core');
896
+	}
897
+
898
+
899
+
900
+	/**
901
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
902
+	 * deactivates any addons considered incompatible with the current version of EE
903
+	 */
904
+	private function _deactivate_incompatible_addons()
905
+	{
906
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
907
+		if (! empty($incompatible_addons)) {
908
+			$active_plugins = get_option('active_plugins', array());
909
+			foreach ($active_plugins as $active_plugin) {
910
+				foreach ($incompatible_addons as $incompatible_addon) {
911
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
912
+						unset($_GET['activate']);
913
+						espresso_deactivate_plugin($active_plugin);
914
+					}
915
+				}
916
+			}
917
+		}
918
+	}
919
+
920
+
921
+
922
+	/**
923
+	 *    perform_activations_upgrades_and_migrations
924
+	 *
925
+	 * @access public
926
+	 * @return    void
927
+	 */
928
+	public function perform_activations_upgrades_and_migrations()
929
+	{
930
+		//first check if we had previously attempted to setup EE's directories but failed
931
+		if (EEH_Activation::upload_directories_incomplete()) {
932
+			EEH_Activation::create_upload_directories();
933
+		}
934
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 *    load_CPTs_and_session
941
+	 *
942
+	 * @access public
943
+	 * @return    void
944
+	 */
945
+	public function load_CPTs_and_session()
946
+	{
947
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
948
+		// register Custom Post Types
949
+		$this->loader->getShared('EE_Register_CPTs');
950
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
951
+	}
952
+
953
+
954
+
955
+	/**
956
+	 * load_controllers
957
+	 * this is the best place to load any additional controllers that needs access to EE core.
958
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
959
+	 * time
960
+	 *
961
+	 * @access public
962
+	 * @return void
963
+	 */
964
+	public function load_controllers()
965
+	{
966
+		do_action('AHEE__EE_System__load_controllers__start');
967
+		// let's get it started
968
+		if (! is_admin() && ! $this->maintenance_mode->level()) {
969
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
970
+			$this->loader->getShared('EE_Front_Controller');
971
+		} else if (! EE_FRONT_AJAX) {
972
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
973
+			$this->loader->getShared('EE_Admin');
974
+		}
975
+		do_action('AHEE__EE_System__load_controllers__complete');
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * core_loaded_and_ready
982
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
983
+	 *
984
+	 * @access public
985
+	 * @return void
986
+	 */
987
+	public function core_loaded_and_ready()
988
+	{
989
+		$this->registry->load_core('Session');
990
+		do_action('AHEE__EE_System__core_loaded_and_ready');
991
+		// load_espresso_template_tags
992
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
993
+			require_once(EE_PUBLIC . 'template_tags.php');
994
+		}
995
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
996
+		$this->loader->getShared('EE_Session');
997
+		$this->loader->getShared('EventEspresso\core\services\assets\Registry');
998
+		wp_enqueue_script('espresso_core');
999
+	}
1000
+
1001
+
1002
+
1003
+	/**
1004
+	 * initialize
1005
+	 * this is the best place to begin initializing client code
1006
+	 *
1007
+	 * @access public
1008
+	 * @return void
1009
+	 */
1010
+	public function initialize()
1011
+	{
1012
+		do_action('AHEE__EE_System__initialize');
1013
+	}
1014
+
1015
+
1016
+
1017
+	/**
1018
+	 * initialize_last
1019
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
1020
+	 * initialize has done so
1021
+	 *
1022
+	 * @access public
1023
+	 * @return void
1024
+	 */
1025
+	public function initialize_last()
1026
+	{
1027
+		do_action('AHEE__EE_System__initialize_last');
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 * set_hooks_for_shortcodes_modules_and_addons
1034
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
1035
+	 * this happens at the very beginning of the wp_loaded hookpoint
1036
+	 *
1037
+	 * @access public
1038
+	 * @return void
1039
+	 */
1040
+	public function set_hooks_for_shortcodes_modules_and_addons()
1041
+	{
1042
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
1043
+	}
1044
+
1045
+
1046
+
1047
+	/**
1048
+	 * do_not_cache
1049
+	 * sets no cache headers and defines no cache constants for WP plugins
1050
+	 *
1051
+	 * @access public
1052
+	 * @return void
1053
+	 */
1054
+	public static function do_not_cache()
1055
+	{
1056
+		// set no cache constants
1057
+		if (! defined('DONOTCACHEPAGE')) {
1058
+			define('DONOTCACHEPAGE', true);
1059
+		}
1060
+		if (! defined('DONOTCACHCEOBJECT')) {
1061
+			define('DONOTCACHCEOBJECT', true);
1062
+		}
1063
+		if (! defined('DONOTCACHEDB')) {
1064
+			define('DONOTCACHEDB', true);
1065
+		}
1066
+		// add no cache headers
1067
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1068
+		// plus a little extra for nginx and Google Chrome
1069
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1070
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1071
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1072
+	}
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 *    extra_nocache_headers
1078
+	 *
1079
+	 * @access    public
1080
+	 * @param $headers
1081
+	 * @return    array
1082
+	 */
1083
+	public static function extra_nocache_headers($headers)
1084
+	{
1085
+		// for NGINX
1086
+		$headers['X-Accel-Expires'] = 0;
1087
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1088
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1089
+		return $headers;
1090
+	}
1091
+
1092
+
1093
+
1094
+	/**
1095
+	 *    nocache_headers
1096
+	 *
1097
+	 * @access    public
1098
+	 * @return    void
1099
+	 */
1100
+	public static function nocache_headers()
1101
+	{
1102
+		nocache_headers();
1103
+	}
1104
+
1105
+
1106
+
1107
+	/**
1108
+	 *    espresso_toolbar_items
1109
+	 *
1110
+	 * @access public
1111
+	 * @param  WP_Admin_Bar $admin_bar
1112
+	 * @return void
1113
+	 */
1114
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1115
+	{
1116
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1117
+		if ($this->maintenance_mode->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1118
+			|| defined('DOING_AJAX')
1119
+			|| ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1120
+		) {
1121
+			return;
1122
+		}
1123
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1124
+		$menu_class = 'espresso_menu_item_class';
1125
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1126
+		//because they're only defined in each of their respective constructors
1127
+		//and this might be a frontend request, in which case they aren't available
1128
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1129
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1130
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1131
+		//Top Level
1132
+		$admin_bar->add_menu(
1133
+			array(
1134
+				'id'    => 'espresso-toolbar',
1135
+				'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1136
+						   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1137
+						   . '</span>',
1138
+				'href'  => $events_admin_url,
1139
+				'meta'  => array(
1140
+					'title' => __('Event Espresso', 'event_espresso'),
1141
+					'class' => $menu_class . 'first',
1142
+				),
1143
+			)
1144
+		);
1145
+		//Events
1146
+		if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1147
+			$admin_bar->add_menu(
1148
+				array(
1149
+					'id'     => 'espresso-toolbar-events',
1150
+					'parent' => 'espresso-toolbar',
1151
+					'title'  => __('Events', 'event_espresso'),
1152
+					'href'   => $events_admin_url,
1153
+					'meta'   => array(
1154
+						'title'  => __('Events', 'event_espresso'),
1155
+						'target' => '',
1156
+						'class'  => $menu_class,
1157
+					),
1158
+				)
1159
+			);
1160
+		}
1161
+		if ($this->capabilities->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1162
+			//Events Add New
1163
+			$admin_bar->add_menu(
1164
+				array(
1165
+					'id'     => 'espresso-toolbar-events-new',
1166
+					'parent' => 'espresso-toolbar-events',
1167
+					'title'  => __('Add New', 'event_espresso'),
1168
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1169
+					'meta'   => array(
1170
+						'title'  => __('Add New', 'event_espresso'),
1171
+						'target' => '',
1172
+						'class'  => $menu_class,
1173
+					),
1174
+				)
1175
+			);
1176
+		}
1177
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1178
+			//Current post
1179
+			global $post;
1180
+			if ($this->capabilities->current_user_can(
1181
+				'ee_edit_event',
1182
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID
1183
+			)
1184
+			) {
1185
+				//Events Edit Current Event
1186
+				$admin_bar->add_menu(
1187
+					array(
1188
+						'id'     => 'espresso-toolbar-events-edit',
1189
+						'parent' => 'espresso-toolbar-events',
1190
+						'title'  => __('Edit Event', 'event_espresso'),
1191
+						'href'   => EEH_URL::add_query_args_and_nonce(
1192
+							array('action' => 'edit', 'post' => $post->ID),
1193
+							$events_admin_url
1194
+						),
1195
+						'meta'   => array(
1196
+							'title'  => __('Edit Event', 'event_espresso'),
1197
+							'target' => '',
1198
+							'class'  => $menu_class,
1199
+						),
1200
+					)
1201
+				);
1202
+			}
1203
+		}
1204
+		//Events View
1205
+		if ($this->capabilities->current_user_can(
1206
+			'ee_read_events',
1207
+			'ee_admin_bar_menu_espresso-toolbar-events-view'
1208
+		)
1209
+		) {
1210
+			$admin_bar->add_menu(
1211
+				array(
1212
+					'id'     => 'espresso-toolbar-events-view',
1213
+					'parent' => 'espresso-toolbar-events',
1214
+					'title'  => __('View', 'event_espresso'),
1215
+					'href'   => $events_admin_url,
1216
+					'meta'   => array(
1217
+						'title'  => __('View', 'event_espresso'),
1218
+						'target' => '',
1219
+						'class'  => $menu_class,
1220
+					),
1221
+				)
1222
+			);
1223
+		}
1224
+		if ($this->capabilities->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1225
+			//Events View All
1226
+			$admin_bar->add_menu(
1227
+				array(
1228
+					'id'     => 'espresso-toolbar-events-all',
1229
+					'parent' => 'espresso-toolbar-events-view',
1230
+					'title'  => __('All', 'event_espresso'),
1231
+					'href'   => $events_admin_url,
1232
+					'meta'   => array(
1233
+						'title'  => __('All', 'event_espresso'),
1234
+						'target' => '',
1235
+						'class'  => $menu_class,
1236
+					),
1237
+				)
1238
+			);
1239
+		}
1240
+		if ($this->capabilities->current_user_can(
1241
+			'ee_read_events',
1242
+			'ee_admin_bar_menu_espresso-toolbar-events-today'
1243
+		)
1244
+		) {
1245
+			//Events View Today
1246
+			$admin_bar->add_menu(
1247
+				array(
1248
+					'id'     => 'espresso-toolbar-events-today',
1249
+					'parent' => 'espresso-toolbar-events-view',
1250
+					'title'  => __('Today', 'event_espresso'),
1251
+					'href'   => EEH_URL::add_query_args_and_nonce(
1252
+						array('action' => 'default', 'status' => 'today'),
1253
+						$events_admin_url
1254
+					),
1255
+					'meta'   => array(
1256
+						'title'  => __('Today', 'event_espresso'),
1257
+						'target' => '',
1258
+						'class'  => $menu_class,
1259
+					),
1260
+				)
1261
+			);
1262
+		}
1263
+		if ($this->capabilities->current_user_can(
1264
+			'ee_read_events',
1265
+			'ee_admin_bar_menu_espresso-toolbar-events-month'
1266
+		)
1267
+		) {
1268
+			//Events View This Month
1269
+			$admin_bar->add_menu(
1270
+				array(
1271
+					'id'     => 'espresso-toolbar-events-month',
1272
+					'parent' => 'espresso-toolbar-events-view',
1273
+					'title'  => __('This Month', 'event_espresso'),
1274
+					'href'   => EEH_URL::add_query_args_and_nonce(
1275
+						array('action' => 'default', 'status' => 'month'),
1276
+						$events_admin_url
1277
+					),
1278
+					'meta'   => array(
1279
+						'title'  => __('This Month', 'event_espresso'),
1280
+						'target' => '',
1281
+						'class'  => $menu_class,
1282
+					),
1283
+				)
1284
+			);
1285
+		}
1286
+		//Registration Overview
1287
+		if ($this->capabilities->current_user_can(
1288
+			'ee_read_registrations',
1289
+			'ee_admin_bar_menu_espresso-toolbar-registrations'
1290
+		)
1291
+		) {
1292
+			$admin_bar->add_menu(
1293
+				array(
1294
+					'id'     => 'espresso-toolbar-registrations',
1295
+					'parent' => 'espresso-toolbar',
1296
+					'title'  => __('Registrations', 'event_espresso'),
1297
+					'href'   => $reg_admin_url,
1298
+					'meta'   => array(
1299
+						'title'  => __('Registrations', 'event_espresso'),
1300
+						'target' => '',
1301
+						'class'  => $menu_class,
1302
+					),
1303
+				)
1304
+			);
1305
+		}
1306
+		//Registration Overview Today
1307
+		if ($this->capabilities->current_user_can(
1308
+			'ee_read_registrations',
1309
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today'
1310
+		)
1311
+		) {
1312
+			$admin_bar->add_menu(
1313
+				array(
1314
+					'id'     => 'espresso-toolbar-registrations-today',
1315
+					'parent' => 'espresso-toolbar-registrations',
1316
+					'title'  => __('Today', 'event_espresso'),
1317
+					'href'   => EEH_URL::add_query_args_and_nonce(
1318
+						array('action' => 'default', 'status' => 'today'),
1319
+						$reg_admin_url
1320
+					),
1321
+					'meta'   => array(
1322
+						'title'  => __('Today', 'event_espresso'),
1323
+						'target' => '',
1324
+						'class'  => $menu_class,
1325
+					),
1326
+				)
1327
+			);
1328
+		}
1329
+		//Registration Overview Today Completed
1330
+		if ($this->capabilities->current_user_can(
1331
+			'ee_read_registrations',
1332
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
1333
+		)
1334
+		) {
1335
+			$admin_bar->add_menu(
1336
+				array(
1337
+					'id'     => 'espresso-toolbar-registrations-today-approved',
1338
+					'parent' => 'espresso-toolbar-registrations-today',
1339
+					'title'  => __('Approved', 'event_espresso'),
1340
+					'href'   => EEH_URL::add_query_args_and_nonce(
1341
+						array(
1342
+							'action'      => 'default',
1343
+							'status'      => 'today',
1344
+							'_reg_status' => EEM_Registration::status_id_approved,
1345
+						), $reg_admin_url
1346
+					),
1347
+					'meta'   => array(
1348
+						'title'  => __('Approved', 'event_espresso'),
1349
+						'target' => '',
1350
+						'class'  => $menu_class,
1351
+					),
1352
+				)
1353
+			);
1354
+		}
1355
+		//Registration Overview Today Pending\
1356
+		if ($this->capabilities->current_user_can(
1357
+			'ee_read_registrations',
1358
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
1359
+		)
1360
+		) {
1361
+			$admin_bar->add_menu(
1362
+				array(
1363
+					'id'     => 'espresso-toolbar-registrations-today-pending',
1364
+					'parent' => 'espresso-toolbar-registrations-today',
1365
+					'title'  => __('Pending', 'event_espresso'),
1366
+					'href'   => EEH_URL::add_query_args_and_nonce(
1367
+						array(
1368
+							'action'     => 'default',
1369
+							'status'     => 'today',
1370
+							'reg_status' => EEM_Registration::status_id_pending_payment,
1371
+						), $reg_admin_url
1372
+					),
1373
+					'meta'   => array(
1374
+						'title'  => __('Pending Payment', 'event_espresso'),
1375
+						'target' => '',
1376
+						'class'  => $menu_class,
1377
+					),
1378
+				)
1379
+			);
1380
+		}
1381
+		//Registration Overview Today Incomplete
1382
+		if ($this->capabilities->current_user_can(
1383
+			'ee_read_registrations',
1384
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
1385
+		)
1386
+		) {
1387
+			$admin_bar->add_menu(
1388
+				array(
1389
+					'id'     => 'espresso-toolbar-registrations-today-not-approved',
1390
+					'parent' => 'espresso-toolbar-registrations-today',
1391
+					'title'  => __('Not Approved', 'event_espresso'),
1392
+					'href'   => EEH_URL::add_query_args_and_nonce(
1393
+						array(
1394
+							'action'      => 'default',
1395
+							'status'      => 'today',
1396
+							'_reg_status' => EEM_Registration::status_id_not_approved,
1397
+						), $reg_admin_url
1398
+					),
1399
+					'meta'   => array(
1400
+						'title'  => __('Not Approved', 'event_espresso'),
1401
+						'target' => '',
1402
+						'class'  => $menu_class,
1403
+					),
1404
+				)
1405
+			);
1406
+		}
1407
+		//Registration Overview Today Incomplete
1408
+		if ($this->capabilities->current_user_can(
1409
+			'ee_read_registrations',
1410
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
1411
+		)
1412
+		) {
1413
+			$admin_bar->add_menu(
1414
+				array(
1415
+					'id'     => 'espresso-toolbar-registrations-today-cancelled',
1416
+					'parent' => 'espresso-toolbar-registrations-today',
1417
+					'title'  => __('Cancelled', 'event_espresso'),
1418
+					'href'   => EEH_URL::add_query_args_and_nonce(
1419
+						array(
1420
+							'action'      => 'default',
1421
+							'status'      => 'today',
1422
+							'_reg_status' => EEM_Registration::status_id_cancelled,
1423
+						), $reg_admin_url
1424
+					),
1425
+					'meta'   => array(
1426
+						'title'  => __('Cancelled', 'event_espresso'),
1427
+						'target' => '',
1428
+						'class'  => $menu_class,
1429
+					),
1430
+				)
1431
+			);
1432
+		}
1433
+		//Registration Overview This Month
1434
+		if ($this->capabilities->current_user_can(
1435
+			'ee_read_registrations',
1436
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month'
1437
+		)
1438
+		) {
1439
+			$admin_bar->add_menu(
1440
+				array(
1441
+					'id'     => 'espresso-toolbar-registrations-month',
1442
+					'parent' => 'espresso-toolbar-registrations',
1443
+					'title'  => __('This Month', 'event_espresso'),
1444
+					'href'   => EEH_URL::add_query_args_and_nonce(
1445
+						array('action' => 'default', 'status' => 'month'),
1446
+						$reg_admin_url
1447
+					),
1448
+					'meta'   => array(
1449
+						'title'  => __('This Month', 'event_espresso'),
1450
+						'target' => '',
1451
+						'class'  => $menu_class,
1452
+					),
1453
+				)
1454
+			);
1455
+		}
1456
+		//Registration Overview This Month Approved
1457
+		if ($this->capabilities->current_user_can(
1458
+			'ee_read_registrations',
1459
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
1460
+		)
1461
+		) {
1462
+			$admin_bar->add_menu(
1463
+				array(
1464
+					'id'     => 'espresso-toolbar-registrations-month-approved',
1465
+					'parent' => 'espresso-toolbar-registrations-month',
1466
+					'title'  => __('Approved', 'event_espresso'),
1467
+					'href'   => EEH_URL::add_query_args_and_nonce(
1468
+						array(
1469
+							'action'      => 'default',
1470
+							'status'      => 'month',
1471
+							'_reg_status' => EEM_Registration::status_id_approved,
1472
+						), $reg_admin_url
1473
+					),
1474
+					'meta'   => array(
1475
+						'title'  => __('Approved', 'event_espresso'),
1476
+						'target' => '',
1477
+						'class'  => $menu_class,
1478
+					),
1479
+				)
1480
+			);
1481
+		}
1482
+		//Registration Overview This Month Pending
1483
+		if ($this->capabilities->current_user_can(
1484
+			'ee_read_registrations',
1485
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
1486
+		)
1487
+		) {
1488
+			$admin_bar->add_menu(
1489
+				array(
1490
+					'id'     => 'espresso-toolbar-registrations-month-pending',
1491
+					'parent' => 'espresso-toolbar-registrations-month',
1492
+					'title'  => __('Pending', 'event_espresso'),
1493
+					'href'   => EEH_URL::add_query_args_and_nonce(
1494
+						array(
1495
+							'action'      => 'default',
1496
+							'status'      => 'month',
1497
+							'_reg_status' => EEM_Registration::status_id_pending_payment,
1498
+						), $reg_admin_url
1499
+					),
1500
+					'meta'   => array(
1501
+						'title'  => __('Pending', 'event_espresso'),
1502
+						'target' => '',
1503
+						'class'  => $menu_class,
1504
+					),
1505
+				)
1506
+			);
1507
+		}
1508
+		//Registration Overview This Month Not Approved
1509
+		if ($this->capabilities->current_user_can(
1510
+			'ee_read_registrations',
1511
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
1512
+		)
1513
+		) {
1514
+			$admin_bar->add_menu(
1515
+				array(
1516
+					'id'     => 'espresso-toolbar-registrations-month-not-approved',
1517
+					'parent' => 'espresso-toolbar-registrations-month',
1518
+					'title'  => __('Not Approved', 'event_espresso'),
1519
+					'href'   => EEH_URL::add_query_args_and_nonce(
1520
+						array(
1521
+							'action'      => 'default',
1522
+							'status'      => 'month',
1523
+							'_reg_status' => EEM_Registration::status_id_not_approved,
1524
+						), $reg_admin_url
1525
+					),
1526
+					'meta'   => array(
1527
+						'title'  => __('Not Approved', 'event_espresso'),
1528
+						'target' => '',
1529
+						'class'  => $menu_class,
1530
+					),
1531
+				)
1532
+			);
1533
+		}
1534
+		//Registration Overview This Month Cancelled
1535
+		if ($this->capabilities->current_user_can(
1536
+			'ee_read_registrations',
1537
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
1538
+		)
1539
+		) {
1540
+			$admin_bar->add_menu(
1541
+				array(
1542
+					'id'     => 'espresso-toolbar-registrations-month-cancelled',
1543
+					'parent' => 'espresso-toolbar-registrations-month',
1544
+					'title'  => __('Cancelled', 'event_espresso'),
1545
+					'href'   => EEH_URL::add_query_args_and_nonce(
1546
+						array(
1547
+							'action'      => 'default',
1548
+							'status'      => 'month',
1549
+							'_reg_status' => EEM_Registration::status_id_cancelled,
1550
+						), $reg_admin_url
1551
+					),
1552
+					'meta'   => array(
1553
+						'title'  => __('Cancelled', 'event_espresso'),
1554
+						'target' => '',
1555
+						'class'  => $menu_class,
1556
+					),
1557
+				)
1558
+			);
1559
+		}
1560
+		//Extensions & Services
1561
+		if ($this->capabilities->current_user_can(
1562
+			'ee_read_ee',
1563
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
1564
+		)
1565
+		) {
1566
+			$admin_bar->add_menu(
1567
+				array(
1568
+					'id'     => 'espresso-toolbar-extensions-and-services',
1569
+					'parent' => 'espresso-toolbar',
1570
+					'title'  => __('Extensions & Services', 'event_espresso'),
1571
+					'href'   => $extensions_admin_url,
1572
+					'meta'   => array(
1573
+						'title'  => __('Extensions & Services', 'event_espresso'),
1574
+						'target' => '',
1575
+						'class'  => $menu_class,
1576
+					),
1577
+				)
1578
+			);
1579
+		}
1580
+	}
1581
+
1582
+
1583
+
1584
+	/**
1585
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1586
+	 * never returned with the function.
1587
+	 *
1588
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1589
+	 * @return array
1590
+	 */
1591
+	public function remove_pages_from_wp_list_pages($exclude_array)
1592
+	{
1593
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1594
+	}
1595 1595
 
1596 1596
 
1597 1597
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\loaders\LoaderInterface;
4 4
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         EE_Maintenance_Mode $maintenance_mode = null
132 132
     ) {
133 133
         // check if class object is instantiated
134
-        if (! self::$_instance instanceof EE_System) {
134
+        if ( ! self::$_instance instanceof EE_System) {
135 135
             self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
136 136
         }
137 137
         return self::$_instance;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     {
228 228
         // set autoloaders for all of the classes implementing EEI_Plugin_API
229 229
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
230
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
230
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
231 231
         //caps need to be initialized on every request so that capability maps are set.
232 232
         //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
233 233
         $this->capabilities->init_caps();
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                 && in_array($_GET['action'], array('activate', 'activate-selected'), true)
250 250
             )
251 251
         ) {
252
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
252
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
253 253
         }
254 254
         do_action('AHEE__EE_System__load_espresso_addons__complete');
255 255
     }
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
359 359
     {
360 360
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
361
-        if (! $espresso_db_update) {
361
+        if ( ! $espresso_db_update) {
362 362
             $espresso_db_update = get_option('espresso_db_update');
363 363
         }
364 364
         // check that option is an array
365
-        if (! is_array($espresso_db_update)) {
365
+        if ( ! is_array($espresso_db_update)) {
366 366
             // if option is FALSE, then it never existed
367 367
             if ($espresso_db_update === false) {
368 368
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
469 469
     {
470
-        if (! $version_history) {
470
+        if ( ! $version_history) {
471 471
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
472 472
         }
473 473
         if ($current_version_to_add === null) {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         if ($activation_history_for_addon) {
566 566
             //it exists, so this isn't a completely new install
567 567
             //check if this version already in that list of previously installed versions
568
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
568
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
569 569
                 //it a version we haven't seen before
570 570
                 if ($version_is_higher === 1) {
571 571
                     $req_type = EE_System::req_type_upgrade;
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
             foreach ($activation_history as $version => $times_activated) {
646 646
                 //check there is a record of when this version was activated. Otherwise,
647 647
                 //mark it as unknown
648
-                if (! $times_activated) {
648
+                if ( ! $times_activated) {
649 649
                     $times_activated = array('unknown-date');
650 650
                 }
651 651
                 if (is_string($times_activated)) {
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
     private function _parse_model_names()
749 749
     {
750 750
         //get all the files in the EE_MODELS folder that end in .model.php
751
-        $models = glob(EE_MODELS . '*.model.php');
751
+        $models = glob(EE_MODELS.'*.model.php');
752 752
         $model_names = array();
753 753
         $non_abstract_db_models = array();
754 754
         foreach ($models as $model) {
@@ -778,8 +778,8 @@  discard block
 block discarded – undo
778 778
      */
779 779
     private function _maybe_brew_regular()
780 780
     {
781
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
782
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
781
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
782
+            require_once EE_CAFF_PATH.'brewing_regular.php';
783 783
         }
784 784
     }
785 785
 
@@ -826,17 +826,17 @@  discard block
 block discarded – undo
826 826
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
827 827
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
828 828
         );
829
-        if (! empty($class_names)) {
829
+        if ( ! empty($class_names)) {
830 830
             $msg = __(
831 831
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
832 832
                 'event_espresso'
833 833
             );
834 834
             $msg .= '<ul>';
835 835
             foreach ($class_names as $class_name) {
836
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
836
+                $msg .= '<li><b>Event Espresso - '.str_replace(
837 837
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
838 838
                         $class_name
839
-                    ) . '</b></li>';
839
+                    ).'</b></li>';
840 840
             }
841 841
             $msg .= '</ul>';
842 842
             $msg .= __(
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
     private function _deactivate_incompatible_addons()
905 905
     {
906 906
         $incompatible_addons = get_option('ee_incompatible_addons', array());
907
-        if (! empty($incompatible_addons)) {
907
+        if ( ! empty($incompatible_addons)) {
908 908
             $active_plugins = get_option('active_plugins', array());
909 909
             foreach ($active_plugins as $active_plugin) {
910 910
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -965,10 +965,10 @@  discard block
 block discarded – undo
965 965
     {
966 966
         do_action('AHEE__EE_System__load_controllers__start');
967 967
         // let's get it started
968
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
968
+        if ( ! is_admin() && ! $this->maintenance_mode->level()) {
969 969
             do_action('AHEE__EE_System__load_controllers__load_front_controllers');
970 970
             $this->loader->getShared('EE_Front_Controller');
971
-        } else if (! EE_FRONT_AJAX) {
971
+        } else if ( ! EE_FRONT_AJAX) {
972 972
             do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
973 973
             $this->loader->getShared('EE_Admin');
974 974
         }
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
         $this->registry->load_core('Session');
990 990
         do_action('AHEE__EE_System__core_loaded_and_ready');
991 991
         // load_espresso_template_tags
992
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
993
-            require_once(EE_PUBLIC . 'template_tags.php');
992
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
993
+            require_once(EE_PUBLIC.'template_tags.php');
994 994
         }
995 995
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
996 996
         $this->loader->getShared('EE_Session');
@@ -1054,13 +1054,13 @@  discard block
 block discarded – undo
1054 1054
     public static function do_not_cache()
1055 1055
     {
1056 1056
         // set no cache constants
1057
-        if (! defined('DONOTCACHEPAGE')) {
1057
+        if ( ! defined('DONOTCACHEPAGE')) {
1058 1058
             define('DONOTCACHEPAGE', true);
1059 1059
         }
1060
-        if (! defined('DONOTCACHCEOBJECT')) {
1060
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1061 1061
             define('DONOTCACHCEOBJECT', true);
1062 1062
         }
1063
-        if (! defined('DONOTCACHEDB')) {
1063
+        if ( ! defined('DONOTCACHEDB')) {
1064 1064
             define('DONOTCACHEDB', true);
1065 1065
         }
1066 1066
         // add no cache headers
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
                 'href'  => $events_admin_url,
1139 1139
                 'meta'  => array(
1140 1140
                     'title' => __('Event Espresso', 'event_espresso'),
1141
-                    'class' => $menu_class . 'first',
1141
+                    'class' => $menu_class.'first',
1142 1142
                 ),
1143 1143
             )
1144 1144
         );
Please login to merge, or discard this patch.