Completed
Pull Request — Gutenberg/master (#637)
by
unknown
09:29
created
admin_pages/general_settings/General_Settings_Admin_Page.core.php 2 patches
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
         wp_enqueue_script('thickbox');
290 290
         wp_register_script(
291 291
             'organization_settings',
292
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
+            GEN_SET_ASSETS_URL.'your_organization_settings.js',
293 293
             array('jquery', 'media-upload', 'thickbox'),
294 294
             EVENT_ESPRESSO_VERSION,
295 295
             true
296 296
         );
297
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
297
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
298 298
         wp_enqueue_script('organization_settings');
299 299
         wp_enqueue_style('organization-css');
300 300
         $confirm_image_delete = array(
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
         // scripts
316 316
         wp_register_script(
317 317
             'gen_settings_countries',
318
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
318
+            GEN_SET_ASSETS_URL.'gen_settings_countries.js',
319 319
             array('ee_admin_js'),
320 320
             EVENT_ESPRESSO_VERSION,
321 321
             true
322 322
         );
323
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
323
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
324 324
         wp_enqueue_script('gen_settings_countries');
325 325
         wp_enqueue_style('organization-css');
326 326
     }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
         $this->_set_add_edit_form_tags('update_espresso_page_settings');
371 371
         $this->_set_publish_post_box_vars(null, false, false, null, false);
372 372
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
373
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
+            GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php',
374 374
             $this->_template_args,
375 375
             true
376 376
         );
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
     {
535 535
         try {
536 536
             $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
537
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
537
+            $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]);
538 538
             EE_Registry::instance()->CFG->admin = apply_filters(
539 539
                 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
540 540
                 EE_Registry::instance()->CFG->admin
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
         $this->_set_add_edit_form_tags('update_country_settings');
626 626
         $this->_set_publish_post_box_vars(null, false, false, null, false);
627 627
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
628
+            GEN_SET_TEMPLATE_PATH.'countries_settings.template.php',
629 629
             $this->_template_args,
630 630
             true
631 631
         );
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         $CNT_ISO = isset($this->_req_data['country'])
649 649
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
650 650
             : $CNT_ISO;
651
-        if (! $CNT_ISO) {
651
+        if ( ! $CNT_ISO) {
652 652
             return '';
653 653
         }
654 654
 
@@ -666,59 +666,59 @@  discard block
 block discarded – undo
666 666
         $country_input_types = array(
667 667
             'CNT_active'      => array(
668 668
                 'type'             => 'RADIO_BTN',
669
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
669
+                'input_name'       => 'cntry['.$CNT_ISO.']',
670 670
                 'class'            => '',
671 671
                 'options'          => $this->_yes_no_values,
672 672
                 'use_desc_4_label' => true,
673 673
             ),
674 674
             'CNT_ISO'         => array(
675 675
                 'type'       => 'TEXT',
676
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
676
+                'input_name' => 'cntry['.$CNT_ISO.']',
677 677
                 'class'      => 'small-text',
678 678
             ),
679 679
             'CNT_ISO3'        => array(
680 680
                 'type'       => 'TEXT',
681
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
681
+                'input_name' => 'cntry['.$CNT_ISO.']',
682 682
                 'class'      => 'small-text',
683 683
             ),
684 684
             'RGN_ID'          => array(
685 685
                 'type'       => 'TEXT',
686
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
686
+                'input_name' => 'cntry['.$CNT_ISO.']',
687 687
                 'class'      => 'small-text',
688 688
             ),
689 689
             'CNT_name'        => array(
690 690
                 'type'       => 'TEXT',
691
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
691
+                'input_name' => 'cntry['.$CNT_ISO.']',
692 692
                 'class'      => 'regular-text',
693 693
             ),
694 694
             'CNT_cur_code'    => array(
695 695
                 'type'       => 'TEXT',
696
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
696
+                'input_name' => 'cntry['.$CNT_ISO.']',
697 697
                 'class'      => 'small-text',
698 698
                 'disabled'   => $CNT_cur_disabled
699 699
             ),
700 700
             'CNT_cur_single'  => array(
701 701
                 'type'       => 'TEXT',
702
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
702
+                'input_name' => 'cntry['.$CNT_ISO.']',
703 703
                 'class'      => 'medium-text',
704 704
                 'disabled' => $CNT_cur_disabled
705 705
             ),
706 706
             'CNT_cur_plural'  => array(
707 707
                 'type'       => 'TEXT',
708
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
708
+                'input_name' => 'cntry['.$CNT_ISO.']',
709 709
                 'class'      => 'medium-text',
710 710
                 'disabled' => $CNT_cur_disabled
711 711
             ),
712 712
             'CNT_cur_sign'    => array(
713 713
                 'type'         => 'TEXT',
714
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
714
+                'input_name'   => 'cntry['.$CNT_ISO.']',
715 715
                 'class'        => 'small-text',
716 716
                 'htmlentities' => false,
717 717
                 'disabled' => $CNT_cur_disabled
718 718
             ),
719 719
             'CNT_cur_sign_b4' => array(
720 720
                 'type'             => 'RADIO_BTN',
721
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
721
+                'input_name'       => 'cntry['.$CNT_ISO.']',
722 722
                 'class'            => '',
723 723
                 'options'          => $this->_yes_no_values,
724 724
                 'use_desc_4_label' => true,
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
             ),
727 727
             'CNT_cur_dec_plc' => array(
728 728
                 'type'       => 'RADIO_BTN',
729
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
729
+                'input_name' => 'cntry['.$CNT_ISO.']',
730 730
                 'class'      => '',
731 731
                 'options'    => array(
732 732
                     array('id' => 0, 'text' => ''),
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             ),
739 739
             'CNT_cur_dec_mrk' => array(
740 740
                 'type'             => 'RADIO_BTN',
741
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
741
+                'input_name'       => 'cntry['.$CNT_ISO.']',
742 742
                 'class'            => '',
743 743
                 'options'          => array(
744 744
                     array(
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
             ),
753 753
             'CNT_cur_thsnds'  => array(
754 754
                 'type'             => 'RADIO_BTN',
755
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
755
+                'input_name'       => 'cntry['.$CNT_ISO.']',
756 756
                 'class'            => '',
757 757
                 'options'          => array(
758 758
                     array(
@@ -766,12 +766,12 @@  discard block
 block discarded – undo
766 766
             ),
767 767
             'CNT_tel_code'    => array(
768 768
                 'type'       => 'TEXT',
769
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
769
+                'input_name' => 'cntry['.$CNT_ISO.']',
770 770
                 'class'      => 'small-text',
771 771
             ),
772 772
             'CNT_is_EU'       => array(
773 773
                 'type'             => 'RADIO_BTN',
774
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
+                'input_name'       => 'cntry['.$CNT_ISO.']',
775 775
                 'class'            => '',
776 776
                 'options'          => $this->_yes_no_values,
777 777
                 'use_desc_4_label' => true,
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
             $country_input_types
783 783
         );
784 784
         $country_details_settings = EEH_Template::display_template(
785
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
785
+            GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php',
786 786
             $this->_template_args,
787 787
             true
788 788
         );
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 
817 817
         $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
818 818
 
819
-        if (! $CNT_ISO) {
819
+        if ( ! $CNT_ISO) {
820 820
             return '';
821 821
         }
822 822
         // for ajax
@@ -833,22 +833,22 @@  discard block
 block discarded – undo
833 833
                     $state_input_types = array(
834 834
                         'STA_abbrev' => array(
835 835
                             'type'       => 'TEXT',
836
-                            'input_name' => 'states[' . $STA_ID . ']',
836
+                            'input_name' => 'states['.$STA_ID.']',
837 837
                             'class'      => 'mid-text',
838 838
                         ),
839 839
                         'STA_name'   => array(
840 840
                             'type'       => 'TEXT',
841
-                            'input_name' => 'states[' . $STA_ID . ']',
841
+                            'input_name' => 'states['.$STA_ID.']',
842 842
                             'class'      => 'regular-text',
843 843
                         ),
844 844
                         'STA_active' => array(
845 845
                             'type'             => 'RADIO_BTN',
846
-                            'input_name'       => 'states[' . $STA_ID . ']',
846
+                            'input_name'       => 'states['.$STA_ID.']',
847 847
                             'options'          => $this->_yes_no_values,
848 848
                             'use_desc_4_label' => true,
849 849
                         ),
850 850
                     );
851
-                    $this->_template_args['states'][ $STA_ID ]['inputs'] =
851
+                    $this->_template_args['states'][$STA_ID]['inputs'] =
852 852
                         EE_Question_Form_Input::generate_question_form_inputs_for_object(
853 853
                             $state,
854 854
                             $state_input_types
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
                         'CNT_ISO'    => $CNT_ISO,
860 860
                         'STA_abbrev' => $state->abbrev(),
861 861
                     );
862
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
862
+                    $this->_template_args['states'][$STA_ID]['delete_state_url'] =
863 863
                         EE_Admin_Page::add_query_args_and_nonce(
864 864
                             $query_args,
865 865
                             GEN_SET_ADMIN_URL
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         );
877 877
 
878 878
         $state_details_settings = EEH_Template::display_template(
879
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
879
+            GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php',
880 880
             $this->_template_args,
881 881
             true
882 882
         );
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
         $CNT_ISO = isset($this->_req_data['CNT_ISO'])
913 913
             ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
914 914
             : false;
915
-        if (! $CNT_ISO) {
915
+        if ( ! $CNT_ISO) {
916 916
             EE_Error::add_error(
917 917
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
918 918
                 __FILE__,
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
925 925
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
926 926
             : false;
927
-        if (! $STA_abbrev) {
927
+        if ( ! $STA_abbrev) {
928 928
             EE_Error::add_error(
929 929
                 __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
930 930
                 __FILE__,
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
         $STA_name = isset($this->_req_data['STA_name'])
937 937
             ? sanitize_text_field($this->_req_data['STA_name'])
938 938
             : false;
939
-        if (! $STA_name) {
939
+        if ( ! $STA_name) {
940 940
             EE_Error::add_error(
941 941
                 __('No State name or an invalid State name was received.', 'event_espresso'),
942 942
                 __FILE__,
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
987 987
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
988 988
             : false;
989
-        if (! $STA_ID) {
989
+        if ( ! $STA_ID) {
990 990
             EE_Error::add_error(
991 991
                 __('No State ID or an invalid State ID was received.', 'event_espresso'),
992 992
                 __FILE__,
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
         $CNT_ISO = isset($this->_req_data['country'])
1036 1036
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
1037 1037
             : false;
1038
-        if (! $CNT_ISO) {
1038
+        if ( ! $CNT_ISO) {
1039 1039
             EE_Error::add_error(
1040 1040
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1041 1041
                 __FILE__,
@@ -1046,63 +1046,63 @@  discard block
 block discarded – undo
1046 1046
             return;
1047 1047
         }
1048 1048
         $cols_n_values = array();
1049
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1050
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1049
+        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])
1050
+            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']))
1051 1051
             : false;
1052
-        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1053
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1052
+        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1053
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1054 1054
             : null;
1055
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1056
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1055
+        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1056
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1057 1057
             : null;
1058
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1058
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) {
1059 1059
             $cols_n_values['CNT_cur_code'] = strtoupper(
1060
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1060
+                sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])
1061 1061
             );
1062 1062
         }
1063
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1063
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) {
1064 1064
             $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1065
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1065
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']
1066 1066
             );
1067 1067
         }
1068
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1068
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) {
1069 1069
             $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1070
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1070
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']
1071 1071
             );
1072 1072
         }
1073
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1073
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) {
1074 1074
             $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1075
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1075
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']
1076 1076
             );
1077 1077
         }
1078
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1078
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) {
1079 1079
             $cols_n_values['CNT_cur_sign_b4'] = absint(
1080
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1080
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']
1081 1081
             );
1082 1082
         }
1083
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1083
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) {
1084 1084
             $cols_n_values['CNT_cur_dec_plc'] = absint(
1085
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1085
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']
1086 1086
             );
1087 1087
         }
1088
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1088
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) {
1089 1089
             $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1090
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1090
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']
1091 1091
             );
1092 1092
         }
1093
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1093
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) {
1094 1094
             $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1095
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1095
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']
1096 1096
             );
1097 1097
         }
1098
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1099
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1098
+        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1099
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1100 1100
             : null;
1101
-        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1102
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1101
+        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1102
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1103 1103
             : false;
1104
-        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1105
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1104
+        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1105
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1106 1106
             : false;
1107 1107
         // allow filtering of country data
1108 1108
         $cols_n_values = apply_filters(
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
         return '
1180 1180
 			<tr>
1181 1181
 				<th>
1182
-					' . $label . '
1182
+					' . $label.'
1183 1183
 				</th>';
1184 1184
     }
1185 1185
 
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
     {
1196 1196
         return '
1197 1197
 				<td class="general-settings-country-input-td">
1198
-					' . $input . '
1198
+					' . $input.'
1199 1199
 				</td>
1200 1200
 			</tr>';
1201 1201
     }
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
     {
1227 1227
         return '
1228 1228
 				<td class="general-settings-country-state-input-td">
1229
-					' . $input . '
1229
+					' . $input.'
1230 1230
 				</td>';
1231 1231
     }
1232 1232
 
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
                  . __('Edit', 'event_espresso')
1253 1253
                  . '</a>';
1254 1254
         $links .= ' &nbsp;|&nbsp; ';
1255
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1255
+        $links .= '<a href="'.get_permalink($ee_page_id).'" >'.__('View', 'event_espresso').'</a>';
1256 1256
 
1257 1257
         return $links;
1258 1258
     }
@@ -1285,9 +1285,9 @@  discard block
 block discarded – undo
1285 1285
             $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1286 1286
         }
1287 1287
 
1288
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1288
+        return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>'
1289 1289
                . $pg_status
1290
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1290
+               . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>';
1291 1291
     }
1292 1292
 
1293 1293
 
Please login to merge, or discard this patch.
Indentation   +1332 added lines, -1332 removed lines patch added patch discarded remove patch
@@ -21,1347 +21,1347 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * _question_group
26
-     * holds the specific question group object for the question group details screen
27
-     *
28
-     * @var object
29
-     */
30
-    protected $_question_group;
31
-
32
-
33
-    /**
34
-     * Initialize basic properties.
35
-     */
36
-    protected function _init_page_props()
37
-    {
38
-        $this->page_slug = GEN_SET_PG_SLUG;
39
-        $this->page_label = GEN_SET_LABEL;
40
-        $this->_admin_base_url = GEN_SET_ADMIN_URL;
41
-        $this->_admin_base_path = GEN_SET_ADMIN;
42
-    }
43
-
44
-
45
-    /**
46
-     * Set ajax hooks
47
-     */
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
51
-        add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
52
-        add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
53
-        add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
54
-    }
55
-
56
-
57
-    /**
58
-     * More page properties initialization.
59
-     */
60
-    protected function _define_page_props()
61
-    {
62
-        $this->_admin_page_title = GEN_SET_LABEL;
63
-        $this->_labels = array(
64
-            'publishbox' => __('Update Settings', 'event_espresso'),
65
-        );
66
-    }
67
-
68
-
69
-    /**
70
-     * Set page routes property.
71
-     */
72
-    protected function _set_page_routes()
73
-    {
74
-        $this->_page_routes = array(
75
-
76
-            'critical_pages'                => array(
77
-                'func'       => '_espresso_page_settings',
78
-                'capability' => 'manage_options',
79
-            ),
80
-            'update_espresso_page_settings' => array(
81
-                'func'       => '_update_espresso_page_settings',
82
-                'capability' => 'manage_options',
83
-                'noheader'   => true,
84
-            ),
85
-            'default'                       => array(
86
-                'func'       => '_your_organization_settings',
87
-                'capability' => 'manage_options',
88
-            ),
89
-
90
-            'update_your_organization_settings' => array(
91
-                'func'       => '_update_your_organization_settings',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-
96
-            'admin_option_settings' => array(
97
-                'func'       => '_admin_option_settings',
98
-                'capability' => 'manage_options',
99
-            ),
100
-
101
-            'update_admin_option_settings' => array(
102
-                'func'       => '_update_admin_option_settings',
103
-                'capability' => 'manage_options',
104
-                'noheader'   => true,
105
-            ),
106
-
107
-            'country_settings' => array(
108
-                'func'       => '_country_settings',
109
-                'capability' => 'manage_options',
110
-            ),
111
-
112
-            'update_country_settings' => array(
113
-                'func'       => '_update_country_settings',
114
-                'capability' => 'manage_options',
115
-                'noheader'   => true,
116
-            ),
117
-
118
-            'display_country_settings' => array(
119
-                'func'       => 'display_country_settings',
120
-                'capability' => 'manage_options',
121
-                'noheader'   => true,
122
-            ),
123
-
124
-            'add_new_state' => array(
125
-                'func'       => 'add_new_state',
126
-                'capability' => 'manage_options',
127
-                'noheader'   => true,
128
-            ),
129
-
130
-            'delete_state' => array(
131
-                'func'       => 'delete_state',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'privacy_settings' => array(
136
-                'func' => 'privacySettings',
137
-                'capability' => 'manage_options',
138
-            ),
139
-            'update_privacy_settings' => array(
140
-                'func' => 'updatePrivacySettings',
141
-                'capability' => 'manage_options',
142
-                'noheader' => true,
143
-                'headers_sent_route' => 'privacy_settings'
144
-            )
145
-        );
146
-    }
147
-
148
-
149
-    /**
150
-     * Set page configuration property
151
-     */
152
-    protected function _set_page_config()
153
-    {
154
-        $this->_page_config = array(
155
-            'critical_pages'        => array(
156
-                'nav'           => array(
157
-                    'label' => __('Critical Pages', 'event_espresso'),
158
-                    'order' => 50,
159
-                ),
160
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
161
-                'help_tabs'     => array(
162
-                    'general_settings_critical_pages_help_tab' => array(
163
-                        'title'    => __('Critical Pages', 'event_espresso'),
164
-                        'filename' => 'general_settings_critical_pages',
165
-                    ),
166
-                ),
167
-                'help_tour'     => array('Critical_Pages_Help_Tour'),
168
-                'require_nonce' => false,
169
-            ),
170
-            'default'               => array(
171
-                'nav'           => array(
172
-                    'label' => __('Your Organization', 'event_espresso'),
173
-                    'order' => 20,
174
-                ),
175
-                'help_tabs'     => array(
176
-                    'general_settings_your_organization_help_tab' => array(
177
-                        'title'    => __('Your Organization', 'event_espresso'),
178
-                        'filename' => 'general_settings_your_organization',
179
-                    ),
180
-                ),
181
-                'help_tour'     => array('Your_Organization_Help_Tour'),
182
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
183
-                'require_nonce' => false,
184
-            ),
185
-            'admin_option_settings' => array(
186
-                'nav'           => array(
187
-                    'label' => __('Admin Options', 'event_espresso'),
188
-                    'order' => 60,
189
-                ),
190
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
191
-                'help_tabs'     => array(
192
-                    'general_settings_admin_options_help_tab' => array(
193
-                        'title'    => __('Admin Options', 'event_espresso'),
194
-                        'filename' => 'general_settings_admin_options',
195
-                    ),
196
-                ),
197
-                'help_tour'     => array('Admin_Options_Help_Tour'),
198
-                'require_nonce' => false,
199
-            ),
200
-            'country_settings'      => array(
201
-                'nav'           => array(
202
-                    'label' => __('Countries', 'event_espresso'),
203
-                    'order' => 70,
204
-                ),
205
-                'help_tabs'     => array(
206
-                    'general_settings_countries_help_tab' => array(
207
-                        'title'    => __('Countries', 'event_espresso'),
208
-                        'filename' => 'general_settings_countries',
209
-                    ),
210
-                ),
211
-                'help_tour'     => array('Countries_Help_Tour'),
212
-                'require_nonce' => false,
213
-            ),
214
-            'privacy_settings' => array(
215
-                'nav' => array(
216
-                    'label' => esc_html__('Privacy', 'event_espresso'),
217
-                    'order' => 80
218
-                ),
219
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
220
-                'require_nonce' => false
221
-            )
222
-        );
223
-    }
224
-
225
-
226
-    protected function _add_screen_options()
227
-    {
228
-    }
229
-
230
-    protected function _add_feature_pointers()
231
-    {
232
-    }
233
-
234
-
235
-    /**
236
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
237
-     */
238
-    public function load_scripts_styles()
239
-    {
240
-        // styles
241
-        wp_enqueue_style('espresso-ui-theme');
242
-        // scripts
243
-        wp_enqueue_script('ee_admin_js');
244
-    }
245
-
246
-
247
-    /**
248
-     * Execute logic running on `admin_init`
249
-     */
250
-    public function admin_init()
251
-    {
252
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
253
-            '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.',
254
-            'event_espresso'
255
-        );
256
-        EE_Registry::$i18n_js_strings['error_occurred'] = __(
257
-            'An error occurred! Please refresh the page and try again.',
258
-            'event_espresso'
259
-        );
260
-        EE_Registry::$i18n_js_strings['confirm_delete_state'] = __(
261
-            'Are you sure you want to delete this State / Province?',
262
-            'event_espresso'
263
-        );
264
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
265
-        EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
266
-            'admin-ajax.php?page=espresso_general_settings',
267
-            $protocol
268
-        );
269
-    }
270
-
271
-    public function admin_notices()
272
-    {
273
-    }
274
-
275
-    public function admin_footer_scripts()
276
-    {
277
-    }
278
-
279
-
280
-    /**
281
-     * Enqueue scripts and styles for the default route.
282
-     */
283
-    public function load_scripts_styles_default()
284
-    {
285
-        // styles
286
-        wp_enqueue_style('thickbox');
287
-        // scripts
288
-        wp_enqueue_script('media-upload');
289
-        wp_enqueue_script('thickbox');
290
-        wp_register_script(
291
-            'organization_settings',
292
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
293
-            array('jquery', 'media-upload', 'thickbox'),
294
-            EVENT_ESPRESSO_VERSION,
295
-            true
296
-        );
297
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
298
-        wp_enqueue_script('organization_settings');
299
-        wp_enqueue_style('organization-css');
300
-        $confirm_image_delete = array(
301
-            'text' => __(
302
-                'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
-                'event_espresso'
304
-            ),
305
-        );
306
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
307
-    }
308
-
309
-
310
-    /**
311
-     * Enqueue scripts and styles for the country settings route.
312
-     */
313
-    public function load_scripts_styles_country_settings()
314
-    {
315
-        // scripts
316
-        wp_register_script(
317
-            'gen_settings_countries',
318
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
319
-            array('ee_admin_js'),
320
-            EVENT_ESPRESSO_VERSION,
321
-            true
322
-        );
323
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
324
-        wp_enqueue_script('gen_settings_countries');
325
-        wp_enqueue_style('organization-css');
326
-    }
327
-
328
-
329
-    /*************        Espresso Pages        *************/
330
-    /**
331
-     * _espresso_page_settings
332
-     *
333
-     * @throws \EE_Error
334
-     * @throws DomainException
335
-     * @throws DomainException
336
-     * @throws InvalidDataTypeException
337
-     * @throws InvalidArgumentException
338
-     */
339
-    protected function _espresso_page_settings()
340
-    {
341
-        // Check to make sure all of the main pages are setup properly,
342
-        // if not create the default pages and display an admin notice
343
-        EEH_Activation::verify_default_pages_exist();
344
-        $this->_transient_garbage_collection();
345
-        $this->_template_args['values'] = $this->_yes_no_values;
346
-        $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
347
-            ? EE_Registry::instance()->CFG->core->reg_page_id
348
-            : null;
349
-        $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
350
-            ? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
351
-            : false;
352
-        $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
353
-            ? EE_Registry::instance()->CFG->core->txn_page_id
354
-            : null;
355
-        $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
356
-            ? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
357
-            : false;
358
-        $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
359
-            ? EE_Registry::instance()->CFG->core->thank_you_page_id
360
-            : null;
361
-        $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
362
-            ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
363
-            : false;
364
-        $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
365
-            ? EE_Registry::instance()->CFG->core->cancel_page_id
366
-            : null;
367
-        $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
368
-            ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
369
-            : false;
370
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
371
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
372
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
373
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
374
-            $this->_template_args,
375
-            true
376
-        );
377
-        $this->display_admin_page_with_sidebar();
378
-    }
379
-
380
-
381
-    /**
382
-     * Handler for updating espresso page settings.
383
-     *
384
-     * @throws EE_Error
385
-     */
386
-    protected function _update_espresso_page_settings()
387
-    {
388
-        // capture incoming request data && set page IDs
389
-        EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
390
-            ? absint($this->_req_data['reg_page_id'])
391
-            : EE_Registry::instance()->CFG->core->reg_page_id;
392
-        EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
393
-            ? absint($this->_req_data['txn_page_id'])
394
-            : EE_Registry::instance()->CFG->core->txn_page_id;
395
-        EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
396
-            ? absint($this->_req_data['thank_you_page_id'])
397
-            : EE_Registry::instance()->CFG->core->thank_you_page_id;
398
-        EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
399
-            ? absint($this->_req_data['cancel_page_id'])
400
-            : EE_Registry::instance()->CFG->core->cancel_page_id;
401
-
402
-        EE_Registry::instance()->CFG->core = apply_filters(
403
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
404
-            EE_Registry::instance()->CFG->core,
405
-            $this->_req_data
406
-        );
407
-        $what = __('Critical Pages & Shortcodes', 'event_espresso');
408
-        $this->_redirect_after_action(
409
-            $this->_update_espresso_configuration(
410
-                $what,
411
-                EE_Registry::instance()->CFG->core,
412
-                __FILE__,
413
-                __FUNCTION__,
414
-                __LINE__
415
-            ),
416
-            $what,
417
-            '',
418
-            array(
419
-                'action' => 'critical_pages',
420
-            ),
421
-            true
422
-        );
423
-    }
424
-
425
-
426
-    /*************        Your Organization        *************/
427
-
428
-
429
-    /**
430
-     * @throws DomainException
431
-     * @throws EE_Error
432
-     * @throws InvalidArgumentException
433
-     * @throws InvalidDataTypeException
434
-     * @throws InvalidInterfaceException
435
-     */
436
-    protected function _your_organization_settings()
437
-    {
438
-        $this->_template_args['admin_page_content'] = '';
439
-        try {
440
-            $organization_settings_form = new OrganizationSettings(
441
-                EE_Registry::instance(),
442
-                EE_Registry::instance()->CFG->organization,
443
-                EE_Registry::instance()->CFG->core,
444
-                EE_Registry::instance()->NET_CFG->core
445
-            );
446
-            $this->_template_args['admin_page_content'] = $organization_settings_form->display();
447
-        } catch (Exception $e) {
448
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
449
-        }
450
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
451
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
452
-        $this->display_admin_page_with_sidebar();
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     * Handler for updating organization settings.
459
-     *
460
-     * @throws EE_Error
461
-     */
462
-    protected function _update_your_organization_settings()
463
-    {
464
-        try {
465
-            $organization_settings_form = new OrganizationSettings(
466
-                EE_Registry::instance(),
467
-                EE_Registry::instance()->CFG->organization,
468
-                EE_Registry::instance()->CFG->core,
469
-                EE_Registry::instance()->NET_CFG->core
470
-            );
471
-            $success = $organization_settings_form->process($this->_req_data);
472
-            EE_Registry::instance()->CFG = apply_filters(
473
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
474
-                EE_Registry::instance()->CFG
475
-            );
476
-        } catch (Exception $e) {
477
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
478
-            $success = false;
479
-        }
480
-
481
-        if ($success) {
482
-            $success = $this->_update_espresso_configuration(
483
-                esc_html__('Your Organization Settings', 'event_espresso'),
484
-                EE_Registry::instance()->CFG,
485
-                __FILE__,
486
-                __FUNCTION__,
487
-                __LINE__
488
-            );
489
-        }
490
-
491
-        $this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
492
-    }
493
-
494
-
495
-
496
-    /*************        Admin Options        *************/
497
-
498
-
499
-    /**
500
-     * _admin_option_settings
501
-     *
502
-     * @throws \EE_Error
503
-     * @throws \LogicException
504
-     */
505
-    protected function _admin_option_settings()
506
-    {
507
-        $this->_template_args['admin_page_content'] = '';
508
-        try {
509
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
510
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
511
-            $this->_template_args['values'] = $this->_yes_no_values;
512
-            // also need to account for the do_action that was in the old template
513
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
514
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
515
-        } catch (Exception $e) {
516
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
517
-        }
518
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
519
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
520
-        $this->display_admin_page_with_sidebar();
521
-    }
522
-
523
-
524
-    /**
525
-     * _update_admin_option_settings
526
-     *
527
-     * @throws \EE_Error
528
-     * @throws InvalidDataTypeException
529
-     * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
530
-     * @throws \InvalidArgumentException
531
-     * @throws \LogicException
532
-     */
533
-    protected function _update_admin_option_settings()
534
-    {
535
-        try {
536
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
537
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
538
-            EE_Registry::instance()->CFG->admin = apply_filters(
539
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
540
-                EE_Registry::instance()->CFG->admin
541
-            );
542
-        } catch (Exception $e) {
543
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
544
-        }
545
-        $this->_redirect_after_action(
546
-            apply_filters(
547
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
548
-                $this->_update_espresso_configuration(
549
-                    'Admin Options',
550
-                    EE_Registry::instance()->CFG->admin,
551
-                    __FILE__,
552
-                    __FUNCTION__,
553
-                    __LINE__
554
-                )
555
-            ),
556
-            'Admin Options',
557
-            'updated',
558
-            array('action' => 'admin_option_settings')
559
-        );
560
-    }
561
-
562
-
563
-    /*************        Countries        *************/
564
-
565
-
566
-    /**
567
-     * @return string
568
-     */
569
-    protected function getCountryIsoForSite()
570
-    {
571
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
572
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
573
-            : 'US';
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * Output Country Settings view.
580
-     *
581
-     * @throws DomainException
582
-     * @throws EE_Error
583
-     */
584
-    protected function _country_settings()
585
-    {
586
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
587
-        $CNT_ISO = isset($this->_req_data['country'])
588
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
589
-            : $CNT_ISO_for_site;
590
-
591
-        // load field generator helper
592
-
593
-        $this->_template_args['values'] = $this->_yes_no_values;
594
-
595
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
596
-            EE_Question::new_instance(
597
-                array(
598
-                    'QST_ID'           => 0,
599
-                    'QST_display_text' => __('Select Country', 'event_espresso'),
600
-                    'QST_system'       => 'admin-country',
601
-                )
602
-            ),
603
-            EE_Answer::new_instance(
604
-                array(
605
-                    'ANS_ID'    => 0,
606
-                    'ANS_value' => $CNT_ISO,
607
-                )
608
-            ),
609
-            array(
610
-                'input_id'       => 'country',
611
-                'input_name'     => 'country',
612
-                'input_prefix'   => '',
613
-                'append_qstn_id' => false,
614
-            )
615
-        );
616
-
617
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
618
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
619
-        $this->_template_args['country_details_settings'] = $this->display_country_settings();
620
-        $this->_template_args['country_states_settings'] = $this->display_country_states();
621
-        $this->_template_args['CNT_name_for_site'] = EEM_Country::instance()->get_one_by_ID($CNT_ISO_for_site)
622
-                                                                            ->name();
623
-
624
-        $this->_set_add_edit_form_tags('update_country_settings');
625
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
626
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
628
-            $this->_template_args,
629
-            true
630
-        );
631
-        $this->display_admin_page_with_no_sidebar();
632
-    }
633
-
634
-
635
-    /**
636
-     *        display_country_settings
637
-     *
638
-     * @access    public
639
-     * @param    string $CNT_ISO
640
-     * @return mixed string | array
641
-     * @throws DomainException
642
-     */
643
-    public function display_country_settings($CNT_ISO = '')
644
-    {
645
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
646
-
647
-        $CNT_ISO = isset($this->_req_data['country'])
648
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
649
-            : $CNT_ISO;
650
-        if (! $CNT_ISO) {
651
-            return '';
652
-        }
653
-
654
-        // for ajax
655
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
656
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
657
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
658
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
659
-        /** @var EE_Country $country */
660
-        $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
661
-
662
-        $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
663
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
664
-
665
-        $country_input_types = array(
666
-            'CNT_active'      => array(
667
-                'type'             => 'RADIO_BTN',
668
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
669
-                'class'            => '',
670
-                'options'          => $this->_yes_no_values,
671
-                'use_desc_4_label' => true,
672
-            ),
673
-            'CNT_ISO'         => array(
674
-                'type'       => 'TEXT',
675
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
676
-                'class'      => 'small-text',
677
-            ),
678
-            'CNT_ISO3'        => array(
679
-                'type'       => 'TEXT',
680
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
681
-                'class'      => 'small-text',
682
-            ),
683
-            'RGN_ID'          => array(
684
-                'type'       => 'TEXT',
685
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
686
-                'class'      => 'small-text',
687
-            ),
688
-            'CNT_name'        => array(
689
-                'type'       => 'TEXT',
690
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
691
-                'class'      => 'regular-text',
692
-            ),
693
-            'CNT_cur_code'    => array(
694
-                'type'       => 'TEXT',
695
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
696
-                'class'      => 'small-text',
697
-                'disabled'   => $CNT_cur_disabled
698
-            ),
699
-            'CNT_cur_single'  => array(
700
-                'type'       => 'TEXT',
701
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
702
-                'class'      => 'medium-text',
703
-                'disabled' => $CNT_cur_disabled
704
-            ),
705
-            'CNT_cur_plural'  => array(
706
-                'type'       => 'TEXT',
707
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
708
-                'class'      => 'medium-text',
709
-                'disabled' => $CNT_cur_disabled
710
-            ),
711
-            'CNT_cur_sign'    => array(
712
-                'type'         => 'TEXT',
713
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
714
-                'class'        => 'small-text',
715
-                'htmlentities' => false,
716
-                'disabled' => $CNT_cur_disabled
717
-            ),
718
-            'CNT_cur_sign_b4' => array(
719
-                'type'             => 'RADIO_BTN',
720
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
721
-                'class'            => '',
722
-                'options'          => $this->_yes_no_values,
723
-                'use_desc_4_label' => true,
724
-                'disabled' => $CNT_cur_disabled
725
-            ),
726
-            'CNT_cur_dec_plc' => array(
727
-                'type'       => 'RADIO_BTN',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
729
-                'class'      => '',
730
-                'options'    => array(
731
-                    array('id' => 0, 'text' => ''),
732
-                    array('id' => 1, 'text' => ''),
733
-                    array('id' => 2, 'text' => ''),
734
-                    array('id' => 3, 'text' => ''),
735
-                ),
736
-                'disabled' => $CNT_cur_disabled
737
-            ),
738
-            'CNT_cur_dec_mrk' => array(
739
-                'type'             => 'RADIO_BTN',
740
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
741
-                'class'            => '',
742
-                'options'          => array(
743
-                    array(
744
-                        'id'   => ',',
745
-                        'text' => __(', (comma)', 'event_espresso'),
746
-                    ),
747
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
748
-                ),
749
-                'use_desc_4_label' => true,
750
-                'disabled' => $CNT_cur_disabled
751
-            ),
752
-            'CNT_cur_thsnds'  => array(
753
-                'type'             => 'RADIO_BTN',
754
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
755
-                'class'            => '',
756
-                'options'          => array(
757
-                    array(
758
-                        'id'   => ',',
759
-                        'text' => __(', (comma)', 'event_espresso'),
760
-                    ),
761
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
762
-                ),
763
-                'use_desc_4_label' => true,
764
-                'disabled' => $CNT_cur_disabled
765
-            ),
766
-            'CNT_tel_code'    => array(
767
-                'type'       => 'TEXT',
768
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
769
-                'class'      => 'small-text',
770
-            ),
771
-            'CNT_is_EU'       => array(
772
-                'type'             => 'RADIO_BTN',
773
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
-                'class'            => '',
775
-                'options'          => $this->_yes_no_values,
776
-                'use_desc_4_label' => true,
777
-            ),
778
-        );
779
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
780
-            $country,
781
-            $country_input_types
782
-        );
783
-        $country_details_settings = EEH_Template::display_template(
784
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
785
-            $this->_template_args,
786
-            true
787
-        );
788
-
789
-        if (defined('DOING_AJAX')) {
790
-            $notices = EE_Error::get_notices(false, false, false);
791
-            echo wp_json_encode(
792
-                array(
793
-                    'return_data' => $country_details_settings,
794
-                    'success'     => $notices['success'],
795
-                    'errors'      => $notices['errors'],
796
-                )
797
-            );
798
-            die();
799
-        } else {
800
-            return $country_details_settings;
801
-        }
802
-    }
803
-
804
-
805
-    /**
806
-     *        display_country_states
807
-     *
808
-     * @access    public
809
-     * @param    string $CNT_ISO
810
-     * @return string
811
-     * @throws DomainException
812
-     */
813
-    public function display_country_states($CNT_ISO = '')
814
-    {
815
-
816
-        $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
817
-
818
-        if (! $CNT_ISO) {
819
-            return '';
820
-        }
821
-        // for ajax
822
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
823
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
824
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
825
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
826
-        $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
827
-
828
-        if ($states) {
829
-            foreach ($states as $STA_ID => $state) {
830
-                if ($state instanceof EE_State) {
831
-                    // STA_abbrev    STA_name    STA_active
832
-                    $state_input_types = array(
833
-                        'STA_abbrev' => array(
834
-                            'type'       => 'TEXT',
835
-                            'input_name' => 'states[' . $STA_ID . ']',
836
-                            'class'      => 'mid-text',
837
-                        ),
838
-                        'STA_name'   => array(
839
-                            'type'       => 'TEXT',
840
-                            'input_name' => 'states[' . $STA_ID . ']',
841
-                            'class'      => 'regular-text',
842
-                        ),
843
-                        'STA_active' => array(
844
-                            'type'             => 'RADIO_BTN',
845
-                            'input_name'       => 'states[' . $STA_ID . ']',
846
-                            'options'          => $this->_yes_no_values,
847
-                            'use_desc_4_label' => true,
848
-                        ),
849
-                    );
850
-                    $this->_template_args['states'][ $STA_ID ]['inputs'] =
851
-                        EE_Question_Form_Input::generate_question_form_inputs_for_object(
852
-                            $state,
853
-                            $state_input_types
854
-                        );
855
-                    $query_args = array(
856
-                        'action'     => 'delete_state',
857
-                        'STA_ID'     => $STA_ID,
858
-                        'CNT_ISO'    => $CNT_ISO,
859
-                        'STA_abbrev' => $state->abbrev(),
860
-                    );
861
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
862
-                        EE_Admin_Page::add_query_args_and_nonce(
863
-                            $query_args,
864
-                            GEN_SET_ADMIN_URL
865
-                        );
866
-                }
867
-            }
868
-        } else {
869
-            $this->_template_args['states'] = false;
870
-        }
871
-
872
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
873
-            array('action' => 'add_new_state'),
874
-            GEN_SET_ADMIN_URL
875
-        );
876
-
877
-        $state_details_settings = EEH_Template::display_template(
878
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
879
-            $this->_template_args,
880
-            true
881
-        );
882
-
883
-        if (defined('DOING_AJAX')) {
884
-            $notices = EE_Error::get_notices(false, false, false);
885
-            echo wp_json_encode(
886
-                array(
887
-                    'return_data' => $state_details_settings,
888
-                    'success'     => $notices['success'],
889
-                    'errors'      => $notices['errors'],
890
-                )
891
-            );
892
-            die();
893
-        } else {
894
-            return $state_details_settings;
895
-        }
896
-    }
897
-
898
-
899
-    /**
900
-     *        add_new_state
901
-     *
902
-     * @access    public
903
-     * @return void
904
-     * @throws EE_Error
905
-     */
906
-    public function add_new_state()
907
-    {
908
-
909
-        $success = true;
910
-
911
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
912
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
913
-            : false;
914
-        if (! $CNT_ISO) {
915
-            EE_Error::add_error(
916
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
917
-                __FILE__,
918
-                __FUNCTION__,
919
-                __LINE__
920
-            );
921
-            $success = false;
922
-        }
923
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
924
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
925
-            : false;
926
-        if (! $STA_abbrev) {
927
-            EE_Error::add_error(
928
-                __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
929
-                __FILE__,
930
-                __FUNCTION__,
931
-                __LINE__
932
-            );
933
-            $success = false;
934
-        }
935
-        $STA_name = isset($this->_req_data['STA_name'])
936
-            ? sanitize_text_field($this->_req_data['STA_name'])
937
-            : false;
938
-        if (! $STA_name) {
939
-            EE_Error::add_error(
940
-                __('No State name or an invalid State name was received.', 'event_espresso'),
941
-                __FILE__,
942
-                __FUNCTION__,
943
-                __LINE__
944
-            );
945
-            $success = false;
946
-        }
947
-
948
-        if ($success) {
949
-            $cols_n_values = array(
950
-                'CNT_ISO'    => $CNT_ISO,
951
-                'STA_abbrev' => $STA_abbrev,
952
-                'STA_name'   => $STA_name,
953
-                'STA_active' => true,
954
-            );
955
-            $success = EEM_State::instance()->insert($cols_n_values);
956
-            EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
957
-        }
958
-
959
-        if (defined('DOING_AJAX')) {
960
-            $notices = EE_Error::get_notices(false, false, false);
961
-            echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
962
-            die();
963
-        } else {
964
-            $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
965
-        }
966
-    }
967
-
968
-
969
-    /**
970
-     *        delete_state
971
-     *
972
-     * @access    public
973
-     * @return        boolean
974
-     * @throws EE_Error
975
-     * @throws EE_Error
976
-     */
977
-    public function delete_state()
978
-    {
979
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
980
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
981
-            : false;
982
-        $STA_ID = isset($this->_req_data['STA_ID'])
983
-            ? sanitize_text_field($this->_req_data['STA_ID'])
984
-            : false;
985
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
986
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
987
-            : false;
988
-        if (! $STA_ID) {
989
-            EE_Error::add_error(
990
-                __('No State ID or an invalid State ID was received.', 'event_espresso'),
991
-                __FILE__,
992
-                __FUNCTION__,
993
-                __LINE__
994
-            );
995
-            return false;
996
-        }
997
-
998
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
999
-        if ($success !== false) {
1000
-            do_action(
1001
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1002
-                $CNT_ISO,
1003
-                $STA_ID,
1004
-                array('STA_abbrev' => $STA_abbrev)
1005
-            );
1006
-            EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1007
-        }
1008
-        if (defined('DOING_AJAX')) {
1009
-            $notices = EE_Error::get_notices(false, false);
1010
-            $notices['return_data'] = true;
1011
-            echo wp_json_encode($notices);
1012
-            die();
1013
-        } else {
1014
-            $this->_redirect_after_action(
1015
-                $success,
1016
-                'State',
1017
-                'deleted',
1018
-                array('action' => 'country_settings')
1019
-            );
1020
-        }
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     *        _update_country_settings
1026
-     *
1027
-     * @access    protected
1028
-     * @return void
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _update_country_settings()
1032
-    {
1033
-        // grab the country ISO code
1034
-        $CNT_ISO = isset($this->_req_data['country'])
1035
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
1036
-            : false;
1037
-        if (! $CNT_ISO) {
1038
-            EE_Error::add_error(
1039
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1040
-                __FILE__,
1041
-                __FUNCTION__,
1042
-                __LINE__
1043
-            );
1044
-
1045
-            return;
1046
-        }
1047
-        $cols_n_values = array();
1048
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1049
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1050
-            : false;
1051
-        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1052
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1053
-            : null;
1054
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1055
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1056
-            : null;
1057
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1058
-            $cols_n_values['CNT_cur_code'] = strtoupper(
1059
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1060
-            );
1061
-        }
1062
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1063
-            $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1064
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1065
-            );
1066
-        }
1067
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1068
-            $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1069
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1070
-            );
1071
-        }
1072
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1073
-            $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1074
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1075
-            );
1076
-        }
1077
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1078
-            $cols_n_values['CNT_cur_sign_b4'] = absint(
1079
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1080
-            );
1081
-        }
1082
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1083
-            $cols_n_values['CNT_cur_dec_plc'] = absint(
1084
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1085
-            );
1086
-        }
1087
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1088
-            $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1089
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1090
-            );
1091
-        }
1092
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1093
-            $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1094
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1095
-            );
1096
-        }
1097
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1098
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1099
-            : null;
1100
-        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1101
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1102
-            : false;
1103
-        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1104
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1105
-            : false;
1106
-        // allow filtering of country data
1107
-        $cols_n_values = apply_filters(
1108
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1109
-            $cols_n_values
1110
-        );
1111
-
1112
-        // where values
1113
-        $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1114
-        // run the update
1115
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1116
-
1117
-        if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1118
-            // allow filtering of states data
1119
-            $states = apply_filters(
1120
-                'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1121
-                $this->_req_data['states']
1122
-            );
1123
-
1124
-            // loop thru state data ( looks like : states[75][STA_name] )
1125
-            foreach ($states as $STA_ID => $state) {
1126
-                $cols_n_values = array(
1127
-                    'CNT_ISO'    => $CNT_ISO,
1128
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1129
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1130
-                    'STA_active' => (bool) absint($state['STA_active']),
1131
-                );
1132
-                // where values
1133
-                $where_cols_n_values = array(array('STA_ID' => $STA_ID));
1134
-                // run the update
1135
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1136
-                if ($success !== false) {
1137
-                    do_action(
1138
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1139
-                        $CNT_ISO,
1140
-                        $STA_ID,
1141
-                        $cols_n_values
1142
-                    );
1143
-                }
1144
-            }
1145
-        }
1146
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1147
-        if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1148
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1149
-        ) {
1150
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1151
-            EE_Registry::instance()->CFG->update_espresso_config();
1152
-        }
1153
-
1154
-        if ($success !== false) {
1155
-            EE_Error::add_success(
1156
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1157
-            );
1158
-        }
1159
-        $this->_redirect_after_action(
1160
-            $success,
1161
-            '',
1162
-            '',
1163
-            array('action' => 'country_settings', 'country' => $CNT_ISO),
1164
-            true
1165
-        );
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     *        form_form_field_label_wrap
1171
-     *
1172
-     * @access        public
1173
-     * @param        string $label
1174
-     * @return        string
1175
-     */
1176
-    public function country_form_field_label_wrap($label, $required_text)
1177
-    {
1178
-        return '
24
+	/**
25
+	 * _question_group
26
+	 * holds the specific question group object for the question group details screen
27
+	 *
28
+	 * @var object
29
+	 */
30
+	protected $_question_group;
31
+
32
+
33
+	/**
34
+	 * Initialize basic properties.
35
+	 */
36
+	protected function _init_page_props()
37
+	{
38
+		$this->page_slug = GEN_SET_PG_SLUG;
39
+		$this->page_label = GEN_SET_LABEL;
40
+		$this->_admin_base_url = GEN_SET_ADMIN_URL;
41
+		$this->_admin_base_path = GEN_SET_ADMIN;
42
+	}
43
+
44
+
45
+	/**
46
+	 * Set ajax hooks
47
+	 */
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
51
+		add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
52
+		add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
53
+		add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
54
+	}
55
+
56
+
57
+	/**
58
+	 * More page properties initialization.
59
+	 */
60
+	protected function _define_page_props()
61
+	{
62
+		$this->_admin_page_title = GEN_SET_LABEL;
63
+		$this->_labels = array(
64
+			'publishbox' => __('Update Settings', 'event_espresso'),
65
+		);
66
+	}
67
+
68
+
69
+	/**
70
+	 * Set page routes property.
71
+	 */
72
+	protected function _set_page_routes()
73
+	{
74
+		$this->_page_routes = array(
75
+
76
+			'critical_pages'                => array(
77
+				'func'       => '_espresso_page_settings',
78
+				'capability' => 'manage_options',
79
+			),
80
+			'update_espresso_page_settings' => array(
81
+				'func'       => '_update_espresso_page_settings',
82
+				'capability' => 'manage_options',
83
+				'noheader'   => true,
84
+			),
85
+			'default'                       => array(
86
+				'func'       => '_your_organization_settings',
87
+				'capability' => 'manage_options',
88
+			),
89
+
90
+			'update_your_organization_settings' => array(
91
+				'func'       => '_update_your_organization_settings',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+
96
+			'admin_option_settings' => array(
97
+				'func'       => '_admin_option_settings',
98
+				'capability' => 'manage_options',
99
+			),
100
+
101
+			'update_admin_option_settings' => array(
102
+				'func'       => '_update_admin_option_settings',
103
+				'capability' => 'manage_options',
104
+				'noheader'   => true,
105
+			),
106
+
107
+			'country_settings' => array(
108
+				'func'       => '_country_settings',
109
+				'capability' => 'manage_options',
110
+			),
111
+
112
+			'update_country_settings' => array(
113
+				'func'       => '_update_country_settings',
114
+				'capability' => 'manage_options',
115
+				'noheader'   => true,
116
+			),
117
+
118
+			'display_country_settings' => array(
119
+				'func'       => 'display_country_settings',
120
+				'capability' => 'manage_options',
121
+				'noheader'   => true,
122
+			),
123
+
124
+			'add_new_state' => array(
125
+				'func'       => 'add_new_state',
126
+				'capability' => 'manage_options',
127
+				'noheader'   => true,
128
+			),
129
+
130
+			'delete_state' => array(
131
+				'func'       => 'delete_state',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'privacy_settings' => array(
136
+				'func' => 'privacySettings',
137
+				'capability' => 'manage_options',
138
+			),
139
+			'update_privacy_settings' => array(
140
+				'func' => 'updatePrivacySettings',
141
+				'capability' => 'manage_options',
142
+				'noheader' => true,
143
+				'headers_sent_route' => 'privacy_settings'
144
+			)
145
+		);
146
+	}
147
+
148
+
149
+	/**
150
+	 * Set page configuration property
151
+	 */
152
+	protected function _set_page_config()
153
+	{
154
+		$this->_page_config = array(
155
+			'critical_pages'        => array(
156
+				'nav'           => array(
157
+					'label' => __('Critical Pages', 'event_espresso'),
158
+					'order' => 50,
159
+				),
160
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
161
+				'help_tabs'     => array(
162
+					'general_settings_critical_pages_help_tab' => array(
163
+						'title'    => __('Critical Pages', 'event_espresso'),
164
+						'filename' => 'general_settings_critical_pages',
165
+					),
166
+				),
167
+				'help_tour'     => array('Critical_Pages_Help_Tour'),
168
+				'require_nonce' => false,
169
+			),
170
+			'default'               => array(
171
+				'nav'           => array(
172
+					'label' => __('Your Organization', 'event_espresso'),
173
+					'order' => 20,
174
+				),
175
+				'help_tabs'     => array(
176
+					'general_settings_your_organization_help_tab' => array(
177
+						'title'    => __('Your Organization', 'event_espresso'),
178
+						'filename' => 'general_settings_your_organization',
179
+					),
180
+				),
181
+				'help_tour'     => array('Your_Organization_Help_Tour'),
182
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
183
+				'require_nonce' => false,
184
+			),
185
+			'admin_option_settings' => array(
186
+				'nav'           => array(
187
+					'label' => __('Admin Options', 'event_espresso'),
188
+					'order' => 60,
189
+				),
190
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
191
+				'help_tabs'     => array(
192
+					'general_settings_admin_options_help_tab' => array(
193
+						'title'    => __('Admin Options', 'event_espresso'),
194
+						'filename' => 'general_settings_admin_options',
195
+					),
196
+				),
197
+				'help_tour'     => array('Admin_Options_Help_Tour'),
198
+				'require_nonce' => false,
199
+			),
200
+			'country_settings'      => array(
201
+				'nav'           => array(
202
+					'label' => __('Countries', 'event_espresso'),
203
+					'order' => 70,
204
+				),
205
+				'help_tabs'     => array(
206
+					'general_settings_countries_help_tab' => array(
207
+						'title'    => __('Countries', 'event_espresso'),
208
+						'filename' => 'general_settings_countries',
209
+					),
210
+				),
211
+				'help_tour'     => array('Countries_Help_Tour'),
212
+				'require_nonce' => false,
213
+			),
214
+			'privacy_settings' => array(
215
+				'nav' => array(
216
+					'label' => esc_html__('Privacy', 'event_espresso'),
217
+					'order' => 80
218
+				),
219
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
220
+				'require_nonce' => false
221
+			)
222
+		);
223
+	}
224
+
225
+
226
+	protected function _add_screen_options()
227
+	{
228
+	}
229
+
230
+	protected function _add_feature_pointers()
231
+	{
232
+	}
233
+
234
+
235
+	/**
236
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
237
+	 */
238
+	public function load_scripts_styles()
239
+	{
240
+		// styles
241
+		wp_enqueue_style('espresso-ui-theme');
242
+		// scripts
243
+		wp_enqueue_script('ee_admin_js');
244
+	}
245
+
246
+
247
+	/**
248
+	 * Execute logic running on `admin_init`
249
+	 */
250
+	public function admin_init()
251
+	{
252
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
253
+			'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.',
254
+			'event_espresso'
255
+		);
256
+		EE_Registry::$i18n_js_strings['error_occurred'] = __(
257
+			'An error occurred! Please refresh the page and try again.',
258
+			'event_espresso'
259
+		);
260
+		EE_Registry::$i18n_js_strings['confirm_delete_state'] = __(
261
+			'Are you sure you want to delete this State / Province?',
262
+			'event_espresso'
263
+		);
264
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
265
+		EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
266
+			'admin-ajax.php?page=espresso_general_settings',
267
+			$protocol
268
+		);
269
+	}
270
+
271
+	public function admin_notices()
272
+	{
273
+	}
274
+
275
+	public function admin_footer_scripts()
276
+	{
277
+	}
278
+
279
+
280
+	/**
281
+	 * Enqueue scripts and styles for the default route.
282
+	 */
283
+	public function load_scripts_styles_default()
284
+	{
285
+		// styles
286
+		wp_enqueue_style('thickbox');
287
+		// scripts
288
+		wp_enqueue_script('media-upload');
289
+		wp_enqueue_script('thickbox');
290
+		wp_register_script(
291
+			'organization_settings',
292
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
293
+			array('jquery', 'media-upload', 'thickbox'),
294
+			EVENT_ESPRESSO_VERSION,
295
+			true
296
+		);
297
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
298
+		wp_enqueue_script('organization_settings');
299
+		wp_enqueue_style('organization-css');
300
+		$confirm_image_delete = array(
301
+			'text' => __(
302
+				'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
+				'event_espresso'
304
+			),
305
+		);
306
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
307
+	}
308
+
309
+
310
+	/**
311
+	 * Enqueue scripts and styles for the country settings route.
312
+	 */
313
+	public function load_scripts_styles_country_settings()
314
+	{
315
+		// scripts
316
+		wp_register_script(
317
+			'gen_settings_countries',
318
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
319
+			array('ee_admin_js'),
320
+			EVENT_ESPRESSO_VERSION,
321
+			true
322
+		);
323
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
324
+		wp_enqueue_script('gen_settings_countries');
325
+		wp_enqueue_style('organization-css');
326
+	}
327
+
328
+
329
+	/*************        Espresso Pages        *************/
330
+	/**
331
+	 * _espresso_page_settings
332
+	 *
333
+	 * @throws \EE_Error
334
+	 * @throws DomainException
335
+	 * @throws DomainException
336
+	 * @throws InvalidDataTypeException
337
+	 * @throws InvalidArgumentException
338
+	 */
339
+	protected function _espresso_page_settings()
340
+	{
341
+		// Check to make sure all of the main pages are setup properly,
342
+		// if not create the default pages and display an admin notice
343
+		EEH_Activation::verify_default_pages_exist();
344
+		$this->_transient_garbage_collection();
345
+		$this->_template_args['values'] = $this->_yes_no_values;
346
+		$this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
347
+			? EE_Registry::instance()->CFG->core->reg_page_id
348
+			: null;
349
+		$this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
350
+			? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
351
+			: false;
352
+		$this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
353
+			? EE_Registry::instance()->CFG->core->txn_page_id
354
+			: null;
355
+		$this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
356
+			? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
357
+			: false;
358
+		$this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
359
+			? EE_Registry::instance()->CFG->core->thank_you_page_id
360
+			: null;
361
+		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
362
+			? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
363
+			: false;
364
+		$this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
365
+			? EE_Registry::instance()->CFG->core->cancel_page_id
366
+			: null;
367
+		$this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
368
+			? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
369
+			: false;
370
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
371
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
372
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
373
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
374
+			$this->_template_args,
375
+			true
376
+		);
377
+		$this->display_admin_page_with_sidebar();
378
+	}
379
+
380
+
381
+	/**
382
+	 * Handler for updating espresso page settings.
383
+	 *
384
+	 * @throws EE_Error
385
+	 */
386
+	protected function _update_espresso_page_settings()
387
+	{
388
+		// capture incoming request data && set page IDs
389
+		EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
390
+			? absint($this->_req_data['reg_page_id'])
391
+			: EE_Registry::instance()->CFG->core->reg_page_id;
392
+		EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
393
+			? absint($this->_req_data['txn_page_id'])
394
+			: EE_Registry::instance()->CFG->core->txn_page_id;
395
+		EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
396
+			? absint($this->_req_data['thank_you_page_id'])
397
+			: EE_Registry::instance()->CFG->core->thank_you_page_id;
398
+		EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
399
+			? absint($this->_req_data['cancel_page_id'])
400
+			: EE_Registry::instance()->CFG->core->cancel_page_id;
401
+
402
+		EE_Registry::instance()->CFG->core = apply_filters(
403
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
404
+			EE_Registry::instance()->CFG->core,
405
+			$this->_req_data
406
+		);
407
+		$what = __('Critical Pages & Shortcodes', 'event_espresso');
408
+		$this->_redirect_after_action(
409
+			$this->_update_espresso_configuration(
410
+				$what,
411
+				EE_Registry::instance()->CFG->core,
412
+				__FILE__,
413
+				__FUNCTION__,
414
+				__LINE__
415
+			),
416
+			$what,
417
+			'',
418
+			array(
419
+				'action' => 'critical_pages',
420
+			),
421
+			true
422
+		);
423
+	}
424
+
425
+
426
+	/*************        Your Organization        *************/
427
+
428
+
429
+	/**
430
+	 * @throws DomainException
431
+	 * @throws EE_Error
432
+	 * @throws InvalidArgumentException
433
+	 * @throws InvalidDataTypeException
434
+	 * @throws InvalidInterfaceException
435
+	 */
436
+	protected function _your_organization_settings()
437
+	{
438
+		$this->_template_args['admin_page_content'] = '';
439
+		try {
440
+			$organization_settings_form = new OrganizationSettings(
441
+				EE_Registry::instance(),
442
+				EE_Registry::instance()->CFG->organization,
443
+				EE_Registry::instance()->CFG->core,
444
+				EE_Registry::instance()->NET_CFG->core
445
+			);
446
+			$this->_template_args['admin_page_content'] = $organization_settings_form->display();
447
+		} catch (Exception $e) {
448
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
449
+		}
450
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
451
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
452
+		$this->display_admin_page_with_sidebar();
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 * Handler for updating organization settings.
459
+	 *
460
+	 * @throws EE_Error
461
+	 */
462
+	protected function _update_your_organization_settings()
463
+	{
464
+		try {
465
+			$organization_settings_form = new OrganizationSettings(
466
+				EE_Registry::instance(),
467
+				EE_Registry::instance()->CFG->organization,
468
+				EE_Registry::instance()->CFG->core,
469
+				EE_Registry::instance()->NET_CFG->core
470
+			);
471
+			$success = $organization_settings_form->process($this->_req_data);
472
+			EE_Registry::instance()->CFG = apply_filters(
473
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
474
+				EE_Registry::instance()->CFG
475
+			);
476
+		} catch (Exception $e) {
477
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
478
+			$success = false;
479
+		}
480
+
481
+		if ($success) {
482
+			$success = $this->_update_espresso_configuration(
483
+				esc_html__('Your Organization Settings', 'event_espresso'),
484
+				EE_Registry::instance()->CFG,
485
+				__FILE__,
486
+				__FUNCTION__,
487
+				__LINE__
488
+			);
489
+		}
490
+
491
+		$this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
492
+	}
493
+
494
+
495
+
496
+	/*************        Admin Options        *************/
497
+
498
+
499
+	/**
500
+	 * _admin_option_settings
501
+	 *
502
+	 * @throws \EE_Error
503
+	 * @throws \LogicException
504
+	 */
505
+	protected function _admin_option_settings()
506
+	{
507
+		$this->_template_args['admin_page_content'] = '';
508
+		try {
509
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
510
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
511
+			$this->_template_args['values'] = $this->_yes_no_values;
512
+			// also need to account for the do_action that was in the old template
513
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
514
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
515
+		} catch (Exception $e) {
516
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
517
+		}
518
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
519
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
520
+		$this->display_admin_page_with_sidebar();
521
+	}
522
+
523
+
524
+	/**
525
+	 * _update_admin_option_settings
526
+	 *
527
+	 * @throws \EE_Error
528
+	 * @throws InvalidDataTypeException
529
+	 * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
530
+	 * @throws \InvalidArgumentException
531
+	 * @throws \LogicException
532
+	 */
533
+	protected function _update_admin_option_settings()
534
+	{
535
+		try {
536
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
537
+			$admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
538
+			EE_Registry::instance()->CFG->admin = apply_filters(
539
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
540
+				EE_Registry::instance()->CFG->admin
541
+			);
542
+		} catch (Exception $e) {
543
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
544
+		}
545
+		$this->_redirect_after_action(
546
+			apply_filters(
547
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
548
+				$this->_update_espresso_configuration(
549
+					'Admin Options',
550
+					EE_Registry::instance()->CFG->admin,
551
+					__FILE__,
552
+					__FUNCTION__,
553
+					__LINE__
554
+				)
555
+			),
556
+			'Admin Options',
557
+			'updated',
558
+			array('action' => 'admin_option_settings')
559
+		);
560
+	}
561
+
562
+
563
+	/*************        Countries        *************/
564
+
565
+
566
+	/**
567
+	 * @return string
568
+	 */
569
+	protected function getCountryIsoForSite()
570
+	{
571
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
572
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
573
+			: 'US';
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * Output Country Settings view.
580
+	 *
581
+	 * @throws DomainException
582
+	 * @throws EE_Error
583
+	 */
584
+	protected function _country_settings()
585
+	{
586
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
587
+		$CNT_ISO = isset($this->_req_data['country'])
588
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
589
+			: $CNT_ISO_for_site;
590
+
591
+		// load field generator helper
592
+
593
+		$this->_template_args['values'] = $this->_yes_no_values;
594
+
595
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
596
+			EE_Question::new_instance(
597
+				array(
598
+					'QST_ID'           => 0,
599
+					'QST_display_text' => __('Select Country', 'event_espresso'),
600
+					'QST_system'       => 'admin-country',
601
+				)
602
+			),
603
+			EE_Answer::new_instance(
604
+				array(
605
+					'ANS_ID'    => 0,
606
+					'ANS_value' => $CNT_ISO,
607
+				)
608
+			),
609
+			array(
610
+				'input_id'       => 'country',
611
+				'input_name'     => 'country',
612
+				'input_prefix'   => '',
613
+				'append_qstn_id' => false,
614
+			)
615
+		);
616
+
617
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
618
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
619
+		$this->_template_args['country_details_settings'] = $this->display_country_settings();
620
+		$this->_template_args['country_states_settings'] = $this->display_country_states();
621
+		$this->_template_args['CNT_name_for_site'] = EEM_Country::instance()->get_one_by_ID($CNT_ISO_for_site)
622
+																			->name();
623
+
624
+		$this->_set_add_edit_form_tags('update_country_settings');
625
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
626
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
627
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
628
+			$this->_template_args,
629
+			true
630
+		);
631
+		$this->display_admin_page_with_no_sidebar();
632
+	}
633
+
634
+
635
+	/**
636
+	 *        display_country_settings
637
+	 *
638
+	 * @access    public
639
+	 * @param    string $CNT_ISO
640
+	 * @return mixed string | array
641
+	 * @throws DomainException
642
+	 */
643
+	public function display_country_settings($CNT_ISO = '')
644
+	{
645
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
646
+
647
+		$CNT_ISO = isset($this->_req_data['country'])
648
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
649
+			: $CNT_ISO;
650
+		if (! $CNT_ISO) {
651
+			return '';
652
+		}
653
+
654
+		// for ajax
655
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
656
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
657
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
658
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
659
+		/** @var EE_Country $country */
660
+		$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
661
+
662
+		$CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
663
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
664
+
665
+		$country_input_types = array(
666
+			'CNT_active'      => array(
667
+				'type'             => 'RADIO_BTN',
668
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
669
+				'class'            => '',
670
+				'options'          => $this->_yes_no_values,
671
+				'use_desc_4_label' => true,
672
+			),
673
+			'CNT_ISO'         => array(
674
+				'type'       => 'TEXT',
675
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
676
+				'class'      => 'small-text',
677
+			),
678
+			'CNT_ISO3'        => array(
679
+				'type'       => 'TEXT',
680
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
681
+				'class'      => 'small-text',
682
+			),
683
+			'RGN_ID'          => array(
684
+				'type'       => 'TEXT',
685
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
686
+				'class'      => 'small-text',
687
+			),
688
+			'CNT_name'        => array(
689
+				'type'       => 'TEXT',
690
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
691
+				'class'      => 'regular-text',
692
+			),
693
+			'CNT_cur_code'    => array(
694
+				'type'       => 'TEXT',
695
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
696
+				'class'      => 'small-text',
697
+				'disabled'   => $CNT_cur_disabled
698
+			),
699
+			'CNT_cur_single'  => array(
700
+				'type'       => 'TEXT',
701
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
702
+				'class'      => 'medium-text',
703
+				'disabled' => $CNT_cur_disabled
704
+			),
705
+			'CNT_cur_plural'  => array(
706
+				'type'       => 'TEXT',
707
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
708
+				'class'      => 'medium-text',
709
+				'disabled' => $CNT_cur_disabled
710
+			),
711
+			'CNT_cur_sign'    => array(
712
+				'type'         => 'TEXT',
713
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
714
+				'class'        => 'small-text',
715
+				'htmlentities' => false,
716
+				'disabled' => $CNT_cur_disabled
717
+			),
718
+			'CNT_cur_sign_b4' => array(
719
+				'type'             => 'RADIO_BTN',
720
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
721
+				'class'            => '',
722
+				'options'          => $this->_yes_no_values,
723
+				'use_desc_4_label' => true,
724
+				'disabled' => $CNT_cur_disabled
725
+			),
726
+			'CNT_cur_dec_plc' => array(
727
+				'type'       => 'RADIO_BTN',
728
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
729
+				'class'      => '',
730
+				'options'    => array(
731
+					array('id' => 0, 'text' => ''),
732
+					array('id' => 1, 'text' => ''),
733
+					array('id' => 2, 'text' => ''),
734
+					array('id' => 3, 'text' => ''),
735
+				),
736
+				'disabled' => $CNT_cur_disabled
737
+			),
738
+			'CNT_cur_dec_mrk' => array(
739
+				'type'             => 'RADIO_BTN',
740
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
741
+				'class'            => '',
742
+				'options'          => array(
743
+					array(
744
+						'id'   => ',',
745
+						'text' => __(', (comma)', 'event_espresso'),
746
+					),
747
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
748
+				),
749
+				'use_desc_4_label' => true,
750
+				'disabled' => $CNT_cur_disabled
751
+			),
752
+			'CNT_cur_thsnds'  => array(
753
+				'type'             => 'RADIO_BTN',
754
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
755
+				'class'            => '',
756
+				'options'          => array(
757
+					array(
758
+						'id'   => ',',
759
+						'text' => __(', (comma)', 'event_espresso'),
760
+					),
761
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
762
+				),
763
+				'use_desc_4_label' => true,
764
+				'disabled' => $CNT_cur_disabled
765
+			),
766
+			'CNT_tel_code'    => array(
767
+				'type'       => 'TEXT',
768
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
769
+				'class'      => 'small-text',
770
+			),
771
+			'CNT_is_EU'       => array(
772
+				'type'             => 'RADIO_BTN',
773
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
774
+				'class'            => '',
775
+				'options'          => $this->_yes_no_values,
776
+				'use_desc_4_label' => true,
777
+			),
778
+		);
779
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
780
+			$country,
781
+			$country_input_types
782
+		);
783
+		$country_details_settings = EEH_Template::display_template(
784
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
785
+			$this->_template_args,
786
+			true
787
+		);
788
+
789
+		if (defined('DOING_AJAX')) {
790
+			$notices = EE_Error::get_notices(false, false, false);
791
+			echo wp_json_encode(
792
+				array(
793
+					'return_data' => $country_details_settings,
794
+					'success'     => $notices['success'],
795
+					'errors'      => $notices['errors'],
796
+				)
797
+			);
798
+			die();
799
+		} else {
800
+			return $country_details_settings;
801
+		}
802
+	}
803
+
804
+
805
+	/**
806
+	 *        display_country_states
807
+	 *
808
+	 * @access    public
809
+	 * @param    string $CNT_ISO
810
+	 * @return string
811
+	 * @throws DomainException
812
+	 */
813
+	public function display_country_states($CNT_ISO = '')
814
+	{
815
+
816
+		$CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO;
817
+
818
+		if (! $CNT_ISO) {
819
+			return '';
820
+		}
821
+		// for ajax
822
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
823
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
824
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
825
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
826
+		$states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
827
+
828
+		if ($states) {
829
+			foreach ($states as $STA_ID => $state) {
830
+				if ($state instanceof EE_State) {
831
+					// STA_abbrev    STA_name    STA_active
832
+					$state_input_types = array(
833
+						'STA_abbrev' => array(
834
+							'type'       => 'TEXT',
835
+							'input_name' => 'states[' . $STA_ID . ']',
836
+							'class'      => 'mid-text',
837
+						),
838
+						'STA_name'   => array(
839
+							'type'       => 'TEXT',
840
+							'input_name' => 'states[' . $STA_ID . ']',
841
+							'class'      => 'regular-text',
842
+						),
843
+						'STA_active' => array(
844
+							'type'             => 'RADIO_BTN',
845
+							'input_name'       => 'states[' . $STA_ID . ']',
846
+							'options'          => $this->_yes_no_values,
847
+							'use_desc_4_label' => true,
848
+						),
849
+					);
850
+					$this->_template_args['states'][ $STA_ID ]['inputs'] =
851
+						EE_Question_Form_Input::generate_question_form_inputs_for_object(
852
+							$state,
853
+							$state_input_types
854
+						);
855
+					$query_args = array(
856
+						'action'     => 'delete_state',
857
+						'STA_ID'     => $STA_ID,
858
+						'CNT_ISO'    => $CNT_ISO,
859
+						'STA_abbrev' => $state->abbrev(),
860
+					);
861
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
862
+						EE_Admin_Page::add_query_args_and_nonce(
863
+							$query_args,
864
+							GEN_SET_ADMIN_URL
865
+						);
866
+				}
867
+			}
868
+		} else {
869
+			$this->_template_args['states'] = false;
870
+		}
871
+
872
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
873
+			array('action' => 'add_new_state'),
874
+			GEN_SET_ADMIN_URL
875
+		);
876
+
877
+		$state_details_settings = EEH_Template::display_template(
878
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
879
+			$this->_template_args,
880
+			true
881
+		);
882
+
883
+		if (defined('DOING_AJAX')) {
884
+			$notices = EE_Error::get_notices(false, false, false);
885
+			echo wp_json_encode(
886
+				array(
887
+					'return_data' => $state_details_settings,
888
+					'success'     => $notices['success'],
889
+					'errors'      => $notices['errors'],
890
+				)
891
+			);
892
+			die();
893
+		} else {
894
+			return $state_details_settings;
895
+		}
896
+	}
897
+
898
+
899
+	/**
900
+	 *        add_new_state
901
+	 *
902
+	 * @access    public
903
+	 * @return void
904
+	 * @throws EE_Error
905
+	 */
906
+	public function add_new_state()
907
+	{
908
+
909
+		$success = true;
910
+
911
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
912
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
913
+			: false;
914
+		if (! $CNT_ISO) {
915
+			EE_Error::add_error(
916
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
917
+				__FILE__,
918
+				__FUNCTION__,
919
+				__LINE__
920
+			);
921
+			$success = false;
922
+		}
923
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
924
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
925
+			: false;
926
+		if (! $STA_abbrev) {
927
+			EE_Error::add_error(
928
+				__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
929
+				__FILE__,
930
+				__FUNCTION__,
931
+				__LINE__
932
+			);
933
+			$success = false;
934
+		}
935
+		$STA_name = isset($this->_req_data['STA_name'])
936
+			? sanitize_text_field($this->_req_data['STA_name'])
937
+			: false;
938
+		if (! $STA_name) {
939
+			EE_Error::add_error(
940
+				__('No State name or an invalid State name was received.', 'event_espresso'),
941
+				__FILE__,
942
+				__FUNCTION__,
943
+				__LINE__
944
+			);
945
+			$success = false;
946
+		}
947
+
948
+		if ($success) {
949
+			$cols_n_values = array(
950
+				'CNT_ISO'    => $CNT_ISO,
951
+				'STA_abbrev' => $STA_abbrev,
952
+				'STA_name'   => $STA_name,
953
+				'STA_active' => true,
954
+			);
955
+			$success = EEM_State::instance()->insert($cols_n_values);
956
+			EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
957
+		}
958
+
959
+		if (defined('DOING_AJAX')) {
960
+			$notices = EE_Error::get_notices(false, false, false);
961
+			echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
962
+			die();
963
+		} else {
964
+			$this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
965
+		}
966
+	}
967
+
968
+
969
+	/**
970
+	 *        delete_state
971
+	 *
972
+	 * @access    public
973
+	 * @return        boolean
974
+	 * @throws EE_Error
975
+	 * @throws EE_Error
976
+	 */
977
+	public function delete_state()
978
+	{
979
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
980
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
981
+			: false;
982
+		$STA_ID = isset($this->_req_data['STA_ID'])
983
+			? sanitize_text_field($this->_req_data['STA_ID'])
984
+			: false;
985
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
986
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
987
+			: false;
988
+		if (! $STA_ID) {
989
+			EE_Error::add_error(
990
+				__('No State ID or an invalid State ID was received.', 'event_espresso'),
991
+				__FILE__,
992
+				__FUNCTION__,
993
+				__LINE__
994
+			);
995
+			return false;
996
+		}
997
+
998
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
999
+		if ($success !== false) {
1000
+			do_action(
1001
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1002
+				$CNT_ISO,
1003
+				$STA_ID,
1004
+				array('STA_abbrev' => $STA_abbrev)
1005
+			);
1006
+			EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1007
+		}
1008
+		if (defined('DOING_AJAX')) {
1009
+			$notices = EE_Error::get_notices(false, false);
1010
+			$notices['return_data'] = true;
1011
+			echo wp_json_encode($notices);
1012
+			die();
1013
+		} else {
1014
+			$this->_redirect_after_action(
1015
+				$success,
1016
+				'State',
1017
+				'deleted',
1018
+				array('action' => 'country_settings')
1019
+			);
1020
+		}
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 *        _update_country_settings
1026
+	 *
1027
+	 * @access    protected
1028
+	 * @return void
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _update_country_settings()
1032
+	{
1033
+		// grab the country ISO code
1034
+		$CNT_ISO = isset($this->_req_data['country'])
1035
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
1036
+			: false;
1037
+		if (! $CNT_ISO) {
1038
+			EE_Error::add_error(
1039
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1040
+				__FILE__,
1041
+				__FUNCTION__,
1042
+				__LINE__
1043
+			);
1044
+
1045
+			return;
1046
+		}
1047
+		$cols_n_values = array();
1048
+		$cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1049
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1050
+			: false;
1051
+		$cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1052
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1053
+			: null;
1054
+		$cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1055
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1056
+			: null;
1057
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1058
+			$cols_n_values['CNT_cur_code'] = strtoupper(
1059
+				sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1060
+			);
1061
+		}
1062
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1063
+			$cols_n_values['CNT_cur_single'] = sanitize_text_field(
1064
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1065
+			);
1066
+		}
1067
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1068
+			$cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1069
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1070
+			);
1071
+		}
1072
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1073
+			$cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1074
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1075
+			);
1076
+		}
1077
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1078
+			$cols_n_values['CNT_cur_sign_b4'] = absint(
1079
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1080
+			);
1081
+		}
1082
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1083
+			$cols_n_values['CNT_cur_dec_plc'] = absint(
1084
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1085
+			);
1086
+		}
1087
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1088
+			$cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1089
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1090
+			);
1091
+		}
1092
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1093
+			$cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1094
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1095
+			);
1096
+		}
1097
+		$cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1098
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1099
+			: null;
1100
+		$cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1101
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1102
+			: false;
1103
+		$cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1104
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1105
+			: false;
1106
+		// allow filtering of country data
1107
+		$cols_n_values = apply_filters(
1108
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1109
+			$cols_n_values
1110
+		);
1111
+
1112
+		// where values
1113
+		$where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1114
+		// run the update
1115
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1116
+
1117
+		if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1118
+			// allow filtering of states data
1119
+			$states = apply_filters(
1120
+				'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1121
+				$this->_req_data['states']
1122
+			);
1123
+
1124
+			// loop thru state data ( looks like : states[75][STA_name] )
1125
+			foreach ($states as $STA_ID => $state) {
1126
+				$cols_n_values = array(
1127
+					'CNT_ISO'    => $CNT_ISO,
1128
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1129
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1130
+					'STA_active' => (bool) absint($state['STA_active']),
1131
+				);
1132
+				// where values
1133
+				$where_cols_n_values = array(array('STA_ID' => $STA_ID));
1134
+				// run the update
1135
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1136
+				if ($success !== false) {
1137
+					do_action(
1138
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1139
+						$CNT_ISO,
1140
+						$STA_ID,
1141
+						$cols_n_values
1142
+					);
1143
+				}
1144
+			}
1145
+		}
1146
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1147
+		if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1148
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1149
+		) {
1150
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1151
+			EE_Registry::instance()->CFG->update_espresso_config();
1152
+		}
1153
+
1154
+		if ($success !== false) {
1155
+			EE_Error::add_success(
1156
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1157
+			);
1158
+		}
1159
+		$this->_redirect_after_action(
1160
+			$success,
1161
+			'',
1162
+			'',
1163
+			array('action' => 'country_settings', 'country' => $CNT_ISO),
1164
+			true
1165
+		);
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 *        form_form_field_label_wrap
1171
+	 *
1172
+	 * @access        public
1173
+	 * @param        string $label
1174
+	 * @return        string
1175
+	 */
1176
+	public function country_form_field_label_wrap($label, $required_text)
1177
+	{
1178
+		return '
1179 1179
 			<tr>
1180 1180
 				<th>
1181 1181
 					' . $label . '
1182 1182
 				</th>';
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     *        form_form_field_input__wrap
1188
-     *
1189
-     * @access        public
1190
-     * @param        string $label
1191
-     * @return        string
1192
-     */
1193
-    public function country_form_field_input__wrap($input, $label)
1194
-    {
1195
-        return '
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 *        form_form_field_input__wrap
1188
+	 *
1189
+	 * @access        public
1190
+	 * @param        string $label
1191
+	 * @return        string
1192
+	 */
1193
+	public function country_form_field_input__wrap($input, $label)
1194
+	{
1195
+		return '
1196 1196
 				<td class="general-settings-country-input-td">
1197 1197
 					' . $input . '
1198 1198
 				</td>
1199 1199
 			</tr>';
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     *        form_form_field_label_wrap
1205
-     *
1206
-     * @access        public
1207
-     * @param        string $label
1208
-     * @param        string $required_text
1209
-     * @return        string
1210
-     */
1211
-    public function state_form_field_label_wrap($label, $required_text)
1212
-    {
1213
-        return $required_text;
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     *        form_form_field_input__wrap
1219
-     *
1220
-     * @access        public
1221
-     * @param        string $label
1222
-     * @return        string
1223
-     */
1224
-    public function state_form_field_input__wrap($input, $label)
1225
-    {
1226
-        return '
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 *        form_form_field_label_wrap
1205
+	 *
1206
+	 * @access        public
1207
+	 * @param        string $label
1208
+	 * @param        string $required_text
1209
+	 * @return        string
1210
+	 */
1211
+	public function state_form_field_label_wrap($label, $required_text)
1212
+	{
1213
+		return $required_text;
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 *        form_form_field_input__wrap
1219
+	 *
1220
+	 * @access        public
1221
+	 * @param        string $label
1222
+	 * @return        string
1223
+	 */
1224
+	public function state_form_field_input__wrap($input, $label)
1225
+	{
1226
+		return '
1227 1227
 				<td class="general-settings-country-state-input-td">
1228 1228
 					' . $input . '
1229 1229
 				</td>';
1230
-    }
1231
-
1232
-
1233
-    /***********/
1234
-
1235
-
1236
-    /**
1237
-     * displays edit and view links for critical EE pages
1238
-     *
1239
-     * @access public
1240
-     * @param int $ee_page_id
1241
-     * @return string
1242
-     */
1243
-    public static function edit_view_links($ee_page_id)
1244
-    {
1245
-        $links = '<a href="'
1246
-                 . add_query_arg(
1247
-                     array('post' => $ee_page_id, 'action' => 'edit'),
1248
-                     admin_url('post.php')
1249
-                 )
1250
-                 . '" >'
1251
-                 . __('Edit', 'event_espresso')
1252
-                 . '</a>';
1253
-        $links .= ' &nbsp;|&nbsp; ';
1254
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1255
-
1256
-        return $links;
1257
-    }
1258
-
1259
-
1260
-    /**
1261
-     * displays page and shortcode status for critical EE pages
1262
-     *
1263
-     * @param WP page object $ee_page
1264
-     * @return string
1265
-     */
1266
-    public static function page_and_shortcode_status($ee_page, $shortcode)
1267
-    {
1268
-
1269
-        // page status
1270
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1271
-            $pg_colour = 'green';
1272
-            $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1273
-        } else {
1274
-            $pg_colour = 'red';
1275
-            $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1276
-        }
1277
-
1278
-        // shortcode status
1279
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1280
-            $sc_colour = 'green';
1281
-            $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1282
-        } else {
1283
-            $sc_colour = 'red';
1284
-            $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1285
-        }
1286
-
1287
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1288
-               . $pg_status
1289
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * generates a dropdown of all parent pages - copied from WP core
1295
-     *
1296
-     * @param int $default
1297
-     * @param int $parent
1298
-     * @param int $level
1299
-     */
1300
-    public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1301
-    {
1302
-        global $wpdb;
1303
-        $items = $wpdb->get_results(
1304
-            $wpdb->prepare(
1305
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1306
-                $parent
1307
-            )
1308
-        );
1309
-
1310
-        if ($items) {
1311
-            foreach ($items as $item) {
1312
-                $pad = str_repeat('&nbsp;', $level * 3);
1313
-                if ($item->ID == $default) {
1314
-                    $current = ' selected="selected"';
1315
-                } else {
1316
-                    $current = '';
1317
-                }
1318
-
1319
-                echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1320
-                     . esc_html($item->post_title)
1321
-                     . "</option>";
1322
-                parent_dropdown($default, $item->ID, $level + 1);
1323
-            }
1324
-        }
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Loads the scripts for the privacy settings form
1330
-     */
1331
-    public function load_scripts_styles_privacy_settings()
1332
-    {
1333
-        $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1334
-        $form_handler->enqueueStylesAndScripts();
1335
-    }
1336
-
1337
-
1338
-    /**
1339
-     * display the privacy settings form
1340
-     */
1341
-    public function privacySettings()
1342
-    {
1343
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1344
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1345
-        $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1346
-        $this->_template_args['admin_page_content'] = $form_handler->display();
1347
-        $this->display_admin_page_with_sidebar();
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * Update the privacy settings from form data
1353
-     *
1354
-     * @throws EE_Error
1355
-     */
1356
-    public function updatePrivacySettings()
1357
-    {
1358
-        $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1359
-        $success = $form_handler->process($this->get_request_data());
1360
-        $this->_redirect_after_action(
1361
-            $success,
1362
-            esc_html__('Registration Form Options', 'event_espresso'),
1363
-            'updated',
1364
-            array('action' => 'privacy_settings')
1365
-        );
1366
-    }
1230
+	}
1231
+
1232
+
1233
+	/***********/
1234
+
1235
+
1236
+	/**
1237
+	 * displays edit and view links for critical EE pages
1238
+	 *
1239
+	 * @access public
1240
+	 * @param int $ee_page_id
1241
+	 * @return string
1242
+	 */
1243
+	public static function edit_view_links($ee_page_id)
1244
+	{
1245
+		$links = '<a href="'
1246
+				 . add_query_arg(
1247
+					 array('post' => $ee_page_id, 'action' => 'edit'),
1248
+					 admin_url('post.php')
1249
+				 )
1250
+				 . '" >'
1251
+				 . __('Edit', 'event_espresso')
1252
+				 . '</a>';
1253
+		$links .= ' &nbsp;|&nbsp; ';
1254
+		$links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1255
+
1256
+		return $links;
1257
+	}
1258
+
1259
+
1260
+	/**
1261
+	 * displays page and shortcode status for critical EE pages
1262
+	 *
1263
+	 * @param WP page object $ee_page
1264
+	 * @return string
1265
+	 */
1266
+	public static function page_and_shortcode_status($ee_page, $shortcode)
1267
+	{
1268
+
1269
+		// page status
1270
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1271
+			$pg_colour = 'green';
1272
+			$pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1273
+		} else {
1274
+			$pg_colour = 'red';
1275
+			$pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1276
+		}
1277
+
1278
+		// shortcode status
1279
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1280
+			$sc_colour = 'green';
1281
+			$sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1282
+		} else {
1283
+			$sc_colour = 'red';
1284
+			$sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1285
+		}
1286
+
1287
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1288
+			   . $pg_status
1289
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * generates a dropdown of all parent pages - copied from WP core
1295
+	 *
1296
+	 * @param int $default
1297
+	 * @param int $parent
1298
+	 * @param int $level
1299
+	 */
1300
+	public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1301
+	{
1302
+		global $wpdb;
1303
+		$items = $wpdb->get_results(
1304
+			$wpdb->prepare(
1305
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1306
+				$parent
1307
+			)
1308
+		);
1309
+
1310
+		if ($items) {
1311
+			foreach ($items as $item) {
1312
+				$pad = str_repeat('&nbsp;', $level * 3);
1313
+				if ($item->ID == $default) {
1314
+					$current = ' selected="selected"';
1315
+				} else {
1316
+					$current = '';
1317
+				}
1318
+
1319
+				echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1320
+					 . esc_html($item->post_title)
1321
+					 . "</option>";
1322
+				parent_dropdown($default, $item->ID, $level + 1);
1323
+			}
1324
+		}
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Loads the scripts for the privacy settings form
1330
+	 */
1331
+	public function load_scripts_styles_privacy_settings()
1332
+	{
1333
+		$form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1334
+		$form_handler->enqueueStylesAndScripts();
1335
+	}
1336
+
1337
+
1338
+	/**
1339
+	 * display the privacy settings form
1340
+	 */
1341
+	public function privacySettings()
1342
+	{
1343
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1344
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1345
+		$form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1346
+		$this->_template_args['admin_page_content'] = $form_handler->display();
1347
+		$this->display_admin_page_with_sidebar();
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * Update the privacy settings from form data
1353
+	 *
1354
+	 * @throws EE_Error
1355
+	 */
1356
+	public function updatePrivacySettings()
1357
+	{
1358
+		$form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1359
+		$success = $form_handler->process($this->get_request_data());
1360
+		$this->_redirect_after_action(
1361
+			$success,
1362
+			esc_html__('Registration Form Options', 'event_espresso'),
1363
+			'updated',
1364
+			array('action' => 'privacy_settings')
1365
+		);
1366
+	}
1367 1367
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -29,459 +29,459 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
56
+	const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
57 57
 
58
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
58
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
59 59
 
60
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
60
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
61 61
 
62
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
62
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
63 63
 
64
-    const JS_HANDLE_EE_CORE = 'espresso_core';
64
+	const JS_HANDLE_EE_CORE = 'espresso_core';
65 65
 
66
-    const JS_HANDLE_EE_I18N = 'eei18n';
67
-
68
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
-
70
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
-
72
-    // EE CSS assets handles
73
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
-
75
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
-
77
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
-
79
-    /**
80
-     * @var EE_Currency_Config $currency_config
81
-     */
82
-    protected $currency_config;
83
-
84
-    /**
85
-     * @var EE_Template_Config $template_config
86
-     */
87
-    protected $template_config;
88
-
89
-
90
-    /**
91
-     * CoreAssetRegister constructor.
92
-     *
93
-     * @param AssetCollection    $assets
94
-     * @param EE_Currency_Config $currency_config
95
-     * @param EE_Template_Config $template_config
96
-     * @param DomainInterface    $domain
97
-     * @param Registry           $registry
98
-     */
99
-    public function __construct(
100
-        AssetCollection $assets,
101
-        EE_Currency_Config $currency_config,
102
-        EE_Template_Config $template_config,
103
-        DomainInterface $domain,
104
-        Registry $registry
105
-    ) {
106
-        $this->currency_config = $currency_config;
107
-        $this->template_config = $template_config;
108
-        parent::__construct($domain, $assets, $registry);
109
-    }
110
-
111
-
112
-    /**
113
-     * @since 4.9.62.p
114
-     * @throws DuplicateCollectionIdentifierException
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     */
119
-    public function addAssets()
120
-    {
121
-        $this->addJavascriptFiles();
122
-        $this->addStylesheetFiles();
123
-    }
124
-
125
-
126
-    /**
127
-     * @since 4.9.62.p
128
-     * @throws DuplicateCollectionIdentifierException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidEntityException
132
-     */
133
-    public function addJavascriptFiles()
134
-    {
135
-        $this->loadCoreJs();
136
-        $this->loadJqueryValidate();
137
-        $this->loadAccountingJs();
138
-        add_action(
139
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-            array($this, 'loadQtipJs')
141
-        );
142
-        $this->registerAdminAssets();
143
-    }
144
-
145
-
146
-    /**
147
-     * @since 4.9.62.p
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     */
152
-    public function addStylesheetFiles()
153
-    {
154
-        $this->loadCoreCss();
155
-    }
156
-
157
-
158
-    /**
159
-     * core default javascript
160
-     *
161
-     * @since 4.9.62.p
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidEntityException
166
-     */
167
-    private function loadCoreJs()
168
-    {
169
-        $this->addJavascript(
170
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
-        )
179
-        ->setHasInlineData();
180
-
181
-        $this->addJavascript(
182
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
-        );
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
-        )->setRequiresTranslation();
191
-
192
-        $this->addJavascript(
193
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
194
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
-            array(
196
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
197
-            )
198
-        )->setRequiresTranslation();
199
-
200
-        $this->addJavascript(
201
-            CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
-            array(
204
-                CoreAssetManager::JS_HANDLE_EE_MODEL
205
-            )
206
-        )->setRequiresTranslation();
207
-
208
-        $this->addJavascript(
209
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
-            array(
212
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
-                'wp-data',
214
-                'wp-api-request',
215
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
-            )
217
-        )
218
-             ->setRequiresTranslation();
219
-
220
-        $this->addJavascript(
221
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
-            array(
224
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
-                'wp-components',
227
-            )
228
-        )->setRequiresTranslation();
229
-
230
-        $this->addJavascript(
231
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
-            array(
234
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
-                'wp-components',
237
-            )
238
-        )
239
-        ->setRequiresTranslation();
240
-
241
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
-        $this->registry->addData(
243
-            'paths',
244
-            array(
245
-                'rest_route' => rest_url('ee/v4.8.36/'),
246
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
-                'site_url' => site_url('/'),
249
-                'admin_url' => admin_url('/'),
250
-            )
251
-        );
252
-        /** site formatting values **/
253
-        $this->registry->addData(
254
-            'site_formats',
255
-            array(
256
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
-            )
258
-        );
259
-        /** currency data **/
260
-        $this->registry->addData(
261
-            'currency_config',
262
-            $this->getCurrencySettings()
263
-        );
264
-        /** site timezone */
265
-        $this->registry->addData(
266
-            'default_timezone',
267
-            array(
268
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
-                'string' => get_option('timezone_string'),
270
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
-            )
272
-        );
273
-        /** site locale (user locale if user logged in) */
274
-        $this->registry->addData(
275
-            'locale',
276
-            array(
277
-                'user' => get_user_locale(),
278
-                'site' => get_locale()
279
-            )
280
-        );
281
-
282
-        $this->addJavascript(
283
-            CoreAssetManager::JS_HANDLE_EE_CORE,
284
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
286
-        )
287
-        ->setInlineDataCallback(
288
-            function () {
289
-                wp_localize_script(
290
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
291
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
292
-                    EE_Registry::$i18n_js_strings
293
-                );
294
-            }
295
-        );
296
-    }
297
-
298
-
299
-    /**
300
-     * Returns configuration data for the accounting-js library.
301
-     * @since $VID:$
302
-     * @return array
303
-     */
304
-    private function getAccountingSettings() {
305
-        return array(
306
-            'currency' => array(
307
-                'symbol'    => $this->currency_config->sign,
308
-                'format'    => array(
309
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
-                ),
313
-                'decimal'   => $this->currency_config->dec_mrk,
314
-                'thousand'  => $this->currency_config->thsnds,
315
-                'precision' => $this->currency_config->dec_plc,
316
-            ),
317
-            'number'   => array(
318
-                'precision' => $this->currency_config->dec_plc,
319
-                'thousand'  => $this->currency_config->thsnds,
320
-                'decimal'   => $this->currency_config->dec_mrk,
321
-            ),
322
-        );
323
-    }
324
-
325
-
326
-    /**
327
-     * Returns configuration data for the js Currency VO.
328
-     * @sinc $VID:$
329
-     * @return array
330
-     */
331
-    private function getCurrencySettings()
332
-    {
333
-        return array(
334
-            'code' => $this->currency_config->code,
335
-            'singularLabel' => $this->currency_config->name,
336
-            'pluralLabel' => $this->currency_config->plural,
337
-            'sign' => $this->currency_config->sign,
338
-            'signB4' => $this->currency_config->sign_b4,
339
-            'decimalPlaces' => $this->currency_config->dec_plc,
340
-            'decimalMark' => $this->currency_config->dec_mrk,
341
-            'thousandsSeparator' => $this->currency_config->thsnds,
342
-        );
343
-    }
344
-
345
-
346
-    /**
347
-     * @since 4.9.62.p
348
-     * @throws DuplicateCollectionIdentifierException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidEntityException
351
-     */
352
-    private function loadCoreCss()
353
-    {
354
-        if ($this->template_config->enable_default_style && ! is_admin()) {
355
-            $this->addStylesheet(
356
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
-                array('dashicons')
361
-            );
362
-            //Load custom style sheet if available
363
-            if ($this->template_config->custom_style_sheet !== null) {
364
-                $this->addStylesheet(
365
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
-                );
369
-            }
370
-        }
371
-        $this->addStylesheet(
372
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
-            $this->registry->getCssUrl(
374
-                $this->domain->assetNamespace(),
375
-                'components'
376
-            )
377
-        );
378
-    }
379
-
380
-
381
-    /**
382
-     * jQuery Validate for form validation
383
-     *
384
-     * @since 4.9.62.p
385
-     * @throws DuplicateCollectionIdentifierException
386
-     * @throws InvalidDataTypeException
387
-     * @throws InvalidEntityException
388
-     */
389
-    private function loadJqueryValidate()
390
-    {
391
-        $this->addJavascript(
392
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
393
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
394
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
395
-        )
396
-        ->setVersion('1.15.0');
397
-
398
-        $this->addJavascript(
399
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
400
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
401
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
402
-        )
403
-        ->setVersion('1.15.0');
404
-    }
405
-
406
-
407
-    /**
408
-     * accounting.js for performing client-side calculations
409
-     *
410
-     * @since 4.9.62.p
411
-     * @throws DuplicateCollectionIdentifierException
412
-     * @throws InvalidDataTypeException
413
-     * @throws InvalidEntityException
414
-     */
415
-    private function loadAccountingJs()
416
-    {
417
-        //accounting.js library
418
-        // @link http://josscrowcroft.github.io/accounting.js/
419
-        $this->addJavascript(
420
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
421
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
422
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
423
-        )
424
-        ->setVersion('0.3.2');
425
-
426
-        $this->addJavascript(
427
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
428
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
429
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
430
-        )
431
-        ->setInlineDataCallback(
432
-            function () {
433
-                 wp_localize_script(
434
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
-                     'EE_ACCOUNTING_CFG',
436
-                     $this->getAccountingSettings()
437
-                 );
438
-            }
439
-        )
440
-        ->setVersion();
441
-    }
442
-
443
-
444
-    /**
445
-     * registers assets for cleaning your ears
446
-     *
447
-     * @param JavascriptAsset $script
448
-     */
449
-    public function loadQtipJs(JavascriptAsset $script)
450
-    {
451
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
452
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
453
-        if (
454
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
455
-            && apply_filters('FHEE_load_qtip', false)
456
-        ) {
457
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
458
-        }
459
-    }
460
-
461
-
462
-    /**
463
-     * assets that are used in the WordPress admin
464
-     *
465
-     * @since 4.9.62.p
466
-     * @throws DuplicateCollectionIdentifierException
467
-     * @throws InvalidDataTypeException
468
-     * @throws InvalidEntityException
469
-     */
470
-    private function registerAdminAssets()
471
-    {
472
-        $this->addJavascript(
473
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
475
-            array(
476
-                CoreAssetManager::JS_HANDLE_JQUERY,
477
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
478
-            )
479
-        )
480
-        ->setRequiresTranslation();
481
-
482
-        $this->addStylesheet(
483
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
484
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
485
-        );
486
-    }
66
+	const JS_HANDLE_EE_I18N = 'eei18n';
67
+
68
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
+
70
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
+
72
+	// EE CSS assets handles
73
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
+
75
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
+
77
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
+
79
+	/**
80
+	 * @var EE_Currency_Config $currency_config
81
+	 */
82
+	protected $currency_config;
83
+
84
+	/**
85
+	 * @var EE_Template_Config $template_config
86
+	 */
87
+	protected $template_config;
88
+
89
+
90
+	/**
91
+	 * CoreAssetRegister constructor.
92
+	 *
93
+	 * @param AssetCollection    $assets
94
+	 * @param EE_Currency_Config $currency_config
95
+	 * @param EE_Template_Config $template_config
96
+	 * @param DomainInterface    $domain
97
+	 * @param Registry           $registry
98
+	 */
99
+	public function __construct(
100
+		AssetCollection $assets,
101
+		EE_Currency_Config $currency_config,
102
+		EE_Template_Config $template_config,
103
+		DomainInterface $domain,
104
+		Registry $registry
105
+	) {
106
+		$this->currency_config = $currency_config;
107
+		$this->template_config = $template_config;
108
+		parent::__construct($domain, $assets, $registry);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @since 4.9.62.p
114
+	 * @throws DuplicateCollectionIdentifierException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 */
119
+	public function addAssets()
120
+	{
121
+		$this->addJavascriptFiles();
122
+		$this->addStylesheetFiles();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @since 4.9.62.p
128
+	 * @throws DuplicateCollectionIdentifierException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidEntityException
132
+	 */
133
+	public function addJavascriptFiles()
134
+	{
135
+		$this->loadCoreJs();
136
+		$this->loadJqueryValidate();
137
+		$this->loadAccountingJs();
138
+		add_action(
139
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+			array($this, 'loadQtipJs')
141
+		);
142
+		$this->registerAdminAssets();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @since 4.9.62.p
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 */
152
+	public function addStylesheetFiles()
153
+	{
154
+		$this->loadCoreCss();
155
+	}
156
+
157
+
158
+	/**
159
+	 * core default javascript
160
+	 *
161
+	 * @since 4.9.62.p
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidEntityException
166
+	 */
167
+	private function loadCoreJs()
168
+	{
169
+		$this->addJavascript(
170
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
+		)
179
+		->setHasInlineData();
180
+
181
+		$this->addJavascript(
182
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
+		);
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
189
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
190
+		)->setRequiresTranslation();
191
+
192
+		$this->addJavascript(
193
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
194
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
195
+			array(
196
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
197
+			)
198
+		)->setRequiresTranslation();
199
+
200
+		$this->addJavascript(
201
+			CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
202
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
203
+			array(
204
+				CoreAssetManager::JS_HANDLE_EE_MODEL
205
+			)
206
+		)->setRequiresTranslation();
207
+
208
+		$this->addJavascript(
209
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
211
+			array(
212
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
213
+				'wp-data',
214
+				'wp-api-request',
215
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS
216
+			)
217
+		)
218
+			 ->setRequiresTranslation();
219
+
220
+		$this->addJavascript(
221
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
222
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
223
+			array(
224
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
225
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
226
+				'wp-components',
227
+			)
228
+		)->setRequiresTranslation();
229
+
230
+		$this->addJavascript(
231
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
232
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
233
+			array(
234
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
235
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
236
+				'wp-components',
237
+			)
238
+		)
239
+		->setRequiresTranslation();
240
+
241
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
242
+		$this->registry->addData(
243
+			'paths',
244
+			array(
245
+				'rest_route' => rest_url('ee/v4.8.36/'),
246
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
247
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
248
+				'site_url' => site_url('/'),
249
+				'admin_url' => admin_url('/'),
250
+			)
251
+		);
252
+		/** site formatting values **/
253
+		$this->registry->addData(
254
+			'site_formats',
255
+			array(
256
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
257
+			)
258
+		);
259
+		/** currency data **/
260
+		$this->registry->addData(
261
+			'currency_config',
262
+			$this->getCurrencySettings()
263
+		);
264
+		/** site timezone */
265
+		$this->registry->addData(
266
+			'default_timezone',
267
+			array(
268
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
269
+				'string' => get_option('timezone_string'),
270
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
271
+			)
272
+		);
273
+		/** site locale (user locale if user logged in) */
274
+		$this->registry->addData(
275
+			'locale',
276
+			array(
277
+				'user' => get_user_locale(),
278
+				'site' => get_locale()
279
+			)
280
+		);
281
+
282
+		$this->addJavascript(
283
+			CoreAssetManager::JS_HANDLE_EE_CORE,
284
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
285
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
286
+		)
287
+		->setInlineDataCallback(
288
+			function () {
289
+				wp_localize_script(
290
+					CoreAssetManager::JS_HANDLE_EE_CORE,
291
+					CoreAssetManager::JS_HANDLE_EE_I18N,
292
+					EE_Registry::$i18n_js_strings
293
+				);
294
+			}
295
+		);
296
+	}
297
+
298
+
299
+	/**
300
+	 * Returns configuration data for the accounting-js library.
301
+	 * @since $VID:$
302
+	 * @return array
303
+	 */
304
+	private function getAccountingSettings() {
305
+		return array(
306
+			'currency' => array(
307
+				'symbol'    => $this->currency_config->sign,
308
+				'format'    => array(
309
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
310
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
311
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
312
+				),
313
+				'decimal'   => $this->currency_config->dec_mrk,
314
+				'thousand'  => $this->currency_config->thsnds,
315
+				'precision' => $this->currency_config->dec_plc,
316
+			),
317
+			'number'   => array(
318
+				'precision' => $this->currency_config->dec_plc,
319
+				'thousand'  => $this->currency_config->thsnds,
320
+				'decimal'   => $this->currency_config->dec_mrk,
321
+			),
322
+		);
323
+	}
324
+
325
+
326
+	/**
327
+	 * Returns configuration data for the js Currency VO.
328
+	 * @sinc $VID:$
329
+	 * @return array
330
+	 */
331
+	private function getCurrencySettings()
332
+	{
333
+		return array(
334
+			'code' => $this->currency_config->code,
335
+			'singularLabel' => $this->currency_config->name,
336
+			'pluralLabel' => $this->currency_config->plural,
337
+			'sign' => $this->currency_config->sign,
338
+			'signB4' => $this->currency_config->sign_b4,
339
+			'decimalPlaces' => $this->currency_config->dec_plc,
340
+			'decimalMark' => $this->currency_config->dec_mrk,
341
+			'thousandsSeparator' => $this->currency_config->thsnds,
342
+		);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @since 4.9.62.p
348
+	 * @throws DuplicateCollectionIdentifierException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidEntityException
351
+	 */
352
+	private function loadCoreCss()
353
+	{
354
+		if ($this->template_config->enable_default_style && ! is_admin()) {
355
+			$this->addStylesheet(
356
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
357
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
358
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
359
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
360
+				array('dashicons')
361
+			);
362
+			//Load custom style sheet if available
363
+			if ($this->template_config->custom_style_sheet !== null) {
364
+				$this->addStylesheet(
365
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
366
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
367
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
368
+				);
369
+			}
370
+		}
371
+		$this->addStylesheet(
372
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
373
+			$this->registry->getCssUrl(
374
+				$this->domain->assetNamespace(),
375
+				'components'
376
+			)
377
+		);
378
+	}
379
+
380
+
381
+	/**
382
+	 * jQuery Validate for form validation
383
+	 *
384
+	 * @since 4.9.62.p
385
+	 * @throws DuplicateCollectionIdentifierException
386
+	 * @throws InvalidDataTypeException
387
+	 * @throws InvalidEntityException
388
+	 */
389
+	private function loadJqueryValidate()
390
+	{
391
+		$this->addJavascript(
392
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
393
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
394
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
395
+		)
396
+		->setVersion('1.15.0');
397
+
398
+		$this->addJavascript(
399
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
400
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
401
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
402
+		)
403
+		->setVersion('1.15.0');
404
+	}
405
+
406
+
407
+	/**
408
+	 * accounting.js for performing client-side calculations
409
+	 *
410
+	 * @since 4.9.62.p
411
+	 * @throws DuplicateCollectionIdentifierException
412
+	 * @throws InvalidDataTypeException
413
+	 * @throws InvalidEntityException
414
+	 */
415
+	private function loadAccountingJs()
416
+	{
417
+		//accounting.js library
418
+		// @link http://josscrowcroft.github.io/accounting.js/
419
+		$this->addJavascript(
420
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
421
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
422
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
423
+		)
424
+		->setVersion('0.3.2');
425
+
426
+		$this->addJavascript(
427
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
428
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
429
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
430
+		)
431
+		->setInlineDataCallback(
432
+			function () {
433
+				 wp_localize_script(
434
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
435
+					 'EE_ACCOUNTING_CFG',
436
+					 $this->getAccountingSettings()
437
+				 );
438
+			}
439
+		)
440
+		->setVersion();
441
+	}
442
+
443
+
444
+	/**
445
+	 * registers assets for cleaning your ears
446
+	 *
447
+	 * @param JavascriptAsset $script
448
+	 */
449
+	public function loadQtipJs(JavascriptAsset $script)
450
+	{
451
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
452
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
453
+		if (
454
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
455
+			&& apply_filters('FHEE_load_qtip', false)
456
+		) {
457
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
458
+		}
459
+	}
460
+
461
+
462
+	/**
463
+	 * assets that are used in the WordPress admin
464
+	 *
465
+	 * @since 4.9.62.p
466
+	 * @throws DuplicateCollectionIdentifierException
467
+	 * @throws InvalidDataTypeException
468
+	 * @throws InvalidEntityException
469
+	 */
470
+	private function registerAdminAssets()
471
+	{
472
+		$this->addJavascript(
473
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
475
+			array(
476
+				CoreAssetManager::JS_HANDLE_JQUERY,
477
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
478
+			)
479
+		)
480
+		->setRequiresTranslation();
481
+
482
+		$this->addStylesheet(
483
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
484
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
485
+		);
486
+	}
487 487
 }
Please login to merge, or discard this patch.
admin_pages/venues/templates/event_venues_metabox_content.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@
 block discarded – undo
5 5
                 <?php echo $no_venues_info; ?>
6 6
                 <p><a href="admin.php?page=espresso_venues" target="_blank">
7 7
                         <?php echo __(
8
-                            'Add venues to the Venue Manager',
9
-                            'event_espresso'
10
-                        ) ?></a></p>
8
+							'Add venues to the Venue Manager',
9
+							'event_espresso'
10
+						) ?></a></p>
11 11
             </fieldset>
12 12
         </td>
13 13
     </tr>
Please login to merge, or discard this patch.
domain/entities/route_match/specifications/frontend/AnyFrontendRequest.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@
 block discarded – undo
14 14
  */
15 15
 class AnyFrontendRequest extends RouteMatchSpecification
16 16
 {
17
-    public function isMatchingRoute()
18
-    {
19
-        return $this->request->isFrontend();
20
-    }
17
+	public function isMatchingRoute()
18
+	{
19
+		return $this->request->isFrontend();
20
+	}
21 21
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1292 added lines, -1292 removed lines patch added patch discarded remove patch
@@ -27,1296 +27,1296 @@
 block discarded – undo
27 27
 final class EE_System implements ResettableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
-     */
34
-    const req_type_normal = 0;
35
-
36
-    /**
37
-     * Indicates this is a brand new installation of EE so we should install
38
-     * tables and default data etc
39
-     */
40
-    const req_type_new_activation = 1;
41
-
42
-    /**
43
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
-     * and we just exited maintenance mode). We MUST check the database is setup properly
45
-     * and that default data is setup too
46
-     */
47
-    const req_type_reactivation = 2;
48
-
49
-    /**
50
-     * indicates that EE has been upgraded since its previous request.
51
-     * We may have data migration scripts to call and will want to trigger maintenance mode
52
-     */
53
-    const req_type_upgrade = 3;
54
-
55
-    /**
56
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
-     */
58
-    const req_type_downgrade = 4;
59
-
60
-    /**
61
-     * @deprecated since version 4.6.0.dev.006
62
-     * Now whenever a new_activation is detected the request type is still just
63
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
-     * (Specifically, when the migration manager indicates migrations are finished
67
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
-     */
69
-    const req_type_activation_but_not_installed = 5;
70
-
71
-    /**
72
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
-     */
74
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
-
76
-    /**
77
-     * @var EE_System $_instance
78
-     */
79
-    private static $_instance;
80
-
81
-    /**
82
-     * @var EE_Registry $registry
83
-     */
84
-    private $registry;
85
-
86
-    /**
87
-     * @var LoaderInterface $loader
88
-     */
89
-    private $loader;
90
-
91
-    /**
92
-     * @var EE_Capabilities $capabilities
93
-     */
94
-    private $capabilities;
95
-
96
-    /**
97
-     * @var RequestInterface $request
98
-     */
99
-    private $request;
100
-
101
-    /**
102
-     * @var EE_Maintenance_Mode $maintenance_mode
103
-     */
104
-    private $maintenance_mode;
105
-
106
-    /**
107
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
-     *
110
-     * @var int $_req_type
111
-     */
112
-    private $_req_type;
113
-
114
-    /**
115
-     * Whether or not there was a non-micro version change in EE core version during this request
116
-     *
117
-     * @var boolean $_major_version_change
118
-     */
119
-    private $_major_version_change = false;
120
-
121
-    /**
122
-     * A Context DTO dedicated solely to identifying the current request type.
123
-     *
124
-     * @var RequestTypeContextCheckerInterface $request_type
125
-     */
126
-    private $request_type;
127
-
128
-
129
-    /**
130
-     * @singleton method used to instantiate class object
131
-     * @param EE_Registry|null         $registry
132
-     * @param LoaderInterface|null     $loader
133
-     * @param RequestInterface|null    $request
134
-     * @param EE_Maintenance_Mode|null $maintenance_mode
135
-     * @return EE_System
136
-     */
137
-    public static function instance(
138
-        EE_Registry $registry = null,
139
-        LoaderInterface $loader = null,
140
-        RequestInterface $request = null,
141
-        EE_Maintenance_Mode $maintenance_mode = null
142
-    ) {
143
-        // check if class object is instantiated
144
-        if (! self::$_instance instanceof EE_System) {
145
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
146
-        }
147
-        return self::$_instance;
148
-    }
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        // make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        // we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-    /**
170
-     * sets hooks for running rest of system
171
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
172
-     * starting EE Addons from any other point may lead to problems
173
-     *
174
-     * @param EE_Registry         $registry
175
-     * @param LoaderInterface     $loader
176
-     * @param RequestInterface    $request
177
-     * @param EE_Maintenance_Mode $maintenance_mode
178
-     */
179
-    private function __construct(
180
-        EE_Registry $registry,
181
-        LoaderInterface $loader,
182
-        RequestInterface $request,
183
-        EE_Maintenance_Mode $maintenance_mode
184
-    ) {
185
-        $this->registry = $registry;
186
-        $this->loader = $loader;
187
-        $this->request = $request;
188
-        $this->maintenance_mode = $maintenance_mode;
189
-        do_action('AHEE__EE_System__construct__begin', $this);
190
-        add_action(
191
-            'AHEE__EE_Bootstrap__load_espresso_addons',
192
-            array($this, 'loadCapabilities'),
193
-            5
194
-        );
195
-        add_action(
196
-            'AHEE__EE_Bootstrap__load_espresso_addons',
197
-            array($this, 'loadCommandBus'),
198
-            7
199
-        );
200
-        add_action(
201
-            'AHEE__EE_Bootstrap__load_espresso_addons',
202
-            array($this, 'loadPluginApi'),
203
-            9
204
-        );
205
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
206
-        add_action(
207
-            'AHEE__EE_Bootstrap__load_espresso_addons',
208
-            array($this, 'load_espresso_addons')
209
-        );
210
-        // when an ee addon is activated, we want to call the core hook(s) again
211
-        // because the newly-activated addon didn't get a chance to run at all
212
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
213
-        // detect whether install or upgrade
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
216
-            array($this, 'detect_activations_or_upgrades'),
217
-            3
218
-        );
219
-        // load EE_Config, EE_Textdomain, etc
220
-        add_action(
221
-            'AHEE__EE_Bootstrap__load_core_configuration',
222
-            array($this, 'load_core_configuration'),
223
-            5
224
-        );
225
-        // load specifications for matching routes to current request
226
-        add_action(
227
-            'AHEE__EE_Bootstrap__load_core_configuration',
228
-            array($this, 'loadRouteMatchSpecifications')
229
-        );
230
-        // load EE_Config, EE_Textdomain, etc
231
-        add_action(
232
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
233
-            array($this, 'register_shortcodes_modules_and_widgets'),
234
-            7
235
-        );
236
-        // you wanna get going? I wanna get going... let's get going!
237
-        add_action(
238
-            'AHEE__EE_Bootstrap__brew_espresso',
239
-            array($this, 'brew_espresso'),
240
-            9
241
-        );
242
-        // other housekeeping
243
-        // exclude EE critical pages from wp_list_pages
244
-        add_filter(
245
-            'wp_list_pages_excludes',
246
-            array($this, 'remove_pages_from_wp_list_pages'),
247
-            10
248
-        );
249
-        // ALL EE Addons should use the following hook point to attach their initial setup too
250
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
251
-        do_action('AHEE__EE_System__construct__complete', $this);
252
-    }
253
-
254
-
255
-    /**
256
-     * load and setup EE_Capabilities
257
-     *
258
-     * @return void
259
-     * @throws EE_Error
260
-     */
261
-    public function loadCapabilities()
262
-    {
263
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
264
-        add_action(
265
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
266
-            function () {
267
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
268
-            }
269
-        );
270
-    }
271
-
272
-
273
-    /**
274
-     * create and cache the CommandBus, and also add middleware
275
-     * The CapChecker middleware requires the use of EE_Capabilities
276
-     * which is why we need to load the CommandBus after Caps are set up
277
-     *
278
-     * @return void
279
-     * @throws EE_Error
280
-     */
281
-    public function loadCommandBus()
282
-    {
283
-        $this->loader->getShared(
284
-            'CommandBusInterface',
285
-            array(
286
-                null,
287
-                apply_filters(
288
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
289
-                    array(
290
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
291
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
292
-                    )
293
-                ),
294
-            )
295
-        );
296
-    }
297
-
298
-
299
-    /**
300
-     * @return void
301
-     * @throws EE_Error
302
-     */
303
-    public function loadPluginApi()
304
-    {
305
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
306
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
307
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
308
-        $this->loader->getShared('EE_Request_Handler');
309
-    }
310
-
311
-
312
-    /**
313
-     * @param string $addon_name
314
-     * @param string $version_constant
315
-     * @param string $min_version_required
316
-     * @param string $load_callback
317
-     * @param string $plugin_file_constant
318
-     * @return void
319
-     */
320
-    private function deactivateIncompatibleAddon(
321
-        $addon_name,
322
-        $version_constant,
323
-        $min_version_required,
324
-        $load_callback,
325
-        $plugin_file_constant
326
-    ) {
327
-        if (! defined($version_constant)) {
328
-            return;
329
-        }
330
-        $addon_version = constant($version_constant);
331
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
332
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
333
-            if (! function_exists('deactivate_plugins')) {
334
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
335
-            }
336
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
337
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
338
-            EE_Error::add_error(
339
-                sprintf(
340
-                    esc_html__(
341
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
342
-                        'event_espresso'
343
-                    ),
344
-                    $addon_name,
345
-                    $min_version_required
346
-                ),
347
-                __FILE__,
348
-                __FUNCTION__ . "({$addon_name})",
349
-                __LINE__
350
-            );
351
-            EE_Error::get_notices(false, true);
352
-        }
353
-    }
354
-
355
-
356
-    /**
357
-     * load_espresso_addons
358
-     * allow addons to load first so that they can set hooks for running DMS's, etc
359
-     * this is hooked into both:
360
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
361
-     *        which runs during the WP 'plugins_loaded' action at priority 5
362
-     *    and the WP 'activate_plugin' hook point
363
-     *
364
-     * @access public
365
-     * @return void
366
-     */
367
-    public function load_espresso_addons()
368
-    {
369
-        $this->deactivateIncompatibleAddon(
370
-            'Wait Lists',
371
-            'EE_WAIT_LISTS_VERSION',
372
-            '1.0.0.beta.074',
373
-            'load_espresso_wait_lists',
374
-            'EE_WAIT_LISTS_PLUGIN_FILE'
375
-        );
376
-        $this->deactivateIncompatibleAddon(
377
-            'Automated Upcoming Event Notifications',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
379
-            '1.0.0.beta.091',
380
-            'load_espresso_automated_upcoming_event_notification',
381
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
382
-        );
383
-        do_action('AHEE__EE_System__load_espresso_addons');
384
-        // if the WP API basic auth plugin isn't already loaded, load it now.
385
-        // We want it for mobile apps. Just include the entire plugin
386
-        // also, don't load the basic auth when a plugin is getting activated, because
387
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
388
-        // and causes a fatal error
389
-        if ($this->request->getRequestParam('activate') !== 'true'
390
-            && ! function_exists('json_basic_auth_handler')
391
-            && ! function_exists('json_basic_auth_error')
392
-            && ! in_array(
393
-                $this->request->getRequestParam('action'),
394
-                array('activate', 'activate-selected'),
395
-                true
396
-            )
397
-        ) {
398
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
399
-        }
400
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
401
-    }
402
-
403
-
404
-    /**
405
-     * detect_activations_or_upgrades
406
-     * Checks for activation or upgrade of core first;
407
-     * then also checks if any registered addons have been activated or upgraded
408
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
409
-     * which runs during the WP 'plugins_loaded' action at priority 3
410
-     *
411
-     * @access public
412
-     * @return void
413
-     */
414
-    public function detect_activations_or_upgrades()
415
-    {
416
-        // first off: let's make sure to handle core
417
-        $this->detect_if_activation_or_upgrade();
418
-        foreach ($this->registry->addons as $addon) {
419
-            if ($addon instanceof EE_Addon) {
420
-                // detect teh request type for that addon
421
-                $addon->detect_activation_or_upgrade();
422
-            }
423
-        }
424
-    }
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type = $this->detect_req_type($espresso_db_update);
441
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                // migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                break;
457
-            case EE_System::req_type_downgrade:
458
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
459
-                // its possible migrations are no longer required
460
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
461
-                $this->_handle_core_version_change($espresso_db_update);
462
-                break;
463
-            case EE_System::req_type_normal:
464
-            default:
465
-                break;
466
-        }
467
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
468
-    }
469
-
470
-
471
-    /**
472
-     * Updates the list of installed versions and sets hooks for
473
-     * initializing the database later during the request
474
-     *
475
-     * @param array $espresso_db_update
476
-     */
477
-    private function _handle_core_version_change($espresso_db_update)
478
-    {
479
-        $this->update_list_of_installed_versions($espresso_db_update);
480
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
481
-        add_action(
482
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
483
-            array($this, 'initialize_db_if_no_migrations_required')
484
-        );
485
-    }
486
-
487
-
488
-    /**
489
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
-     * information about what versions of EE have been installed and activated,
491
-     * NOT necessarily the state of the database
492
-     *
493
-     * @param mixed $espresso_db_update           the value of the WordPress option.
494
-     *                                            If not supplied, fetches it from the options table
495
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
-     */
497
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
-    {
499
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
-        if (! $espresso_db_update) {
501
-            $espresso_db_update = get_option('espresso_db_update');
502
-        }
503
-        // check that option is an array
504
-        if (! is_array($espresso_db_update)) {
505
-            // if option is FALSE, then it never existed
506
-            if ($espresso_db_update === false) {
507
-                // make $espresso_db_update an array and save option with autoload OFF
508
-                $espresso_db_update = array();
509
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
-            } else {
511
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
512
-                $espresso_db_update = array($espresso_db_update => array());
513
-                update_option('espresso_db_update', $espresso_db_update);
514
-            }
515
-        } else {
516
-            $corrected_db_update = array();
517
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
-                    // the key is an int, and the value IS NOT an array
521
-                    // so it must be numerically-indexed, where values are versions installed...
522
-                    // fix it!
523
-                    $version_string = $should_be_array;
524
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
525
-                } else {
526
-                    // ok it checks out
527
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
528
-                }
529
-            }
530
-            $espresso_db_update = $corrected_db_update;
531
-            update_option('espresso_db_update', $espresso_db_update);
532
-        }
533
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
-        return $espresso_db_update;
535
-    }
536
-
537
-
538
-    /**
539
-     * Does the traditional work of setting up the plugin's database and adding default data.
540
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
541
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
542
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
543
-     * so that it will be done when migrations are finished
544
-     *
545
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
546
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
547
-     *                                       This is a resource-intensive job
548
-     *                                       so we prefer to only do it when necessary
549
-     * @return void
550
-     * @throws EE_Error
551
-     */
552
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
553
-    {
554
-        $request_type = $this->detect_req_type();
555
-        // only initialize system if we're not in maintenance mode.
556
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
557
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
558
-            $rewrite_rules = $this->loader->getShared(
559
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
560
-            );
561
-            $rewrite_rules->flush();
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-    /**
586
-     * Initializes the db for all registered addons
587
-     *
588
-     * @throws EE_Error
589
-     */
590
-    public function initialize_addons()
591
-    {
592
-        // foreach registered addon, make sure its db is up-to-date too
593
-        foreach ($this->registry->addons as $addon) {
594
-            if ($addon instanceof EE_Addon) {
595
-                $addon->initialize_db_if_no_migrations_required();
596
-            }
597
-        }
598
-    }
599
-
600
-
601
-    /**
602
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
603
-     *
604
-     * @param    array  $version_history
605
-     * @param    string $current_version_to_add version to be added to the version history
606
-     * @return    boolean success as to whether or not this option was changed
607
-     */
608
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
609
-    {
610
-        if (! $version_history) {
611
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
612
-        }
613
-        if ($current_version_to_add === null) {
614
-            $current_version_to_add = espresso_version();
615
-        }
616
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
617
-        // re-save
618
-        return update_option('espresso_db_update', $version_history);
619
-    }
620
-
621
-
622
-    /**
623
-     * Detects if the current version indicated in the has existed in the list of
624
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
-     *
626
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
-     *                                  If not supplied, fetches it from the options table.
628
-     *                                  Also, caches its result so later parts of the code can also know whether
629
-     *                                  there's been an update or not. This way we can add the current version to
630
-     *                                  espresso_db_update, but still know if this is a new install or not
631
-     * @return int one of the constants on EE_System::req_type_
632
-     */
633
-    public function detect_req_type($espresso_db_update = null)
634
-    {
635
-        if ($this->_req_type === null) {
636
-            $espresso_db_update = ! empty($espresso_db_update)
637
-                ? $espresso_db_update
638
-                : $this->fix_espresso_db_upgrade_option();
639
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
640
-                $espresso_db_update,
641
-                'ee_espresso_activation',
642
-                espresso_version()
643
-            );
644
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
645
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
646
-        }
647
-        return $this->_req_type;
648
-    }
649
-
650
-
651
-    /**
652
-     * Returns whether or not there was a non-micro version change (ie, change in either
653
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
654
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
655
-     *
656
-     * @param $activation_history
657
-     * @return bool
658
-     */
659
-    private function _detect_major_version_change($activation_history)
660
-    {
661
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
662
-        $previous_version_parts = explode('.', $previous_version);
663
-        $current_version_parts = explode('.', espresso_version());
664
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
665
-               && ($previous_version_parts[0] !== $current_version_parts[0]
666
-                   || $previous_version_parts[1] !== $current_version_parts[1]
667
-               );
668
-    }
669
-
670
-
671
-    /**
672
-     * Returns true if either the major or minor version of EE changed during this request.
673
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
-     *
675
-     * @return bool
676
-     */
677
-    public function is_major_version_change()
678
-    {
679
-        return $this->_major_version_change;
680
-    }
681
-
682
-
683
-    /**
684
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
685
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
686
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
687
-     * just activated to (for core that will always be espresso_version())
688
-     *
689
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
690
-     *                                                 ee plugin. for core that's 'espresso_db_update'
691
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
692
-     *                                                 indicate that this plugin was just activated
693
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
694
-     *                                                 espresso_version())
695
-     * @return int one of the constants on EE_System::req_type_*
696
-     */
697
-    public static function detect_req_type_given_activation_history(
698
-        $activation_history_for_addon,
699
-        $activation_indicator_option_name,
700
-        $version_to_upgrade_to
701
-    ) {
702
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
703
-        if ($activation_history_for_addon) {
704
-            // it exists, so this isn't a completely new install
705
-            // check if this version already in that list of previously installed versions
706
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
707
-                // it a version we haven't seen before
708
-                if ($version_is_higher === 1) {
709
-                    $req_type = EE_System::req_type_upgrade;
710
-                } else {
711
-                    $req_type = EE_System::req_type_downgrade;
712
-                }
713
-                delete_option($activation_indicator_option_name);
714
-            } else {
715
-                // its not an update. maybe a reactivation?
716
-                if (get_option($activation_indicator_option_name, false)) {
717
-                    if ($version_is_higher === -1) {
718
-                        $req_type = EE_System::req_type_downgrade;
719
-                    } elseif ($version_is_higher === 0) {
720
-                        // we've seen this version before, but it's an activation. must be a reactivation
721
-                        $req_type = EE_System::req_type_reactivation;
722
-                    } else {// $version_is_higher === 1
723
-                        $req_type = EE_System::req_type_upgrade;
724
-                    }
725
-                    delete_option($activation_indicator_option_name);
726
-                } else {
727
-                    // we've seen this version before and the activation indicate doesn't show it was just activated
728
-                    if ($version_is_higher === -1) {
729
-                        $req_type = EE_System::req_type_downgrade;
730
-                    } elseif ($version_is_higher === 0) {
731
-                        // we've seen this version before and it's not an activation. its normal request
732
-                        $req_type = EE_System::req_type_normal;
733
-                    } else {// $version_is_higher === 1
734
-                        $req_type = EE_System::req_type_upgrade;
735
-                    }
736
-                }
737
-            }
738
-        } else {
739
-            // brand new install
740
-            $req_type = EE_System::req_type_new_activation;
741
-            delete_option($activation_indicator_option_name);
742
-        }
743
-        return $req_type;
744
-    }
745
-
746
-
747
-    /**
748
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
749
-     * the $activation_history_for_addon
750
-     *
751
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
752
-     *                                             sometimes containing 'unknown-date'
753
-     * @param string $version_to_upgrade_to        (current version)
754
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
755
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
756
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
757
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
758
-     */
759
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
760
-    {
761
-        // find the most recently-activated version
762
-        $most_recently_active_version =
763
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
764
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets the most recently active version listed in the activation history,
770
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
771
-     *
772
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
773
-     *                                   sometimes containing 'unknown-date'
774
-     * @return string
775
-     */
776
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
777
-    {
778
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
779
-        $most_recently_active_version = '0.0.0.dev.000';
780
-        if (is_array($activation_history)) {
781
-            foreach ($activation_history as $version => $times_activated) {
782
-                // check there is a record of when this version was activated. Otherwise,
783
-                // mark it as unknown
784
-                if (! $times_activated) {
785
-                    $times_activated = array('unknown-date');
786
-                }
787
-                if (is_string($times_activated)) {
788
-                    $times_activated = array($times_activated);
789
-                }
790
-                foreach ($times_activated as $an_activation) {
791
-                    if ($an_activation !== 'unknown-date'
792
-                        && $an_activation
793
-                           > $most_recently_active_version_activation) {
794
-                        $most_recently_active_version = $version;
795
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
796
-                            ? '1970-01-01 00:00:00'
797
-                            : $an_activation;
798
-                    }
799
-                }
800
-            }
801
-        }
802
-        return $most_recently_active_version;
803
-    }
804
-
805
-
806
-    /**
807
-     * This redirects to the about EE page after activation
808
-     *
809
-     * @return void
810
-     */
811
-    public function redirect_to_about_ee()
812
-    {
813
-        $notices = EE_Error::get_notices(false);
814
-        // if current user is an admin and it's not an ajax or rest request
815
-        if (! isset($notices['errors'])
816
-            && $this->request->isAdmin()
817
-            && apply_filters(
818
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
819
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
820
-            )
821
-        ) {
822
-            $query_params = array('page' => 'espresso_about');
823
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
824
-                $query_params['new_activation'] = true;
825
-            }
826
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
827
-                $query_params['reactivation'] = true;
828
-            }
829
-            $url = add_query_arg($query_params, admin_url('admin.php'));
830
-            wp_safe_redirect($url);
831
-            exit();
832
-        }
833
-    }
834
-
835
-
836
-    /**
837
-     * load_core_configuration
838
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
839
-     * which runs during the WP 'plugins_loaded' action at priority 5
840
-     *
841
-     * @return void
842
-     * @throws ReflectionException
843
-     * @throws Exception
844
-     */
845
-    public function load_core_configuration()
846
-    {
847
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
848
-        $this->loader->getShared('EE_Load_Textdomain');
849
-        // load textdomain
850
-        EE_Load_Textdomain::load_textdomain();
851
-        // load and setup EE_Config and EE_Network_Config
852
-        $config = $this->loader->getShared('EE_Config');
853
-        $this->loader->getShared('EE_Network_Config');
854
-        // setup autoloaders
855
-        // enable logging?
856
-        if ($config->admin->use_full_logging) {
857
-            $this->loader->getShared('EE_Log');
858
-        }
859
-        // check for activation errors
860
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
861
-        if ($activation_errors) {
862
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
863
-            update_option('ee_plugin_activation_errors', false);
864
-        }
865
-        // get model names
866
-        $this->_parse_model_names();
867
-        // load caf stuff a chance to play during the activation process too.
868
-        $this->_maybe_brew_regular();
869
-        // configure custom post type definitions
870
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
871
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
872
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
873
-    }
874
-
875
-
876
-    /**
877
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
878
-     *
879
-     * @return void
880
-     * @throws ReflectionException
881
-     */
882
-    private function _parse_model_names()
883
-    {
884
-        // get all the files in the EE_MODELS folder that end in .model.php
885
-        $models = glob(EE_MODELS . '*.model.php');
886
-        $model_names = array();
887
-        $non_abstract_db_models = array();
888
-        foreach ($models as $model) {
889
-            // get model classname
890
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
891
-            $short_name = str_replace('EEM_', '', $classname);
892
-            $reflectionClass = new ReflectionClass($classname);
893
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
894
-                $non_abstract_db_models[ $short_name ] = $classname;
895
-            }
896
-            $model_names[ $short_name ] = $classname;
897
-        }
898
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
899
-        $this->registry->non_abstract_db_models = apply_filters(
900
-            'FHEE__EE_System__parse_implemented_model_names',
901
-            $non_abstract_db_models
902
-        );
903
-    }
904
-
905
-
906
-    /**
907
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
908
-     * that need to be setup before our EE_System launches.
909
-     *
910
-     * @return void
911
-     * @throws DomainException
912
-     * @throws InvalidArgumentException
913
-     * @throws InvalidDataTypeException
914
-     * @throws InvalidInterfaceException
915
-     * @throws InvalidClassException
916
-     * @throws InvalidFilePathException
917
-     */
918
-    private function _maybe_brew_regular()
919
-    {
920
-        /** @var Domain $domain */
921
-        $domain = DomainFactory::getShared(
922
-            new FullyQualifiedName(
923
-                'EventEspresso\core\domain\Domain'
924
-            ),
925
-            array(
926
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
927
-                Version::fromString(espresso_version()),
928
-            )
929
-        );
930
-        if ($domain->isCaffeinated()) {
931
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
932
-        }
933
-    }
934
-
935
-
936
-    /**
937
-     * @since $VID:$
938
-     * @throws Exception
939
-     */
940
-    public function loadRouteMatchSpecifications()
941
-    {
942
-        try {
943
-            $this->loader->getShared(
944
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationManager'
945
-            );
946
-        } catch (Exception $exception) {
947
-            new ExceptionStackTraceDisplay($exception);
948
-        }
949
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
950
-    }
951
-
952
-
953
-    /**
954
-     * register_shortcodes_modules_and_widgets
955
-     * generate lists of shortcodes and modules, then verify paths and classes
956
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
957
-     * which runs during the WP 'plugins_loaded' action at priority 7
958
-     *
959
-     * @access public
960
-     * @return void
961
-     * @throws Exception
962
-     */
963
-    public function register_shortcodes_modules_and_widgets()
964
-    {
965
-        if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
966
-            try {
967
-                // load, register, and add shortcodes the new way
968
-                $this->loader->getShared(
969
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
970
-                    array(
971
-                        // and the old way, but we'll put it under control of the new system
972
-                        EE_Config::getLegacyShortcodesManager(),
973
-                    )
974
-                );
975
-            } catch (Exception $exception) {
976
-                new ExceptionStackTraceDisplay($exception);
977
-            }
978
-        }
979
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
980
-        // check for addons using old hook point
981
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
982
-            $this->_incompatible_addon_error();
983
-        }
984
-    }
985
-
986
-
987
-    /**
988
-     * _incompatible_addon_error
989
-     *
990
-     * @access public
991
-     * @return void
992
-     */
993
-    private function _incompatible_addon_error()
994
-    {
995
-        // get array of classes hooking into here
996
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
997
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
998
-        );
999
-        if (! empty($class_names)) {
1000
-            $msg = __(
1001
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1002
-                'event_espresso'
1003
-            );
1004
-            $msg .= '<ul>';
1005
-            foreach ($class_names as $class_name) {
1006
-                $msg .= '<li><b>Event Espresso - '
1007
-                        . str_replace(
1008
-                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1009
-                            '',
1010
-                            $class_name
1011
-                        ) . '</b></li>';
1012
-            }
1013
-            $msg .= '</ul>';
1014
-            $msg .= __(
1015
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1016
-                'event_espresso'
1017
-            );
1018
-            // save list of incompatible addons to wp-options for later use
1019
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1020
-            if (is_admin()) {
1021
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1022
-            }
1023
-        }
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * brew_espresso
1029
-     * begins the process of setting hooks for initializing EE in the correct order
1030
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1031
-     * which runs during the WP 'plugins_loaded' action at priority 9
1032
-     *
1033
-     * @return void
1034
-     */
1035
-    public function brew_espresso()
1036
-    {
1037
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1038
-        // load some final core systems
1039
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1040
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1041
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1042
-        add_action('init', array($this, 'load_controllers'), 7);
1043
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1044
-        add_action('init', array($this, 'initialize'), 10);
1045
-        add_action('init', array($this, 'initialize_last'), 100);
1046
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1047
-            // pew pew pew
1048
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1049
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1050
-        }
1051
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     *    set_hooks_for_core
1057
-     *
1058
-     * @access public
1059
-     * @return    void
1060
-     * @throws EE_Error
1061
-     */
1062
-    public function set_hooks_for_core()
1063
-    {
1064
-        $this->_deactivate_incompatible_addons();
1065
-        do_action('AHEE__EE_System__set_hooks_for_core');
1066
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
-        // caps need to be initialized on every request so that capability maps are set.
1068
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
-        $this->registry->CAP->init_caps();
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1075
-     * deactivates any addons considered incompatible with the current version of EE
1076
-     */
1077
-    private function _deactivate_incompatible_addons()
1078
-    {
1079
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1080
-        if (! empty($incompatible_addons)) {
1081
-            $active_plugins = get_option('active_plugins', array());
1082
-            foreach ($active_plugins as $active_plugin) {
1083
-                foreach ($incompatible_addons as $incompatible_addon) {
1084
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1085
-                        unset($_GET['activate']);
1086
-                        espresso_deactivate_plugin($active_plugin);
1087
-                    }
1088
-                }
1089
-            }
1090
-        }
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     *    perform_activations_upgrades_and_migrations
1096
-     *
1097
-     * @access public
1098
-     * @return    void
1099
-     */
1100
-    public function perform_activations_upgrades_and_migrations()
1101
-    {
1102
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * @return void
1108
-     * @throws DomainException
1109
-     */
1110
-    public function load_CPTs_and_session()
1111
-    {
1112
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1113
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1114
-        $register_custom_taxonomies = $this->loader->getShared(
1115
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1116
-        );
1117
-        $register_custom_taxonomies->registerCustomTaxonomies();
1118
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1119
-        $register_custom_post_types = $this->loader->getShared(
1120
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1121
-        );
1122
-        $register_custom_post_types->registerCustomPostTypes();
1123
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1124
-        $register_custom_taxonomy_terms = $this->loader->getShared(
1125
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1126
-        );
1127
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1128
-        // load legacy Custom Post Types and Taxonomies
1129
-        $this->loader->getShared('EE_Register_CPTs');
1130
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * load_controllers
1136
-     * this is the best place to load any additional controllers that needs access to EE core.
1137
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1138
-     * time
1139
-     *
1140
-     * @access public
1141
-     * @return void
1142
-     */
1143
-    public function load_controllers()
1144
-    {
1145
-        do_action('AHEE__EE_System__load_controllers__start');
1146
-        // let's get it started
1147
-        if (! $this->maintenance_mode->level()
1148
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1149
-        ) {
1150
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1151
-            $this->loader->getShared('EE_Front_Controller');
1152
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1153
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1154
-            $this->loader->getShared('EE_Admin');
1155
-        }
1156
-        do_action('AHEE__EE_System__load_controllers__complete');
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * core_loaded_and_ready
1162
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1163
-     *
1164
-     * @access public
1165
-     * @return void
1166
-     * @throws Exception
1167
-     */
1168
-    public function core_loaded_and_ready()
1169
-    {
1170
-        if ($this->request->isAdmin()
1171
-            || $this->request->isFrontend()
1172
-            || $this->request->isIframe()
1173
-            || $this->request->isWordPressApi()
1174
-        ) {
1175
-            try {
1176
-                $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1177
-                $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1178
-                if (function_exists('register_block_type')) {
1179
-                    $this->loader->getShared(
1180
-                        'EventEspresso\core\services\editor\BlockRegistrationManager'
1181
-                    );
1182
-                }
1183
-            } catch (Exception $exception) {
1184
-                new ExceptionStackTraceDisplay($exception);
1185
-            }
1186
-        }
1187
-        if ($this->request->isAdmin()
1188
-            || $this->request->isEeAjax()
1189
-            || $this->request->isFrontend()
1190
-        ) {
1191
-            $this->loader->getShared('EE_Session');
1192
-        }
1193
-        // integrate WP_Query with the EE models
1194
-        $this->loader->getShared('EE_CPT_Strategy');
1195
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1196
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1197
-        // builders require these even on the front-end
1198
-        require_once EE_PUBLIC . 'template_tags.php';
1199
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * initialize
1205
-     * this is the best place to begin initializing client code
1206
-     *
1207
-     * @access public
1208
-     * @return void
1209
-     */
1210
-    public function initialize()
1211
-    {
1212
-        do_action('AHEE__EE_System__initialize');
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * initialize_last
1218
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1219
-     * initialize has done so
1220
-     *
1221
-     * @access public
1222
-     * @return void
1223
-     */
1224
-    public function initialize_last()
1225
-    {
1226
-        do_action('AHEE__EE_System__initialize_last');
1227
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1228
-        $rewrite_rules = $this->loader->getShared(
1229
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1230
-        );
1231
-        $rewrite_rules->flushRewriteRules();
1232
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1233
-        if (($this->request->isAjax() || $this->request->isAdmin())
1234
-            && $this->maintenance_mode->models_can_query()) {
1235
-            $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1236
-            $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1237
-        }
1238
-    }
1239
-
1240
-
1241
-    /**
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function addEspressoToolbar()
1246
-    {
1247
-        $this->loader->getShared(
1248
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1249
-            array($this->registry->CAP)
1250
-        );
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     * do_not_cache
1256
-     * sets no cache headers and defines no cache constants for WP plugins
1257
-     *
1258
-     * @access public
1259
-     * @return void
1260
-     */
1261
-    public static function do_not_cache()
1262
-    {
1263
-        // set no cache constants
1264
-        if (! defined('DONOTCACHEPAGE')) {
1265
-            define('DONOTCACHEPAGE', true);
1266
-        }
1267
-        if (! defined('DONOTCACHCEOBJECT')) {
1268
-            define('DONOTCACHCEOBJECT', true);
1269
-        }
1270
-        if (! defined('DONOTCACHEDB')) {
1271
-            define('DONOTCACHEDB', true);
1272
-        }
1273
-        // add no cache headers
1274
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1275
-        // plus a little extra for nginx and Google Chrome
1276
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1277
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1278
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     *    extra_nocache_headers
1284
-     *
1285
-     * @access    public
1286
-     * @param $headers
1287
-     * @return    array
1288
-     */
1289
-    public static function extra_nocache_headers($headers)
1290
-    {
1291
-        // for NGINX
1292
-        $headers['X-Accel-Expires'] = 0;
1293
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1294
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1295
-        return $headers;
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     *    nocache_headers
1301
-     *
1302
-     * @access    public
1303
-     * @return    void
1304
-     */
1305
-    public static function nocache_headers()
1306
-    {
1307
-        nocache_headers();
1308
-    }
1309
-
1310
-
1311
-    /**
1312
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1313
-     * never returned with the function.
1314
-     *
1315
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1316
-     * @return array
1317
-     */
1318
-    public function remove_pages_from_wp_list_pages($exclude_array)
1319
-    {
1320
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1321
-    }
30
+	/**
31
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
+	 */
34
+	const req_type_normal = 0;
35
+
36
+	/**
37
+	 * Indicates this is a brand new installation of EE so we should install
38
+	 * tables and default data etc
39
+	 */
40
+	const req_type_new_activation = 1;
41
+
42
+	/**
43
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
45
+	 * and that default data is setup too
46
+	 */
47
+	const req_type_reactivation = 2;
48
+
49
+	/**
50
+	 * indicates that EE has been upgraded since its previous request.
51
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
52
+	 */
53
+	const req_type_upgrade = 3;
54
+
55
+	/**
56
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
+	 */
58
+	const req_type_downgrade = 4;
59
+
60
+	/**
61
+	 * @deprecated since version 4.6.0.dev.006
62
+	 * Now whenever a new_activation is detected the request type is still just
63
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
+	 * (Specifically, when the migration manager indicates migrations are finished
67
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
+	 */
69
+	const req_type_activation_but_not_installed = 5;
70
+
71
+	/**
72
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
+	 */
74
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
+
76
+	/**
77
+	 * @var EE_System $_instance
78
+	 */
79
+	private static $_instance;
80
+
81
+	/**
82
+	 * @var EE_Registry $registry
83
+	 */
84
+	private $registry;
85
+
86
+	/**
87
+	 * @var LoaderInterface $loader
88
+	 */
89
+	private $loader;
90
+
91
+	/**
92
+	 * @var EE_Capabilities $capabilities
93
+	 */
94
+	private $capabilities;
95
+
96
+	/**
97
+	 * @var RequestInterface $request
98
+	 */
99
+	private $request;
100
+
101
+	/**
102
+	 * @var EE_Maintenance_Mode $maintenance_mode
103
+	 */
104
+	private $maintenance_mode;
105
+
106
+	/**
107
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
+	 *
110
+	 * @var int $_req_type
111
+	 */
112
+	private $_req_type;
113
+
114
+	/**
115
+	 * Whether or not there was a non-micro version change in EE core version during this request
116
+	 *
117
+	 * @var boolean $_major_version_change
118
+	 */
119
+	private $_major_version_change = false;
120
+
121
+	/**
122
+	 * A Context DTO dedicated solely to identifying the current request type.
123
+	 *
124
+	 * @var RequestTypeContextCheckerInterface $request_type
125
+	 */
126
+	private $request_type;
127
+
128
+
129
+	/**
130
+	 * @singleton method used to instantiate class object
131
+	 * @param EE_Registry|null         $registry
132
+	 * @param LoaderInterface|null     $loader
133
+	 * @param RequestInterface|null    $request
134
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
135
+	 * @return EE_System
136
+	 */
137
+	public static function instance(
138
+		EE_Registry $registry = null,
139
+		LoaderInterface $loader = null,
140
+		RequestInterface $request = null,
141
+		EE_Maintenance_Mode $maintenance_mode = null
142
+	) {
143
+		// check if class object is instantiated
144
+		if (! self::$_instance instanceof EE_System) {
145
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
146
+		}
147
+		return self::$_instance;
148
+	}
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		// make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		// we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+	/**
170
+	 * sets hooks for running rest of system
171
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
172
+	 * starting EE Addons from any other point may lead to problems
173
+	 *
174
+	 * @param EE_Registry         $registry
175
+	 * @param LoaderInterface     $loader
176
+	 * @param RequestInterface    $request
177
+	 * @param EE_Maintenance_Mode $maintenance_mode
178
+	 */
179
+	private function __construct(
180
+		EE_Registry $registry,
181
+		LoaderInterface $loader,
182
+		RequestInterface $request,
183
+		EE_Maintenance_Mode $maintenance_mode
184
+	) {
185
+		$this->registry = $registry;
186
+		$this->loader = $loader;
187
+		$this->request = $request;
188
+		$this->maintenance_mode = $maintenance_mode;
189
+		do_action('AHEE__EE_System__construct__begin', $this);
190
+		add_action(
191
+			'AHEE__EE_Bootstrap__load_espresso_addons',
192
+			array($this, 'loadCapabilities'),
193
+			5
194
+		);
195
+		add_action(
196
+			'AHEE__EE_Bootstrap__load_espresso_addons',
197
+			array($this, 'loadCommandBus'),
198
+			7
199
+		);
200
+		add_action(
201
+			'AHEE__EE_Bootstrap__load_espresso_addons',
202
+			array($this, 'loadPluginApi'),
203
+			9
204
+		);
205
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
206
+		add_action(
207
+			'AHEE__EE_Bootstrap__load_espresso_addons',
208
+			array($this, 'load_espresso_addons')
209
+		);
210
+		// when an ee addon is activated, we want to call the core hook(s) again
211
+		// because the newly-activated addon didn't get a chance to run at all
212
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
213
+		// detect whether install or upgrade
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
216
+			array($this, 'detect_activations_or_upgrades'),
217
+			3
218
+		);
219
+		// load EE_Config, EE_Textdomain, etc
220
+		add_action(
221
+			'AHEE__EE_Bootstrap__load_core_configuration',
222
+			array($this, 'load_core_configuration'),
223
+			5
224
+		);
225
+		// load specifications for matching routes to current request
226
+		add_action(
227
+			'AHEE__EE_Bootstrap__load_core_configuration',
228
+			array($this, 'loadRouteMatchSpecifications')
229
+		);
230
+		// load EE_Config, EE_Textdomain, etc
231
+		add_action(
232
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
233
+			array($this, 'register_shortcodes_modules_and_widgets'),
234
+			7
235
+		);
236
+		// you wanna get going? I wanna get going... let's get going!
237
+		add_action(
238
+			'AHEE__EE_Bootstrap__brew_espresso',
239
+			array($this, 'brew_espresso'),
240
+			9
241
+		);
242
+		// other housekeeping
243
+		// exclude EE critical pages from wp_list_pages
244
+		add_filter(
245
+			'wp_list_pages_excludes',
246
+			array($this, 'remove_pages_from_wp_list_pages'),
247
+			10
248
+		);
249
+		// ALL EE Addons should use the following hook point to attach their initial setup too
250
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
251
+		do_action('AHEE__EE_System__construct__complete', $this);
252
+	}
253
+
254
+
255
+	/**
256
+	 * load and setup EE_Capabilities
257
+	 *
258
+	 * @return void
259
+	 * @throws EE_Error
260
+	 */
261
+	public function loadCapabilities()
262
+	{
263
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
264
+		add_action(
265
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
266
+			function () {
267
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
268
+			}
269
+		);
270
+	}
271
+
272
+
273
+	/**
274
+	 * create and cache the CommandBus, and also add middleware
275
+	 * The CapChecker middleware requires the use of EE_Capabilities
276
+	 * which is why we need to load the CommandBus after Caps are set up
277
+	 *
278
+	 * @return void
279
+	 * @throws EE_Error
280
+	 */
281
+	public function loadCommandBus()
282
+	{
283
+		$this->loader->getShared(
284
+			'CommandBusInterface',
285
+			array(
286
+				null,
287
+				apply_filters(
288
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
289
+					array(
290
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
291
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
292
+					)
293
+				),
294
+			)
295
+		);
296
+	}
297
+
298
+
299
+	/**
300
+	 * @return void
301
+	 * @throws EE_Error
302
+	 */
303
+	public function loadPluginApi()
304
+	{
305
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
306
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
307
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
308
+		$this->loader->getShared('EE_Request_Handler');
309
+	}
310
+
311
+
312
+	/**
313
+	 * @param string $addon_name
314
+	 * @param string $version_constant
315
+	 * @param string $min_version_required
316
+	 * @param string $load_callback
317
+	 * @param string $plugin_file_constant
318
+	 * @return void
319
+	 */
320
+	private function deactivateIncompatibleAddon(
321
+		$addon_name,
322
+		$version_constant,
323
+		$min_version_required,
324
+		$load_callback,
325
+		$plugin_file_constant
326
+	) {
327
+		if (! defined($version_constant)) {
328
+			return;
329
+		}
330
+		$addon_version = constant($version_constant);
331
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
332
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
333
+			if (! function_exists('deactivate_plugins')) {
334
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
335
+			}
336
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
337
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
338
+			EE_Error::add_error(
339
+				sprintf(
340
+					esc_html__(
341
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
342
+						'event_espresso'
343
+					),
344
+					$addon_name,
345
+					$min_version_required
346
+				),
347
+				__FILE__,
348
+				__FUNCTION__ . "({$addon_name})",
349
+				__LINE__
350
+			);
351
+			EE_Error::get_notices(false, true);
352
+		}
353
+	}
354
+
355
+
356
+	/**
357
+	 * load_espresso_addons
358
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
359
+	 * this is hooked into both:
360
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
361
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
362
+	 *    and the WP 'activate_plugin' hook point
363
+	 *
364
+	 * @access public
365
+	 * @return void
366
+	 */
367
+	public function load_espresso_addons()
368
+	{
369
+		$this->deactivateIncompatibleAddon(
370
+			'Wait Lists',
371
+			'EE_WAIT_LISTS_VERSION',
372
+			'1.0.0.beta.074',
373
+			'load_espresso_wait_lists',
374
+			'EE_WAIT_LISTS_PLUGIN_FILE'
375
+		);
376
+		$this->deactivateIncompatibleAddon(
377
+			'Automated Upcoming Event Notifications',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
379
+			'1.0.0.beta.091',
380
+			'load_espresso_automated_upcoming_event_notification',
381
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
382
+		);
383
+		do_action('AHEE__EE_System__load_espresso_addons');
384
+		// if the WP API basic auth plugin isn't already loaded, load it now.
385
+		// We want it for mobile apps. Just include the entire plugin
386
+		// also, don't load the basic auth when a plugin is getting activated, because
387
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
388
+		// and causes a fatal error
389
+		if ($this->request->getRequestParam('activate') !== 'true'
390
+			&& ! function_exists('json_basic_auth_handler')
391
+			&& ! function_exists('json_basic_auth_error')
392
+			&& ! in_array(
393
+				$this->request->getRequestParam('action'),
394
+				array('activate', 'activate-selected'),
395
+				true
396
+			)
397
+		) {
398
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
399
+		}
400
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
401
+	}
402
+
403
+
404
+	/**
405
+	 * detect_activations_or_upgrades
406
+	 * Checks for activation or upgrade of core first;
407
+	 * then also checks if any registered addons have been activated or upgraded
408
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
409
+	 * which runs during the WP 'plugins_loaded' action at priority 3
410
+	 *
411
+	 * @access public
412
+	 * @return void
413
+	 */
414
+	public function detect_activations_or_upgrades()
415
+	{
416
+		// first off: let's make sure to handle core
417
+		$this->detect_if_activation_or_upgrade();
418
+		foreach ($this->registry->addons as $addon) {
419
+			if ($addon instanceof EE_Addon) {
420
+				// detect teh request type for that addon
421
+				$addon->detect_activation_or_upgrade();
422
+			}
423
+		}
424
+	}
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type = $this->detect_req_type($espresso_db_update);
441
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				// migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				break;
457
+			case EE_System::req_type_downgrade:
458
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
459
+				// its possible migrations are no longer required
460
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
461
+				$this->_handle_core_version_change($espresso_db_update);
462
+				break;
463
+			case EE_System::req_type_normal:
464
+			default:
465
+				break;
466
+		}
467
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
468
+	}
469
+
470
+
471
+	/**
472
+	 * Updates the list of installed versions and sets hooks for
473
+	 * initializing the database later during the request
474
+	 *
475
+	 * @param array $espresso_db_update
476
+	 */
477
+	private function _handle_core_version_change($espresso_db_update)
478
+	{
479
+		$this->update_list_of_installed_versions($espresso_db_update);
480
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
481
+		add_action(
482
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
483
+			array($this, 'initialize_db_if_no_migrations_required')
484
+		);
485
+	}
486
+
487
+
488
+	/**
489
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
+	 * information about what versions of EE have been installed and activated,
491
+	 * NOT necessarily the state of the database
492
+	 *
493
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
494
+	 *                                            If not supplied, fetches it from the options table
495
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
+	 */
497
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
+	{
499
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
+		if (! $espresso_db_update) {
501
+			$espresso_db_update = get_option('espresso_db_update');
502
+		}
503
+		// check that option is an array
504
+		if (! is_array($espresso_db_update)) {
505
+			// if option is FALSE, then it never existed
506
+			if ($espresso_db_update === false) {
507
+				// make $espresso_db_update an array and save option with autoload OFF
508
+				$espresso_db_update = array();
509
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
+			} else {
511
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
512
+				$espresso_db_update = array($espresso_db_update => array());
513
+				update_option('espresso_db_update', $espresso_db_update);
514
+			}
515
+		} else {
516
+			$corrected_db_update = array();
517
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
+					// the key is an int, and the value IS NOT an array
521
+					// so it must be numerically-indexed, where values are versions installed...
522
+					// fix it!
523
+					$version_string = $should_be_array;
524
+					$corrected_db_update[ $version_string ] = array('unknown-date');
525
+				} else {
526
+					// ok it checks out
527
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
528
+				}
529
+			}
530
+			$espresso_db_update = $corrected_db_update;
531
+			update_option('espresso_db_update', $espresso_db_update);
532
+		}
533
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
+		return $espresso_db_update;
535
+	}
536
+
537
+
538
+	/**
539
+	 * Does the traditional work of setting up the plugin's database and adding default data.
540
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
541
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
542
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
543
+	 * so that it will be done when migrations are finished
544
+	 *
545
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
546
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
547
+	 *                                       This is a resource-intensive job
548
+	 *                                       so we prefer to only do it when necessary
549
+	 * @return void
550
+	 * @throws EE_Error
551
+	 */
552
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
553
+	{
554
+		$request_type = $this->detect_req_type();
555
+		// only initialize system if we're not in maintenance mode.
556
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
557
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
558
+			$rewrite_rules = $this->loader->getShared(
559
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
560
+			);
561
+			$rewrite_rules->flush();
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+	/**
586
+	 * Initializes the db for all registered addons
587
+	 *
588
+	 * @throws EE_Error
589
+	 */
590
+	public function initialize_addons()
591
+	{
592
+		// foreach registered addon, make sure its db is up-to-date too
593
+		foreach ($this->registry->addons as $addon) {
594
+			if ($addon instanceof EE_Addon) {
595
+				$addon->initialize_db_if_no_migrations_required();
596
+			}
597
+		}
598
+	}
599
+
600
+
601
+	/**
602
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
603
+	 *
604
+	 * @param    array  $version_history
605
+	 * @param    string $current_version_to_add version to be added to the version history
606
+	 * @return    boolean success as to whether or not this option was changed
607
+	 */
608
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
609
+	{
610
+		if (! $version_history) {
611
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
612
+		}
613
+		if ($current_version_to_add === null) {
614
+			$current_version_to_add = espresso_version();
615
+		}
616
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
617
+		// re-save
618
+		return update_option('espresso_db_update', $version_history);
619
+	}
620
+
621
+
622
+	/**
623
+	 * Detects if the current version indicated in the has existed in the list of
624
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
+	 *
626
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
+	 *                                  If not supplied, fetches it from the options table.
628
+	 *                                  Also, caches its result so later parts of the code can also know whether
629
+	 *                                  there's been an update or not. This way we can add the current version to
630
+	 *                                  espresso_db_update, but still know if this is a new install or not
631
+	 * @return int one of the constants on EE_System::req_type_
632
+	 */
633
+	public function detect_req_type($espresso_db_update = null)
634
+	{
635
+		if ($this->_req_type === null) {
636
+			$espresso_db_update = ! empty($espresso_db_update)
637
+				? $espresso_db_update
638
+				: $this->fix_espresso_db_upgrade_option();
639
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
640
+				$espresso_db_update,
641
+				'ee_espresso_activation',
642
+				espresso_version()
643
+			);
644
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
645
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
646
+		}
647
+		return $this->_req_type;
648
+	}
649
+
650
+
651
+	/**
652
+	 * Returns whether or not there was a non-micro version change (ie, change in either
653
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
654
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
655
+	 *
656
+	 * @param $activation_history
657
+	 * @return bool
658
+	 */
659
+	private function _detect_major_version_change($activation_history)
660
+	{
661
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
662
+		$previous_version_parts = explode('.', $previous_version);
663
+		$current_version_parts = explode('.', espresso_version());
664
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
665
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
666
+				   || $previous_version_parts[1] !== $current_version_parts[1]
667
+			   );
668
+	}
669
+
670
+
671
+	/**
672
+	 * Returns true if either the major or minor version of EE changed during this request.
673
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
+	 *
675
+	 * @return bool
676
+	 */
677
+	public function is_major_version_change()
678
+	{
679
+		return $this->_major_version_change;
680
+	}
681
+
682
+
683
+	/**
684
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
685
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
686
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
687
+	 * just activated to (for core that will always be espresso_version())
688
+	 *
689
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
690
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
691
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
692
+	 *                                                 indicate that this plugin was just activated
693
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
694
+	 *                                                 espresso_version())
695
+	 * @return int one of the constants on EE_System::req_type_*
696
+	 */
697
+	public static function detect_req_type_given_activation_history(
698
+		$activation_history_for_addon,
699
+		$activation_indicator_option_name,
700
+		$version_to_upgrade_to
701
+	) {
702
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
703
+		if ($activation_history_for_addon) {
704
+			// it exists, so this isn't a completely new install
705
+			// check if this version already in that list of previously installed versions
706
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
707
+				// it a version we haven't seen before
708
+				if ($version_is_higher === 1) {
709
+					$req_type = EE_System::req_type_upgrade;
710
+				} else {
711
+					$req_type = EE_System::req_type_downgrade;
712
+				}
713
+				delete_option($activation_indicator_option_name);
714
+			} else {
715
+				// its not an update. maybe a reactivation?
716
+				if (get_option($activation_indicator_option_name, false)) {
717
+					if ($version_is_higher === -1) {
718
+						$req_type = EE_System::req_type_downgrade;
719
+					} elseif ($version_is_higher === 0) {
720
+						// we've seen this version before, but it's an activation. must be a reactivation
721
+						$req_type = EE_System::req_type_reactivation;
722
+					} else {// $version_is_higher === 1
723
+						$req_type = EE_System::req_type_upgrade;
724
+					}
725
+					delete_option($activation_indicator_option_name);
726
+				} else {
727
+					// we've seen this version before and the activation indicate doesn't show it was just activated
728
+					if ($version_is_higher === -1) {
729
+						$req_type = EE_System::req_type_downgrade;
730
+					} elseif ($version_is_higher === 0) {
731
+						// we've seen this version before and it's not an activation. its normal request
732
+						$req_type = EE_System::req_type_normal;
733
+					} else {// $version_is_higher === 1
734
+						$req_type = EE_System::req_type_upgrade;
735
+					}
736
+				}
737
+			}
738
+		} else {
739
+			// brand new install
740
+			$req_type = EE_System::req_type_new_activation;
741
+			delete_option($activation_indicator_option_name);
742
+		}
743
+		return $req_type;
744
+	}
745
+
746
+
747
+	/**
748
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
749
+	 * the $activation_history_for_addon
750
+	 *
751
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
752
+	 *                                             sometimes containing 'unknown-date'
753
+	 * @param string $version_to_upgrade_to        (current version)
754
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
755
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
756
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
757
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
758
+	 */
759
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
760
+	{
761
+		// find the most recently-activated version
762
+		$most_recently_active_version =
763
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
764
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets the most recently active version listed in the activation history,
770
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
771
+	 *
772
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
773
+	 *                                   sometimes containing 'unknown-date'
774
+	 * @return string
775
+	 */
776
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
777
+	{
778
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
779
+		$most_recently_active_version = '0.0.0.dev.000';
780
+		if (is_array($activation_history)) {
781
+			foreach ($activation_history as $version => $times_activated) {
782
+				// check there is a record of when this version was activated. Otherwise,
783
+				// mark it as unknown
784
+				if (! $times_activated) {
785
+					$times_activated = array('unknown-date');
786
+				}
787
+				if (is_string($times_activated)) {
788
+					$times_activated = array($times_activated);
789
+				}
790
+				foreach ($times_activated as $an_activation) {
791
+					if ($an_activation !== 'unknown-date'
792
+						&& $an_activation
793
+						   > $most_recently_active_version_activation) {
794
+						$most_recently_active_version = $version;
795
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
796
+							? '1970-01-01 00:00:00'
797
+							: $an_activation;
798
+					}
799
+				}
800
+			}
801
+		}
802
+		return $most_recently_active_version;
803
+	}
804
+
805
+
806
+	/**
807
+	 * This redirects to the about EE page after activation
808
+	 *
809
+	 * @return void
810
+	 */
811
+	public function redirect_to_about_ee()
812
+	{
813
+		$notices = EE_Error::get_notices(false);
814
+		// if current user is an admin and it's not an ajax or rest request
815
+		if (! isset($notices['errors'])
816
+			&& $this->request->isAdmin()
817
+			&& apply_filters(
818
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
819
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
820
+			)
821
+		) {
822
+			$query_params = array('page' => 'espresso_about');
823
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
824
+				$query_params['new_activation'] = true;
825
+			}
826
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
827
+				$query_params['reactivation'] = true;
828
+			}
829
+			$url = add_query_arg($query_params, admin_url('admin.php'));
830
+			wp_safe_redirect($url);
831
+			exit();
832
+		}
833
+	}
834
+
835
+
836
+	/**
837
+	 * load_core_configuration
838
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
839
+	 * which runs during the WP 'plugins_loaded' action at priority 5
840
+	 *
841
+	 * @return void
842
+	 * @throws ReflectionException
843
+	 * @throws Exception
844
+	 */
845
+	public function load_core_configuration()
846
+	{
847
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
848
+		$this->loader->getShared('EE_Load_Textdomain');
849
+		// load textdomain
850
+		EE_Load_Textdomain::load_textdomain();
851
+		// load and setup EE_Config and EE_Network_Config
852
+		$config = $this->loader->getShared('EE_Config');
853
+		$this->loader->getShared('EE_Network_Config');
854
+		// setup autoloaders
855
+		// enable logging?
856
+		if ($config->admin->use_full_logging) {
857
+			$this->loader->getShared('EE_Log');
858
+		}
859
+		// check for activation errors
860
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
861
+		if ($activation_errors) {
862
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
863
+			update_option('ee_plugin_activation_errors', false);
864
+		}
865
+		// get model names
866
+		$this->_parse_model_names();
867
+		// load caf stuff a chance to play during the activation process too.
868
+		$this->_maybe_brew_regular();
869
+		// configure custom post type definitions
870
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
871
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
872
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
873
+	}
874
+
875
+
876
+	/**
877
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
878
+	 *
879
+	 * @return void
880
+	 * @throws ReflectionException
881
+	 */
882
+	private function _parse_model_names()
883
+	{
884
+		// get all the files in the EE_MODELS folder that end in .model.php
885
+		$models = glob(EE_MODELS . '*.model.php');
886
+		$model_names = array();
887
+		$non_abstract_db_models = array();
888
+		foreach ($models as $model) {
889
+			// get model classname
890
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
891
+			$short_name = str_replace('EEM_', '', $classname);
892
+			$reflectionClass = new ReflectionClass($classname);
893
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
894
+				$non_abstract_db_models[ $short_name ] = $classname;
895
+			}
896
+			$model_names[ $short_name ] = $classname;
897
+		}
898
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
899
+		$this->registry->non_abstract_db_models = apply_filters(
900
+			'FHEE__EE_System__parse_implemented_model_names',
901
+			$non_abstract_db_models
902
+		);
903
+	}
904
+
905
+
906
+	/**
907
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
908
+	 * that need to be setup before our EE_System launches.
909
+	 *
910
+	 * @return void
911
+	 * @throws DomainException
912
+	 * @throws InvalidArgumentException
913
+	 * @throws InvalidDataTypeException
914
+	 * @throws InvalidInterfaceException
915
+	 * @throws InvalidClassException
916
+	 * @throws InvalidFilePathException
917
+	 */
918
+	private function _maybe_brew_regular()
919
+	{
920
+		/** @var Domain $domain */
921
+		$domain = DomainFactory::getShared(
922
+			new FullyQualifiedName(
923
+				'EventEspresso\core\domain\Domain'
924
+			),
925
+			array(
926
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
927
+				Version::fromString(espresso_version()),
928
+			)
929
+		);
930
+		if ($domain->isCaffeinated()) {
931
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
932
+		}
933
+	}
934
+
935
+
936
+	/**
937
+	 * @since $VID:$
938
+	 * @throws Exception
939
+	 */
940
+	public function loadRouteMatchSpecifications()
941
+	{
942
+		try {
943
+			$this->loader->getShared(
944
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationManager'
945
+			);
946
+		} catch (Exception $exception) {
947
+			new ExceptionStackTraceDisplay($exception);
948
+		}
949
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
950
+	}
951
+
952
+
953
+	/**
954
+	 * register_shortcodes_modules_and_widgets
955
+	 * generate lists of shortcodes and modules, then verify paths and classes
956
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
957
+	 * which runs during the WP 'plugins_loaded' action at priority 7
958
+	 *
959
+	 * @access public
960
+	 * @return void
961
+	 * @throws Exception
962
+	 */
963
+	public function register_shortcodes_modules_and_widgets()
964
+	{
965
+		if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
966
+			try {
967
+				// load, register, and add shortcodes the new way
968
+				$this->loader->getShared(
969
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
970
+					array(
971
+						// and the old way, but we'll put it under control of the new system
972
+						EE_Config::getLegacyShortcodesManager(),
973
+					)
974
+				);
975
+			} catch (Exception $exception) {
976
+				new ExceptionStackTraceDisplay($exception);
977
+			}
978
+		}
979
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
980
+		// check for addons using old hook point
981
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
982
+			$this->_incompatible_addon_error();
983
+		}
984
+	}
985
+
986
+
987
+	/**
988
+	 * _incompatible_addon_error
989
+	 *
990
+	 * @access public
991
+	 * @return void
992
+	 */
993
+	private function _incompatible_addon_error()
994
+	{
995
+		// get array of classes hooking into here
996
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
997
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
998
+		);
999
+		if (! empty($class_names)) {
1000
+			$msg = __(
1001
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1002
+				'event_espresso'
1003
+			);
1004
+			$msg .= '<ul>';
1005
+			foreach ($class_names as $class_name) {
1006
+				$msg .= '<li><b>Event Espresso - '
1007
+						. str_replace(
1008
+							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1009
+							'',
1010
+							$class_name
1011
+						) . '</b></li>';
1012
+			}
1013
+			$msg .= '</ul>';
1014
+			$msg .= __(
1015
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1016
+				'event_espresso'
1017
+			);
1018
+			// save list of incompatible addons to wp-options for later use
1019
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1020
+			if (is_admin()) {
1021
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1022
+			}
1023
+		}
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * brew_espresso
1029
+	 * begins the process of setting hooks for initializing EE in the correct order
1030
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1031
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1032
+	 *
1033
+	 * @return void
1034
+	 */
1035
+	public function brew_espresso()
1036
+	{
1037
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1038
+		// load some final core systems
1039
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1040
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1041
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1042
+		add_action('init', array($this, 'load_controllers'), 7);
1043
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1044
+		add_action('init', array($this, 'initialize'), 10);
1045
+		add_action('init', array($this, 'initialize_last'), 100);
1046
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1047
+			// pew pew pew
1048
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1049
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1050
+		}
1051
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 *    set_hooks_for_core
1057
+	 *
1058
+	 * @access public
1059
+	 * @return    void
1060
+	 * @throws EE_Error
1061
+	 */
1062
+	public function set_hooks_for_core()
1063
+	{
1064
+		$this->_deactivate_incompatible_addons();
1065
+		do_action('AHEE__EE_System__set_hooks_for_core');
1066
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
+		// caps need to be initialized on every request so that capability maps are set.
1068
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
+		$this->registry->CAP->init_caps();
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1075
+	 * deactivates any addons considered incompatible with the current version of EE
1076
+	 */
1077
+	private function _deactivate_incompatible_addons()
1078
+	{
1079
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1080
+		if (! empty($incompatible_addons)) {
1081
+			$active_plugins = get_option('active_plugins', array());
1082
+			foreach ($active_plugins as $active_plugin) {
1083
+				foreach ($incompatible_addons as $incompatible_addon) {
1084
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1085
+						unset($_GET['activate']);
1086
+						espresso_deactivate_plugin($active_plugin);
1087
+					}
1088
+				}
1089
+			}
1090
+		}
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 *    perform_activations_upgrades_and_migrations
1096
+	 *
1097
+	 * @access public
1098
+	 * @return    void
1099
+	 */
1100
+	public function perform_activations_upgrades_and_migrations()
1101
+	{
1102
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * @return void
1108
+	 * @throws DomainException
1109
+	 */
1110
+	public function load_CPTs_and_session()
1111
+	{
1112
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1113
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1114
+		$register_custom_taxonomies = $this->loader->getShared(
1115
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1116
+		);
1117
+		$register_custom_taxonomies->registerCustomTaxonomies();
1118
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1119
+		$register_custom_post_types = $this->loader->getShared(
1120
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1121
+		);
1122
+		$register_custom_post_types->registerCustomPostTypes();
1123
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1124
+		$register_custom_taxonomy_terms = $this->loader->getShared(
1125
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1126
+		);
1127
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1128
+		// load legacy Custom Post Types and Taxonomies
1129
+		$this->loader->getShared('EE_Register_CPTs');
1130
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * load_controllers
1136
+	 * this is the best place to load any additional controllers that needs access to EE core.
1137
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1138
+	 * time
1139
+	 *
1140
+	 * @access public
1141
+	 * @return void
1142
+	 */
1143
+	public function load_controllers()
1144
+	{
1145
+		do_action('AHEE__EE_System__load_controllers__start');
1146
+		// let's get it started
1147
+		if (! $this->maintenance_mode->level()
1148
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1149
+		) {
1150
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1151
+			$this->loader->getShared('EE_Front_Controller');
1152
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1153
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1154
+			$this->loader->getShared('EE_Admin');
1155
+		}
1156
+		do_action('AHEE__EE_System__load_controllers__complete');
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * core_loaded_and_ready
1162
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1163
+	 *
1164
+	 * @access public
1165
+	 * @return void
1166
+	 * @throws Exception
1167
+	 */
1168
+	public function core_loaded_and_ready()
1169
+	{
1170
+		if ($this->request->isAdmin()
1171
+			|| $this->request->isFrontend()
1172
+			|| $this->request->isIframe()
1173
+			|| $this->request->isWordPressApi()
1174
+		) {
1175
+			try {
1176
+				$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1177
+				$this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1178
+				if (function_exists('register_block_type')) {
1179
+					$this->loader->getShared(
1180
+						'EventEspresso\core\services\editor\BlockRegistrationManager'
1181
+					);
1182
+				}
1183
+			} catch (Exception $exception) {
1184
+				new ExceptionStackTraceDisplay($exception);
1185
+			}
1186
+		}
1187
+		if ($this->request->isAdmin()
1188
+			|| $this->request->isEeAjax()
1189
+			|| $this->request->isFrontend()
1190
+		) {
1191
+			$this->loader->getShared('EE_Session');
1192
+		}
1193
+		// integrate WP_Query with the EE models
1194
+		$this->loader->getShared('EE_CPT_Strategy');
1195
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1196
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1197
+		// builders require these even on the front-end
1198
+		require_once EE_PUBLIC . 'template_tags.php';
1199
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * initialize
1205
+	 * this is the best place to begin initializing client code
1206
+	 *
1207
+	 * @access public
1208
+	 * @return void
1209
+	 */
1210
+	public function initialize()
1211
+	{
1212
+		do_action('AHEE__EE_System__initialize');
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * initialize_last
1218
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1219
+	 * initialize has done so
1220
+	 *
1221
+	 * @access public
1222
+	 * @return void
1223
+	 */
1224
+	public function initialize_last()
1225
+	{
1226
+		do_action('AHEE__EE_System__initialize_last');
1227
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1228
+		$rewrite_rules = $this->loader->getShared(
1229
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1230
+		);
1231
+		$rewrite_rules->flushRewriteRules();
1232
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1233
+		if (($this->request->isAjax() || $this->request->isAdmin())
1234
+			&& $this->maintenance_mode->models_can_query()) {
1235
+			$this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1236
+			$this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1237
+		}
1238
+	}
1239
+
1240
+
1241
+	/**
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function addEspressoToolbar()
1246
+	{
1247
+		$this->loader->getShared(
1248
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1249
+			array($this->registry->CAP)
1250
+		);
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 * do_not_cache
1256
+	 * sets no cache headers and defines no cache constants for WP plugins
1257
+	 *
1258
+	 * @access public
1259
+	 * @return void
1260
+	 */
1261
+	public static function do_not_cache()
1262
+	{
1263
+		// set no cache constants
1264
+		if (! defined('DONOTCACHEPAGE')) {
1265
+			define('DONOTCACHEPAGE', true);
1266
+		}
1267
+		if (! defined('DONOTCACHCEOBJECT')) {
1268
+			define('DONOTCACHCEOBJECT', true);
1269
+		}
1270
+		if (! defined('DONOTCACHEDB')) {
1271
+			define('DONOTCACHEDB', true);
1272
+		}
1273
+		// add no cache headers
1274
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1275
+		// plus a little extra for nginx and Google Chrome
1276
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1277
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1278
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 *    extra_nocache_headers
1284
+	 *
1285
+	 * @access    public
1286
+	 * @param $headers
1287
+	 * @return    array
1288
+	 */
1289
+	public static function extra_nocache_headers($headers)
1290
+	{
1291
+		// for NGINX
1292
+		$headers['X-Accel-Expires'] = 0;
1293
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1294
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1295
+		return $headers;
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 *    nocache_headers
1301
+	 *
1302
+	 * @access    public
1303
+	 * @return    void
1304
+	 */
1305
+	public static function nocache_headers()
1306
+	{
1307
+		nocache_headers();
1308
+	}
1309
+
1310
+
1311
+	/**
1312
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1313
+	 * never returned with the function.
1314
+	 *
1315
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1316
+	 * @return array
1317
+	 */
1318
+	public function remove_pages_from_wp_list_pages($exclude_array)
1319
+	{
1320
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1321
+	}
1322 1322
 }
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 1 patch
Indentation   +2484 added lines, -2484 removed lines patch added patch discarded remove patch
@@ -14,2488 +14,2488 @@
 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
-        );
437
-        if (/**
438
-             * Filters whether a link to the "Failed Transactions" list table
439
-             * appears on the Transactions Admin Page list table.
440
-             * List display can be turned back on via the following:
441
-             * add_filter(
442
-             *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
443
-             *     '__return_true'
444
-             * );
445
-             *
446
-             * @since $VID:$
447
-             * @param boolean                 $display_failed_txns_list
448
-             * @param Transactions_Admin_Page $this
449
-             */
450
-            apply_filters(
451
-                'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
452
-                false,
453
-                $this
454
-            )
455
-        ) {
456
-            $this->_views['failed'] = array(
457
-                'slug'  => 'failed',
458
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
459
-                'count' => 0,
460
-            );
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     * _set_transaction_object
467
-     * This sets the _transaction property for the transaction details screen
468
-     *
469
-     * @access private
470
-     * @return void
471
-     * @throws EE_Error
472
-     * @throws InvalidArgumentException
473
-     * @throws RuntimeException
474
-     * @throws InvalidDataTypeException
475
-     * @throws InvalidInterfaceException
476
-     * @throws ReflectionException
477
-     */
478
-    private function _set_transaction_object()
479
-    {
480
-        if ($this->_transaction instanceof EE_Transaction) {
481
-            return;
482
-        } //get out we've already set the object
483
-
484
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
485
-            ? absint($this->_req_data['TXN_ID'])
486
-            : false;
487
-
488
-        // get transaction object
489
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
490
-        $this->_session = $this->_transaction instanceof EE_Transaction
491
-            ? $this->_transaction->get('TXN_session_data')
492
-            : null;
493
-        if ($this->_transaction instanceof EE_Transaction) {
494
-            $this->_transaction->verify_abandoned_transaction_status();
495
-        }
496
-
497
-        if (! $this->_transaction instanceof EE_Transaction) {
498
-            $error_msg = sprintf(
499
-                esc_html__(
500
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
501
-                    'event_espresso'
502
-                ),
503
-                $TXN_ID
504
-            );
505
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
506
-        }
507
-    }
508
-
509
-
510
-    /**
511
-     *    _transaction_legend_items
512
-     *
513
-     * @access protected
514
-     * @return array
515
-     * @throws EE_Error
516
-     * @throws InvalidArgumentException
517
-     * @throws ReflectionException
518
-     * @throws InvalidDataTypeException
519
-     * @throws InvalidInterfaceException
520
-     */
521
-    protected function _transaction_legend_items()
522
-    {
523
-        EE_Registry::instance()->load_helper('MSG_Template');
524
-        $items = array();
525
-
526
-        if (EE_Registry::instance()->CAP->current_user_can(
527
-            'ee_read_global_messages',
528
-            'view_filtered_messages'
529
-        )) {
530
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
531
-            if (is_array($related_for_icon)
532
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
533
-            ) {
534
-                $items['view_related_messages'] = array(
535
-                    'class' => $related_for_icon['css_class'],
536
-                    'desc'  => $related_for_icon['label'],
537
-                );
538
-            }
539
-        }
540
-
541
-        $items = apply_filters(
542
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
543
-            array_merge(
544
-                $items,
545
-                array(
546
-                    'view_details'          => array(
547
-                        'class' => 'dashicons dashicons-cart',
548
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
549
-                    ),
550
-                    'view_invoice'          => array(
551
-                        'class' => 'dashicons dashicons-media-spreadsheet',
552
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
553
-                    ),
554
-                    'view_receipt'          => array(
555
-                        'class' => 'dashicons dashicons-media-default',
556
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
557
-                    ),
558
-                    'view_registration'     => array(
559
-                        'class' => 'dashicons dashicons-clipboard',
560
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
561
-                    ),
562
-                    'payment_overview_link' => array(
563
-                        'class' => 'dashicons dashicons-money',
564
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
565
-                    ),
566
-                )
567
-            )
568
-        );
569
-
570
-        if (EE_Registry::instance()->CAP->current_user_can(
571
-            'ee_send_message',
572
-            'espresso_transactions_send_payment_reminder'
573
-        )) {
574
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
575
-                $items['send_payment_reminder'] = array(
576
-                    'class' => 'dashicons dashicons-email-alt',
577
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
578
-                );
579
-            } else {
580
-                $items['blank*'] = array(
581
-                    'class' => '',
582
-                    'desc'  => '',
583
-                );
584
-            }
585
-        } else {
586
-            $items['blank*'] = array(
587
-                'class' => '',
588
-                'desc'  => '',
589
-            );
590
-        }
591
-        $more_items = apply_filters(
592
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
593
-            array(
594
-                'overpaid'   => array(
595
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
596
-                    'desc'  => EEH_Template::pretty_status(
597
-                        EEM_Transaction::overpaid_status_code,
598
-                        false,
599
-                        'sentence'
600
-                    ),
601
-                ),
602
-                'complete'   => array(
603
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
604
-                    'desc'  => EEH_Template::pretty_status(
605
-                        EEM_Transaction::complete_status_code,
606
-                        false,
607
-                        'sentence'
608
-                    ),
609
-                ),
610
-                'incomplete' => array(
611
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
612
-                    'desc'  => EEH_Template::pretty_status(
613
-                        EEM_Transaction::incomplete_status_code,
614
-                        false,
615
-                        'sentence'
616
-                    ),
617
-                ),
618
-                'abandoned'  => array(
619
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
620
-                    'desc'  => EEH_Template::pretty_status(
621
-                        EEM_Transaction::abandoned_status_code,
622
-                        false,
623
-                        'sentence'
624
-                    ),
625
-                ),
626
-                'failed'     => array(
627
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
628
-                    'desc'  => EEH_Template::pretty_status(
629
-                        EEM_Transaction::failed_status_code,
630
-                        false,
631
-                        'sentence'
632
-                    ),
633
-                ),
634
-            )
635
-        );
636
-
637
-        return array_merge($items, $more_items);
638
-    }
639
-
640
-
641
-    /**
642
-     *    _transactions_overview_list_table
643
-     *
644
-     * @access protected
645
-     * @return void
646
-     * @throws DomainException
647
-     * @throws EE_Error
648
-     * @throws InvalidArgumentException
649
-     * @throws InvalidDataTypeException
650
-     * @throws InvalidInterfaceException
651
-     * @throws ReflectionException
652
-     */
653
-    protected function _transactions_overview_list_table()
654
-    {
655
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
656
-        $event = isset($this->_req_data['EVT_ID'])
657
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
658
-            : null;
659
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
660
-            ? sprintf(
661
-                esc_html__(
662
-                    '%sViewing Transactions for the Event: %s%s',
663
-                    'event_espresso'
664
-                ),
665
-                '<h3>',
666
-                '<a href="'
667
-                . EE_Admin_Page::add_query_args_and_nonce(
668
-                    array('action' => 'edit', 'post' => $event->ID()),
669
-                    EVENTS_ADMIN_URL
670
-                )
671
-                . '" title="'
672
-                . esc_attr__(
673
-                    'Click to Edit event',
674
-                    'event_espresso'
675
-                )
676
-                . '">' . $event->get('EVT_name') . '</a>',
677
-                '</h3>'
678
-            )
679
-            : '';
680
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
681
-        $this->display_admin_list_table_page_with_no_sidebar();
682
-    }
683
-
684
-
685
-    /**
686
-     *    _transaction_details
687
-     * generates HTML for the View Transaction Details Admin page
688
-     *
689
-     * @access protected
690
-     * @return void
691
-     * @throws DomainException
692
-     * @throws EE_Error
693
-     * @throws InvalidArgumentException
694
-     * @throws InvalidDataTypeException
695
-     * @throws InvalidInterfaceException
696
-     * @throws RuntimeException
697
-     * @throws ReflectionException
698
-     */
699
-    protected function _transaction_details()
700
-    {
701
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
702
-
703
-        $this->_set_transaction_status_array();
704
-
705
-        $this->_template_args = array();
706
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
707
-
708
-        $this->_set_transaction_object();
709
-
710
-        if (! $this->_transaction instanceof EE_Transaction) {
711
-            return;
712
-        }
713
-        $primary_registration = $this->_transaction->primary_registration();
714
-        $attendee = $primary_registration instanceof EE_Registration
715
-            ? $primary_registration->attendee()
716
-            : null;
717
-
718
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
719
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
720
-
721
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
722
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
723
-
724
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ];
725
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
726
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
727
-
728
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
729
-        $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
730
-
731
-        $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
732
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
733
-            $amount_due,
734
-            true
735
-        );
736
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
737
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
738
-                                                  . $this->_template_args['amount_due'];
739
-        } else {
740
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
741
-        }
742
-        $this->_template_args['amount_due_class'] = '';
743
-
744
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
745
-            // paid in full
746
-            $this->_template_args['amount_due'] = false;
747
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
748
-            // overpaid
749
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
750
-        } elseif ($this->_transaction->get('TXN_total') > 0
751
-                  && $this->_transaction->get('TXN_paid') > 0
752
-        ) {
753
-            // monies owing
754
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
755
-        } elseif ($this->_transaction->get('TXN_total') > 0
756
-                  && $this->_transaction->get('TXN_paid') == 0
757
-        ) {
758
-            // no payments made yet
759
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
760
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
761
-            // free event
762
-            $this->_template_args['amount_due'] = false;
763
-        }
764
-
765
-        $payment_method = $this->_transaction->payment_method();
766
-
767
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
768
-            ? $payment_method->admin_name()
769
-            : esc_html__('Unknown', 'event_espresso');
770
-
771
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
772
-        // link back to overview
773
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
774
-            ? $_SERVER['HTTP_REFERER']
775
-            : TXN_ADMIN_URL;
776
-
777
-
778
-        // next link
779
-        $next_txn = $this->_transaction->next(
780
-            null,
781
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
782
-            'TXN_ID'
783
-        );
784
-        $this->_template_args['next_transaction'] = $next_txn
785
-            ? $this->_next_link(
786
-                EE_Admin_Page::add_query_args_and_nonce(
787
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
788
-                    TXN_ADMIN_URL
789
-                ),
790
-                'dashicons dashicons-arrow-right ee-icon-size-22'
791
-            )
792
-            : '';
793
-        // previous link
794
-        $previous_txn = $this->_transaction->previous(
795
-            null,
796
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
797
-            'TXN_ID'
798
-        );
799
-        $this->_template_args['previous_transaction'] = $previous_txn
800
-            ? $this->_previous_link(
801
-                EE_Admin_Page::add_query_args_and_nonce(
802
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
803
-                    TXN_ADMIN_URL
804
-                ),
805
-                'dashicons dashicons-arrow-left ee-icon-size-22'
806
-            )
807
-            : '';
808
-
809
-        // were we just redirected here after adding a new registration ???
810
-        if (isset(
811
-            $this->_req_data['redirect_from'],
812
-            $this->_req_data['EVT_ID'],
813
-            $this->_req_data['event_name']
814
-        )) {
815
-            if (EE_Registry::instance()->CAP->current_user_can(
816
-                'ee_edit_registrations',
817
-                'espresso_registrations_new_registration',
818
-                $this->_req_data['EVT_ID']
819
-            )) {
820
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
821
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
822
-                    array(
823
-                        'page'     => 'espresso_registrations',
824
-                        'action'   => 'new_registration',
825
-                        'return'   => 'default',
826
-                        'TXN_ID'   => $this->_transaction->ID(),
827
-                        'event_id' => $this->_req_data['EVT_ID'],
828
-                    ),
829
-                    REG_ADMIN_URL
830
-                );
831
-                $this->_admin_page_title .= '">';
832
-
833
-                $this->_admin_page_title .= sprintf(
834
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
835
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
836
-                );
837
-                $this->_admin_page_title .= '</a>';
838
-            }
839
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
840
-        }
841
-        // grab messages at the last second
842
-        $this->_template_args['notices'] = EE_Error::get_notices();
843
-        // path to template
844
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
845
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
846
-            $template_path,
847
-            $this->_template_args,
848
-            true
849
-        );
850
-
851
-        // the details template wrapper
852
-        $this->display_admin_page_with_sidebar();
853
-    }
854
-
855
-
856
-    /**
857
-     *        _transaction_details_metaboxes
858
-     *
859
-     * @access protected
860
-     * @return void
861
-     * @throws EE_Error
862
-     * @throws InvalidArgumentException
863
-     * @throws InvalidDataTypeException
864
-     * @throws InvalidInterfaceException
865
-     * @throws RuntimeException
866
-     * @throws ReflectionException
867
-     */
868
-    protected function _transaction_details_metaboxes()
869
-    {
870
-
871
-        $this->_set_transaction_object();
872
-
873
-        if (! $this->_transaction instanceof EE_Transaction) {
874
-            return;
875
-        }
876
-        add_meta_box(
877
-            'edit-txn-details-mbox',
878
-            esc_html__('Transaction Details', 'event_espresso'),
879
-            array($this, 'txn_details_meta_box'),
880
-            $this->_wp_page_slug,
881
-            'normal',
882
-            'high'
883
-        );
884
-        add_meta_box(
885
-            'edit-txn-attendees-mbox',
886
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
887
-            array($this, 'txn_attendees_meta_box'),
888
-            $this->_wp_page_slug,
889
-            'normal',
890
-            'high',
891
-            array('TXN_ID' => $this->_transaction->ID())
892
-        );
893
-        add_meta_box(
894
-            'edit-txn-registrant-mbox',
895
-            esc_html__('Primary Contact', 'event_espresso'),
896
-            array($this, 'txn_registrant_side_meta_box'),
897
-            $this->_wp_page_slug,
898
-            'side',
899
-            'high'
900
-        );
901
-        add_meta_box(
902
-            'edit-txn-billing-info-mbox',
903
-            esc_html__('Billing Information', 'event_espresso'),
904
-            array($this, 'txn_billing_info_side_meta_box'),
905
-            $this->_wp_page_slug,
906
-            'side',
907
-            'high'
908
-        );
909
-    }
910
-
911
-
912
-    /**
913
-     * Callback for transaction actions metabox.
914
-     *
915
-     * @param EE_Transaction|null $transaction
916
-     * @throws DomainException
917
-     * @throws EE_Error
918
-     * @throws InvalidArgumentException
919
-     * @throws InvalidDataTypeException
920
-     * @throws InvalidInterfaceException
921
-     * @throws ReflectionException
922
-     * @throws RuntimeException
923
-     */
924
-    public function getActionButtons(EE_Transaction $transaction = null)
925
-    {
926
-        $content = '';
927
-        $actions = array();
928
-        if (! $transaction instanceof EE_Transaction) {
929
-            return $content;
930
-        }
931
-        /** @var EE_Registration $primary_registration */
932
-        $primary_registration = $transaction->primary_registration();
933
-        $attendee = $primary_registration instanceof EE_Registration
934
-            ? $primary_registration->attendee()
935
-            : null;
936
-
937
-        if ($attendee instanceof EE_Attendee
938
-            && EE_Registry::instance()->CAP->current_user_can(
939
-                'ee_send_message',
940
-                'espresso_transactions_send_payment_reminder'
941
-            )
942
-        ) {
943
-            $actions['payment_reminder'] =
944
-                EEH_MSG_Template::is_mt_active('payment_reminder')
945
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
946
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
947
-                    ? EEH_Template::get_button_or_link(
948
-                        EE_Admin_Page::add_query_args_and_nonce(
949
-                            array(
950
-                                'action'      => 'send_payment_reminder',
951
-                                'TXN_ID'      => $this->_transaction->ID(),
952
-                                'redirect_to' => 'view_transaction',
953
-                            ),
954
-                            TXN_ADMIN_URL
955
-                        ),
956
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
957
-                        'button secondary-button',
958
-                        'dashicons dashicons-email-alt'
959
-                    )
960
-                    : '';
961
-        }
962
-
963
-        if ($primary_registration instanceof EE_Registration
964
-            && EEH_MSG_Template::is_mt_active('receipt')
965
-        ) {
966
-            $actions['receipt'] = EEH_Template::get_button_or_link(
967
-                $primary_registration->receipt_url(),
968
-                esc_html__('View Receipt', 'event_espresso'),
969
-                'button secondary-button',
970
-                'dashicons dashicons-media-default'
971
-            );
972
-        }
973
-
974
-        if ($primary_registration instanceof EE_Registration
975
-            && EEH_MSG_Template::is_mt_active('invoice')
976
-        ) {
977
-            $actions['invoice'] = EEH_Template::get_button_or_link(
978
-                $primary_registration->invoice_url(),
979
-                esc_html__('View Invoice', 'event_espresso'),
980
-                'button secondary-button',
981
-                'dashicons dashicons-media-spreadsheet'
982
-            );
983
-        }
984
-        $actions = array_filter(
985
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
986
-        );
987
-        if ($actions) {
988
-            $content = '<ul>';
989
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
990
-            $content .= '</uL>';
991
-        }
992
-        return $content;
993
-    }
994
-
995
-
996
-    /**
997
-     * txn_details_meta_box
998
-     * generates HTML for the Transaction main meta box
999
-     *
1000
-     * @return void
1001
-     * @throws DomainException
1002
-     * @throws EE_Error
1003
-     * @throws InvalidArgumentException
1004
-     * @throws InvalidDataTypeException
1005
-     * @throws InvalidInterfaceException
1006
-     * @throws RuntimeException
1007
-     * @throws ReflectionException
1008
-     */
1009
-    public function txn_details_meta_box()
1010
-    {
1011
-        $this->_set_transaction_object();
1012
-        $this->_template_args['TXN_ID'] = $this->_transaction->ID();
1013
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1014
-            ? $this->_transaction->primary_registration()->attendee()
1015
-            : null;
1016
-        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1017
-            'ee_edit_payments',
1018
-            'apply_payment_or_refund_from_registration_details'
1019
-        );
1020
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1021
-            'ee_delete_payments',
1022
-            'delete_payment_from_registration_details'
1023
-        );
1024
-
1025
-        // get line table
1026
-        EEH_Autoloader::register_line_item_display_autoloaders();
1027
-        $Line_Item_Display = new EE_Line_Item_Display(
1028
-            'admin_table',
1029
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1030
-        );
1031
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1032
-            $this->_transaction->total_line_item()
1033
-        );
1034
-        $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')
1035
-                                                               ->get('REG_code');
1036
-
1037
-        // process taxes
1038
-        $taxes = $this->_transaction->get_many_related(
1039
-            'Line_Item',
1040
-            array(array('LIN_type' => EEM_Line_Item::type_tax))
1041
-        );
1042
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
-
1044
-        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1045
-            $this->_transaction->get('TXN_total'),
1046
-            false,
1047
-            false
1048
-        );
1049
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1050
-        $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID');
1051
-
1052
-        // process payment details
1053
-        $payments = $this->_transaction->get_many_related('Payment');
1054
-        if (! empty($payments)) {
1055
-            $this->_template_args['payments'] = $payments;
1056
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1057
-        } else {
1058
-            $this->_template_args['payments'] = false;
1059
-            $this->_template_args['existing_reg_payments'] = array();
1060
-        }
1061
-
1062
-        $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1063
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1064
-            array('action' => 'espresso_delete_payment'),
1065
-            TXN_ADMIN_URL
1066
-        );
1067
-
1068
-        if (isset($txn_details['invoice_number'])) {
1069
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1070
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1071
-                'Invoice Number',
1072
-                'event_espresso'
1073
-            );
1074
-        }
1075
-
1076
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1077
-            ->get_first_related('Registration')
1078
-            ->get('REG_session');
1079
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1080
-            'Registration Session',
1081
-            'event_espresso'
1082
-        );
1083
-
1084
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1085
-            ? $this->_session['ip_address']
1086
-            : '';
1087
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1088
-            'Transaction placed from IP',
1089
-            'event_espresso'
1090
-        );
1091
-
1092
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1093
-            ? $this->_session['user_agent']
1094
-            : '';
1095
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1096
-            'Registrant User Agent',
1097
-            'event_espresso'
1098
-        );
1099
-
1100
-        $reg_steps = '<ul>';
1101
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1102
-            if ($reg_step_status === true) {
1103
-                $reg_steps .= '<li style="color:#70cc50">'
1104
-                              . sprintf(
1105
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1106
-                                  ucwords(str_replace('_', ' ', $reg_step))
1107
-                              )
1108
-                              . '</li>';
1109
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1110
-                $reg_steps .= '<li style="color:#2EA2CC">'
1111
-                              . sprintf(
1112
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1113
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1114
-                                  date(
1115
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1116
-                                      ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1117
-                                  )
1118
-                              )
1119
-                              . '</li>';
1120
-            } else {
1121
-                $reg_steps .= '<li style="color:#E76700">'
1122
-                              . sprintf(
1123
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1124
-                                  ucwords(str_replace('_', ' ', $reg_step))
1125
-                              )
1126
-                              . '</li>';
1127
-            }
1128
-        }
1129
-        $reg_steps .= '</ul>';
1130
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1131
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1132
-            'Registration Step Progress',
1133
-            'event_espresso'
1134
-        );
1135
-
1136
-
1137
-        $this->_get_registrations_to_apply_payment_to();
1138
-        $this->_get_payment_methods($payments);
1139
-        $this->_get_payment_status_array();
1140
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1141
-
1142
-        $this->_template_args['transaction_form_url'] = add_query_arg(
1143
-            array(
1144
-                'action'  => 'edit_transaction',
1145
-                'process' => 'transaction',
1146
-            ),
1147
-            TXN_ADMIN_URL
1148
-        );
1149
-        $this->_template_args['apply_payment_form_url'] = add_query_arg(
1150
-            array(
1151
-                'page'   => 'espresso_transactions',
1152
-                'action' => 'espresso_apply_payment',
1153
-            ),
1154
-            WP_AJAX_URL
1155
-        );
1156
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1157
-            array(
1158
-                'page'   => 'espresso_transactions',
1159
-                'action' => 'espresso_delete_payment',
1160
-            ),
1161
-            WP_AJAX_URL
1162
-        );
1163
-
1164
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1165
-
1166
-        // 'espresso_delete_payment_nonce'
1167
-
1168
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1169
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1170
-    }
1171
-
1172
-
1173
-    /**
1174
-     * _get_registration_payment_IDs
1175
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1176
-     *
1177
-     * @access protected
1178
-     * @param EE_Payment[] $payments
1179
-     * @return array
1180
-     * @throws EE_Error
1181
-     * @throws InvalidArgumentException
1182
-     * @throws InvalidDataTypeException
1183
-     * @throws InvalidInterfaceException
1184
-     * @throws ReflectionException
1185
-     */
1186
-    protected function _get_registration_payment_IDs($payments = array())
1187
-    {
1188
-        $existing_reg_payments = array();
1189
-        // get all reg payments for these payments
1190
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1191
-            array(
1192
-                array(
1193
-                    'PAY_ID' => array(
1194
-                        'IN',
1195
-                        array_keys($payments),
1196
-                    ),
1197
-                ),
1198
-            )
1199
-        );
1200
-        if (! empty($reg_payments)) {
1201
-            foreach ($payments as $payment) {
1202
-                if (! $payment instanceof EE_Payment) {
1203
-                    continue;
1204
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1205
-                    $existing_reg_payments[ $payment->ID() ] = array();
1206
-                }
1207
-                foreach ($reg_payments as $reg_payment) {
1208
-                    if ($reg_payment instanceof EE_Registration_Payment
1209
-                        && $reg_payment->payment_ID() === $payment->ID()
1210
-                    ) {
1211
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1212
-                    }
1213
-                }
1214
-            }
1215
-        }
1216
-
1217
-        return $existing_reg_payments;
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * _get_registrations_to_apply_payment_to
1223
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1224
-     * which allows the admin to only apply the payment to the specific registrations
1225
-     *
1226
-     * @access protected
1227
-     * @return void
1228
-     * @throws \EE_Error
1229
-     */
1230
-    protected function _get_registrations_to_apply_payment_to()
1231
-    {
1232
-        // we want any registration with an active status (ie: not deleted or cancelled)
1233
-        $query_params = array(
1234
-            array(
1235
-                'STS_ID' => array(
1236
-                    'IN',
1237
-                    array(
1238
-                        EEM_Registration::status_id_approved,
1239
-                        EEM_Registration::status_id_pending_payment,
1240
-                        EEM_Registration::status_id_not_approved,
1241
-                    ),
1242
-                ),
1243
-            ),
1244
-        );
1245
-        $registrations_to_apply_payment_to = EEH_HTML::br()
1246
-                                             . EEH_HTML::div(
1247
-                                                 '',
1248
-                                                 'txn-admin-apply-payment-to-registrations-dv',
1249
-                                                 '',
1250
-                                                 'clear: both; margin: 1.5em 0 0; display: none;'
1251
-                                             );
1252
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1253
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1254
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1255
-            EEH_HTML::tr(
1256
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1257
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1258
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1259
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1260
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1261
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1262
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1263
-            )
1264
-        );
1265
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1266
-        // get registrations for TXN
1267
-        $registrations = $this->_transaction->registrations($query_params);
1268
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1269
-        foreach ($registrations as $registration) {
1270
-            if ($registration instanceof EE_Registration) {
1271
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
1272
-                    ? $registration->attendee()->full_name()
1273
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1274
-                $owing = $registration->final_price() - $registration->paid();
1275
-                $taxable = $registration->ticket()->taxable()
1276
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1277
-                    : '';
1278
-                $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1279
-                    ? ' checked="checked"'
1280
-                    : '';
1281
-                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1282
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1283
-                    EEH_HTML::td($registration->ID()) .
1284
-                    EEH_HTML::td($attendee_name) .
1285
-                    EEH_HTML::td(
1286
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1287
-                    ) .
1288
-                    EEH_HTML::td($registration->event_name()) .
1289
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1290
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1291
-                    EEH_HTML::td(
1292
-                        '<input type="checkbox" value="' . $registration->ID()
1293
-                        . '" name="txn_admin_payment[registrations]"'
1294
-                        . $checked . $disabled . '>',
1295
-                        '',
1296
-                        'jst-cntr'
1297
-                    ),
1298
-                    'apply-payment-registration-row-' . $registration->ID()
1299
-                );
1300
-            }
1301
-        }
1302
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1303
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1304
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1305
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1306
-            esc_html__(
1307
-                '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.',
1308
-                'event_espresso'
1309
-            ),
1310
-            '',
1311
-            'clear description'
1312
-        );
1313
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1314
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * _get_reg_status_selection
1320
-     *
1321
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1322
-     *         instead of events.
1323
-     * @access protected
1324
-     * @return void
1325
-     * @throws EE_Error
1326
-     */
1327
-    protected function _get_reg_status_selection()
1328
-    {
1329
-        // first get all possible statuses
1330
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1331
-        // let's add a "don't change" option.
1332
-        $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1333
-        $status_array = array_merge($status_array, $statuses);
1334
-        $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1335
-            'txn_reg_status_change[reg_status]',
1336
-            $status_array,
1337
-            'NAN',
1338
-            'id="txn-admin-payment-reg-status-inp"',
1339
-            'txn-reg-status-change-reg-status'
1340
-        );
1341
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1342
-            'delete_txn_reg_status_change[reg_status]',
1343
-            $status_array,
1344
-            'NAN',
1345
-            'delete-txn-admin-payment-reg-status-inp',
1346
-            'delete-txn-reg-status-change-reg-status'
1347
-        );
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     *    _get_payment_methods
1353
-     * Gets all the payment methods available generally, or the ones that are already
1354
-     * selected on these payments (in case their payment methods are no longer active).
1355
-     * Has the side-effect of updating the template args' payment_methods item
1356
-     *
1357
-     * @access private
1358
-     * @param EE_Payment[] to show on this page
1359
-     * @return void
1360
-     * @throws EE_Error
1361
-     * @throws InvalidArgumentException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     * @throws ReflectionException
1365
-     */
1366
-    private function _get_payment_methods($payments = array())
1367
-    {
1368
-        $payment_methods_of_payments = array();
1369
-        foreach ($payments as $payment) {
1370
-            if ($payment instanceof EE_Payment) {
1371
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1372
-            }
1373
-        }
1374
-        if ($payment_methods_of_payments) {
1375
-            $query_args = array(
1376
-                array(
1377
-                    'OR*payment_method_for_payment' => array(
1378
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1379
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1380
-                    ),
1381
-                ),
1382
-            );
1383
-        } else {
1384
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1385
-        }
1386
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * txn_attendees_meta_box
1392
-     *    generates HTML for the Attendees Transaction main meta box
1393
-     *
1394
-     * @access public
1395
-     * @param WP_Post $post
1396
-     * @param array   $metabox
1397
-     * @return void
1398
-     * @throws DomainException
1399
-     * @throws EE_Error
1400
-     */
1401
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1402
-    {
1403
-
1404
-        /** @noinspection NonSecureExtractUsageInspection */
1405
-        extract($metabox['args']);
1406
-        $this->_template_args['post'] = $post;
1407
-        $this->_template_args['event_attendees'] = array();
1408
-        // process items in cart
1409
-        $line_items = $this->_transaction->get_many_related(
1410
-            'Line_Item',
1411
-            array(array('LIN_type' => 'line-item'))
1412
-        );
1413
-        if (! empty($line_items)) {
1414
-            foreach ($line_items as $item) {
1415
-                if ($item instanceof EE_Line_Item) {
1416
-                    switch ($item->OBJ_type()) {
1417
-                        case 'Event':
1418
-                            break;
1419
-                        case 'Ticket':
1420
-                            $ticket = $item->ticket();
1421
-                            // right now we're only handling tickets here.
1422
-                            // Cause its expected that only tickets will have attendees right?
1423
-                            if (! $ticket instanceof EE_Ticket) {
1424
-                                continue;
1425
-                            }
1426
-                            try {
1427
-                                $event_name = $ticket->get_event_name();
1428
-                            } catch (Exception $e) {
1429
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1430
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1431
-                            }
1432
-                            $event_name .= ' - ' . $item->get('LIN_name');
1433
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1434
-                            // now get all of the registrations for this transaction that use this ticket
1435
-                            $registrations = $ticket->get_many_related(
1436
-                                'Registration',
1437
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1438
-                            );
1439
-                            foreach ($registrations as $registration) {
1440
-                                if (! $registration instanceof EE_Registration) {
1441
-                                    continue;
1442
-                                }
1443
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1444
-                                    = $registration->status_ID();
1445
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1446
-                                    = $registration->count();
1447
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1448
-                                    = $event_name;
1449
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1450
-                                    = $ticket_price;
1451
-                                // attendee info
1452
-                                $attendee = $registration->get_first_related('Attendee');
1453
-                                if ($attendee instanceof EE_Attendee) {
1454
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1455
-                                        = $attendee->ID();
1456
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1457
-                                        = $attendee->full_name();
1458
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1459
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1460
-                                          . esc_html__(
1461
-                                              ' Event',
1462
-                                              'event_espresso'
1463
-                                          )
1464
-                                          . '">' . $attendee->email() . '</a>';
1465
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1466
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1467
-                                } else {
1468
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1469
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1471
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1472
-                                }
1473
-                            }
1474
-                            break;
1475
-                    }
1476
-                }
1477
-            }
1478
-
1479
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1480
-                array(
1481
-                    'action'  => 'edit_transaction',
1482
-                    'process' => 'attendees',
1483
-                ),
1484
-                TXN_ADMIN_URL
1485
-            );
1486
-            echo EEH_Template::display_template(
1487
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1488
-                $this->_template_args,
1489
-                true
1490
-            );
1491
-        } else {
1492
-            echo sprintf(
1493
-                esc_html__(
1494
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1495
-                    'event_espresso'
1496
-                ),
1497
-                '<p class="important-notice">',
1498
-                '</p>'
1499
-            );
1500
-        }
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * txn_registrant_side_meta_box
1506
-     * generates HTML for the Edit Transaction side meta box
1507
-     *
1508
-     * @access public
1509
-     * @return void
1510
-     * @throws DomainException
1511
-     * @throws EE_Error
1512
-     * @throws InvalidArgumentException
1513
-     * @throws InvalidDataTypeException
1514
-     * @throws InvalidInterfaceException
1515
-     * @throws ReflectionException
1516
-     */
1517
-    public function txn_registrant_side_meta_box()
1518
-    {
1519
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1520
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1521
-            : null;
1522
-        if (! $primary_att instanceof EE_Attendee) {
1523
-            $this->_template_args['no_attendee_message'] = esc_html__(
1524
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1525
-                'event_espresso'
1526
-            );
1527
-            $primary_att = EEM_Attendee::instance()->create_default_object();
1528
-        }
1529
-        $this->_template_args['ATT_ID'] = $primary_att->ID();
1530
-        $this->_template_args['prime_reg_fname'] = $primary_att->fname();
1531
-        $this->_template_args['prime_reg_lname'] = $primary_att->lname();
1532
-        $this->_template_args['prime_reg_email'] = $primary_att->email();
1533
-        $this->_template_args['prime_reg_phone'] = $primary_att->phone();
1534
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1535
-            array(
1536
-                'action' => 'edit_attendee',
1537
-                'post'   => $primary_att->ID(),
1538
-            ),
1539
-            REG_ADMIN_URL
1540
-        );
1541
-        // get formatted address for registrant
1542
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1543
-        echo EEH_Template::display_template(
1544
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1545
-            $this->_template_args,
1546
-            true
1547
-        );
1548
-    }
1549
-
1550
-
1551
-    /**
1552
-     * txn_billing_info_side_meta_box
1553
-     *    generates HTML for the Edit Transaction side meta box
1554
-     *
1555
-     * @access public
1556
-     * @return void
1557
-     * @throws DomainException
1558
-     * @throws EE_Error
1559
-     */
1560
-    public function txn_billing_info_side_meta_box()
1561
-    {
1562
-
1563
-        $this->_template_args['billing_form'] = $this->_transaction->billing_info();
1564
-        $this->_template_args['billing_form_url'] = add_query_arg(
1565
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1566
-            TXN_ADMIN_URL
1567
-        );
1568
-
1569
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1570
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1571
-    }
1572
-
1573
-
1574
-    /**
1575
-     * apply_payments_or_refunds
1576
-     *    registers a payment or refund made towards a transaction
1577
-     *
1578
-     * @access public
1579
-     * @return void
1580
-     * @throws EE_Error
1581
-     * @throws InvalidArgumentException
1582
-     * @throws ReflectionException
1583
-     * @throws RuntimeException
1584
-     * @throws InvalidDataTypeException
1585
-     * @throws InvalidInterfaceException
1586
-     */
1587
-    public function apply_payments_or_refunds()
1588
-    {
1589
-        $json_response_data = array('return_data' => false);
1590
-        $valid_data = $this->_validate_payment_request_data();
1591
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1592
-            'ee_edit_payments',
1593
-            'apply_payment_or_refund_from_registration_details'
1594
-        );
1595
-        if (! empty($valid_data) && $has_access) {
1596
-            $PAY_ID = $valid_data['PAY_ID'];
1597
-            // save  the new payment
1598
-            $payment = $this->_create_payment_from_request_data($valid_data);
1599
-            // get the TXN for this payment
1600
-            $transaction = $payment->transaction();
1601
-            // verify transaction
1602
-            if ($transaction instanceof EE_Transaction) {
1603
-                // calculate_total_payments_and_update_status
1604
-                $this->_process_transaction_payments($transaction);
1605
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1606
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1607
-                // apply payment to registrations (if applicable)
1608
-                if (! empty($REG_IDs)) {
1609
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1610
-                    $this->_maybe_send_notifications();
1611
-                    // now process status changes for the same registrations
1612
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1613
-                }
1614
-                $this->_maybe_send_notifications($payment);
1615
-                // prepare to render page
1616
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1617
-                do_action(
1618
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1619
-                    $transaction,
1620
-                    $payment
1621
-                );
1622
-            } else {
1623
-                EE_Error::add_error(
1624
-                    esc_html__(
1625
-                        'A valid Transaction for this payment could not be retrieved.',
1626
-                        'event_espresso'
1627
-                    ),
1628
-                    __FILE__,
1629
-                    __FUNCTION__,
1630
-                    __LINE__
1631
-                );
1632
-            }
1633
-        } else {
1634
-            if ($has_access) {
1635
-                EE_Error::add_error(
1636
-                    esc_html__(
1637
-                        'The payment form data could not be processed. Please try again.',
1638
-                        'event_espresso'
1639
-                    ),
1640
-                    __FILE__,
1641
-                    __FUNCTION__,
1642
-                    __LINE__
1643
-                );
1644
-            } else {
1645
-                EE_Error::add_error(
1646
-                    esc_html__(
1647
-                        'You do not have access to apply payments or refunds to a registration.',
1648
-                        'event_espresso'
1649
-                    ),
1650
-                    __FILE__,
1651
-                    __FUNCTION__,
1652
-                    __LINE__
1653
-                );
1654
-            }
1655
-        }
1656
-        $notices = EE_Error::get_notices(
1657
-            false,
1658
-            false,
1659
-            false
1660
-        );
1661
-        $this->_template_args = array(
1662
-            'data'    => $json_response_data,
1663
-            'error'   => $notices['errors'],
1664
-            'success' => $notices['success'],
1665
-        );
1666
-        $this->_return_json();
1667
-    }
1668
-
1669
-
1670
-    /**
1671
-     * _validate_payment_request_data
1672
-     *
1673
-     * @return array
1674
-     * @throws EE_Error
1675
-     */
1676
-    protected function _validate_payment_request_data()
1677
-    {
1678
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1679
-            return false;
1680
-        }
1681
-        $payment_form = $this->_generate_payment_form_section();
1682
-        try {
1683
-            if ($payment_form->was_submitted()) {
1684
-                $payment_form->receive_form_submission();
1685
-                if (! $payment_form->is_valid()) {
1686
-                    $submission_error_messages = array();
1687
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1688
-                        if ($validation_error instanceof EE_Validation_Error) {
1689
-                            $submission_error_messages[] = sprintf(
1690
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1691
-                                $validation_error->get_form_section()->html_label_text(),
1692
-                                $validation_error->getMessage()
1693
-                            );
1694
-                        }
1695
-                    }
1696
-                    EE_Error::add_error(
1697
-                        implode('<br />', $submission_error_messages),
1698
-                        __FILE__,
1699
-                        __FUNCTION__,
1700
-                        __LINE__
1701
-                    );
1702
-
1703
-                    return array();
1704
-                }
1705
-            }
1706
-        } catch (EE_Error $e) {
1707
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1708
-
1709
-            return array();
1710
-        }
1711
-
1712
-        return $payment_form->valid_data();
1713
-    }
1714
-
1715
-
1716
-    /**
1717
-     * _generate_payment_form_section
1718
-     *
1719
-     * @return EE_Form_Section_Proper
1720
-     * @throws EE_Error
1721
-     */
1722
-    protected function _generate_payment_form_section()
1723
-    {
1724
-        return new EE_Form_Section_Proper(
1725
-            array(
1726
-                'name'        => 'txn_admin_payment',
1727
-                'subsections' => array(
1728
-                    'PAY_ID'          => new EE_Text_Input(
1729
-                        array(
1730
-                            'default'               => 0,
1731
-                            'required'              => false,
1732
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1733
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1734
-                        )
1735
-                    ),
1736
-                    'TXN_ID'          => new EE_Text_Input(
1737
-                        array(
1738
-                            'default'               => 0,
1739
-                            'required'              => true,
1740
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1741
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1742
-                        )
1743
-                    ),
1744
-                    'type'            => new EE_Text_Input(
1745
-                        array(
1746
-                            'default'               => 1,
1747
-                            'required'              => true,
1748
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1749
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1750
-                        )
1751
-                    ),
1752
-                    'amount'          => new EE_Text_Input(
1753
-                        array(
1754
-                            'default'               => 0,
1755
-                            'required'              => true,
1756
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1757
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1758
-                        )
1759
-                    ),
1760
-                    'status'          => new EE_Text_Input(
1761
-                        array(
1762
-                            'default'         => EEM_Payment::status_id_approved,
1763
-                            'required'        => true,
1764
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1765
-                        )
1766
-                    ),
1767
-                    'PMD_ID'          => new EE_Text_Input(
1768
-                        array(
1769
-                            'default'               => 2,
1770
-                            'required'              => true,
1771
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1772
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1773
-                        )
1774
-                    ),
1775
-                    'date'            => new EE_Text_Input(
1776
-                        array(
1777
-                            'default'         => time(),
1778
-                            'required'        => true,
1779
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1780
-                        )
1781
-                    ),
1782
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1783
-                        array(
1784
-                            'default'               => '',
1785
-                            'required'              => false,
1786
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1787
-                            'validation_strategies' => array(
1788
-                                new EE_Max_Length_Validation_Strategy(
1789
-                                    esc_html__('Input too long', 'event_espresso'),
1790
-                                    100
1791
-                                ),
1792
-                            ),
1793
-                        )
1794
-                    ),
1795
-                    'po_number'       => new EE_Text_Input(
1796
-                        array(
1797
-                            'default'               => '',
1798
-                            'required'              => false,
1799
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1800
-                            'validation_strategies' => array(
1801
-                                new EE_Max_Length_Validation_Strategy(
1802
-                                    esc_html__('Input too long', 'event_espresso'),
1803
-                                    100
1804
-                                ),
1805
-                            ),
1806
-                        )
1807
-                    ),
1808
-                    'accounting'      => new EE_Text_Input(
1809
-                        array(
1810
-                            'default'               => '',
1811
-                            'required'              => false,
1812
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1813
-                            'validation_strategies' => array(
1814
-                                new EE_Max_Length_Validation_Strategy(
1815
-                                    esc_html__('Input too long', 'event_espresso'),
1816
-                                    100
1817
-                                ),
1818
-                            ),
1819
-                        )
1820
-                    ),
1821
-                ),
1822
-            )
1823
-        );
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * _create_payment_from_request_data
1829
-     *
1830
-     * @param array $valid_data
1831
-     * @return EE_Payment
1832
-     * @throws EE_Error
1833
-     */
1834
-    protected function _create_payment_from_request_data($valid_data)
1835
-    {
1836
-        $PAY_ID = $valid_data['PAY_ID'];
1837
-        // get payment amount
1838
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1839
-        // payments have a type value of 1 and refunds have a type value of -1
1840
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1841
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1842
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1843
-        $date = $valid_data['date']
1844
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1845
-            : date('Y-m-d g:i a', current_time('timestamp'));
1846
-        $payment = EE_Payment::new_instance(
1847
-            array(
1848
-                'TXN_ID'              => $valid_data['TXN_ID'],
1849
-                'STS_ID'              => $valid_data['status'],
1850
-                'PAY_timestamp'       => $date,
1851
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1852
-                'PMD_ID'              => $valid_data['PMD_ID'],
1853
-                'PAY_amount'          => $amount,
1854
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1855
-                'PAY_po_number'       => $valid_data['po_number'],
1856
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1857
-                'PAY_details'         => $valid_data,
1858
-                'PAY_ID'              => $PAY_ID,
1859
-            ),
1860
-            '',
1861
-            array('Y-m-d', 'g:i a')
1862
-        );
1863
-
1864
-        if (! $payment->save()) {
1865
-            EE_Error::add_error(
1866
-                sprintf(
1867
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1868
-                    $payment->ID()
1869
-                ),
1870
-                __FILE__,
1871
-                __FUNCTION__,
1872
-                __LINE__
1873
-            );
1874
-        }
1875
-
1876
-        return $payment;
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * _process_transaction_payments
1882
-     *
1883
-     * @param \EE_Transaction $transaction
1884
-     * @return void
1885
-     * @throws EE_Error
1886
-     * @throws InvalidArgumentException
1887
-     * @throws ReflectionException
1888
-     * @throws InvalidDataTypeException
1889
-     * @throws InvalidInterfaceException
1890
-     */
1891
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1892
-    {
1893
-        /** @type EE_Transaction_Payments $transaction_payments */
1894
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1895
-        // update the transaction with this payment
1896
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1897
-            EE_Error::add_success(
1898
-                esc_html__(
1899
-                    'The payment has been processed successfully.',
1900
-                    'event_espresso'
1901
-                ),
1902
-                __FILE__,
1903
-                __FUNCTION__,
1904
-                __LINE__
1905
-            );
1906
-        } else {
1907
-            EE_Error::add_error(
1908
-                esc_html__(
1909
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1910
-                    'event_espresso'
1911
-                ),
1912
-                __FILE__,
1913
-                __FUNCTION__,
1914
-                __LINE__
1915
-            );
1916
-        }
1917
-    }
1918
-
1919
-
1920
-    /**
1921
-     * _get_REG_IDs_to_apply_payment_to
1922
-     * returns a list of registration IDs that the payment will apply to
1923
-     *
1924
-     * @param \EE_Payment $payment
1925
-     * @return array
1926
-     * @throws EE_Error
1927
-     */
1928
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1929
-    {
1930
-        $REG_IDs = array();
1931
-        // grab array of IDs for specific registrations to apply changes to
1932
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1933
-            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1934
-        }
1935
-        // nothing specified ? then get all reg IDs
1936
-        if (empty($REG_IDs)) {
1937
-            $registrations = $payment->transaction()->registrations();
1938
-            $REG_IDs = ! empty($registrations)
1939
-                ? array_keys($registrations)
1940
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1941
-        }
1942
-
1943
-        // ensure that REG_IDs are integers and NOT strings
1944
-        return array_map('intval', $REG_IDs);
1945
-    }
1946
-
1947
-
1948
-    /**
1949
-     * @return array
1950
-     */
1951
-    public function existing_reg_payment_REG_IDs()
1952
-    {
1953
-        return $this->_existing_reg_payment_REG_IDs;
1954
-    }
1955
-
1956
-
1957
-    /**
1958
-     * @param array $existing_reg_payment_REG_IDs
1959
-     */
1960
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1961
-    {
1962
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1963
-    }
1964
-
1965
-
1966
-    /**
1967
-     * _get_existing_reg_payment_REG_IDs
1968
-     * returns a list of registration IDs that the payment is currently related to
1969
-     * as recorded in the database
1970
-     *
1971
-     * @param \EE_Payment $payment
1972
-     * @return array
1973
-     * @throws EE_Error
1974
-     */
1975
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1976
-    {
1977
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1978
-            // let's get any existing reg payment records for this payment
1979
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1980
-            // but we only want the REG IDs, so grab the array keys
1981
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1982
-                ? array_keys($existing_reg_payment_REG_IDs)
1983
-                : array();
1984
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1985
-        }
1986
-
1987
-        return $this->existing_reg_payment_REG_IDs();
1988
-    }
1989
-
1990
-
1991
-    /**
1992
-     * _remove_existing_registration_payments
1993
-     * this calculates the difference between existing relations
1994
-     * to the supplied payment and the new list registration IDs,
1995
-     * removes any related registrations that no longer apply,
1996
-     * and then updates the registration paid fields
1997
-     *
1998
-     * @param \EE_Payment $payment
1999
-     * @param int         $PAY_ID
2000
-     * @return bool;
2001
-     * @throws EE_Error
2002
-     * @throws InvalidArgumentException
2003
-     * @throws ReflectionException
2004
-     * @throws InvalidDataTypeException
2005
-     * @throws InvalidInterfaceException
2006
-     */
2007
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2008
-    {
2009
-        // newly created payments will have nothing recorded for $PAY_ID
2010
-        if ($PAY_ID == 0) {
2011
-            return false;
2012
-        }
2013
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2014
-        if (empty($existing_reg_payment_REG_IDs)) {
2015
-            return false;
2016
-        }
2017
-        /** @type EE_Transaction_Payments $transaction_payments */
2018
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2019
-
2020
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2021
-            $payment,
2022
-            array(
2023
-                array(
2024
-                    'PAY_ID' => $payment->ID(),
2025
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2026
-                ),
2027
-            )
2028
-        );
2029
-    }
2030
-
2031
-
2032
-    /**
2033
-     * _update_registration_payments
2034
-     * this applies the payments to the selected registrations
2035
-     * but only if they have not already been paid for
2036
-     *
2037
-     * @param  EE_Transaction $transaction
2038
-     * @param \EE_Payment     $payment
2039
-     * @param array           $REG_IDs
2040
-     * @return void
2041
-     * @throws EE_Error
2042
-     * @throws InvalidArgumentException
2043
-     * @throws ReflectionException
2044
-     * @throws RuntimeException
2045
-     * @throws InvalidDataTypeException
2046
-     * @throws InvalidInterfaceException
2047
-     */
2048
-    protected function _update_registration_payments(
2049
-        EE_Transaction $transaction,
2050
-        EE_Payment $payment,
2051
-        $REG_IDs = array()
2052
-    ) {
2053
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2054
-        // so let's do that using our set of REG_IDs from the form
2055
-        $registration_query_where_params = array(
2056
-            'REG_ID' => array('IN', $REG_IDs),
2057
-        );
2058
-        // but add in some conditions regarding payment,
2059
-        // so that we don't apply payments to registrations that are free or have already been paid for
2060
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2061
-        if (! $payment->is_a_refund()) {
2062
-            $registration_query_where_params['REG_final_price'] = array('!=', 0);
2063
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2064
-        }
2065
-        $registrations = $transaction->registrations(array($registration_query_where_params));
2066
-        if (! empty($registrations)) {
2067
-            /** @type EE_Payment_Processor $payment_processor */
2068
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2069
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2070
-        }
2071
-    }
2072
-
2073
-
2074
-    /**
2075
-     * _process_registration_status_change
2076
-     * This processes requested registration status changes for all the registrations
2077
-     * on a given transaction and (optionally) sends out notifications for the changes.
2078
-     *
2079
-     * @param  EE_Transaction $transaction
2080
-     * @param array           $REG_IDs
2081
-     * @return bool
2082
-     * @throws EE_Error
2083
-     * @throws InvalidArgumentException
2084
-     * @throws ReflectionException
2085
-     * @throws InvalidDataTypeException
2086
-     * @throws InvalidInterfaceException
2087
-     */
2088
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2089
-    {
2090
-        // first if there is no change in status then we get out.
2091
-        if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2092
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2093
-        ) {
2094
-            // no error message, no change requested, just nothing to do man.
2095
-            return false;
2096
-        }
2097
-        /** @type EE_Transaction_Processor $transaction_processor */
2098
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2099
-
2100
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2101
-        return $transaction_processor->manually_update_registration_statuses(
2102
-            $transaction,
2103
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2104
-            array(array('REG_ID' => array('IN', $REG_IDs)))
2105
-        );
2106
-    }
2107
-
2108
-
2109
-    /**
2110
-     * _build_payment_json_response
2111
-     *
2112
-     * @access public
2113
-     * @param \EE_Payment $payment
2114
-     * @param array       $REG_IDs
2115
-     * @param bool | null $delete_txn_reg_status_change
2116
-     * @return array
2117
-     * @throws EE_Error
2118
-     * @throws InvalidArgumentException
2119
-     * @throws InvalidDataTypeException
2120
-     * @throws InvalidInterfaceException
2121
-     * @throws ReflectionException
2122
-     */
2123
-    protected function _build_payment_json_response(
2124
-        EE_Payment $payment,
2125
-        $REG_IDs = array(),
2126
-        $delete_txn_reg_status_change = null
2127
-    ) {
2128
-        // was the payment deleted ?
2129
-        if (is_bool($delete_txn_reg_status_change)) {
2130
-            return array(
2131
-                'PAY_ID'                       => $payment->ID(),
2132
-                'amount'                       => $payment->amount(),
2133
-                'total_paid'                   => $payment->transaction()->paid(),
2134
-                'txn_status'                   => $payment->transaction()->status_ID(),
2135
-                'pay_status'                   => $payment->STS_ID(),
2136
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2137
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2138
-            );
2139
-        } else {
2140
-            $this->_get_payment_status_array();
2141
-
2142
-            return array(
2143
-                'amount'           => $payment->amount(),
2144
-                'total_paid'       => $payment->transaction()->paid(),
2145
-                'txn_status'       => $payment->transaction()->status_ID(),
2146
-                'pay_status'       => $payment->STS_ID(),
2147
-                'PAY_ID'           => $payment->ID(),
2148
-                'STS_ID'           => $payment->STS_ID(),
2149
-                'status'           => self::$_pay_status[ $payment->STS_ID() ],
2150
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2151
-                'method'           => strtoupper($payment->source()),
2152
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2153
-                'gateway'          => $payment->payment_method()
2154
-                    ? $payment->payment_method()->admin_name()
2155
-                    : esc_html__("Unknown", 'event_espresso'),
2156
-                'gateway_response' => $payment->gateway_response(),
2157
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2158
-                'po_number'        => $payment->po_number(),
2159
-                'extra_accntng'    => $payment->extra_accntng(),
2160
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2161
-            );
2162
-        }
2163
-    }
2164
-
2165
-
2166
-    /**
2167
-     * delete_payment
2168
-     *    delete a payment or refund made towards a transaction
2169
-     *
2170
-     * @access public
2171
-     * @return void
2172
-     * @throws EE_Error
2173
-     * @throws InvalidArgumentException
2174
-     * @throws ReflectionException
2175
-     * @throws InvalidDataTypeException
2176
-     * @throws InvalidInterfaceException
2177
-     */
2178
-    public function delete_payment()
2179
-    {
2180
-        $json_response_data = array('return_data' => false);
2181
-        $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2182
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2183
-            : 0;
2184
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2185
-            'ee_delete_payments',
2186
-            'delete_payment_from_registration_details'
2187
-        );
2188
-        if ($PAY_ID && $can_delete) {
2189
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2190
-                ? $this->_req_data['delete_txn_reg_status_change']
2191
-                : false;
2192
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2193
-            if ($payment instanceof EE_Payment) {
2194
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2195
-                /** @type EE_Transaction_Payments $transaction_payments */
2196
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2197
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2198
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2199
-                        $payment,
2200
-                        $REG_IDs,
2201
-                        $delete_txn_reg_status_change
2202
-                    );
2203
-                    if ($delete_txn_reg_status_change) {
2204
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2205
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2206
-                        // $_REQUEST global because that's how messages will be looking for it.
2207
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2208
-                        $this->_maybe_send_notifications();
2209
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2210
-                    }
2211
-                }
2212
-            } else {
2213
-                EE_Error::add_error(
2214
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2215
-                    __FILE__,
2216
-                    __FUNCTION__,
2217
-                    __LINE__
2218
-                );
2219
-            }
2220
-        } else {
2221
-            if ($can_delete) {
2222
-                EE_Error::add_error(
2223
-                    esc_html__(
2224
-                        'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2225
-                        'event_espresso'
2226
-                    ),
2227
-                    __FILE__,
2228
-                    __FUNCTION__,
2229
-                    __LINE__
2230
-                );
2231
-            } else {
2232
-                EE_Error::add_error(
2233
-                    esc_html__(
2234
-                        'You do not have access to delete a payment.',
2235
-                        'event_espresso'
2236
-                    ),
2237
-                    __FILE__,
2238
-                    __FUNCTION__,
2239
-                    __LINE__
2240
-                );
2241
-            }
2242
-        }
2243
-        $notices = EE_Error::get_notices(false, false, false);
2244
-        $this->_template_args = array(
2245
-            'data'      => $json_response_data,
2246
-            'success'   => $notices['success'],
2247
-            'error'     => $notices['errors'],
2248
-            'attention' => $notices['attention'],
2249
-        );
2250
-        $this->_return_json();
2251
-    }
2252
-
2253
-
2254
-    /**
2255
-     * _registration_payment_data_array
2256
-     * adds info for 'owing' and 'paid' for each registration to the json response
2257
-     *
2258
-     * @access protected
2259
-     * @param array $REG_IDs
2260
-     * @return array
2261
-     * @throws EE_Error
2262
-     * @throws InvalidArgumentException
2263
-     * @throws InvalidDataTypeException
2264
-     * @throws InvalidInterfaceException
2265
-     * @throws ReflectionException
2266
-     */
2267
-    protected function _registration_payment_data_array($REG_IDs)
2268
-    {
2269
-        $registration_payment_data = array();
2270
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2271
-        if (! empty($REG_IDs)) {
2272
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2273
-            foreach ($registrations as $registration) {
2274
-                if ($registration instanceof EE_Registration) {
2275
-                    $registration_payment_data[ $registration->ID() ] = array(
2276
-                        'paid'  => $registration->pretty_paid(),
2277
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2278
-                    );
2279
-                }
2280
-            }
2281
-        }
2282
-
2283
-        return $registration_payment_data;
2284
-    }
2285
-
2286
-
2287
-    /**
2288
-     * _maybe_send_notifications
2289
-     * determines whether or not the admin has indicated that notifications should be sent.
2290
-     * If so, will toggle a filter switch for delivering registration notices.
2291
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2292
-     *
2293
-     * @access protected
2294
-     * @param \EE_Payment | null $payment
2295
-     */
2296
-    protected function _maybe_send_notifications($payment = null)
2297
-    {
2298
-        switch ($payment instanceof EE_Payment) {
2299
-            // payment notifications
2300
-            case true:
2301
-                if (isset(
2302
-                    $this->_req_data['txn_payments'],
2303
-                    $this->_req_data['txn_payments']['send_notifications']
2304
-                )
2305
-                    && filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2306
-                ) {
2307
-                    $this->_process_payment_notification($payment);
2308
-                }
2309
-                break;
2310
-            // registration notifications
2311
-            case false:
2312
-                if (isset(
2313
-                    $this->_req_data['txn_reg_status_change'],
2314
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
2315
-                )
2316
-                    && filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2317
-                ) {
2318
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2319
-                }
2320
-                break;
2321
-        }
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * _send_payment_reminder
2327
-     *    generates HTML for the View Transaction Details Admin page
2328
-     *
2329
-     * @access protected
2330
-     * @return void
2331
-     * @throws EE_Error
2332
-     * @throws InvalidArgumentException
2333
-     * @throws InvalidDataTypeException
2334
-     * @throws InvalidInterfaceException
2335
-     */
2336
-    protected function _send_payment_reminder()
2337
-    {
2338
-        $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2339
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2340
-        $query_args = isset($this->_req_data['redirect_to']) ? array(
2341
-            'action' => $this->_req_data['redirect_to'],
2342
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2343
-        ) : array();
2344
-        do_action(
2345
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2346
-            $transaction
2347
-        );
2348
-        $this->_redirect_after_action(
2349
-            false,
2350
-            esc_html__('payment reminder', 'event_espresso'),
2351
-            esc_html__('sent', 'event_espresso'),
2352
-            $query_args,
2353
-            true
2354
-        );
2355
-    }
2356
-
2357
-
2358
-    /**
2359
-     *  get_transactions
2360
-     *    get transactions for given parameters (used by list table)
2361
-     *
2362
-     * @param  int     $perpage how many transactions displayed per page
2363
-     * @param  boolean $count   return the count or objects
2364
-     * @param string   $view
2365
-     * @return mixed int = count || array of transaction objects
2366
-     * @throws EE_Error
2367
-     * @throws InvalidArgumentException
2368
-     * @throws InvalidDataTypeException
2369
-     * @throws InvalidInterfaceException
2370
-     */
2371
-    public function get_transactions($perpage, $count = false, $view = '')
2372
-    {
2373
-
2374
-        $TXN = EEM_Transaction::instance();
2375
-
2376
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2377
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2378
-            : date(
2379
-                'm/d/Y',
2380
-                strtotime('-10 year')
2381
-            );
2382
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
2383
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2384
-            : date('m/d/Y');
2385
-
2386
-        // make sure our timestamps start and end right at the boundaries for each day
2387
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2388
-        $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2389
-
2390
-
2391
-        // convert to timestamps
2392
-        $start_date = strtotime($start_date);
2393
-        $end_date = strtotime($end_date);
2394
-
2395
-        // makes sure start date is the lowest value and vice versa
2396
-        $start_date = min($start_date, $end_date);
2397
-        $end_date = max($start_date, $end_date);
2398
-
2399
-        // convert to correct format for query
2400
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2401
-            'TXN_timestamp',
2402
-            date('Y-m-d H:i:s', $start_date),
2403
-            'Y-m-d H:i:s'
2404
-        );
2405
-        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2406
-            'TXN_timestamp',
2407
-            date('Y-m-d H:i:s', $end_date),
2408
-            'Y-m-d H:i:s'
2409
-        );
2410
-
2411
-
2412
-        // set orderby
2413
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2414
-
2415
-        switch ($this->_req_data['orderby']) {
2416
-            case 'TXN_ID':
2417
-                $orderby = 'TXN_ID';
2418
-                break;
2419
-            case 'ATT_fname':
2420
-                $orderby = 'Registration.Attendee.ATT_fname';
2421
-                break;
2422
-            case 'event_name':
2423
-                $orderby = 'Registration.Event.EVT_name';
2424
-                break;
2425
-            default: // 'TXN_timestamp'
2426
-                $orderby = 'TXN_timestamp';
2427
-        }
2428
-
2429
-        $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2430
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2431
-        $per_page = ! empty($perpage) ? $perpage : 10;
2432
-        $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2433
-
2434
-        $offset = ($current_page - 1) * $per_page;
2435
-        $limit = array($offset, $per_page);
2436
-
2437
-        $_where = array(
2438
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2439
-            'Registration.REG_count' => 1,
2440
-        );
2441
-
2442
-        if (isset($this->_req_data['EVT_ID'])) {
2443
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2444
-        }
2445
-
2446
-        if (isset($this->_req_data['s'])) {
2447
-            $search_string = '%' . $this->_req_data['s'] . '%';
2448
-            $_where['OR'] = array(
2449
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2450
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2451
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2452
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2453
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2454
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2455
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2456
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2457
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2458
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2459
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2460
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2461
-                'Registration.REG_code'               => array('LIKE', $search_string),
2462
-                'Registration.REG_count'              => array('LIKE', $search_string),
2463
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2464
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2465
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2466
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2467
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2468
-                'TXN_session_data'                    => array('LIKE', $search_string),
2469
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2470
-            );
2471
-        }
2472
-
2473
-        // failed transactions
2474
-        $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2475
-                  || ($count && $view === 'failed');
2476
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2477
-                     || ($count && $view === 'abandoned');
2478
-
2479
-        if ($failed) {
2480
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2481
-        } elseif ($abandoned) {
2482
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2483
-        } else {
2484
-            $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2485
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2486
-        }
2487
-
2488
-        $query_params = array(
2489
-            $_where,
2490
-            'order_by'                 => array($orderby => $sort),
2491
-            'limit'                    => $limit,
2492
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2493
-        );
2494
-
2495
-        $transactions = $count
2496
-            ? $TXN->count(array($_where), 'TXN_ID', true)
2497
-            : $TXN->get_all($query_params);
2498
-
2499
-        return $transactions;
2500
-    }
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
+		);
437
+		if (/**
438
+		 * Filters whether a link to the "Failed Transactions" list table
439
+		 * appears on the Transactions Admin Page list table.
440
+		 * List display can be turned back on via the following:
441
+		 * add_filter(
442
+		 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
443
+		 *     '__return_true'
444
+		 * );
445
+		 *
446
+		 * @since $VID:$
447
+		 * @param boolean                 $display_failed_txns_list
448
+		 * @param Transactions_Admin_Page $this
449
+		 */
450
+			apply_filters(
451
+				'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
452
+				false,
453
+				$this
454
+			)
455
+		) {
456
+			$this->_views['failed'] = array(
457
+				'slug'  => 'failed',
458
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
459
+				'count' => 0,
460
+			);
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 * _set_transaction_object
467
+	 * This sets the _transaction property for the transaction details screen
468
+	 *
469
+	 * @access private
470
+	 * @return void
471
+	 * @throws EE_Error
472
+	 * @throws InvalidArgumentException
473
+	 * @throws RuntimeException
474
+	 * @throws InvalidDataTypeException
475
+	 * @throws InvalidInterfaceException
476
+	 * @throws ReflectionException
477
+	 */
478
+	private function _set_transaction_object()
479
+	{
480
+		if ($this->_transaction instanceof EE_Transaction) {
481
+			return;
482
+		} //get out we've already set the object
483
+
484
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
485
+			? absint($this->_req_data['TXN_ID'])
486
+			: false;
487
+
488
+		// get transaction object
489
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
490
+		$this->_session = $this->_transaction instanceof EE_Transaction
491
+			? $this->_transaction->get('TXN_session_data')
492
+			: null;
493
+		if ($this->_transaction instanceof EE_Transaction) {
494
+			$this->_transaction->verify_abandoned_transaction_status();
495
+		}
496
+
497
+		if (! $this->_transaction instanceof EE_Transaction) {
498
+			$error_msg = sprintf(
499
+				esc_html__(
500
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
501
+					'event_espresso'
502
+				),
503
+				$TXN_ID
504
+			);
505
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
506
+		}
507
+	}
508
+
509
+
510
+	/**
511
+	 *    _transaction_legend_items
512
+	 *
513
+	 * @access protected
514
+	 * @return array
515
+	 * @throws EE_Error
516
+	 * @throws InvalidArgumentException
517
+	 * @throws ReflectionException
518
+	 * @throws InvalidDataTypeException
519
+	 * @throws InvalidInterfaceException
520
+	 */
521
+	protected function _transaction_legend_items()
522
+	{
523
+		EE_Registry::instance()->load_helper('MSG_Template');
524
+		$items = array();
525
+
526
+		if (EE_Registry::instance()->CAP->current_user_can(
527
+			'ee_read_global_messages',
528
+			'view_filtered_messages'
529
+		)) {
530
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
531
+			if (is_array($related_for_icon)
532
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
533
+			) {
534
+				$items['view_related_messages'] = array(
535
+					'class' => $related_for_icon['css_class'],
536
+					'desc'  => $related_for_icon['label'],
537
+				);
538
+			}
539
+		}
540
+
541
+		$items = apply_filters(
542
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
543
+			array_merge(
544
+				$items,
545
+				array(
546
+					'view_details'          => array(
547
+						'class' => 'dashicons dashicons-cart',
548
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
549
+					),
550
+					'view_invoice'          => array(
551
+						'class' => 'dashicons dashicons-media-spreadsheet',
552
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
553
+					),
554
+					'view_receipt'          => array(
555
+						'class' => 'dashicons dashicons-media-default',
556
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
557
+					),
558
+					'view_registration'     => array(
559
+						'class' => 'dashicons dashicons-clipboard',
560
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
561
+					),
562
+					'payment_overview_link' => array(
563
+						'class' => 'dashicons dashicons-money',
564
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
565
+					),
566
+				)
567
+			)
568
+		);
569
+
570
+		if (EE_Registry::instance()->CAP->current_user_can(
571
+			'ee_send_message',
572
+			'espresso_transactions_send_payment_reminder'
573
+		)) {
574
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
575
+				$items['send_payment_reminder'] = array(
576
+					'class' => 'dashicons dashicons-email-alt',
577
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
578
+				);
579
+			} else {
580
+				$items['blank*'] = array(
581
+					'class' => '',
582
+					'desc'  => '',
583
+				);
584
+			}
585
+		} else {
586
+			$items['blank*'] = array(
587
+				'class' => '',
588
+				'desc'  => '',
589
+			);
590
+		}
591
+		$more_items = apply_filters(
592
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
593
+			array(
594
+				'overpaid'   => array(
595
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
596
+					'desc'  => EEH_Template::pretty_status(
597
+						EEM_Transaction::overpaid_status_code,
598
+						false,
599
+						'sentence'
600
+					),
601
+				),
602
+				'complete'   => array(
603
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
604
+					'desc'  => EEH_Template::pretty_status(
605
+						EEM_Transaction::complete_status_code,
606
+						false,
607
+						'sentence'
608
+					),
609
+				),
610
+				'incomplete' => array(
611
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
612
+					'desc'  => EEH_Template::pretty_status(
613
+						EEM_Transaction::incomplete_status_code,
614
+						false,
615
+						'sentence'
616
+					),
617
+				),
618
+				'abandoned'  => array(
619
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
620
+					'desc'  => EEH_Template::pretty_status(
621
+						EEM_Transaction::abandoned_status_code,
622
+						false,
623
+						'sentence'
624
+					),
625
+				),
626
+				'failed'     => array(
627
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
628
+					'desc'  => EEH_Template::pretty_status(
629
+						EEM_Transaction::failed_status_code,
630
+						false,
631
+						'sentence'
632
+					),
633
+				),
634
+			)
635
+		);
636
+
637
+		return array_merge($items, $more_items);
638
+	}
639
+
640
+
641
+	/**
642
+	 *    _transactions_overview_list_table
643
+	 *
644
+	 * @access protected
645
+	 * @return void
646
+	 * @throws DomainException
647
+	 * @throws EE_Error
648
+	 * @throws InvalidArgumentException
649
+	 * @throws InvalidDataTypeException
650
+	 * @throws InvalidInterfaceException
651
+	 * @throws ReflectionException
652
+	 */
653
+	protected function _transactions_overview_list_table()
654
+	{
655
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
656
+		$event = isset($this->_req_data['EVT_ID'])
657
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
658
+			: null;
659
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
660
+			? sprintf(
661
+				esc_html__(
662
+					'%sViewing Transactions for the Event: %s%s',
663
+					'event_espresso'
664
+				),
665
+				'<h3>',
666
+				'<a href="'
667
+				. EE_Admin_Page::add_query_args_and_nonce(
668
+					array('action' => 'edit', 'post' => $event->ID()),
669
+					EVENTS_ADMIN_URL
670
+				)
671
+				. '" title="'
672
+				. esc_attr__(
673
+					'Click to Edit event',
674
+					'event_espresso'
675
+				)
676
+				. '">' . $event->get('EVT_name') . '</a>',
677
+				'</h3>'
678
+			)
679
+			: '';
680
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
681
+		$this->display_admin_list_table_page_with_no_sidebar();
682
+	}
683
+
684
+
685
+	/**
686
+	 *    _transaction_details
687
+	 * generates HTML for the View Transaction Details Admin page
688
+	 *
689
+	 * @access protected
690
+	 * @return void
691
+	 * @throws DomainException
692
+	 * @throws EE_Error
693
+	 * @throws InvalidArgumentException
694
+	 * @throws InvalidDataTypeException
695
+	 * @throws InvalidInterfaceException
696
+	 * @throws RuntimeException
697
+	 * @throws ReflectionException
698
+	 */
699
+	protected function _transaction_details()
700
+	{
701
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
702
+
703
+		$this->_set_transaction_status_array();
704
+
705
+		$this->_template_args = array();
706
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
707
+
708
+		$this->_set_transaction_object();
709
+
710
+		if (! $this->_transaction instanceof EE_Transaction) {
711
+			return;
712
+		}
713
+		$primary_registration = $this->_transaction->primary_registration();
714
+		$attendee = $primary_registration instanceof EE_Registration
715
+			? $primary_registration->attendee()
716
+			: null;
717
+
718
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
719
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
720
+
721
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
722
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
723
+
724
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ];
725
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
726
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
727
+
728
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
729
+		$this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
730
+
731
+		$amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
732
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
733
+			$amount_due,
734
+			true
735
+		);
736
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
737
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
738
+												  . $this->_template_args['amount_due'];
739
+		} else {
740
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
741
+		}
742
+		$this->_template_args['amount_due_class'] = '';
743
+
744
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
745
+			// paid in full
746
+			$this->_template_args['amount_due'] = false;
747
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
748
+			// overpaid
749
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
750
+		} elseif ($this->_transaction->get('TXN_total') > 0
751
+				  && $this->_transaction->get('TXN_paid') > 0
752
+		) {
753
+			// monies owing
754
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
755
+		} elseif ($this->_transaction->get('TXN_total') > 0
756
+				  && $this->_transaction->get('TXN_paid') == 0
757
+		) {
758
+			// no payments made yet
759
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
760
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
761
+			// free event
762
+			$this->_template_args['amount_due'] = false;
763
+		}
764
+
765
+		$payment_method = $this->_transaction->payment_method();
766
+
767
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
768
+			? $payment_method->admin_name()
769
+			: esc_html__('Unknown', 'event_espresso');
770
+
771
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
772
+		// link back to overview
773
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
774
+			? $_SERVER['HTTP_REFERER']
775
+			: TXN_ADMIN_URL;
776
+
777
+
778
+		// next link
779
+		$next_txn = $this->_transaction->next(
780
+			null,
781
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
782
+			'TXN_ID'
783
+		);
784
+		$this->_template_args['next_transaction'] = $next_txn
785
+			? $this->_next_link(
786
+				EE_Admin_Page::add_query_args_and_nonce(
787
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
788
+					TXN_ADMIN_URL
789
+				),
790
+				'dashicons dashicons-arrow-right ee-icon-size-22'
791
+			)
792
+			: '';
793
+		// previous link
794
+		$previous_txn = $this->_transaction->previous(
795
+			null,
796
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
797
+			'TXN_ID'
798
+		);
799
+		$this->_template_args['previous_transaction'] = $previous_txn
800
+			? $this->_previous_link(
801
+				EE_Admin_Page::add_query_args_and_nonce(
802
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
803
+					TXN_ADMIN_URL
804
+				),
805
+				'dashicons dashicons-arrow-left ee-icon-size-22'
806
+			)
807
+			: '';
808
+
809
+		// were we just redirected here after adding a new registration ???
810
+		if (isset(
811
+			$this->_req_data['redirect_from'],
812
+			$this->_req_data['EVT_ID'],
813
+			$this->_req_data['event_name']
814
+		)) {
815
+			if (EE_Registry::instance()->CAP->current_user_can(
816
+				'ee_edit_registrations',
817
+				'espresso_registrations_new_registration',
818
+				$this->_req_data['EVT_ID']
819
+			)) {
820
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
821
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
822
+					array(
823
+						'page'     => 'espresso_registrations',
824
+						'action'   => 'new_registration',
825
+						'return'   => 'default',
826
+						'TXN_ID'   => $this->_transaction->ID(),
827
+						'event_id' => $this->_req_data['EVT_ID'],
828
+					),
829
+					REG_ADMIN_URL
830
+				);
831
+				$this->_admin_page_title .= '">';
832
+
833
+				$this->_admin_page_title .= sprintf(
834
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
835
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
836
+				);
837
+				$this->_admin_page_title .= '</a>';
838
+			}
839
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
840
+		}
841
+		// grab messages at the last second
842
+		$this->_template_args['notices'] = EE_Error::get_notices();
843
+		// path to template
844
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
845
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
846
+			$template_path,
847
+			$this->_template_args,
848
+			true
849
+		);
850
+
851
+		// the details template wrapper
852
+		$this->display_admin_page_with_sidebar();
853
+	}
854
+
855
+
856
+	/**
857
+	 *        _transaction_details_metaboxes
858
+	 *
859
+	 * @access protected
860
+	 * @return void
861
+	 * @throws EE_Error
862
+	 * @throws InvalidArgumentException
863
+	 * @throws InvalidDataTypeException
864
+	 * @throws InvalidInterfaceException
865
+	 * @throws RuntimeException
866
+	 * @throws ReflectionException
867
+	 */
868
+	protected function _transaction_details_metaboxes()
869
+	{
870
+
871
+		$this->_set_transaction_object();
872
+
873
+		if (! $this->_transaction instanceof EE_Transaction) {
874
+			return;
875
+		}
876
+		add_meta_box(
877
+			'edit-txn-details-mbox',
878
+			esc_html__('Transaction Details', 'event_espresso'),
879
+			array($this, 'txn_details_meta_box'),
880
+			$this->_wp_page_slug,
881
+			'normal',
882
+			'high'
883
+		);
884
+		add_meta_box(
885
+			'edit-txn-attendees-mbox',
886
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
887
+			array($this, 'txn_attendees_meta_box'),
888
+			$this->_wp_page_slug,
889
+			'normal',
890
+			'high',
891
+			array('TXN_ID' => $this->_transaction->ID())
892
+		);
893
+		add_meta_box(
894
+			'edit-txn-registrant-mbox',
895
+			esc_html__('Primary Contact', 'event_espresso'),
896
+			array($this, 'txn_registrant_side_meta_box'),
897
+			$this->_wp_page_slug,
898
+			'side',
899
+			'high'
900
+		);
901
+		add_meta_box(
902
+			'edit-txn-billing-info-mbox',
903
+			esc_html__('Billing Information', 'event_espresso'),
904
+			array($this, 'txn_billing_info_side_meta_box'),
905
+			$this->_wp_page_slug,
906
+			'side',
907
+			'high'
908
+		);
909
+	}
910
+
911
+
912
+	/**
913
+	 * Callback for transaction actions metabox.
914
+	 *
915
+	 * @param EE_Transaction|null $transaction
916
+	 * @throws DomainException
917
+	 * @throws EE_Error
918
+	 * @throws InvalidArgumentException
919
+	 * @throws InvalidDataTypeException
920
+	 * @throws InvalidInterfaceException
921
+	 * @throws ReflectionException
922
+	 * @throws RuntimeException
923
+	 */
924
+	public function getActionButtons(EE_Transaction $transaction = null)
925
+	{
926
+		$content = '';
927
+		$actions = array();
928
+		if (! $transaction instanceof EE_Transaction) {
929
+			return $content;
930
+		}
931
+		/** @var EE_Registration $primary_registration */
932
+		$primary_registration = $transaction->primary_registration();
933
+		$attendee = $primary_registration instanceof EE_Registration
934
+			? $primary_registration->attendee()
935
+			: null;
936
+
937
+		if ($attendee instanceof EE_Attendee
938
+			&& EE_Registry::instance()->CAP->current_user_can(
939
+				'ee_send_message',
940
+				'espresso_transactions_send_payment_reminder'
941
+			)
942
+		) {
943
+			$actions['payment_reminder'] =
944
+				EEH_MSG_Template::is_mt_active('payment_reminder')
945
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
946
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
947
+					? EEH_Template::get_button_or_link(
948
+						EE_Admin_Page::add_query_args_and_nonce(
949
+							array(
950
+								'action'      => 'send_payment_reminder',
951
+								'TXN_ID'      => $this->_transaction->ID(),
952
+								'redirect_to' => 'view_transaction',
953
+							),
954
+							TXN_ADMIN_URL
955
+						),
956
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
957
+						'button secondary-button',
958
+						'dashicons dashicons-email-alt'
959
+					)
960
+					: '';
961
+		}
962
+
963
+		if ($primary_registration instanceof EE_Registration
964
+			&& EEH_MSG_Template::is_mt_active('receipt')
965
+		) {
966
+			$actions['receipt'] = EEH_Template::get_button_or_link(
967
+				$primary_registration->receipt_url(),
968
+				esc_html__('View Receipt', 'event_espresso'),
969
+				'button secondary-button',
970
+				'dashicons dashicons-media-default'
971
+			);
972
+		}
973
+
974
+		if ($primary_registration instanceof EE_Registration
975
+			&& EEH_MSG_Template::is_mt_active('invoice')
976
+		) {
977
+			$actions['invoice'] = EEH_Template::get_button_or_link(
978
+				$primary_registration->invoice_url(),
979
+				esc_html__('View Invoice', 'event_espresso'),
980
+				'button secondary-button',
981
+				'dashicons dashicons-media-spreadsheet'
982
+			);
983
+		}
984
+		$actions = array_filter(
985
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
986
+		);
987
+		if ($actions) {
988
+			$content = '<ul>';
989
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
990
+			$content .= '</uL>';
991
+		}
992
+		return $content;
993
+	}
994
+
995
+
996
+	/**
997
+	 * txn_details_meta_box
998
+	 * generates HTML for the Transaction main meta box
999
+	 *
1000
+	 * @return void
1001
+	 * @throws DomainException
1002
+	 * @throws EE_Error
1003
+	 * @throws InvalidArgumentException
1004
+	 * @throws InvalidDataTypeException
1005
+	 * @throws InvalidInterfaceException
1006
+	 * @throws RuntimeException
1007
+	 * @throws ReflectionException
1008
+	 */
1009
+	public function txn_details_meta_box()
1010
+	{
1011
+		$this->_set_transaction_object();
1012
+		$this->_template_args['TXN_ID'] = $this->_transaction->ID();
1013
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1014
+			? $this->_transaction->primary_registration()->attendee()
1015
+			: null;
1016
+		$this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1017
+			'ee_edit_payments',
1018
+			'apply_payment_or_refund_from_registration_details'
1019
+		);
1020
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1021
+			'ee_delete_payments',
1022
+			'delete_payment_from_registration_details'
1023
+		);
1024
+
1025
+		// get line table
1026
+		EEH_Autoloader::register_line_item_display_autoloaders();
1027
+		$Line_Item_Display = new EE_Line_Item_Display(
1028
+			'admin_table',
1029
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1030
+		);
1031
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1032
+			$this->_transaction->total_line_item()
1033
+		);
1034
+		$this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')
1035
+															   ->get('REG_code');
1036
+
1037
+		// process taxes
1038
+		$taxes = $this->_transaction->get_many_related(
1039
+			'Line_Item',
1040
+			array(array('LIN_type' => EEM_Line_Item::type_tax))
1041
+		);
1042
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
+
1044
+		$this->_template_args['grand_total'] = EEH_Template::format_currency(
1045
+			$this->_transaction->get('TXN_total'),
1046
+			false,
1047
+			false
1048
+		);
1049
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1050
+		$this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID');
1051
+
1052
+		// process payment details
1053
+		$payments = $this->_transaction->get_many_related('Payment');
1054
+		if (! empty($payments)) {
1055
+			$this->_template_args['payments'] = $payments;
1056
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1057
+		} else {
1058
+			$this->_template_args['payments'] = false;
1059
+			$this->_template_args['existing_reg_payments'] = array();
1060
+		}
1061
+
1062
+		$this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1063
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1064
+			array('action' => 'espresso_delete_payment'),
1065
+			TXN_ADMIN_URL
1066
+		);
1067
+
1068
+		if (isset($txn_details['invoice_number'])) {
1069
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1070
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1071
+				'Invoice Number',
1072
+				'event_espresso'
1073
+			);
1074
+		}
1075
+
1076
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1077
+			->get_first_related('Registration')
1078
+			->get('REG_session');
1079
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1080
+			'Registration Session',
1081
+			'event_espresso'
1082
+		);
1083
+
1084
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1085
+			? $this->_session['ip_address']
1086
+			: '';
1087
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1088
+			'Transaction placed from IP',
1089
+			'event_espresso'
1090
+		);
1091
+
1092
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1093
+			? $this->_session['user_agent']
1094
+			: '';
1095
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1096
+			'Registrant User Agent',
1097
+			'event_espresso'
1098
+		);
1099
+
1100
+		$reg_steps = '<ul>';
1101
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1102
+			if ($reg_step_status === true) {
1103
+				$reg_steps .= '<li style="color:#70cc50">'
1104
+							  . sprintf(
1105
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1106
+								  ucwords(str_replace('_', ' ', $reg_step))
1107
+							  )
1108
+							  . '</li>';
1109
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1110
+				$reg_steps .= '<li style="color:#2EA2CC">'
1111
+							  . sprintf(
1112
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1113
+								  ucwords(str_replace('_', ' ', $reg_step)),
1114
+								  date(
1115
+									  get_option('date_format') . ' ' . get_option('time_format'),
1116
+									  ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1117
+								  )
1118
+							  )
1119
+							  . '</li>';
1120
+			} else {
1121
+				$reg_steps .= '<li style="color:#E76700">'
1122
+							  . sprintf(
1123
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1124
+								  ucwords(str_replace('_', ' ', $reg_step))
1125
+							  )
1126
+							  . '</li>';
1127
+			}
1128
+		}
1129
+		$reg_steps .= '</ul>';
1130
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1131
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1132
+			'Registration Step Progress',
1133
+			'event_espresso'
1134
+		);
1135
+
1136
+
1137
+		$this->_get_registrations_to_apply_payment_to();
1138
+		$this->_get_payment_methods($payments);
1139
+		$this->_get_payment_status_array();
1140
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1141
+
1142
+		$this->_template_args['transaction_form_url'] = add_query_arg(
1143
+			array(
1144
+				'action'  => 'edit_transaction',
1145
+				'process' => 'transaction',
1146
+			),
1147
+			TXN_ADMIN_URL
1148
+		);
1149
+		$this->_template_args['apply_payment_form_url'] = add_query_arg(
1150
+			array(
1151
+				'page'   => 'espresso_transactions',
1152
+				'action' => 'espresso_apply_payment',
1153
+			),
1154
+			WP_AJAX_URL
1155
+		);
1156
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1157
+			array(
1158
+				'page'   => 'espresso_transactions',
1159
+				'action' => 'espresso_delete_payment',
1160
+			),
1161
+			WP_AJAX_URL
1162
+		);
1163
+
1164
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1165
+
1166
+		// 'espresso_delete_payment_nonce'
1167
+
1168
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1169
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1170
+	}
1171
+
1172
+
1173
+	/**
1174
+	 * _get_registration_payment_IDs
1175
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1176
+	 *
1177
+	 * @access protected
1178
+	 * @param EE_Payment[] $payments
1179
+	 * @return array
1180
+	 * @throws EE_Error
1181
+	 * @throws InvalidArgumentException
1182
+	 * @throws InvalidDataTypeException
1183
+	 * @throws InvalidInterfaceException
1184
+	 * @throws ReflectionException
1185
+	 */
1186
+	protected function _get_registration_payment_IDs($payments = array())
1187
+	{
1188
+		$existing_reg_payments = array();
1189
+		// get all reg payments for these payments
1190
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1191
+			array(
1192
+				array(
1193
+					'PAY_ID' => array(
1194
+						'IN',
1195
+						array_keys($payments),
1196
+					),
1197
+				),
1198
+			)
1199
+		);
1200
+		if (! empty($reg_payments)) {
1201
+			foreach ($payments as $payment) {
1202
+				if (! $payment instanceof EE_Payment) {
1203
+					continue;
1204
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1205
+					$existing_reg_payments[ $payment->ID() ] = array();
1206
+				}
1207
+				foreach ($reg_payments as $reg_payment) {
1208
+					if ($reg_payment instanceof EE_Registration_Payment
1209
+						&& $reg_payment->payment_ID() === $payment->ID()
1210
+					) {
1211
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1212
+					}
1213
+				}
1214
+			}
1215
+		}
1216
+
1217
+		return $existing_reg_payments;
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * _get_registrations_to_apply_payment_to
1223
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1224
+	 * which allows the admin to only apply the payment to the specific registrations
1225
+	 *
1226
+	 * @access protected
1227
+	 * @return void
1228
+	 * @throws \EE_Error
1229
+	 */
1230
+	protected function _get_registrations_to_apply_payment_to()
1231
+	{
1232
+		// we want any registration with an active status (ie: not deleted or cancelled)
1233
+		$query_params = array(
1234
+			array(
1235
+				'STS_ID' => array(
1236
+					'IN',
1237
+					array(
1238
+						EEM_Registration::status_id_approved,
1239
+						EEM_Registration::status_id_pending_payment,
1240
+						EEM_Registration::status_id_not_approved,
1241
+					),
1242
+				),
1243
+			),
1244
+		);
1245
+		$registrations_to_apply_payment_to = EEH_HTML::br()
1246
+											 . EEH_HTML::div(
1247
+												 '',
1248
+												 'txn-admin-apply-payment-to-registrations-dv',
1249
+												 '',
1250
+												 'clear: both; margin: 1.5em 0 0; display: none;'
1251
+											 );
1252
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1253
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1254
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1255
+			EEH_HTML::tr(
1256
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1257
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1258
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1259
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1260
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1261
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1262
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1263
+			)
1264
+		);
1265
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1266
+		// get registrations for TXN
1267
+		$registrations = $this->_transaction->registrations($query_params);
1268
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1269
+		foreach ($registrations as $registration) {
1270
+			if ($registration instanceof EE_Registration) {
1271
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
1272
+					? $registration->attendee()->full_name()
1273
+					: esc_html__('Unknown Attendee', 'event_espresso');
1274
+				$owing = $registration->final_price() - $registration->paid();
1275
+				$taxable = $registration->ticket()->taxable()
1276
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1277
+					: '';
1278
+				$checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1279
+					? ' checked="checked"'
1280
+					: '';
1281
+				$disabled = $registration->final_price() > 0 ? '' : ' disabled';
1282
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1283
+					EEH_HTML::td($registration->ID()) .
1284
+					EEH_HTML::td($attendee_name) .
1285
+					EEH_HTML::td(
1286
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1287
+					) .
1288
+					EEH_HTML::td($registration->event_name()) .
1289
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1290
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1291
+					EEH_HTML::td(
1292
+						'<input type="checkbox" value="' . $registration->ID()
1293
+						. '" name="txn_admin_payment[registrations]"'
1294
+						. $checked . $disabled . '>',
1295
+						'',
1296
+						'jst-cntr'
1297
+					),
1298
+					'apply-payment-registration-row-' . $registration->ID()
1299
+				);
1300
+			}
1301
+		}
1302
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1303
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1304
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1305
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1306
+			esc_html__(
1307
+				'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.',
1308
+				'event_espresso'
1309
+			),
1310
+			'',
1311
+			'clear description'
1312
+		);
1313
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1314
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * _get_reg_status_selection
1320
+	 *
1321
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1322
+	 *         instead of events.
1323
+	 * @access protected
1324
+	 * @return void
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	protected function _get_reg_status_selection()
1328
+	{
1329
+		// first get all possible statuses
1330
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1331
+		// let's add a "don't change" option.
1332
+		$status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1333
+		$status_array = array_merge($status_array, $statuses);
1334
+		$this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1335
+			'txn_reg_status_change[reg_status]',
1336
+			$status_array,
1337
+			'NAN',
1338
+			'id="txn-admin-payment-reg-status-inp"',
1339
+			'txn-reg-status-change-reg-status'
1340
+		);
1341
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1342
+			'delete_txn_reg_status_change[reg_status]',
1343
+			$status_array,
1344
+			'NAN',
1345
+			'delete-txn-admin-payment-reg-status-inp',
1346
+			'delete-txn-reg-status-change-reg-status'
1347
+		);
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 *    _get_payment_methods
1353
+	 * Gets all the payment methods available generally, or the ones that are already
1354
+	 * selected on these payments (in case their payment methods are no longer active).
1355
+	 * Has the side-effect of updating the template args' payment_methods item
1356
+	 *
1357
+	 * @access private
1358
+	 * @param EE_Payment[] to show on this page
1359
+	 * @return void
1360
+	 * @throws EE_Error
1361
+	 * @throws InvalidArgumentException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 * @throws ReflectionException
1365
+	 */
1366
+	private function _get_payment_methods($payments = array())
1367
+	{
1368
+		$payment_methods_of_payments = array();
1369
+		foreach ($payments as $payment) {
1370
+			if ($payment instanceof EE_Payment) {
1371
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1372
+			}
1373
+		}
1374
+		if ($payment_methods_of_payments) {
1375
+			$query_args = array(
1376
+				array(
1377
+					'OR*payment_method_for_payment' => array(
1378
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1379
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1380
+					),
1381
+				),
1382
+			);
1383
+		} else {
1384
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1385
+		}
1386
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * txn_attendees_meta_box
1392
+	 *    generates HTML for the Attendees Transaction main meta box
1393
+	 *
1394
+	 * @access public
1395
+	 * @param WP_Post $post
1396
+	 * @param array   $metabox
1397
+	 * @return void
1398
+	 * @throws DomainException
1399
+	 * @throws EE_Error
1400
+	 */
1401
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1402
+	{
1403
+
1404
+		/** @noinspection NonSecureExtractUsageInspection */
1405
+		extract($metabox['args']);
1406
+		$this->_template_args['post'] = $post;
1407
+		$this->_template_args['event_attendees'] = array();
1408
+		// process items in cart
1409
+		$line_items = $this->_transaction->get_many_related(
1410
+			'Line_Item',
1411
+			array(array('LIN_type' => 'line-item'))
1412
+		);
1413
+		if (! empty($line_items)) {
1414
+			foreach ($line_items as $item) {
1415
+				if ($item instanceof EE_Line_Item) {
1416
+					switch ($item->OBJ_type()) {
1417
+						case 'Event':
1418
+							break;
1419
+						case 'Ticket':
1420
+							$ticket = $item->ticket();
1421
+							// right now we're only handling tickets here.
1422
+							// Cause its expected that only tickets will have attendees right?
1423
+							if (! $ticket instanceof EE_Ticket) {
1424
+								continue;
1425
+							}
1426
+							try {
1427
+								$event_name = $ticket->get_event_name();
1428
+							} catch (Exception $e) {
1429
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1430
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1431
+							}
1432
+							$event_name .= ' - ' . $item->get('LIN_name');
1433
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1434
+							// now get all of the registrations for this transaction that use this ticket
1435
+							$registrations = $ticket->get_many_related(
1436
+								'Registration',
1437
+								array(array('TXN_ID' => $this->_transaction->ID()))
1438
+							);
1439
+							foreach ($registrations as $registration) {
1440
+								if (! $registration instanceof EE_Registration) {
1441
+									continue;
1442
+								}
1443
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1444
+									= $registration->status_ID();
1445
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1446
+									= $registration->count();
1447
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1448
+									= $event_name;
1449
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1450
+									= $ticket_price;
1451
+								// attendee info
1452
+								$attendee = $registration->get_first_related('Attendee');
1453
+								if ($attendee instanceof EE_Attendee) {
1454
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1455
+										= $attendee->ID();
1456
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1457
+										= $attendee->full_name();
1458
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1459
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1460
+										  . esc_html__(
1461
+											  ' Event',
1462
+											  'event_espresso'
1463
+										  )
1464
+										  . '">' . $attendee->email() . '</a>';
1465
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1466
+										= EEH_Address::format($attendee, 'inline', false, false);
1467
+								} else {
1468
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1469
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1470
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1471
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1472
+								}
1473
+							}
1474
+							break;
1475
+					}
1476
+				}
1477
+			}
1478
+
1479
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1480
+				array(
1481
+					'action'  => 'edit_transaction',
1482
+					'process' => 'attendees',
1483
+				),
1484
+				TXN_ADMIN_URL
1485
+			);
1486
+			echo EEH_Template::display_template(
1487
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1488
+				$this->_template_args,
1489
+				true
1490
+			);
1491
+		} else {
1492
+			echo sprintf(
1493
+				esc_html__(
1494
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1495
+					'event_espresso'
1496
+				),
1497
+				'<p class="important-notice">',
1498
+				'</p>'
1499
+			);
1500
+		}
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * txn_registrant_side_meta_box
1506
+	 * generates HTML for the Edit Transaction side meta box
1507
+	 *
1508
+	 * @access public
1509
+	 * @return void
1510
+	 * @throws DomainException
1511
+	 * @throws EE_Error
1512
+	 * @throws InvalidArgumentException
1513
+	 * @throws InvalidDataTypeException
1514
+	 * @throws InvalidInterfaceException
1515
+	 * @throws ReflectionException
1516
+	 */
1517
+	public function txn_registrant_side_meta_box()
1518
+	{
1519
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1520
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1521
+			: null;
1522
+		if (! $primary_att instanceof EE_Attendee) {
1523
+			$this->_template_args['no_attendee_message'] = esc_html__(
1524
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1525
+				'event_espresso'
1526
+			);
1527
+			$primary_att = EEM_Attendee::instance()->create_default_object();
1528
+		}
1529
+		$this->_template_args['ATT_ID'] = $primary_att->ID();
1530
+		$this->_template_args['prime_reg_fname'] = $primary_att->fname();
1531
+		$this->_template_args['prime_reg_lname'] = $primary_att->lname();
1532
+		$this->_template_args['prime_reg_email'] = $primary_att->email();
1533
+		$this->_template_args['prime_reg_phone'] = $primary_att->phone();
1534
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1535
+			array(
1536
+				'action' => 'edit_attendee',
1537
+				'post'   => $primary_att->ID(),
1538
+			),
1539
+			REG_ADMIN_URL
1540
+		);
1541
+		// get formatted address for registrant
1542
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1543
+		echo EEH_Template::display_template(
1544
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1545
+			$this->_template_args,
1546
+			true
1547
+		);
1548
+	}
1549
+
1550
+
1551
+	/**
1552
+	 * txn_billing_info_side_meta_box
1553
+	 *    generates HTML for the Edit Transaction side meta box
1554
+	 *
1555
+	 * @access public
1556
+	 * @return void
1557
+	 * @throws DomainException
1558
+	 * @throws EE_Error
1559
+	 */
1560
+	public function txn_billing_info_side_meta_box()
1561
+	{
1562
+
1563
+		$this->_template_args['billing_form'] = $this->_transaction->billing_info();
1564
+		$this->_template_args['billing_form_url'] = add_query_arg(
1565
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1566
+			TXN_ADMIN_URL
1567
+		);
1568
+
1569
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1570
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1571
+	}
1572
+
1573
+
1574
+	/**
1575
+	 * apply_payments_or_refunds
1576
+	 *    registers a payment or refund made towards a transaction
1577
+	 *
1578
+	 * @access public
1579
+	 * @return void
1580
+	 * @throws EE_Error
1581
+	 * @throws InvalidArgumentException
1582
+	 * @throws ReflectionException
1583
+	 * @throws RuntimeException
1584
+	 * @throws InvalidDataTypeException
1585
+	 * @throws InvalidInterfaceException
1586
+	 */
1587
+	public function apply_payments_or_refunds()
1588
+	{
1589
+		$json_response_data = array('return_data' => false);
1590
+		$valid_data = $this->_validate_payment_request_data();
1591
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1592
+			'ee_edit_payments',
1593
+			'apply_payment_or_refund_from_registration_details'
1594
+		);
1595
+		if (! empty($valid_data) && $has_access) {
1596
+			$PAY_ID = $valid_data['PAY_ID'];
1597
+			// save  the new payment
1598
+			$payment = $this->_create_payment_from_request_data($valid_data);
1599
+			// get the TXN for this payment
1600
+			$transaction = $payment->transaction();
1601
+			// verify transaction
1602
+			if ($transaction instanceof EE_Transaction) {
1603
+				// calculate_total_payments_and_update_status
1604
+				$this->_process_transaction_payments($transaction);
1605
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1606
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1607
+				// apply payment to registrations (if applicable)
1608
+				if (! empty($REG_IDs)) {
1609
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1610
+					$this->_maybe_send_notifications();
1611
+					// now process status changes for the same registrations
1612
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1613
+				}
1614
+				$this->_maybe_send_notifications($payment);
1615
+				// prepare to render page
1616
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1617
+				do_action(
1618
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1619
+					$transaction,
1620
+					$payment
1621
+				);
1622
+			} else {
1623
+				EE_Error::add_error(
1624
+					esc_html__(
1625
+						'A valid Transaction for this payment could not be retrieved.',
1626
+						'event_espresso'
1627
+					),
1628
+					__FILE__,
1629
+					__FUNCTION__,
1630
+					__LINE__
1631
+				);
1632
+			}
1633
+		} else {
1634
+			if ($has_access) {
1635
+				EE_Error::add_error(
1636
+					esc_html__(
1637
+						'The payment form data could not be processed. Please try again.',
1638
+						'event_espresso'
1639
+					),
1640
+					__FILE__,
1641
+					__FUNCTION__,
1642
+					__LINE__
1643
+				);
1644
+			} else {
1645
+				EE_Error::add_error(
1646
+					esc_html__(
1647
+						'You do not have access to apply payments or refunds to a registration.',
1648
+						'event_espresso'
1649
+					),
1650
+					__FILE__,
1651
+					__FUNCTION__,
1652
+					__LINE__
1653
+				);
1654
+			}
1655
+		}
1656
+		$notices = EE_Error::get_notices(
1657
+			false,
1658
+			false,
1659
+			false
1660
+		);
1661
+		$this->_template_args = array(
1662
+			'data'    => $json_response_data,
1663
+			'error'   => $notices['errors'],
1664
+			'success' => $notices['success'],
1665
+		);
1666
+		$this->_return_json();
1667
+	}
1668
+
1669
+
1670
+	/**
1671
+	 * _validate_payment_request_data
1672
+	 *
1673
+	 * @return array
1674
+	 * @throws EE_Error
1675
+	 */
1676
+	protected function _validate_payment_request_data()
1677
+	{
1678
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1679
+			return false;
1680
+		}
1681
+		$payment_form = $this->_generate_payment_form_section();
1682
+		try {
1683
+			if ($payment_form->was_submitted()) {
1684
+				$payment_form->receive_form_submission();
1685
+				if (! $payment_form->is_valid()) {
1686
+					$submission_error_messages = array();
1687
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1688
+						if ($validation_error instanceof EE_Validation_Error) {
1689
+							$submission_error_messages[] = sprintf(
1690
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1691
+								$validation_error->get_form_section()->html_label_text(),
1692
+								$validation_error->getMessage()
1693
+							);
1694
+						}
1695
+					}
1696
+					EE_Error::add_error(
1697
+						implode('<br />', $submission_error_messages),
1698
+						__FILE__,
1699
+						__FUNCTION__,
1700
+						__LINE__
1701
+					);
1702
+
1703
+					return array();
1704
+				}
1705
+			}
1706
+		} catch (EE_Error $e) {
1707
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1708
+
1709
+			return array();
1710
+		}
1711
+
1712
+		return $payment_form->valid_data();
1713
+	}
1714
+
1715
+
1716
+	/**
1717
+	 * _generate_payment_form_section
1718
+	 *
1719
+	 * @return EE_Form_Section_Proper
1720
+	 * @throws EE_Error
1721
+	 */
1722
+	protected function _generate_payment_form_section()
1723
+	{
1724
+		return new EE_Form_Section_Proper(
1725
+			array(
1726
+				'name'        => 'txn_admin_payment',
1727
+				'subsections' => array(
1728
+					'PAY_ID'          => new EE_Text_Input(
1729
+						array(
1730
+							'default'               => 0,
1731
+							'required'              => false,
1732
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1733
+							'validation_strategies' => array(new EE_Int_Normalization()),
1734
+						)
1735
+					),
1736
+					'TXN_ID'          => new EE_Text_Input(
1737
+						array(
1738
+							'default'               => 0,
1739
+							'required'              => true,
1740
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1741
+							'validation_strategies' => array(new EE_Int_Normalization()),
1742
+						)
1743
+					),
1744
+					'type'            => new EE_Text_Input(
1745
+						array(
1746
+							'default'               => 1,
1747
+							'required'              => true,
1748
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1749
+							'validation_strategies' => array(new EE_Int_Normalization()),
1750
+						)
1751
+					),
1752
+					'amount'          => new EE_Text_Input(
1753
+						array(
1754
+							'default'               => 0,
1755
+							'required'              => true,
1756
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1757
+							'validation_strategies' => array(new EE_Float_Normalization()),
1758
+						)
1759
+					),
1760
+					'status'          => new EE_Text_Input(
1761
+						array(
1762
+							'default'         => EEM_Payment::status_id_approved,
1763
+							'required'        => true,
1764
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1765
+						)
1766
+					),
1767
+					'PMD_ID'          => new EE_Text_Input(
1768
+						array(
1769
+							'default'               => 2,
1770
+							'required'              => true,
1771
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1772
+							'validation_strategies' => array(new EE_Int_Normalization()),
1773
+						)
1774
+					),
1775
+					'date'            => new EE_Text_Input(
1776
+						array(
1777
+							'default'         => time(),
1778
+							'required'        => true,
1779
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1780
+						)
1781
+					),
1782
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1783
+						array(
1784
+							'default'               => '',
1785
+							'required'              => false,
1786
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1787
+							'validation_strategies' => array(
1788
+								new EE_Max_Length_Validation_Strategy(
1789
+									esc_html__('Input too long', 'event_espresso'),
1790
+									100
1791
+								),
1792
+							),
1793
+						)
1794
+					),
1795
+					'po_number'       => new EE_Text_Input(
1796
+						array(
1797
+							'default'               => '',
1798
+							'required'              => false,
1799
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1800
+							'validation_strategies' => array(
1801
+								new EE_Max_Length_Validation_Strategy(
1802
+									esc_html__('Input too long', 'event_espresso'),
1803
+									100
1804
+								),
1805
+							),
1806
+						)
1807
+					),
1808
+					'accounting'      => new EE_Text_Input(
1809
+						array(
1810
+							'default'               => '',
1811
+							'required'              => false,
1812
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1813
+							'validation_strategies' => array(
1814
+								new EE_Max_Length_Validation_Strategy(
1815
+									esc_html__('Input too long', 'event_espresso'),
1816
+									100
1817
+								),
1818
+							),
1819
+						)
1820
+					),
1821
+				),
1822
+			)
1823
+		);
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * _create_payment_from_request_data
1829
+	 *
1830
+	 * @param array $valid_data
1831
+	 * @return EE_Payment
1832
+	 * @throws EE_Error
1833
+	 */
1834
+	protected function _create_payment_from_request_data($valid_data)
1835
+	{
1836
+		$PAY_ID = $valid_data['PAY_ID'];
1837
+		// get payment amount
1838
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1839
+		// payments have a type value of 1 and refunds have a type value of -1
1840
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1841
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1842
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1843
+		$date = $valid_data['date']
1844
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1845
+			: date('Y-m-d g:i a', current_time('timestamp'));
1846
+		$payment = EE_Payment::new_instance(
1847
+			array(
1848
+				'TXN_ID'              => $valid_data['TXN_ID'],
1849
+				'STS_ID'              => $valid_data['status'],
1850
+				'PAY_timestamp'       => $date,
1851
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1852
+				'PMD_ID'              => $valid_data['PMD_ID'],
1853
+				'PAY_amount'          => $amount,
1854
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1855
+				'PAY_po_number'       => $valid_data['po_number'],
1856
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1857
+				'PAY_details'         => $valid_data,
1858
+				'PAY_ID'              => $PAY_ID,
1859
+			),
1860
+			'',
1861
+			array('Y-m-d', 'g:i a')
1862
+		);
1863
+
1864
+		if (! $payment->save()) {
1865
+			EE_Error::add_error(
1866
+				sprintf(
1867
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1868
+					$payment->ID()
1869
+				),
1870
+				__FILE__,
1871
+				__FUNCTION__,
1872
+				__LINE__
1873
+			);
1874
+		}
1875
+
1876
+		return $payment;
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * _process_transaction_payments
1882
+	 *
1883
+	 * @param \EE_Transaction $transaction
1884
+	 * @return void
1885
+	 * @throws EE_Error
1886
+	 * @throws InvalidArgumentException
1887
+	 * @throws ReflectionException
1888
+	 * @throws InvalidDataTypeException
1889
+	 * @throws InvalidInterfaceException
1890
+	 */
1891
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1892
+	{
1893
+		/** @type EE_Transaction_Payments $transaction_payments */
1894
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1895
+		// update the transaction with this payment
1896
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1897
+			EE_Error::add_success(
1898
+				esc_html__(
1899
+					'The payment has been processed successfully.',
1900
+					'event_espresso'
1901
+				),
1902
+				__FILE__,
1903
+				__FUNCTION__,
1904
+				__LINE__
1905
+			);
1906
+		} else {
1907
+			EE_Error::add_error(
1908
+				esc_html__(
1909
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1910
+					'event_espresso'
1911
+				),
1912
+				__FILE__,
1913
+				__FUNCTION__,
1914
+				__LINE__
1915
+			);
1916
+		}
1917
+	}
1918
+
1919
+
1920
+	/**
1921
+	 * _get_REG_IDs_to_apply_payment_to
1922
+	 * returns a list of registration IDs that the payment will apply to
1923
+	 *
1924
+	 * @param \EE_Payment $payment
1925
+	 * @return array
1926
+	 * @throws EE_Error
1927
+	 */
1928
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1929
+	{
1930
+		$REG_IDs = array();
1931
+		// grab array of IDs for specific registrations to apply changes to
1932
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1933
+			$REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1934
+		}
1935
+		// nothing specified ? then get all reg IDs
1936
+		if (empty($REG_IDs)) {
1937
+			$registrations = $payment->transaction()->registrations();
1938
+			$REG_IDs = ! empty($registrations)
1939
+				? array_keys($registrations)
1940
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1941
+		}
1942
+
1943
+		// ensure that REG_IDs are integers and NOT strings
1944
+		return array_map('intval', $REG_IDs);
1945
+	}
1946
+
1947
+
1948
+	/**
1949
+	 * @return array
1950
+	 */
1951
+	public function existing_reg_payment_REG_IDs()
1952
+	{
1953
+		return $this->_existing_reg_payment_REG_IDs;
1954
+	}
1955
+
1956
+
1957
+	/**
1958
+	 * @param array $existing_reg_payment_REG_IDs
1959
+	 */
1960
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1961
+	{
1962
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1963
+	}
1964
+
1965
+
1966
+	/**
1967
+	 * _get_existing_reg_payment_REG_IDs
1968
+	 * returns a list of registration IDs that the payment is currently related to
1969
+	 * as recorded in the database
1970
+	 *
1971
+	 * @param \EE_Payment $payment
1972
+	 * @return array
1973
+	 * @throws EE_Error
1974
+	 */
1975
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1976
+	{
1977
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1978
+			// let's get any existing reg payment records for this payment
1979
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1980
+			// but we only want the REG IDs, so grab the array keys
1981
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1982
+				? array_keys($existing_reg_payment_REG_IDs)
1983
+				: array();
1984
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1985
+		}
1986
+
1987
+		return $this->existing_reg_payment_REG_IDs();
1988
+	}
1989
+
1990
+
1991
+	/**
1992
+	 * _remove_existing_registration_payments
1993
+	 * this calculates the difference between existing relations
1994
+	 * to the supplied payment and the new list registration IDs,
1995
+	 * removes any related registrations that no longer apply,
1996
+	 * and then updates the registration paid fields
1997
+	 *
1998
+	 * @param \EE_Payment $payment
1999
+	 * @param int         $PAY_ID
2000
+	 * @return bool;
2001
+	 * @throws EE_Error
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws ReflectionException
2004
+	 * @throws InvalidDataTypeException
2005
+	 * @throws InvalidInterfaceException
2006
+	 */
2007
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2008
+	{
2009
+		// newly created payments will have nothing recorded for $PAY_ID
2010
+		if ($PAY_ID == 0) {
2011
+			return false;
2012
+		}
2013
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2014
+		if (empty($existing_reg_payment_REG_IDs)) {
2015
+			return false;
2016
+		}
2017
+		/** @type EE_Transaction_Payments $transaction_payments */
2018
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2019
+
2020
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2021
+			$payment,
2022
+			array(
2023
+				array(
2024
+					'PAY_ID' => $payment->ID(),
2025
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2026
+				),
2027
+			)
2028
+		);
2029
+	}
2030
+
2031
+
2032
+	/**
2033
+	 * _update_registration_payments
2034
+	 * this applies the payments to the selected registrations
2035
+	 * but only if they have not already been paid for
2036
+	 *
2037
+	 * @param  EE_Transaction $transaction
2038
+	 * @param \EE_Payment     $payment
2039
+	 * @param array           $REG_IDs
2040
+	 * @return void
2041
+	 * @throws EE_Error
2042
+	 * @throws InvalidArgumentException
2043
+	 * @throws ReflectionException
2044
+	 * @throws RuntimeException
2045
+	 * @throws InvalidDataTypeException
2046
+	 * @throws InvalidInterfaceException
2047
+	 */
2048
+	protected function _update_registration_payments(
2049
+		EE_Transaction $transaction,
2050
+		EE_Payment $payment,
2051
+		$REG_IDs = array()
2052
+	) {
2053
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2054
+		// so let's do that using our set of REG_IDs from the form
2055
+		$registration_query_where_params = array(
2056
+			'REG_ID' => array('IN', $REG_IDs),
2057
+		);
2058
+		// but add in some conditions regarding payment,
2059
+		// so that we don't apply payments to registrations that are free or have already been paid for
2060
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2061
+		if (! $payment->is_a_refund()) {
2062
+			$registration_query_where_params['REG_final_price'] = array('!=', 0);
2063
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2064
+		}
2065
+		$registrations = $transaction->registrations(array($registration_query_where_params));
2066
+		if (! empty($registrations)) {
2067
+			/** @type EE_Payment_Processor $payment_processor */
2068
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2069
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2070
+		}
2071
+	}
2072
+
2073
+
2074
+	/**
2075
+	 * _process_registration_status_change
2076
+	 * This processes requested registration status changes for all the registrations
2077
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2078
+	 *
2079
+	 * @param  EE_Transaction $transaction
2080
+	 * @param array           $REG_IDs
2081
+	 * @return bool
2082
+	 * @throws EE_Error
2083
+	 * @throws InvalidArgumentException
2084
+	 * @throws ReflectionException
2085
+	 * @throws InvalidDataTypeException
2086
+	 * @throws InvalidInterfaceException
2087
+	 */
2088
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2089
+	{
2090
+		// first if there is no change in status then we get out.
2091
+		if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2092
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2093
+		) {
2094
+			// no error message, no change requested, just nothing to do man.
2095
+			return false;
2096
+		}
2097
+		/** @type EE_Transaction_Processor $transaction_processor */
2098
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2099
+
2100
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2101
+		return $transaction_processor->manually_update_registration_statuses(
2102
+			$transaction,
2103
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2104
+			array(array('REG_ID' => array('IN', $REG_IDs)))
2105
+		);
2106
+	}
2107
+
2108
+
2109
+	/**
2110
+	 * _build_payment_json_response
2111
+	 *
2112
+	 * @access public
2113
+	 * @param \EE_Payment $payment
2114
+	 * @param array       $REG_IDs
2115
+	 * @param bool | null $delete_txn_reg_status_change
2116
+	 * @return array
2117
+	 * @throws EE_Error
2118
+	 * @throws InvalidArgumentException
2119
+	 * @throws InvalidDataTypeException
2120
+	 * @throws InvalidInterfaceException
2121
+	 * @throws ReflectionException
2122
+	 */
2123
+	protected function _build_payment_json_response(
2124
+		EE_Payment $payment,
2125
+		$REG_IDs = array(),
2126
+		$delete_txn_reg_status_change = null
2127
+	) {
2128
+		// was the payment deleted ?
2129
+		if (is_bool($delete_txn_reg_status_change)) {
2130
+			return array(
2131
+				'PAY_ID'                       => $payment->ID(),
2132
+				'amount'                       => $payment->amount(),
2133
+				'total_paid'                   => $payment->transaction()->paid(),
2134
+				'txn_status'                   => $payment->transaction()->status_ID(),
2135
+				'pay_status'                   => $payment->STS_ID(),
2136
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2137
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2138
+			);
2139
+		} else {
2140
+			$this->_get_payment_status_array();
2141
+
2142
+			return array(
2143
+				'amount'           => $payment->amount(),
2144
+				'total_paid'       => $payment->transaction()->paid(),
2145
+				'txn_status'       => $payment->transaction()->status_ID(),
2146
+				'pay_status'       => $payment->STS_ID(),
2147
+				'PAY_ID'           => $payment->ID(),
2148
+				'STS_ID'           => $payment->STS_ID(),
2149
+				'status'           => self::$_pay_status[ $payment->STS_ID() ],
2150
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2151
+				'method'           => strtoupper($payment->source()),
2152
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2153
+				'gateway'          => $payment->payment_method()
2154
+					? $payment->payment_method()->admin_name()
2155
+					: esc_html__("Unknown", 'event_espresso'),
2156
+				'gateway_response' => $payment->gateway_response(),
2157
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2158
+				'po_number'        => $payment->po_number(),
2159
+				'extra_accntng'    => $payment->extra_accntng(),
2160
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2161
+			);
2162
+		}
2163
+	}
2164
+
2165
+
2166
+	/**
2167
+	 * delete_payment
2168
+	 *    delete a payment or refund made towards a transaction
2169
+	 *
2170
+	 * @access public
2171
+	 * @return void
2172
+	 * @throws EE_Error
2173
+	 * @throws InvalidArgumentException
2174
+	 * @throws ReflectionException
2175
+	 * @throws InvalidDataTypeException
2176
+	 * @throws InvalidInterfaceException
2177
+	 */
2178
+	public function delete_payment()
2179
+	{
2180
+		$json_response_data = array('return_data' => false);
2181
+		$PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2182
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2183
+			: 0;
2184
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2185
+			'ee_delete_payments',
2186
+			'delete_payment_from_registration_details'
2187
+		);
2188
+		if ($PAY_ID && $can_delete) {
2189
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2190
+				? $this->_req_data['delete_txn_reg_status_change']
2191
+				: false;
2192
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2193
+			if ($payment instanceof EE_Payment) {
2194
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2195
+				/** @type EE_Transaction_Payments $transaction_payments */
2196
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2197
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2198
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2199
+						$payment,
2200
+						$REG_IDs,
2201
+						$delete_txn_reg_status_change
2202
+					);
2203
+					if ($delete_txn_reg_status_change) {
2204
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2205
+						// MAKE sure we also add the delete_txn_req_status_change to the
2206
+						// $_REQUEST global because that's how messages will be looking for it.
2207
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2208
+						$this->_maybe_send_notifications();
2209
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2210
+					}
2211
+				}
2212
+			} else {
2213
+				EE_Error::add_error(
2214
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2215
+					__FILE__,
2216
+					__FUNCTION__,
2217
+					__LINE__
2218
+				);
2219
+			}
2220
+		} else {
2221
+			if ($can_delete) {
2222
+				EE_Error::add_error(
2223
+					esc_html__(
2224
+						'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2225
+						'event_espresso'
2226
+					),
2227
+					__FILE__,
2228
+					__FUNCTION__,
2229
+					__LINE__
2230
+				);
2231
+			} else {
2232
+				EE_Error::add_error(
2233
+					esc_html__(
2234
+						'You do not have access to delete a payment.',
2235
+						'event_espresso'
2236
+					),
2237
+					__FILE__,
2238
+					__FUNCTION__,
2239
+					__LINE__
2240
+				);
2241
+			}
2242
+		}
2243
+		$notices = EE_Error::get_notices(false, false, false);
2244
+		$this->_template_args = array(
2245
+			'data'      => $json_response_data,
2246
+			'success'   => $notices['success'],
2247
+			'error'     => $notices['errors'],
2248
+			'attention' => $notices['attention'],
2249
+		);
2250
+		$this->_return_json();
2251
+	}
2252
+
2253
+
2254
+	/**
2255
+	 * _registration_payment_data_array
2256
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2257
+	 *
2258
+	 * @access protected
2259
+	 * @param array $REG_IDs
2260
+	 * @return array
2261
+	 * @throws EE_Error
2262
+	 * @throws InvalidArgumentException
2263
+	 * @throws InvalidDataTypeException
2264
+	 * @throws InvalidInterfaceException
2265
+	 * @throws ReflectionException
2266
+	 */
2267
+	protected function _registration_payment_data_array($REG_IDs)
2268
+	{
2269
+		$registration_payment_data = array();
2270
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2271
+		if (! empty($REG_IDs)) {
2272
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2273
+			foreach ($registrations as $registration) {
2274
+				if ($registration instanceof EE_Registration) {
2275
+					$registration_payment_data[ $registration->ID() ] = array(
2276
+						'paid'  => $registration->pretty_paid(),
2277
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2278
+					);
2279
+				}
2280
+			}
2281
+		}
2282
+
2283
+		return $registration_payment_data;
2284
+	}
2285
+
2286
+
2287
+	/**
2288
+	 * _maybe_send_notifications
2289
+	 * determines whether or not the admin has indicated that notifications should be sent.
2290
+	 * If so, will toggle a filter switch for delivering registration notices.
2291
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2292
+	 *
2293
+	 * @access protected
2294
+	 * @param \EE_Payment | null $payment
2295
+	 */
2296
+	protected function _maybe_send_notifications($payment = null)
2297
+	{
2298
+		switch ($payment instanceof EE_Payment) {
2299
+			// payment notifications
2300
+			case true:
2301
+				if (isset(
2302
+					$this->_req_data['txn_payments'],
2303
+					$this->_req_data['txn_payments']['send_notifications']
2304
+				)
2305
+					&& filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2306
+				) {
2307
+					$this->_process_payment_notification($payment);
2308
+				}
2309
+				break;
2310
+			// registration notifications
2311
+			case false:
2312
+				if (isset(
2313
+					$this->_req_data['txn_reg_status_change'],
2314
+					$this->_req_data['txn_reg_status_change']['send_notifications']
2315
+				)
2316
+					&& filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2317
+				) {
2318
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2319
+				}
2320
+				break;
2321
+		}
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * _send_payment_reminder
2327
+	 *    generates HTML for the View Transaction Details Admin page
2328
+	 *
2329
+	 * @access protected
2330
+	 * @return void
2331
+	 * @throws EE_Error
2332
+	 * @throws InvalidArgumentException
2333
+	 * @throws InvalidDataTypeException
2334
+	 * @throws InvalidInterfaceException
2335
+	 */
2336
+	protected function _send_payment_reminder()
2337
+	{
2338
+		$TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2339
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2340
+		$query_args = isset($this->_req_data['redirect_to']) ? array(
2341
+			'action' => $this->_req_data['redirect_to'],
2342
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2343
+		) : array();
2344
+		do_action(
2345
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2346
+			$transaction
2347
+		);
2348
+		$this->_redirect_after_action(
2349
+			false,
2350
+			esc_html__('payment reminder', 'event_espresso'),
2351
+			esc_html__('sent', 'event_espresso'),
2352
+			$query_args,
2353
+			true
2354
+		);
2355
+	}
2356
+
2357
+
2358
+	/**
2359
+	 *  get_transactions
2360
+	 *    get transactions for given parameters (used by list table)
2361
+	 *
2362
+	 * @param  int     $perpage how many transactions displayed per page
2363
+	 * @param  boolean $count   return the count or objects
2364
+	 * @param string   $view
2365
+	 * @return mixed int = count || array of transaction objects
2366
+	 * @throws EE_Error
2367
+	 * @throws InvalidArgumentException
2368
+	 * @throws InvalidDataTypeException
2369
+	 * @throws InvalidInterfaceException
2370
+	 */
2371
+	public function get_transactions($perpage, $count = false, $view = '')
2372
+	{
2373
+
2374
+		$TXN = EEM_Transaction::instance();
2375
+
2376
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2377
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2378
+			: date(
2379
+				'm/d/Y',
2380
+				strtotime('-10 year')
2381
+			);
2382
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
2383
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2384
+			: date('m/d/Y');
2385
+
2386
+		// make sure our timestamps start and end right at the boundaries for each day
2387
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2388
+		$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2389
+
2390
+
2391
+		// convert to timestamps
2392
+		$start_date = strtotime($start_date);
2393
+		$end_date = strtotime($end_date);
2394
+
2395
+		// makes sure start date is the lowest value and vice versa
2396
+		$start_date = min($start_date, $end_date);
2397
+		$end_date = max($start_date, $end_date);
2398
+
2399
+		// convert to correct format for query
2400
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2401
+			'TXN_timestamp',
2402
+			date('Y-m-d H:i:s', $start_date),
2403
+			'Y-m-d H:i:s'
2404
+		);
2405
+		$end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2406
+			'TXN_timestamp',
2407
+			date('Y-m-d H:i:s', $end_date),
2408
+			'Y-m-d H:i:s'
2409
+		);
2410
+
2411
+
2412
+		// set orderby
2413
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2414
+
2415
+		switch ($this->_req_data['orderby']) {
2416
+			case 'TXN_ID':
2417
+				$orderby = 'TXN_ID';
2418
+				break;
2419
+			case 'ATT_fname':
2420
+				$orderby = 'Registration.Attendee.ATT_fname';
2421
+				break;
2422
+			case 'event_name':
2423
+				$orderby = 'Registration.Event.EVT_name';
2424
+				break;
2425
+			default: // 'TXN_timestamp'
2426
+				$orderby = 'TXN_timestamp';
2427
+		}
2428
+
2429
+		$sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2430
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2431
+		$per_page = ! empty($perpage) ? $perpage : 10;
2432
+		$per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2433
+
2434
+		$offset = ($current_page - 1) * $per_page;
2435
+		$limit = array($offset, $per_page);
2436
+
2437
+		$_where = array(
2438
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2439
+			'Registration.REG_count' => 1,
2440
+		);
2441
+
2442
+		if (isset($this->_req_data['EVT_ID'])) {
2443
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2444
+		}
2445
+
2446
+		if (isset($this->_req_data['s'])) {
2447
+			$search_string = '%' . $this->_req_data['s'] . '%';
2448
+			$_where['OR'] = array(
2449
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2450
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2451
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2452
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2453
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2454
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2455
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2456
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2457
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2458
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2459
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2460
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2461
+				'Registration.REG_code'               => array('LIKE', $search_string),
2462
+				'Registration.REG_count'              => array('LIKE', $search_string),
2463
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2464
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2465
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2466
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2467
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2468
+				'TXN_session_data'                    => array('LIKE', $search_string),
2469
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2470
+			);
2471
+		}
2472
+
2473
+		// failed transactions
2474
+		$failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2475
+				  || ($count && $view === 'failed');
2476
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2477
+					 || ($count && $view === 'abandoned');
2478
+
2479
+		if ($failed) {
2480
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2481
+		} elseif ($abandoned) {
2482
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2483
+		} else {
2484
+			$_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2485
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2486
+		}
2487
+
2488
+		$query_params = array(
2489
+			$_where,
2490
+			'order_by'                 => array($orderby => $sort),
2491
+			'limit'                    => $limit,
2492
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2493
+		);
2494
+
2495
+		$transactions = $count
2496
+			? $TXN->count(array($_where), 'TXN_ID', true)
2497
+			: $TXN->get_all($query_params);
2498
+
2499
+		return $transactions;
2500
+	}
2501 2501
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.70.rc.010');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.70.rc.010');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
entities/route_match/specifications/frontend/EspressoBlockRenderer.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@
 block discarded – undo
15 15
 class EspressoBlockRenderer extends RouteMatchSpecification
16 16
 {
17 17
 
18
-    /**
19
-     * returns true if current request matches specification
20
-     *
21
-     * @since $VID:$
22
-     * @return boolean
23
-     */
24
-    public function isMatchingRoute()
25
-    {
26
-        return strpos(
27
-            $this->request->requestUri(),
28
-            'wp-json/wp/v2/block-renderer/eventespresso'
29
-        ) !== false
30
-            || strpos(
31
-                $this->request->requestUri(),
32
-                'wp-json/gutenberg/v2/block-renderer/eventespresso'
33
-            ) !== false;
34
-    }
18
+	/**
19
+	 * returns true if current request matches specification
20
+	 *
21
+	 * @since $VID:$
22
+	 * @return boolean
23
+	 */
24
+	public function isMatchingRoute()
25
+	{
26
+		return strpos(
27
+			$this->request->requestUri(),
28
+			'wp-json/wp/v2/block-renderer/eventespresso'
29
+		) !== false
30
+			|| strpos(
31
+				$this->request->requestUri(),
32
+				'wp-json/gutenberg/v2/block-renderer/eventespresso'
33
+			) !== false;
34
+	}
35 35
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/EventAttendees.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -24,226 +24,226 @@
 block discarded – undo
24 24
 class EventAttendees extends Block
25 25
 {
26 26
 
27
-    const BLOCK_TYPE = 'event-attendees';
28
-
29
-    /**
30
-     * @var EspressoEventAttendees $shortcode
31
-     */
32
-    protected $shortcode;
33
-
34
-
35
-    /**
36
-     * EventAttendees constructor.
37
-     *
38
-     * @param CoreBlocksAssetManager $block_asset_manager
39
-     * @param RequestInterface       $request
40
-     * @param EspressoEventAttendees $shortcode
41
-     */
42
-    public function __construct(
43
-        CoreBlocksAssetManager $block_asset_manager,
44
-        RequestInterface $request,
45
-        EspressoEventAttendees $shortcode
46
-    ) {
47
-        parent::__construct($block_asset_manager, $request);
48
-        $this->shortcode = $shortcode;
49
-    }
50
-
51
-
52
-    /**
53
-     * Perform any early setup required by the block
54
-     * including setting the block type and supported post types
55
-     *
56
-     * @return void
57
-     */
58
-    public function initialize()
59
-    {
60
-        $this->setBlockType(self::BLOCK_TYPE);
61
-        $this->setSupportedRoutes(
62
-            array(
63
-                'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoStandardPostTypeEditor',
64
-                'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPostTypeEditor',
65
-                'EventEspresso\core\domain\entities\route_match\specifications\frontend\EspressoBlockRenderer',
66
-                'EventEspresso\core\domain\entities\route_match\specifications\frontend\AnyFrontendRequest'
67
-            )
68
-        );
69
-        $EVT_ID = $this->request->getRequestParam('page') === 'espresso_events'
70
-            ? $this->request->getRequestParam('post', 0)
71
-            : 0;
72
-        $this->setAttributes(
73
-            array(
74
-                'eventId'           => array(
75
-                    'type'    => 'number',
76
-                    'default' => $EVT_ID,
77
-                ),
78
-                'datetimeId'        => array(
79
-                    'type'    => 'number',
80
-                    'default' => 0,
81
-                ),
82
-                'ticketId'          => array(
83
-                    'type'    => 'number',
84
-                    'default' => 0,
85
-                ),
86
-                'status'            => array(
87
-                    'type'    => 'string',
88
-                    'default' => EEM_Registration::status_id_approved,
89
-                ),
90
-                'limit'             => array(
91
-                    'type'    => 'number',
92
-                    'default' => 10,
93
-                ),
94
-                'showGravatar'      => array(
95
-                    'type'    => 'boolean',
96
-                    'default' => false,
97
-                ),
98
-                'displayOnArchives' => array(
99
-                    'type'    => 'boolean',
100
-                    'default' => false,
101
-                ),
102
-            )
103
-        );
104
-        $this->setDynamic();
105
-    }
106
-
107
-
108
-    /**
109
-     * returns an array where the key corresponds to the incoming attribute name from the WP block
110
-     * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode
111
-     *
112
-     * @since $VID:$
113
-     * @return array
114
-     */
115
-    private function getAttributesMap()
116
-    {
117
-        return array(
118
-            'eventId'           => array('attribute' => 'event_id', 'sanitize' => 'absint'),
119
-            'datetimeId'        => array('attribute' => 'datetime_id', 'sanitize' => 'absint'),
120
-            'ticketId'          => array('attribute' => 'ticket_id', 'sanitize' => 'absint'),
121
-            'status'            => array('attribute' => 'status', 'sanitize' => 'sanitize_text_field'),
122
-            'limit'             => array('attribute' => 'limit', 'sanitize' => 'intval'),
123
-            'showGravatar'      => array('attribute' => 'show_gravatar', 'sanitize' => 'bool'),
124
-            'displayOnArchives' => array('attribute' => 'display_on_archives', 'sanitize' => 'bool'),
125
-        );
126
-    }
127
-
128
-
129
-    /**
130
-     * @param array $attributes
131
-     * @since $VID:$
132
-     * @return array
133
-     */
134
-    private function parseAttributes(array $attributes)
135
-    {
136
-        foreach ($attributes as $attribute => $value) {
137
-            $convert = $this->getAttributesMap();
138
-            if (isset($convert[ $attribute ])) {
139
-                $sanitize = $convert[ $attribute ]['sanitize'];
140
-                $converted_attribute_key = $convert[ $attribute ]['attribute'];
141
-                if ($sanitize === 'bool') {
142
-                    $attributes[ $converted_attribute_key ] = filter_var(
143
-                        $value,
144
-                        FILTER_VALIDATE_BOOLEAN
145
-                    );
146
-                } else {
147
-                    $attributes[ $converted_attribute_key ] = $sanitize($value);
148
-                }
149
-                if ($attribute !== $converted_attribute_key) {
150
-                    unset($attributes[ $attribute ]);
151
-                }
152
-                // don't pass along attributes with a 0 value
153
-                if ($attributes[ $converted_attribute_key ] === 0) {
154
-                    unset($attributes[ $converted_attribute_key ]);
155
-                }
156
-            }
157
-        }
158
-        return $attributes;
159
-    }
160
-
161
-
162
-    /**
163
-     * This ensures we're only sending along the needed attribute for grabbing attendees.
164
-     * In order:
165
-     *
166
-     * - if ticket_id is present then datetime or event id are unneeded.
167
-     * - if datetime_id is present than event_id is not needed.
168
-     *
169
-     * @param array $attributes
170
-     * @return array
171
-     */
172
-    private function includeNecessaryOnly(array $attributes)
173
-    {
174
-        if ($attributes['ticket_id'] > 0) {
175
-            unset($attributes['event_id'], $attributes['datetime_id']);
176
-        }
177
-        if ($attributes['datetime_id'] > 0) {
178
-            unset($attributes['event_id']);
179
-        }
180
-        return $attributes;
181
-    }
182
-
183
-
184
-    /**
185
-     * Returns true when there are no id values in the attributes.
186
-     *
187
-     * @param array $attributes
188
-     * @return bool
189
-     */
190
-    private function hasNoIds(array $attributes)
191
-    {
192
-        return empty($attributes['event_id']) && empty($attributes['datetime_id']) && empty($attributes['ticket_id']);
193
-    }
194
-
195
-    /**
196
-     * Returns the rendered HTML for the block
197
-     *
198
-     * @param array $attributes
199
-     * @return string
200
-     * @throws EE_Error
201
-     * @throws InvalidDataTypeException
202
-     * @throws InvalidInterfaceException
203
-     * @throws InvalidArgumentException
204
-     * @throws DomainException
205
-     */
206
-    public function renderBlock(array $attributes = array())
207
-    {
208
-        $attributes = $this->includeNecessaryOnly($this->parseAttributes($attributes));
209
-        $rendered_content = $this->shortcode->processShortcode($attributes);
210
-        if (empty($rendered_content)) {
211
-            return $this->noContentRender($attributes);
212
-        }
213
-        if ($this->hasNoIds($attributes) && $this->request->isWordPressApi()) {
214
-            $rendered_content = '<div class="components-notice is-success"><p>' . esc_html__(
215
-                'The content displayed is for the most recent active or upcoming event.  You can display attendees from a different event, ticket or datetime via the block settings.',
216
-                'event_espresso'
217
-            ) . '</p></div>' . $rendered_content;
218
-        }
219
-        return $rendered_content;
220
-    }
221
-
222
-
223
-    /**
224
-     * Returns rendered content for block when there is no content for rendering due to various conditions.
225
-     * This content ONLY appears in the editor context.
226
-     *
227
-     * @param array $attributes
228
-     * @return string
229
-     */
230
-    private function noContentRender(array $attributes)
231
-    {
232
-        $content = '';
233
-        if ($this->request->isWordPressApi()) {
234
-            if (empty($attributes['event_id'])) {
235
-                $content .= esc_html__(
236
-                    'There are no active or selected events to pull attendees from at this moment. This message only appears in the editor.',
237
-                    'event_espresso'
238
-                );
239
-            } else {
240
-                $content .= esc_html__(
241
-                    'There was a problem displaying the content for the selected options. This message only appears in the editor.',
242
-                    'event_espresso'
243
-                );
244
-            }
245
-            $content = $content !== '' ? '<div class="components-notice is-error"><p>' . $content . '</p></div>' : $content;
246
-        }
247
-        return $content;
248
-    }
27
+	const BLOCK_TYPE = 'event-attendees';
28
+
29
+	/**
30
+	 * @var EspressoEventAttendees $shortcode
31
+	 */
32
+	protected $shortcode;
33
+
34
+
35
+	/**
36
+	 * EventAttendees constructor.
37
+	 *
38
+	 * @param CoreBlocksAssetManager $block_asset_manager
39
+	 * @param RequestInterface       $request
40
+	 * @param EspressoEventAttendees $shortcode
41
+	 */
42
+	public function __construct(
43
+		CoreBlocksAssetManager $block_asset_manager,
44
+		RequestInterface $request,
45
+		EspressoEventAttendees $shortcode
46
+	) {
47
+		parent::__construct($block_asset_manager, $request);
48
+		$this->shortcode = $shortcode;
49
+	}
50
+
51
+
52
+	/**
53
+	 * Perform any early setup required by the block
54
+	 * including setting the block type and supported post types
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function initialize()
59
+	{
60
+		$this->setBlockType(self::BLOCK_TYPE);
61
+		$this->setSupportedRoutes(
62
+			array(
63
+				'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoStandardPostTypeEditor',
64
+				'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPostTypeEditor',
65
+				'EventEspresso\core\domain\entities\route_match\specifications\frontend\EspressoBlockRenderer',
66
+				'EventEspresso\core\domain\entities\route_match\specifications\frontend\AnyFrontendRequest'
67
+			)
68
+		);
69
+		$EVT_ID = $this->request->getRequestParam('page') === 'espresso_events'
70
+			? $this->request->getRequestParam('post', 0)
71
+			: 0;
72
+		$this->setAttributes(
73
+			array(
74
+				'eventId'           => array(
75
+					'type'    => 'number',
76
+					'default' => $EVT_ID,
77
+				),
78
+				'datetimeId'        => array(
79
+					'type'    => 'number',
80
+					'default' => 0,
81
+				),
82
+				'ticketId'          => array(
83
+					'type'    => 'number',
84
+					'default' => 0,
85
+				),
86
+				'status'            => array(
87
+					'type'    => 'string',
88
+					'default' => EEM_Registration::status_id_approved,
89
+				),
90
+				'limit'             => array(
91
+					'type'    => 'number',
92
+					'default' => 10,
93
+				),
94
+				'showGravatar'      => array(
95
+					'type'    => 'boolean',
96
+					'default' => false,
97
+				),
98
+				'displayOnArchives' => array(
99
+					'type'    => 'boolean',
100
+					'default' => false,
101
+				),
102
+			)
103
+		);
104
+		$this->setDynamic();
105
+	}
106
+
107
+
108
+	/**
109
+	 * returns an array where the key corresponds to the incoming attribute name from the WP block
110
+	 * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode
111
+	 *
112
+	 * @since $VID:$
113
+	 * @return array
114
+	 */
115
+	private function getAttributesMap()
116
+	{
117
+		return array(
118
+			'eventId'           => array('attribute' => 'event_id', 'sanitize' => 'absint'),
119
+			'datetimeId'        => array('attribute' => 'datetime_id', 'sanitize' => 'absint'),
120
+			'ticketId'          => array('attribute' => 'ticket_id', 'sanitize' => 'absint'),
121
+			'status'            => array('attribute' => 'status', 'sanitize' => 'sanitize_text_field'),
122
+			'limit'             => array('attribute' => 'limit', 'sanitize' => 'intval'),
123
+			'showGravatar'      => array('attribute' => 'show_gravatar', 'sanitize' => 'bool'),
124
+			'displayOnArchives' => array('attribute' => 'display_on_archives', 'sanitize' => 'bool'),
125
+		);
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param array $attributes
131
+	 * @since $VID:$
132
+	 * @return array
133
+	 */
134
+	private function parseAttributes(array $attributes)
135
+	{
136
+		foreach ($attributes as $attribute => $value) {
137
+			$convert = $this->getAttributesMap();
138
+			if (isset($convert[ $attribute ])) {
139
+				$sanitize = $convert[ $attribute ]['sanitize'];
140
+				$converted_attribute_key = $convert[ $attribute ]['attribute'];
141
+				if ($sanitize === 'bool') {
142
+					$attributes[ $converted_attribute_key ] = filter_var(
143
+						$value,
144
+						FILTER_VALIDATE_BOOLEAN
145
+					);
146
+				} else {
147
+					$attributes[ $converted_attribute_key ] = $sanitize($value);
148
+				}
149
+				if ($attribute !== $converted_attribute_key) {
150
+					unset($attributes[ $attribute ]);
151
+				}
152
+				// don't pass along attributes with a 0 value
153
+				if ($attributes[ $converted_attribute_key ] === 0) {
154
+					unset($attributes[ $converted_attribute_key ]);
155
+				}
156
+			}
157
+		}
158
+		return $attributes;
159
+	}
160
+
161
+
162
+	/**
163
+	 * This ensures we're only sending along the needed attribute for grabbing attendees.
164
+	 * In order:
165
+	 *
166
+	 * - if ticket_id is present then datetime or event id are unneeded.
167
+	 * - if datetime_id is present than event_id is not needed.
168
+	 *
169
+	 * @param array $attributes
170
+	 * @return array
171
+	 */
172
+	private function includeNecessaryOnly(array $attributes)
173
+	{
174
+		if ($attributes['ticket_id'] > 0) {
175
+			unset($attributes['event_id'], $attributes['datetime_id']);
176
+		}
177
+		if ($attributes['datetime_id'] > 0) {
178
+			unset($attributes['event_id']);
179
+		}
180
+		return $attributes;
181
+	}
182
+
183
+
184
+	/**
185
+	 * Returns true when there are no id values in the attributes.
186
+	 *
187
+	 * @param array $attributes
188
+	 * @return bool
189
+	 */
190
+	private function hasNoIds(array $attributes)
191
+	{
192
+		return empty($attributes['event_id']) && empty($attributes['datetime_id']) && empty($attributes['ticket_id']);
193
+	}
194
+
195
+	/**
196
+	 * Returns the rendered HTML for the block
197
+	 *
198
+	 * @param array $attributes
199
+	 * @return string
200
+	 * @throws EE_Error
201
+	 * @throws InvalidDataTypeException
202
+	 * @throws InvalidInterfaceException
203
+	 * @throws InvalidArgumentException
204
+	 * @throws DomainException
205
+	 */
206
+	public function renderBlock(array $attributes = array())
207
+	{
208
+		$attributes = $this->includeNecessaryOnly($this->parseAttributes($attributes));
209
+		$rendered_content = $this->shortcode->processShortcode($attributes);
210
+		if (empty($rendered_content)) {
211
+			return $this->noContentRender($attributes);
212
+		}
213
+		if ($this->hasNoIds($attributes) && $this->request->isWordPressApi()) {
214
+			$rendered_content = '<div class="components-notice is-success"><p>' . esc_html__(
215
+				'The content displayed is for the most recent active or upcoming event.  You can display attendees from a different event, ticket or datetime via the block settings.',
216
+				'event_espresso'
217
+			) . '</p></div>' . $rendered_content;
218
+		}
219
+		return $rendered_content;
220
+	}
221
+
222
+
223
+	/**
224
+	 * Returns rendered content for block when there is no content for rendering due to various conditions.
225
+	 * This content ONLY appears in the editor context.
226
+	 *
227
+	 * @param array $attributes
228
+	 * @return string
229
+	 */
230
+	private function noContentRender(array $attributes)
231
+	{
232
+		$content = '';
233
+		if ($this->request->isWordPressApi()) {
234
+			if (empty($attributes['event_id'])) {
235
+				$content .= esc_html__(
236
+					'There are no active or selected events to pull attendees from at this moment. This message only appears in the editor.',
237
+					'event_espresso'
238
+				);
239
+			} else {
240
+				$content .= esc_html__(
241
+					'There was a problem displaying the content for the selected options. This message only appears in the editor.',
242
+					'event_espresso'
243
+				);
244
+			}
245
+			$content = $content !== '' ? '<div class="components-notice is-error"><p>' . $content . '</p></div>' : $content;
246
+		}
247
+		return $content;
248
+	}
249 249
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -135,23 +135,23 @@  discard block
 block discarded – undo
135 135
     {
136 136
         foreach ($attributes as $attribute => $value) {
137 137
             $convert = $this->getAttributesMap();
138
-            if (isset($convert[ $attribute ])) {
139
-                $sanitize = $convert[ $attribute ]['sanitize'];
140
-                $converted_attribute_key = $convert[ $attribute ]['attribute'];
138
+            if (isset($convert[$attribute])) {
139
+                $sanitize = $convert[$attribute]['sanitize'];
140
+                $converted_attribute_key = $convert[$attribute]['attribute'];
141 141
                 if ($sanitize === 'bool') {
142
-                    $attributes[ $converted_attribute_key ] = filter_var(
142
+                    $attributes[$converted_attribute_key] = filter_var(
143 143
                         $value,
144 144
                         FILTER_VALIDATE_BOOLEAN
145 145
                     );
146 146
                 } else {
147
-                    $attributes[ $converted_attribute_key ] = $sanitize($value);
147
+                    $attributes[$converted_attribute_key] = $sanitize($value);
148 148
                 }
149 149
                 if ($attribute !== $converted_attribute_key) {
150
-                    unset($attributes[ $attribute ]);
150
+                    unset($attributes[$attribute]);
151 151
                 }
152 152
                 // don't pass along attributes with a 0 value
153
-                if ($attributes[ $converted_attribute_key ] === 0) {
154
-                    unset($attributes[ $converted_attribute_key ]);
153
+                if ($attributes[$converted_attribute_key] === 0) {
154
+                    unset($attributes[$converted_attribute_key]);
155 155
                 }
156 156
             }
157 157
         }
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
             return $this->noContentRender($attributes);
212 212
         }
213 213
         if ($this->hasNoIds($attributes) && $this->request->isWordPressApi()) {
214
-            $rendered_content = '<div class="components-notice is-success"><p>' . esc_html__(
214
+            $rendered_content = '<div class="components-notice is-success"><p>'.esc_html__(
215 215
                 'The content displayed is for the most recent active or upcoming event.  You can display attendees from a different event, ticket or datetime via the block settings.',
216 216
                 'event_espresso'
217
-            ) . '</p></div>' . $rendered_content;
217
+            ).'</p></div>'.$rendered_content;
218 218
         }
219 219
         return $rendered_content;
220 220
     }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
                     'event_espresso'
243 243
                 );
244 244
             }
245
-            $content = $content !== '' ? '<div class="components-notice is-error"><p>' . $content . '</p></div>' : $content;
245
+            $content = $content !== '' ? '<div class="components-notice is-error"><p>'.$content.'</p></div>' : $content;
246 246
         }
247 247
         return $content;
248 248
     }
Please login to merge, or discard this patch.