Completed
Branch BUG/reg-status-change-recursio... (2db0c9)
by
unknown
20:03 queued 10:32
created
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
         // enqueue style
364 364
         wp_register_style(
365 365
             'espresso_txn',
366
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
366
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
367 367
             array(),
368 368
             EVENT_ESPRESSO_VERSION
369 369
         );
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         // scripts
372 372
         wp_register_script(
373 373
             'espresso_txn',
374
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
374
+            TXN_ASSETS_URL.'espresso_transactions_admin.js',
375 375
             array(
376 376
                 'ee_admin_js',
377 377
                 'ee-datepicker',
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             $this->_transaction->verify_abandoned_transaction_status();
500 500
         }
501 501
 
502
-        if (! $this->_transaction instanceof EE_Transaction) {
502
+        if ( ! $this->_transaction instanceof EE_Transaction) {
503 503
             $error_msg = sprintf(
504 504
                 esc_html__(
505 505
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
598 598
             array(
599 599
                 'overpaid'   => array(
600
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
600
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
601 601
                     'desc'  => EEH_Template::pretty_status(
602 602
                         EEM_Transaction::overpaid_status_code,
603 603
                         false,
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
                     ),
606 606
                 ),
607 607
                 'complete'   => array(
608
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
608
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
609 609
                     'desc'  => EEH_Template::pretty_status(
610 610
                         EEM_Transaction::complete_status_code,
611 611
                         false,
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
                     ),
614 614
                 ),
615 615
                 'incomplete' => array(
616
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
616
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
617 617
                     'desc'  => EEH_Template::pretty_status(
618 618
                         EEM_Transaction::incomplete_status_code,
619 619
                         false,
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
                     ),
622 622
                 ),
623 623
                 'abandoned'  => array(
624
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
624
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
625 625
                     'desc'  => EEH_Template::pretty_status(
626 626
                         EEM_Transaction::abandoned_status_code,
627 627
                         false,
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
                     ),
630 630
                 ),
631 631
                 'failed'     => array(
632
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
632
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
633 633
                     'desc'  => EEH_Template::pretty_status(
634 634
                         EEM_Transaction::failed_status_code,
635 635
                         false,
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
                     'Click to Edit event',
679 679
                     'event_espresso'
680 680
                 )
681
-                . '">' . $event->get('EVT_name') . '</a>',
681
+                . '">'.$event->get('EVT_name').'</a>',
682 682
                 '</h3>'
683 683
             )
684 684
             : '';
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 
713 713
         $this->_set_transaction_object();
714 714
 
715
-        if (! $this->_transaction instanceof EE_Transaction) {
715
+        if ( ! $this->_transaction instanceof EE_Transaction) {
716 716
             return;
717 717
         }
718 718
         $primary_registration = $this->_transaction->primary_registration();
@@ -726,9 +726,9 @@  discard block
 block discarded – undo
726 726
         $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
727 727
         $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
728 728
 
729
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ];
729
+        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
730 730
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
731
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
731
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
732 732
 
733 733
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
734 734
         $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
         // grab messages at the last second
847 847
         $this->_template_args['notices'] = EE_Error::get_notices();
848 848
         // path to template
849
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
849
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
850 850
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
851 851
             $template_path,
852 852
             $this->_template_args,
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 
876 876
         $this->_set_transaction_object();
877 877
 
878
-        if (! $this->_transaction instanceof EE_Transaction) {
878
+        if ( ! $this->_transaction instanceof EE_Transaction) {
879 879
             return;
880 880
         }
881 881
         add_meta_box(
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     {
931 931
         $content = '';
932 932
         $actions = array();
933
-        if (! $transaction instanceof EE_Transaction) {
933
+        if ( ! $transaction instanceof EE_Transaction) {
934 934
             return $content;
935 935
         }
936 936
         /** @var EE_Registration $primary_registration */
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
         );
992 992
         if ($actions) {
993 993
             $content = '<ul>';
994
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
994
+            $content .= '<li>'.implode('</li><li>', $actions).'</li>';
995 995
             $content .= '</uL>';
996 996
         }
997 997
         return $content;
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
         // process payment details
1058 1058
         $payments = $this->_transaction->get_many_related('Payment');
1059
-        if (! empty($payments)) {
1059
+        if ( ! empty($payments)) {
1060 1060
             $this->_template_args['payments'] = $payments;
1061 1061
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1062 1062
         } else {
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1118 1118
                                   ucwords(str_replace('_', ' ', $reg_step)),
1119 1119
                                   date(
1120
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1120
+                                      get_option('date_format').' '.get_option('time_format'),
1121 1121
                                       ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1122 1122
                                   )
1123 1123
                               )
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 
1171 1171
         // 'espresso_delete_payment_nonce'
1172 1172
 
1173
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1173
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1174 1174
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1175 1175
     }
1176 1176
 
@@ -1202,18 +1202,18 @@  discard block
 block discarded – undo
1202 1202
                 ),
1203 1203
             )
1204 1204
         );
1205
-        if (! empty($reg_payments)) {
1205
+        if ( ! empty($reg_payments)) {
1206 1206
             foreach ($payments as $payment) {
1207
-                if (! $payment instanceof EE_Payment) {
1207
+                if ( ! $payment instanceof EE_Payment) {
1208 1208
                     continue;
1209
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1210
-                    $existing_reg_payments[ $payment->ID() ] = array();
1209
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1210
+                    $existing_reg_payments[$payment->ID()] = array();
1211 1211
                 }
1212 1212
                 foreach ($reg_payments as $reg_payment) {
1213 1213
                     if ($reg_payment instanceof EE_Registration_Payment
1214 1214
                         && $reg_payment->payment_ID() === $payment->ID()
1215 1215
                     ) {
1216
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1216
+                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1217 1217
                     }
1218 1218
                 }
1219 1219
             }
@@ -1254,16 +1254,16 @@  discard block
 block discarded – undo
1254 1254
                                                  '',
1255 1255
                                                  'clear: both; margin: 1.5em 0 0; display: none;'
1256 1256
                                              );
1257
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1257
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258 1258
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259 1259
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1260 1260
             EEH_HTML::tr(
1261
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1261
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1262
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1263
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1264
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1265
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1266
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1267 1267
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268 1268
             )
1269 1269
         );
@@ -1278,29 +1278,29 @@  discard block
 block discarded – undo
1278 1278
                     : esc_html__('Unknown Attendee', 'event_espresso');
1279 1279
                 $owing = $registration->final_price() - $registration->paid();
1280 1280
                 $taxable = $registration->ticket()->taxable()
1281
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1281
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1282 1282
                     : '';
1283 1283
                 $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1284 1284
                     ? ' checked="checked"'
1285 1285
                     : '';
1286 1286
                 $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1287 1287
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1288
-                    EEH_HTML::td($registration->ID()) .
1289
-                    EEH_HTML::td($attendee_name) .
1288
+                    EEH_HTML::td($registration->ID()).
1289
+                    EEH_HTML::td($attendee_name).
1290 1290
                     EEH_HTML::td(
1291
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1292
-                    ) .
1293
-                    EEH_HTML::td($registration->event_name()) .
1294
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1295
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1291
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1292
+                    ).
1293
+                    EEH_HTML::td($registration->event_name()).
1294
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1295
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
1296 1296
                     EEH_HTML::td(
1297
-                        '<input type="checkbox" value="' . $registration->ID()
1297
+                        '<input type="checkbox" value="'.$registration->ID()
1298 1298
                         . '" name="txn_admin_payment[registrations]"'
1299
-                        . $checked . $disabled . '>',
1299
+                        . $checked.$disabled.'>',
1300 1300
                         '',
1301 1301
                         'jst-cntr'
1302 1302
                     ),
1303
-                    'apply-payment-registration-row-' . $registration->ID()
1303
+                    'apply-payment-registration-row-'.$registration->ID()
1304 1304
                 );
1305 1305
             }
1306 1306
         }
@@ -1381,12 +1381,12 @@  discard block
 block discarded – undo
1381 1381
                 array(
1382 1382
                     'OR*payment_method_for_payment' => array(
1383 1383
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1384
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1384
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'),
1385 1385
                     ),
1386 1386
                 ),
1387 1387
             );
1388 1388
         } else {
1389
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1389
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1390 1390
         }
1391 1391
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1392 1392
     }
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
             'Line_Item',
1416 1416
             array(array('LIN_type' => 'line-item'))
1417 1417
         );
1418
-        if (! empty($line_items)) {
1418
+        if ( ! empty($line_items)) {
1419 1419
             foreach ($line_items as $item) {
1420 1420
                 if ($item instanceof EE_Line_Item) {
1421 1421
                     switch ($item->OBJ_type()) {
@@ -1425,7 +1425,7 @@  discard block
 block discarded – undo
1425 1425
                             $ticket = $item->ticket();
1426 1426
                             // right now we're only handling tickets here.
1427 1427
                             // Cause its expected that only tickets will have attendees right?
1428
-                            if (! $ticket instanceof EE_Ticket) {
1428
+                            if ( ! $ticket instanceof EE_Ticket) {
1429 1429
                                 continue;
1430 1430
                             }
1431 1431
                             try {
@@ -1434,7 +1434,7 @@  discard block
 block discarded – undo
1434 1434
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1435 1435
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1436 1436
                             }
1437
-                            $event_name .= ' - ' . $item->get('LIN_name');
1437
+                            $event_name .= ' - '.$item->get('LIN_name');
1438 1438
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1439 1439
                             // now get all of the registrations for this transaction that use this ticket
1440 1440
                             $registrations = $ticket->get_many_related(
@@ -1442,38 +1442,38 @@  discard block
 block discarded – undo
1442 1442
                                 array(array('TXN_ID' => $this->_transaction->ID()))
1443 1443
                             );
1444 1444
                             foreach ($registrations as $registration) {
1445
-                                if (! $registration instanceof EE_Registration) {
1445
+                                if ( ! $registration instanceof EE_Registration) {
1446 1446
                                     continue;
1447 1447
                                 }
1448
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1448
+                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1449 1449
                                     = $registration->status_ID();
1450
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1450
+                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1451 1451
                                     = $registration->count();
1452
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1452
+                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1453 1453
                                     = $event_name;
1454
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1454
+                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1455 1455
                                     = $ticket_price;
1456 1456
                                 // attendee info
1457 1457
                                 $attendee = $registration->get_first_related('Attendee');
1458 1458
                                 if ($attendee instanceof EE_Attendee) {
1459
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1459
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1460 1460
                                         = $attendee->ID();
1461
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1461
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1462 1462
                                         = $attendee->full_name();
1463
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1464
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1463
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1464
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1465 1465
                                           . esc_html__(
1466 1466
                                               ' Event',
1467 1467
                                               'event_espresso'
1468 1468
                                           )
1469
-                                          . '">' . $attendee->email() . '</a>';
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1469
+                                          . '">'.$attendee->email().'</a>';
1470
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1471 1471
                                         = EEH_Address::format($attendee, 'inline', false, false);
1472 1472
                                 } else {
1473
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1474
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1475
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1476
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1473
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = '';
1474
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1475
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email'] = '';
1476
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address'] = '';
1477 1477
                                 }
1478 1478
                             }
1479 1479
                             break;
@@ -1489,7 +1489,7 @@  discard block
 block discarded – undo
1489 1489
                 TXN_ADMIN_URL
1490 1490
             );
1491 1491
             echo EEH_Template::display_template(
1492
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1492
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1493 1493
                 $this->_template_args,
1494 1494
                 true
1495 1495
             );
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1525 1525
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1526 1526
             : null;
1527
-        if (! $primary_att instanceof EE_Attendee) {
1527
+        if ( ! $primary_att instanceof EE_Attendee) {
1528 1528
             $this->_template_args['no_attendee_message'] = esc_html__(
1529 1529
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1530 1530
                 'event_espresso'
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
         // get formatted address for registrant
1547 1547
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1548 1548
         echo EEH_Template::display_template(
1549
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1549
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1550 1550
             $this->_template_args,
1551 1551
             true
1552 1552
         );
@@ -1571,8 +1571,8 @@  discard block
 block discarded – undo
1571 1571
             TXN_ADMIN_URL
1572 1572
         );
1573 1573
 
1574
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1575
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1574
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1575
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1576 1576
     }
1577 1577
 
1578 1578
 
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
             'ee_edit_payments',
1598 1598
             'apply_payment_or_refund_from_registration_details'
1599 1599
         );
1600
-        if (! empty($valid_data) && $has_access) {
1600
+        if ( ! empty($valid_data) && $has_access) {
1601 1601
             $PAY_ID = $valid_data['PAY_ID'];
1602 1602
             // save  the new payment
1603 1603
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1611 1611
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1612 1612
                 // apply payment to registrations (if applicable)
1613
-                if (! empty($REG_IDs)) {
1613
+                if ( ! empty($REG_IDs)) {
1614 1614
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1615 1615
                     $this->_maybe_send_notifications();
1616 1616
                     // now process status changes for the same registrations
@@ -1680,14 +1680,14 @@  discard block
 block discarded – undo
1680 1680
      */
1681 1681
     protected function _validate_payment_request_data()
1682 1682
     {
1683
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1683
+        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1684 1684
             return false;
1685 1685
         }
1686 1686
         $payment_form = $this->_generate_payment_form_section();
1687 1687
         try {
1688 1688
             if ($payment_form->was_submitted()) {
1689 1689
                 $payment_form->receive_form_submission();
1690
-                if (! $payment_form->is_valid()) {
1690
+                if ( ! $payment_form->is_valid()) {
1691 1691
                     $submission_error_messages = array();
1692 1692
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1693 1693
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
             array('Y-m-d', 'g:i a')
1867 1867
         );
1868 1868
 
1869
-        if (! $payment->save()) {
1869
+        if ( ! $payment->save()) {
1870 1870
             EE_Error::add_error(
1871 1871
                 sprintf(
1872 1872
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -2063,12 +2063,12 @@  discard block
 block discarded – undo
2063 2063
         // but add in some conditions regarding payment,
2064 2064
         // so that we don't apply payments to registrations that are free or have already been paid for
2065 2065
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2066
-        if (! $payment->is_a_refund()) {
2066
+        if ( ! $payment->is_a_refund()) {
2067 2067
             $registration_query_where_params['REG_final_price'] = array('!=', 0);
2068 2068
             $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2069 2069
         }
2070 2070
         $registrations = $transaction->registrations(array($registration_query_where_params));
2071
-        if (! empty($registrations)) {
2071
+        if ( ! empty($registrations)) {
2072 2072
             /** @type EE_Payment_Processor $payment_processor */
2073 2073
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2074 2074
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2093,7 +2093,7 @@  discard block
 block discarded – undo
2093 2093
     protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2094 2094
     {
2095 2095
         // first if there is no change in status then we get out.
2096
-        if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2096
+        if ( ! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2097 2097
             || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2098 2098
         ) {
2099 2099
             // no error message, no change requested, just nothing to do man.
@@ -2151,7 +2151,7 @@  discard block
 block discarded – undo
2151 2151
                 'pay_status'       => $payment->STS_ID(),
2152 2152
                 'PAY_ID'           => $payment->ID(),
2153 2153
                 'STS_ID'           => $payment->STS_ID(),
2154
-                'status'           => self::$_pay_status[ $payment->STS_ID() ],
2154
+                'status'           => self::$_pay_status[$payment->STS_ID()],
2155 2155
                 'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2156 2156
                 'method'           => strtoupper($payment->source()),
2157 2157
                 'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
@@ -2273,11 +2273,11 @@  discard block
 block discarded – undo
2273 2273
     {
2274 2274
         $registration_payment_data = array();
2275 2275
         // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2276
-        if (! empty($REG_IDs)) {
2276
+        if ( ! empty($REG_IDs)) {
2277 2277
             $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2278 2278
             foreach ($registrations as $registration) {
2279 2279
                 if ($registration instanceof EE_Registration) {
2280
-                    $registration_payment_data[ $registration->ID() ] = array(
2280
+                    $registration_payment_data[$registration->ID()] = array(
2281 2281
                         'paid'  => $registration->pretty_paid(),
2282 2282
                         'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2283 2283
                     );
@@ -2389,8 +2389,8 @@  discard block
 block discarded – undo
2389 2389
             : date('m/d/Y');
2390 2390
 
2391 2391
         // make sure our timestamps start and end right at the boundaries for each day
2392
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2393
-        $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2392
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2393
+        $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2394 2394
 
2395 2395
 
2396 2396
         // convert to timestamps
@@ -2449,7 +2449,7 @@  discard block
 block discarded – undo
2449 2449
         }
2450 2450
 
2451 2451
         if (isset($this->_req_data['s'])) {
2452
-            $search_string = '%' . $this->_req_data['s'] . '%';
2452
+            $search_string = '%'.$this->_req_data['s'].'%';
2453 2453
             $_where['OR'] = array(
2454 2454
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2455 2455
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
@@ -2476,11 +2476,11 @@  discard block
 block discarded – undo
2476 2476
         }
2477 2477
 
2478 2478
         // failed transactions
2479
-        $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2479
+        $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2480 2480
                   || ($count && $view === 'failed');
2481
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2481
+        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2482 2482
                      || ($count && $view === 'abandoned');
2483
-        $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2483
+        $incomplete = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2484 2484
                       || ($count && $view === 'incomplete');
2485 2485
 
2486 2486
         if ($failed) {
Please login to merge, or discard this patch.
Indentation   +2499 added lines, -2499 removed lines patch added patch discarded remove patch
@@ -14,2503 +14,2503 @@
 block discarded – undo
14 14
 class Transactions_Admin_Page extends EE_Admin_Page
15 15
 {
16 16
 
17
-    /**
18
-     * @var EE_Transaction
19
-     */
20
-    private $_transaction;
21
-
22
-    /**
23
-     * @var EE_Session
24
-     */
25
-    private $_session;
26
-
27
-    /**
28
-     * @var array $_txn_status
29
-     */
30
-    private static $_txn_status;
31
-
32
-    /**
33
-     * @var array $_pay_status
34
-     */
35
-    private static $_pay_status;
36
-
37
-    /**
38
-     * @var array $_existing_reg_payment_REG_IDs
39
-     */
40
-    protected $_existing_reg_payment_REG_IDs = null;
41
-
42
-
43
-    /**
44
-     * @Constructor
45
-     * @access public
46
-     * @param bool $routing
47
-     * @throws EE_Error
48
-     * @throws InvalidArgumentException
49
-     * @throws ReflectionException
50
-     * @throws InvalidDataTypeException
51
-     * @throws InvalidInterfaceException
52
-     */
53
-    public function __construct($routing = true)
54
-    {
55
-        parent::__construct($routing);
56
-    }
57
-
58
-
59
-    /**
60
-     *    _init_page_props
61
-     *
62
-     * @return void
63
-     */
64
-    protected function _init_page_props()
65
-    {
66
-        $this->page_slug = TXN_PG_SLUG;
67
-        $this->page_label = esc_html__('Transactions', 'event_espresso');
68
-        $this->_admin_base_url = TXN_ADMIN_URL;
69
-        $this->_admin_base_path = TXN_ADMIN;
70
-    }
71
-
72
-
73
-    /**
74
-     *    _ajax_hooks
75
-     *
76
-     * @return void
77
-     */
78
-    protected function _ajax_hooks()
79
-    {
80
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
81
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
82
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
83
-    }
84
-
85
-
86
-    /**
87
-     *    _define_page_props
88
-     *
89
-     * @return void
90
-     */
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = $this->page_label;
94
-        $this->_labels = array(
95
-            'buttons' => array(
96
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
97
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
98
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
99
-            ),
100
-        );
101
-    }
102
-
103
-
104
-    /**
105
-     *        grab url requests and route them
106
-     *
107
-     * @access private
108
-     * @return void
109
-     * @throws EE_Error
110
-     * @throws InvalidArgumentException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    public function _set_page_routes()
115
-    {
116
-
117
-        $this->_set_transaction_status_array();
118
-
119
-        $txn_id = ! empty($this->_req_data['TXN_ID'])
120
-                  && ! is_array($this->_req_data['TXN_ID'])
121
-            ? $this->_req_data['TXN_ID']
122
-            : 0;
123
-
124
-        $this->_page_routes = array(
125
-
126
-            'default' => array(
127
-                'func'       => '_transactions_overview_list_table',
128
-                'capability' => 'ee_read_transactions',
129
-            ),
130
-
131
-            'view_transaction' => array(
132
-                'func'       => '_transaction_details',
133
-                'capability' => 'ee_read_transaction',
134
-                'obj_id'     => $txn_id,
135
-            ),
136
-
137
-            'send_payment_reminder' => array(
138
-                'func'       => '_send_payment_reminder',
139
-                'noheader'   => true,
140
-                'capability' => 'ee_send_message',
141
-            ),
142
-
143
-            'espresso_apply_payment' => array(
144
-                'func'       => 'apply_payments_or_refunds',
145
-                'noheader'   => true,
146
-                'capability' => 'ee_edit_payments',
147
-            ),
148
-
149
-            'espresso_apply_refund' => array(
150
-                'func'       => 'apply_payments_or_refunds',
151
-                'noheader'   => true,
152
-                'capability' => 'ee_edit_payments',
153
-            ),
154
-
155
-            'espresso_delete_payment' => array(
156
-                'func'       => 'delete_payment',
157
-                'noheader'   => true,
158
-                'capability' => 'ee_delete_payments',
159
-            ),
160
-
161
-        );
162
-    }
163
-
164
-
165
-    protected function _set_page_config()
166
-    {
167
-        $this->_page_config = array(
168
-            'default'          => array(
169
-                'nav'           => array(
170
-                    'label' => esc_html__('Overview', 'event_espresso'),
171
-                    'order' => 10,
172
-                ),
173
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
174
-                'help_tabs'     => array(
175
-                    'transactions_overview_help_tab'                       => array(
176
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
177
-                        'filename' => 'transactions_overview',
178
-                    ),
179
-                    'transactions_overview_table_column_headings_help_tab' => array(
180
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
181
-                        'filename' => 'transactions_overview_table_column_headings',
182
-                    ),
183
-                    'transactions_overview_views_filters_help_tab'         => array(
184
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
185
-                        'filename' => 'transactions_overview_views_filters_search',
186
-                    ),
187
-                ),
188
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
189
-                /**
190
-                 * commented out because currently we are not displaying tips for transaction list table status but this
191
-                 * may change in a later iteration so want to keep the code for then.
192
-                 */
193
-                // 'qtips' => array( 'Transactions_List_Table_Tips' ),
194
-                'require_nonce' => false,
195
-            ),
196
-            'view_transaction' => array(
197
-                'nav'       => array(
198
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
199
-                    'order'      => 5,
200
-                    'url'        => isset($this->_req_data['TXN_ID'])
201
-                        ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
202
-                        : $this->_admin_base_url,
203
-                    'persistent' => false,
204
-                ),
205
-                'help_tabs' => array(
206
-                    'transactions_view_transaction_help_tab'                                              => array(
207
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
208
-                        'filename' => 'transactions_view_transaction',
209
-                    ),
210
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
213
-                    ),
214
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
-                        'filename' => 'transactions_view_transaction_attendees_registered',
217
-                    ),
218
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
221
-                    ),
222
-                ),
223
-                'qtips'     => array('Transaction_Details_Tips'),
224
-                'help_tour' => array('Transaction_Details_Help_Tour'),
225
-                'metaboxes' => array('_transaction_details_metaboxes'),
226
-
227
-                'require_nonce' => false,
228
-            ),
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * The below methods aren't used by this class currently
235
-     */
236
-    protected function _add_screen_options()
237
-    {
238
-        // noop
239
-    }
240
-
241
-    protected function _add_feature_pointers()
242
-    {
243
-        // noop
244
-    }
245
-
246
-    public function admin_init()
247
-    {
248
-        // IF a registration was JUST added via the admin...
249
-        if (isset(
250
-            $this->_req_data['redirect_from'],
251
-            $this->_req_data['EVT_ID'],
252
-            $this->_req_data['event_name']
253
-        )) {
254
-            // then set a cookie so that we can block any attempts to use
255
-            // the back button as a way to enter another registration.
256
-            setcookie(
257
-                'ee_registration_added',
258
-                $this->_req_data['EVT_ID'],
259
-                time() + WEEK_IN_SECONDS,
260
-                '/'
261
-            );
262
-            // and update the global
263
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
-        }
265
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
-            'event_espresso'
268
-        );
269
-        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
270
-            'An error occurred! Please refresh the page and try again.',
271
-            'event_espresso'
272
-        );
273
-        EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status;
274
-        EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status;
275
-        EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso');
276
-        EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__(
277
-            'This transaction has been overpaid ! Payments Total',
278
-            'event_espresso'
279
-        );
280
-    }
281
-
282
-    public function admin_notices()
283
-    {
284
-        // noop
285
-    }
286
-
287
-    public function admin_footer_scripts()
288
-    {
289
-        // noop
290
-    }
291
-
292
-
293
-    /**
294
-     * _set_transaction_status_array
295
-     * sets list of transaction statuses
296
-     *
297
-     * @access private
298
-     * @return void
299
-     * @throws EE_Error
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     */
304
-    private function _set_transaction_status_array()
305
-    {
306
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
-    }
308
-
309
-
310
-    /**
311
-     * get_transaction_status_array
312
-     * return the transaction status array for wp_list_table
313
-     *
314
-     * @access public
315
-     * @return array
316
-     */
317
-    public function get_transaction_status_array()
318
-    {
319
-        return self::$_txn_status;
320
-    }
321
-
322
-
323
-    /**
324
-     *    get list of payment statuses
325
-     *
326
-     * @access private
327
-     * @return void
328
-     * @throws EE_Error
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    private function _get_payment_status_array()
334
-    {
335
-        self::$_pay_status = EEM_Payment::instance()->status_array(true);
336
-        $this->_template_args['payment_status'] = self::$_pay_status;
337
-    }
338
-
339
-
340
-    /**
341
-     *    _add_screen_options_default
342
-     *
343
-     * @access protected
344
-     * @return void
345
-     * @throws InvalidArgumentException
346
-     * @throws InvalidDataTypeException
347
-     * @throws InvalidInterfaceException
348
-     */
349
-    protected function _add_screen_options_default()
350
-    {
351
-        $this->_per_page_screen_option();
352
-    }
353
-
354
-
355
-    /**
356
-     * load_scripts_styles
357
-     *
358
-     * @access public
359
-     * @return void
360
-     */
361
-    public function load_scripts_styles()
362
-    {
363
-        // enqueue style
364
-        wp_register_style(
365
-            'espresso_txn',
366
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
367
-            array(),
368
-            EVENT_ESPRESSO_VERSION
369
-        );
370
-        wp_enqueue_style('espresso_txn');
371
-        // scripts
372
-        wp_register_script(
373
-            'espresso_txn',
374
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
375
-            array(
376
-                'ee_admin_js',
377
-                'ee-datepicker',
378
-                'jquery-ui-datepicker',
379
-                'jquery-ui-draggable',
380
-                'ee-dialog',
381
-                'ee-accounting',
382
-                'ee-serialize-full-array',
383
-            ),
384
-            EVENT_ESPRESSO_VERSION,
385
-            true
386
-        );
387
-        wp_enqueue_script('espresso_txn');
388
-    }
389
-
390
-
391
-    /**
392
-     *    load_scripts_styles_view_transaction
393
-     *
394
-     * @access public
395
-     * @return void
396
-     */
397
-    public function load_scripts_styles_view_transaction()
398
-    {
399
-        // styles
400
-        wp_enqueue_style('espresso-ui-theme');
401
-    }
402
-
403
-
404
-    /**
405
-     *    load_scripts_styles_default
406
-     *
407
-     * @access public
408
-     * @return void
409
-     */
410
-    public function load_scripts_styles_default()
411
-    {
412
-        // styles
413
-        wp_enqueue_style('espresso-ui-theme');
414
-    }
415
-
416
-
417
-    /**
418
-     *    _set_list_table_views_default
419
-     *
420
-     * @access protected
421
-     * @return void
422
-     */
423
-    protected function _set_list_table_views_default()
424
-    {
425
-        $this->_views = array(
426
-            'all'       => array(
427
-                'slug'  => 'all',
428
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
429
-                'count' => 0,
430
-            ),
431
-            'abandoned' => array(
432
-                'slug'  => 'abandoned',
433
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
434
-                'count' => 0,
435
-            ),
436
-            'incomplete' => array(
437
-                'slug'  => 'incomplete',
438
-                'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
439
-                'count' => 0,
440
-            )
441
-        );
442
-        if (/**
443
-             * Filters whether a link to the "Failed Transactions" list table
444
-             * appears on the Transactions Admin Page list table.
445
-             * List display can be turned back on via the following:
446
-             * add_filter(
447
-             *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
448
-             *     '__return_true'
449
-             * );
450
-             *
451
-             * @since 4.9.70.p
452
-             * @param boolean                 $display_failed_txns_list
453
-             * @param Transactions_Admin_Page $this
454
-             */
455
-            apply_filters(
456
-                'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
457
-                false,
458
-                $this
459
-            )
460
-        ) {
461
-            $this->_views['failed'] = array(
462
-                'slug'  => 'failed',
463
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
464
-                'count' => 0,
465
-            );
466
-        }
467
-    }
468
-
469
-
470
-    /**
471
-     * _set_transaction_object
472
-     * This sets the _transaction property for the transaction details screen
473
-     *
474
-     * @access private
475
-     * @return void
476
-     * @throws EE_Error
477
-     * @throws InvalidArgumentException
478
-     * @throws RuntimeException
479
-     * @throws InvalidDataTypeException
480
-     * @throws InvalidInterfaceException
481
-     * @throws ReflectionException
482
-     */
483
-    private function _set_transaction_object()
484
-    {
485
-        if ($this->_transaction instanceof EE_Transaction) {
486
-            return;
487
-        } //get out we've already set the object
488
-
489
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
490
-            ? absint($this->_req_data['TXN_ID'])
491
-            : false;
492
-
493
-        // get transaction object
494
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
495
-        $this->_session = $this->_transaction instanceof EE_Transaction
496
-            ? $this->_transaction->get('TXN_session_data')
497
-            : null;
498
-        if ($this->_transaction instanceof EE_Transaction) {
499
-            $this->_transaction->verify_abandoned_transaction_status();
500
-        }
501
-
502
-        if (! $this->_transaction instanceof EE_Transaction) {
503
-            $error_msg = sprintf(
504
-                esc_html__(
505
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
506
-                    'event_espresso'
507
-                ),
508
-                $TXN_ID
509
-            );
510
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
511
-        }
512
-    }
513
-
514
-
515
-    /**
516
-     *    _transaction_legend_items
517
-     *
518
-     * @access protected
519
-     * @return array
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws ReflectionException
523
-     * @throws InvalidDataTypeException
524
-     * @throws InvalidInterfaceException
525
-     */
526
-    protected function _transaction_legend_items()
527
-    {
528
-        EE_Registry::instance()->load_helper('MSG_Template');
529
-        $items = array();
530
-
531
-        if (EE_Registry::instance()->CAP->current_user_can(
532
-            'ee_read_global_messages',
533
-            'view_filtered_messages'
534
-        )) {
535
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
536
-            if (is_array($related_for_icon)
537
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
538
-            ) {
539
-                $items['view_related_messages'] = array(
540
-                    'class' => $related_for_icon['css_class'],
541
-                    'desc'  => $related_for_icon['label'],
542
-                );
543
-            }
544
-        }
545
-
546
-        $items = apply_filters(
547
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
548
-            array_merge(
549
-                $items,
550
-                array(
551
-                    'view_details'          => array(
552
-                        'class' => 'dashicons dashicons-cart',
553
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
554
-                    ),
555
-                    'view_invoice'          => array(
556
-                        'class' => 'dashicons dashicons-media-spreadsheet',
557
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
558
-                    ),
559
-                    'view_receipt'          => array(
560
-                        'class' => 'dashicons dashicons-media-default',
561
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
562
-                    ),
563
-                    'view_registration'     => array(
564
-                        'class' => 'dashicons dashicons-clipboard',
565
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
566
-                    ),
567
-                    'payment_overview_link' => array(
568
-                        'class' => 'dashicons dashicons-money',
569
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
570
-                    ),
571
-                )
572
-            )
573
-        );
574
-
575
-        if (EE_Registry::instance()->CAP->current_user_can(
576
-            'ee_send_message',
577
-            'espresso_transactions_send_payment_reminder'
578
-        )) {
579
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
580
-                $items['send_payment_reminder'] = array(
581
-                    'class' => 'dashicons dashicons-email-alt',
582
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
583
-                );
584
-            } else {
585
-                $items['blank*'] = array(
586
-                    'class' => '',
587
-                    'desc'  => '',
588
-                );
589
-            }
590
-        } else {
591
-            $items['blank*'] = array(
592
-                'class' => '',
593
-                'desc'  => '',
594
-            );
595
-        }
596
-        $more_items = apply_filters(
597
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
598
-            array(
599
-                'overpaid'   => array(
600
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
601
-                    'desc'  => EEH_Template::pretty_status(
602
-                        EEM_Transaction::overpaid_status_code,
603
-                        false,
604
-                        'sentence'
605
-                    ),
606
-                ),
607
-                'complete'   => array(
608
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
609
-                    'desc'  => EEH_Template::pretty_status(
610
-                        EEM_Transaction::complete_status_code,
611
-                        false,
612
-                        'sentence'
613
-                    ),
614
-                ),
615
-                'incomplete' => array(
616
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
617
-                    'desc'  => EEH_Template::pretty_status(
618
-                        EEM_Transaction::incomplete_status_code,
619
-                        false,
620
-                        'sentence'
621
-                    ),
622
-                ),
623
-                'abandoned'  => array(
624
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
625
-                    'desc'  => EEH_Template::pretty_status(
626
-                        EEM_Transaction::abandoned_status_code,
627
-                        false,
628
-                        'sentence'
629
-                    ),
630
-                ),
631
-                'failed'     => array(
632
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
633
-                    'desc'  => EEH_Template::pretty_status(
634
-                        EEM_Transaction::failed_status_code,
635
-                        false,
636
-                        'sentence'
637
-                    ),
638
-                ),
639
-            )
640
-        );
641
-
642
-        return array_merge($items, $more_items);
643
-    }
644
-
645
-
646
-    /**
647
-     *    _transactions_overview_list_table
648
-     *
649
-     * @access protected
650
-     * @return void
651
-     * @throws DomainException
652
-     * @throws EE_Error
653
-     * @throws InvalidArgumentException
654
-     * @throws InvalidDataTypeException
655
-     * @throws InvalidInterfaceException
656
-     * @throws ReflectionException
657
-     */
658
-    protected function _transactions_overview_list_table()
659
-    {
660
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
661
-        $event = isset($this->_req_data['EVT_ID'])
662
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
663
-            : null;
664
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
665
-            ? sprintf(
666
-                esc_html__(
667
-                    '%sViewing Transactions for the Event: %s%s',
668
-                    'event_espresso'
669
-                ),
670
-                '<h3>',
671
-                '<a href="'
672
-                . EE_Admin_Page::add_query_args_and_nonce(
673
-                    array('action' => 'edit', 'post' => $event->ID()),
674
-                    EVENTS_ADMIN_URL
675
-                )
676
-                . '" title="'
677
-                . esc_attr__(
678
-                    'Click to Edit event',
679
-                    'event_espresso'
680
-                )
681
-                . '">' . $event->get('EVT_name') . '</a>',
682
-                '</h3>'
683
-            )
684
-            : '';
685
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
686
-        $this->display_admin_list_table_page_with_no_sidebar();
687
-    }
688
-
689
-
690
-    /**
691
-     *    _transaction_details
692
-     * generates HTML for the View Transaction Details Admin page
693
-     *
694
-     * @access protected
695
-     * @return void
696
-     * @throws DomainException
697
-     * @throws EE_Error
698
-     * @throws InvalidArgumentException
699
-     * @throws InvalidDataTypeException
700
-     * @throws InvalidInterfaceException
701
-     * @throws RuntimeException
702
-     * @throws ReflectionException
703
-     */
704
-    protected function _transaction_details()
705
-    {
706
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
707
-
708
-        $this->_set_transaction_status_array();
709
-
710
-        $this->_template_args = array();
711
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
712
-
713
-        $this->_set_transaction_object();
714
-
715
-        if (! $this->_transaction instanceof EE_Transaction) {
716
-            return;
717
-        }
718
-        $primary_registration = $this->_transaction->primary_registration();
719
-        $attendee = $primary_registration instanceof EE_Registration
720
-            ? $primary_registration->attendee()
721
-            : null;
722
-
723
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
724
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
725
-
726
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
727
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
728
-
729
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ];
730
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
731
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
732
-
733
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
734
-        $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
735
-
736
-        $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
737
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
738
-            $amount_due,
739
-            true
740
-        );
741
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
742
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
743
-                                                  . $this->_template_args['amount_due'];
744
-        } else {
745
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
746
-        }
747
-        $this->_template_args['amount_due_class'] = '';
748
-
749
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
750
-            // paid in full
751
-            $this->_template_args['amount_due'] = false;
752
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
753
-            // overpaid
754
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
755
-        } elseif ($this->_transaction->get('TXN_total') > 0
756
-                  && $this->_transaction->get('TXN_paid') > 0
757
-        ) {
758
-            // monies owing
759
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
760
-        } elseif ($this->_transaction->get('TXN_total') > 0
761
-                  && $this->_transaction->get('TXN_paid') == 0
762
-        ) {
763
-            // no payments made yet
764
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
765
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
766
-            // free event
767
-            $this->_template_args['amount_due'] = false;
768
-        }
769
-
770
-        $payment_method = $this->_transaction->payment_method();
771
-
772
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
773
-            ? $payment_method->admin_name()
774
-            : esc_html__('Unknown', 'event_espresso');
775
-
776
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
777
-        // link back to overview
778
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
779
-            ? $_SERVER['HTTP_REFERER']
780
-            : TXN_ADMIN_URL;
781
-
782
-
783
-        // next link
784
-        $next_txn = $this->_transaction->next(
785
-            null,
786
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
787
-            'TXN_ID'
788
-        );
789
-        $this->_template_args['next_transaction'] = $next_txn
790
-            ? $this->_next_link(
791
-                EE_Admin_Page::add_query_args_and_nonce(
792
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
793
-                    TXN_ADMIN_URL
794
-                ),
795
-                'dashicons dashicons-arrow-right ee-icon-size-22'
796
-            )
797
-            : '';
798
-        // previous link
799
-        $previous_txn = $this->_transaction->previous(
800
-            null,
801
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
802
-            'TXN_ID'
803
-        );
804
-        $this->_template_args['previous_transaction'] = $previous_txn
805
-            ? $this->_previous_link(
806
-                EE_Admin_Page::add_query_args_and_nonce(
807
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
808
-                    TXN_ADMIN_URL
809
-                ),
810
-                'dashicons dashicons-arrow-left ee-icon-size-22'
811
-            )
812
-            : '';
813
-
814
-        // were we just redirected here after adding a new registration ???
815
-        if (isset(
816
-            $this->_req_data['redirect_from'],
817
-            $this->_req_data['EVT_ID'],
818
-            $this->_req_data['event_name']
819
-        )) {
820
-            if (EE_Registry::instance()->CAP->current_user_can(
821
-                'ee_edit_registrations',
822
-                'espresso_registrations_new_registration',
823
-                $this->_req_data['EVT_ID']
824
-            )) {
825
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
826
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
827
-                    array(
828
-                        'page'     => 'espresso_registrations',
829
-                        'action'   => 'new_registration',
830
-                        'return'   => 'default',
831
-                        'TXN_ID'   => $this->_transaction->ID(),
832
-                        'event_id' => $this->_req_data['EVT_ID'],
833
-                    ),
834
-                    REG_ADMIN_URL
835
-                );
836
-                $this->_admin_page_title .= '">';
837
-
838
-                $this->_admin_page_title .= sprintf(
839
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
840
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
841
-                );
842
-                $this->_admin_page_title .= '</a>';
843
-            }
844
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
845
-        }
846
-        // grab messages at the last second
847
-        $this->_template_args['notices'] = EE_Error::get_notices();
848
-        // path to template
849
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
850
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
851
-            $template_path,
852
-            $this->_template_args,
853
-            true
854
-        );
855
-
856
-        // the details template wrapper
857
-        $this->display_admin_page_with_sidebar();
858
-    }
859
-
860
-
861
-    /**
862
-     *        _transaction_details_metaboxes
863
-     *
864
-     * @access protected
865
-     * @return void
866
-     * @throws EE_Error
867
-     * @throws InvalidArgumentException
868
-     * @throws InvalidDataTypeException
869
-     * @throws InvalidInterfaceException
870
-     * @throws RuntimeException
871
-     * @throws ReflectionException
872
-     */
873
-    protected function _transaction_details_metaboxes()
874
-    {
875
-
876
-        $this->_set_transaction_object();
877
-
878
-        if (! $this->_transaction instanceof EE_Transaction) {
879
-            return;
880
-        }
881
-        add_meta_box(
882
-            'edit-txn-details-mbox',
883
-            esc_html__('Transaction Details', 'event_espresso'),
884
-            array($this, 'txn_details_meta_box'),
885
-            $this->_wp_page_slug,
886
-            'normal',
887
-            'high'
888
-        );
889
-        add_meta_box(
890
-            'edit-txn-attendees-mbox',
891
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
892
-            array($this, 'txn_attendees_meta_box'),
893
-            $this->_wp_page_slug,
894
-            'normal',
895
-            'high',
896
-            array('TXN_ID' => $this->_transaction->ID())
897
-        );
898
-        add_meta_box(
899
-            'edit-txn-registrant-mbox',
900
-            esc_html__('Primary Contact', 'event_espresso'),
901
-            array($this, 'txn_registrant_side_meta_box'),
902
-            $this->_wp_page_slug,
903
-            'side',
904
-            'high'
905
-        );
906
-        add_meta_box(
907
-            'edit-txn-billing-info-mbox',
908
-            esc_html__('Billing Information', 'event_espresso'),
909
-            array($this, 'txn_billing_info_side_meta_box'),
910
-            $this->_wp_page_slug,
911
-            'side',
912
-            'high'
913
-        );
914
-    }
915
-
916
-
917
-    /**
918
-     * Callback for transaction actions metabox.
919
-     *
920
-     * @param EE_Transaction|null $transaction
921
-     * @throws DomainException
922
-     * @throws EE_Error
923
-     * @throws InvalidArgumentException
924
-     * @throws InvalidDataTypeException
925
-     * @throws InvalidInterfaceException
926
-     * @throws ReflectionException
927
-     * @throws RuntimeException
928
-     */
929
-    public function getActionButtons(EE_Transaction $transaction = null)
930
-    {
931
-        $content = '';
932
-        $actions = array();
933
-        if (! $transaction instanceof EE_Transaction) {
934
-            return $content;
935
-        }
936
-        /** @var EE_Registration $primary_registration */
937
-        $primary_registration = $transaction->primary_registration();
938
-        $attendee = $primary_registration instanceof EE_Registration
939
-            ? $primary_registration->attendee()
940
-            : null;
941
-
942
-        if ($attendee instanceof EE_Attendee
943
-            && EE_Registry::instance()->CAP->current_user_can(
944
-                'ee_send_message',
945
-                'espresso_transactions_send_payment_reminder'
946
-            )
947
-        ) {
948
-            $actions['payment_reminder'] =
949
-                EEH_MSG_Template::is_mt_active('payment_reminder')
950
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
951
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
952
-                    ? EEH_Template::get_button_or_link(
953
-                        EE_Admin_Page::add_query_args_and_nonce(
954
-                            array(
955
-                                'action'      => 'send_payment_reminder',
956
-                                'TXN_ID'      => $this->_transaction->ID(),
957
-                                'redirect_to' => 'view_transaction',
958
-                            ),
959
-                            TXN_ADMIN_URL
960
-                        ),
961
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
962
-                        'button secondary-button',
963
-                        'dashicons dashicons-email-alt'
964
-                    )
965
-                    : '';
966
-        }
967
-
968
-        if ($primary_registration instanceof EE_Registration
969
-            && EEH_MSG_Template::is_mt_active('receipt')
970
-        ) {
971
-            $actions['receipt'] = EEH_Template::get_button_or_link(
972
-                $primary_registration->receipt_url(),
973
-                esc_html__('View Receipt', 'event_espresso'),
974
-                'button secondary-button',
975
-                'dashicons dashicons-media-default'
976
-            );
977
-        }
978
-
979
-        if ($primary_registration instanceof EE_Registration
980
-            && EEH_MSG_Template::is_mt_active('invoice')
981
-        ) {
982
-            $actions['invoice'] = EEH_Template::get_button_or_link(
983
-                $primary_registration->invoice_url(),
984
-                esc_html__('View Invoice', 'event_espresso'),
985
-                'button secondary-button',
986
-                'dashicons dashicons-media-spreadsheet'
987
-            );
988
-        }
989
-        $actions = array_filter(
990
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
991
-        );
992
-        if ($actions) {
993
-            $content = '<ul>';
994
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
995
-            $content .= '</uL>';
996
-        }
997
-        return $content;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * txn_details_meta_box
1003
-     * generates HTML for the Transaction main meta box
1004
-     *
1005
-     * @return void
1006
-     * @throws DomainException
1007
-     * @throws EE_Error
1008
-     * @throws InvalidArgumentException
1009
-     * @throws InvalidDataTypeException
1010
-     * @throws InvalidInterfaceException
1011
-     * @throws RuntimeException
1012
-     * @throws ReflectionException
1013
-     */
1014
-    public function txn_details_meta_box()
1015
-    {
1016
-        $this->_set_transaction_object();
1017
-        $this->_template_args['TXN_ID'] = $this->_transaction->ID();
1018
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1019
-            ? $this->_transaction->primary_registration()->attendee()
1020
-            : null;
1021
-        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1022
-            'ee_edit_payments',
1023
-            'apply_payment_or_refund_from_registration_details'
1024
-        );
1025
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1026
-            'ee_delete_payments',
1027
-            'delete_payment_from_registration_details'
1028
-        );
1029
-
1030
-        // get line table
1031
-        EEH_Autoloader::register_line_item_display_autoloaders();
1032
-        $Line_Item_Display = new EE_Line_Item_Display(
1033
-            'admin_table',
1034
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1035
-        );
1036
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1037
-            $this->_transaction->total_line_item()
1038
-        );
1039
-        $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')
1040
-                                                               ->get('REG_code');
1041
-
1042
-        // process taxes
1043
-        $taxes = $this->_transaction->get_many_related(
1044
-            'Line_Item',
1045
-            array(array('LIN_type' => EEM_Line_Item::type_tax))
1046
-        );
1047
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1048
-
1049
-        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1050
-            $this->_transaction->get('TXN_total'),
1051
-            false,
1052
-            false
1053
-        );
1054
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1055
-        $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID');
1056
-
1057
-        // process payment details
1058
-        $payments = $this->_transaction->get_many_related('Payment');
1059
-        if (! empty($payments)) {
1060
-            $this->_template_args['payments'] = $payments;
1061
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1062
-        } else {
1063
-            $this->_template_args['payments'] = false;
1064
-            $this->_template_args['existing_reg_payments'] = array();
1065
-        }
1066
-
1067
-        $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1068
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1069
-            array('action' => 'espresso_delete_payment'),
1070
-            TXN_ADMIN_URL
1071
-        );
1072
-
1073
-        if (isset($txn_details['invoice_number'])) {
1074
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1075
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1076
-                'Invoice Number',
1077
-                'event_espresso'
1078
-            );
1079
-        }
1080
-
1081
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1082
-            ->get_first_related('Registration')
1083
-            ->get('REG_session');
1084
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1085
-            'Registration Session',
1086
-            'event_espresso'
1087
-        );
1088
-
1089
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1090
-            ? $this->_session['ip_address']
1091
-            : '';
1092
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1093
-            'Transaction placed from IP',
1094
-            'event_espresso'
1095
-        );
1096
-
1097
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1098
-            ? $this->_session['user_agent']
1099
-            : '';
1100
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1101
-            'Registrant User Agent',
1102
-            'event_espresso'
1103
-        );
1104
-
1105
-        $reg_steps = '<ul>';
1106
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1107
-            if ($reg_step_status === true) {
1108
-                $reg_steps .= '<li style="color:#70cc50">'
1109
-                              . sprintf(
1110
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1111
-                                  ucwords(str_replace('_', ' ', $reg_step))
1112
-                              )
1113
-                              . '</li>';
1114
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1115
-                $reg_steps .= '<li style="color:#2EA2CC">'
1116
-                              . sprintf(
1117
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1118
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1119
-                                  date(
1120
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1121
-                                      ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1122
-                                  )
1123
-                              )
1124
-                              . '</li>';
1125
-            } else {
1126
-                $reg_steps .= '<li style="color:#E76700">'
1127
-                              . sprintf(
1128
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1129
-                                  ucwords(str_replace('_', ' ', $reg_step))
1130
-                              )
1131
-                              . '</li>';
1132
-            }
1133
-        }
1134
-        $reg_steps .= '</ul>';
1135
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1136
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1137
-            'Registration Step Progress',
1138
-            'event_espresso'
1139
-        );
1140
-
1141
-
1142
-        $this->_get_registrations_to_apply_payment_to();
1143
-        $this->_get_payment_methods($payments);
1144
-        $this->_get_payment_status_array();
1145
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1146
-
1147
-        $this->_template_args['transaction_form_url'] = add_query_arg(
1148
-            array(
1149
-                'action'  => 'edit_transaction',
1150
-                'process' => 'transaction',
1151
-            ),
1152
-            TXN_ADMIN_URL
1153
-        );
1154
-        $this->_template_args['apply_payment_form_url'] = add_query_arg(
1155
-            array(
1156
-                'page'   => 'espresso_transactions',
1157
-                'action' => 'espresso_apply_payment',
1158
-            ),
1159
-            WP_AJAX_URL
1160
-        );
1161
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1162
-            array(
1163
-                'page'   => 'espresso_transactions',
1164
-                'action' => 'espresso_delete_payment',
1165
-            ),
1166
-            WP_AJAX_URL
1167
-        );
1168
-
1169
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1170
-
1171
-        // 'espresso_delete_payment_nonce'
1172
-
1173
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1174
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * _get_registration_payment_IDs
1180
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1181
-     *
1182
-     * @access protected
1183
-     * @param EE_Payment[] $payments
1184
-     * @return array
1185
-     * @throws EE_Error
1186
-     * @throws InvalidArgumentException
1187
-     * @throws InvalidDataTypeException
1188
-     * @throws InvalidInterfaceException
1189
-     * @throws ReflectionException
1190
-     */
1191
-    protected function _get_registration_payment_IDs($payments = array())
1192
-    {
1193
-        $existing_reg_payments = array();
1194
-        // get all reg payments for these payments
1195
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1196
-            array(
1197
-                array(
1198
-                    'PAY_ID' => array(
1199
-                        'IN',
1200
-                        array_keys($payments),
1201
-                    ),
1202
-                ),
1203
-            )
1204
-        );
1205
-        if (! empty($reg_payments)) {
1206
-            foreach ($payments as $payment) {
1207
-                if (! $payment instanceof EE_Payment) {
1208
-                    continue;
1209
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1210
-                    $existing_reg_payments[ $payment->ID() ] = array();
1211
-                }
1212
-                foreach ($reg_payments as $reg_payment) {
1213
-                    if ($reg_payment instanceof EE_Registration_Payment
1214
-                        && $reg_payment->payment_ID() === $payment->ID()
1215
-                    ) {
1216
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1217
-                    }
1218
-                }
1219
-            }
1220
-        }
1221
-
1222
-        return $existing_reg_payments;
1223
-    }
1224
-
1225
-
1226
-    /**
1227
-     * _get_registrations_to_apply_payment_to
1228
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1229
-     * which allows the admin to only apply the payment to the specific registrations
1230
-     *
1231
-     * @access protected
1232
-     * @return void
1233
-     * @throws \EE_Error
1234
-     */
1235
-    protected function _get_registrations_to_apply_payment_to()
1236
-    {
1237
-        // we want any registration with an active status (ie: not deleted or cancelled)
1238
-        $query_params = array(
1239
-            array(
1240
-                'STS_ID' => array(
1241
-                    'IN',
1242
-                    array(
1243
-                        EEM_Registration::status_id_approved,
1244
-                        EEM_Registration::status_id_pending_payment,
1245
-                        EEM_Registration::status_id_not_approved,
1246
-                    ),
1247
-                ),
1248
-            ),
1249
-        );
1250
-        $registrations_to_apply_payment_to = EEH_HTML::br()
1251
-                                             . EEH_HTML::div(
1252
-                                                 '',
1253
-                                                 'txn-admin-apply-payment-to-registrations-dv',
1254
-                                                 '',
1255
-                                                 'clear: both; margin: 1.5em 0 0; display: none;'
1256
-                                             );
1257
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
-            EEH_HTML::tr(
1261
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
-            )
1269
-        );
1270
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
-        // get registrations for TXN
1272
-        $registrations = $this->_transaction->registrations($query_params);
1273
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
-        foreach ($registrations as $registration) {
1275
-            if ($registration instanceof EE_Registration) {
1276
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
1277
-                    ? $registration->attendee()->full_name()
1278
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1279
-                $owing = $registration->final_price() - $registration->paid();
1280
-                $taxable = $registration->ticket()->taxable()
1281
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
-                    : '';
1283
-                $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1284
-                    ? ' checked="checked"'
1285
-                    : '';
1286
-                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1287
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1288
-                    EEH_HTML::td($registration->ID()) .
1289
-                    EEH_HTML::td($attendee_name) .
1290
-                    EEH_HTML::td(
1291
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1292
-                    ) .
1293
-                    EEH_HTML::td($registration->event_name()) .
1294
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1295
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1296
-                    EEH_HTML::td(
1297
-                        '<input type="checkbox" value="' . $registration->ID()
1298
-                        . '" name="txn_admin_payment[registrations]"'
1299
-                        . $checked . $disabled . '>',
1300
-                        '',
1301
-                        'jst-cntr'
1302
-                    ),
1303
-                    'apply-payment-registration-row-' . $registration->ID()
1304
-                );
1305
-            }
1306
-        }
1307
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1308
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1309
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1310
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1311
-            esc_html__(
1312
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1313
-                'event_espresso'
1314
-            ),
1315
-            '',
1316
-            'clear description'
1317
-        );
1318
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1319
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1320
-    }
1321
-
1322
-
1323
-    /**
1324
-     * _get_reg_status_selection
1325
-     *
1326
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1327
-     *         instead of events.
1328
-     * @access protected
1329
-     * @return void
1330
-     * @throws EE_Error
1331
-     */
1332
-    protected function _get_reg_status_selection()
1333
-    {
1334
-        // first get all possible statuses
1335
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1336
-        // let's add a "don't change" option.
1337
-        $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1338
-        $status_array = array_merge($status_array, $statuses);
1339
-        $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1340
-            'txn_reg_status_change[reg_status]',
1341
-            $status_array,
1342
-            'NAN',
1343
-            'id="txn-admin-payment-reg-status-inp"',
1344
-            'txn-reg-status-change-reg-status'
1345
-        );
1346
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1347
-            'delete_txn_reg_status_change[reg_status]',
1348
-            $status_array,
1349
-            'NAN',
1350
-            'delete-txn-admin-payment-reg-status-inp',
1351
-            'delete-txn-reg-status-change-reg-status'
1352
-        );
1353
-    }
1354
-
1355
-
1356
-    /**
1357
-     *    _get_payment_methods
1358
-     * Gets all the payment methods available generally, or the ones that are already
1359
-     * selected on these payments (in case their payment methods are no longer active).
1360
-     * Has the side-effect of updating the template args' payment_methods item
1361
-     *
1362
-     * @access private
1363
-     * @param EE_Payment[] to show on this page
1364
-     * @return void
1365
-     * @throws EE_Error
1366
-     * @throws InvalidArgumentException
1367
-     * @throws InvalidDataTypeException
1368
-     * @throws InvalidInterfaceException
1369
-     * @throws ReflectionException
1370
-     */
1371
-    private function _get_payment_methods($payments = array())
1372
-    {
1373
-        $payment_methods_of_payments = array();
1374
-        foreach ($payments as $payment) {
1375
-            if ($payment instanceof EE_Payment) {
1376
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1377
-            }
1378
-        }
1379
-        if ($payment_methods_of_payments) {
1380
-            $query_args = array(
1381
-                array(
1382
-                    'OR*payment_method_for_payment' => array(
1383
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1384
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1385
-                    ),
1386
-                ),
1387
-            );
1388
-        } else {
1389
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1390
-        }
1391
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1392
-    }
1393
-
1394
-
1395
-    /**
1396
-     * txn_attendees_meta_box
1397
-     *    generates HTML for the Attendees Transaction main meta box
1398
-     *
1399
-     * @access public
1400
-     * @param WP_Post $post
1401
-     * @param array   $metabox
1402
-     * @return void
1403
-     * @throws DomainException
1404
-     * @throws EE_Error
1405
-     */
1406
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1407
-    {
1408
-
1409
-        /** @noinspection NonSecureExtractUsageInspection */
1410
-        extract($metabox['args']);
1411
-        $this->_template_args['post'] = $post;
1412
-        $this->_template_args['event_attendees'] = array();
1413
-        // process items in cart
1414
-        $line_items = $this->_transaction->get_many_related(
1415
-            'Line_Item',
1416
-            array(array('LIN_type' => 'line-item'))
1417
-        );
1418
-        if (! empty($line_items)) {
1419
-            foreach ($line_items as $item) {
1420
-                if ($item instanceof EE_Line_Item) {
1421
-                    switch ($item->OBJ_type()) {
1422
-                        case 'Event':
1423
-                            break;
1424
-                        case 'Ticket':
1425
-                            $ticket = $item->ticket();
1426
-                            // right now we're only handling tickets here.
1427
-                            // Cause its expected that only tickets will have attendees right?
1428
-                            if (! $ticket instanceof EE_Ticket) {
1429
-                                continue;
1430
-                            }
1431
-                            try {
1432
-                                $event_name = $ticket->get_event_name();
1433
-                            } catch (Exception $e) {
1434
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1435
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1436
-                            }
1437
-                            $event_name .= ' - ' . $item->get('LIN_name');
1438
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1439
-                            // now get all of the registrations for this transaction that use this ticket
1440
-                            $registrations = $ticket->get_many_related(
1441
-                                'Registration',
1442
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1443
-                            );
1444
-                            foreach ($registrations as $registration) {
1445
-                                if (! $registration instanceof EE_Registration) {
1446
-                                    continue;
1447
-                                }
1448
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1449
-                                    = $registration->status_ID();
1450
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1451
-                                    = $registration->count();
1452
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1453
-                                    = $event_name;
1454
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1455
-                                    = $ticket_price;
1456
-                                // attendee info
1457
-                                $attendee = $registration->get_first_related('Attendee');
1458
-                                if ($attendee instanceof EE_Attendee) {
1459
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1460
-                                        = $attendee->ID();
1461
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1462
-                                        = $attendee->full_name();
1463
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1464
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1465
-                                          . esc_html__(
1466
-                                              ' Event',
1467
-                                              'event_espresso'
1468
-                                          )
1469
-                                          . '">' . $attendee->email() . '</a>';
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1471
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1472
-                                } else {
1473
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1474
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1475
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1476
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1477
-                                }
1478
-                            }
1479
-                            break;
1480
-                    }
1481
-                }
1482
-            }
1483
-
1484
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1485
-                array(
1486
-                    'action'  => 'edit_transaction',
1487
-                    'process' => 'attendees',
1488
-                ),
1489
-                TXN_ADMIN_URL
1490
-            );
1491
-            echo EEH_Template::display_template(
1492
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1493
-                $this->_template_args,
1494
-                true
1495
-            );
1496
-        } else {
1497
-            echo sprintf(
1498
-                esc_html__(
1499
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1500
-                    'event_espresso'
1501
-                ),
1502
-                '<p class="important-notice">',
1503
-                '</p>'
1504
-            );
1505
-        }
1506
-    }
1507
-
1508
-
1509
-    /**
1510
-     * txn_registrant_side_meta_box
1511
-     * generates HTML for the Edit Transaction side meta box
1512
-     *
1513
-     * @access public
1514
-     * @return void
1515
-     * @throws DomainException
1516
-     * @throws EE_Error
1517
-     * @throws InvalidArgumentException
1518
-     * @throws InvalidDataTypeException
1519
-     * @throws InvalidInterfaceException
1520
-     * @throws ReflectionException
1521
-     */
1522
-    public function txn_registrant_side_meta_box()
1523
-    {
1524
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1525
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1526
-            : null;
1527
-        if (! $primary_att instanceof EE_Attendee) {
1528
-            $this->_template_args['no_attendee_message'] = esc_html__(
1529
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1530
-                'event_espresso'
1531
-            );
1532
-            $primary_att = EEM_Attendee::instance()->create_default_object();
1533
-        }
1534
-        $this->_template_args['ATT_ID'] = $primary_att->ID();
1535
-        $this->_template_args['prime_reg_fname'] = $primary_att->fname();
1536
-        $this->_template_args['prime_reg_lname'] = $primary_att->lname();
1537
-        $this->_template_args['prime_reg_email'] = $primary_att->email();
1538
-        $this->_template_args['prime_reg_phone'] = $primary_att->phone();
1539
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1540
-            array(
1541
-                'action' => 'edit_attendee',
1542
-                'post'   => $primary_att->ID(),
1543
-            ),
1544
-            REG_ADMIN_URL
1545
-        );
1546
-        // get formatted address for registrant
1547
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1548
-        echo EEH_Template::display_template(
1549
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1550
-            $this->_template_args,
1551
-            true
1552
-        );
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     * txn_billing_info_side_meta_box
1558
-     *    generates HTML for the Edit Transaction side meta box
1559
-     *
1560
-     * @access public
1561
-     * @return void
1562
-     * @throws DomainException
1563
-     * @throws EE_Error
1564
-     */
1565
-    public function txn_billing_info_side_meta_box()
1566
-    {
1567
-
1568
-        $this->_template_args['billing_form'] = $this->_transaction->billing_info();
1569
-        $this->_template_args['billing_form_url'] = add_query_arg(
1570
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1571
-            TXN_ADMIN_URL
1572
-        );
1573
-
1574
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1575
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1576
-    }
1577
-
1578
-
1579
-    /**
1580
-     * apply_payments_or_refunds
1581
-     *    registers a payment or refund made towards a transaction
1582
-     *
1583
-     * @access public
1584
-     * @return void
1585
-     * @throws EE_Error
1586
-     * @throws InvalidArgumentException
1587
-     * @throws ReflectionException
1588
-     * @throws RuntimeException
1589
-     * @throws InvalidDataTypeException
1590
-     * @throws InvalidInterfaceException
1591
-     */
1592
-    public function apply_payments_or_refunds()
1593
-    {
1594
-        $json_response_data = array('return_data' => false);
1595
-        $valid_data = $this->_validate_payment_request_data();
1596
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1597
-            'ee_edit_payments',
1598
-            'apply_payment_or_refund_from_registration_details'
1599
-        );
1600
-        if (! empty($valid_data) && $has_access) {
1601
-            $PAY_ID = $valid_data['PAY_ID'];
1602
-            // save  the new payment
1603
-            $payment = $this->_create_payment_from_request_data($valid_data);
1604
-            // get the TXN for this payment
1605
-            $transaction = $payment->transaction();
1606
-            // verify transaction
1607
-            if ($transaction instanceof EE_Transaction) {
1608
-                // calculate_total_payments_and_update_status
1609
-                $this->_process_transaction_payments($transaction);
1610
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1611
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1612
-                // apply payment to registrations (if applicable)
1613
-                if (! empty($REG_IDs)) {
1614
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1615
-                    $this->_maybe_send_notifications();
1616
-                    // now process status changes for the same registrations
1617
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1618
-                }
1619
-                $this->_maybe_send_notifications($payment);
1620
-                // prepare to render page
1621
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1622
-                do_action(
1623
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1624
-                    $transaction,
1625
-                    $payment
1626
-                );
1627
-            } else {
1628
-                EE_Error::add_error(
1629
-                    esc_html__(
1630
-                        'A valid Transaction for this payment could not be retrieved.',
1631
-                        'event_espresso'
1632
-                    ),
1633
-                    __FILE__,
1634
-                    __FUNCTION__,
1635
-                    __LINE__
1636
-                );
1637
-            }
1638
-        } else {
1639
-            if ($has_access) {
1640
-                EE_Error::add_error(
1641
-                    esc_html__(
1642
-                        'The payment form data could not be processed. Please try again.',
1643
-                        'event_espresso'
1644
-                    ),
1645
-                    __FILE__,
1646
-                    __FUNCTION__,
1647
-                    __LINE__
1648
-                );
1649
-            } else {
1650
-                EE_Error::add_error(
1651
-                    esc_html__(
1652
-                        'You do not have access to apply payments or refunds to a registration.',
1653
-                        'event_espresso'
1654
-                    ),
1655
-                    __FILE__,
1656
-                    __FUNCTION__,
1657
-                    __LINE__
1658
-                );
1659
-            }
1660
-        }
1661
-        $notices = EE_Error::get_notices(
1662
-            false,
1663
-            false,
1664
-            false
1665
-        );
1666
-        $this->_template_args = array(
1667
-            'data'    => $json_response_data,
1668
-            'error'   => $notices['errors'],
1669
-            'success' => $notices['success'],
1670
-        );
1671
-        $this->_return_json();
1672
-    }
1673
-
1674
-
1675
-    /**
1676
-     * _validate_payment_request_data
1677
-     *
1678
-     * @return array
1679
-     * @throws EE_Error
1680
-     */
1681
-    protected function _validate_payment_request_data()
1682
-    {
1683
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1684
-            return false;
1685
-        }
1686
-        $payment_form = $this->_generate_payment_form_section();
1687
-        try {
1688
-            if ($payment_form->was_submitted()) {
1689
-                $payment_form->receive_form_submission();
1690
-                if (! $payment_form->is_valid()) {
1691
-                    $submission_error_messages = array();
1692
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1693
-                        if ($validation_error instanceof EE_Validation_Error) {
1694
-                            $submission_error_messages[] = sprintf(
1695
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1696
-                                $validation_error->get_form_section()->html_label_text(),
1697
-                                $validation_error->getMessage()
1698
-                            );
1699
-                        }
1700
-                    }
1701
-                    EE_Error::add_error(
1702
-                        implode('<br />', $submission_error_messages),
1703
-                        __FILE__,
1704
-                        __FUNCTION__,
1705
-                        __LINE__
1706
-                    );
1707
-
1708
-                    return array();
1709
-                }
1710
-            }
1711
-        } catch (EE_Error $e) {
1712
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1713
-
1714
-            return array();
1715
-        }
1716
-
1717
-        return $payment_form->valid_data();
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     * _generate_payment_form_section
1723
-     *
1724
-     * @return EE_Form_Section_Proper
1725
-     * @throws EE_Error
1726
-     */
1727
-    protected function _generate_payment_form_section()
1728
-    {
1729
-        return new EE_Form_Section_Proper(
1730
-            array(
1731
-                'name'        => 'txn_admin_payment',
1732
-                'subsections' => array(
1733
-                    'PAY_ID'          => new EE_Text_Input(
1734
-                        array(
1735
-                            'default'               => 0,
1736
-                            'required'              => false,
1737
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1738
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1739
-                        )
1740
-                    ),
1741
-                    'TXN_ID'          => new EE_Text_Input(
1742
-                        array(
1743
-                            'default'               => 0,
1744
-                            'required'              => true,
1745
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1746
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1747
-                        )
1748
-                    ),
1749
-                    'type'            => new EE_Text_Input(
1750
-                        array(
1751
-                            'default'               => 1,
1752
-                            'required'              => true,
1753
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1754
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1755
-                        )
1756
-                    ),
1757
-                    'amount'          => new EE_Text_Input(
1758
-                        array(
1759
-                            'default'               => 0,
1760
-                            'required'              => true,
1761
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1762
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1763
-                        )
1764
-                    ),
1765
-                    'status'          => new EE_Text_Input(
1766
-                        array(
1767
-                            'default'         => EEM_Payment::status_id_approved,
1768
-                            'required'        => true,
1769
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1770
-                        )
1771
-                    ),
1772
-                    'PMD_ID'          => new EE_Text_Input(
1773
-                        array(
1774
-                            'default'               => 2,
1775
-                            'required'              => true,
1776
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1777
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1778
-                        )
1779
-                    ),
1780
-                    'date'            => new EE_Text_Input(
1781
-                        array(
1782
-                            'default'         => time(),
1783
-                            'required'        => true,
1784
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1785
-                        )
1786
-                    ),
1787
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1788
-                        array(
1789
-                            'default'               => '',
1790
-                            'required'              => false,
1791
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1792
-                            'validation_strategies' => array(
1793
-                                new EE_Max_Length_Validation_Strategy(
1794
-                                    esc_html__('Input too long', 'event_espresso'),
1795
-                                    100
1796
-                                ),
1797
-                            ),
1798
-                        )
1799
-                    ),
1800
-                    'po_number'       => new EE_Text_Input(
1801
-                        array(
1802
-                            'default'               => '',
1803
-                            'required'              => false,
1804
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1805
-                            'validation_strategies' => array(
1806
-                                new EE_Max_Length_Validation_Strategy(
1807
-                                    esc_html__('Input too long', 'event_espresso'),
1808
-                                    100
1809
-                                ),
1810
-                            ),
1811
-                        )
1812
-                    ),
1813
-                    'accounting'      => new EE_Text_Input(
1814
-                        array(
1815
-                            'default'               => '',
1816
-                            'required'              => false,
1817
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1818
-                            'validation_strategies' => array(
1819
-                                new EE_Max_Length_Validation_Strategy(
1820
-                                    esc_html__('Input too long', 'event_espresso'),
1821
-                                    100
1822
-                                ),
1823
-                            ),
1824
-                        )
1825
-                    ),
1826
-                ),
1827
-            )
1828
-        );
1829
-    }
1830
-
1831
-
1832
-    /**
1833
-     * _create_payment_from_request_data
1834
-     *
1835
-     * @param array $valid_data
1836
-     * @return EE_Payment
1837
-     * @throws EE_Error
1838
-     */
1839
-    protected function _create_payment_from_request_data($valid_data)
1840
-    {
1841
-        $PAY_ID = $valid_data['PAY_ID'];
1842
-        // get payment amount
1843
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1844
-        // payments have a type value of 1 and refunds have a type value of -1
1845
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1846
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1847
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1848
-        $date = $valid_data['date']
1849
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1850
-            : date('Y-m-d g:i a', current_time('timestamp'));
1851
-        $payment = EE_Payment::new_instance(
1852
-            array(
1853
-                'TXN_ID'              => $valid_data['TXN_ID'],
1854
-                'STS_ID'              => $valid_data['status'],
1855
-                'PAY_timestamp'       => $date,
1856
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1857
-                'PMD_ID'              => $valid_data['PMD_ID'],
1858
-                'PAY_amount'          => $amount,
1859
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1860
-                'PAY_po_number'       => $valid_data['po_number'],
1861
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1862
-                'PAY_details'         => $valid_data,
1863
-                'PAY_ID'              => $PAY_ID,
1864
-            ),
1865
-            '',
1866
-            array('Y-m-d', 'g:i a')
1867
-        );
1868
-
1869
-        if (! $payment->save()) {
1870
-            EE_Error::add_error(
1871
-                sprintf(
1872
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1873
-                    $payment->ID()
1874
-                ),
1875
-                __FILE__,
1876
-                __FUNCTION__,
1877
-                __LINE__
1878
-            );
1879
-        }
1880
-
1881
-        return $payment;
1882
-    }
1883
-
1884
-
1885
-    /**
1886
-     * _process_transaction_payments
1887
-     *
1888
-     * @param \EE_Transaction $transaction
1889
-     * @return void
1890
-     * @throws EE_Error
1891
-     * @throws InvalidArgumentException
1892
-     * @throws ReflectionException
1893
-     * @throws InvalidDataTypeException
1894
-     * @throws InvalidInterfaceException
1895
-     */
1896
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1897
-    {
1898
-        /** @type EE_Transaction_Payments $transaction_payments */
1899
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1900
-        // update the transaction with this payment
1901
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1902
-            EE_Error::add_success(
1903
-                esc_html__(
1904
-                    'The payment has been processed successfully.',
1905
-                    'event_espresso'
1906
-                ),
1907
-                __FILE__,
1908
-                __FUNCTION__,
1909
-                __LINE__
1910
-            );
1911
-        } else {
1912
-            EE_Error::add_error(
1913
-                esc_html__(
1914
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1915
-                    'event_espresso'
1916
-                ),
1917
-                __FILE__,
1918
-                __FUNCTION__,
1919
-                __LINE__
1920
-            );
1921
-        }
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * _get_REG_IDs_to_apply_payment_to
1927
-     * returns a list of registration IDs that the payment will apply to
1928
-     *
1929
-     * @param \EE_Payment $payment
1930
-     * @return array
1931
-     * @throws EE_Error
1932
-     */
1933
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1934
-    {
1935
-        $REG_IDs = array();
1936
-        // grab array of IDs for specific registrations to apply changes to
1937
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1938
-            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1939
-        }
1940
-        // nothing specified ? then get all reg IDs
1941
-        if (empty($REG_IDs)) {
1942
-            $registrations = $payment->transaction()->registrations();
1943
-            $REG_IDs = ! empty($registrations)
1944
-                ? array_keys($registrations)
1945
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1946
-        }
1947
-
1948
-        // ensure that REG_IDs are integers and NOT strings
1949
-        return array_map('intval', $REG_IDs);
1950
-    }
1951
-
1952
-
1953
-    /**
1954
-     * @return array
1955
-     */
1956
-    public function existing_reg_payment_REG_IDs()
1957
-    {
1958
-        return $this->_existing_reg_payment_REG_IDs;
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     * @param array $existing_reg_payment_REG_IDs
1964
-     */
1965
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1966
-    {
1967
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1968
-    }
1969
-
1970
-
1971
-    /**
1972
-     * _get_existing_reg_payment_REG_IDs
1973
-     * returns a list of registration IDs that the payment is currently related to
1974
-     * as recorded in the database
1975
-     *
1976
-     * @param \EE_Payment $payment
1977
-     * @return array
1978
-     * @throws EE_Error
1979
-     */
1980
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1981
-    {
1982
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1983
-            // let's get any existing reg payment records for this payment
1984
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1985
-            // but we only want the REG IDs, so grab the array keys
1986
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1987
-                ? array_keys($existing_reg_payment_REG_IDs)
1988
-                : array();
1989
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1990
-        }
1991
-
1992
-        return $this->existing_reg_payment_REG_IDs();
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * _remove_existing_registration_payments
1998
-     * this calculates the difference between existing relations
1999
-     * to the supplied payment and the new list registration IDs,
2000
-     * removes any related registrations that no longer apply,
2001
-     * and then updates the registration paid fields
2002
-     *
2003
-     * @param \EE_Payment $payment
2004
-     * @param int         $PAY_ID
2005
-     * @return bool;
2006
-     * @throws EE_Error
2007
-     * @throws InvalidArgumentException
2008
-     * @throws ReflectionException
2009
-     * @throws InvalidDataTypeException
2010
-     * @throws InvalidInterfaceException
2011
-     */
2012
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2013
-    {
2014
-        // newly created payments will have nothing recorded for $PAY_ID
2015
-        if ($PAY_ID == 0) {
2016
-            return false;
2017
-        }
2018
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2019
-        if (empty($existing_reg_payment_REG_IDs)) {
2020
-            return false;
2021
-        }
2022
-        /** @type EE_Transaction_Payments $transaction_payments */
2023
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2024
-
2025
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2026
-            $payment,
2027
-            array(
2028
-                array(
2029
-                    'PAY_ID' => $payment->ID(),
2030
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2031
-                ),
2032
-            )
2033
-        );
2034
-    }
2035
-
2036
-
2037
-    /**
2038
-     * _update_registration_payments
2039
-     * this applies the payments to the selected registrations
2040
-     * but only if they have not already been paid for
2041
-     *
2042
-     * @param  EE_Transaction $transaction
2043
-     * @param \EE_Payment     $payment
2044
-     * @param array           $REG_IDs
2045
-     * @return void
2046
-     * @throws EE_Error
2047
-     * @throws InvalidArgumentException
2048
-     * @throws ReflectionException
2049
-     * @throws RuntimeException
2050
-     * @throws InvalidDataTypeException
2051
-     * @throws InvalidInterfaceException
2052
-     */
2053
-    protected function _update_registration_payments(
2054
-        EE_Transaction $transaction,
2055
-        EE_Payment $payment,
2056
-        $REG_IDs = array()
2057
-    ) {
2058
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2059
-        // so let's do that using our set of REG_IDs from the form
2060
-        $registration_query_where_params = array(
2061
-            'REG_ID' => array('IN', $REG_IDs),
2062
-        );
2063
-        // but add in some conditions regarding payment,
2064
-        // so that we don't apply payments to registrations that are free or have already been paid for
2065
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2066
-        if (! $payment->is_a_refund()) {
2067
-            $registration_query_where_params['REG_final_price'] = array('!=', 0);
2068
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2069
-        }
2070
-        $registrations = $transaction->registrations(array($registration_query_where_params));
2071
-        if (! empty($registrations)) {
2072
-            /** @type EE_Payment_Processor $payment_processor */
2073
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2074
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2075
-        }
2076
-    }
2077
-
2078
-
2079
-    /**
2080
-     * _process_registration_status_change
2081
-     * This processes requested registration status changes for all the registrations
2082
-     * on a given transaction and (optionally) sends out notifications for the changes.
2083
-     *
2084
-     * @param  EE_Transaction $transaction
2085
-     * @param array           $REG_IDs
2086
-     * @return bool
2087
-     * @throws EE_Error
2088
-     * @throws InvalidArgumentException
2089
-     * @throws ReflectionException
2090
-     * @throws InvalidDataTypeException
2091
-     * @throws InvalidInterfaceException
2092
-     */
2093
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2094
-    {
2095
-        // first if there is no change in status then we get out.
2096
-        if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2097
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2098
-        ) {
2099
-            // no error message, no change requested, just nothing to do man.
2100
-            return false;
2101
-        }
2102
-        /** @type EE_Transaction_Processor $transaction_processor */
2103
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2104
-
2105
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2106
-        return $transaction_processor->manually_update_registration_statuses(
2107
-            $transaction,
2108
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2109
-            array(array('REG_ID' => array('IN', $REG_IDs)))
2110
-        );
2111
-    }
2112
-
2113
-
2114
-    /**
2115
-     * _build_payment_json_response
2116
-     *
2117
-     * @access public
2118
-     * @param \EE_Payment $payment
2119
-     * @param array       $REG_IDs
2120
-     * @param bool | null $delete_txn_reg_status_change
2121
-     * @return array
2122
-     * @throws EE_Error
2123
-     * @throws InvalidArgumentException
2124
-     * @throws InvalidDataTypeException
2125
-     * @throws InvalidInterfaceException
2126
-     * @throws ReflectionException
2127
-     */
2128
-    protected function _build_payment_json_response(
2129
-        EE_Payment $payment,
2130
-        $REG_IDs = array(),
2131
-        $delete_txn_reg_status_change = null
2132
-    ) {
2133
-        // was the payment deleted ?
2134
-        if (is_bool($delete_txn_reg_status_change)) {
2135
-            return array(
2136
-                'PAY_ID'                       => $payment->ID(),
2137
-                'amount'                       => $payment->amount(),
2138
-                'total_paid'                   => $payment->transaction()->paid(),
2139
-                'txn_status'                   => $payment->transaction()->status_ID(),
2140
-                'pay_status'                   => $payment->STS_ID(),
2141
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2142
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2143
-            );
2144
-        } else {
2145
-            $this->_get_payment_status_array();
2146
-
2147
-            return array(
2148
-                'amount'           => $payment->amount(),
2149
-                'total_paid'       => $payment->transaction()->paid(),
2150
-                'txn_status'       => $payment->transaction()->status_ID(),
2151
-                'pay_status'       => $payment->STS_ID(),
2152
-                'PAY_ID'           => $payment->ID(),
2153
-                'STS_ID'           => $payment->STS_ID(),
2154
-                'status'           => self::$_pay_status[ $payment->STS_ID() ],
2155
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2156
-                'method'           => strtoupper($payment->source()),
2157
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2158
-                'gateway'          => $payment->payment_method()
2159
-                    ? $payment->payment_method()->admin_name()
2160
-                    : esc_html__("Unknown", 'event_espresso'),
2161
-                'gateway_response' => $payment->gateway_response(),
2162
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2163
-                'po_number'        => $payment->po_number(),
2164
-                'extra_accntng'    => $payment->extra_accntng(),
2165
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2166
-            );
2167
-        }
2168
-    }
2169
-
2170
-
2171
-    /**
2172
-     * delete_payment
2173
-     *    delete a payment or refund made towards a transaction
2174
-     *
2175
-     * @access public
2176
-     * @return void
2177
-     * @throws EE_Error
2178
-     * @throws InvalidArgumentException
2179
-     * @throws ReflectionException
2180
-     * @throws InvalidDataTypeException
2181
-     * @throws InvalidInterfaceException
2182
-     */
2183
-    public function delete_payment()
2184
-    {
2185
-        $json_response_data = array('return_data' => false);
2186
-        $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2187
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2188
-            : 0;
2189
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2190
-            'ee_delete_payments',
2191
-            'delete_payment_from_registration_details'
2192
-        );
2193
-        if ($PAY_ID && $can_delete) {
2194
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2195
-                ? $this->_req_data['delete_txn_reg_status_change']
2196
-                : false;
2197
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2198
-            if ($payment instanceof EE_Payment) {
2199
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2200
-                /** @type EE_Transaction_Payments $transaction_payments */
2201
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2202
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2203
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2204
-                        $payment,
2205
-                        $REG_IDs,
2206
-                        $delete_txn_reg_status_change
2207
-                    );
2208
-                    if ($delete_txn_reg_status_change) {
2209
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2210
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2211
-                        // $_REQUEST global because that's how messages will be looking for it.
2212
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2213
-                        $this->_maybe_send_notifications();
2214
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2215
-                    }
2216
-                }
2217
-            } else {
2218
-                EE_Error::add_error(
2219
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2220
-                    __FILE__,
2221
-                    __FUNCTION__,
2222
-                    __LINE__
2223
-                );
2224
-            }
2225
-        } else {
2226
-            if ($can_delete) {
2227
-                EE_Error::add_error(
2228
-                    esc_html__(
2229
-                        'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2230
-                        'event_espresso'
2231
-                    ),
2232
-                    __FILE__,
2233
-                    __FUNCTION__,
2234
-                    __LINE__
2235
-                );
2236
-            } else {
2237
-                EE_Error::add_error(
2238
-                    esc_html__(
2239
-                        'You do not have access to delete a payment.',
2240
-                        'event_espresso'
2241
-                    ),
2242
-                    __FILE__,
2243
-                    __FUNCTION__,
2244
-                    __LINE__
2245
-                );
2246
-            }
2247
-        }
2248
-        $notices = EE_Error::get_notices(false, false, false);
2249
-        $this->_template_args = array(
2250
-            'data'      => $json_response_data,
2251
-            'success'   => $notices['success'],
2252
-            'error'     => $notices['errors'],
2253
-            'attention' => $notices['attention'],
2254
-        );
2255
-        $this->_return_json();
2256
-    }
2257
-
2258
-
2259
-    /**
2260
-     * _registration_payment_data_array
2261
-     * adds info for 'owing' and 'paid' for each registration to the json response
2262
-     *
2263
-     * @access protected
2264
-     * @param array $REG_IDs
2265
-     * @return array
2266
-     * @throws EE_Error
2267
-     * @throws InvalidArgumentException
2268
-     * @throws InvalidDataTypeException
2269
-     * @throws InvalidInterfaceException
2270
-     * @throws ReflectionException
2271
-     */
2272
-    protected function _registration_payment_data_array($REG_IDs)
2273
-    {
2274
-        $registration_payment_data = array();
2275
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2276
-        if (! empty($REG_IDs)) {
2277
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2278
-            foreach ($registrations as $registration) {
2279
-                if ($registration instanceof EE_Registration) {
2280
-                    $registration_payment_data[ $registration->ID() ] = array(
2281
-                        'paid'  => $registration->pretty_paid(),
2282
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2283
-                    );
2284
-                }
2285
-            }
2286
-        }
2287
-
2288
-        return $registration_payment_data;
2289
-    }
2290
-
2291
-
2292
-    /**
2293
-     * _maybe_send_notifications
2294
-     * determines whether or not the admin has indicated that notifications should be sent.
2295
-     * If so, will toggle a filter switch for delivering registration notices.
2296
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2297
-     *
2298
-     * @access protected
2299
-     * @param \EE_Payment | null $payment
2300
-     */
2301
-    protected function _maybe_send_notifications($payment = null)
2302
-    {
2303
-        switch ($payment instanceof EE_Payment) {
2304
-            // payment notifications
2305
-            case true:
2306
-                if (isset(
2307
-                    $this->_req_data['txn_payments'],
2308
-                    $this->_req_data['txn_payments']['send_notifications']
2309
-                )
2310
-                    && filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2311
-                ) {
2312
-                    $this->_process_payment_notification($payment);
2313
-                }
2314
-                break;
2315
-            // registration notifications
2316
-            case false:
2317
-                if (isset(
2318
-                    $this->_req_data['txn_reg_status_change'],
2319
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
2320
-                )
2321
-                    && filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2322
-                ) {
2323
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2324
-                }
2325
-                break;
2326
-        }
2327
-    }
2328
-
2329
-
2330
-    /**
2331
-     * _send_payment_reminder
2332
-     *    generates HTML for the View Transaction Details Admin page
2333
-     *
2334
-     * @access protected
2335
-     * @return void
2336
-     * @throws EE_Error
2337
-     * @throws InvalidArgumentException
2338
-     * @throws InvalidDataTypeException
2339
-     * @throws InvalidInterfaceException
2340
-     */
2341
-    protected function _send_payment_reminder()
2342
-    {
2343
-        $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2344
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2345
-        $query_args = isset($this->_req_data['redirect_to']) ? array(
2346
-            'action' => $this->_req_data['redirect_to'],
2347
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2348
-        ) : array();
2349
-        do_action(
2350
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2351
-            $transaction
2352
-        );
2353
-        $this->_redirect_after_action(
2354
-            false,
2355
-            esc_html__('payment reminder', 'event_espresso'),
2356
-            esc_html__('sent', 'event_espresso'),
2357
-            $query_args,
2358
-            true
2359
-        );
2360
-    }
2361
-
2362
-
2363
-    /**
2364
-     *  get_transactions
2365
-     *    get transactions for given parameters (used by list table)
2366
-     *
2367
-     * @param  int     $perpage how many transactions displayed per page
2368
-     * @param  boolean $count   return the count or objects
2369
-     * @param string   $view
2370
-     * @return mixed int = count || array of transaction objects
2371
-     * @throws EE_Error
2372
-     * @throws InvalidArgumentException
2373
-     * @throws InvalidDataTypeException
2374
-     * @throws InvalidInterfaceException
2375
-     */
2376
-    public function get_transactions($perpage, $count = false, $view = '')
2377
-    {
2378
-
2379
-        $TXN = EEM_Transaction::instance();
2380
-
2381
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2382
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2383
-            : date(
2384
-                'm/d/Y',
2385
-                strtotime('-10 year')
2386
-            );
2387
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
2388
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2389
-            : date('m/d/Y');
2390
-
2391
-        // make sure our timestamps start and end right at the boundaries for each day
2392
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2393
-        $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2394
-
2395
-
2396
-        // convert to timestamps
2397
-        $start_date = strtotime($start_date);
2398
-        $end_date = strtotime($end_date);
2399
-
2400
-        // makes sure start date is the lowest value and vice versa
2401
-        $start_date = min($start_date, $end_date);
2402
-        $end_date = max($start_date, $end_date);
2403
-
2404
-        // convert to correct format for query
2405
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2406
-            'TXN_timestamp',
2407
-            date('Y-m-d H:i:s', $start_date),
2408
-            'Y-m-d H:i:s'
2409
-        );
2410
-        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2411
-            'TXN_timestamp',
2412
-            date('Y-m-d H:i:s', $end_date),
2413
-            'Y-m-d H:i:s'
2414
-        );
2415
-
2416
-
2417
-        // set orderby
2418
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2419
-
2420
-        switch ($this->_req_data['orderby']) {
2421
-            case 'TXN_ID':
2422
-                $orderby = 'TXN_ID';
2423
-                break;
2424
-            case 'ATT_fname':
2425
-                $orderby = 'Registration.Attendee.ATT_fname';
2426
-                break;
2427
-            case 'event_name':
2428
-                $orderby = 'Registration.Event.EVT_name';
2429
-                break;
2430
-            default: // 'TXN_timestamp'
2431
-                $orderby = 'TXN_timestamp';
2432
-        }
2433
-
2434
-        $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2435
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2436
-        $per_page = ! empty($perpage) ? $perpage : 10;
2437
-        $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2438
-
2439
-        $offset = ($current_page - 1) * $per_page;
2440
-        $limit = array($offset, $per_page);
2441
-
2442
-        $_where = array(
2443
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2444
-            'Registration.REG_count' => 1,
2445
-        );
2446
-
2447
-        if (isset($this->_req_data['EVT_ID'])) {
2448
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2449
-        }
2450
-
2451
-        if (isset($this->_req_data['s'])) {
2452
-            $search_string = '%' . $this->_req_data['s'] . '%';
2453
-            $_where['OR'] = array(
2454
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2455
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2456
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2457
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2458
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2459
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2460
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2461
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2462
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2463
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2464
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2465
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2466
-                'Registration.REG_code'               => array('LIKE', $search_string),
2467
-                'Registration.REG_count'              => array('LIKE', $search_string),
2468
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2469
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2470
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2471
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2472
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2473
-                'TXN_session_data'                    => array('LIKE', $search_string),
2474
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2475
-            );
2476
-        }
2477
-
2478
-        // failed transactions
2479
-        $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2480
-                  || ($count && $view === 'failed');
2481
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2482
-                     || ($count && $view === 'abandoned');
2483
-        $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2484
-                      || ($count && $view === 'incomplete');
2485
-
2486
-        if ($failed) {
2487
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2488
-        } elseif ($abandoned) {
2489
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2490
-        } elseif ($incomplete) {
2491
-            $_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2492
-        } else {
2493
-            $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2494
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2495
-        }
2496
-
2497
-        $query_params = apply_filters(
2498
-            'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2499
-            array(
2500
-                $_where,
2501
-                'order_by'                 => array($orderby => $sort),
2502
-                'limit'                    => $limit,
2503
-                'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2504
-            ),
2505
-            $this->_req_data,
2506
-            $view,
2507
-            $count
2508
-        );
2509
-
2510
-        $transactions = $count
2511
-            ? $TXN->count(array($query_params[0]), 'TXN_ID', true)
2512
-            : $TXN->get_all($query_params);
2513
-
2514
-        return $transactions;
2515
-    }
17
+	/**
18
+	 * @var EE_Transaction
19
+	 */
20
+	private $_transaction;
21
+
22
+	/**
23
+	 * @var EE_Session
24
+	 */
25
+	private $_session;
26
+
27
+	/**
28
+	 * @var array $_txn_status
29
+	 */
30
+	private static $_txn_status;
31
+
32
+	/**
33
+	 * @var array $_pay_status
34
+	 */
35
+	private static $_pay_status;
36
+
37
+	/**
38
+	 * @var array $_existing_reg_payment_REG_IDs
39
+	 */
40
+	protected $_existing_reg_payment_REG_IDs = null;
41
+
42
+
43
+	/**
44
+	 * @Constructor
45
+	 * @access public
46
+	 * @param bool $routing
47
+	 * @throws EE_Error
48
+	 * @throws InvalidArgumentException
49
+	 * @throws ReflectionException
50
+	 * @throws InvalidDataTypeException
51
+	 * @throws InvalidInterfaceException
52
+	 */
53
+	public function __construct($routing = true)
54
+	{
55
+		parent::__construct($routing);
56
+	}
57
+
58
+
59
+	/**
60
+	 *    _init_page_props
61
+	 *
62
+	 * @return void
63
+	 */
64
+	protected function _init_page_props()
65
+	{
66
+		$this->page_slug = TXN_PG_SLUG;
67
+		$this->page_label = esc_html__('Transactions', 'event_espresso');
68
+		$this->_admin_base_url = TXN_ADMIN_URL;
69
+		$this->_admin_base_path = TXN_ADMIN;
70
+	}
71
+
72
+
73
+	/**
74
+	 *    _ajax_hooks
75
+	 *
76
+	 * @return void
77
+	 */
78
+	protected function _ajax_hooks()
79
+	{
80
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
81
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
82
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
83
+	}
84
+
85
+
86
+	/**
87
+	 *    _define_page_props
88
+	 *
89
+	 * @return void
90
+	 */
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = $this->page_label;
94
+		$this->_labels = array(
95
+			'buttons' => array(
96
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
97
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
98
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
99
+			),
100
+		);
101
+	}
102
+
103
+
104
+	/**
105
+	 *        grab url requests and route them
106
+	 *
107
+	 * @access private
108
+	 * @return void
109
+	 * @throws EE_Error
110
+	 * @throws InvalidArgumentException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	public function _set_page_routes()
115
+	{
116
+
117
+		$this->_set_transaction_status_array();
118
+
119
+		$txn_id = ! empty($this->_req_data['TXN_ID'])
120
+				  && ! is_array($this->_req_data['TXN_ID'])
121
+			? $this->_req_data['TXN_ID']
122
+			: 0;
123
+
124
+		$this->_page_routes = array(
125
+
126
+			'default' => array(
127
+				'func'       => '_transactions_overview_list_table',
128
+				'capability' => 'ee_read_transactions',
129
+			),
130
+
131
+			'view_transaction' => array(
132
+				'func'       => '_transaction_details',
133
+				'capability' => 'ee_read_transaction',
134
+				'obj_id'     => $txn_id,
135
+			),
136
+
137
+			'send_payment_reminder' => array(
138
+				'func'       => '_send_payment_reminder',
139
+				'noheader'   => true,
140
+				'capability' => 'ee_send_message',
141
+			),
142
+
143
+			'espresso_apply_payment' => array(
144
+				'func'       => 'apply_payments_or_refunds',
145
+				'noheader'   => true,
146
+				'capability' => 'ee_edit_payments',
147
+			),
148
+
149
+			'espresso_apply_refund' => array(
150
+				'func'       => 'apply_payments_or_refunds',
151
+				'noheader'   => true,
152
+				'capability' => 'ee_edit_payments',
153
+			),
154
+
155
+			'espresso_delete_payment' => array(
156
+				'func'       => 'delete_payment',
157
+				'noheader'   => true,
158
+				'capability' => 'ee_delete_payments',
159
+			),
160
+
161
+		);
162
+	}
163
+
164
+
165
+	protected function _set_page_config()
166
+	{
167
+		$this->_page_config = array(
168
+			'default'          => array(
169
+				'nav'           => array(
170
+					'label' => esc_html__('Overview', 'event_espresso'),
171
+					'order' => 10,
172
+				),
173
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
174
+				'help_tabs'     => array(
175
+					'transactions_overview_help_tab'                       => array(
176
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
177
+						'filename' => 'transactions_overview',
178
+					),
179
+					'transactions_overview_table_column_headings_help_tab' => array(
180
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
181
+						'filename' => 'transactions_overview_table_column_headings',
182
+					),
183
+					'transactions_overview_views_filters_help_tab'         => array(
184
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
185
+						'filename' => 'transactions_overview_views_filters_search',
186
+					),
187
+				),
188
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
189
+				/**
190
+				 * commented out because currently we are not displaying tips for transaction list table status but this
191
+				 * may change in a later iteration so want to keep the code for then.
192
+				 */
193
+				// 'qtips' => array( 'Transactions_List_Table_Tips' ),
194
+				'require_nonce' => false,
195
+			),
196
+			'view_transaction' => array(
197
+				'nav'       => array(
198
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
199
+					'order'      => 5,
200
+					'url'        => isset($this->_req_data['TXN_ID'])
201
+						? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
202
+						: $this->_admin_base_url,
203
+					'persistent' => false,
204
+				),
205
+				'help_tabs' => array(
206
+					'transactions_view_transaction_help_tab'                                              => array(
207
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
208
+						'filename' => 'transactions_view_transaction',
209
+					),
210
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
+						'filename' => 'transactions_view_transaction_transaction_details_table',
213
+					),
214
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
+						'filename' => 'transactions_view_transaction_attendees_registered',
217
+					),
218
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
221
+					),
222
+				),
223
+				'qtips'     => array('Transaction_Details_Tips'),
224
+				'help_tour' => array('Transaction_Details_Help_Tour'),
225
+				'metaboxes' => array('_transaction_details_metaboxes'),
226
+
227
+				'require_nonce' => false,
228
+			),
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * The below methods aren't used by this class currently
235
+	 */
236
+	protected function _add_screen_options()
237
+	{
238
+		// noop
239
+	}
240
+
241
+	protected function _add_feature_pointers()
242
+	{
243
+		// noop
244
+	}
245
+
246
+	public function admin_init()
247
+	{
248
+		// IF a registration was JUST added via the admin...
249
+		if (isset(
250
+			$this->_req_data['redirect_from'],
251
+			$this->_req_data['EVT_ID'],
252
+			$this->_req_data['event_name']
253
+		)) {
254
+			// then set a cookie so that we can block any attempts to use
255
+			// the back button as a way to enter another registration.
256
+			setcookie(
257
+				'ee_registration_added',
258
+				$this->_req_data['EVT_ID'],
259
+				time() + WEEK_IN_SECONDS,
260
+				'/'
261
+			);
262
+			// and update the global
263
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
+		}
265
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
+			'event_espresso'
268
+		);
269
+		EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
270
+			'An error occurred! Please refresh the page and try again.',
271
+			'event_espresso'
272
+		);
273
+		EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status;
274
+		EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status;
275
+		EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso');
276
+		EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__(
277
+			'This transaction has been overpaid ! Payments Total',
278
+			'event_espresso'
279
+		);
280
+	}
281
+
282
+	public function admin_notices()
283
+	{
284
+		// noop
285
+	}
286
+
287
+	public function admin_footer_scripts()
288
+	{
289
+		// noop
290
+	}
291
+
292
+
293
+	/**
294
+	 * _set_transaction_status_array
295
+	 * sets list of transaction statuses
296
+	 *
297
+	 * @access private
298
+	 * @return void
299
+	 * @throws EE_Error
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 */
304
+	private function _set_transaction_status_array()
305
+	{
306
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
+	}
308
+
309
+
310
+	/**
311
+	 * get_transaction_status_array
312
+	 * return the transaction status array for wp_list_table
313
+	 *
314
+	 * @access public
315
+	 * @return array
316
+	 */
317
+	public function get_transaction_status_array()
318
+	{
319
+		return self::$_txn_status;
320
+	}
321
+
322
+
323
+	/**
324
+	 *    get list of payment statuses
325
+	 *
326
+	 * @access private
327
+	 * @return void
328
+	 * @throws EE_Error
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	private function _get_payment_status_array()
334
+	{
335
+		self::$_pay_status = EEM_Payment::instance()->status_array(true);
336
+		$this->_template_args['payment_status'] = self::$_pay_status;
337
+	}
338
+
339
+
340
+	/**
341
+	 *    _add_screen_options_default
342
+	 *
343
+	 * @access protected
344
+	 * @return void
345
+	 * @throws InvalidArgumentException
346
+	 * @throws InvalidDataTypeException
347
+	 * @throws InvalidInterfaceException
348
+	 */
349
+	protected function _add_screen_options_default()
350
+	{
351
+		$this->_per_page_screen_option();
352
+	}
353
+
354
+
355
+	/**
356
+	 * load_scripts_styles
357
+	 *
358
+	 * @access public
359
+	 * @return void
360
+	 */
361
+	public function load_scripts_styles()
362
+	{
363
+		// enqueue style
364
+		wp_register_style(
365
+			'espresso_txn',
366
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
367
+			array(),
368
+			EVENT_ESPRESSO_VERSION
369
+		);
370
+		wp_enqueue_style('espresso_txn');
371
+		// scripts
372
+		wp_register_script(
373
+			'espresso_txn',
374
+			TXN_ASSETS_URL . 'espresso_transactions_admin.js',
375
+			array(
376
+				'ee_admin_js',
377
+				'ee-datepicker',
378
+				'jquery-ui-datepicker',
379
+				'jquery-ui-draggable',
380
+				'ee-dialog',
381
+				'ee-accounting',
382
+				'ee-serialize-full-array',
383
+			),
384
+			EVENT_ESPRESSO_VERSION,
385
+			true
386
+		);
387
+		wp_enqueue_script('espresso_txn');
388
+	}
389
+
390
+
391
+	/**
392
+	 *    load_scripts_styles_view_transaction
393
+	 *
394
+	 * @access public
395
+	 * @return void
396
+	 */
397
+	public function load_scripts_styles_view_transaction()
398
+	{
399
+		// styles
400
+		wp_enqueue_style('espresso-ui-theme');
401
+	}
402
+
403
+
404
+	/**
405
+	 *    load_scripts_styles_default
406
+	 *
407
+	 * @access public
408
+	 * @return void
409
+	 */
410
+	public function load_scripts_styles_default()
411
+	{
412
+		// styles
413
+		wp_enqueue_style('espresso-ui-theme');
414
+	}
415
+
416
+
417
+	/**
418
+	 *    _set_list_table_views_default
419
+	 *
420
+	 * @access protected
421
+	 * @return void
422
+	 */
423
+	protected function _set_list_table_views_default()
424
+	{
425
+		$this->_views = array(
426
+			'all'       => array(
427
+				'slug'  => 'all',
428
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
429
+				'count' => 0,
430
+			),
431
+			'abandoned' => array(
432
+				'slug'  => 'abandoned',
433
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
434
+				'count' => 0,
435
+			),
436
+			'incomplete' => array(
437
+				'slug'  => 'incomplete',
438
+				'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
439
+				'count' => 0,
440
+			)
441
+		);
442
+		if (/**
443
+		 * Filters whether a link to the "Failed Transactions" list table
444
+		 * appears on the Transactions Admin Page list table.
445
+		 * List display can be turned back on via the following:
446
+		 * add_filter(
447
+		 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
448
+		 *     '__return_true'
449
+		 * );
450
+		 *
451
+		 * @since 4.9.70.p
452
+		 * @param boolean                 $display_failed_txns_list
453
+		 * @param Transactions_Admin_Page $this
454
+		 */
455
+			apply_filters(
456
+				'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
457
+				false,
458
+				$this
459
+			)
460
+		) {
461
+			$this->_views['failed'] = array(
462
+				'slug'  => 'failed',
463
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
464
+				'count' => 0,
465
+			);
466
+		}
467
+	}
468
+
469
+
470
+	/**
471
+	 * _set_transaction_object
472
+	 * This sets the _transaction property for the transaction details screen
473
+	 *
474
+	 * @access private
475
+	 * @return void
476
+	 * @throws EE_Error
477
+	 * @throws InvalidArgumentException
478
+	 * @throws RuntimeException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws InvalidInterfaceException
481
+	 * @throws ReflectionException
482
+	 */
483
+	private function _set_transaction_object()
484
+	{
485
+		if ($this->_transaction instanceof EE_Transaction) {
486
+			return;
487
+		} //get out we've already set the object
488
+
489
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
490
+			? absint($this->_req_data['TXN_ID'])
491
+			: false;
492
+
493
+		// get transaction object
494
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
495
+		$this->_session = $this->_transaction instanceof EE_Transaction
496
+			? $this->_transaction->get('TXN_session_data')
497
+			: null;
498
+		if ($this->_transaction instanceof EE_Transaction) {
499
+			$this->_transaction->verify_abandoned_transaction_status();
500
+		}
501
+
502
+		if (! $this->_transaction instanceof EE_Transaction) {
503
+			$error_msg = sprintf(
504
+				esc_html__(
505
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
506
+					'event_espresso'
507
+				),
508
+				$TXN_ID
509
+			);
510
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
511
+		}
512
+	}
513
+
514
+
515
+	/**
516
+	 *    _transaction_legend_items
517
+	 *
518
+	 * @access protected
519
+	 * @return array
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws ReflectionException
523
+	 * @throws InvalidDataTypeException
524
+	 * @throws InvalidInterfaceException
525
+	 */
526
+	protected function _transaction_legend_items()
527
+	{
528
+		EE_Registry::instance()->load_helper('MSG_Template');
529
+		$items = array();
530
+
531
+		if (EE_Registry::instance()->CAP->current_user_can(
532
+			'ee_read_global_messages',
533
+			'view_filtered_messages'
534
+		)) {
535
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
536
+			if (is_array($related_for_icon)
537
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
538
+			) {
539
+				$items['view_related_messages'] = array(
540
+					'class' => $related_for_icon['css_class'],
541
+					'desc'  => $related_for_icon['label'],
542
+				);
543
+			}
544
+		}
545
+
546
+		$items = apply_filters(
547
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
548
+			array_merge(
549
+				$items,
550
+				array(
551
+					'view_details'          => array(
552
+						'class' => 'dashicons dashicons-cart',
553
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
554
+					),
555
+					'view_invoice'          => array(
556
+						'class' => 'dashicons dashicons-media-spreadsheet',
557
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
558
+					),
559
+					'view_receipt'          => array(
560
+						'class' => 'dashicons dashicons-media-default',
561
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
562
+					),
563
+					'view_registration'     => array(
564
+						'class' => 'dashicons dashicons-clipboard',
565
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
566
+					),
567
+					'payment_overview_link' => array(
568
+						'class' => 'dashicons dashicons-money',
569
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
570
+					),
571
+				)
572
+			)
573
+		);
574
+
575
+		if (EE_Registry::instance()->CAP->current_user_can(
576
+			'ee_send_message',
577
+			'espresso_transactions_send_payment_reminder'
578
+		)) {
579
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
580
+				$items['send_payment_reminder'] = array(
581
+					'class' => 'dashicons dashicons-email-alt',
582
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
583
+				);
584
+			} else {
585
+				$items['blank*'] = array(
586
+					'class' => '',
587
+					'desc'  => '',
588
+				);
589
+			}
590
+		} else {
591
+			$items['blank*'] = array(
592
+				'class' => '',
593
+				'desc'  => '',
594
+			);
595
+		}
596
+		$more_items = apply_filters(
597
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
598
+			array(
599
+				'overpaid'   => array(
600
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
601
+					'desc'  => EEH_Template::pretty_status(
602
+						EEM_Transaction::overpaid_status_code,
603
+						false,
604
+						'sentence'
605
+					),
606
+				),
607
+				'complete'   => array(
608
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
609
+					'desc'  => EEH_Template::pretty_status(
610
+						EEM_Transaction::complete_status_code,
611
+						false,
612
+						'sentence'
613
+					),
614
+				),
615
+				'incomplete' => array(
616
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
617
+					'desc'  => EEH_Template::pretty_status(
618
+						EEM_Transaction::incomplete_status_code,
619
+						false,
620
+						'sentence'
621
+					),
622
+				),
623
+				'abandoned'  => array(
624
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
625
+					'desc'  => EEH_Template::pretty_status(
626
+						EEM_Transaction::abandoned_status_code,
627
+						false,
628
+						'sentence'
629
+					),
630
+				),
631
+				'failed'     => array(
632
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
633
+					'desc'  => EEH_Template::pretty_status(
634
+						EEM_Transaction::failed_status_code,
635
+						false,
636
+						'sentence'
637
+					),
638
+				),
639
+			)
640
+		);
641
+
642
+		return array_merge($items, $more_items);
643
+	}
644
+
645
+
646
+	/**
647
+	 *    _transactions_overview_list_table
648
+	 *
649
+	 * @access protected
650
+	 * @return void
651
+	 * @throws DomainException
652
+	 * @throws EE_Error
653
+	 * @throws InvalidArgumentException
654
+	 * @throws InvalidDataTypeException
655
+	 * @throws InvalidInterfaceException
656
+	 * @throws ReflectionException
657
+	 */
658
+	protected function _transactions_overview_list_table()
659
+	{
660
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
661
+		$event = isset($this->_req_data['EVT_ID'])
662
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
663
+			: null;
664
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
665
+			? sprintf(
666
+				esc_html__(
667
+					'%sViewing Transactions for the Event: %s%s',
668
+					'event_espresso'
669
+				),
670
+				'<h3>',
671
+				'<a href="'
672
+				. EE_Admin_Page::add_query_args_and_nonce(
673
+					array('action' => 'edit', 'post' => $event->ID()),
674
+					EVENTS_ADMIN_URL
675
+				)
676
+				. '" title="'
677
+				. esc_attr__(
678
+					'Click to Edit event',
679
+					'event_espresso'
680
+				)
681
+				. '">' . $event->get('EVT_name') . '</a>',
682
+				'</h3>'
683
+			)
684
+			: '';
685
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
686
+		$this->display_admin_list_table_page_with_no_sidebar();
687
+	}
688
+
689
+
690
+	/**
691
+	 *    _transaction_details
692
+	 * generates HTML for the View Transaction Details Admin page
693
+	 *
694
+	 * @access protected
695
+	 * @return void
696
+	 * @throws DomainException
697
+	 * @throws EE_Error
698
+	 * @throws InvalidArgumentException
699
+	 * @throws InvalidDataTypeException
700
+	 * @throws InvalidInterfaceException
701
+	 * @throws RuntimeException
702
+	 * @throws ReflectionException
703
+	 */
704
+	protected function _transaction_details()
705
+	{
706
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
707
+
708
+		$this->_set_transaction_status_array();
709
+
710
+		$this->_template_args = array();
711
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
712
+
713
+		$this->_set_transaction_object();
714
+
715
+		if (! $this->_transaction instanceof EE_Transaction) {
716
+			return;
717
+		}
718
+		$primary_registration = $this->_transaction->primary_registration();
719
+		$attendee = $primary_registration instanceof EE_Registration
720
+			? $primary_registration->attendee()
721
+			: null;
722
+
723
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
724
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
725
+
726
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
727
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
728
+
729
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ];
730
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
731
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
732
+
733
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
734
+		$this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
735
+
736
+		$amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
737
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
738
+			$amount_due,
739
+			true
740
+		);
741
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
742
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
743
+												  . $this->_template_args['amount_due'];
744
+		} else {
745
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
746
+		}
747
+		$this->_template_args['amount_due_class'] = '';
748
+
749
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
750
+			// paid in full
751
+			$this->_template_args['amount_due'] = false;
752
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
753
+			// overpaid
754
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
755
+		} elseif ($this->_transaction->get('TXN_total') > 0
756
+				  && $this->_transaction->get('TXN_paid') > 0
757
+		) {
758
+			// monies owing
759
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
760
+		} elseif ($this->_transaction->get('TXN_total') > 0
761
+				  && $this->_transaction->get('TXN_paid') == 0
762
+		) {
763
+			// no payments made yet
764
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
765
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
766
+			// free event
767
+			$this->_template_args['amount_due'] = false;
768
+		}
769
+
770
+		$payment_method = $this->_transaction->payment_method();
771
+
772
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
773
+			? $payment_method->admin_name()
774
+			: esc_html__('Unknown', 'event_espresso');
775
+
776
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
777
+		// link back to overview
778
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
779
+			? $_SERVER['HTTP_REFERER']
780
+			: TXN_ADMIN_URL;
781
+
782
+
783
+		// next link
784
+		$next_txn = $this->_transaction->next(
785
+			null,
786
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
787
+			'TXN_ID'
788
+		);
789
+		$this->_template_args['next_transaction'] = $next_txn
790
+			? $this->_next_link(
791
+				EE_Admin_Page::add_query_args_and_nonce(
792
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
793
+					TXN_ADMIN_URL
794
+				),
795
+				'dashicons dashicons-arrow-right ee-icon-size-22'
796
+			)
797
+			: '';
798
+		// previous link
799
+		$previous_txn = $this->_transaction->previous(
800
+			null,
801
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
802
+			'TXN_ID'
803
+		);
804
+		$this->_template_args['previous_transaction'] = $previous_txn
805
+			? $this->_previous_link(
806
+				EE_Admin_Page::add_query_args_and_nonce(
807
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
808
+					TXN_ADMIN_URL
809
+				),
810
+				'dashicons dashicons-arrow-left ee-icon-size-22'
811
+			)
812
+			: '';
813
+
814
+		// were we just redirected here after adding a new registration ???
815
+		if (isset(
816
+			$this->_req_data['redirect_from'],
817
+			$this->_req_data['EVT_ID'],
818
+			$this->_req_data['event_name']
819
+		)) {
820
+			if (EE_Registry::instance()->CAP->current_user_can(
821
+				'ee_edit_registrations',
822
+				'espresso_registrations_new_registration',
823
+				$this->_req_data['EVT_ID']
824
+			)) {
825
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
826
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
827
+					array(
828
+						'page'     => 'espresso_registrations',
829
+						'action'   => 'new_registration',
830
+						'return'   => 'default',
831
+						'TXN_ID'   => $this->_transaction->ID(),
832
+						'event_id' => $this->_req_data['EVT_ID'],
833
+					),
834
+					REG_ADMIN_URL
835
+				);
836
+				$this->_admin_page_title .= '">';
837
+
838
+				$this->_admin_page_title .= sprintf(
839
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
840
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
841
+				);
842
+				$this->_admin_page_title .= '</a>';
843
+			}
844
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
845
+		}
846
+		// grab messages at the last second
847
+		$this->_template_args['notices'] = EE_Error::get_notices();
848
+		// path to template
849
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
850
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
851
+			$template_path,
852
+			$this->_template_args,
853
+			true
854
+		);
855
+
856
+		// the details template wrapper
857
+		$this->display_admin_page_with_sidebar();
858
+	}
859
+
860
+
861
+	/**
862
+	 *        _transaction_details_metaboxes
863
+	 *
864
+	 * @access protected
865
+	 * @return void
866
+	 * @throws EE_Error
867
+	 * @throws InvalidArgumentException
868
+	 * @throws InvalidDataTypeException
869
+	 * @throws InvalidInterfaceException
870
+	 * @throws RuntimeException
871
+	 * @throws ReflectionException
872
+	 */
873
+	protected function _transaction_details_metaboxes()
874
+	{
875
+
876
+		$this->_set_transaction_object();
877
+
878
+		if (! $this->_transaction instanceof EE_Transaction) {
879
+			return;
880
+		}
881
+		add_meta_box(
882
+			'edit-txn-details-mbox',
883
+			esc_html__('Transaction Details', 'event_espresso'),
884
+			array($this, 'txn_details_meta_box'),
885
+			$this->_wp_page_slug,
886
+			'normal',
887
+			'high'
888
+		);
889
+		add_meta_box(
890
+			'edit-txn-attendees-mbox',
891
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
892
+			array($this, 'txn_attendees_meta_box'),
893
+			$this->_wp_page_slug,
894
+			'normal',
895
+			'high',
896
+			array('TXN_ID' => $this->_transaction->ID())
897
+		);
898
+		add_meta_box(
899
+			'edit-txn-registrant-mbox',
900
+			esc_html__('Primary Contact', 'event_espresso'),
901
+			array($this, 'txn_registrant_side_meta_box'),
902
+			$this->_wp_page_slug,
903
+			'side',
904
+			'high'
905
+		);
906
+		add_meta_box(
907
+			'edit-txn-billing-info-mbox',
908
+			esc_html__('Billing Information', 'event_espresso'),
909
+			array($this, 'txn_billing_info_side_meta_box'),
910
+			$this->_wp_page_slug,
911
+			'side',
912
+			'high'
913
+		);
914
+	}
915
+
916
+
917
+	/**
918
+	 * Callback for transaction actions metabox.
919
+	 *
920
+	 * @param EE_Transaction|null $transaction
921
+	 * @throws DomainException
922
+	 * @throws EE_Error
923
+	 * @throws InvalidArgumentException
924
+	 * @throws InvalidDataTypeException
925
+	 * @throws InvalidInterfaceException
926
+	 * @throws ReflectionException
927
+	 * @throws RuntimeException
928
+	 */
929
+	public function getActionButtons(EE_Transaction $transaction = null)
930
+	{
931
+		$content = '';
932
+		$actions = array();
933
+		if (! $transaction instanceof EE_Transaction) {
934
+			return $content;
935
+		}
936
+		/** @var EE_Registration $primary_registration */
937
+		$primary_registration = $transaction->primary_registration();
938
+		$attendee = $primary_registration instanceof EE_Registration
939
+			? $primary_registration->attendee()
940
+			: null;
941
+
942
+		if ($attendee instanceof EE_Attendee
943
+			&& EE_Registry::instance()->CAP->current_user_can(
944
+				'ee_send_message',
945
+				'espresso_transactions_send_payment_reminder'
946
+			)
947
+		) {
948
+			$actions['payment_reminder'] =
949
+				EEH_MSG_Template::is_mt_active('payment_reminder')
950
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
951
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
952
+					? EEH_Template::get_button_or_link(
953
+						EE_Admin_Page::add_query_args_and_nonce(
954
+							array(
955
+								'action'      => 'send_payment_reminder',
956
+								'TXN_ID'      => $this->_transaction->ID(),
957
+								'redirect_to' => 'view_transaction',
958
+							),
959
+							TXN_ADMIN_URL
960
+						),
961
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
962
+						'button secondary-button',
963
+						'dashicons dashicons-email-alt'
964
+					)
965
+					: '';
966
+		}
967
+
968
+		if ($primary_registration instanceof EE_Registration
969
+			&& EEH_MSG_Template::is_mt_active('receipt')
970
+		) {
971
+			$actions['receipt'] = EEH_Template::get_button_or_link(
972
+				$primary_registration->receipt_url(),
973
+				esc_html__('View Receipt', 'event_espresso'),
974
+				'button secondary-button',
975
+				'dashicons dashicons-media-default'
976
+			);
977
+		}
978
+
979
+		if ($primary_registration instanceof EE_Registration
980
+			&& EEH_MSG_Template::is_mt_active('invoice')
981
+		) {
982
+			$actions['invoice'] = EEH_Template::get_button_or_link(
983
+				$primary_registration->invoice_url(),
984
+				esc_html__('View Invoice', 'event_espresso'),
985
+				'button secondary-button',
986
+				'dashicons dashicons-media-spreadsheet'
987
+			);
988
+		}
989
+		$actions = array_filter(
990
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
991
+		);
992
+		if ($actions) {
993
+			$content = '<ul>';
994
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
995
+			$content .= '</uL>';
996
+		}
997
+		return $content;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * txn_details_meta_box
1003
+	 * generates HTML for the Transaction main meta box
1004
+	 *
1005
+	 * @return void
1006
+	 * @throws DomainException
1007
+	 * @throws EE_Error
1008
+	 * @throws InvalidArgumentException
1009
+	 * @throws InvalidDataTypeException
1010
+	 * @throws InvalidInterfaceException
1011
+	 * @throws RuntimeException
1012
+	 * @throws ReflectionException
1013
+	 */
1014
+	public function txn_details_meta_box()
1015
+	{
1016
+		$this->_set_transaction_object();
1017
+		$this->_template_args['TXN_ID'] = $this->_transaction->ID();
1018
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1019
+			? $this->_transaction->primary_registration()->attendee()
1020
+			: null;
1021
+		$this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1022
+			'ee_edit_payments',
1023
+			'apply_payment_or_refund_from_registration_details'
1024
+		);
1025
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1026
+			'ee_delete_payments',
1027
+			'delete_payment_from_registration_details'
1028
+		);
1029
+
1030
+		// get line table
1031
+		EEH_Autoloader::register_line_item_display_autoloaders();
1032
+		$Line_Item_Display = new EE_Line_Item_Display(
1033
+			'admin_table',
1034
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1035
+		);
1036
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1037
+			$this->_transaction->total_line_item()
1038
+		);
1039
+		$this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')
1040
+															   ->get('REG_code');
1041
+
1042
+		// process taxes
1043
+		$taxes = $this->_transaction->get_many_related(
1044
+			'Line_Item',
1045
+			array(array('LIN_type' => EEM_Line_Item::type_tax))
1046
+		);
1047
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1048
+
1049
+		$this->_template_args['grand_total'] = EEH_Template::format_currency(
1050
+			$this->_transaction->get('TXN_total'),
1051
+			false,
1052
+			false
1053
+		);
1054
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1055
+		$this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID');
1056
+
1057
+		// process payment details
1058
+		$payments = $this->_transaction->get_many_related('Payment');
1059
+		if (! empty($payments)) {
1060
+			$this->_template_args['payments'] = $payments;
1061
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1062
+		} else {
1063
+			$this->_template_args['payments'] = false;
1064
+			$this->_template_args['existing_reg_payments'] = array();
1065
+		}
1066
+
1067
+		$this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1068
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1069
+			array('action' => 'espresso_delete_payment'),
1070
+			TXN_ADMIN_URL
1071
+		);
1072
+
1073
+		if (isset($txn_details['invoice_number'])) {
1074
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1075
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1076
+				'Invoice Number',
1077
+				'event_espresso'
1078
+			);
1079
+		}
1080
+
1081
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1082
+			->get_first_related('Registration')
1083
+			->get('REG_session');
1084
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1085
+			'Registration Session',
1086
+			'event_espresso'
1087
+		);
1088
+
1089
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1090
+			? $this->_session['ip_address']
1091
+			: '';
1092
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1093
+			'Transaction placed from IP',
1094
+			'event_espresso'
1095
+		);
1096
+
1097
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1098
+			? $this->_session['user_agent']
1099
+			: '';
1100
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1101
+			'Registrant User Agent',
1102
+			'event_espresso'
1103
+		);
1104
+
1105
+		$reg_steps = '<ul>';
1106
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1107
+			if ($reg_step_status === true) {
1108
+				$reg_steps .= '<li style="color:#70cc50">'
1109
+							  . sprintf(
1110
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1111
+								  ucwords(str_replace('_', ' ', $reg_step))
1112
+							  )
1113
+							  . '</li>';
1114
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1115
+				$reg_steps .= '<li style="color:#2EA2CC">'
1116
+							  . sprintf(
1117
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1118
+								  ucwords(str_replace('_', ' ', $reg_step)),
1119
+								  date(
1120
+									  get_option('date_format') . ' ' . get_option('time_format'),
1121
+									  ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1122
+								  )
1123
+							  )
1124
+							  . '</li>';
1125
+			} else {
1126
+				$reg_steps .= '<li style="color:#E76700">'
1127
+							  . sprintf(
1128
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1129
+								  ucwords(str_replace('_', ' ', $reg_step))
1130
+							  )
1131
+							  . '</li>';
1132
+			}
1133
+		}
1134
+		$reg_steps .= '</ul>';
1135
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1136
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1137
+			'Registration Step Progress',
1138
+			'event_espresso'
1139
+		);
1140
+
1141
+
1142
+		$this->_get_registrations_to_apply_payment_to();
1143
+		$this->_get_payment_methods($payments);
1144
+		$this->_get_payment_status_array();
1145
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1146
+
1147
+		$this->_template_args['transaction_form_url'] = add_query_arg(
1148
+			array(
1149
+				'action'  => 'edit_transaction',
1150
+				'process' => 'transaction',
1151
+			),
1152
+			TXN_ADMIN_URL
1153
+		);
1154
+		$this->_template_args['apply_payment_form_url'] = add_query_arg(
1155
+			array(
1156
+				'page'   => 'espresso_transactions',
1157
+				'action' => 'espresso_apply_payment',
1158
+			),
1159
+			WP_AJAX_URL
1160
+		);
1161
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1162
+			array(
1163
+				'page'   => 'espresso_transactions',
1164
+				'action' => 'espresso_delete_payment',
1165
+			),
1166
+			WP_AJAX_URL
1167
+		);
1168
+
1169
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1170
+
1171
+		// 'espresso_delete_payment_nonce'
1172
+
1173
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1174
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * _get_registration_payment_IDs
1180
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1181
+	 *
1182
+	 * @access protected
1183
+	 * @param EE_Payment[] $payments
1184
+	 * @return array
1185
+	 * @throws EE_Error
1186
+	 * @throws InvalidArgumentException
1187
+	 * @throws InvalidDataTypeException
1188
+	 * @throws InvalidInterfaceException
1189
+	 * @throws ReflectionException
1190
+	 */
1191
+	protected function _get_registration_payment_IDs($payments = array())
1192
+	{
1193
+		$existing_reg_payments = array();
1194
+		// get all reg payments for these payments
1195
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1196
+			array(
1197
+				array(
1198
+					'PAY_ID' => array(
1199
+						'IN',
1200
+						array_keys($payments),
1201
+					),
1202
+				),
1203
+			)
1204
+		);
1205
+		if (! empty($reg_payments)) {
1206
+			foreach ($payments as $payment) {
1207
+				if (! $payment instanceof EE_Payment) {
1208
+					continue;
1209
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1210
+					$existing_reg_payments[ $payment->ID() ] = array();
1211
+				}
1212
+				foreach ($reg_payments as $reg_payment) {
1213
+					if ($reg_payment instanceof EE_Registration_Payment
1214
+						&& $reg_payment->payment_ID() === $payment->ID()
1215
+					) {
1216
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1217
+					}
1218
+				}
1219
+			}
1220
+		}
1221
+
1222
+		return $existing_reg_payments;
1223
+	}
1224
+
1225
+
1226
+	/**
1227
+	 * _get_registrations_to_apply_payment_to
1228
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1229
+	 * which allows the admin to only apply the payment to the specific registrations
1230
+	 *
1231
+	 * @access protected
1232
+	 * @return void
1233
+	 * @throws \EE_Error
1234
+	 */
1235
+	protected function _get_registrations_to_apply_payment_to()
1236
+	{
1237
+		// we want any registration with an active status (ie: not deleted or cancelled)
1238
+		$query_params = array(
1239
+			array(
1240
+				'STS_ID' => array(
1241
+					'IN',
1242
+					array(
1243
+						EEM_Registration::status_id_approved,
1244
+						EEM_Registration::status_id_pending_payment,
1245
+						EEM_Registration::status_id_not_approved,
1246
+					),
1247
+				),
1248
+			),
1249
+		);
1250
+		$registrations_to_apply_payment_to = EEH_HTML::br()
1251
+											 . EEH_HTML::div(
1252
+												 '',
1253
+												 'txn-admin-apply-payment-to-registrations-dv',
1254
+												 '',
1255
+												 'clear: both; margin: 1.5em 0 0; display: none;'
1256
+											 );
1257
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
+			EEH_HTML::tr(
1261
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
+			)
1269
+		);
1270
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
+		// get registrations for TXN
1272
+		$registrations = $this->_transaction->registrations($query_params);
1273
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
+		foreach ($registrations as $registration) {
1275
+			if ($registration instanceof EE_Registration) {
1276
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
1277
+					? $registration->attendee()->full_name()
1278
+					: esc_html__('Unknown Attendee', 'event_espresso');
1279
+				$owing = $registration->final_price() - $registration->paid();
1280
+				$taxable = $registration->ticket()->taxable()
1281
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
+					: '';
1283
+				$checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1284
+					? ' checked="checked"'
1285
+					: '';
1286
+				$disabled = $registration->final_price() > 0 ? '' : ' disabled';
1287
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1288
+					EEH_HTML::td($registration->ID()) .
1289
+					EEH_HTML::td($attendee_name) .
1290
+					EEH_HTML::td(
1291
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1292
+					) .
1293
+					EEH_HTML::td($registration->event_name()) .
1294
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1295
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1296
+					EEH_HTML::td(
1297
+						'<input type="checkbox" value="' . $registration->ID()
1298
+						. '" name="txn_admin_payment[registrations]"'
1299
+						. $checked . $disabled . '>',
1300
+						'',
1301
+						'jst-cntr'
1302
+					),
1303
+					'apply-payment-registration-row-' . $registration->ID()
1304
+				);
1305
+			}
1306
+		}
1307
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1308
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1309
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1310
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1311
+			esc_html__(
1312
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1313
+				'event_espresso'
1314
+			),
1315
+			'',
1316
+			'clear description'
1317
+		);
1318
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1319
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1320
+	}
1321
+
1322
+
1323
+	/**
1324
+	 * _get_reg_status_selection
1325
+	 *
1326
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1327
+	 *         instead of events.
1328
+	 * @access protected
1329
+	 * @return void
1330
+	 * @throws EE_Error
1331
+	 */
1332
+	protected function _get_reg_status_selection()
1333
+	{
1334
+		// first get all possible statuses
1335
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1336
+		// let's add a "don't change" option.
1337
+		$status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1338
+		$status_array = array_merge($status_array, $statuses);
1339
+		$this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1340
+			'txn_reg_status_change[reg_status]',
1341
+			$status_array,
1342
+			'NAN',
1343
+			'id="txn-admin-payment-reg-status-inp"',
1344
+			'txn-reg-status-change-reg-status'
1345
+		);
1346
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1347
+			'delete_txn_reg_status_change[reg_status]',
1348
+			$status_array,
1349
+			'NAN',
1350
+			'delete-txn-admin-payment-reg-status-inp',
1351
+			'delete-txn-reg-status-change-reg-status'
1352
+		);
1353
+	}
1354
+
1355
+
1356
+	/**
1357
+	 *    _get_payment_methods
1358
+	 * Gets all the payment methods available generally, or the ones that are already
1359
+	 * selected on these payments (in case their payment methods are no longer active).
1360
+	 * Has the side-effect of updating the template args' payment_methods item
1361
+	 *
1362
+	 * @access private
1363
+	 * @param EE_Payment[] to show on this page
1364
+	 * @return void
1365
+	 * @throws EE_Error
1366
+	 * @throws InvalidArgumentException
1367
+	 * @throws InvalidDataTypeException
1368
+	 * @throws InvalidInterfaceException
1369
+	 * @throws ReflectionException
1370
+	 */
1371
+	private function _get_payment_methods($payments = array())
1372
+	{
1373
+		$payment_methods_of_payments = array();
1374
+		foreach ($payments as $payment) {
1375
+			if ($payment instanceof EE_Payment) {
1376
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1377
+			}
1378
+		}
1379
+		if ($payment_methods_of_payments) {
1380
+			$query_args = array(
1381
+				array(
1382
+					'OR*payment_method_for_payment' => array(
1383
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1384
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1385
+					),
1386
+				),
1387
+			);
1388
+		} else {
1389
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1390
+		}
1391
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1392
+	}
1393
+
1394
+
1395
+	/**
1396
+	 * txn_attendees_meta_box
1397
+	 *    generates HTML for the Attendees Transaction main meta box
1398
+	 *
1399
+	 * @access public
1400
+	 * @param WP_Post $post
1401
+	 * @param array   $metabox
1402
+	 * @return void
1403
+	 * @throws DomainException
1404
+	 * @throws EE_Error
1405
+	 */
1406
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1407
+	{
1408
+
1409
+		/** @noinspection NonSecureExtractUsageInspection */
1410
+		extract($metabox['args']);
1411
+		$this->_template_args['post'] = $post;
1412
+		$this->_template_args['event_attendees'] = array();
1413
+		// process items in cart
1414
+		$line_items = $this->_transaction->get_many_related(
1415
+			'Line_Item',
1416
+			array(array('LIN_type' => 'line-item'))
1417
+		);
1418
+		if (! empty($line_items)) {
1419
+			foreach ($line_items as $item) {
1420
+				if ($item instanceof EE_Line_Item) {
1421
+					switch ($item->OBJ_type()) {
1422
+						case 'Event':
1423
+							break;
1424
+						case 'Ticket':
1425
+							$ticket = $item->ticket();
1426
+							// right now we're only handling tickets here.
1427
+							// Cause its expected that only tickets will have attendees right?
1428
+							if (! $ticket instanceof EE_Ticket) {
1429
+								continue;
1430
+							}
1431
+							try {
1432
+								$event_name = $ticket->get_event_name();
1433
+							} catch (Exception $e) {
1434
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1435
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1436
+							}
1437
+							$event_name .= ' - ' . $item->get('LIN_name');
1438
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1439
+							// now get all of the registrations for this transaction that use this ticket
1440
+							$registrations = $ticket->get_many_related(
1441
+								'Registration',
1442
+								array(array('TXN_ID' => $this->_transaction->ID()))
1443
+							);
1444
+							foreach ($registrations as $registration) {
1445
+								if (! $registration instanceof EE_Registration) {
1446
+									continue;
1447
+								}
1448
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1449
+									= $registration->status_ID();
1450
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1451
+									= $registration->count();
1452
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1453
+									= $event_name;
1454
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1455
+									= $ticket_price;
1456
+								// attendee info
1457
+								$attendee = $registration->get_first_related('Attendee');
1458
+								if ($attendee instanceof EE_Attendee) {
1459
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1460
+										= $attendee->ID();
1461
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1462
+										= $attendee->full_name();
1463
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1464
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1465
+										  . esc_html__(
1466
+											  ' Event',
1467
+											  'event_espresso'
1468
+										  )
1469
+										  . '">' . $attendee->email() . '</a>';
1470
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1471
+										= EEH_Address::format($attendee, 'inline', false, false);
1472
+								} else {
1473
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1474
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1475
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1476
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1477
+								}
1478
+							}
1479
+							break;
1480
+					}
1481
+				}
1482
+			}
1483
+
1484
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1485
+				array(
1486
+					'action'  => 'edit_transaction',
1487
+					'process' => 'attendees',
1488
+				),
1489
+				TXN_ADMIN_URL
1490
+			);
1491
+			echo EEH_Template::display_template(
1492
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1493
+				$this->_template_args,
1494
+				true
1495
+			);
1496
+		} else {
1497
+			echo sprintf(
1498
+				esc_html__(
1499
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1500
+					'event_espresso'
1501
+				),
1502
+				'<p class="important-notice">',
1503
+				'</p>'
1504
+			);
1505
+		}
1506
+	}
1507
+
1508
+
1509
+	/**
1510
+	 * txn_registrant_side_meta_box
1511
+	 * generates HTML for the Edit Transaction side meta box
1512
+	 *
1513
+	 * @access public
1514
+	 * @return void
1515
+	 * @throws DomainException
1516
+	 * @throws EE_Error
1517
+	 * @throws InvalidArgumentException
1518
+	 * @throws InvalidDataTypeException
1519
+	 * @throws InvalidInterfaceException
1520
+	 * @throws ReflectionException
1521
+	 */
1522
+	public function txn_registrant_side_meta_box()
1523
+	{
1524
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1525
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1526
+			: null;
1527
+		if (! $primary_att instanceof EE_Attendee) {
1528
+			$this->_template_args['no_attendee_message'] = esc_html__(
1529
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1530
+				'event_espresso'
1531
+			);
1532
+			$primary_att = EEM_Attendee::instance()->create_default_object();
1533
+		}
1534
+		$this->_template_args['ATT_ID'] = $primary_att->ID();
1535
+		$this->_template_args['prime_reg_fname'] = $primary_att->fname();
1536
+		$this->_template_args['prime_reg_lname'] = $primary_att->lname();
1537
+		$this->_template_args['prime_reg_email'] = $primary_att->email();
1538
+		$this->_template_args['prime_reg_phone'] = $primary_att->phone();
1539
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1540
+			array(
1541
+				'action' => 'edit_attendee',
1542
+				'post'   => $primary_att->ID(),
1543
+			),
1544
+			REG_ADMIN_URL
1545
+		);
1546
+		// get formatted address for registrant
1547
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1548
+		echo EEH_Template::display_template(
1549
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1550
+			$this->_template_args,
1551
+			true
1552
+		);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 * txn_billing_info_side_meta_box
1558
+	 *    generates HTML for the Edit Transaction side meta box
1559
+	 *
1560
+	 * @access public
1561
+	 * @return void
1562
+	 * @throws DomainException
1563
+	 * @throws EE_Error
1564
+	 */
1565
+	public function txn_billing_info_side_meta_box()
1566
+	{
1567
+
1568
+		$this->_template_args['billing_form'] = $this->_transaction->billing_info();
1569
+		$this->_template_args['billing_form_url'] = add_query_arg(
1570
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1571
+			TXN_ADMIN_URL
1572
+		);
1573
+
1574
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1575
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1576
+	}
1577
+
1578
+
1579
+	/**
1580
+	 * apply_payments_or_refunds
1581
+	 *    registers a payment or refund made towards a transaction
1582
+	 *
1583
+	 * @access public
1584
+	 * @return void
1585
+	 * @throws EE_Error
1586
+	 * @throws InvalidArgumentException
1587
+	 * @throws ReflectionException
1588
+	 * @throws RuntimeException
1589
+	 * @throws InvalidDataTypeException
1590
+	 * @throws InvalidInterfaceException
1591
+	 */
1592
+	public function apply_payments_or_refunds()
1593
+	{
1594
+		$json_response_data = array('return_data' => false);
1595
+		$valid_data = $this->_validate_payment_request_data();
1596
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1597
+			'ee_edit_payments',
1598
+			'apply_payment_or_refund_from_registration_details'
1599
+		);
1600
+		if (! empty($valid_data) && $has_access) {
1601
+			$PAY_ID = $valid_data['PAY_ID'];
1602
+			// save  the new payment
1603
+			$payment = $this->_create_payment_from_request_data($valid_data);
1604
+			// get the TXN for this payment
1605
+			$transaction = $payment->transaction();
1606
+			// verify transaction
1607
+			if ($transaction instanceof EE_Transaction) {
1608
+				// calculate_total_payments_and_update_status
1609
+				$this->_process_transaction_payments($transaction);
1610
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1611
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1612
+				// apply payment to registrations (if applicable)
1613
+				if (! empty($REG_IDs)) {
1614
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1615
+					$this->_maybe_send_notifications();
1616
+					// now process status changes for the same registrations
1617
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1618
+				}
1619
+				$this->_maybe_send_notifications($payment);
1620
+				// prepare to render page
1621
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1622
+				do_action(
1623
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1624
+					$transaction,
1625
+					$payment
1626
+				);
1627
+			} else {
1628
+				EE_Error::add_error(
1629
+					esc_html__(
1630
+						'A valid Transaction for this payment could not be retrieved.',
1631
+						'event_espresso'
1632
+					),
1633
+					__FILE__,
1634
+					__FUNCTION__,
1635
+					__LINE__
1636
+				);
1637
+			}
1638
+		} else {
1639
+			if ($has_access) {
1640
+				EE_Error::add_error(
1641
+					esc_html__(
1642
+						'The payment form data could not be processed. Please try again.',
1643
+						'event_espresso'
1644
+					),
1645
+					__FILE__,
1646
+					__FUNCTION__,
1647
+					__LINE__
1648
+				);
1649
+			} else {
1650
+				EE_Error::add_error(
1651
+					esc_html__(
1652
+						'You do not have access to apply payments or refunds to a registration.',
1653
+						'event_espresso'
1654
+					),
1655
+					__FILE__,
1656
+					__FUNCTION__,
1657
+					__LINE__
1658
+				);
1659
+			}
1660
+		}
1661
+		$notices = EE_Error::get_notices(
1662
+			false,
1663
+			false,
1664
+			false
1665
+		);
1666
+		$this->_template_args = array(
1667
+			'data'    => $json_response_data,
1668
+			'error'   => $notices['errors'],
1669
+			'success' => $notices['success'],
1670
+		);
1671
+		$this->_return_json();
1672
+	}
1673
+
1674
+
1675
+	/**
1676
+	 * _validate_payment_request_data
1677
+	 *
1678
+	 * @return array
1679
+	 * @throws EE_Error
1680
+	 */
1681
+	protected function _validate_payment_request_data()
1682
+	{
1683
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1684
+			return false;
1685
+		}
1686
+		$payment_form = $this->_generate_payment_form_section();
1687
+		try {
1688
+			if ($payment_form->was_submitted()) {
1689
+				$payment_form->receive_form_submission();
1690
+				if (! $payment_form->is_valid()) {
1691
+					$submission_error_messages = array();
1692
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1693
+						if ($validation_error instanceof EE_Validation_Error) {
1694
+							$submission_error_messages[] = sprintf(
1695
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1696
+								$validation_error->get_form_section()->html_label_text(),
1697
+								$validation_error->getMessage()
1698
+							);
1699
+						}
1700
+					}
1701
+					EE_Error::add_error(
1702
+						implode('<br />', $submission_error_messages),
1703
+						__FILE__,
1704
+						__FUNCTION__,
1705
+						__LINE__
1706
+					);
1707
+
1708
+					return array();
1709
+				}
1710
+			}
1711
+		} catch (EE_Error $e) {
1712
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1713
+
1714
+			return array();
1715
+		}
1716
+
1717
+		return $payment_form->valid_data();
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 * _generate_payment_form_section
1723
+	 *
1724
+	 * @return EE_Form_Section_Proper
1725
+	 * @throws EE_Error
1726
+	 */
1727
+	protected function _generate_payment_form_section()
1728
+	{
1729
+		return new EE_Form_Section_Proper(
1730
+			array(
1731
+				'name'        => 'txn_admin_payment',
1732
+				'subsections' => array(
1733
+					'PAY_ID'          => new EE_Text_Input(
1734
+						array(
1735
+							'default'               => 0,
1736
+							'required'              => false,
1737
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1738
+							'validation_strategies' => array(new EE_Int_Normalization()),
1739
+						)
1740
+					),
1741
+					'TXN_ID'          => new EE_Text_Input(
1742
+						array(
1743
+							'default'               => 0,
1744
+							'required'              => true,
1745
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1746
+							'validation_strategies' => array(new EE_Int_Normalization()),
1747
+						)
1748
+					),
1749
+					'type'            => new EE_Text_Input(
1750
+						array(
1751
+							'default'               => 1,
1752
+							'required'              => true,
1753
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1754
+							'validation_strategies' => array(new EE_Int_Normalization()),
1755
+						)
1756
+					),
1757
+					'amount'          => new EE_Text_Input(
1758
+						array(
1759
+							'default'               => 0,
1760
+							'required'              => true,
1761
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1762
+							'validation_strategies' => array(new EE_Float_Normalization()),
1763
+						)
1764
+					),
1765
+					'status'          => new EE_Text_Input(
1766
+						array(
1767
+							'default'         => EEM_Payment::status_id_approved,
1768
+							'required'        => true,
1769
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1770
+						)
1771
+					),
1772
+					'PMD_ID'          => new EE_Text_Input(
1773
+						array(
1774
+							'default'               => 2,
1775
+							'required'              => true,
1776
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1777
+							'validation_strategies' => array(new EE_Int_Normalization()),
1778
+						)
1779
+					),
1780
+					'date'            => new EE_Text_Input(
1781
+						array(
1782
+							'default'         => time(),
1783
+							'required'        => true,
1784
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1785
+						)
1786
+					),
1787
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1788
+						array(
1789
+							'default'               => '',
1790
+							'required'              => false,
1791
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1792
+							'validation_strategies' => array(
1793
+								new EE_Max_Length_Validation_Strategy(
1794
+									esc_html__('Input too long', 'event_espresso'),
1795
+									100
1796
+								),
1797
+							),
1798
+						)
1799
+					),
1800
+					'po_number'       => new EE_Text_Input(
1801
+						array(
1802
+							'default'               => '',
1803
+							'required'              => false,
1804
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1805
+							'validation_strategies' => array(
1806
+								new EE_Max_Length_Validation_Strategy(
1807
+									esc_html__('Input too long', 'event_espresso'),
1808
+									100
1809
+								),
1810
+							),
1811
+						)
1812
+					),
1813
+					'accounting'      => new EE_Text_Input(
1814
+						array(
1815
+							'default'               => '',
1816
+							'required'              => false,
1817
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1818
+							'validation_strategies' => array(
1819
+								new EE_Max_Length_Validation_Strategy(
1820
+									esc_html__('Input too long', 'event_espresso'),
1821
+									100
1822
+								),
1823
+							),
1824
+						)
1825
+					),
1826
+				),
1827
+			)
1828
+		);
1829
+	}
1830
+
1831
+
1832
+	/**
1833
+	 * _create_payment_from_request_data
1834
+	 *
1835
+	 * @param array $valid_data
1836
+	 * @return EE_Payment
1837
+	 * @throws EE_Error
1838
+	 */
1839
+	protected function _create_payment_from_request_data($valid_data)
1840
+	{
1841
+		$PAY_ID = $valid_data['PAY_ID'];
1842
+		// get payment amount
1843
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1844
+		// payments have a type value of 1 and refunds have a type value of -1
1845
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1846
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1847
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1848
+		$date = $valid_data['date']
1849
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1850
+			: date('Y-m-d g:i a', current_time('timestamp'));
1851
+		$payment = EE_Payment::new_instance(
1852
+			array(
1853
+				'TXN_ID'              => $valid_data['TXN_ID'],
1854
+				'STS_ID'              => $valid_data['status'],
1855
+				'PAY_timestamp'       => $date,
1856
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1857
+				'PMD_ID'              => $valid_data['PMD_ID'],
1858
+				'PAY_amount'          => $amount,
1859
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1860
+				'PAY_po_number'       => $valid_data['po_number'],
1861
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1862
+				'PAY_details'         => $valid_data,
1863
+				'PAY_ID'              => $PAY_ID,
1864
+			),
1865
+			'',
1866
+			array('Y-m-d', 'g:i a')
1867
+		);
1868
+
1869
+		if (! $payment->save()) {
1870
+			EE_Error::add_error(
1871
+				sprintf(
1872
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1873
+					$payment->ID()
1874
+				),
1875
+				__FILE__,
1876
+				__FUNCTION__,
1877
+				__LINE__
1878
+			);
1879
+		}
1880
+
1881
+		return $payment;
1882
+	}
1883
+
1884
+
1885
+	/**
1886
+	 * _process_transaction_payments
1887
+	 *
1888
+	 * @param \EE_Transaction $transaction
1889
+	 * @return void
1890
+	 * @throws EE_Error
1891
+	 * @throws InvalidArgumentException
1892
+	 * @throws ReflectionException
1893
+	 * @throws InvalidDataTypeException
1894
+	 * @throws InvalidInterfaceException
1895
+	 */
1896
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1897
+	{
1898
+		/** @type EE_Transaction_Payments $transaction_payments */
1899
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1900
+		// update the transaction with this payment
1901
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1902
+			EE_Error::add_success(
1903
+				esc_html__(
1904
+					'The payment has been processed successfully.',
1905
+					'event_espresso'
1906
+				),
1907
+				__FILE__,
1908
+				__FUNCTION__,
1909
+				__LINE__
1910
+			);
1911
+		} else {
1912
+			EE_Error::add_error(
1913
+				esc_html__(
1914
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1915
+					'event_espresso'
1916
+				),
1917
+				__FILE__,
1918
+				__FUNCTION__,
1919
+				__LINE__
1920
+			);
1921
+		}
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * _get_REG_IDs_to_apply_payment_to
1927
+	 * returns a list of registration IDs that the payment will apply to
1928
+	 *
1929
+	 * @param \EE_Payment $payment
1930
+	 * @return array
1931
+	 * @throws EE_Error
1932
+	 */
1933
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1934
+	{
1935
+		$REG_IDs = array();
1936
+		// grab array of IDs for specific registrations to apply changes to
1937
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1938
+			$REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1939
+		}
1940
+		// nothing specified ? then get all reg IDs
1941
+		if (empty($REG_IDs)) {
1942
+			$registrations = $payment->transaction()->registrations();
1943
+			$REG_IDs = ! empty($registrations)
1944
+				? array_keys($registrations)
1945
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1946
+		}
1947
+
1948
+		// ensure that REG_IDs are integers and NOT strings
1949
+		return array_map('intval', $REG_IDs);
1950
+	}
1951
+
1952
+
1953
+	/**
1954
+	 * @return array
1955
+	 */
1956
+	public function existing_reg_payment_REG_IDs()
1957
+	{
1958
+		return $this->_existing_reg_payment_REG_IDs;
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 * @param array $existing_reg_payment_REG_IDs
1964
+	 */
1965
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1966
+	{
1967
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1968
+	}
1969
+
1970
+
1971
+	/**
1972
+	 * _get_existing_reg_payment_REG_IDs
1973
+	 * returns a list of registration IDs that the payment is currently related to
1974
+	 * as recorded in the database
1975
+	 *
1976
+	 * @param \EE_Payment $payment
1977
+	 * @return array
1978
+	 * @throws EE_Error
1979
+	 */
1980
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1981
+	{
1982
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1983
+			// let's get any existing reg payment records for this payment
1984
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1985
+			// but we only want the REG IDs, so grab the array keys
1986
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1987
+				? array_keys($existing_reg_payment_REG_IDs)
1988
+				: array();
1989
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1990
+		}
1991
+
1992
+		return $this->existing_reg_payment_REG_IDs();
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * _remove_existing_registration_payments
1998
+	 * this calculates the difference between existing relations
1999
+	 * to the supplied payment and the new list registration IDs,
2000
+	 * removes any related registrations that no longer apply,
2001
+	 * and then updates the registration paid fields
2002
+	 *
2003
+	 * @param \EE_Payment $payment
2004
+	 * @param int         $PAY_ID
2005
+	 * @return bool;
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidArgumentException
2008
+	 * @throws ReflectionException
2009
+	 * @throws InvalidDataTypeException
2010
+	 * @throws InvalidInterfaceException
2011
+	 */
2012
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2013
+	{
2014
+		// newly created payments will have nothing recorded for $PAY_ID
2015
+		if ($PAY_ID == 0) {
2016
+			return false;
2017
+		}
2018
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2019
+		if (empty($existing_reg_payment_REG_IDs)) {
2020
+			return false;
2021
+		}
2022
+		/** @type EE_Transaction_Payments $transaction_payments */
2023
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2024
+
2025
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2026
+			$payment,
2027
+			array(
2028
+				array(
2029
+					'PAY_ID' => $payment->ID(),
2030
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2031
+				),
2032
+			)
2033
+		);
2034
+	}
2035
+
2036
+
2037
+	/**
2038
+	 * _update_registration_payments
2039
+	 * this applies the payments to the selected registrations
2040
+	 * but only if they have not already been paid for
2041
+	 *
2042
+	 * @param  EE_Transaction $transaction
2043
+	 * @param \EE_Payment     $payment
2044
+	 * @param array           $REG_IDs
2045
+	 * @return void
2046
+	 * @throws EE_Error
2047
+	 * @throws InvalidArgumentException
2048
+	 * @throws ReflectionException
2049
+	 * @throws RuntimeException
2050
+	 * @throws InvalidDataTypeException
2051
+	 * @throws InvalidInterfaceException
2052
+	 */
2053
+	protected function _update_registration_payments(
2054
+		EE_Transaction $transaction,
2055
+		EE_Payment $payment,
2056
+		$REG_IDs = array()
2057
+	) {
2058
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2059
+		// so let's do that using our set of REG_IDs from the form
2060
+		$registration_query_where_params = array(
2061
+			'REG_ID' => array('IN', $REG_IDs),
2062
+		);
2063
+		// but add in some conditions regarding payment,
2064
+		// so that we don't apply payments to registrations that are free or have already been paid for
2065
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2066
+		if (! $payment->is_a_refund()) {
2067
+			$registration_query_where_params['REG_final_price'] = array('!=', 0);
2068
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2069
+		}
2070
+		$registrations = $transaction->registrations(array($registration_query_where_params));
2071
+		if (! empty($registrations)) {
2072
+			/** @type EE_Payment_Processor $payment_processor */
2073
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2074
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2075
+		}
2076
+	}
2077
+
2078
+
2079
+	/**
2080
+	 * _process_registration_status_change
2081
+	 * This processes requested registration status changes for all the registrations
2082
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2083
+	 *
2084
+	 * @param  EE_Transaction $transaction
2085
+	 * @param array           $REG_IDs
2086
+	 * @return bool
2087
+	 * @throws EE_Error
2088
+	 * @throws InvalidArgumentException
2089
+	 * @throws ReflectionException
2090
+	 * @throws InvalidDataTypeException
2091
+	 * @throws InvalidInterfaceException
2092
+	 */
2093
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2094
+	{
2095
+		// first if there is no change in status then we get out.
2096
+		if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2097
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2098
+		) {
2099
+			// no error message, no change requested, just nothing to do man.
2100
+			return false;
2101
+		}
2102
+		/** @type EE_Transaction_Processor $transaction_processor */
2103
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2104
+
2105
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2106
+		return $transaction_processor->manually_update_registration_statuses(
2107
+			$transaction,
2108
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2109
+			array(array('REG_ID' => array('IN', $REG_IDs)))
2110
+		);
2111
+	}
2112
+
2113
+
2114
+	/**
2115
+	 * _build_payment_json_response
2116
+	 *
2117
+	 * @access public
2118
+	 * @param \EE_Payment $payment
2119
+	 * @param array       $REG_IDs
2120
+	 * @param bool | null $delete_txn_reg_status_change
2121
+	 * @return array
2122
+	 * @throws EE_Error
2123
+	 * @throws InvalidArgumentException
2124
+	 * @throws InvalidDataTypeException
2125
+	 * @throws InvalidInterfaceException
2126
+	 * @throws ReflectionException
2127
+	 */
2128
+	protected function _build_payment_json_response(
2129
+		EE_Payment $payment,
2130
+		$REG_IDs = array(),
2131
+		$delete_txn_reg_status_change = null
2132
+	) {
2133
+		// was the payment deleted ?
2134
+		if (is_bool($delete_txn_reg_status_change)) {
2135
+			return array(
2136
+				'PAY_ID'                       => $payment->ID(),
2137
+				'amount'                       => $payment->amount(),
2138
+				'total_paid'                   => $payment->transaction()->paid(),
2139
+				'txn_status'                   => $payment->transaction()->status_ID(),
2140
+				'pay_status'                   => $payment->STS_ID(),
2141
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2142
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2143
+			);
2144
+		} else {
2145
+			$this->_get_payment_status_array();
2146
+
2147
+			return array(
2148
+				'amount'           => $payment->amount(),
2149
+				'total_paid'       => $payment->transaction()->paid(),
2150
+				'txn_status'       => $payment->transaction()->status_ID(),
2151
+				'pay_status'       => $payment->STS_ID(),
2152
+				'PAY_ID'           => $payment->ID(),
2153
+				'STS_ID'           => $payment->STS_ID(),
2154
+				'status'           => self::$_pay_status[ $payment->STS_ID() ],
2155
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2156
+				'method'           => strtoupper($payment->source()),
2157
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2158
+				'gateway'          => $payment->payment_method()
2159
+					? $payment->payment_method()->admin_name()
2160
+					: esc_html__("Unknown", 'event_espresso'),
2161
+				'gateway_response' => $payment->gateway_response(),
2162
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2163
+				'po_number'        => $payment->po_number(),
2164
+				'extra_accntng'    => $payment->extra_accntng(),
2165
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2166
+			);
2167
+		}
2168
+	}
2169
+
2170
+
2171
+	/**
2172
+	 * delete_payment
2173
+	 *    delete a payment or refund made towards a transaction
2174
+	 *
2175
+	 * @access public
2176
+	 * @return void
2177
+	 * @throws EE_Error
2178
+	 * @throws InvalidArgumentException
2179
+	 * @throws ReflectionException
2180
+	 * @throws InvalidDataTypeException
2181
+	 * @throws InvalidInterfaceException
2182
+	 */
2183
+	public function delete_payment()
2184
+	{
2185
+		$json_response_data = array('return_data' => false);
2186
+		$PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2187
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2188
+			: 0;
2189
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2190
+			'ee_delete_payments',
2191
+			'delete_payment_from_registration_details'
2192
+		);
2193
+		if ($PAY_ID && $can_delete) {
2194
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2195
+				? $this->_req_data['delete_txn_reg_status_change']
2196
+				: false;
2197
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2198
+			if ($payment instanceof EE_Payment) {
2199
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2200
+				/** @type EE_Transaction_Payments $transaction_payments */
2201
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2202
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2203
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2204
+						$payment,
2205
+						$REG_IDs,
2206
+						$delete_txn_reg_status_change
2207
+					);
2208
+					if ($delete_txn_reg_status_change) {
2209
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2210
+						// MAKE sure we also add the delete_txn_req_status_change to the
2211
+						// $_REQUEST global because that's how messages will be looking for it.
2212
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2213
+						$this->_maybe_send_notifications();
2214
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2215
+					}
2216
+				}
2217
+			} else {
2218
+				EE_Error::add_error(
2219
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2220
+					__FILE__,
2221
+					__FUNCTION__,
2222
+					__LINE__
2223
+				);
2224
+			}
2225
+		} else {
2226
+			if ($can_delete) {
2227
+				EE_Error::add_error(
2228
+					esc_html__(
2229
+						'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2230
+						'event_espresso'
2231
+					),
2232
+					__FILE__,
2233
+					__FUNCTION__,
2234
+					__LINE__
2235
+				);
2236
+			} else {
2237
+				EE_Error::add_error(
2238
+					esc_html__(
2239
+						'You do not have access to delete a payment.',
2240
+						'event_espresso'
2241
+					),
2242
+					__FILE__,
2243
+					__FUNCTION__,
2244
+					__LINE__
2245
+				);
2246
+			}
2247
+		}
2248
+		$notices = EE_Error::get_notices(false, false, false);
2249
+		$this->_template_args = array(
2250
+			'data'      => $json_response_data,
2251
+			'success'   => $notices['success'],
2252
+			'error'     => $notices['errors'],
2253
+			'attention' => $notices['attention'],
2254
+		);
2255
+		$this->_return_json();
2256
+	}
2257
+
2258
+
2259
+	/**
2260
+	 * _registration_payment_data_array
2261
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2262
+	 *
2263
+	 * @access protected
2264
+	 * @param array $REG_IDs
2265
+	 * @return array
2266
+	 * @throws EE_Error
2267
+	 * @throws InvalidArgumentException
2268
+	 * @throws InvalidDataTypeException
2269
+	 * @throws InvalidInterfaceException
2270
+	 * @throws ReflectionException
2271
+	 */
2272
+	protected function _registration_payment_data_array($REG_IDs)
2273
+	{
2274
+		$registration_payment_data = array();
2275
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2276
+		if (! empty($REG_IDs)) {
2277
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2278
+			foreach ($registrations as $registration) {
2279
+				if ($registration instanceof EE_Registration) {
2280
+					$registration_payment_data[ $registration->ID() ] = array(
2281
+						'paid'  => $registration->pretty_paid(),
2282
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2283
+					);
2284
+				}
2285
+			}
2286
+		}
2287
+
2288
+		return $registration_payment_data;
2289
+	}
2290
+
2291
+
2292
+	/**
2293
+	 * _maybe_send_notifications
2294
+	 * determines whether or not the admin has indicated that notifications should be sent.
2295
+	 * If so, will toggle a filter switch for delivering registration notices.
2296
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2297
+	 *
2298
+	 * @access protected
2299
+	 * @param \EE_Payment | null $payment
2300
+	 */
2301
+	protected function _maybe_send_notifications($payment = null)
2302
+	{
2303
+		switch ($payment instanceof EE_Payment) {
2304
+			// payment notifications
2305
+			case true:
2306
+				if (isset(
2307
+					$this->_req_data['txn_payments'],
2308
+					$this->_req_data['txn_payments']['send_notifications']
2309
+				)
2310
+					&& filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2311
+				) {
2312
+					$this->_process_payment_notification($payment);
2313
+				}
2314
+				break;
2315
+			// registration notifications
2316
+			case false:
2317
+				if (isset(
2318
+					$this->_req_data['txn_reg_status_change'],
2319
+					$this->_req_data['txn_reg_status_change']['send_notifications']
2320
+				)
2321
+					&& filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2322
+				) {
2323
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2324
+				}
2325
+				break;
2326
+		}
2327
+	}
2328
+
2329
+
2330
+	/**
2331
+	 * _send_payment_reminder
2332
+	 *    generates HTML for the View Transaction Details Admin page
2333
+	 *
2334
+	 * @access protected
2335
+	 * @return void
2336
+	 * @throws EE_Error
2337
+	 * @throws InvalidArgumentException
2338
+	 * @throws InvalidDataTypeException
2339
+	 * @throws InvalidInterfaceException
2340
+	 */
2341
+	protected function _send_payment_reminder()
2342
+	{
2343
+		$TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2344
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2345
+		$query_args = isset($this->_req_data['redirect_to']) ? array(
2346
+			'action' => $this->_req_data['redirect_to'],
2347
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2348
+		) : array();
2349
+		do_action(
2350
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2351
+			$transaction
2352
+		);
2353
+		$this->_redirect_after_action(
2354
+			false,
2355
+			esc_html__('payment reminder', 'event_espresso'),
2356
+			esc_html__('sent', 'event_espresso'),
2357
+			$query_args,
2358
+			true
2359
+		);
2360
+	}
2361
+
2362
+
2363
+	/**
2364
+	 *  get_transactions
2365
+	 *    get transactions for given parameters (used by list table)
2366
+	 *
2367
+	 * @param  int     $perpage how many transactions displayed per page
2368
+	 * @param  boolean $count   return the count or objects
2369
+	 * @param string   $view
2370
+	 * @return mixed int = count || array of transaction objects
2371
+	 * @throws EE_Error
2372
+	 * @throws InvalidArgumentException
2373
+	 * @throws InvalidDataTypeException
2374
+	 * @throws InvalidInterfaceException
2375
+	 */
2376
+	public function get_transactions($perpage, $count = false, $view = '')
2377
+	{
2378
+
2379
+		$TXN = EEM_Transaction::instance();
2380
+
2381
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2382
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2383
+			: date(
2384
+				'm/d/Y',
2385
+				strtotime('-10 year')
2386
+			);
2387
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
2388
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2389
+			: date('m/d/Y');
2390
+
2391
+		// make sure our timestamps start and end right at the boundaries for each day
2392
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2393
+		$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2394
+
2395
+
2396
+		// convert to timestamps
2397
+		$start_date = strtotime($start_date);
2398
+		$end_date = strtotime($end_date);
2399
+
2400
+		// makes sure start date is the lowest value and vice versa
2401
+		$start_date = min($start_date, $end_date);
2402
+		$end_date = max($start_date, $end_date);
2403
+
2404
+		// convert to correct format for query
2405
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2406
+			'TXN_timestamp',
2407
+			date('Y-m-d H:i:s', $start_date),
2408
+			'Y-m-d H:i:s'
2409
+		);
2410
+		$end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2411
+			'TXN_timestamp',
2412
+			date('Y-m-d H:i:s', $end_date),
2413
+			'Y-m-d H:i:s'
2414
+		);
2415
+
2416
+
2417
+		// set orderby
2418
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2419
+
2420
+		switch ($this->_req_data['orderby']) {
2421
+			case 'TXN_ID':
2422
+				$orderby = 'TXN_ID';
2423
+				break;
2424
+			case 'ATT_fname':
2425
+				$orderby = 'Registration.Attendee.ATT_fname';
2426
+				break;
2427
+			case 'event_name':
2428
+				$orderby = 'Registration.Event.EVT_name';
2429
+				break;
2430
+			default: // 'TXN_timestamp'
2431
+				$orderby = 'TXN_timestamp';
2432
+		}
2433
+
2434
+		$sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2435
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2436
+		$per_page = ! empty($perpage) ? $perpage : 10;
2437
+		$per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2438
+
2439
+		$offset = ($current_page - 1) * $per_page;
2440
+		$limit = array($offset, $per_page);
2441
+
2442
+		$_where = array(
2443
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2444
+			'Registration.REG_count' => 1,
2445
+		);
2446
+
2447
+		if (isset($this->_req_data['EVT_ID'])) {
2448
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2449
+		}
2450
+
2451
+		if (isset($this->_req_data['s'])) {
2452
+			$search_string = '%' . $this->_req_data['s'] . '%';
2453
+			$_where['OR'] = array(
2454
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2455
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2456
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2457
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2458
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2459
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2460
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2461
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2462
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2463
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2464
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2465
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2466
+				'Registration.REG_code'               => array('LIKE', $search_string),
2467
+				'Registration.REG_count'              => array('LIKE', $search_string),
2468
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2469
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2470
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2471
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2472
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2473
+				'TXN_session_data'                    => array('LIKE', $search_string),
2474
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2475
+			);
2476
+		}
2477
+
2478
+		// failed transactions
2479
+		$failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2480
+				  || ($count && $view === 'failed');
2481
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2482
+					 || ($count && $view === 'abandoned');
2483
+		$incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2484
+					  || ($count && $view === 'incomplete');
2485
+
2486
+		if ($failed) {
2487
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2488
+		} elseif ($abandoned) {
2489
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2490
+		} elseif ($incomplete) {
2491
+			$_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2492
+		} else {
2493
+			$_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2494
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2495
+		}
2496
+
2497
+		$query_params = apply_filters(
2498
+			'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2499
+			array(
2500
+				$_where,
2501
+				'order_by'                 => array($orderby => $sort),
2502
+				'limit'                    => $limit,
2503
+				'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2504
+			),
2505
+			$this->_req_data,
2506
+			$view,
2507
+			$count
2508
+		);
2509
+
2510
+		$transactions = $count
2511
+			? $TXN->count(array($query_params[0]), 'TXN_ID', true)
2512
+			: $TXN->get_all($query_params);
2513
+
2514
+		return $transactions;
2515
+	}
2516 2516
 }
Please login to merge, or discard this patch.
core/domain/values/assets/BrowserAsset.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -17,144 +17,144 @@
 block discarded – undo
17 17
 abstract class BrowserAsset extends Asset
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $source
22
-     */
23
-    private $source;
24
-
25
-    /**
26
-     * @var array $dependencies
27
-     */
28
-    private $dependencies;
29
-
30
-    /**
31
-     * @var string $version
32
-     */
33
-    private $version;
34
-
35
-
36
-    /**
37
-     * Asset constructor.
38
-     *
39
-     * @param string          $type
40
-     * @param string          $handle
41
-     * @param string          $source
42
-     * @param array           $dependencies
43
-     * @param DomainInterface $domain
44
-     * @throws InvalidDataTypeException
45
-     */
46
-    public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain)
47
-    {
48
-        parent::__construct($type, $handle, $domain);
49
-        $this->setSource($source);
50
-        $this->setDependencies($dependencies);
51
-    }
52
-
53
-
54
-    /**
55
-     * @since 4.9.62.p
56
-     */
57
-    abstract public function enqueueAsset();
58
-
59
-
60
-    /**
61
-     * @return array
62
-     */
63
-    public function dependencies()
64
-    {
65
-        return $this->dependencies;
66
-    }
67
-
68
-
69
-    /**
70
-     * @param array $dependencies
71
-     */
72
-    private function setDependencies(array $dependencies)
73
-    {
74
-        $this->dependencies = $dependencies;
75
-    }
76
-
77
-
78
-    /**
79
-     * @since 4.9.62.p
80
-     * @return bool
81
-     */
82
-    public function hasDependencies()
83
-    {
84
-        return count($this->dependencies) > 0;
85
-    }
86
-
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function source()
92
-    {
93
-        return $this->source;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param string $source
99
-     * @throws InvalidDataTypeException
100
-     */
101
-    private function setSource($source)
102
-    {
103
-        if (! is_string($source)) {
104
-            throw new InvalidDataTypeException(
105
-                '$source',
106
-                $source,
107
-                'string'
108
-            );
109
-        }
110
-        $this->source = $source;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return string
116
-     * @throws InvalidDataTypeException
117
-     * @throws DomainException
118
-     */
119
-    public function version()
120
-    {
121
-        // if version is NOT set and this asset was NOT built for distribution,
122
-        // then set the version equal to the EE core plugin version
123
-        if ($this->version === null && ! $this->isBuiltDistributionSource()) {
124
-            $this->setVersion();
125
-        }
126
-        return $this->version;
127
-    }
128
-
129
-
130
-    /**
131
-     * @param string $version
132
-     * @return BrowserAsset
133
-     * @throws InvalidDataTypeException
134
-     * @throws DomainException
135
-     */
136
-    public function setVersion($version = '')
137
-    {
138
-        if (! is_string($version)) {
139
-            throw new InvalidDataTypeException(
140
-                '$version',
141
-                $version,
142
-                'string'
143
-            );
144
-        }
145
-        if ( $version === '' ) {
146
-            $version = $this->domain->version();
147
-        }
148
-        $this->version = $version;
149
-        return $this;
150
-    }
151
-
152
-
153
-    /**
154
-     * @return bool
155
-     */
156
-    public function isBuiltDistributionSource() {
157
-        return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
158
-               || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
159
-    }
20
+	/**
21
+	 * @var string $source
22
+	 */
23
+	private $source;
24
+
25
+	/**
26
+	 * @var array $dependencies
27
+	 */
28
+	private $dependencies;
29
+
30
+	/**
31
+	 * @var string $version
32
+	 */
33
+	private $version;
34
+
35
+
36
+	/**
37
+	 * Asset constructor.
38
+	 *
39
+	 * @param string          $type
40
+	 * @param string          $handle
41
+	 * @param string          $source
42
+	 * @param array           $dependencies
43
+	 * @param DomainInterface $domain
44
+	 * @throws InvalidDataTypeException
45
+	 */
46
+	public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain)
47
+	{
48
+		parent::__construct($type, $handle, $domain);
49
+		$this->setSource($source);
50
+		$this->setDependencies($dependencies);
51
+	}
52
+
53
+
54
+	/**
55
+	 * @since 4.9.62.p
56
+	 */
57
+	abstract public function enqueueAsset();
58
+
59
+
60
+	/**
61
+	 * @return array
62
+	 */
63
+	public function dependencies()
64
+	{
65
+		return $this->dependencies;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param array $dependencies
71
+	 */
72
+	private function setDependencies(array $dependencies)
73
+	{
74
+		$this->dependencies = $dependencies;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @since 4.9.62.p
80
+	 * @return bool
81
+	 */
82
+	public function hasDependencies()
83
+	{
84
+		return count($this->dependencies) > 0;
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function source()
92
+	{
93
+		return $this->source;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param string $source
99
+	 * @throws InvalidDataTypeException
100
+	 */
101
+	private function setSource($source)
102
+	{
103
+		if (! is_string($source)) {
104
+			throw new InvalidDataTypeException(
105
+				'$source',
106
+				$source,
107
+				'string'
108
+			);
109
+		}
110
+		$this->source = $source;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return string
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws DomainException
118
+	 */
119
+	public function version()
120
+	{
121
+		// if version is NOT set and this asset was NOT built for distribution,
122
+		// then set the version equal to the EE core plugin version
123
+		if ($this->version === null && ! $this->isBuiltDistributionSource()) {
124
+			$this->setVersion();
125
+		}
126
+		return $this->version;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @param string $version
132
+	 * @return BrowserAsset
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws DomainException
135
+	 */
136
+	public function setVersion($version = '')
137
+	{
138
+		if (! is_string($version)) {
139
+			throw new InvalidDataTypeException(
140
+				'$version',
141
+				$version,
142
+				'string'
143
+			);
144
+		}
145
+		if ( $version === '' ) {
146
+			$version = $this->domain->version();
147
+		}
148
+		$this->version = $version;
149
+		return $this;
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return bool
155
+	 */
156
+	public function isBuiltDistributionSource() {
157
+		return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
158
+			   || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
159
+	}
160 160
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     private function setSource($source)
102 102
     {
103
-        if (! is_string($source)) {
103
+        if ( ! is_string($source)) {
104 104
             throw new InvalidDataTypeException(
105 105
                 '$source',
106 106
                 $source,
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function setVersion($version = '')
137 137
     {
138
-        if (! is_string($version)) {
138
+        if ( ! is_string($version)) {
139 139
             throw new InvalidDataTypeException(
140 140
                 '$version',
141 141
                 $version,
142 142
                 'string'
143 143
             );
144 144
         }
145
-        if ( $version === '' ) {
145
+        if ($version === '') {
146 146
             $version = $this->domain->version();
147 147
         }
148 148
         $this->version = $version;
Please login to merge, or discard this patch.
core/bootstrap_espresso.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@  discard block
 block discarded – undo
6 6
  */
7 7
 function espresso_load_error_handling()
8 8
 {
9
-    static $error_handling_loaded = false;
10
-    if ($error_handling_loaded) {
11
-        return;
12
-    }
13
-    // load debugging tools
14
-    if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
-        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
16
-        \EEH_Debug_Tools::instance();
17
-    }
18
-    // load error handling
19
-    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
-        require_once EE_CORE . 'EE_Error.core.php';
21
-    } else {
22
-        wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23
-    }
24
-    $error_handling_loaded = true;
9
+	static $error_handling_loaded = false;
10
+	if ($error_handling_loaded) {
11
+		return;
12
+	}
13
+	// load debugging tools
14
+	if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
+		require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
16
+		\EEH_Debug_Tools::instance();
17
+	}
18
+	// load error handling
19
+	if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
+		require_once EE_CORE . 'EE_Error.core.php';
21
+	} else {
22
+		wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23
+	}
24
+	$error_handling_loaded = true;
25 25
 }
26 26
 
27 27
 
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function espresso_load_required($classname, $full_path_to_file)
37 37
 {
38
-    if (is_readable($full_path_to_file)) {
39
-        require_once $full_path_to_file;
40
-    } else {
41
-        throw new \EE_Error(
42
-            sprintf(
43
-                esc_html__(
44
-                    'The %s class file could not be located or is not readable due to file permissions.',
45
-                    'event_espresso'
46
-                ),
47
-                $classname
48
-            )
49
-        );
50
-    }
38
+	if (is_readable($full_path_to_file)) {
39
+		require_once $full_path_to_file;
40
+	} else {
41
+		throw new \EE_Error(
42
+			sprintf(
43
+				esc_html__(
44
+					'The %s class file could not be located or is not readable due to file permissions.',
45
+					'event_espresso'
46
+				),
47
+				$classname
48
+			)
49
+		);
50
+	}
51 51
 }
52 52
 
53 53
 
@@ -66,48 +66,48 @@  discard block
 block discarded – undo
66 66
  */
67 67
 function bootstrap_espresso()
68 68
 {
69
-    require_once __DIR__ . '/espresso_definitions.php';
70
-    try {
71
-        espresso_load_error_handling();
72
-        // include WordPress shims for functions introduced in later versions of WordPress
73
-        espresso_load_required(
74
-            '',
75
-            EE_CORE . 'wordpress-shims.php'
76
-        );
77
-        espresso_load_required(
78
-            'EEH_Base',
79
-            EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
80
-        );
81
-        espresso_load_required(
82
-            'EEH_File',
83
-            EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
84
-        );
85
-        espresso_load_required(
86
-            'EEH_File',
87
-            EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
88
-        );
89
-        espresso_load_required(
90
-            'EEH_Array',
91
-            EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
92
-        );
93
-        espresso_load_required(
94
-            'EE_Base',
95
-            EE_CORE . 'EE_Base.core.php'
96
-        );
97
-        // instantiate and configure PSR4 autoloader
98
-        espresso_load_required(
99
-            'Psr4Autoloader',
100
-            EE_CORE . 'Psr4Autoloader.php'
101
-        );
102
-        espresso_load_required(
103
-            'EE_Psr4AutoloaderInit',
104
-            EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
105
-        );
106
-        $AutoloaderInit = new EE_Psr4AutoloaderInit();
107
-        $AutoloaderInit->initializeAutoloader();
108
-        new EventEspresso\core\services\bootstrap\BootstrapCore();
109
-    } catch (Exception $e) {
110
-        require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
111
-        new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
112
-    }
69
+	require_once __DIR__ . '/espresso_definitions.php';
70
+	try {
71
+		espresso_load_error_handling();
72
+		// include WordPress shims for functions introduced in later versions of WordPress
73
+		espresso_load_required(
74
+			'',
75
+			EE_CORE . 'wordpress-shims.php'
76
+		);
77
+		espresso_load_required(
78
+			'EEH_Base',
79
+			EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
80
+		);
81
+		espresso_load_required(
82
+			'EEH_File',
83
+			EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
84
+		);
85
+		espresso_load_required(
86
+			'EEH_File',
87
+			EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
88
+		);
89
+		espresso_load_required(
90
+			'EEH_Array',
91
+			EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
92
+		);
93
+		espresso_load_required(
94
+			'EE_Base',
95
+			EE_CORE . 'EE_Base.core.php'
96
+		);
97
+		// instantiate and configure PSR4 autoloader
98
+		espresso_load_required(
99
+			'Psr4Autoloader',
100
+			EE_CORE . 'Psr4Autoloader.php'
101
+		);
102
+		espresso_load_required(
103
+			'EE_Psr4AutoloaderInit',
104
+			EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
105
+		);
106
+		$AutoloaderInit = new EE_Psr4AutoloaderInit();
107
+		$AutoloaderInit->initializeAutoloader();
108
+		new EventEspresso\core\services\bootstrap\BootstrapCore();
109
+	} catch (Exception $e) {
110
+		require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
111
+		new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
         return;
12 12
     }
13 13
     // load debugging tools
14
-    if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
15
-        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
14
+    if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
15
+        require_once EE_HELPERS.'EEH_Debug_Tools.helper.php';
16 16
         \EEH_Debug_Tools::instance();
17 17
     }
18 18
     // load error handling
19
-    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
20
-        require_once EE_CORE . 'EE_Error.core.php';
19
+    if (is_readable(EE_CORE.'EE_Error.core.php')) {
20
+        require_once EE_CORE.'EE_Error.core.php';
21 21
     } else {
22 22
         wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
23 23
     }
@@ -66,48 +66,48 @@  discard block
 block discarded – undo
66 66
  */
67 67
 function bootstrap_espresso()
68 68
 {
69
-    require_once __DIR__ . '/espresso_definitions.php';
69
+    require_once __DIR__.'/espresso_definitions.php';
70 70
     try {
71 71
         espresso_load_error_handling();
72 72
         // include WordPress shims for functions introduced in later versions of WordPress
73 73
         espresso_load_required(
74 74
             '',
75
-            EE_CORE . 'wordpress-shims.php'
75
+            EE_CORE.'wordpress-shims.php'
76 76
         );
77 77
         espresso_load_required(
78 78
             'EEH_Base',
79
-            EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
79
+            EE_CORE.'helpers'.DS.'EEH_Base.helper.php'
80 80
         );
81 81
         espresso_load_required(
82 82
             'EEH_File',
83
-            EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
83
+            EE_CORE.'interfaces'.DS.'EEHI_File.interface.php'
84 84
         );
85 85
         espresso_load_required(
86 86
             'EEH_File',
87
-            EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
87
+            EE_CORE.'helpers'.DS.'EEH_File.helper.php'
88 88
         );
89 89
         espresso_load_required(
90 90
             'EEH_Array',
91
-            EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
91
+            EE_CORE.'helpers'.DS.'EEH_Array.helper.php'
92 92
         );
93 93
         espresso_load_required(
94 94
             'EE_Base',
95
-            EE_CORE . 'EE_Base.core.php'
95
+            EE_CORE.'EE_Base.core.php'
96 96
         );
97 97
         // instantiate and configure PSR4 autoloader
98 98
         espresso_load_required(
99 99
             'Psr4Autoloader',
100
-            EE_CORE . 'Psr4Autoloader.php'
100
+            EE_CORE.'Psr4Autoloader.php'
101 101
         );
102 102
         espresso_load_required(
103 103
             'EE_Psr4AutoloaderInit',
104
-            EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
104
+            EE_CORE.'EE_Psr4AutoloaderInit.core.php'
105 105
         );
106 106
         $AutoloaderInit = new EE_Psr4AutoloaderInit();
107 107
         $AutoloaderInit->initializeAutoloader();
108 108
         new EventEspresso\core\services\bootstrap\BootstrapCore();
109 109
     } catch (Exception $e) {
110
-        require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
110
+        require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php';
111 111
         new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
112 112
     }
113 113
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1446 added lines, -1446 removed lines patch added patch discarded remove patch
@@ -27,474 +27,474 @@  discard block
 block discarded – undo
27 27
 {
28 28
 
29 29
 
30
-    /**
31
-     * This gets set in _setup_cpt
32
-     * It will contain the object for the custom post type.
33
-     *
34
-     * @var EE_CPT_Base
35
-     */
36
-    protected $_cpt_object;
37
-
38
-
39
-    /**
40
-     * a boolean flag to set whether the current route is a cpt route or not.
41
-     *
42
-     * @var bool
43
-     */
44
-    protected $_cpt_route = false;
45
-
46
-
47
-    /**
48
-     * This property allows cpt classes to define multiple routes as cpt routes.
49
-     * //in this array we define what the custom post type for this route is.
50
-     * array(
51
-     * 'route_name' => 'custom_post_type_slug'
52
-     * )
53
-     *
54
-     * @var array
55
-     */
56
-    protected $_cpt_routes = array();
57
-
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
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
-     * _cpt_model_names property should be in the following format: array(
75
-     * 'route_defined_by_action_param' => 'Model_Name')
76
-     *
77
-     * @var array $_cpt_model_names
78
-     */
79
-    protected $_cpt_model_names = array();
80
-
81
-
82
-    /**
83
-     * @var EE_CPT_Base
84
-     */
85
-    protected $_cpt_model_obj = false;
86
-
87
-
88
-    /**
89
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
-     * Registration of containers should be done before load_page_dependencies() is run.
93
-     *
94
-     * @var array()
95
-     */
96
-    protected $_autosave_containers = array();
97
-    protected $_autosave_fields = array();
98
-
99
-    /**
100
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_pagenow_map;
106
-
107
-
108
-    /**
109
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
-     *
115
-     * @access protected
116
-     * @abstract
117
-     * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
-     * @return void
120
-     */
121
-    abstract protected function _insert_update_cpt_item($post_id, $post);
122
-
123
-
124
-    /**
125
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
-     *
127
-     * @abstract
128
-     * @access public
129
-     * @param  string $post_id The ID of the cpt that was trashed
130
-     * @return void
131
-     */
132
-    abstract public function trash_cpt_item($post_id);
133
-
134
-
135
-    /**
136
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
-     *
138
-     * @param  string $post_id theID of the cpt that was untrashed
139
-     * @return void
140
-     */
141
-    abstract public function restore_cpt_item($post_id);
142
-
143
-
144
-    /**
145
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
-     * from the db
147
-     *
148
-     * @param  string $post_id the ID of the cpt that was deleted
149
-     * @return void
150
-     */
151
-    abstract public function delete_cpt_item($post_id);
152
-
153
-
154
-    /**
155
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
-     *
157
-     * @access protected
158
-     * @return void
159
-     */
160
-    protected function _before_page_setup()
161
-    {
162
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
-        $this->_cpt_routes = array_merge(
164
-            array(
165
-                'create_new' => $this->page_slug,
166
-                'edit'       => $this->page_slug,
167
-                'trash'      => $this->page_slug,
168
-            ),
169
-            $this->_cpt_routes
170
-        );
171
-        // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
-            : get_post_type_object($page);
175
-        // tweak pagenow for page loading.
176
-        if (! $this->_pagenow_map) {
177
-            $this->_pagenow_map = array(
178
-                'create_new' => 'post-new.php',
179
-                'edit'       => 'post.php',
180
-                'trash'      => 'post.php',
181
-            );
182
-        }
183
-        add_action('current_screen', array($this, 'modify_pagenow'));
184
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
-        // get current page from autosave
186
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
-            : null;
189
-        $this->_current_page = isset($this->_req_data['current_page'])
190
-            ? $this->_req_data['current_page']
191
-            : $current_page;
192
-        // autosave... make sure its only for the correct page
193
-        // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
-        // setup autosave ajax hook
195
-        // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
-        // }
197
-    }
198
-
199
-
200
-    /**
201
-     * Simply ensure that we simulate the correct post route for cpt screens
202
-     *
203
-     * @param WP_Screen $current_screen
204
-     * @return void
205
-     */
206
-    public function modify_pagenow($current_screen)
207
-    {
208
-        global $pagenow, $hook_suffix;
209
-        // possibly reset pagenow.
210
-        if (! empty($this->_req_data['page'])
211
-            && $this->_req_data['page'] == $this->page_slug
212
-            && ! empty($this->_req_data['action'])
213
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
-        ) {
215
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
-            $hook_suffix = $pagenow;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This method is used to register additional autosave containers to the _autosave_containers property.
223
-     *
224
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
-     *       automatically register the id for the post metabox as a container.
226
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
-     *                    you would send along the id of a metabox container.
228
-     * @return void
229
-     */
230
-    protected function _register_autosave_containers($ids)
231
-    {
232
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
-    }
234
-
235
-
236
-    /**
237
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
-     */
240
-    protected function _set_autosave_containers()
241
-    {
242
-        global $wp_meta_boxes;
243
-        $containers = array();
244
-        if (empty($wp_meta_boxes)) {
245
-            return;
246
-        }
247
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
-        foreach ($current_metaboxes as $box_context) {
249
-            foreach ($box_context as $box_details) {
250
-                foreach ($box_details as $box) {
251
-                    if (is_array($box['callback'])
252
-                        && (
253
-                            $box['callback'][0] instanceof EE_Admin_Page
254
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
255
-                        )
256
-                    ) {
257
-                        $containers[] = $box['id'];
258
-                    }
259
-                }
260
-            }
261
-        }
262
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
-        // add hidden inputs container
264
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
-    }
266
-
267
-
268
-    protected function _load_autosave_scripts_styles()
269
-    {
270
-        /*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 );
30
+	/**
31
+	 * This gets set in _setup_cpt
32
+	 * It will contain the object for the custom post type.
33
+	 *
34
+	 * @var EE_CPT_Base
35
+	 */
36
+	protected $_cpt_object;
37
+
38
+
39
+	/**
40
+	 * a boolean flag to set whether the current route is a cpt route or not.
41
+	 *
42
+	 * @var bool
43
+	 */
44
+	protected $_cpt_route = false;
45
+
46
+
47
+	/**
48
+	 * This property allows cpt classes to define multiple routes as cpt routes.
49
+	 * //in this array we define what the custom post type for this route is.
50
+	 * array(
51
+	 * 'route_name' => 'custom_post_type_slug'
52
+	 * )
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $_cpt_routes = array();
57
+
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
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
+	 * _cpt_model_names property should be in the following format: array(
75
+	 * 'route_defined_by_action_param' => 'Model_Name')
76
+	 *
77
+	 * @var array $_cpt_model_names
78
+	 */
79
+	protected $_cpt_model_names = array();
80
+
81
+
82
+	/**
83
+	 * @var EE_CPT_Base
84
+	 */
85
+	protected $_cpt_model_obj = false;
86
+
87
+
88
+	/**
89
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
+	 * Registration of containers should be done before load_page_dependencies() is run.
93
+	 *
94
+	 * @var array()
95
+	 */
96
+	protected $_autosave_containers = array();
97
+	protected $_autosave_fields = array();
98
+
99
+	/**
100
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_pagenow_map;
106
+
107
+
108
+	/**
109
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
+	 *
115
+	 * @access protected
116
+	 * @abstract
117
+	 * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
+	 * @return void
120
+	 */
121
+	abstract protected function _insert_update_cpt_item($post_id, $post);
122
+
123
+
124
+	/**
125
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
+	 *
127
+	 * @abstract
128
+	 * @access public
129
+	 * @param  string $post_id The ID of the cpt that was trashed
130
+	 * @return void
131
+	 */
132
+	abstract public function trash_cpt_item($post_id);
133
+
134
+
135
+	/**
136
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
+	 *
138
+	 * @param  string $post_id theID of the cpt that was untrashed
139
+	 * @return void
140
+	 */
141
+	abstract public function restore_cpt_item($post_id);
142
+
143
+
144
+	/**
145
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
+	 * from the db
147
+	 *
148
+	 * @param  string $post_id the ID of the cpt that was deleted
149
+	 * @return void
150
+	 */
151
+	abstract public function delete_cpt_item($post_id);
152
+
153
+
154
+	/**
155
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
+	 *
157
+	 * @access protected
158
+	 * @return void
159
+	 */
160
+	protected function _before_page_setup()
161
+	{
162
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
+		$this->_cpt_routes = array_merge(
164
+			array(
165
+				'create_new' => $this->page_slug,
166
+				'edit'       => $this->page_slug,
167
+				'trash'      => $this->page_slug,
168
+			),
169
+			$this->_cpt_routes
170
+		);
171
+		// let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
+			? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
+			: get_post_type_object($page);
175
+		// tweak pagenow for page loading.
176
+		if (! $this->_pagenow_map) {
177
+			$this->_pagenow_map = array(
178
+				'create_new' => 'post-new.php',
179
+				'edit'       => 'post.php',
180
+				'trash'      => 'post.php',
181
+			);
182
+		}
183
+		add_action('current_screen', array($this, 'modify_pagenow'));
184
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
+		// get current page from autosave
186
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
+			: null;
189
+		$this->_current_page = isset($this->_req_data['current_page'])
190
+			? $this->_req_data['current_page']
191
+			: $current_page;
192
+		// autosave... make sure its only for the correct page
193
+		// if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
+		// setup autosave ajax hook
195
+		// add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
+		// }
197
+	}
198
+
199
+
200
+	/**
201
+	 * Simply ensure that we simulate the correct post route for cpt screens
202
+	 *
203
+	 * @param WP_Screen $current_screen
204
+	 * @return void
205
+	 */
206
+	public function modify_pagenow($current_screen)
207
+	{
208
+		global $pagenow, $hook_suffix;
209
+		// possibly reset pagenow.
210
+		if (! empty($this->_req_data['page'])
211
+			&& $this->_req_data['page'] == $this->page_slug
212
+			&& ! empty($this->_req_data['action'])
213
+			&& isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
+		) {
215
+			$pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
+			$hook_suffix = $pagenow;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
223
+	 *
224
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
+	 *       automatically register the id for the post metabox as a container.
226
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
+	 *                    you would send along the id of a metabox container.
228
+	 * @return void
229
+	 */
230
+	protected function _register_autosave_containers($ids)
231
+	{
232
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
+	}
234
+
235
+
236
+	/**
237
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
+	 */
240
+	protected function _set_autosave_containers()
241
+	{
242
+		global $wp_meta_boxes;
243
+		$containers = array();
244
+		if (empty($wp_meta_boxes)) {
245
+			return;
246
+		}
247
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
+		foreach ($current_metaboxes as $box_context) {
249
+			foreach ($box_context as $box_details) {
250
+				foreach ($box_details as $box) {
251
+					if (is_array($box['callback'])
252
+						&& (
253
+							$box['callback'][0] instanceof EE_Admin_Page
254
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
255
+						)
256
+					) {
257
+						$containers[] = $box['id'];
258
+					}
259
+				}
260
+			}
261
+		}
262
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
+		// add hidden inputs container
264
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
+	}
266
+
267
+
268
+	protected function _load_autosave_scripts_styles()
269
+	{
270
+		/*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 );
271 271
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
272 272
 
273
-        // filter _autosave_containers
274
-        $containers = apply_filters(
275
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
-            $this->_autosave_containers,
277
-            $this
278
-        );
279
-        $containers = apply_filters(
280
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
-            $containers,
282
-            $this
283
-        );
284
-
285
-        wp_localize_script(
286
-            'event_editor_js',
287
-            'EE_AUTOSAVE_IDS',
288
-            $containers
289
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
-
291
-        $unsaved_data_msg = array(
292
-            'eventmsg'     => sprintf(
293
-                __(
294
-                    "The changes you made to this %s will be lost if you navigate away from this page.",
295
-                    'event_espresso'
296
-                ),
297
-                $this->_cpt_object->labels->singular_name
298
-            ),
299
-            'inputChanged' => 0,
300
-        );
301
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
302
-    }
303
-
304
-
305
-    public function load_page_dependencies()
306
-    {
307
-        try {
308
-            $this->_load_page_dependencies();
309
-        } catch (EE_Error $e) {
310
-            $e->get_error();
311
-        }
312
-    }
313
-
314
-
315
-    /**
316
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
317
-     *
318
-     * @access protected
319
-     * @return void
320
-     */
321
-    protected function _load_page_dependencies()
322
-    {
323
-        // we only add stuff if this is a cpt_route!
324
-        if (! $this->_cpt_route) {
325
-            parent::_load_page_dependencies();
326
-            return;
327
-        }
328
-        // now let's do some automatic filters into the wp_system
329
-        // and we'll check to make sure the CHILD class
330
-        // automatically has the required methods in place.
331
-        // the following filters are for setting all the redirects
332
-        // on DEFAULT WP custom post type actions
333
-        // let's add a hidden input to the post-edit form
334
-        // so we know when we have to trigger our custom redirects!
335
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
336
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
337
-        // inject our Admin page nav tabs...
338
-        // let's make sure the nav tabs are set if they aren't already
339
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
340
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
341
-        // modify the post_updated messages array
342
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
343
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
344
-        // cpts use the same format for shortlinks as posts!
345
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
346
-        // This basically allows us to change the title of the "publish" metabox area
347
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
348
-        if (! empty($this->_labels['publishbox'])) {
349
-            $box_label = is_array($this->_labels['publishbox'])
350
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
351
-                ? $this->_labels['publishbox'][ $this->_req_action ]
352
-                : $this->_labels['publishbox'];
353
-            add_meta_box(
354
-                'submitdiv',
355
-                $box_label,
356
-                'post_submit_meta_box',
357
-                $this->_cpt_routes[ $this->_req_action ],
358
-                'side',
359
-                'core'
360
-            );
361
-        }
362
-        // let's add page_templates metabox if this cpt added support for it.
363
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
364
-            add_meta_box(
365
-                'page_templates',
366
-                __('Page Template', 'event_espresso'),
367
-                array($this, 'page_template_meta_box'),
368
-                $this->_cpt_routes[ $this->_req_action ],
369
-                'side',
370
-                'default'
371
-            );
372
-        }
373
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
374
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
375
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
376
-        }
377
-        // add preview button
378
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
379
-        // insert our own post_stati dropdown
380
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
381
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
382
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
383
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
384
-        }
385
-        // This allows for adding additional stuff after the title field on the wp post edit form.
386
-        // This is also before the wp_editor for post description field.
387
-        if (method_exists($this, 'edit_form_after_title')) {
388
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
389
-        }
390
-        /**
391
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
392
-         */
393
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
394
-        parent::_load_page_dependencies();
395
-        // notice we are ALSO going to load the pagenow hook set for this route
396
-        // (see _before_page_setup for the reset of the pagenow global ).
397
-        // This is for any plugins that are doing things properly
398
-        // and hooking into the load page hook for core wp cpt routes.
399
-        global $pagenow;
400
-        do_action('load-' . $pagenow);
401
-        $this->modify_current_screen();
402
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
403
-        // we route REALLY early.
404
-        try {
405
-            $this->_route_admin_request();
406
-        } catch (EE_Error $e) {
407
-            $e->get_error();
408
-        }
409
-    }
410
-
411
-
412
-    /**
413
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
414
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
415
-     * route instead.
416
-     *
417
-     * @param string $good_protocol_url The escaped url.
418
-     * @param string $original_url      The original url.
419
-     * @param string $_context          The context sent to the esc_url method.
420
-     * @return string possibly a new url for our route.
421
-     */
422
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
423
-    {
424
-        $routes_to_match = array(
425
-            0 => array(
426
-                'edit.php?post_type=espresso_attendees',
427
-                'admin.php?page=espresso_registrations&action=contact_list',
428
-            ),
429
-            1 => array(
430
-                'edit.php?post_type=' . $this->_cpt_object->name,
431
-                'admin.php?page=' . $this->_cpt_object->name,
432
-            ),
433
-        );
434
-        foreach ($routes_to_match as $route_matches) {
435
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
436
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
437
-            }
438
-        }
439
-        return $good_protocol_url;
440
-    }
441
-
442
-
443
-    /**
444
-     * Determine whether the current cpt supports page templates or not.
445
-     *
446
-     * @since %VER%
447
-     * @param string $cpt_name The cpt slug we're checking on.
448
-     * @return bool True supported, false not.
449
-     * @throws InvalidArgumentException
450
-     * @throws InvalidDataTypeException
451
-     * @throws InvalidInterfaceException
452
-     */
453
-    private function _supports_page_templates($cpt_name)
454
-    {
455
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
456
-        $custom_post_types = LoaderFactory::getLoader()->getShared(
457
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
458
-        );
459
-        $cpt_args = $custom_post_types->getDefinitions();
460
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
461
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
462
-
463
-        // if the installed version of WP is > 4.7 we do some additional checks.
464
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
465
-            $post_templates = wp_get_theme()->get_post_templates();
466
-            // if there are $post_templates for this cpt, then we return false for this method because
467
-            // that means we aren't going to load our page template manager and leave that up to the native
468
-            // cpt template manager.
469
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
470
-        }
471
-
472
-        return $cpt_has_support;
473
-    }
474
-
475
-
476
-    /**
477
-     * Callback for the page_templates metabox selector.
478
-     *
479
-     * @since %VER%
480
-     * @return void
481
-     */
482
-    public function page_template_meta_box()
483
-    {
484
-        global $post;
485
-        $template = '';
486
-
487
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
488
-            $page_template_count = count(get_page_templates());
489
-        } else {
490
-            $page_template_count = count(get_page_templates($post));
491
-        };
492
-
493
-        if ($page_template_count) {
494
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
495
-            $template = ! empty($page_template) ? $page_template : '';
496
-        }
497
-        ?>
273
+		// filter _autosave_containers
274
+		$containers = apply_filters(
275
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
+			$this->_autosave_containers,
277
+			$this
278
+		);
279
+		$containers = apply_filters(
280
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
+			$containers,
282
+			$this
283
+		);
284
+
285
+		wp_localize_script(
286
+			'event_editor_js',
287
+			'EE_AUTOSAVE_IDS',
288
+			$containers
289
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
+
291
+		$unsaved_data_msg = array(
292
+			'eventmsg'     => sprintf(
293
+				__(
294
+					"The changes you made to this %s will be lost if you navigate away from this page.",
295
+					'event_espresso'
296
+				),
297
+				$this->_cpt_object->labels->singular_name
298
+			),
299
+			'inputChanged' => 0,
300
+		);
301
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
302
+	}
303
+
304
+
305
+	public function load_page_dependencies()
306
+	{
307
+		try {
308
+			$this->_load_page_dependencies();
309
+		} catch (EE_Error $e) {
310
+			$e->get_error();
311
+		}
312
+	}
313
+
314
+
315
+	/**
316
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
317
+	 *
318
+	 * @access protected
319
+	 * @return void
320
+	 */
321
+	protected function _load_page_dependencies()
322
+	{
323
+		// we only add stuff if this is a cpt_route!
324
+		if (! $this->_cpt_route) {
325
+			parent::_load_page_dependencies();
326
+			return;
327
+		}
328
+		// now let's do some automatic filters into the wp_system
329
+		// and we'll check to make sure the CHILD class
330
+		// automatically has the required methods in place.
331
+		// the following filters are for setting all the redirects
332
+		// on DEFAULT WP custom post type actions
333
+		// let's add a hidden input to the post-edit form
334
+		// so we know when we have to trigger our custom redirects!
335
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
336
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
337
+		// inject our Admin page nav tabs...
338
+		// let's make sure the nav tabs are set if they aren't already
339
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
340
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
341
+		// modify the post_updated messages array
342
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
343
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
344
+		// cpts use the same format for shortlinks as posts!
345
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
346
+		// This basically allows us to change the title of the "publish" metabox area
347
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
348
+		if (! empty($this->_labels['publishbox'])) {
349
+			$box_label = is_array($this->_labels['publishbox'])
350
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
351
+				? $this->_labels['publishbox'][ $this->_req_action ]
352
+				: $this->_labels['publishbox'];
353
+			add_meta_box(
354
+				'submitdiv',
355
+				$box_label,
356
+				'post_submit_meta_box',
357
+				$this->_cpt_routes[ $this->_req_action ],
358
+				'side',
359
+				'core'
360
+			);
361
+		}
362
+		// let's add page_templates metabox if this cpt added support for it.
363
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
364
+			add_meta_box(
365
+				'page_templates',
366
+				__('Page Template', 'event_espresso'),
367
+				array($this, 'page_template_meta_box'),
368
+				$this->_cpt_routes[ $this->_req_action ],
369
+				'side',
370
+				'default'
371
+			);
372
+		}
373
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
374
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
375
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
376
+		}
377
+		// add preview button
378
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
379
+		// insert our own post_stati dropdown
380
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
381
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
382
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
383
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
384
+		}
385
+		// This allows for adding additional stuff after the title field on the wp post edit form.
386
+		// This is also before the wp_editor for post description field.
387
+		if (method_exists($this, 'edit_form_after_title')) {
388
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
389
+		}
390
+		/**
391
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
392
+		 */
393
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
394
+		parent::_load_page_dependencies();
395
+		// notice we are ALSO going to load the pagenow hook set for this route
396
+		// (see _before_page_setup for the reset of the pagenow global ).
397
+		// This is for any plugins that are doing things properly
398
+		// and hooking into the load page hook for core wp cpt routes.
399
+		global $pagenow;
400
+		do_action('load-' . $pagenow);
401
+		$this->modify_current_screen();
402
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
403
+		// we route REALLY early.
404
+		try {
405
+			$this->_route_admin_request();
406
+		} catch (EE_Error $e) {
407
+			$e->get_error();
408
+		}
409
+	}
410
+
411
+
412
+	/**
413
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
414
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
415
+	 * route instead.
416
+	 *
417
+	 * @param string $good_protocol_url The escaped url.
418
+	 * @param string $original_url      The original url.
419
+	 * @param string $_context          The context sent to the esc_url method.
420
+	 * @return string possibly a new url for our route.
421
+	 */
422
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
423
+	{
424
+		$routes_to_match = array(
425
+			0 => array(
426
+				'edit.php?post_type=espresso_attendees',
427
+				'admin.php?page=espresso_registrations&action=contact_list',
428
+			),
429
+			1 => array(
430
+				'edit.php?post_type=' . $this->_cpt_object->name,
431
+				'admin.php?page=' . $this->_cpt_object->name,
432
+			),
433
+		);
434
+		foreach ($routes_to_match as $route_matches) {
435
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
436
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
437
+			}
438
+		}
439
+		return $good_protocol_url;
440
+	}
441
+
442
+
443
+	/**
444
+	 * Determine whether the current cpt supports page templates or not.
445
+	 *
446
+	 * @since %VER%
447
+	 * @param string $cpt_name The cpt slug we're checking on.
448
+	 * @return bool True supported, false not.
449
+	 * @throws InvalidArgumentException
450
+	 * @throws InvalidDataTypeException
451
+	 * @throws InvalidInterfaceException
452
+	 */
453
+	private function _supports_page_templates($cpt_name)
454
+	{
455
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
456
+		$custom_post_types = LoaderFactory::getLoader()->getShared(
457
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
458
+		);
459
+		$cpt_args = $custom_post_types->getDefinitions();
460
+		$cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
461
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
462
+
463
+		// if the installed version of WP is > 4.7 we do some additional checks.
464
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
465
+			$post_templates = wp_get_theme()->get_post_templates();
466
+			// if there are $post_templates for this cpt, then we return false for this method because
467
+			// that means we aren't going to load our page template manager and leave that up to the native
468
+			// cpt template manager.
469
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
470
+		}
471
+
472
+		return $cpt_has_support;
473
+	}
474
+
475
+
476
+	/**
477
+	 * Callback for the page_templates metabox selector.
478
+	 *
479
+	 * @since %VER%
480
+	 * @return void
481
+	 */
482
+	public function page_template_meta_box()
483
+	{
484
+		global $post;
485
+		$template = '';
486
+
487
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
488
+			$page_template_count = count(get_page_templates());
489
+		} else {
490
+			$page_template_count = count(get_page_templates($post));
491
+		};
492
+
493
+		if ($page_template_count) {
494
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
495
+			$template = ! empty($page_template) ? $page_template : '';
496
+		}
497
+		?>
498 498
         <p><strong><?php _e('Template', 'event_espresso') ?></strong></p>
499 499
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select
500 500
         name="page_template" id="page_template">
@@ -502,468 +502,468 @@  discard block
 block discarded – undo
502 502
         <?php page_template_dropdown($template); ?>
503 503
     </select>
504 504
         <?php
505
-    }
506
-
507
-
508
-    /**
509
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
510
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
511
-     *
512
-     * @param  string $return    the current html
513
-     * @param  int    $id        the post id for the page
514
-     * @param  string $new_title What the title is
515
-     * @param  string $new_slug  what the slug is
516
-     * @return string            The new html string for the permalink area
517
-     */
518
-    public function preview_button_html($return, $id, $new_title, $new_slug)
519
-    {
520
-        $post = get_post($id);
521
-        if ('publish' !== get_post_status($post)) {
522
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
523
-                       . get_preview_post_link($id)
524
-                       . '" class="button button-small">'
525
-                       . __('Preview', 'event_espresso')
526
-                       . '</a></span>'
527
-                       . "\n";
528
-        }
529
-        return $return;
530
-    }
531
-
532
-
533
-    /**
534
-     * add our custom post stati dropdown on the wp post page for this cpt
535
-     *
536
-     * @return void
537
-     */
538
-    public function custom_post_stati_dropdown()
539
-    {
540
-
541
-        $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
542
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
543
-            ? $statuses[ $this->_cpt_model_obj->status() ]
544
-            : '';
545
-        $template_args = array(
546
-            'cur_status'            => $this->_cpt_model_obj->status(),
547
-            'statuses'              => $statuses,
548
-            'cur_status_label'      => $cur_status_label,
549
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
550
-        );
551
-        // we'll add a trash post status (WP doesn't add one for some reason)
552
-        if ($this->_cpt_model_obj->status() === 'trash') {
553
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
554
-            $statuses['trash'] = __('Trashed', 'event_espresso');
555
-            $template_args['statuses'] = $statuses;
556
-        }
557
-
558
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
559
-        EEH_Template::display_template($template, $template_args);
560
-    }
561
-
562
-
563
-    public function setup_autosave_hooks()
564
-    {
565
-        $this->_set_autosave_containers();
566
-        $this->_load_autosave_scripts_styles();
567
-    }
568
-
569
-
570
-    /**
571
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
572
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
573
-     * for the nonce in here, but then this method looks for two things:
574
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
575
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
576
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
577
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
578
-     * template args.
579
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
580
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
581
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
582
-     *    $this->_template_args['data']['items'] = array(
583
-     *        'event-datetime-ids' => '1,2,3';
584
-     *    );
585
-     *    Keep in mind the following things:
586
-     *    - "where" index is for the input with the id as that string.
587
-     *    - "what" index is what will be used for the value of that input.
588
-     *
589
-     * @return void
590
-     */
591
-    public function do_extra_autosave_stuff()
592
-    {
593
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
594
-        $nonce = isset($this->_req_data['autosavenonce'])
595
-            ? $this->_req_data['autosavenonce']
596
-            : null;
597
-        $this->_verify_nonce($nonce, 'autosave');
598
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
599
-        if (! defined('DOING_AUTOSAVE')) {
600
-            define('DOING_AUTOSAVE', true);
601
-        }
602
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
603
-        $autosave = "_ee_autosave_{$this->_current_view}";
604
-        if (method_exists($this, $autosave)) {
605
-            $this->$autosave();
606
-        } else {
607
-            $this->_template_args['success'] = true;
608
-        }
609
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
610
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
611
-        // now let's return json
612
-        $this->_return_json();
613
-    }
614
-
615
-
616
-    /**
617
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
-     *
621
-     * @access protected
622
-     * @throws EE_Error
623
-     * @return void
624
-     */
625
-    protected function _extend_page_config_for_cpt()
626
-    {
627
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
-            return;
630
-        }
631
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
-        if (! empty($this->_cpt_object)) {
633
-            $this->_page_routes = array_merge(
634
-                array(
635
-                    'create_new' => '_create_new_cpt_item',
636
-                    'edit'       => '_edit_cpt_item',
637
-                ),
638
-                $this->_page_routes
639
-            );
640
-            $this->_page_config = array_merge(
641
-                array(
642
-                    'create_new' => array(
643
-                        'nav'           => array(
644
-                            'label' => $this->_cpt_object->labels->add_new_item,
645
-                            'order' => 5,
646
-                        ),
647
-                        'require_nonce' => false,
648
-                    ),
649
-                    'edit'       => array(
650
-                        'nav'           => array(
651
-                            'label'      => $this->_cpt_object->labels->edit_item,
652
-                            'order'      => 5,
653
-                            'persistent' => false,
654
-                            'url'        => '',
655
-                        ),
656
-                        'require_nonce' => false,
657
-                    ),
658
-                ),
659
-                $this->_page_config
660
-            );
661
-        }
662
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
663
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
664
-            return;
665
-        }
666
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
667
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
668
-        if (empty($this->_cpt_object)) {
669
-            $msg = sprintf(
670
-                __(
671
-                    '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).',
672
-                    'event_espresso'
673
-                ),
674
-                $this->page_slug,
675
-                $this->_req_action,
676
-                get_class($this)
677
-            );
678
-            throw new EE_Error($msg);
679
-        }
680
-        if ($this->_cpt_route) {
681
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
682
-            $this->_set_model_object($id);
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
689
-     *
690
-     * @access protected
691
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
692
-     * @param bool   $ignore_route_check
693
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
694
-     * @throws EE_Error
695
-     * @throws InvalidArgumentException
696
-     * @throws InvalidDataTypeException
697
-     * @throws InvalidInterfaceException
698
-     * @throws ReflectionException
699
-     */
700
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
701
-    {
702
-        $model = null;
703
-        if (empty($this->_cpt_model_names)
704
-            || (
705
-                ! $ignore_route_check
706
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
707
-            ) || (
708
-                $this->_cpt_model_obj instanceof EE_CPT_Base
709
-                && $this->_cpt_model_obj->ID() === $id
710
-            )
711
-        ) {
712
-            // 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.
713
-            return;
714
-        }
715
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
716
-        if ($ignore_route_check) {
717
-            $post_type = get_post_type($id);
718
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
719
-            $custom_post_types = LoaderFactory::getLoader()->getShared(
720
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
721
-            );
722
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
723
-            if (isset($model_names[ $post_type ])) {
724
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
725
-            }
726
-        } else {
727
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
728
-        }
729
-        if ($model instanceof EEM_Base) {
730
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
731
-        }
732
-        do_action(
733
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
734
-            $this->_cpt_model_obj,
735
-            $req_type
736
-        );
737
-    }
738
-
739
-
740
-    /**
741
-     * admin_init_global
742
-     * This runs all the code that we want executed within the WP admin_init hook.
743
-     * This method executes for ALL EE Admin pages.
744
-     *
745
-     * @access public
746
-     * @return void
747
-     */
748
-    public function admin_init_global()
749
-    {
750
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
751
-        // its possible this is a new save so let's catch that instead
752
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
753
-        $post_type = $post ? $post->post_type : false;
754
-        $current_route = isset($this->_req_data['current_route'])
755
-            ? $this->_req_data['current_route']
756
-            : 'shouldneverwork';
757
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
758
-            ? $this->_cpt_routes[ $current_route ]
759
-            : '';
760
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
761
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
762
-        if ($post_type === $route_to_check) {
763
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
764
-        }
765
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
766
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
767
-        if (! empty($revision)) {
768
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
769
-            // doing a restore?
770
-            if (! empty($action) && $action === 'restore') {
771
-                // get post for revision
772
-                $rev_post = get_post($revision);
773
-                $rev_parent = get_post($rev_post->post_parent);
774
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
775
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
776
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
777
-                    // restores of revisions
778
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
779
-                }
780
-            }
781
-        }
782
-        // 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!
783
-        if ($post_type && $post_type === $route_to_check) {
784
-            // $post_id, $post
785
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
786
-            // $post_id
787
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
788
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
789
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
790
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
791
-        }
792
-    }
793
-
794
-
795
-    /**
796
-     * Callback for the WordPress trashed_post hook.
797
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
798
-     *
799
-     * @param int $post_id
800
-     * @throws \EE_Error
801
-     */
802
-    public function before_trash_cpt_item($post_id)
803
-    {
804
-        $this->_set_model_object($post_id, true, 'trash');
805
-        // if our cpt object isn't existent then get out immediately.
806
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
807
-            return;
808
-        }
809
-        $this->trash_cpt_item($post_id);
810
-    }
811
-
812
-
813
-    /**
814
-     * Callback for the WordPress untrashed_post hook.
815
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
816
-     *
817
-     * @param $post_id
818
-     * @throws \EE_Error
819
-     */
820
-    public function before_restore_cpt_item($post_id)
821
-    {
822
-        $this->_set_model_object($post_id, true, 'restore');
823
-        // if our cpt object isn't existent then get out immediately.
824
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
825
-            return;
826
-        }
827
-        $this->restore_cpt_item($post_id);
828
-    }
829
-
830
-
831
-    /**
832
-     * Callback for the WordPress after_delete_post hook.
833
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
834
-     *
835
-     * @param $post_id
836
-     * @throws \EE_Error
837
-     */
838
-    public function before_delete_cpt_item($post_id)
839
-    {
840
-        $this->_set_model_object($post_id, true, 'delete');
841
-        // if our cpt object isn't existent then get out immediately.
842
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
-            return;
844
-        }
845
-        $this->delete_cpt_item($post_id);
846
-    }
847
-
848
-
849
-    /**
850
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
851
-     * accordingly.
852
-     *
853
-     * @access public
854
-     * @throws EE_Error
855
-     * @return void
856
-     */
857
-    public function verify_cpt_object()
858
-    {
859
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
860
-        // verify event object
861
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
862
-            throw new EE_Error(
863
-                sprintf(
864
-                    __(
865
-                        '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',
866
-                        'event_espresso'
867
-                    ),
868
-                    $label
869
-                )
870
-            );
871
-        }
872
-        // if auto-draft then throw an error
873
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
874
-            EE_Error::overwrite_errors();
875
-            EE_Error::add_error(
876
-                sprintf(
877
-                    __(
878
-                        '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.',
879
-                        'event_espresso'
880
-                    ),
881
-                    $label
882
-                ),
883
-                __FILE__,
884
-                __FUNCTION__,
885
-                __LINE__
886
-            );
887
-        }
888
-    }
889
-
890
-
891
-    /**
892
-     * admin_footer_scripts_global
893
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
894
-     * will apply on ALL EE_Admin pages.
895
-     *
896
-     * @access public
897
-     * @return void
898
-     */
899
-    public function admin_footer_scripts_global()
900
-    {
901
-        $this->_add_admin_page_ajax_loading_img();
902
-        $this->_add_admin_page_overlay();
903
-    }
904
-
905
-
906
-    /**
907
-     * add in any global scripts for cpt routes
908
-     *
909
-     * @return void
910
-     */
911
-    public function load_global_scripts_styles()
912
-    {
913
-        parent::load_global_scripts_styles();
914
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
915
-            // setup custom post status object for localize script but only if we've got a cpt object
916
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
917
-            if (! empty($statuses)) {
918
-                // get ALL statuses!
919
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
920
-                // setup object
921
-                $ee_cpt_statuses = array();
922
-                foreach ($statuses as $status => $label) {
923
-                    $ee_cpt_statuses[ $status ] = array(
924
-                        'label'      => $label,
925
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
926
-                    );
927
-                }
928
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
929
-            }
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
936
-     * insert/updates
937
-     *
938
-     * @param  int     $post_id ID of post being updated
939
-     * @param  WP_Post $post    Post object from WP
940
-     * @param  bool    $update  Whether this is an update or a new save.
941
-     * @return void
942
-     * @throws \EE_Error
943
-     */
944
-    public function insert_update($post_id, $post, $update)
945
-    {
946
-        // make sure that if this is a revision OR trash action that we don't do any updates!
947
-        if (isset($this->_req_data['action'])
948
-            && (
949
-                $this->_req_data['action'] === 'restore'
950
-                || $this->_req_data['action'] === 'trash'
951
-            )
952
-        ) {
953
-            return;
954
-        }
955
-        $this->_set_model_object($post_id, true, 'insert_update');
956
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
957
-        if ($update
958
-            && (
959
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
960
-                || $this->_cpt_model_obj->ID() !== $post_id
961
-            )
962
-        ) {
963
-            return;
964
-        }
965
-        // check for autosave and update our req_data property accordingly.
966
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
505
+	}
506
+
507
+
508
+	/**
509
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
510
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
511
+	 *
512
+	 * @param  string $return    the current html
513
+	 * @param  int    $id        the post id for the page
514
+	 * @param  string $new_title What the title is
515
+	 * @param  string $new_slug  what the slug is
516
+	 * @return string            The new html string for the permalink area
517
+	 */
518
+	public function preview_button_html($return, $id, $new_title, $new_slug)
519
+	{
520
+		$post = get_post($id);
521
+		if ('publish' !== get_post_status($post)) {
522
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
523
+					   . get_preview_post_link($id)
524
+					   . '" class="button button-small">'
525
+					   . __('Preview', 'event_espresso')
526
+					   . '</a></span>'
527
+					   . "\n";
528
+		}
529
+		return $return;
530
+	}
531
+
532
+
533
+	/**
534
+	 * add our custom post stati dropdown on the wp post page for this cpt
535
+	 *
536
+	 * @return void
537
+	 */
538
+	public function custom_post_stati_dropdown()
539
+	{
540
+
541
+		$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
542
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
543
+			? $statuses[ $this->_cpt_model_obj->status() ]
544
+			: '';
545
+		$template_args = array(
546
+			'cur_status'            => $this->_cpt_model_obj->status(),
547
+			'statuses'              => $statuses,
548
+			'cur_status_label'      => $cur_status_label,
549
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
550
+		);
551
+		// we'll add a trash post status (WP doesn't add one for some reason)
552
+		if ($this->_cpt_model_obj->status() === 'trash') {
553
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
554
+			$statuses['trash'] = __('Trashed', 'event_espresso');
555
+			$template_args['statuses'] = $statuses;
556
+		}
557
+
558
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
559
+		EEH_Template::display_template($template, $template_args);
560
+	}
561
+
562
+
563
+	public function setup_autosave_hooks()
564
+	{
565
+		$this->_set_autosave_containers();
566
+		$this->_load_autosave_scripts_styles();
567
+	}
568
+
569
+
570
+	/**
571
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
572
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
573
+	 * for the nonce in here, but then this method looks for two things:
574
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
575
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
576
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
577
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
578
+	 * template args.
579
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
580
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
581
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
582
+	 *    $this->_template_args['data']['items'] = array(
583
+	 *        'event-datetime-ids' => '1,2,3';
584
+	 *    );
585
+	 *    Keep in mind the following things:
586
+	 *    - "where" index is for the input with the id as that string.
587
+	 *    - "what" index is what will be used for the value of that input.
588
+	 *
589
+	 * @return void
590
+	 */
591
+	public function do_extra_autosave_stuff()
592
+	{
593
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
594
+		$nonce = isset($this->_req_data['autosavenonce'])
595
+			? $this->_req_data['autosavenonce']
596
+			: null;
597
+		$this->_verify_nonce($nonce, 'autosave');
598
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
599
+		if (! defined('DOING_AUTOSAVE')) {
600
+			define('DOING_AUTOSAVE', true);
601
+		}
602
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
603
+		$autosave = "_ee_autosave_{$this->_current_view}";
604
+		if (method_exists($this, $autosave)) {
605
+			$this->$autosave();
606
+		} else {
607
+			$this->_template_args['success'] = true;
608
+		}
609
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
610
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
611
+		// now let's return json
612
+		$this->_return_json();
613
+	}
614
+
615
+
616
+	/**
617
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
+	 *
621
+	 * @access protected
622
+	 * @throws EE_Error
623
+	 * @return void
624
+	 */
625
+	protected function _extend_page_config_for_cpt()
626
+	{
627
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
+			return;
630
+		}
631
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
+		if (! empty($this->_cpt_object)) {
633
+			$this->_page_routes = array_merge(
634
+				array(
635
+					'create_new' => '_create_new_cpt_item',
636
+					'edit'       => '_edit_cpt_item',
637
+				),
638
+				$this->_page_routes
639
+			);
640
+			$this->_page_config = array_merge(
641
+				array(
642
+					'create_new' => array(
643
+						'nav'           => array(
644
+							'label' => $this->_cpt_object->labels->add_new_item,
645
+							'order' => 5,
646
+						),
647
+						'require_nonce' => false,
648
+					),
649
+					'edit'       => array(
650
+						'nav'           => array(
651
+							'label'      => $this->_cpt_object->labels->edit_item,
652
+							'order'      => 5,
653
+							'persistent' => false,
654
+							'url'        => '',
655
+						),
656
+						'require_nonce' => false,
657
+					),
658
+				),
659
+				$this->_page_config
660
+			);
661
+		}
662
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
663
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
664
+			return;
665
+		}
666
+		$this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
667
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
668
+		if (empty($this->_cpt_object)) {
669
+			$msg = sprintf(
670
+				__(
671
+					'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).',
672
+					'event_espresso'
673
+				),
674
+				$this->page_slug,
675
+				$this->_req_action,
676
+				get_class($this)
677
+			);
678
+			throw new EE_Error($msg);
679
+		}
680
+		if ($this->_cpt_route) {
681
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
682
+			$this->_set_model_object($id);
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
689
+	 *
690
+	 * @access protected
691
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
692
+	 * @param bool   $ignore_route_check
693
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
694
+	 * @throws EE_Error
695
+	 * @throws InvalidArgumentException
696
+	 * @throws InvalidDataTypeException
697
+	 * @throws InvalidInterfaceException
698
+	 * @throws ReflectionException
699
+	 */
700
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
701
+	{
702
+		$model = null;
703
+		if (empty($this->_cpt_model_names)
704
+			|| (
705
+				! $ignore_route_check
706
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
707
+			) || (
708
+				$this->_cpt_model_obj instanceof EE_CPT_Base
709
+				&& $this->_cpt_model_obj->ID() === $id
710
+			)
711
+		) {
712
+			// 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.
713
+			return;
714
+		}
715
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
716
+		if ($ignore_route_check) {
717
+			$post_type = get_post_type($id);
718
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
719
+			$custom_post_types = LoaderFactory::getLoader()->getShared(
720
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
721
+			);
722
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
723
+			if (isset($model_names[ $post_type ])) {
724
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
725
+			}
726
+		} else {
727
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
728
+		}
729
+		if ($model instanceof EEM_Base) {
730
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
731
+		}
732
+		do_action(
733
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
734
+			$this->_cpt_model_obj,
735
+			$req_type
736
+		);
737
+	}
738
+
739
+
740
+	/**
741
+	 * admin_init_global
742
+	 * This runs all the code that we want executed within the WP admin_init hook.
743
+	 * This method executes for ALL EE Admin pages.
744
+	 *
745
+	 * @access public
746
+	 * @return void
747
+	 */
748
+	public function admin_init_global()
749
+	{
750
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
751
+		// its possible this is a new save so let's catch that instead
752
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
753
+		$post_type = $post ? $post->post_type : false;
754
+		$current_route = isset($this->_req_data['current_route'])
755
+			? $this->_req_data['current_route']
756
+			: 'shouldneverwork';
757
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
758
+			? $this->_cpt_routes[ $current_route ]
759
+			: '';
760
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
761
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
762
+		if ($post_type === $route_to_check) {
763
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
764
+		}
765
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
766
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
767
+		if (! empty($revision)) {
768
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
769
+			// doing a restore?
770
+			if (! empty($action) && $action === 'restore') {
771
+				// get post for revision
772
+				$rev_post = get_post($revision);
773
+				$rev_parent = get_post($rev_post->post_parent);
774
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
775
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
776
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
777
+					// restores of revisions
778
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
779
+				}
780
+			}
781
+		}
782
+		// 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!
783
+		if ($post_type && $post_type === $route_to_check) {
784
+			// $post_id, $post
785
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
786
+			// $post_id
787
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
788
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
789
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
790
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
791
+		}
792
+	}
793
+
794
+
795
+	/**
796
+	 * Callback for the WordPress trashed_post hook.
797
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
798
+	 *
799
+	 * @param int $post_id
800
+	 * @throws \EE_Error
801
+	 */
802
+	public function before_trash_cpt_item($post_id)
803
+	{
804
+		$this->_set_model_object($post_id, true, 'trash');
805
+		// if our cpt object isn't existent then get out immediately.
806
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
807
+			return;
808
+		}
809
+		$this->trash_cpt_item($post_id);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Callback for the WordPress untrashed_post hook.
815
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
816
+	 *
817
+	 * @param $post_id
818
+	 * @throws \EE_Error
819
+	 */
820
+	public function before_restore_cpt_item($post_id)
821
+	{
822
+		$this->_set_model_object($post_id, true, 'restore');
823
+		// if our cpt object isn't existent then get out immediately.
824
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
825
+			return;
826
+		}
827
+		$this->restore_cpt_item($post_id);
828
+	}
829
+
830
+
831
+	/**
832
+	 * Callback for the WordPress after_delete_post hook.
833
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
834
+	 *
835
+	 * @param $post_id
836
+	 * @throws \EE_Error
837
+	 */
838
+	public function before_delete_cpt_item($post_id)
839
+	{
840
+		$this->_set_model_object($post_id, true, 'delete');
841
+		// if our cpt object isn't existent then get out immediately.
842
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
+			return;
844
+		}
845
+		$this->delete_cpt_item($post_id);
846
+	}
847
+
848
+
849
+	/**
850
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
851
+	 * accordingly.
852
+	 *
853
+	 * @access public
854
+	 * @throws EE_Error
855
+	 * @return void
856
+	 */
857
+	public function verify_cpt_object()
858
+	{
859
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
860
+		// verify event object
861
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
862
+			throw new EE_Error(
863
+				sprintf(
864
+					__(
865
+						'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',
866
+						'event_espresso'
867
+					),
868
+					$label
869
+				)
870
+			);
871
+		}
872
+		// if auto-draft then throw an error
873
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
874
+			EE_Error::overwrite_errors();
875
+			EE_Error::add_error(
876
+				sprintf(
877
+					__(
878
+						'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.',
879
+						'event_espresso'
880
+					),
881
+					$label
882
+				),
883
+				__FILE__,
884
+				__FUNCTION__,
885
+				__LINE__
886
+			);
887
+		}
888
+	}
889
+
890
+
891
+	/**
892
+	 * admin_footer_scripts_global
893
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
894
+	 * will apply on ALL EE_Admin pages.
895
+	 *
896
+	 * @access public
897
+	 * @return void
898
+	 */
899
+	public function admin_footer_scripts_global()
900
+	{
901
+		$this->_add_admin_page_ajax_loading_img();
902
+		$this->_add_admin_page_overlay();
903
+	}
904
+
905
+
906
+	/**
907
+	 * add in any global scripts for cpt routes
908
+	 *
909
+	 * @return void
910
+	 */
911
+	public function load_global_scripts_styles()
912
+	{
913
+		parent::load_global_scripts_styles();
914
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
915
+			// setup custom post status object for localize script but only if we've got a cpt object
916
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
917
+			if (! empty($statuses)) {
918
+				// get ALL statuses!
919
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
920
+				// setup object
921
+				$ee_cpt_statuses = array();
922
+				foreach ($statuses as $status => $label) {
923
+					$ee_cpt_statuses[ $status ] = array(
924
+						'label'      => $label,
925
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
926
+					);
927
+				}
928
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
929
+			}
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
936
+	 * insert/updates
937
+	 *
938
+	 * @param  int     $post_id ID of post being updated
939
+	 * @param  WP_Post $post    Post object from WP
940
+	 * @param  bool    $update  Whether this is an update or a new save.
941
+	 * @return void
942
+	 * @throws \EE_Error
943
+	 */
944
+	public function insert_update($post_id, $post, $update)
945
+	{
946
+		// make sure that if this is a revision OR trash action that we don't do any updates!
947
+		if (isset($this->_req_data['action'])
948
+			&& (
949
+				$this->_req_data['action'] === 'restore'
950
+				|| $this->_req_data['action'] === 'trash'
951
+			)
952
+		) {
953
+			return;
954
+		}
955
+		$this->_set_model_object($post_id, true, 'insert_update');
956
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
957
+		if ($update
958
+			&& (
959
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
960
+				|| $this->_cpt_model_obj->ID() !== $post_id
961
+			)
962
+		) {
963
+			return;
964
+		}
965
+		// check for autosave and update our req_data property accordingly.
966
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
967 967
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
968 968
 
969 969
                 foreach ( (array) $values as $key => $value ) {
@@ -973,532 +973,532 @@  discard block
 block discarded – undo
973 973
 
974 974
         }/**/ // TODO reactivate after autosave is implemented in 4.2
975 975
 
976
-        // take care of updating any selected page_template IF this cpt supports it.
977
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
978
-            // wp version aware.
979
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
980
-                $page_templates = wp_get_theme()->get_page_templates();
981
-            } else {
982
-                $post->page_template = $this->_req_data['page_template'];
983
-                $page_templates = wp_get_theme()->get_page_templates($post);
984
-            }
985
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
986
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
987
-            } else {
988
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
989
-            }
990
-        }
991
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
992
-            return;
993
-        } //TODO we'll remove this after reimplementing autosave in 4.2
994
-        $this->_insert_update_cpt_item($post_id, $post);
995
-    }
996
-
997
-
998
-    /**
999
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1000
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1001
-     * so we don't have to check for our CPT.
1002
-     *
1003
-     * @param  int $post_id ID of the post
1004
-     * @return void
1005
-     */
1006
-    public function dont_permanently_delete_ee_cpts($post_id)
1007
-    {
1008
-        // only do this if we're actually processing one of our CPTs
1009
-        // if our cpt object isn't existent then get out immediately.
1010
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1011
-            return;
1012
-        }
1013
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1014
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1015
-        // our cpts may have comments so let's take care of that too
1016
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1022
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1023
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1024
-     *
1025
-     * @param  int $post_id     ID of cpt item
1026
-     * @param  int $revision_id ID of revision being restored
1027
-     * @return void
1028
-     */
1029
-    public function restore_revision($post_id, $revision_id)
1030
-    {
1031
-        $this->_restore_cpt_item($post_id, $revision_id);
1032
-        // global action
1033
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1034
-        // class specific action so you can limit hooking into a specific page.
1035
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * @see restore_revision() for details
1041
-     * @param  int $post_id     ID of cpt item
1042
-     * @param  int $revision_id ID of revision for item
1043
-     * @return void
1044
-     */
1045
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1046
-
1047
-
1048
-    /**
1049
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1050
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1051
-     * To fix we have to reset the current_screen using the page_slug
1052
-     * (which is identical - or should be - to our registered_post_type id.)
1053
-     * Also, since the core WP file loads the admin_header.php for WP
1054
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1055
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1056
-     *
1057
-     * @return void
1058
-     */
1059
-    public function modify_current_screen()
1060
-    {
1061
-        // ONLY do this if the current page_route IS a cpt route
1062
-        if (! $this->_cpt_route) {
1063
-            return;
1064
-        }
1065
-        // routing things REALLY early b/c this is a cpt admin page
1066
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1067
-        $this->_current_screen = get_current_screen();
1068
-        $this->_current_screen->base = 'event-espresso';
1069
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1070
-        /*try {
976
+		// take care of updating any selected page_template IF this cpt supports it.
977
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
978
+			// wp version aware.
979
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
980
+				$page_templates = wp_get_theme()->get_page_templates();
981
+			} else {
982
+				$post->page_template = $this->_req_data['page_template'];
983
+				$page_templates = wp_get_theme()->get_page_templates($post);
984
+			}
985
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
986
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
987
+			} else {
988
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
989
+			}
990
+		}
991
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
992
+			return;
993
+		} //TODO we'll remove this after reimplementing autosave in 4.2
994
+		$this->_insert_update_cpt_item($post_id, $post);
995
+	}
996
+
997
+
998
+	/**
999
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1000
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1001
+	 * so we don't have to check for our CPT.
1002
+	 *
1003
+	 * @param  int $post_id ID of the post
1004
+	 * @return void
1005
+	 */
1006
+	public function dont_permanently_delete_ee_cpts($post_id)
1007
+	{
1008
+		// only do this if we're actually processing one of our CPTs
1009
+		// if our cpt object isn't existent then get out immediately.
1010
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1011
+			return;
1012
+		}
1013
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1014
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1015
+		// our cpts may have comments so let's take care of that too
1016
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1022
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1023
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1024
+	 *
1025
+	 * @param  int $post_id     ID of cpt item
1026
+	 * @param  int $revision_id ID of revision being restored
1027
+	 * @return void
1028
+	 */
1029
+	public function restore_revision($post_id, $revision_id)
1030
+	{
1031
+		$this->_restore_cpt_item($post_id, $revision_id);
1032
+		// global action
1033
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1034
+		// class specific action so you can limit hooking into a specific page.
1035
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * @see restore_revision() for details
1041
+	 * @param  int $post_id     ID of cpt item
1042
+	 * @param  int $revision_id ID of revision for item
1043
+	 * @return void
1044
+	 */
1045
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1046
+
1047
+
1048
+	/**
1049
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1050
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1051
+	 * To fix we have to reset the current_screen using the page_slug
1052
+	 * (which is identical - or should be - to our registered_post_type id.)
1053
+	 * Also, since the core WP file loads the admin_header.php for WP
1054
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1055
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1056
+	 *
1057
+	 * @return void
1058
+	 */
1059
+	public function modify_current_screen()
1060
+	{
1061
+		// ONLY do this if the current page_route IS a cpt route
1062
+		if (! $this->_cpt_route) {
1063
+			return;
1064
+		}
1065
+		// routing things REALLY early b/c this is a cpt admin page
1066
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1067
+		$this->_current_screen = get_current_screen();
1068
+		$this->_current_screen->base = 'event-espresso';
1069
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1070
+		/*try {
1071 1071
             $this->_route_admin_request();
1072 1072
         } catch ( EE_Error $e ) {
1073 1073
             $e->get_error();
1074 1074
         }/**/
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1080
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1081
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1082
-     * default to be.
1083
-     *
1084
-     * @param string $title The new title (or existing if there is no editor_title defined)
1085
-     * @return string
1086
-     */
1087
-    public function add_custom_editor_default_title($title)
1088
-    {
1089
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1090
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1091
-            : $title;
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1097
-     *
1098
-     * @param string $shortlink   The already generated shortlink
1099
-     * @param int    $id          Post ID for this item
1100
-     * @param string $context     The context for the link
1101
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1102
-     * @return string
1103
-     */
1104
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1105
-    {
1106
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1107
-            $post = get_post($id);
1108
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
-                $shortlink = home_url('?p=' . $post->ID);
1110
-            }
1111
-        }
1112
-        return $shortlink;
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1118
-     * already run in modify_current_screen())
1119
-     *
1120
-     * @return void
1121
-     */
1122
-    public function route_admin_request()
1123
-    {
1124
-        if ($this->_cpt_route) {
1125
-            return;
1126
-        }
1127
-        try {
1128
-            $this->_route_admin_request();
1129
-        } catch (EE_Error $e) {
1130
-            $e->get_error();
1131
-        }
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1137
-     *
1138
-     * @return void
1139
-     */
1140
-    public function cpt_post_form_hidden_input()
1141
-    {
1142
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1143
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1144
-        echo '<div id="ee-cpt-hidden-inputs">';
1145
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1146
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1147
-        echo '</div>';
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1153
-     *
1154
-     * @param  string $location Original location url
1155
-     * @param  int    $status   Status for http header
1156
-     * @return string           new (or original) url to redirect to.
1157
-     */
1158
-    public function revision_redirect($location, $status)
1159
-    {
1160
-        // get revision
1161
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1162
-        // can't do anything without revision so let's get out if not present
1163
-        if (empty($rev_id)) {
1164
-            return $location;
1165
-        }
1166
-        // get rev_post_data
1167
-        $rev = get_post($rev_id);
1168
-        $admin_url = $this->_admin_base_url;
1169
-        $query_args = array(
1170
-            'action'   => 'edit',
1171
-            'post'     => $rev->post_parent,
1172
-            'revision' => $rev_id,
1173
-            'message'  => 5,
1174
-        );
1175
-        $this->_process_notices($query_args, true);
1176
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1177
-    }
1178
-
1179
-
1180
-    /**
1181
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1182
-     *
1183
-     * @param  string $link    the original generated link
1184
-     * @param  int    $id      post id
1185
-     * @param  string $context optional, defaults to display.  How to write the '&'
1186
-     * @return string          the link
1187
-     */
1188
-    public function modify_edit_post_link($link, $id, $context)
1189
-    {
1190
-        $post = get_post($id);
1191
-        if (! isset($this->_req_data['action'])
1192
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1193
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1194
-        ) {
1195
-            return $link;
1196
-        }
1197
-        $query_args = array(
1198
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1199
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1200
-                : 'edit',
1201
-            'post'   => $id,
1202
-        );
1203
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1209
-     * our routes.
1210
-     *
1211
-     * @param  string $delete_link  original delete link
1212
-     * @param  int    $post_id      id of cpt object
1213
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1214
-     * @return string new delete link
1215
-     * @throws EE_Error
1216
-     */
1217
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1218
-    {
1219
-        $post = get_post($post_id);
1220
-
1221
-        if (empty($this->_req_data['action'])
1222
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1223
-            || ! $post instanceof WP_Post
1224
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1225
-        ) {
1226
-            return $delete_link;
1227
-        }
1228
-        $this->_set_model_object($post->ID, true);
1229
-
1230
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1231
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1232
-
1233
-        return EE_Admin_Page::add_query_args_and_nonce(
1234
-            array(
1235
-                'page'   => $this->_req_data['page'],
1236
-                'action' => $action,
1237
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1238
-                         => $post->ID,
1239
-            ),
1240
-            admin_url()
1241
-        );
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1247
-     * so that we can hijack the default redirect locations for wp custom post types
1248
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1249
-     *
1250
-     * @param  string $location This is the incoming currently set redirect location
1251
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1252
-     * @return string           the new location to redirect to
1253
-     */
1254
-    public function cpt_post_location_redirect($location, $post_id)
1255
-    {
1256
-        // we DO have a match so let's setup the url
1257
-        // we have to get the post to determine our route
1258
-        $post = get_post($post_id);
1259
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1260
-        // shared query_args
1261
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1262
-        $admin_url = $this->_admin_base_url;
1263
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1264
-            $status = get_post_status($post_id);
1265
-            if (isset($this->_req_data['publish'])) {
1266
-                switch ($status) {
1267
-                    case 'pending':
1268
-                        $message = 8;
1269
-                        break;
1270
-                    case 'future':
1271
-                        $message = 9;
1272
-                        break;
1273
-                    default:
1274
-                        $message = 6;
1275
-                }
1276
-            } else {
1277
-                $message = 'draft' === $status ? 10 : 1;
1278
-            }
1279
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1280
-            $message = 2;
1281
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1282
-            $message = 3;
1283
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1284
-            $message = 7;
1285
-        } else {
1286
-            $message = 4;
1287
-        }
1288
-        // change the message if the post type is not viewable on the frontend
1289
-        $this->_cpt_object = get_post_type_object($post->post_type);
1290
-        $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1291
-        $query_args = array_merge(array('message' => $message), $query_args);
1292
-        $this->_process_notices($query_args, true);
1293
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1294
-    }
1295
-
1296
-
1297
-    /**
1298
-     * This method is called to inject nav tabs on core WP cpt pages
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function inject_nav_tabs()
1304
-    {
1305
-        // can we hijack and insert the nav_tabs?
1306
-        $nav_tabs = $this->_get_main_nav_tabs();
1307
-        // first close off existing form tag
1308
-        $html = '>';
1309
-        $html .= $nav_tabs;
1310
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1311
-        $html .= '<span></span';
1312
-        echo $html;
1313
-    }
1314
-
1315
-
1316
-    /**
1317
-     * This just sets up the post update messages when an update form is loaded
1318
-     *
1319
-     * @access public
1320
-     * @param  array $messages the original messages array
1321
-     * @return array           the new messages array
1322
-     */
1323
-    public function post_update_messages($messages)
1324
-    {
1325
-        global $post;
1326
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1327
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1328
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1080
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1081
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1082
+	 * default to be.
1083
+	 *
1084
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1085
+	 * @return string
1086
+	 */
1087
+	public function add_custom_editor_default_title($title)
1088
+	{
1089
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1090
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1091
+			: $title;
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1097
+	 *
1098
+	 * @param string $shortlink   The already generated shortlink
1099
+	 * @param int    $id          Post ID for this item
1100
+	 * @param string $context     The context for the link
1101
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1102
+	 * @return string
1103
+	 */
1104
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1105
+	{
1106
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1107
+			$post = get_post($id);
1108
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
+				$shortlink = home_url('?p=' . $post->ID);
1110
+			}
1111
+		}
1112
+		return $shortlink;
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1118
+	 * already run in modify_current_screen())
1119
+	 *
1120
+	 * @return void
1121
+	 */
1122
+	public function route_admin_request()
1123
+	{
1124
+		if ($this->_cpt_route) {
1125
+			return;
1126
+		}
1127
+		try {
1128
+			$this->_route_admin_request();
1129
+		} catch (EE_Error $e) {
1130
+			$e->get_error();
1131
+		}
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1137
+	 *
1138
+	 * @return void
1139
+	 */
1140
+	public function cpt_post_form_hidden_input()
1141
+	{
1142
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1143
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1144
+		echo '<div id="ee-cpt-hidden-inputs">';
1145
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1146
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1147
+		echo '</div>';
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1153
+	 *
1154
+	 * @param  string $location Original location url
1155
+	 * @param  int    $status   Status for http header
1156
+	 * @return string           new (or original) url to redirect to.
1157
+	 */
1158
+	public function revision_redirect($location, $status)
1159
+	{
1160
+		// get revision
1161
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1162
+		// can't do anything without revision so let's get out if not present
1163
+		if (empty($rev_id)) {
1164
+			return $location;
1165
+		}
1166
+		// get rev_post_data
1167
+		$rev = get_post($rev_id);
1168
+		$admin_url = $this->_admin_base_url;
1169
+		$query_args = array(
1170
+			'action'   => 'edit',
1171
+			'post'     => $rev->post_parent,
1172
+			'revision' => $rev_id,
1173
+			'message'  => 5,
1174
+		);
1175
+		$this->_process_notices($query_args, true);
1176
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1177
+	}
1178
+
1179
+
1180
+	/**
1181
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1182
+	 *
1183
+	 * @param  string $link    the original generated link
1184
+	 * @param  int    $id      post id
1185
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1186
+	 * @return string          the link
1187
+	 */
1188
+	public function modify_edit_post_link($link, $id, $context)
1189
+	{
1190
+		$post = get_post($id);
1191
+		if (! isset($this->_req_data['action'])
1192
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1193
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1194
+		) {
1195
+			return $link;
1196
+		}
1197
+		$query_args = array(
1198
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1199
+				? $this->_cpt_edit_routes[ $post->post_type ]
1200
+				: 'edit',
1201
+			'post'   => $id,
1202
+		);
1203
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1209
+	 * our routes.
1210
+	 *
1211
+	 * @param  string $delete_link  original delete link
1212
+	 * @param  int    $post_id      id of cpt object
1213
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1214
+	 * @return string new delete link
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1218
+	{
1219
+		$post = get_post($post_id);
1220
+
1221
+		if (empty($this->_req_data['action'])
1222
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1223
+			|| ! $post instanceof WP_Post
1224
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1225
+		) {
1226
+			return $delete_link;
1227
+		}
1228
+		$this->_set_model_object($post->ID, true);
1229
+
1230
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1231
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1232
+
1233
+		return EE_Admin_Page::add_query_args_and_nonce(
1234
+			array(
1235
+				'page'   => $this->_req_data['page'],
1236
+				'action' => $action,
1237
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1238
+						 => $post->ID,
1239
+			),
1240
+			admin_url()
1241
+		);
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1247
+	 * so that we can hijack the default redirect locations for wp custom post types
1248
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1249
+	 *
1250
+	 * @param  string $location This is the incoming currently set redirect location
1251
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1252
+	 * @return string           the new location to redirect to
1253
+	 */
1254
+	public function cpt_post_location_redirect($location, $post_id)
1255
+	{
1256
+		// we DO have a match so let's setup the url
1257
+		// we have to get the post to determine our route
1258
+		$post = get_post($post_id);
1259
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1260
+		// shared query_args
1261
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1262
+		$admin_url = $this->_admin_base_url;
1263
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1264
+			$status = get_post_status($post_id);
1265
+			if (isset($this->_req_data['publish'])) {
1266
+				switch ($status) {
1267
+					case 'pending':
1268
+						$message = 8;
1269
+						break;
1270
+					case 'future':
1271
+						$message = 9;
1272
+						break;
1273
+					default:
1274
+						$message = 6;
1275
+				}
1276
+			} else {
1277
+				$message = 'draft' === $status ? 10 : 1;
1278
+			}
1279
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1280
+			$message = 2;
1281
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1282
+			$message = 3;
1283
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1284
+			$message = 7;
1285
+		} else {
1286
+			$message = 4;
1287
+		}
1288
+		// change the message if the post type is not viewable on the frontend
1289
+		$this->_cpt_object = get_post_type_object($post->post_type);
1290
+		$message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1291
+		$query_args = array_merge(array('message' => $message), $query_args);
1292
+		$this->_process_notices($query_args, true);
1293
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1294
+	}
1295
+
1296
+
1297
+	/**
1298
+	 * This method is called to inject nav tabs on core WP cpt pages
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function inject_nav_tabs()
1304
+	{
1305
+		// can we hijack and insert the nav_tabs?
1306
+		$nav_tabs = $this->_get_main_nav_tabs();
1307
+		// first close off existing form tag
1308
+		$html = '>';
1309
+		$html .= $nav_tabs;
1310
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1311
+		$html .= '<span></span';
1312
+		echo $html;
1313
+	}
1314
+
1315
+
1316
+	/**
1317
+	 * This just sets up the post update messages when an update form is loaded
1318
+	 *
1319
+	 * @access public
1320
+	 * @param  array $messages the original messages array
1321
+	 * @return array           the new messages array
1322
+	 */
1323
+	public function post_update_messages($messages)
1324
+	{
1325
+		global $post;
1326
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1327
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1328
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1329 1329
 
1330 1330
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1331
-        $messages[ $post->post_type ] = array(
1332
-            0  => '', // Unused. Messages start at index 1.
1333
-            1  => sprintf(
1334
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1335
-                $this->_cpt_object->labels->singular_name,
1336
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1337
-                '</a>'
1338
-            ),
1339
-            2  => __('Custom field updated', 'event_espresso'),
1340
-            3  => __('Custom field deleted.', 'event_espresso'),
1341
-            4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1342
-            5  => isset($_GET['revision']) ? sprintf(
1343
-                __('%s restored to revision from %s', 'event_espresso'),
1344
-                $this->_cpt_object->labels->singular_name,
1345
-                wp_post_revision_title((int) $_GET['revision'], false)
1346
-            )
1347
-                : false,
1348
-            6  => sprintf(
1349
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1350
-                $this->_cpt_object->labels->singular_name,
1351
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1352
-                '</a>'
1353
-            ),
1354
-            7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1355
-            8  => sprintf(
1356
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1357
-                $this->_cpt_object->labels->singular_name,
1358
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1359
-                '</a>'
1360
-            ),
1361
-            9  => sprintf(
1362
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1363
-                $this->_cpt_object->labels->singular_name,
1364
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1365
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1366
-                '</a>'
1367
-            ),
1368
-            10 => sprintf(
1369
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1370
-                $this->_cpt_object->labels->singular_name,
1371
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1372
-                '</a>'
1373
-            ),
1374
-        );
1375
-        return $messages;
1376
-    }
1377
-
1378
-
1379
-    /**
1380
-     * default method for the 'create_new' route for cpt admin pages.
1381
-     * For reference what to include in here, see wp-admin/post-new.php
1382
-     *
1383
-     * @access  protected
1384
-     * @return void
1385
-     */
1386
-    protected function _create_new_cpt_item()
1387
-    {
1388
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1389
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1390
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1391
-        $post_type_object = $this->_cpt_object;
1392
-        $title = $post_type_object->labels->add_new_item;
1393
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1394
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1395
-        // modify the default editor title field with default title.
1396
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1397
-        $this->loadEditorTemplate(true);
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * Enqueues auto-save and loads the editor template
1403
-     *
1404
-     * @param bool $creating
1405
-     */
1406
-    private function loadEditorTemplate($creating = true)
1407
-    {
1408
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1409
-        // these vars are used by the template
1410
-        $editing = true;
1411
-        $post_ID = $post->ID;
1412
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1413
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1414
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1415
-            if ($creating) {
1416
-                wp_enqueue_script('autosave');
1417
-            } else {
1418
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1419
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1420
-                ) {
1421
-                    $create_new_action = apply_filters(
1422
-                        'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1423
-                        'create_new',
1424
-                        $this
1425
-                    );
1426
-                    $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1427
-                        array(
1428
-                            'action' => $create_new_action,
1429
-                            'page'   => $this->page_slug,
1430
-                        ),
1431
-                        'admin.php'
1432
-                    );
1433
-                }
1434
-            }
1435
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1436
-        }
1437
-    }
1438
-
1439
-
1440
-    public function add_new_admin_page_global()
1441
-    {
1442
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1443
-        ?>
1331
+		$messages[ $post->post_type ] = array(
1332
+			0  => '', // Unused. Messages start at index 1.
1333
+			1  => sprintf(
1334
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1335
+				$this->_cpt_object->labels->singular_name,
1336
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1337
+				'</a>'
1338
+			),
1339
+			2  => __('Custom field updated', 'event_espresso'),
1340
+			3  => __('Custom field deleted.', 'event_espresso'),
1341
+			4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1342
+			5  => isset($_GET['revision']) ? sprintf(
1343
+				__('%s restored to revision from %s', 'event_espresso'),
1344
+				$this->_cpt_object->labels->singular_name,
1345
+				wp_post_revision_title((int) $_GET['revision'], false)
1346
+			)
1347
+				: false,
1348
+			6  => sprintf(
1349
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1350
+				$this->_cpt_object->labels->singular_name,
1351
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1352
+				'</a>'
1353
+			),
1354
+			7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1355
+			8  => sprintf(
1356
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1357
+				$this->_cpt_object->labels->singular_name,
1358
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1359
+				'</a>'
1360
+			),
1361
+			9  => sprintf(
1362
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1363
+				$this->_cpt_object->labels->singular_name,
1364
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1365
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1366
+				'</a>'
1367
+			),
1368
+			10 => sprintf(
1369
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1370
+				$this->_cpt_object->labels->singular_name,
1371
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1372
+				'</a>'
1373
+			),
1374
+		);
1375
+		return $messages;
1376
+	}
1377
+
1378
+
1379
+	/**
1380
+	 * default method for the 'create_new' route for cpt admin pages.
1381
+	 * For reference what to include in here, see wp-admin/post-new.php
1382
+	 *
1383
+	 * @access  protected
1384
+	 * @return void
1385
+	 */
1386
+	protected function _create_new_cpt_item()
1387
+	{
1388
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1389
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1390
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1391
+		$post_type_object = $this->_cpt_object;
1392
+		$title = $post_type_object->labels->add_new_item;
1393
+		$post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1394
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1395
+		// modify the default editor title field with default title.
1396
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1397
+		$this->loadEditorTemplate(true);
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * Enqueues auto-save and loads the editor template
1403
+	 *
1404
+	 * @param bool $creating
1405
+	 */
1406
+	private function loadEditorTemplate($creating = true)
1407
+	{
1408
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1409
+		// these vars are used by the template
1410
+		$editing = true;
1411
+		$post_ID = $post->ID;
1412
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1413
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1414
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1415
+			if ($creating) {
1416
+				wp_enqueue_script('autosave');
1417
+			} else {
1418
+				if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1419
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1420
+				) {
1421
+					$create_new_action = apply_filters(
1422
+						'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1423
+						'create_new',
1424
+						$this
1425
+					);
1426
+					$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1427
+						array(
1428
+							'action' => $create_new_action,
1429
+							'page'   => $this->page_slug,
1430
+						),
1431
+						'admin.php'
1432
+					);
1433
+				}
1434
+			}
1435
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1436
+		}
1437
+	}
1438
+
1439
+
1440
+	public function add_new_admin_page_global()
1441
+	{
1442
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1443
+		?>
1444 1444
         <script type="text/javascript">
1445 1445
             adminpage = '<?php echo $admin_page; ?>';
1446 1446
         </script>
1447 1447
         <?php
1448
-    }
1449
-
1450
-
1451
-    /**
1452
-     * default method for the 'edit' route for cpt admin pages
1453
-     * For reference on what to put in here, refer to wp-admin/post.php
1454
-     *
1455
-     * @access protected
1456
-     * @return string   template for edit cpt form
1457
-     */
1458
-    protected function _edit_cpt_item()
1459
-    {
1460
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1461
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1462
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1463
-        if (empty($post)) {
1464
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1465
-        }
1466
-        if (! empty($_GET['get-post-lock'])) {
1467
-            wp_set_post_lock($post_id);
1468
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1469
-            exit();
1470
-        }
1471
-
1472
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1473
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1474
-        $post_type_object = $this->_cpt_object;
1475
-
1476
-        if (! wp_check_post_lock($post->ID)) {
1477
-            wp_set_post_lock($post->ID);
1478
-        }
1479
-        add_action('admin_footer', '_admin_notice_post_locked');
1480
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1481
-            wp_enqueue_script('admin-comments');
1482
-            enqueue_comment_hotkeys_js();
1483
-        }
1484
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1485
-        // modify the default editor title field with default title.
1486
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1487
-        $this->loadEditorTemplate(false);
1488
-    }
1489
-
1490
-
1491
-
1492
-    /**
1493
-     * some getters
1494
-     */
1495
-    /**
1496
-     * This returns the protected _cpt_model_obj property
1497
-     *
1498
-     * @return EE_CPT_Base
1499
-     */
1500
-    public function get_cpt_model_obj()
1501
-    {
1502
-        return $this->_cpt_model_obj;
1503
-    }
1448
+	}
1449
+
1450
+
1451
+	/**
1452
+	 * default method for the 'edit' route for cpt admin pages
1453
+	 * For reference on what to put in here, refer to wp-admin/post.php
1454
+	 *
1455
+	 * @access protected
1456
+	 * @return string   template for edit cpt form
1457
+	 */
1458
+	protected function _edit_cpt_item()
1459
+	{
1460
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1461
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1462
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1463
+		if (empty($post)) {
1464
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1465
+		}
1466
+		if (! empty($_GET['get-post-lock'])) {
1467
+			wp_set_post_lock($post_id);
1468
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1469
+			exit();
1470
+		}
1471
+
1472
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1473
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1474
+		$post_type_object = $this->_cpt_object;
1475
+
1476
+		if (! wp_check_post_lock($post->ID)) {
1477
+			wp_set_post_lock($post->ID);
1478
+		}
1479
+		add_action('admin_footer', '_admin_notice_post_locked');
1480
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1481
+			wp_enqueue_script('admin-comments');
1482
+			enqueue_comment_hotkeys_js();
1483
+		}
1484
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1485
+		// modify the default editor title field with default title.
1486
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1487
+		$this->loadEditorTemplate(false);
1488
+	}
1489
+
1490
+
1491
+
1492
+	/**
1493
+	 * some getters
1494
+	 */
1495
+	/**
1496
+	 * This returns the protected _cpt_model_obj property
1497
+	 *
1498
+	 * @return EE_CPT_Base
1499
+	 */
1500
+	public function get_cpt_model_obj()
1501
+	{
1502
+		return $this->_cpt_model_obj;
1503
+	}
1504 1504
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
             $this->_cpt_routes
170 170
         );
171 171
         // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
172
+        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
173
+            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
174 174
             : get_post_type_object($page);
175 175
         // tweak pagenow for page loading.
176
-        if (! $this->_pagenow_map) {
176
+        if ( ! $this->_pagenow_map) {
177 177
             $this->_pagenow_map = array(
178 178
                 'create_new' => 'post-new.php',
179 179
                 'edit'       => 'post.php',
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
     {
208 208
         global $pagenow, $hook_suffix;
209 209
         // possibly reset pagenow.
210
-        if (! empty($this->_req_data['page'])
210
+        if ( ! empty($this->_req_data['page'])
211 211
             && $this->_req_data['page'] == $this->page_slug
212 212
             && ! empty($this->_req_data['action'])
213
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
213
+            && isset($this->_pagenow_map[$this->_req_data['action']])
214 214
         ) {
215
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
215
+            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
216 216
             $hook_suffix = $pagenow;
217 217
         }
218 218
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         if (empty($wp_meta_boxes)) {
245 245
             return;
246 246
         }
247
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
247
+        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
248 248
         foreach ($current_metaboxes as $box_context) {
249 249
             foreach ($box_context as $box_details) {
250 250
                 foreach ($box_details as $box) {
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             $this
278 278
         );
279 279
         $containers = apply_filters(
280
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
280
+            'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
281 281
             $containers,
282 282
             $this
283 283
         );
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     protected function _load_page_dependencies()
322 322
     {
323 323
         // we only add stuff if this is a cpt_route!
324
-        if (! $this->_cpt_route) {
324
+        if ( ! $this->_cpt_route) {
325 325
             parent::_load_page_dependencies();
326 326
             return;
327 327
         }
@@ -345,16 +345,16 @@  discard block
 block discarded – undo
345 345
         add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
346 346
         // This basically allows us to change the title of the "publish" metabox area
347 347
         // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
348
-        if (! empty($this->_labels['publishbox'])) {
348
+        if ( ! empty($this->_labels['publishbox'])) {
349 349
             $box_label = is_array($this->_labels['publishbox'])
350
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
351
-                ? $this->_labels['publishbox'][ $this->_req_action ]
350
+                         && isset($this->_labels['publishbox'][$this->_req_action])
351
+                ? $this->_labels['publishbox'][$this->_req_action]
352 352
                 : $this->_labels['publishbox'];
353 353
             add_meta_box(
354 354
                 'submitdiv',
355 355
                 $box_label,
356 356
                 'post_submit_meta_box',
357
-                $this->_cpt_routes[ $this->_req_action ],
357
+                $this->_cpt_routes[$this->_req_action],
358 358
                 'side',
359 359
                 'core'
360 360
             );
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                 'page_templates',
366 366
                 __('Page Template', 'event_espresso'),
367 367
                 array($this, 'page_template_meta_box'),
368
-                $this->_cpt_routes[ $this->_req_action ],
368
+                $this->_cpt_routes[$this->_req_action],
369 369
                 'side',
370 370
                 'default'
371 371
             );
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
         // This is for any plugins that are doing things properly
398 398
         // and hooking into the load page hook for core wp cpt routes.
399 399
         global $pagenow;
400
-        do_action('load-' . $pagenow);
400
+        do_action('load-'.$pagenow);
401 401
         $this->modify_current_screen();
402 402
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
403 403
         // we route REALLY early.
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
                 'admin.php?page=espresso_registrations&action=contact_list',
428 428
             ),
429 429
             1 => array(
430
-                'edit.php?post_type=' . $this->_cpt_object->name,
431
-                'admin.php?page=' . $this->_cpt_object->name,
430
+                'edit.php?post_type='.$this->_cpt_object->name,
431
+                'admin.php?page='.$this->_cpt_object->name,
432 432
             ),
433 433
         );
434 434
         foreach ($routes_to_match as $route_matches) {
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
             'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
458 458
         );
459 459
         $cpt_args = $custom_post_types->getDefinitions();
460
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
460
+        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
461 461
         $cpt_has_support = ! empty($cpt_args['page_templates']);
462 462
 
463 463
         // if the installed version of WP is > 4.7 we do some additional checks.
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             // if there are $post_templates for this cpt, then we return false for this method because
467 467
             // that means we aren't going to load our page template manager and leave that up to the native
468 468
             // cpt template manager.
469
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
469
+            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
470 470
         }
471 471
 
472 472
         return $cpt_has_support;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 
541 541
         $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
542 542
         $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
543
-            ? $statuses[ $this->_cpt_model_obj->status() ]
543
+            ? $statuses[$this->_cpt_model_obj->status()]
544 544
             : '';
545 545
         $template_args = array(
546 546
             'cur_status'            => $this->_cpt_model_obj->status(),
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             $template_args['statuses'] = $statuses;
556 556
         }
557 557
 
558
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
558
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
559 559
         EEH_Template::display_template($template, $template_args);
560 560
     }
561 561
 
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
             : null;
597 597
         $this->_verify_nonce($nonce, 'autosave');
598 598
         // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
599
-        if (! defined('DOING_AUTOSAVE')) {
599
+        if ( ! defined('DOING_AUTOSAVE')) {
600 600
             define('DOING_AUTOSAVE', true);
601 601
         }
602 602
         // if we made it here then the nonce checked out.  Let's run our methods and actions
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
             $this->_template_args['success'] = true;
608 608
         }
609 609
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
610
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
610
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
611 611
         // now let's return json
612 612
         $this->_return_json();
613 613
     }
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
             return;
630 630
         }
631 631
         // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
-        if (! empty($this->_cpt_object)) {
632
+        if ( ! empty($this->_cpt_object)) {
633 633
             $this->_page_routes = array_merge(
634 634
                 array(
635 635
                     'create_new' => '_create_new_cpt_item',
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
             );
661 661
         }
662 662
         // load the next section only if this is a matching cpt route as set in the cpt routes array.
663
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
663
+        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
664 664
             return;
665 665
         }
666
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
666
+        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
667 667
         // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
668 668
         if (empty($this->_cpt_object)) {
669 669
             $msg = sprintf(
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
         if (empty($this->_cpt_model_names)
704 704
             || (
705 705
                 ! $ignore_route_check
706
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
706
+                && ! isset($this->_cpt_routes[$this->_req_action])
707 707
             ) || (
708 708
                 $this->_cpt_model_obj instanceof EE_CPT_Base
709 709
                 && $this->_cpt_model_obj->ID() === $id
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
                 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
721 721
             );
722 722
             $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
723
-            if (isset($model_names[ $post_type ])) {
724
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
723
+            if (isset($model_names[$post_type])) {
724
+                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
725 725
             }
726 726
         } else {
727
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
727
+            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
728 728
         }
729 729
         if ($model instanceof EEM_Base) {
730 730
             $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
@@ -754,8 +754,8 @@  discard block
 block discarded – undo
754 754
         $current_route = isset($this->_req_data['current_route'])
755 755
             ? $this->_req_data['current_route']
756 756
             : 'shouldneverwork';
757
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
758
-            ? $this->_cpt_routes[ $current_route ]
757
+        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
758
+            ? $this->_cpt_routes[$current_route]
759 759
             : '';
760 760
         add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
761 761
         add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
@@ -764,10 +764,10 @@  discard block
 block discarded – undo
764 764
         }
765 765
         // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
766 766
         $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
767
-        if (! empty($revision)) {
767
+        if ( ! empty($revision)) {
768 768
             $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
769 769
             // doing a restore?
770
-            if (! empty($action) && $action === 'restore') {
770
+            if ( ! empty($action) && $action === 'restore') {
771 771
                 // get post for revision
772 772
                 $rev_post = get_post($revision);
773 773
                 $rev_parent = get_post($rev_post->post_parent);
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
     {
804 804
         $this->_set_model_object($post_id, true, 'trash');
805 805
         // if our cpt object isn't existent then get out immediately.
806
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
806
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
807 807
             return;
808 808
         }
809 809
         $this->trash_cpt_item($post_id);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
     {
822 822
         $this->_set_model_object($post_id, true, 'restore');
823 823
         // if our cpt object isn't existent then get out immediately.
824
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
824
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
825 825
             return;
826 826
         }
827 827
         $this->restore_cpt_item($post_id);
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
     {
840 840
         $this->_set_model_object($post_id, true, 'delete');
841 841
         // if our cpt object isn't existent then get out immediately.
842
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
842
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843 843
             return;
844 844
         }
845 845
         $this->delete_cpt_item($post_id);
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
     {
859 859
         $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
860 860
         // verify event object
861
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
861
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
862 862
             throw new EE_Error(
863 863
                 sprintf(
864 864
                     __(
@@ -914,13 +914,13 @@  discard block
 block discarded – undo
914 914
         if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
915 915
             // setup custom post status object for localize script but only if we've got a cpt object
916 916
             $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
917
-            if (! empty($statuses)) {
917
+            if ( ! empty($statuses)) {
918 918
                 // get ALL statuses!
919 919
                 $statuses = $this->_cpt_model_obj->get_all_post_statuses();
920 920
                 // setup object
921 921
                 $ee_cpt_statuses = array();
922 922
                 foreach ($statuses as $status => $label) {
923
-                    $ee_cpt_statuses[ $status ] = array(
923
+                    $ee_cpt_statuses[$status] = array(
924 924
                         'label'      => $label,
925 925
                         'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
926 926
                     );
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 $post->page_template = $this->_req_data['page_template'];
983 983
                 $page_templates = wp_get_theme()->get_page_templates($post);
984 984
             }
985
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
985
+            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
986 986
                 EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
987 987
             } else {
988 988
                 update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
     {
1008 1008
         // only do this if we're actually processing one of our CPTs
1009 1009
         // if our cpt object isn't existent then get out immediately.
1010
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1010
+        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1011 1011
             return;
1012 1012
         }
1013 1013
         delete_post_meta($post_id, '_wp_trash_meta_status');
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
         // global action
1033 1033
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1034 1034
         // class specific action so you can limit hooking into a specific page.
1035
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1035
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1036 1036
     }
1037 1037
 
1038 1038
 
@@ -1059,11 +1059,11 @@  discard block
 block discarded – undo
1059 1059
     public function modify_current_screen()
1060 1060
     {
1061 1061
         // ONLY do this if the current page_route IS a cpt route
1062
-        if (! $this->_cpt_route) {
1062
+        if ( ! $this->_cpt_route) {
1063 1063
             return;
1064 1064
         }
1065 1065
         // routing things REALLY early b/c this is a cpt admin page
1066
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1066
+        set_current_screen($this->_cpt_routes[$this->_req_action]);
1067 1067
         $this->_current_screen = get_current_screen();
1068 1068
         $this->_current_screen->base = 'event-espresso';
1069 1069
         $this->_add_help_tabs(); // we make sure we add any help tabs back in!
@@ -1086,8 +1086,8 @@  discard block
 block discarded – undo
1086 1086
      */
1087 1087
     public function add_custom_editor_default_title($title)
1088 1088
     {
1089
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1090
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1089
+        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1090
+            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1091 1091
             : $title;
1092 1092
     }
1093 1093
 
@@ -1103,10 +1103,10 @@  discard block
 block discarded – undo
1103 1103
      */
1104 1104
     public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1105 1105
     {
1106
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1106
+        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1107 1107
             $post = get_post($id);
1108 1108
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
-                $shortlink = home_url('?p=' . $post->ID);
1109
+                $shortlink = home_url('?p='.$post->ID);
1110 1110
             }
1111 1111
         }
1112 1112
         return $shortlink;
@@ -1139,11 +1139,11 @@  discard block
 block discarded – undo
1139 1139
      */
1140 1140
     public function cpt_post_form_hidden_input()
1141 1141
     {
1142
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1142
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1143 1143
         // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1144 1144
         echo '<div id="ee-cpt-hidden-inputs">';
1145
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1146
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1145
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1146
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1147 1147
         echo '</div>';
1148 1148
     }
1149 1149
 
@@ -1188,15 +1188,15 @@  discard block
 block discarded – undo
1188 1188
     public function modify_edit_post_link($link, $id, $context)
1189 1189
     {
1190 1190
         $post = get_post($id);
1191
-        if (! isset($this->_req_data['action'])
1192
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1193
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1191
+        if ( ! isset($this->_req_data['action'])
1192
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1193
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1194 1194
         ) {
1195 1195
             return $link;
1196 1196
         }
1197 1197
         $query_args = array(
1198
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1199
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1198
+            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1199
+                ? $this->_cpt_edit_routes[$post->post_type]
1200 1200
                 : 'edit',
1201 1201
             'post'   => $id,
1202 1202
         );
@@ -1219,16 +1219,16 @@  discard block
 block discarded – undo
1219 1219
         $post = get_post($post_id);
1220 1220
 
1221 1221
         if (empty($this->_req_data['action'])
1222
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1222
+            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1223 1223
             || ! $post instanceof WP_Post
1224
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1224
+            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1225 1225
         ) {
1226 1226
             return $delete_link;
1227 1227
         }
1228 1228
         $this->_set_model_object($post->ID, true);
1229 1229
 
1230 1230
         // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1231
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1231
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1232 1232
 
1233 1233
         return EE_Admin_Page::add_query_args_and_nonce(
1234 1234
             array(
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
         // we DO have a match so let's setup the url
1257 1257
         // we have to get the post to determine our route
1258 1258
         $post = get_post($post_id);
1259
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1259
+        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1260 1260
         // shared query_args
1261 1261
         $query_args = array('action' => $edit_route, 'post' => $post_id);
1262 1262
         $admin_url = $this->_admin_base_url;
@@ -1328,12 +1328,12 @@  discard block
 block discarded – undo
1328 1328
         /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1329 1329
 
1330 1330
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1331
-        $messages[ $post->post_type ] = array(
1331
+        $messages[$post->post_type] = array(
1332 1332
             0  => '', // Unused. Messages start at index 1.
1333 1333
             1  => sprintf(
1334 1334
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1335 1335
                 $this->_cpt_object->labels->singular_name,
1336
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1336
+                '<a href="'.esc_url(get_permalink($id)).'">',
1337 1337
                 '</a>'
1338 1338
             ),
1339 1339
             2  => __('Custom field updated', 'event_espresso'),
@@ -1348,27 +1348,27 @@  discard block
 block discarded – undo
1348 1348
             6  => sprintf(
1349 1349
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1350 1350
                 $this->_cpt_object->labels->singular_name,
1351
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1351
+                '<a href="'.esc_url(get_permalink($id)).'">',
1352 1352
                 '</a>'
1353 1353
             ),
1354 1354
             7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1355 1355
             8  => sprintf(
1356 1356
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1357 1357
                 $this->_cpt_object->labels->singular_name,
1358
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1358
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1359 1359
                 '</a>'
1360 1360
             ),
1361 1361
             9  => sprintf(
1362 1362
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1363 1363
                 $this->_cpt_object->labels->singular_name,
1364
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1365
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1364
+                '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>',
1365
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1366 1366
                 '</a>'
1367 1367
             ),
1368 1368
             10 => sprintf(
1369 1369
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1370 1370
                 $this->_cpt_object->labels->singular_name,
1371
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1371
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1372 1372
                 '</a>'
1373 1373
             ),
1374 1374
         );
@@ -1387,10 +1387,10 @@  discard block
 block discarded – undo
1387 1387
     {
1388 1388
         // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1389 1389
         global $post, $title, $is_IE, $post_type, $post_type_object;
1390
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1390
+        $post_type = $this->_cpt_routes[$this->_req_action];
1391 1391
         $post_type_object = $this->_cpt_object;
1392 1392
         $title = $post_type_object->labels->add_new_item;
1393
-        $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1393
+        $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1394 1394
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1395 1395
         // modify the default editor title field with default title.
1396 1396
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
@@ -1415,8 +1415,8 @@  discard block
 block discarded – undo
1415 1415
             if ($creating) {
1416 1416
                 wp_enqueue_script('autosave');
1417 1417
             } else {
1418
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1419
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1418
+                if (isset($this->_cpt_routes[$this->_req_data['action']])
1419
+                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1420 1420
                 ) {
1421 1421
                     $create_new_action = apply_filters(
1422 1422
                         'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
                     );
1433 1433
                 }
1434 1434
             }
1435
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1435
+            include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1436 1436
         }
1437 1437
     }
1438 1438
 
@@ -1463,21 +1463,21 @@  discard block
 block discarded – undo
1463 1463
         if (empty($post)) {
1464 1464
             wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1465 1465
         }
1466
-        if (! empty($_GET['get-post-lock'])) {
1466
+        if ( ! empty($_GET['get-post-lock'])) {
1467 1467
             wp_set_post_lock($post_id);
1468 1468
             wp_redirect(get_edit_post_link($post_id, 'url'));
1469 1469
             exit();
1470 1470
         }
1471 1471
 
1472 1472
         // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1473
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1473
+        $post_type = $this->_cpt_routes[$this->_req_action];
1474 1474
         $post_type_object = $this->_cpt_object;
1475 1475
 
1476
-        if (! wp_check_post_lock($post->ID)) {
1476
+        if ( ! wp_check_post_lock($post->ID)) {
1477 1477
             wp_set_post_lock($post->ID);
1478 1478
         }
1479 1479
         add_action('admin_footer', '_admin_notice_post_locked');
1480
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1480
+        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1481 1481
             wp_enqueue_script('admin-comments');
1482 1482
             enqueue_comment_hotkeys_js();
1483 1483
         }
Please login to merge, or discard this patch.
core/wordpress-shims.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -5,91 +5,91 @@
 block discarded – undo
5 5
  * it does not override any existing definition of the function in WP.
6 6
  */
7 7
 if (! function_exists('get_preview_post_link')) {
8
-    /**
9
-     * Function was added in WordPress 4.4.0
10
-     *
11
-     * @param null   $post
12
-     * @param array  $query_args
13
-     * @param string $preview_link
14
-     * @return mixed
15
-     */
16
-    function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
17
-    {
18
-        $post = get_post($post);
19
-        if (! $post) {
20
-            return '';
21
-        }
8
+	/**
9
+	 * Function was added in WordPress 4.4.0
10
+	 *
11
+	 * @param null   $post
12
+	 * @param array  $query_args
13
+	 * @param string $preview_link
14
+	 * @return mixed
15
+	 */
16
+	function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
17
+	{
18
+		$post = get_post($post);
19
+		if (! $post) {
20
+			return '';
21
+		}
22 22
 
23
-        $post_type_object = get_post_type_object($post->post_type);
24
-        if (is_post_type_viewable($post_type_object)) {
25
-            if (! $preview_link) {
26
-                $preview_link = set_url_scheme(get_permalink($post));
27
-            }
23
+		$post_type_object = get_post_type_object($post->post_type);
24
+		if (is_post_type_viewable($post_type_object)) {
25
+			if (! $preview_link) {
26
+				$preview_link = set_url_scheme(get_permalink($post));
27
+			}
28 28
 
29
-            $query_args['preview'] = 'true';
30
-            $preview_link = add_query_arg($query_args, $preview_link);
31
-        }
29
+			$query_args['preview'] = 'true';
30
+			$preview_link = add_query_arg($query_args, $preview_link);
31
+		}
32 32
 
33
-        /**
34
-         * Filters the URL used for a post preview.
35
-         *
36
-         * @since 2.0.5
37
-         * @since 4.0.0 Added the `$post` parameter.
38
-         * @param string  $preview_link URL used for the post preview.
39
-         * @param WP_Post $post         Post object.
40
-         */
41
-        return apply_filters('preview_post_link', $preview_link, $post);
42
-    }
33
+		/**
34
+		 * Filters the URL used for a post preview.
35
+		 *
36
+		 * @since 2.0.5
37
+		 * @since 4.0.0 Added the `$post` parameter.
38
+		 * @param string  $preview_link URL used for the post preview.
39
+		 * @param WP_Post $post         Post object.
40
+		 */
41
+		return apply_filters('preview_post_link', $preview_link, $post);
42
+	}
43 43
 }
44 44
 
45 45
 if (! function_exists('is_post_type_viewable')) {
46
-    function is_post_type_viewable($post_type)
47
-    {
48
-        if (is_scalar($post_type)) {
49
-            $post_type = get_post_type_object($post_type);
50
-            if (! $post_type) {
51
-                return false;
52
-            }
53
-        }
46
+	function is_post_type_viewable($post_type)
47
+	{
48
+		if (is_scalar($post_type)) {
49
+			$post_type = get_post_type_object($post_type);
50
+			if (! $post_type) {
51
+				return false;
52
+			}
53
+		}
54 54
 
55
-        return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public);
56
-    }
55
+		return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public);
56
+	}
57 57
 }
58 58
 
59 59
 if (! function_exists('wp_scripts_get_suffix')) {
60
-    /**
61
-     * Returns the suffix that can be used for the scripts.
62
-     *
63
-     * There are two suffix types, the normal one and the dev suffix.
64
-     *
65
-     * @since 5.0.0
66
-     *
67
-     * @param string $type The type of suffix to retrieve.
68
-     * @return string The script suffix.
69
-     */
70
-    function wp_scripts_get_suffix($type = '')
71
-    {
72
-        global $wp_version;
73
-        static $suffixes;
60
+	/**
61
+	 * Returns the suffix that can be used for the scripts.
62
+	 *
63
+	 * There are two suffix types, the normal one and the dev suffix.
64
+	 *
65
+	 * @since 5.0.0
66
+	 *
67
+	 * @param string $type The type of suffix to retrieve.
68
+	 * @return string The script suffix.
69
+	 */
70
+	function wp_scripts_get_suffix($type = '')
71
+	{
72
+		global $wp_version;
73
+		static $suffixes;
74 74
 
75
-        if ($suffixes === null) {
76
-            include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version
75
+		if ($suffixes === null) {
76
+			include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version
77 77
 
78
-            $develop_src = false !== strpos($wp_version, '-src');
78
+			$develop_src = false !== strpos($wp_version, '-src');
79 79
 
80
-            if (! defined('SCRIPT_DEBUG')) {
81
-                define('SCRIPT_DEBUG', $develop_src);
82
-            }
83
-            $suffix = SCRIPT_DEBUG ? '' : '.min';
84
-            $dev_suffix = $develop_src ? '' : '.min';
80
+			if (! defined('SCRIPT_DEBUG')) {
81
+				define('SCRIPT_DEBUG', $develop_src);
82
+			}
83
+			$suffix = SCRIPT_DEBUG ? '' : '.min';
84
+			$dev_suffix = $develop_src ? '' : '.min';
85 85
 
86
-            $suffixes = array('suffix' => $suffix, 'dev_suffix' => $dev_suffix);
87
-        }
86
+			$suffixes = array('suffix' => $suffix, 'dev_suffix' => $dev_suffix);
87
+		}
88 88
 
89
-        if ($type === 'dev') {
90
-            return $suffixes['dev_suffix'];
91
-        }
89
+		if ($type === 'dev') {
90
+			return $suffixes['dev_suffix'];
91
+		}
92 92
 
93
-        return $suffixes['suffix'];
94
-    }
93
+		return $suffixes['suffix'];
94
+	}
95 95
 }
96 96
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Note: this file should only be required right before calling the function the shim is for.  This is to ensure that
5 5
  * it does not override any existing definition of the function in WP.
6 6
  */
7
-if (! function_exists('get_preview_post_link')) {
7
+if ( ! function_exists('get_preview_post_link')) {
8 8
     /**
9 9
      * Function was added in WordPress 4.4.0
10 10
      *
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
     function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
17 17
     {
18 18
         $post = get_post($post);
19
-        if (! $post) {
19
+        if ( ! $post) {
20 20
             return '';
21 21
         }
22 22
 
23 23
         $post_type_object = get_post_type_object($post->post_type);
24 24
         if (is_post_type_viewable($post_type_object)) {
25
-            if (! $preview_link) {
25
+            if ( ! $preview_link) {
26 26
                 $preview_link = set_url_scheme(get_permalink($post));
27 27
             }
28 28
 
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
     }
43 43
 }
44 44
 
45
-if (! function_exists('is_post_type_viewable')) {
45
+if ( ! function_exists('is_post_type_viewable')) {
46 46
     function is_post_type_viewable($post_type)
47 47
     {
48 48
         if (is_scalar($post_type)) {
49 49
             $post_type = get_post_type_object($post_type);
50
-            if (! $post_type) {
50
+            if ( ! $post_type) {
51 51
                 return false;
52 52
             }
53 53
         }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     }
57 57
 }
58 58
 
59
-if (! function_exists('wp_scripts_get_suffix')) {
59
+if ( ! function_exists('wp_scripts_get_suffix')) {
60 60
     /**
61 61
      * Returns the suffix that can be used for the scripts.
62 62
      *
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
         static $suffixes;
74 74
 
75 75
         if ($suffixes === null) {
76
-            include(ABSPATH . WPINC . '/version.php'); // include an unmodified $wp_version
76
+            include(ABSPATH.WPINC.'/version.php'); // include an unmodified $wp_version
77 77
 
78 78
             $develop_src = false !== strpos($wp_version, '-src');
79 79
 
80
-            if (! defined('SCRIPT_DEBUG')) {
80
+            if ( ! defined('SCRIPT_DEBUG')) {
81 81
                 define('SCRIPT_DEBUG', $develop_src);
82 82
             }
83 83
             $suffix = SCRIPT_DEBUG ? '' : '.min';
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -23,179 +23,179 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
-        add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
-    }
59
-
60
-
61
-    /**
62
-     * @since $VID:$
63
-     * @return string
64
-     */
65
-    public function assetNamespace()
66
-    {
67
-        return $this->domain->assetNamespace();
68
-    }
69
-
70
-
71
-    /**
72
-     * @return void
73
-     * @throws DuplicateCollectionIdentifierException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidEntityException
76
-     * @since 4.9.62.p
77
-     */
78
-    public function addManifestFile()
79
-    {
80
-        // if a manifest file has already been added for this domain, then just return
81
-        if ($this->assets->has($this->domain->assetNamespace())) {
82
-            return;
83
-        }
84
-        $asset = new ManifestFile($this->domain);
85
-        $this->assets->add($asset, $this->domain->assetNamespace());
86
-    }
87
-
88
-
89
-    /**
90
-     * @return ManifestFile[]
91
-     * @since 4.9.62.p
92
-     */
93
-    public function getManifestFile()
94
-    {
95
-        return $this->assets->getManifestFiles();
96
-    }
97
-
98
-
99
-    /**
100
-     * @param string $handle
101
-     * @param string $source
102
-     * @param array  $dependencies
103
-     * @param bool   $load_in_footer
104
-     * @return JavascriptAsset
105
-     * @throws DuplicateCollectionIdentifierException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidEntityException
108
-     * @since 4.9.62.p
109
-     */
110
-    public function addJavascript(
111
-        $handle,
112
-        $source,
113
-        array $dependencies = array(),
114
-        $load_in_footer = true
115
-    ) {
116
-        $asset = new JavascriptAsset(
117
-            $handle,
118
-            $source,
119
-            $dependencies,
120
-            $load_in_footer,
121
-            $this->domain
122
-        );
123
-        $this->assets->add($asset, $handle);
124
-        return $asset;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $handle
130
-     * @param array  $dependencies
131
-     * @param bool   $load_in_footer
132
-     * @return JavascriptAsset
133
-     * @throws DuplicateCollectionIdentifierException
134
-     * @throws InvalidDataTypeException
135
-     * @throws InvalidEntityException
136
-     * @throws DomainException
137
-     * @since $VID:$
138
-     */
139
-    public function addVendorJavascript(
140
-        $handle,
141
-        array $dependencies = array(),
142
-        $load_in_footer = true
143
-    ) {
144
-        $dev_suffix = wp_scripts_get_suffix('dev');
145
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
146
-        return $this->addJavascript(
147
-            $handle,
148
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
149
-            $dependencies,
150
-            $load_in_footer
151
-        );
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param string $handle
158
-     * @param string $source
159
-     * @param array  $dependencies
160
-     * @param string $media
161
-     * @return StylesheetAsset
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidDataTypeException
164
-     * @throws InvalidEntityException
165
-     * @since 4.9.62.p
166
-     */
167
-    public function addStylesheet(
168
-        $handle,
169
-        $source,
170
-        array $dependencies = array(),
171
-        $media = 'all'
172
-    ) {
173
-        $asset = new StylesheetAsset(
174
-            $handle,
175
-            $source,
176
-            $dependencies,
177
-            $this->domain,
178
-            $media
179
-        );
180
-        $this->assets->add($asset, $handle);
181
-        return $asset;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $handle
187
-     * @return bool
188
-     * @since 4.9.62.p
189
-     */
190
-    public function enqueueAsset($handle)
191
-    {
192
-        if ($this->assets->has($handle)) {
193
-            $asset = $this->assets->get($handle);
194
-            if ($asset->isRegistered()) {
195
-                $asset->enqueueAsset();
196
-                return true;
197
-            }
198
-        }
199
-        return false;
200
-    }
26
+	/**
27
+	 * @var AssetCollection $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
+		add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @since $VID:$
63
+	 * @return string
64
+	 */
65
+	public function assetNamespace()
66
+	{
67
+		return $this->domain->assetNamespace();
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return void
73
+	 * @throws DuplicateCollectionIdentifierException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidEntityException
76
+	 * @since 4.9.62.p
77
+	 */
78
+	public function addManifestFile()
79
+	{
80
+		// if a manifest file has already been added for this domain, then just return
81
+		if ($this->assets->has($this->domain->assetNamespace())) {
82
+			return;
83
+		}
84
+		$asset = new ManifestFile($this->domain);
85
+		$this->assets->add($asset, $this->domain->assetNamespace());
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return ManifestFile[]
91
+	 * @since 4.9.62.p
92
+	 */
93
+	public function getManifestFile()
94
+	{
95
+		return $this->assets->getManifestFiles();
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param string $handle
101
+	 * @param string $source
102
+	 * @param array  $dependencies
103
+	 * @param bool   $load_in_footer
104
+	 * @return JavascriptAsset
105
+	 * @throws DuplicateCollectionIdentifierException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidEntityException
108
+	 * @since 4.9.62.p
109
+	 */
110
+	public function addJavascript(
111
+		$handle,
112
+		$source,
113
+		array $dependencies = array(),
114
+		$load_in_footer = true
115
+	) {
116
+		$asset = new JavascriptAsset(
117
+			$handle,
118
+			$source,
119
+			$dependencies,
120
+			$load_in_footer,
121
+			$this->domain
122
+		);
123
+		$this->assets->add($asset, $handle);
124
+		return $asset;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $handle
130
+	 * @param array  $dependencies
131
+	 * @param bool   $load_in_footer
132
+	 * @return JavascriptAsset
133
+	 * @throws DuplicateCollectionIdentifierException
134
+	 * @throws InvalidDataTypeException
135
+	 * @throws InvalidEntityException
136
+	 * @throws DomainException
137
+	 * @since $VID:$
138
+	 */
139
+	public function addVendorJavascript(
140
+		$handle,
141
+		array $dependencies = array(),
142
+		$load_in_footer = true
143
+	) {
144
+		$dev_suffix = wp_scripts_get_suffix('dev');
145
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
146
+		return $this->addJavascript(
147
+			$handle,
148
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
149
+			$dependencies,
150
+			$load_in_footer
151
+		);
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param string $handle
158
+	 * @param string $source
159
+	 * @param array  $dependencies
160
+	 * @param string $media
161
+	 * @return StylesheetAsset
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidDataTypeException
164
+	 * @throws InvalidEntityException
165
+	 * @since 4.9.62.p
166
+	 */
167
+	public function addStylesheet(
168
+		$handle,
169
+		$source,
170
+		array $dependencies = array(),
171
+		$media = 'all'
172
+	) {
173
+		$asset = new StylesheetAsset(
174
+			$handle,
175
+			$source,
176
+			$dependencies,
177
+			$this->domain,
178
+			$media
179
+		);
180
+		$this->assets->add($asset, $handle);
181
+		return $asset;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $handle
187
+	 * @return bool
188
+	 * @since 4.9.62.p
189
+	 */
190
+	public function enqueueAsset($handle)
191
+	{
192
+		if ($this->assets->has($handle)) {
193
+			$asset = $this->assets->get($handle);
194
+			if ($asset->isRegistered()) {
195
+				$asset->enqueueAsset();
196
+				return true;
197
+			}
198
+		}
199
+		return false;
200
+	}
201 201
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
         $load_in_footer = true
143 143
     ) {
144 144
         $dev_suffix = wp_scripts_get_suffix('dev');
145
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
145
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
146 146
         return $this->addJavascript(
147 147
             $handle,
148 148
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
core/services/assets/AssetManagerInterface.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -20,92 +20,92 @@
 block discarded – undo
20 20
  */
21 21
 interface AssetManagerInterface
22 22
 {
23
-    /**
24
-     * @since $VID:$
25
-     * @return string
26
-     */
27
-    public function assetNamespace();
28
-
29
-    /**
30
-     * @since 4.9.62.p
31
-     */
32
-    public function addAssets();
33
-
34
-
35
-    /**
36
-     * @return ManifestFile
37
-     * @throws DuplicateCollectionIdentifierException
38
-     * @throws InvalidDataTypeException
39
-     * @throws InvalidEntityException
40
-     * @since 4.9.62.p
41
-     */
42
-    public function addManifestFile();
43
-
44
-
45
-    /**
46
-     * @return ManifestFile[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getManifestFile();
50
-
51
-
52
-    /**
53
-     * @param string $handle
54
-     * @param string $source
55
-     * @param array  $dependencies
56
-     * @param bool   $load_in_footer
57
-     * @return JavascriptAsset
58
-     * @throws DuplicateCollectionIdentifierException
59
-     * @throws InvalidDataTypeException
60
-     * @throws InvalidEntityException
61
-     * @since 4.9.62.p
62
-     */
63
-    public function addJavascript(
64
-        $handle,
65
-        $source,
66
-        array $dependencies = array(),
67
-        $load_in_footer = true
68
-    );
69
-
70
-
71
-    /**
72
-     * @since $VID:$
73
-     * @param string $handle
74
-     * @param array  $dependencies
75
-     * @param bool   $load_in_footer
76
-     * @return JavascriptAsset
77
-     */
78
-    public function addVendorJavascript(
79
-        $handle,
80
-        array $dependencies = array(),
81
-        $load_in_footer = true
82
-    );
83
-
84
-
85
-
86
-    /**
87
-     * @param string $handle
88
-     * @param string $source
89
-     * @param array  $dependencies
90
-     * @param string $media
91
-     * @return StylesheetAsset
92
-     * @throws DuplicateCollectionIdentifierException
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidEntityException
95
-     * @since 4.9.62.p
96
-     */
97
-    public function addStylesheet(
98
-        $handle,
99
-        $source,
100
-        array $dependencies = array(),
101
-        $media = 'all'
102
-    );
103
-
104
-
105
-    /**
106
-     * @param string $handle
107
-     * @return bool
108
-     * @since 4.9.62.p
109
-     */
110
-    public function enqueueAsset($handle);
23
+	/**
24
+	 * @since $VID:$
25
+	 * @return string
26
+	 */
27
+	public function assetNamespace();
28
+
29
+	/**
30
+	 * @since 4.9.62.p
31
+	 */
32
+	public function addAssets();
33
+
34
+
35
+	/**
36
+	 * @return ManifestFile
37
+	 * @throws DuplicateCollectionIdentifierException
38
+	 * @throws InvalidDataTypeException
39
+	 * @throws InvalidEntityException
40
+	 * @since 4.9.62.p
41
+	 */
42
+	public function addManifestFile();
43
+
44
+
45
+	/**
46
+	 * @return ManifestFile[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getManifestFile();
50
+
51
+
52
+	/**
53
+	 * @param string $handle
54
+	 * @param string $source
55
+	 * @param array  $dependencies
56
+	 * @param bool   $load_in_footer
57
+	 * @return JavascriptAsset
58
+	 * @throws DuplicateCollectionIdentifierException
59
+	 * @throws InvalidDataTypeException
60
+	 * @throws InvalidEntityException
61
+	 * @since 4.9.62.p
62
+	 */
63
+	public function addJavascript(
64
+		$handle,
65
+		$source,
66
+		array $dependencies = array(),
67
+		$load_in_footer = true
68
+	);
69
+
70
+
71
+	/**
72
+	 * @since $VID:$
73
+	 * @param string $handle
74
+	 * @param array  $dependencies
75
+	 * @param bool   $load_in_footer
76
+	 * @return JavascriptAsset
77
+	 */
78
+	public function addVendorJavascript(
79
+		$handle,
80
+		array $dependencies = array(),
81
+		$load_in_footer = true
82
+	);
83
+
84
+
85
+
86
+	/**
87
+	 * @param string $handle
88
+	 * @param string $source
89
+	 * @param array  $dependencies
90
+	 * @param string $media
91
+	 * @return StylesheetAsset
92
+	 * @throws DuplicateCollectionIdentifierException
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidEntityException
95
+	 * @since 4.9.62.p
96
+	 */
97
+	public function addStylesheet(
98
+		$handle,
99
+		$source,
100
+		array $dependencies = array(),
101
+		$media = 'all'
102
+	);
103
+
104
+
105
+	/**
106
+	 * @param string $handle
107
+	 * @return bool
108
+	 * @since 4.9.62.p
109
+	 */
110
+	public function enqueueAsset($handle);
111 111
 }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     public static function instance(ClassInterfaceCache $class_cache = null)
123 123
     {
124 124
         // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
125
+        if ( ! self::$_instance instanceof EE_Dependency_Map
126 126
             && $class_cache instanceof ClassInterfaceCache
127 127
         ) {
128 128
             self::$_instance = new EE_Dependency_Map($class_cache);
@@ -203,18 +203,18 @@  discard block
 block discarded – undo
203 203
     ) {
204 204
         $class = trim($class, '\\');
205 205
         $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
206
+        if (empty(self::$_instance->_dependency_map[$class])) {
207
+            self::$_instance->_dependency_map[$class] = array();
208 208
         }
209 209
         // we need to make sure that any aliases used when registering a dependency
210 210
         // get resolved to the correct class name
211 211
         foreach ($dependencies as $dependency => $load_source) {
212 212
             $alias = self::$_instance->getFqnForAlias($dependency);
213 213
             if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
214
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
215 215
             ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
216
+                unset($dependencies[$dependency]);
217
+                $dependencies[$alias] = $load_source;
218 218
                 $registered = true;
219 219
             }
220 220
         }
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225 225
         // Union is way faster than array_merge() but should be used with caution...
226 226
         // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
227
+        $dependencies += self::$_instance->_dependency_map[$class];
228 228
         // now we need to ensure that the resulting dependencies
229 229
         // array only has the entries that are required for the class
230 230
         // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
231
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
232 232
         // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
233
+        self::$_instance->_dependency_map[$class] = $dependency_count
234 234
             // then truncate the  final array to match that count
235 235
             ? array_slice($dependencies, 0, $dependency_count)
236 236
             // otherwise just take the incoming array because nothing previously existed
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public static function register_class_loader($class_name, $loader = 'load_core')
249 249
     {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
250
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251 251
             throw new DomainException(
252 252
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253 253
             );
254 254
         }
255 255
         // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
256
+        if ( ! is_callable($loader)
257 257
             && (
258 258
                 strpos($loader, 'load_') !== 0
259 259
                 || ! method_exists('EE_Registry', $loader)
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
             );
271 271
         }
272 272
         $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
273
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
274
+            self::$_instance->_class_loaders[$class_name] = $loader;
275 275
             return true;
276 276
         }
277 277
         return false;
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         if (strpos($class_name, 'EEM_') === 0) {
300 300
             $class_name = 'LEGACY_MODELS';
301 301
         }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
302
+        return isset($this->_dependency_map[$class_name]) ? true : false;
303 303
     }
304 304
 
305 305
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             $class_name = 'LEGACY_MODELS';
318 318
         }
319 319
         $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
320
+        return isset($this->_dependency_map[$class_name][$dependency])
321 321
             ? true
322 322
             : false;
323 323
     }
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
         }
339 339
         $dependency = $this->getFqnForAlias($dependency);
340 340
         return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
341
+            ? $this->_dependency_map[$class_name][$dependency]
342 342
             : EE_Dependency_Map::not_registered;
343 343
     }
344 344
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
             return 'load_core';
362 362
         }
363 363
         $class_name = $this->getFqnForAlias($class_name);
364
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
364
+        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
365 365
     }
366 366
 
367 367
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
     {
866 866
         $this->_class_loaders = array(
867 867
             // load_core
868
-            'EE_Dependency_Map'                            => function () {
868
+            'EE_Dependency_Map'                            => function() {
869 869
                 return $this;
870 870
             },
871 871
             'EE_Capabilities'                              => 'load_core',
@@ -873,13 +873,13 @@  discard block
 block discarded – undo
873 873
             'EE_Front_Controller'                          => 'load_core',
874 874
             'EE_Module_Request_Router'                     => 'load_core',
875 875
             'EE_Registry'                                  => 'load_core',
876
-            'EE_Request'                                   => function () {
876
+            'EE_Request'                                   => function() {
877 877
                 return $this->legacy_request;
878 878
             },
879
-            'EventEspresso\core\services\request\Request'  => function () {
879
+            'EventEspresso\core\services\request\Request'  => function() {
880 880
                 return $this->request;
881 881
             },
882
-            'EventEspresso\core\services\request\Response' => function () {
882
+            'EventEspresso\core\services\request\Response' => function() {
883 883
                 return $this->response;
884 884
             },
885 885
             'EE_Base'                                      => 'load_core',
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
             'EE_Messages_Data_Handler_Collection'          => 'load_lib',
904 904
             'EE_Message_Template_Group_Collection'         => 'load_lib',
905 905
             'EE_Payment_Method_Manager'                    => 'load_lib',
906
-            'EE_Messages_Generator'                        => function () {
906
+            'EE_Messages_Generator'                        => function() {
907 907
                 return EE_Registry::instance()->load_lib(
908 908
                     'Messages_Generator',
909 909
                     array(),
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
                     false
912 912
                 );
913 913
             },
914
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
914
+            'EE_Messages_Template_Defaults'                => function($arguments = array()) {
915 915
                 return EE_Registry::instance()->load_lib(
916 916
                     'Messages_Template_Defaults',
917 917
                     $arguments,
@@ -920,43 +920,43 @@  discard block
 block discarded – undo
920 920
                 );
921 921
             },
922 922
             // load_helper
923
-            'EEH_Parse_Shortcodes'                         => function () {
923
+            'EEH_Parse_Shortcodes'                         => function() {
924 924
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
925 925
                     return new EEH_Parse_Shortcodes();
926 926
                 }
927 927
                 return null;
928 928
             },
929
-            'EE_Template_Config'                           => function () {
929
+            'EE_Template_Config'                           => function() {
930 930
                 return EE_Config::instance()->template_settings;
931 931
             },
932
-            'EE_Currency_Config'                           => function () {
932
+            'EE_Currency_Config'                           => function() {
933 933
                 return EE_Config::instance()->currency;
934 934
             },
935
-            'EE_Registration_Config'                       => function () {
935
+            'EE_Registration_Config'                       => function() {
936 936
                 return EE_Config::instance()->registration;
937 937
             },
938
-            'EE_Core_Config'                               => function () {
938
+            'EE_Core_Config'                               => function() {
939 939
                 return EE_Config::instance()->core;
940 940
             },
941
-            'EventEspresso\core\services\loaders\Loader'   => function () {
941
+            'EventEspresso\core\services\loaders\Loader'   => function() {
942 942
                 return LoaderFactory::getLoader();
943 943
             },
944
-            'EE_Network_Config'                            => function () {
944
+            'EE_Network_Config'                            => function() {
945 945
                 return EE_Network_Config::instance();
946 946
             },
947
-            'EE_Config'                                    => function () {
947
+            'EE_Config'                                    => function() {
948 948
                 return EE_Config::instance();
949 949
             },
950
-            'EventEspresso\core\domain\Domain'             => function () {
950
+            'EventEspresso\core\domain\Domain'             => function() {
951 951
                 return DomainFactory::getEventEspressoCoreDomain();
952 952
             },
953
-            'EE_Admin_Config'                              => function () {
953
+            'EE_Admin_Config'                              => function() {
954 954
                 return EE_Config::instance()->admin;
955 955
             },
956
-            'EE_Organization_Config'                       => function () {
956
+            'EE_Organization_Config'                       => function() {
957 957
                 return EE_Config::instance()->organization;
958 958
             },
959
-            'EE_Network_Core_Config'                            => function () {
959
+            'EE_Network_Core_Config'                            => function() {
960 960
                 return EE_Network_Config::instance()->core;
961 961
             },
962 962
         );
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
             }
1018 1018
             $this->class_cache->addAlias($fqn, $alias);
1019 1019
         }
1020
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1020
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1021 1021
             $this->class_cache->addAlias(
1022 1022
                 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
1023 1023
                 'EventEspresso\core\services\notices\NoticeConverterInterface'
Please login to merge, or discard this patch.
Indentation   +1069 added lines, -1069 removed lines patch added patch discarded remove patch
@@ -20,1073 +20,1073 @@
 block discarded – undo
20 20
 class EE_Dependency_Map
21 21
 {
22 22
 
23
-    /**
24
-     * This means that the requested class dependency is not present in the dependency map
25
-     */
26
-    const not_registered = 0;
27
-
28
-    /**
29
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
-     */
31
-    const load_new_object = 1;
32
-
33
-    /**
34
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
-     */
37
-    const load_from_cache = 2;
38
-
39
-    /**
40
-     * When registering a dependency,
41
-     * this indicates to keep any existing dependencies that already exist,
42
-     * and simply discard any new dependencies declared in the incoming data
43
-     */
44
-    const KEEP_EXISTING_DEPENDENCIES = 0;
45
-
46
-    /**
47
-     * When registering a dependency,
48
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
-     */
50
-    const OVERWRITE_DEPENDENCIES = 1;
51
-
52
-
53
-    /**
54
-     * @type EE_Dependency_Map $_instance
55
-     */
56
-    protected static $_instance;
57
-
58
-    /**
59
-     * @var ClassInterfaceCache $class_cache
60
-     */
61
-    private $class_cache;
62
-
63
-    /**
64
-     * @type RequestInterface $request
65
-     */
66
-    protected $request;
67
-
68
-    /**
69
-     * @type LegacyRequestInterface $legacy_request
70
-     */
71
-    protected $legacy_request;
72
-
73
-    /**
74
-     * @type ResponseInterface $response
75
-     */
76
-    protected $response;
77
-
78
-    /**
79
-     * @type LoaderInterface $loader
80
-     */
81
-    protected $loader;
82
-
83
-    /**
84
-     * @type array $_dependency_map
85
-     */
86
-    protected $_dependency_map = array();
87
-
88
-    /**
89
-     * @type array $_class_loaders
90
-     */
91
-    protected $_class_loaders = array();
92
-
93
-
94
-    /**
95
-     * EE_Dependency_Map constructor.
96
-     *
97
-     * @param ClassInterfaceCache $class_cache
98
-     */
99
-    protected function __construct(ClassInterfaceCache $class_cache)
100
-    {
101
-        $this->class_cache = $class_cache;
102
-        do_action('EE_Dependency_Map____construct', $this);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function initialize()
110
-    {
111
-        $this->_register_core_dependencies();
112
-        $this->_register_core_class_loaders();
113
-        $this->_register_core_aliases();
114
-    }
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param ClassInterfaceCache|null $class_cache
120
-     * @return EE_Dependency_Map
121
-     */
122
-    public static function instance(ClassInterfaceCache $class_cache = null)
123
-    {
124
-        // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
126
-            && $class_cache instanceof ClassInterfaceCache
127
-        ) {
128
-            self::$_instance = new EE_Dependency_Map($class_cache);
129
-        }
130
-        return self::$_instance;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param RequestInterface $request
136
-     */
137
-    public function setRequest(RequestInterface $request)
138
-    {
139
-        $this->request = $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param LegacyRequestInterface $legacy_request
145
-     */
146
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
-    {
148
-        $this->legacy_request = $legacy_request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param ResponseInterface $response
154
-     */
155
-    public function setResponse(ResponseInterface $response)
156
-    {
157
-        $this->response = $response;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param LoaderInterface $loader
163
-     */
164
-    public function setLoader(LoaderInterface $loader)
165
-    {
166
-        $this->loader = $loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $class
172
-     * @param array  $dependencies
173
-     * @param int    $overwrite
174
-     * @return bool
175
-     */
176
-    public static function register_dependencies(
177
-        $class,
178
-        array $dependencies,
179
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
-    ) {
181
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
-    }
183
-
184
-
185
-    /**
186
-     * Assigns an array of class names and corresponding load sources (new or cached)
187
-     * to the class specified by the first parameter.
188
-     * IMPORTANT !!!
189
-     * The order of elements in the incoming $dependencies array MUST match
190
-     * the order of the constructor parameters for the class in question.
191
-     * This is especially important when overriding any existing dependencies that are registered.
192
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
-     *
194
-     * @param string $class
195
-     * @param array  $dependencies
196
-     * @param int    $overwrite
197
-     * @return bool
198
-     */
199
-    public function registerDependencies(
200
-        $class,
201
-        array $dependencies,
202
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
-    ) {
204
-        $class = trim($class, '\\');
205
-        $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
208
-        }
209
-        // we need to make sure that any aliases used when registering a dependency
210
-        // get resolved to the correct class name
211
-        foreach ($dependencies as $dependency => $load_source) {
212
-            $alias = self::$_instance->getFqnForAlias($dependency);
213
-            if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
-            ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
218
-                $registered = true;
219
-            }
220
-        }
221
-        // now add our two lists of dependencies together.
222
-        // using Union (+=) favours the arrays in precedence from left to right,
223
-        // so $dependencies is NOT overwritten because it is listed first
224
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
-        // Union is way faster than array_merge() but should be used with caution...
226
-        // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
228
-        // now we need to ensure that the resulting dependencies
229
-        // array only has the entries that are required for the class
230
-        // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
-        // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
234
-            // then truncate the  final array to match that count
235
-            ? array_slice($dependencies, 0, $dependency_count)
236
-            // otherwise just take the incoming array because nothing previously existed
237
-            : $dependencies;
238
-        return $registered;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param string $class_name
244
-     * @param string $loader
245
-     * @return bool
246
-     * @throws DomainException
247
-     */
248
-    public static function register_class_loader($class_name, $loader = 'load_core')
249
-    {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
-            throw new DomainException(
252
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
-            );
254
-        }
255
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
257
-            && (
258
-                strpos($loader, 'load_') !== 0
259
-                || ! method_exists('EE_Registry', $loader)
260
-            )
261
-        ) {
262
-            throw new DomainException(
263
-                sprintf(
264
-                    esc_html__(
265
-                        '"%1$s" is not a valid loader method on EE_Registry.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $loader
269
-                )
270
-            );
271
-        }
272
-        $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
275
-            return true;
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function dependency_map()
285
-    {
286
-        return $this->_dependency_map;
287
-    }
288
-
289
-
290
-    /**
291
-     * returns TRUE if dependency map contains a listing for the provided class name
292
-     *
293
-     * @param string $class_name
294
-     * @return boolean
295
-     */
296
-    public function has($class_name = '')
297
-    {
298
-        // all legacy models have the same dependencies
299
-        if (strpos($class_name, 'EEM_') === 0) {
300
-            $class_name = 'LEGACY_MODELS';
301
-        }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return bool
312
-     */
313
-    public function has_dependency_for_class($class_name = '', $dependency = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
-            ? true
322
-            : false;
323
-    }
324
-
325
-
326
-    /**
327
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
-     *
329
-     * @param string $class_name
330
-     * @param string $dependency
331
-     * @return int
332
-     */
333
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
-    {
335
-        // all legacy models have the same dependencies
336
-        if (strpos($class_name, 'EEM_') === 0) {
337
-            $class_name = 'LEGACY_MODELS';
338
-        }
339
-        $dependency = $this->getFqnForAlias($dependency);
340
-        return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
342
-            : EE_Dependency_Map::not_registered;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $class_name
348
-     * @return string | Closure
349
-     */
350
-    public function class_loader($class_name)
351
-    {
352
-        // all legacy models use load_model()
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            return 'load_model';
355
-        }
356
-        // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
-        // perform strpos() first to avoid loading regex every time we load a class
358
-        if (strpos($class_name, 'EE_CPT_') === 0
359
-            && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
-        ) {
361
-            return 'load_core';
362
-        }
363
-        $class_name = $this->getFqnForAlias($class_name);
364
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
-    }
366
-
367
-
368
-    /**
369
-     * @return array
370
-     */
371
-    public function class_loaders()
372
-    {
373
-        return $this->_class_loaders;
374
-    }
375
-
376
-
377
-    /**
378
-     * adds an alias for a classname
379
-     *
380
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
-     */
384
-    public function add_alias($fqcn, $alias, $for_class = '')
385
-    {
386
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns TRUE if the provided fully qualified name IS an alias
392
-     * WHY?
393
-     * Because if a class is type hinting for a concretion,
394
-     * then why would we need to find another class to supply it?
395
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
-     * Don't go looking for some substitute.
398
-     * Whereas if a class is type hinting for an interface...
399
-     * then we need to find an actual class to use.
400
-     * So the interface IS the alias for some other FQN,
401
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
-     * represents some other class.
403
-     *
404
-     * @param string $fqn
405
-     * @param string $for_class
406
-     * @return bool
407
-     */
408
-    public function isAlias($fqn = '', $for_class = '')
409
-    {
410
-        return $this->class_cache->isAlias($fqn, $for_class);
411
-    }
412
-
413
-
414
-    /**
415
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
-     *  for example:
418
-     *      if the following two entries were added to the _aliases array:
419
-     *          array(
420
-     *              'interface_alias'           => 'some\namespace\interface'
421
-     *              'some\namespace\interface'  => 'some\namespace\classname'
422
-     *          )
423
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
-     *      to load an instance of 'some\namespace\classname'
425
-     *
426
-     * @param string $alias
427
-     * @param string $for_class
428
-     * @return string
429
-     */
430
-    public function getFqnForAlias($alias = '', $for_class = '')
431
-    {
432
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
-    }
434
-
435
-
436
-    /**
437
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
-     * This is done by using the following class constants:
440
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
442
-     */
443
-    protected function _register_core_dependencies()
444
-    {
445
-        $this->_dependency_map = array(
446
-            'EE_Request_Handler'                                                                                          => array(
447
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_System'                                                                                                   => array(
450
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
-            ),
455
-            'EE_Session'                                                                                                  => array(
456
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
-                'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
-            ),
462
-            'EE_Cart'                                                                                                     => array(
463
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_Front_Controller'                                                                                         => array(
466
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
-            ),
470
-            'EE_Messenger_Collection_Loader'                                                                              => array(
471
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
-            ),
473
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
474
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
-            ),
476
-            'EE_Message_Resource_Manager'                                                                                 => array(
477
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
-            ),
481
-            'EE_Message_Factory'                                                                                          => array(
482
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_messages'                                                                                                 => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Generator'                                                                                       => array(
488
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
-            ),
493
-            'EE_Messages_Processor'                                                                                       => array(
494
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EE_Messages_Queue'                                                                                           => array(
497
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
-            ),
499
-            'EE_Messages_Template_Defaults'                                                                               => array(
500
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
504
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
-            ),
507
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
-            ),
517
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
561
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EE_Data_Migration_Class_Base'                                                                                => array(
564
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
572
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
-            ),
579
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
580
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
584
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
-            ),
587
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
588
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
-            ),
591
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
592
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
596
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
-            ),
599
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
600
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
-            ),
603
-            'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
-                array(),
605
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
-            ),
611
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
-            ),
620
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
-            ),
623
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
-            ),
626
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
-            ),
632
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
-            ),
635
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
-                'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
-            ),
642
-            'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
-                null,
644
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'LEGACY_MODELS'                                                                                               => array(
650
-                null,
651
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
-            ),
653
-            'EE_Module_Request_Router'                                                                                    => array(
654
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
655
-            ),
656
-            'EE_Registration_Processor'                                                                                   => array(
657
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
658
-            ),
659
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
-                null,
661
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
-                'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
-            ),
664
-            'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
-            ),
668
-            'EE_Admin_Transactions_List_Table'                                                                            => array(
669
-                null,
670
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
-            ),
672
-            'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
-            ),
677
-            'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
-            ),
681
-            'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
-            ),
690
-            'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
-            ),
693
-            'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
-            ),
696
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
-            ),
700
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
-            ),
703
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
-                'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
-                'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
-                'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
-                'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
-            ),
710
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
-            ),
713
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
-                'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
-            ),
717
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
-            ),
720
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
-            ),
723
-            'EE_CPT_Strategy'                                                                                             => array(
724
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
-            ),
727
-            'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
-            ),
730
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
-            ),
737
-            'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
-            ),
741
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
-            ),
744
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
-            ),
748
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
-                'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
-            ),
751
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
-            ),
754
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
-            ),
757
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
-            ),
760
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
-                'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
-            ),
764
-            'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
-                null,
766
-                null,
767
-                null,
768
-                'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
-            ),
772
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
-                'EE_Config' => EE_Dependency_Map::load_from_cache
775
-            ),
776
-            'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
777
-                'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
778
-                'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
779
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache,
780
-                'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
781
-            ),
782
-            'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array(
783
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
784
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
785
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
786
-            ),
787
-            'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array(
788
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
789
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
790
-            ),
791
-            'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array(
792
-                'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache,
793
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
794
-                'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache,
795
-            ),
796
-            'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array(
797
-                'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache,
798
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
799
-                'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache,
800
-            ),
801
-            'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array(
802
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache,
803
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
804
-            ),
805
-            'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array(
806
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache,
807
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache,
808
-            ),
809
-            'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
810
-                'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
811
-            ),
812
-            'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
813
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
814
-            ),
815
-            'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
816
-                'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
817
-            ),
818
-            'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
819
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
820
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
821
-            ),
822
-            'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
823
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
824
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
825
-            ),
826
-            'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
827
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
828
-            ),
829
-            'EventEspresso\core\services\session\SessionStartHandler' => array(
830
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
831
-            ),
832
-            'EE_URL_Validation_Strategy' => array(
833
-                null,
834
-                null,
835
-                'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache
836
-            ),
837
-            'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array(
838
-                'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
839
-                'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
840
-                'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
841
-                'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
842
-                'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
843
-            ),
844
-            'EventEspresso\core\services\address\CountrySubRegionDao' => array(
845
-                'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
846
-                'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
847
-            ),
848
-        );
849
-    }
850
-
851
-
852
-    /**
853
-     * Registers how core classes are loaded.
854
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
855
-     *        'EE_Request_Handler' => 'load_core'
856
-     *        'EE_Messages_Queue'  => 'load_lib'
857
-     *        'EEH_Debug_Tools'    => 'load_helper'
858
-     * or, if greater control is required, by providing a custom closure. For example:
859
-     *        'Some_Class' => function () {
860
-     *            return new Some_Class();
861
-     *        },
862
-     * This is required for instantiating dependencies
863
-     * where an interface has been type hinted in a class constructor. For example:
864
-     *        'Required_Interface' => function () {
865
-     *            return new A_Class_That_Implements_Required_Interface();
866
-     *        },
867
-     */
868
-    protected function _register_core_class_loaders()
869
-    {
870
-        $this->_class_loaders = array(
871
-            // load_core
872
-            'EE_Dependency_Map'                            => function () {
873
-                return $this;
874
-            },
875
-            'EE_Capabilities'                              => 'load_core',
876
-            'EE_Encryption'                                => 'load_core',
877
-            'EE_Front_Controller'                          => 'load_core',
878
-            'EE_Module_Request_Router'                     => 'load_core',
879
-            'EE_Registry'                                  => 'load_core',
880
-            'EE_Request'                                   => function () {
881
-                return $this->legacy_request;
882
-            },
883
-            'EventEspresso\core\services\request\Request'  => function () {
884
-                return $this->request;
885
-            },
886
-            'EventEspresso\core\services\request\Response' => function () {
887
-                return $this->response;
888
-            },
889
-            'EE_Base'                                      => 'load_core',
890
-            'EE_Request_Handler'                           => 'load_core',
891
-            'EE_Session'                                   => 'load_core',
892
-            'EE_Cron_Tasks'                                => 'load_core',
893
-            'EE_System'                                    => 'load_core',
894
-            'EE_Maintenance_Mode'                          => 'load_core',
895
-            'EE_Register_CPTs'                             => 'load_core',
896
-            'EE_Admin'                                     => 'load_core',
897
-            'EE_CPT_Strategy'                              => 'load_core',
898
-            // load_lib
899
-            'EE_Message_Resource_Manager'                  => 'load_lib',
900
-            'EE_Message_Type_Collection'                   => 'load_lib',
901
-            'EE_Message_Type_Collection_Loader'            => 'load_lib',
902
-            'EE_Messenger_Collection'                      => 'load_lib',
903
-            'EE_Messenger_Collection_Loader'               => 'load_lib',
904
-            'EE_Messages_Processor'                        => 'load_lib',
905
-            'EE_Message_Repository'                        => 'load_lib',
906
-            'EE_Messages_Queue'                            => 'load_lib',
907
-            'EE_Messages_Data_Handler_Collection'          => 'load_lib',
908
-            'EE_Message_Template_Group_Collection'         => 'load_lib',
909
-            'EE_Payment_Method_Manager'                    => 'load_lib',
910
-            'EE_Messages_Generator'                        => function () {
911
-                return EE_Registry::instance()->load_lib(
912
-                    'Messages_Generator',
913
-                    array(),
914
-                    false,
915
-                    false
916
-                );
917
-            },
918
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
919
-                return EE_Registry::instance()->load_lib(
920
-                    'Messages_Template_Defaults',
921
-                    $arguments,
922
-                    false,
923
-                    false
924
-                );
925
-            },
926
-            // load_helper
927
-            'EEH_Parse_Shortcodes'                         => function () {
928
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
929
-                    return new EEH_Parse_Shortcodes();
930
-                }
931
-                return null;
932
-            },
933
-            'EE_Template_Config'                           => function () {
934
-                return EE_Config::instance()->template_settings;
935
-            },
936
-            'EE_Currency_Config'                           => function () {
937
-                return EE_Config::instance()->currency;
938
-            },
939
-            'EE_Registration_Config'                       => function () {
940
-                return EE_Config::instance()->registration;
941
-            },
942
-            'EE_Core_Config'                               => function () {
943
-                return EE_Config::instance()->core;
944
-            },
945
-            'EventEspresso\core\services\loaders\Loader'   => function () {
946
-                return LoaderFactory::getLoader();
947
-            },
948
-            'EE_Network_Config'                            => function () {
949
-                return EE_Network_Config::instance();
950
-            },
951
-            'EE_Config'                                    => function () {
952
-                return EE_Config::instance();
953
-            },
954
-            'EventEspresso\core\domain\Domain'             => function () {
955
-                return DomainFactory::getEventEspressoCoreDomain();
956
-            },
957
-            'EE_Admin_Config'                              => function () {
958
-                return EE_Config::instance()->admin;
959
-            },
960
-            'EE_Organization_Config'                       => function () {
961
-                return EE_Config::instance()->organization;
962
-            },
963
-            'EE_Network_Core_Config'                            => function () {
964
-                return EE_Network_Config::instance()->core;
965
-            },
966
-        );
967
-    }
968
-
969
-
970
-    /**
971
-     * can be used for supplying alternate names for classes,
972
-     * or for connecting interface names to instantiable classes
973
-     */
974
-    protected function _register_core_aliases()
975
-    {
976
-        $aliases = array(
977
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
978
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
979
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
980
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
981
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
982
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
983
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
984
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
985
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
986
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
987
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
988
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
989
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
990
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
991
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
992
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
993
-            'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
994
-            'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
995
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
996
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
997
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
998
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
999
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
1000
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
1001
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
1002
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
1003
-            'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
1004
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
1005
-            'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
1006
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
1007
-            'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
1008
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
1009
-            'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
1010
-            'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
1011
-            'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
1012
-            'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
1013
-            'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
1014
-        );
1015
-        foreach ($aliases as $alias => $fqn) {
1016
-            if (is_array($fqn)) {
1017
-                foreach ($fqn as $class => $for_class) {
1018
-                    $this->class_cache->addAlias($class, $alias, $for_class);
1019
-                }
1020
-                continue;
1021
-            }
1022
-            $this->class_cache->addAlias($fqn, $alias);
1023
-        }
1024
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1025
-            $this->class_cache->addAlias(
1026
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
1027
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
1028
-            );
1029
-        }
1030
-    }
1031
-
1032
-
1033
-    /**
1034
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
1035
-     * request Primarily used by unit tests.
1036
-     */
1037
-    public function reset()
1038
-    {
1039
-        $this->_register_core_class_loaders();
1040
-        $this->_register_core_dependencies();
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * PLZ NOTE: a better name for this method would be is_alias()
1046
-     * because it returns TRUE if the provided fully qualified name IS an alias
1047
-     * WHY?
1048
-     * Because if a class is type hinting for a concretion,
1049
-     * then why would we need to find another class to supply it?
1050
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1051
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1052
-     * Don't go looking for some substitute.
1053
-     * Whereas if a class is type hinting for an interface...
1054
-     * then we need to find an actual class to use.
1055
-     * So the interface IS the alias for some other FQN,
1056
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1057
-     * represents some other class.
1058
-     *
1059
-     * @deprecated 4.9.62.p
1060
-     * @param string $fqn
1061
-     * @param string $for_class
1062
-     * @return bool
1063
-     */
1064
-    public function has_alias($fqn = '', $for_class = '')
1065
-    {
1066
-        return $this->isAlias($fqn, $for_class);
1067
-    }
1068
-
1069
-
1070
-    /**
1071
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1072
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1073
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
1074
-     *  for example:
1075
-     *      if the following two entries were added to the _aliases array:
1076
-     *          array(
1077
-     *              'interface_alias'           => 'some\namespace\interface'
1078
-     *              'some\namespace\interface'  => 'some\namespace\classname'
1079
-     *          )
1080
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1081
-     *      to load an instance of 'some\namespace\classname'
1082
-     *
1083
-     * @deprecated 4.9.62.p
1084
-     * @param string $alias
1085
-     * @param string $for_class
1086
-     * @return string
1087
-     */
1088
-    public function get_alias($alias = '', $for_class = '')
1089
-    {
1090
-        return $this->getFqnForAlias($alias, $for_class);
1091
-    }
23
+	/**
24
+	 * This means that the requested class dependency is not present in the dependency map
25
+	 */
26
+	const not_registered = 0;
27
+
28
+	/**
29
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
+	 */
31
+	const load_new_object = 1;
32
+
33
+	/**
34
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
+	 */
37
+	const load_from_cache = 2;
38
+
39
+	/**
40
+	 * When registering a dependency,
41
+	 * this indicates to keep any existing dependencies that already exist,
42
+	 * and simply discard any new dependencies declared in the incoming data
43
+	 */
44
+	const KEEP_EXISTING_DEPENDENCIES = 0;
45
+
46
+	/**
47
+	 * When registering a dependency,
48
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
+	 */
50
+	const OVERWRITE_DEPENDENCIES = 1;
51
+
52
+
53
+	/**
54
+	 * @type EE_Dependency_Map $_instance
55
+	 */
56
+	protected static $_instance;
57
+
58
+	/**
59
+	 * @var ClassInterfaceCache $class_cache
60
+	 */
61
+	private $class_cache;
62
+
63
+	/**
64
+	 * @type RequestInterface $request
65
+	 */
66
+	protected $request;
67
+
68
+	/**
69
+	 * @type LegacyRequestInterface $legacy_request
70
+	 */
71
+	protected $legacy_request;
72
+
73
+	/**
74
+	 * @type ResponseInterface $response
75
+	 */
76
+	protected $response;
77
+
78
+	/**
79
+	 * @type LoaderInterface $loader
80
+	 */
81
+	protected $loader;
82
+
83
+	/**
84
+	 * @type array $_dependency_map
85
+	 */
86
+	protected $_dependency_map = array();
87
+
88
+	/**
89
+	 * @type array $_class_loaders
90
+	 */
91
+	protected $_class_loaders = array();
92
+
93
+
94
+	/**
95
+	 * EE_Dependency_Map constructor.
96
+	 *
97
+	 * @param ClassInterfaceCache $class_cache
98
+	 */
99
+	protected function __construct(ClassInterfaceCache $class_cache)
100
+	{
101
+		$this->class_cache = $class_cache;
102
+		do_action('EE_Dependency_Map____construct', $this);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function initialize()
110
+	{
111
+		$this->_register_core_dependencies();
112
+		$this->_register_core_class_loaders();
113
+		$this->_register_core_aliases();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param ClassInterfaceCache|null $class_cache
120
+	 * @return EE_Dependency_Map
121
+	 */
122
+	public static function instance(ClassInterfaceCache $class_cache = null)
123
+	{
124
+		// check if class object is instantiated, and instantiated properly
125
+		if (! self::$_instance instanceof EE_Dependency_Map
126
+			&& $class_cache instanceof ClassInterfaceCache
127
+		) {
128
+			self::$_instance = new EE_Dependency_Map($class_cache);
129
+		}
130
+		return self::$_instance;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param RequestInterface $request
136
+	 */
137
+	public function setRequest(RequestInterface $request)
138
+	{
139
+		$this->request = $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param LegacyRequestInterface $legacy_request
145
+	 */
146
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
+	{
148
+		$this->legacy_request = $legacy_request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param ResponseInterface $response
154
+	 */
155
+	public function setResponse(ResponseInterface $response)
156
+	{
157
+		$this->response = $response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param LoaderInterface $loader
163
+	 */
164
+	public function setLoader(LoaderInterface $loader)
165
+	{
166
+		$this->loader = $loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $class
172
+	 * @param array  $dependencies
173
+	 * @param int    $overwrite
174
+	 * @return bool
175
+	 */
176
+	public static function register_dependencies(
177
+		$class,
178
+		array $dependencies,
179
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
+	) {
181
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Assigns an array of class names and corresponding load sources (new or cached)
187
+	 * to the class specified by the first parameter.
188
+	 * IMPORTANT !!!
189
+	 * The order of elements in the incoming $dependencies array MUST match
190
+	 * the order of the constructor parameters for the class in question.
191
+	 * This is especially important when overriding any existing dependencies that are registered.
192
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
+	 *
194
+	 * @param string $class
195
+	 * @param array  $dependencies
196
+	 * @param int    $overwrite
197
+	 * @return bool
198
+	 */
199
+	public function registerDependencies(
200
+		$class,
201
+		array $dependencies,
202
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
+	) {
204
+		$class = trim($class, '\\');
205
+		$registered = false;
206
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
207
+			self::$_instance->_dependency_map[ $class ] = array();
208
+		}
209
+		// we need to make sure that any aliases used when registering a dependency
210
+		// get resolved to the correct class name
211
+		foreach ($dependencies as $dependency => $load_source) {
212
+			$alias = self::$_instance->getFqnForAlias($dependency);
213
+			if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
+			) {
216
+				unset($dependencies[ $dependency ]);
217
+				$dependencies[ $alias ] = $load_source;
218
+				$registered = true;
219
+			}
220
+		}
221
+		// now add our two lists of dependencies together.
222
+		// using Union (+=) favours the arrays in precedence from left to right,
223
+		// so $dependencies is NOT overwritten because it is listed first
224
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
+		// Union is way faster than array_merge() but should be used with caution...
226
+		// especially with numerically indexed arrays
227
+		$dependencies += self::$_instance->_dependency_map[ $class ];
228
+		// now we need to ensure that the resulting dependencies
229
+		// array only has the entries that are required for the class
230
+		// so first count how many dependencies were originally registered for the class
231
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
+		// if that count is non-zero (meaning dependencies were already registered)
233
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
234
+			// then truncate the  final array to match that count
235
+			? array_slice($dependencies, 0, $dependency_count)
236
+			// otherwise just take the incoming array because nothing previously existed
237
+			: $dependencies;
238
+		return $registered;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param string $class_name
244
+	 * @param string $loader
245
+	 * @return bool
246
+	 * @throws DomainException
247
+	 */
248
+	public static function register_class_loader($class_name, $loader = 'load_core')
249
+	{
250
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
+			throw new DomainException(
252
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
+			);
254
+		}
255
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
256
+		if (! is_callable($loader)
257
+			&& (
258
+				strpos($loader, 'load_') !== 0
259
+				|| ! method_exists('EE_Registry', $loader)
260
+			)
261
+		) {
262
+			throw new DomainException(
263
+				sprintf(
264
+					esc_html__(
265
+						'"%1$s" is not a valid loader method on EE_Registry.',
266
+						'event_espresso'
267
+					),
268
+					$loader
269
+				)
270
+			);
271
+		}
272
+		$class_name = self::$_instance->getFqnForAlias($class_name);
273
+		if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
+			self::$_instance->_class_loaders[ $class_name ] = $loader;
275
+			return true;
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function dependency_map()
285
+	{
286
+		return $this->_dependency_map;
287
+	}
288
+
289
+
290
+	/**
291
+	 * returns TRUE if dependency map contains a listing for the provided class name
292
+	 *
293
+	 * @param string $class_name
294
+	 * @return boolean
295
+	 */
296
+	public function has($class_name = '')
297
+	{
298
+		// all legacy models have the same dependencies
299
+		if (strpos($class_name, 'EEM_') === 0) {
300
+			$class_name = 'LEGACY_MODELS';
301
+		}
302
+		return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return bool
312
+	 */
313
+	public function has_dependency_for_class($class_name = '', $dependency = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
320
+		return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
+			? true
322
+			: false;
323
+	}
324
+
325
+
326
+	/**
327
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
+	 *
329
+	 * @param string $class_name
330
+	 * @param string $dependency
331
+	 * @return int
332
+	 */
333
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
+	{
335
+		// all legacy models have the same dependencies
336
+		if (strpos($class_name, 'EEM_') === 0) {
337
+			$class_name = 'LEGACY_MODELS';
338
+		}
339
+		$dependency = $this->getFqnForAlias($dependency);
340
+		return $this->has_dependency_for_class($class_name, $dependency)
341
+			? $this->_dependency_map[ $class_name ][ $dependency ]
342
+			: EE_Dependency_Map::not_registered;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $class_name
348
+	 * @return string | Closure
349
+	 */
350
+	public function class_loader($class_name)
351
+	{
352
+		// all legacy models use load_model()
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			return 'load_model';
355
+		}
356
+		// EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
+		// perform strpos() first to avoid loading regex every time we load a class
358
+		if (strpos($class_name, 'EE_CPT_') === 0
359
+			&& preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
+		) {
361
+			return 'load_core';
362
+		}
363
+		$class_name = $this->getFqnForAlias($class_name);
364
+		return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return array
370
+	 */
371
+	public function class_loaders()
372
+	{
373
+		return $this->_class_loaders;
374
+	}
375
+
376
+
377
+	/**
378
+	 * adds an alias for a classname
379
+	 *
380
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
+	 */
384
+	public function add_alias($fqcn, $alias, $for_class = '')
385
+	{
386
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns TRUE if the provided fully qualified name IS an alias
392
+	 * WHY?
393
+	 * Because if a class is type hinting for a concretion,
394
+	 * then why would we need to find another class to supply it?
395
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
+	 * Don't go looking for some substitute.
398
+	 * Whereas if a class is type hinting for an interface...
399
+	 * then we need to find an actual class to use.
400
+	 * So the interface IS the alias for some other FQN,
401
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
+	 * represents some other class.
403
+	 *
404
+	 * @param string $fqn
405
+	 * @param string $for_class
406
+	 * @return bool
407
+	 */
408
+	public function isAlias($fqn = '', $for_class = '')
409
+	{
410
+		return $this->class_cache->isAlias($fqn, $for_class);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
+	 *  for example:
418
+	 *      if the following two entries were added to the _aliases array:
419
+	 *          array(
420
+	 *              'interface_alias'           => 'some\namespace\interface'
421
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
422
+	 *          )
423
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
+	 *      to load an instance of 'some\namespace\classname'
425
+	 *
426
+	 * @param string $alias
427
+	 * @param string $for_class
428
+	 * @return string
429
+	 */
430
+	public function getFqnForAlias($alias = '', $for_class = '')
431
+	{
432
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
+	 * This is done by using the following class constants:
440
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
442
+	 */
443
+	protected function _register_core_dependencies()
444
+	{
445
+		$this->_dependency_map = array(
446
+			'EE_Request_Handler'                                                                                          => array(
447
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_System'                                                                                                   => array(
450
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
+			),
455
+			'EE_Session'                                                                                                  => array(
456
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
+				'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
+			),
462
+			'EE_Cart'                                                                                                     => array(
463
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_Front_Controller'                                                                                         => array(
466
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
+			),
470
+			'EE_Messenger_Collection_Loader'                                                                              => array(
471
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
+			),
473
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
474
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
+			),
476
+			'EE_Message_Resource_Manager'                                                                                 => array(
477
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
+			),
481
+			'EE_Message_Factory'                                                                                          => array(
482
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_messages'                                                                                                 => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Generator'                                                                                       => array(
488
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
+			),
493
+			'EE_Messages_Processor'                                                                                       => array(
494
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EE_Messages_Queue'                                                                                           => array(
497
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
+			),
499
+			'EE_Messages_Template_Defaults'                                                                               => array(
500
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
504
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
+			),
507
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
+			),
517
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
561
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EE_Data_Migration_Class_Base'                                                                                => array(
564
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
572
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
+			),
579
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
580
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
584
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
+			),
587
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
588
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
+			),
591
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
592
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
596
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
+			),
599
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
600
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
+			),
603
+			'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
+				array(),
605
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
+			),
611
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
+			),
620
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
+			),
623
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
+			),
626
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
+			),
632
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
+			),
635
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
+				'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
+			),
642
+			'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
+				null,
644
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'LEGACY_MODELS'                                                                                               => array(
650
+				null,
651
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
+			),
653
+			'EE_Module_Request_Router'                                                                                    => array(
654
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
655
+			),
656
+			'EE_Registration_Processor'                                                                                   => array(
657
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
658
+			),
659
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
+				null,
661
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
+				'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
+			),
664
+			'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
+			),
668
+			'EE_Admin_Transactions_List_Table'                                                                            => array(
669
+				null,
670
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
+			),
672
+			'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
+			),
677
+			'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
+			),
681
+			'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
+			),
690
+			'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
+			),
693
+			'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
+			),
696
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
+			),
700
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
+			),
703
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
+				'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
+				'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
+				'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
+				'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
+			),
710
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
+			),
713
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
+				'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
+			),
717
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
+			),
720
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
+			),
723
+			'EE_CPT_Strategy'                                                                                             => array(
724
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
+			),
727
+			'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
+			),
730
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
+			),
737
+			'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
+			),
741
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
+			),
744
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
+			),
748
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
+				'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
+			),
751
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
+			),
754
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
+			),
757
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
+			),
760
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
+				'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
+			),
764
+			'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
+				null,
766
+				null,
767
+				null,
768
+				'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
+			),
772
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
+				'EE_Config' => EE_Dependency_Map::load_from_cache
775
+			),
776
+			'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
777
+				'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
778
+				'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
779
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache,
780
+				'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
781
+			),
782
+			'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array(
783
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
784
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
785
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
786
+			),
787
+			'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array(
788
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
789
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
790
+			),
791
+			'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array(
792
+				'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache,
793
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
794
+				'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache,
795
+			),
796
+			'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array(
797
+				'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache,
798
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
799
+				'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache,
800
+			),
801
+			'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array(
802
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache,
803
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
804
+			),
805
+			'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array(
806
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache,
807
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache,
808
+			),
809
+			'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
810
+				'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
811
+			),
812
+			'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
813
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
814
+			),
815
+			'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
816
+				'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
817
+			),
818
+			'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
819
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
820
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
821
+			),
822
+			'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
823
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
824
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
825
+			),
826
+			'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
827
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
828
+			),
829
+			'EventEspresso\core\services\session\SessionStartHandler' => array(
830
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
831
+			),
832
+			'EE_URL_Validation_Strategy' => array(
833
+				null,
834
+				null,
835
+				'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache
836
+			),
837
+			'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array(
838
+				'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
839
+				'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
840
+				'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
841
+				'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
842
+				'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
843
+			),
844
+			'EventEspresso\core\services\address\CountrySubRegionDao' => array(
845
+				'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
846
+				'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
847
+			),
848
+		);
849
+	}
850
+
851
+
852
+	/**
853
+	 * Registers how core classes are loaded.
854
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
855
+	 *        'EE_Request_Handler' => 'load_core'
856
+	 *        'EE_Messages_Queue'  => 'load_lib'
857
+	 *        'EEH_Debug_Tools'    => 'load_helper'
858
+	 * or, if greater control is required, by providing a custom closure. For example:
859
+	 *        'Some_Class' => function () {
860
+	 *            return new Some_Class();
861
+	 *        },
862
+	 * This is required for instantiating dependencies
863
+	 * where an interface has been type hinted in a class constructor. For example:
864
+	 *        'Required_Interface' => function () {
865
+	 *            return new A_Class_That_Implements_Required_Interface();
866
+	 *        },
867
+	 */
868
+	protected function _register_core_class_loaders()
869
+	{
870
+		$this->_class_loaders = array(
871
+			// load_core
872
+			'EE_Dependency_Map'                            => function () {
873
+				return $this;
874
+			},
875
+			'EE_Capabilities'                              => 'load_core',
876
+			'EE_Encryption'                                => 'load_core',
877
+			'EE_Front_Controller'                          => 'load_core',
878
+			'EE_Module_Request_Router'                     => 'load_core',
879
+			'EE_Registry'                                  => 'load_core',
880
+			'EE_Request'                                   => function () {
881
+				return $this->legacy_request;
882
+			},
883
+			'EventEspresso\core\services\request\Request'  => function () {
884
+				return $this->request;
885
+			},
886
+			'EventEspresso\core\services\request\Response' => function () {
887
+				return $this->response;
888
+			},
889
+			'EE_Base'                                      => 'load_core',
890
+			'EE_Request_Handler'                           => 'load_core',
891
+			'EE_Session'                                   => 'load_core',
892
+			'EE_Cron_Tasks'                                => 'load_core',
893
+			'EE_System'                                    => 'load_core',
894
+			'EE_Maintenance_Mode'                          => 'load_core',
895
+			'EE_Register_CPTs'                             => 'load_core',
896
+			'EE_Admin'                                     => 'load_core',
897
+			'EE_CPT_Strategy'                              => 'load_core',
898
+			// load_lib
899
+			'EE_Message_Resource_Manager'                  => 'load_lib',
900
+			'EE_Message_Type_Collection'                   => 'load_lib',
901
+			'EE_Message_Type_Collection_Loader'            => 'load_lib',
902
+			'EE_Messenger_Collection'                      => 'load_lib',
903
+			'EE_Messenger_Collection_Loader'               => 'load_lib',
904
+			'EE_Messages_Processor'                        => 'load_lib',
905
+			'EE_Message_Repository'                        => 'load_lib',
906
+			'EE_Messages_Queue'                            => 'load_lib',
907
+			'EE_Messages_Data_Handler_Collection'          => 'load_lib',
908
+			'EE_Message_Template_Group_Collection'         => 'load_lib',
909
+			'EE_Payment_Method_Manager'                    => 'load_lib',
910
+			'EE_Messages_Generator'                        => function () {
911
+				return EE_Registry::instance()->load_lib(
912
+					'Messages_Generator',
913
+					array(),
914
+					false,
915
+					false
916
+				);
917
+			},
918
+			'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
919
+				return EE_Registry::instance()->load_lib(
920
+					'Messages_Template_Defaults',
921
+					$arguments,
922
+					false,
923
+					false
924
+				);
925
+			},
926
+			// load_helper
927
+			'EEH_Parse_Shortcodes'                         => function () {
928
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
929
+					return new EEH_Parse_Shortcodes();
930
+				}
931
+				return null;
932
+			},
933
+			'EE_Template_Config'                           => function () {
934
+				return EE_Config::instance()->template_settings;
935
+			},
936
+			'EE_Currency_Config'                           => function () {
937
+				return EE_Config::instance()->currency;
938
+			},
939
+			'EE_Registration_Config'                       => function () {
940
+				return EE_Config::instance()->registration;
941
+			},
942
+			'EE_Core_Config'                               => function () {
943
+				return EE_Config::instance()->core;
944
+			},
945
+			'EventEspresso\core\services\loaders\Loader'   => function () {
946
+				return LoaderFactory::getLoader();
947
+			},
948
+			'EE_Network_Config'                            => function () {
949
+				return EE_Network_Config::instance();
950
+			},
951
+			'EE_Config'                                    => function () {
952
+				return EE_Config::instance();
953
+			},
954
+			'EventEspresso\core\domain\Domain'             => function () {
955
+				return DomainFactory::getEventEspressoCoreDomain();
956
+			},
957
+			'EE_Admin_Config'                              => function () {
958
+				return EE_Config::instance()->admin;
959
+			},
960
+			'EE_Organization_Config'                       => function () {
961
+				return EE_Config::instance()->organization;
962
+			},
963
+			'EE_Network_Core_Config'                            => function () {
964
+				return EE_Network_Config::instance()->core;
965
+			},
966
+		);
967
+	}
968
+
969
+
970
+	/**
971
+	 * can be used for supplying alternate names for classes,
972
+	 * or for connecting interface names to instantiable classes
973
+	 */
974
+	protected function _register_core_aliases()
975
+	{
976
+		$aliases = array(
977
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
978
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
979
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
980
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
981
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
982
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
983
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
984
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
985
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
986
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
987
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
988
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
989
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
990
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
991
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
992
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
993
+			'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
994
+			'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
995
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
996
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
997
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
998
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
999
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
1000
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
1001
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
1002
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
1003
+			'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
1004
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
1005
+			'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
1006
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
1007
+			'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
1008
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
1009
+			'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
1010
+			'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
1011
+			'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
1012
+			'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
1013
+			'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
1014
+		);
1015
+		foreach ($aliases as $alias => $fqn) {
1016
+			if (is_array($fqn)) {
1017
+				foreach ($fqn as $class => $for_class) {
1018
+					$this->class_cache->addAlias($class, $alias, $for_class);
1019
+				}
1020
+				continue;
1021
+			}
1022
+			$this->class_cache->addAlias($fqn, $alias);
1023
+		}
1024
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1025
+			$this->class_cache->addAlias(
1026
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
1027
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
1028
+			);
1029
+		}
1030
+	}
1031
+
1032
+
1033
+	/**
1034
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
1035
+	 * request Primarily used by unit tests.
1036
+	 */
1037
+	public function reset()
1038
+	{
1039
+		$this->_register_core_class_loaders();
1040
+		$this->_register_core_dependencies();
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * PLZ NOTE: a better name for this method would be is_alias()
1046
+	 * because it returns TRUE if the provided fully qualified name IS an alias
1047
+	 * WHY?
1048
+	 * Because if a class is type hinting for a concretion,
1049
+	 * then why would we need to find another class to supply it?
1050
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1051
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1052
+	 * Don't go looking for some substitute.
1053
+	 * Whereas if a class is type hinting for an interface...
1054
+	 * then we need to find an actual class to use.
1055
+	 * So the interface IS the alias for some other FQN,
1056
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1057
+	 * represents some other class.
1058
+	 *
1059
+	 * @deprecated 4.9.62.p
1060
+	 * @param string $fqn
1061
+	 * @param string $for_class
1062
+	 * @return bool
1063
+	 */
1064
+	public function has_alias($fqn = '', $for_class = '')
1065
+	{
1066
+		return $this->isAlias($fqn, $for_class);
1067
+	}
1068
+
1069
+
1070
+	/**
1071
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1072
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1073
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
1074
+	 *  for example:
1075
+	 *      if the following two entries were added to the _aliases array:
1076
+	 *          array(
1077
+	 *              'interface_alias'           => 'some\namespace\interface'
1078
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
1079
+	 *          )
1080
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1081
+	 *      to load an instance of 'some\namespace\classname'
1082
+	 *
1083
+	 * @deprecated 4.9.62.p
1084
+	 * @param string $alias
1085
+	 * @param string $for_class
1086
+	 * @return string
1087
+	 */
1088
+	public function get_alias($alias = '', $for_class = '')
1089
+	{
1090
+		return $this->getFqnForAlias($alias, $for_class);
1091
+	}
1092 1092
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Attendee.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 class Attendee extends AttendeeCalculationsBase
18 18
 {
19 19
 
20
-    /**
21
-     * @param array                  $wpdb_row
22
-     * @param WP_REST_Request        $request
23
-     * @param AttendeeControllerBase $controller
24
-     * @since 4.9.66.p
25
-     * @return string
26
-     */
27
-    public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller)
28
-    {
29
-        if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
30
-            $email_address = $wpdb_row['Attendee_Meta.ATT_email'];
31
-        }
32
-        if (empty($email_address)) {
33
-            return get_avatar_url('', array('default' => 'mm', 'force_default' => true));
34
-        }
35
-        $avatar = get_avatar_url($email_address);
36
-        return $avatar ? $avatar : '';
37
-    }
20
+	/**
21
+	 * @param array                  $wpdb_row
22
+	 * @param WP_REST_Request        $request
23
+	 * @param AttendeeControllerBase $controller
24
+	 * @since 4.9.66.p
25
+	 * @return string
26
+	 */
27
+	public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller)
28
+	{
29
+		if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) {
30
+			$email_address = $wpdb_row['Attendee_Meta.ATT_email'];
31
+		}
32
+		if (empty($email_address)) {
33
+			return get_avatar_url('', array('default' => 'mm', 'force_default' => true));
34
+		}
35
+		$avatar = get_avatar_url($email_address);
36
+		return $avatar ? $avatar : '';
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
42
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
43
-     *
44
-     * @since 4.9.68.p
45
-     * @return array
46
-     */
47
-    public function schemaForCalculations()
48
-    {
49
-        return array(
50
-            'user_avatar' => array(
51
-                'description' => esc_html__(
52
-                    'The avatar url for the attendee (if available).',
53
-                    'event_espresso'
54
-                ),
55
-                'type'        => 'string',
56
-            ),
57
-        );
58
-    }
40
+	/**
41
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
42
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
43
+	 *
44
+	 * @since 4.9.68.p
45
+	 * @return array
46
+	 */
47
+	public function schemaForCalculations()
48
+	{
49
+		return array(
50
+			'user_avatar' => array(
51
+				'description' => esc_html__(
52
+					'The avatar url for the attendee (if available).',
53
+					'event_espresso'
54
+				),
55
+				'type'        => 'string',
56
+			),
57
+		);
58
+	}
59 59
 }
Please login to merge, or discard this patch.