Completed
Branch master (5979d3)
by
unknown
26:18 queued 23:58
created
events_archive_caff/templates/admin-event-list-settings.template.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -5,18 +5,18 @@  discard block
 block discarded – undo
5 5
 add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
6 6
 
7 7
 $values = EEH_Form_Fields::prep_answer_options(
8
-    array(
9
-        array('id' => 1, 'text' => esc_html__('Yes', 'event_espresso')),
10
-        array('id' => 0, 'text' => esc_html__('No', 'event_espresso')),
11
-    )
8
+	array(
9
+		array('id' => 1, 'text' => esc_html__('Yes', 'event_espresso')),
10
+		array('id' => 0, 'text' => esc_html__('No', 'event_espresso')),
11
+	)
12 12
 );
13 13
 
14 14
 $description = EEH_Form_Fields::prep_answer_options(
15
-    array(
16
-        array('id' => 0, 'text' => esc_html__('none', 'event_espresso')),
17
-        array('id' => 1, 'text' => esc_html__('excerpt (short desc)', 'event_espresso')),
18
-        array('id' => 2, 'text' => esc_html__('full description', 'event_espresso')),
19
-    )
15
+	array(
16
+		array('id' => 0, 'text' => esc_html__('none', 'event_espresso')),
17
+		array('id' => 1, 'text' => esc_html__('excerpt (short desc)', 'event_espresso')),
18
+		array('id' => 2, 'text' => esc_html__('full description', 'event_espresso')),
19
+	)
20 20
 );
21 21
 
22 22
 ?>
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
         <th>
36 36
             <label for="event_listings_url">
37 37
                 <?php esc_html_e('Event Listings URL', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
38
-                    'event_listings_url_info'
39
-                ); ?>
38
+					'event_listings_url_info'
39
+				); ?>
40 40
             </label>
41 41
         </th>
42 42
         <td>
43 43
             <a id="event_listings_url" class="ee-admin-settings-hdr-lnk small-text"
44 44
                href="<?php echo EEH_Event_View::event_archive_url(); ?>"><?php
45
-                echo EEH_Event_View::event_archive_url(); ?></a>
45
+				echo EEH_Event_View::event_archive_url(); ?></a>
46 46
         </td>
47 47
     </tr>
48 48
 
@@ -54,30 +54,30 @@  discard block
 block discarded – undo
54 54
         </th>
55 55
         <td>
56 56
             <p><?php echo site_url() . '/ '
57
-                          . EEH_Form_Fields::text(
58
-                              'not_used',
59
-                              EE_Registry::instance()->CFG->core->event_cpt_slug,
60
-                              'event_cpt_slug',
61
-                              'event_cpt_slug',
62
-                              'regular'
63
-                          ); ?></p>
57
+						  . EEH_Form_Fields::text(
58
+							  'not_used',
59
+							  EE_Registry::instance()->CFG->core->event_cpt_slug,
60
+							  'event_cpt_slug',
61
+							  'event_cpt_slug',
62
+							  'regular'
63
+						  ); ?></p>
64 64
             <p class="description"><?php
65
-                esc_html_e(
66
-                    'This allows you to configure what slug is used for the url of all event pages.',
67
-                    'event_espresso'
68
-                ); ?></p>
65
+				esc_html_e(
66
+					'This allows you to configure what slug is used for the url of all event pages.',
67
+					'event_espresso'
68
+				); ?></p>
69 69
             <?php if (has_filter('FHEE__EE_Register_CPTs__register_CPT__rewrite')) : ?>
70 70
                 <p class="important-notice">
71 71
                     <?php
72
-                    sprintf(
73
-                        esc_html__(
74
-                            'Usage of the %1$s FHEE__EE_Register_CPTs__register_CPT__rewrite %2$s filter has been detected.  Please be aware that while this filter is being used, this setting has no affect.',
75
-                            'event_espresso'
76
-                        ),
77
-                        '<code>',
78
-                        '</code>'
79
-                    );
80
-                    ?>
72
+					sprintf(
73
+						esc_html__(
74
+							'Usage of the %1$s FHEE__EE_Register_CPTs__register_CPT__rewrite %2$s filter has been detected.  Please be aware that while this filter is being used, this setting has no affect.',
75
+							'event_espresso'
76
+						),
77
+						'<code>',
78
+						'</code>'
79
+					);
80
+					?>
81 81
                 </p>
82 82
             <?php endif; ?>
83 83
         </td>
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
         </th>
92 92
         <td>
93 93
             <?php echo EEH_Form_Fields::select(
94
-                'display_status_banner',
95
-                $display_status_banner,
96
-                $values,
97
-                'EED_Events_Archive_display_status_banner',
98
-                'EED_Events_Archive_display_status_banner'
99
-            ); ?>
94
+				'display_status_banner',
95
+				$display_status_banner,
96
+				$values,
97
+				'EED_Events_Archive_display_status_banner',
98
+				'EED_Events_Archive_display_status_banner'
99
+			); ?>
100 100
             <p class="description"><?php
101
-                esc_html_e(
102
-                    'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the events archive page.',
103
-                    'event_espresso'
104
-                ); ?></p>
101
+				esc_html_e(
102
+					'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the events archive page.',
103
+					'event_espresso'
104
+				); ?></p>
105 105
         </td>
106 106
     </tr>
107 107
 
@@ -109,18 +109,18 @@  discard block
 block discarded – undo
109 109
         <th>
110 110
             <label for="EED_Events_Archive_display_description">
111 111
                 <?php esc_html_e('Display Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
112
-                    'display_description_info'
113
-                ); ?>
112
+					'display_description_info'
113
+				); ?>
114 114
             </label>
115 115
         </th>
116 116
         <td>
117 117
             <?php echo EEH_Form_Fields::select(
118
-                'description',
119
-                $display_description,
120
-                $description,
121
-                'EED_Events_Archive_display_description',
122
-                'EED_Events_Archive_display_description'
123
-            ); ?>
118
+				'description',
119
+				$display_description,
120
+				$description,
121
+				'EED_Events_Archive_display_description',
122
+				'EED_Events_Archive_display_description'
123
+			); ?>
124 124
         </td>
125 125
     </tr>
126 126
 
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
         <th>
129 129
             <label for="EED_Events_Archive_display_ticket_selector">
130 130
                 <?php esc_html_e('Display Ticket Selector', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
131
-                    'display_ticket_selector_info'
132
-                ); ?>
131
+					'display_ticket_selector_info'
132
+				); ?>
133 133
             </label>
134 134
         </th>
135 135
         <td>
136 136
             <?php echo EEH_Form_Fields::select(
137
-                'ticket_selector',
138
-                $display_ticket_selector,
139
-                $values,
140
-                'EED_Events_Archive_display_ticket_selector',
141
-                'EED_Events_Archive_display_ticket_selector'
142
-            ); ?>
137
+				'ticket_selector',
138
+				$display_ticket_selector,
139
+				$values,
140
+				'EED_Events_Archive_display_ticket_selector',
141
+				'EED_Events_Archive_display_ticket_selector'
142
+			); ?>
143 143
         </td>
144 144
     </tr>
145 145
 
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
         <th>
148 148
             <label for="EED_Events_Archive_display_datetimes">
149 149
                 <?php esc_html_e('Display Datetimes', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
150
-                    'display_datetimes_info'
151
-                ); ?>
150
+					'display_datetimes_info'
151
+				); ?>
152 152
             </label>
153 153
         </th>
154 154
         <td>
155 155
             <?php echo EEH_Form_Fields::select(
156
-                'venue_details',
157
-                $display_datetimes,
158
-                $values,
159
-                'EED_Events_Archive_display_datetimes',
160
-                'EED_Events_Archive_display_datetimes'
161
-            ); ?>
156
+				'venue_details',
157
+				$display_datetimes,
158
+				$values,
159
+				'EED_Events_Archive_display_datetimes',
160
+				'EED_Events_Archive_display_datetimes'
161
+			); ?>
162 162
         </td>
163 163
     </tr>
164 164
 
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
         <th>
167 167
             <label for="EED_Events_Archive_display_venue">
168 168
                 <?php esc_html_e('Display Venue Details', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
169
-                    'display_venue_details_info'
170
-                ); ?>
169
+					'display_venue_details_info'
170
+				); ?>
171 171
             </label>
172 172
         </th>
173 173
         <td>
174 174
             <?php echo EEH_Form_Fields::select(
175
-                'display_venue',
176
-                $display_venue,
177
-                $values,
178
-                'EED_Events_Archive_display_venue',
179
-                'EED_Events_Archive_display_venue'
180
-            ); ?>
175
+				'display_venue',
176
+				$display_venue,
177
+				$values,
178
+				'EED_Events_Archive_display_venue',
179
+				'EED_Events_Archive_display_venue'
180
+			); ?>
181 181
         </td>
182 182
     </tr>
183 183
 
@@ -185,18 +185,18 @@  discard block
 block discarded – undo
185 185
         <th>
186 186
             <label for="EED_Events_Archive_display_expired_events">
187 187
                 <?php esc_html_e('Display Expired Events', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link(
188
-                    'display_expired_events_info'
189
-                ); ?>
188
+					'display_expired_events_info'
189
+				); ?>
190 190
             </label>
191 191
         </th>
192 192
         <td>
193 193
             <?php echo EEH_Form_Fields::select(
194
-                'expired_events',
195
-                $display_expired_events,
196
-                $values,
197
-                'EED_Events_Archive_display_expired_events',
198
-                'EED_Events_Archive_display_expired_events'
199
-            ); ?>
194
+				'expired_events',
195
+				$display_expired_events,
196
+				$values,
197
+				'EED_Events_Archive_display_expired_events',
198
+				'EED_Events_Archive_display_expired_events'
199
+			); ?>
200 200
         </td>
201 201
     </tr>
202 202
 
@@ -204,43 +204,43 @@  discard block
 block discarded – undo
204 204
         <th>
205 205
             <label for="EED_Events_Archive_use_sortable_display_order">
206 206
                 <?php esc_html_e(
207
-                    'Use Custom Display Order?',
208
-                    'event_espresso'
209
-                ); ?><?php // echo EEH_Template::get_help_tab_link('use_sortable_display_order_info');?>
207
+					'Use Custom Display Order?',
208
+					'event_espresso'
209
+				); ?><?php // echo EEH_Template::get_help_tab_link('use_sortable_display_order_info');?>
210 210
             </label>
211 211
         </th>
212 212
         <td>
213 213
             <?php echo EEH_Form_Fields::select(
214
-                'use_sortable_display_order',
215
-                $use_sortable_display_order,
216
-                $values,
217
-                'EED_Events_Archive_use_sortable_display_order',
218
-                'EED_Events_Archive_use_sortable_display_order'
219
-            ); ?>
214
+				'use_sortable_display_order',
215
+				$use_sortable_display_order,
216
+				$values,
217
+				'EED_Events_Archive_use_sortable_display_order',
218
+				'EED_Events_Archive_use_sortable_display_order'
219
+			); ?>
220 220
         </td>
221 221
     </tr>
222 222
 
223 223
     <tr>
224 224
         <th>
225 225
             <?php esc_html_e(
226
-                'Display Order',
227
-                'event_espresso'
228
-            ); ?><?php // echo EEH_Template::get_help_tab_link( 'event_archive_order_info' ); ?>
226
+				'Display Order',
227
+				'event_espresso'
228
+			); ?><?php // echo EEH_Template::get_help_tab_link( 'event_archive_order_info' ); ?>
229 229
         </th>
230 230
         <td>
231 231
 
232 232
             <?php wp_nonce_field(
233
-                'espresso_update_event_archive_order',
234
-                'espresso_update_event_archive_order_nonce',
235
-                false
236
-            ); ?>
233
+				'espresso_update_event_archive_order',
234
+				'espresso_update_event_archive_order_nonce',
235
+				false
236
+			); ?>
237 237
             <?php echo wp_kses($event_archive_display_order, AllowedTags::getWithFormTags()); ?>
238 238
 
239 239
             <p class="description"><?php
240
-                esc_html_e(
241
-                    'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the event archive page.',
242
-                    'event_espresso'
243
-                ); ?></p>
240
+				esc_html_e(
241
+					'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the event archive page.',
242
+					'event_espresso'
243
+				); ?></p>
244 244
 
245 245
         </td>
246 246
     </tr>
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
         </th>
254 254
         <td>
255 255
             <?php echo EEH_Form_Fields::select(
256
-                'reset_event_list_settings',
257
-                0,
258
-                $values,
259
-                'EED_Events_Archive_reset_event_list_settings',
260
-                'EED_Events_Archive_reset_event_list_settings'
261
-            ); ?>
256
+				'reset_event_list_settings',
257
+				0,
258
+				$values,
259
+				'EED_Events_Archive_reset_event_list_settings',
260
+				'EED_Events_Archive_reset_event_list_settings'
261
+			); ?>
262 262
         </td>
263 263
     </tr>
264 264
 
Please login to merge, or discard this patch.
ticket_selector_caff/templates/ticket_selector_price_details.template.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,39 +10,39 @@  discard block
 block discarded – undo
10 10
 if ($display_ticket_price) { ?>
11 11
     <section class="tckt-slctr-tkt-price-sctn">
12 12
         <h5><?php
13
-            echo apply_filters(
14
-                'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
15
-                esc_html__('Price', 'event_espresso')
16
-            ); ?></h5>
13
+			echo apply_filters(
14
+				'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
15
+				esc_html__('Price', 'event_espresso')
16
+			); ?></h5>
17 17
         <div class="tckt-slctr-tkt-details-tbl-wrap-dv">
18 18
             <table class="tckt-slctr-tkt-details-tbl">
19 19
                 <thead>
20 20
                 <tr>
21 21
                     <th class="ee-third-width"><span class="small-text">
22 22
                             <?php
23
-                            esc_html_e(
24
-                                'Name',
25
-                                'event_espresso'
26
-                            ); ?></span>
23
+							esc_html_e(
24
+								'Name',
25
+								'event_espresso'
26
+							); ?></span>
27 27
                     </th>
28 28
                     <th class="jst-cntr"><span class="small-text">
29 29
                             <?php
30
-                            esc_html_e(
31
-                                'Description',
32
-                                'event_espresso'
33
-                            ); ?></span>
30
+							esc_html_e(
31
+								'Description',
32
+								'event_espresso'
33
+							); ?></span>
34 34
                     </th>
35 35
                     <th class="ee-fourth-width jst-rght"><span class="small-text">
36 36
                             <?php
37
-                            esc_html_e(
38
-                                'Amount',
39
-                                'event_espresso'
40
-                            ); ?></span></th>
37
+							esc_html_e(
38
+								'Amount',
39
+								'event_espresso'
40
+							); ?></span></th>
41 41
                 </tr>
42 42
                 </thead>
43 43
                 <tbody>
44 44
                 <?php
45
-                if ($ticket->base_price() instanceof EE_Price) { ?>
45
+				if ($ticket->base_price() instanceof EE_Price) { ?>
46 46
                     <tr>
47 47
                         <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" class="small-text" colspan="2">
48 48
                             <b><?php echo wp_kses($ticket->base_price()->name(), AllowedTags::getAllowedTags()); ?></b></td>
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
                             class="jst-rght small-text"><?php echo wp_kses($ticket->base_price()->pretty_price(), AllowedTags::getAllowedTags()); ?></td>
51 51
                     </tr>
52 52
                     <?php
53
-                    $running_total = $ticket->base_price()->amount();
54
-                } else {
55
-                    $running_total = 0;
56
-                }
57
-                // now add price modifiers
58
-                foreach ($ticket->price_modifiers() as $price_mod) { ?>
53
+					$running_total = $ticket->base_price()->amount();
54
+				} else {
55
+					$running_total = 0;
56
+				}
57
+				// now add price modifiers
58
+				foreach ($ticket->price_modifiers() as $price_mod) { ?>
59 59
                     <tr>
60 60
                         <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>"
61 61
                             class="jst-rght small-text"><?php echo wp_kses($price_mod->name(), AllowedTags::getAllowedTags()); ?></td>
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
                                 %
66 66
                             </td>
67 67
                             <?php
68
-                            $new_sub_total = $running_total * ($price_mod->amount() / 100);
69
-                            $new_sub_total = $price_mod->is_discount() ? $new_sub_total * -1 : $new_sub_total;
70
-                            ?>
68
+							$new_sub_total = $running_total * ($price_mod->amount() / 100);
69
+							$new_sub_total = $price_mod->is_discount() ? $new_sub_total * -1 : $new_sub_total;
70
+							?>
71 71
                         <?php } else { ?>
72 72
                             <?php $new_sub_total = $price_mod->is_discount() ? $price_mod->amount() * -1
73
-                                : $price_mod->amount(); ?>
73
+								: $price_mod->amount(); ?>
74 74
                             <td data-th="<?php esc_html_e('Description', 'event_espresso'); ?>"
75 75
                                 class="small-text"><?php echo wp_kses($price_mod->desc(), AllowedTags::getAllowedTags()); ?></td>
76 76
                             <?php $new_sub_total = $price_mod->is_discount() ? $price_mod->amount() * -1
77
-                                : $price_mod->amount(); ?>
77
+								: $price_mod->amount(); ?>
78 78
                         <?php } ?>
79 79
                         <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>"
80 80
                             class="jst-rght small-text">
81 81
                             <?php
82
-                            echo EEH_Template::format_currency(
83
-                                $new_sub_total
84
-                            ); ?></td>
82
+							echo EEH_Template::format_currency(
83
+								$new_sub_total
84
+							); ?></td>
85 85
                         <?php $running_total += $new_sub_total; ?>
86 86
                     </tr>
87 87
                 <?php } ?>
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
                     <tr>
91 91
                         <td colspan="2" class="jst-rght small-text sbttl"><b>
92 92
                                 <?php
93
-                                esc_html_e(
94
-                                    'subtotal',
95
-                                    'event_espresso'
96
-                                ); ?></b></td>
93
+								esc_html_e(
94
+									'subtotal',
95
+									'event_espresso'
96
+								); ?></b></td>
97 97
                         <td data-th="<?php esc_html_e('subtotal', 'event_espresso'); ?>" class="jst-rght small-text">
98 98
                             <b><?php echo EEH_Template::format_currency($running_total); ?></b></td>
99 99
                     </tr>
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
                             <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>"
110 110
                                 class="jst-rght small-text">
111 111
                                 <?php
112
-                                echo EEH_Template::format_currency(
113
-                                    $tax_amount
114
-                                ); ?></td>
112
+								echo EEH_Template::format_currency(
113
+									$tax_amount
114
+								); ?></td>
115 115
                             <?php $running_total += $tax_amount; ?>
116 116
                         </tr>
117 117
                     <?php } ?>
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
                 <tr>
120 120
                     <td colspan="2" class="jst-rght small-text ttl-lbl-td">
121 121
                         <b><?php
122
-                            echo apply_filters(
123
-                                'FHEE__ticket_selector_chart_template__ticket_details_total_price',
124
-                                esc_html__('Total', 'event_espresso')
125
-                            ); ?></b></td>
122
+							echo apply_filters(
123
+								'FHEE__ticket_selector_chart_template__ticket_details_total_price',
124
+								esc_html__('Total', 'event_espresso')
125
+							); ?></b></td>
126 126
                     <td data-th="<?php
127
-                                    echo apply_filters(
128
-                                        'FHEE__ticket_selector_chart_template__ticket_details_total_price',
129
-                                        esc_html__('Total', 'event_espresso')
130
-                                    ); ?>" class="jst-rght small-text">
127
+									echo apply_filters(
128
+										'FHEE__ticket_selector_chart_template__ticket_details_total_price',
129
+										esc_html__('Total', 'event_espresso')
130
+									); ?>" class="jst-rght small-text">
131 131
                         <b><?php echo EEH_Template::format_currency($running_total); ?></b></td>
132 132
                 </tr>
133 133
                 </tbody>
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks.class.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -16,95 +16,95 @@  discard block
 block discarded – undo
16 16
 class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Event|null
21
-     */
22
-    protected $_event;
23
-
24
-
25
-    protected function _set_hooks_properties()
26
-    {
27
-
28
-        $this->_name      = 'registration_form';
29
-        $this->_metaboxes = [
30
-            0 => [
31
-                'page_route' => ['edit', 'create_new'],
32
-                'func'       => 'primary_questions',
33
-                'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
34
-                'priority'   => 'default',
35
-                'context'    => 'side',
36
-            ],
37
-        ];
38
-
39
-        // hook into the handler for saving question groups
40
-        add_filter(
41
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
42
-            [$this, 'modify_callbacks'],
43
-            10
44
-        );
45
-
46
-        // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
47
-        // restricted by page)
48
-        add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
49
-    }
50
-
51
-
52
-    /**
53
-     * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
54
-     *
55
-     * @param $callbacks
56
-     * @return array
57
-     */
58
-    public function modify_callbacks($callbacks)
59
-    {
60
-        // now let's add the question group callback
61
-        $callbacks[] = [$this, 'primary_question_group_update'];
62
-        return $callbacks;
63
-    }
64
-
65
-
66
-    /**
67
-     * Hooked into revision restores.
68
-     *
69
-     * @param $post_id
70
-     * @param $revision_id
71
-     * @return EE_Base_Class
72
-     * @throws EE_Error
73
-     * @throws InvalidArgumentException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     */
77
-    public function restore_revision($post_id, $revision_id)
78
-    {
79
-        $post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
80
-        // restore revision for primary questions
81
-        if ($post_evt instanceof EE_Event) {
82
-            $post_evt->restore_revision(
83
-                $revision_id,
84
-                ['Question_Group'],
85
-                ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
86
-            );
87
-        }
88
-        return $post_evt;
89
-    }
90
-
91
-
92
-    /**
93
-     * Content of metabox.
94
-     *
95
-     * @param $post_id
96
-     * @param $post
97
-     * @throws EE_Error
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     * @throws ReflectionException
102
-     */
103
-    public function primary_questions($post_id, $post)
104
-    {
105
-        $this->_event = $this->_adminpage_obj->get_event_object();
106
-        $event_id     = $this->_event->ID();
107
-        ?>
19
+	/**
20
+	 * @var EE_Event|null
21
+	 */
22
+	protected $_event;
23
+
24
+
25
+	protected function _set_hooks_properties()
26
+	{
27
+
28
+		$this->_name      = 'registration_form';
29
+		$this->_metaboxes = [
30
+			0 => [
31
+				'page_route' => ['edit', 'create_new'],
32
+				'func'       => 'primary_questions',
33
+				'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
34
+				'priority'   => 'default',
35
+				'context'    => 'side',
36
+			],
37
+		];
38
+
39
+		// hook into the handler for saving question groups
40
+		add_filter(
41
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
42
+			[$this, 'modify_callbacks'],
43
+			10
44
+		);
45
+
46
+		// hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
47
+		// restricted by page)
48
+		add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
49
+	}
50
+
51
+
52
+	/**
53
+	 * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
54
+	 *
55
+	 * @param $callbacks
56
+	 * @return array
57
+	 */
58
+	public function modify_callbacks($callbacks)
59
+	{
60
+		// now let's add the question group callback
61
+		$callbacks[] = [$this, 'primary_question_group_update'];
62
+		return $callbacks;
63
+	}
64
+
65
+
66
+	/**
67
+	 * Hooked into revision restores.
68
+	 *
69
+	 * @param $post_id
70
+	 * @param $revision_id
71
+	 * @return EE_Base_Class
72
+	 * @throws EE_Error
73
+	 * @throws InvalidArgumentException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 */
77
+	public function restore_revision($post_id, $revision_id)
78
+	{
79
+		$post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
80
+		// restore revision for primary questions
81
+		if ($post_evt instanceof EE_Event) {
82
+			$post_evt->restore_revision(
83
+				$revision_id,
84
+				['Question_Group'],
85
+				['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
86
+			);
87
+		}
88
+		return $post_evt;
89
+	}
90
+
91
+
92
+	/**
93
+	 * Content of metabox.
94
+	 *
95
+	 * @param $post_id
96
+	 * @param $post
97
+	 * @throws EE_Error
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 * @throws ReflectionException
102
+	 */
103
+	public function primary_questions($post_id, $post)
104
+	{
105
+		$this->_event = $this->_adminpage_obj->get_event_object();
106
+		$event_id     = $this->_event->ID();
107
+		?>
108 108
         <div class="inside">
109 109
             <p>
110 110
                 <strong>
@@ -112,64 +112,64 @@  discard block
 block discarded – undo
112 112
                 </strong>
113 113
                 <br />
114 114
                 <?php
115
-                printf(
116
-                    esc_html__(
117
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
118
-                        'event_espresso'
119
-                    ),
120
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
121
-                    '</a>'
122
-                )
123
-                ?>
115
+				printf(
116
+					esc_html__(
117
+						'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
118
+						'event_espresso'
119
+					),
120
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
121
+					'</a>'
122
+				)
123
+				?>
124 124
             </p>
125 125
             <?php
126 126
 
127
-            $qsg_where['QSG_deleted'] = false;
128
-            $query_params             = apply_filters(
129
-                'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
130
-                [$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
131
-            );
132
-            $QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
133
-            $EQGs                     = ! empty($event_id)
134
-                ? $this->_event->get_many_related(
135
-                    'Question_Group',
136
-                    [['Event_Question_Group.EQG_primary' => true]]
137
-                )
138
-                : [];
139
-            $EQGids                   = array_keys($EQGs);
140
-
141
-            if (! empty($QSGs)) {
142
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
143
-                foreach ($QSGs as $QSG) {
144
-                    $QSG_ID          = absint($QSG->ID());
145
-                    $checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
146
-                        ? ' checked'
147
-                        : '';
148
-                    $visibility      = $QSG->get('QSG_system') === 1
149
-                        ? ' style="visibility:hidden"'
150
-                        : '';
151
-                    $edit_query_args = $this->_adminpage_obj->is_caf()
152
-                        ? [
153
-                            'action' => 'edit_question_group',
154
-                            'QSG_ID' => $QSG_ID,
155
-                        ]
156
-                        : ['action' => 'question_groups'];
157
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
158
-                        $edit_query_args,
159
-                        EE_FORMS_ADMIN_URL
160
-                    );
161
-                    $edit_link_title = sprintf(
162
-                        esc_attr__('Edit %s Group', 'event_espresso'),
163
-                        $QSG->get('QSG_name')
164
-                    );
165
-
166
-                    $html .= '
127
+			$qsg_where['QSG_deleted'] = false;
128
+			$query_params             = apply_filters(
129
+				'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
130
+				[$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
131
+			);
132
+			$QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
133
+			$EQGs                     = ! empty($event_id)
134
+				? $this->_event->get_many_related(
135
+					'Question_Group',
136
+					[['Event_Question_Group.EQG_primary' => true]]
137
+				)
138
+				: [];
139
+			$EQGids                   = array_keys($EQGs);
140
+
141
+			if (! empty($QSGs)) {
142
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
143
+				foreach ($QSGs as $QSG) {
144
+					$QSG_ID          = absint($QSG->ID());
145
+					$checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
146
+						? ' checked'
147
+						: '';
148
+					$visibility      = $QSG->get('QSG_system') === 1
149
+						? ' style="visibility:hidden"'
150
+						: '';
151
+					$edit_query_args = $this->_adminpage_obj->is_caf()
152
+						? [
153
+							'action' => 'edit_question_group',
154
+							'QSG_ID' => $QSG_ID,
155
+						]
156
+						: ['action' => 'question_groups'];
157
+					$edit_link       = EE_Admin_Page::add_query_args_and_nonce(
158
+						$edit_query_args,
159
+						EE_FORMS_ADMIN_URL
160
+					);
161
+					$edit_link_title = sprintf(
162
+						esc_attr__('Edit %s Group', 'event_espresso'),
163
+						$QSG->get('QSG_name')
164
+					);
165
+
166
+					$html .= '
167 167
 					<p id="event-question-group-' . $QSG_ID . '">
168 168
 						<input value="' . $QSG_ID . '" 
169 169
 						    type="checkbox"
170 170
 						    name="question_groups[' . $QSG_ID . ']" '
171
-                             . $visibility
172
-                             . $checked . ' 
171
+							 . $visibility
172
+							 . $checked . ' 
173 173
                         />
174 174
 						<a href="' . esc_url_raw($edit_link) . '" 
175 175
 						    title="' . esc_attr($edit_link_title) . '" 
@@ -178,62 +178,62 @@  discard block
 block discarded – undo
178 178
 						    ' . $QSG->get('QSG_name') . '
179 179
                         </a>
180 180
 					</p>';
181
-                }
182
-                $html .= count($QSGs) > 10 ? '</div>' : '';
183
-                echo wp_kses($html, AllowedTags::getWithFormTags());
184
-            } else {
185
-                esc_html_e(
186
-                    'There seems to be a problem with your questions. Please contact [email protected]',
187
-                    'event_espresso'
188
-                );
189
-            }
190
-            do_action('AHEE_event_editor_questions_notice');
191
-            ?>
181
+				}
182
+				$html .= count($QSGs) > 10 ? '</div>' : '';
183
+				echo wp_kses($html, AllowedTags::getWithFormTags());
184
+			} else {
185
+				esc_html_e(
186
+					'There seems to be a problem with your questions. Please contact [email protected]',
187
+					'event_espresso'
188
+				);
189
+			}
190
+			do_action('AHEE_event_editor_questions_notice');
191
+			?>
192 192
         </div>
193 193
         <?php
194
-    }
195
-
196
-
197
-    /**
198
-     * @param EE_Event $event
199
-     * @param array    $data
200
-     * @return bool
201
-     * @throws EE_Error
202
-     * @throws ReflectionException
203
-     */
204
-    public function primary_question_group_update($event, $data)
205
-    {
206
-        $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
207
-        $added_qgs       = array_keys($question_groups);
208
-        $success         = true;
209
-
210
-        // let's get all current question groups associated with this event.
211
-        $current_qgs = $event->get_many_related(
212
-            'Question_Group',
213
-            [['Event_Question_Group.EQG_primary' => true]]
214
-        );
215
-        $current_qgs = array_keys($current_qgs); // we just want the ids
216
-
217
-        // now let's get the groups selected in the editor and update (IF we have data)
218
-        if (! empty($question_groups)) {
219
-            foreach ($question_groups as $QSG_ID => $val) {
220
-                // add to event
221
-                if ($val) {
222
-                    $qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
223
-                }
224
-                // trip success to false if result is empty
225
-                $success = ! empty($qg) ? $success : false;
226
-            }
227
-        }
228
-
229
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
230
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
231
-
232
-        foreach ($removed_qgs as $QSG_ID) {
233
-            $qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
234
-            // trip success to false if result is empty
235
-            $success = ! empty($qg) ? $success : false;
236
-        }
237
-        return $success;
238
-    }
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param EE_Event $event
199
+	 * @param array    $data
200
+	 * @return bool
201
+	 * @throws EE_Error
202
+	 * @throws ReflectionException
203
+	 */
204
+	public function primary_question_group_update($event, $data)
205
+	{
206
+		$question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
207
+		$added_qgs       = array_keys($question_groups);
208
+		$success         = true;
209
+
210
+		// let's get all current question groups associated with this event.
211
+		$current_qgs = $event->get_many_related(
212
+			'Question_Group',
213
+			[['Event_Question_Group.EQG_primary' => true]]
214
+		);
215
+		$current_qgs = array_keys($current_qgs); // we just want the ids
216
+
217
+		// now let's get the groups selected in the editor and update (IF we have data)
218
+		if (! empty($question_groups)) {
219
+			foreach ($question_groups as $QSG_ID => $val) {
220
+				// add to event
221
+				if ($val) {
222
+					$qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
223
+				}
224
+				// trip success to false if result is empty
225
+				$success = ! empty($qg) ? $success : false;
226
+			}
227
+		}
228
+
229
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
230
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
231
+
232
+		foreach ($removed_qgs as $QSG_ID) {
233
+			$qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
234
+			// trip success to false if result is empty
235
+			$success = ! empty($qg) ? $success : false;
236
+		}
237
+		return $success;
238
+	}
239 239
 }
Please login to merge, or discard this patch.
registration_form/templates/questions_main_meta_box.template.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         EEH_HTML::h4(
35 35
             '<span class="dashicons dashicons-info"></span>'
36 36
             . esc_html__('Did you know...', 'event_espresso')
37
-        ) .
37
+        ).
38 38
         EEH_HTML::p(
39 39
             esc_html__(
40 40
                 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.',
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
                                type="hidden"
96 96
                                value="<?php echo esc_attr($question->get('QST_order')); ?>"
97 97
                         />
98
-                        <?php if (! empty($QST_system)) { ?>
98
+                        <?php if ( ! empty($QST_system)) { ?>
99 99
                             <input id='QST_admin_label'
100 100
                                    name="QST_admin_label"
101 101
                                    type="hidden"
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
                         <?php } ?>
105 105
                         <br />
106 106
                         <p class="description">
107
-                            <?php if (! empty($QST_system)) { ?>
107
+                            <?php if ( ! empty($QST_system)) { ?>
108 108
                                 <span class="description" style="color:#D54E21;">
109 109
                                 <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?>
110 110
                         </span>
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                         <br />
142 142
                         <p class="description">
143 143
                             <?php
144
-                            if (! empty($QST_system)) { ?>
144
+                            if ( ! empty($QST_system)) { ?>
145 145
                                 <span class="description" style="color:#D54E21;">
146 146
                                     <?php esc_html_e(
147 147
                                         'System question! This field cannot be changed.',
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 
174 174
                         // Only display Confirm email for
175 175
                         if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) {
176
-                            unset($question_types[ EEM_Question::QST_type_email_confirm ]);
176
+                            unset($question_types[EEM_Question::QST_type_email_confirm]);
177 177
                         }
178 178
 
179 179
                         echo EEH_Form_Fields::select_input(
180
-                            'QST_type' . $id,
180
+                            'QST_type'.$id,
181 181
                             $question_types,
182 182
                             $question->type(),
183
-                            'id="QST_type' . $id . '"' . $disabled_attr
183
+                            'id="QST_type'.$id.'"'.$disabled_attr
184 184
                         ); // already escaped
185 185
                         if ($disabled) { ?>
186 186
                             <input id='QST_type'
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     </th>
220 220
                     <td>
221 221
                         <input id="QST_max"
222
-                            <?php echo ($max_max === EE_INF ? '' : 'max="' . esc_attr($max_max) . '"'); ?>
222
+                            <?php echo ($max_max === EE_INF ? '' : 'max="'.esc_attr($max_max).'"'); ?>
223 223
                                min="1"
224 224
                                name="QST_max"
225 225
                                type="number"
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
                                 <?php
304 304
                                 $count            = 0;
305 305
                                 $question_options = $question->options();
306
-                                if (! empty($question_options)) {
306
+                                if ( ! empty($question_options)) {
307 307
                                     foreach ($question_options as $option_id => $option) {
308 308
                                         $disabled_attr = $has_answers || $option->get('QSO_system')
309 309
                                             ? 'disabled'
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                                                 />
338 338
                                             </td>
339 339
                                             <td>
340
-                                                <?php if (! $option->system()) { ?>
340
+                                                <?php if ( ! $option->system()) { ?>
341 341
                                                     <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item">
342 342
                                         </span>
343 343
                                                 <?php } ?>
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
                             ['text' => esc_html__('Required', 'event_espresso'), 'id' => 1],
441 441
                         ];
442 442
                         echo EEH_Form_Fields::select_input(
443
-                            'QST_required' . $id,
443
+                            'QST_required'.$id,
444 444
                             $requiredOptions,
445 445
                             $question->required(),
446
-                            'id="QST_required' . $id . '"' . $disabled_attr
446
+                            'id="QST_required'.$id.'"'.$disabled_attr
447 447
                         ); // already escaped
448 448
                         ?>
449 449
                         <p>
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                                 ) ?>
465 465
                             </span>
466 466
                         </p>
467
-                        <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
467
+                        <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
468 468
                             <input type="hidden" id="QST_required" name="QST_required" value="1" />
469 469
                             <p>
470 470
                             <span class="description" style="color:#D54E21;">
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 2 patches
Indentation   +1397 added lines, -1397 removed lines patch added patch discarded remove patch
@@ -18,1412 +18,1412 @@
 block discarded – undo
18 18
 class General_Settings_Admin_Page extends EE_Admin_Page
19 19
 {
20 20
 
21
-    /**
22
-     * _question_group
23
-     * holds the specific question group object for the question group details screen
24
-     *
25
-     * @var object
26
-     */
27
-    protected $_question_group;
28
-
29
-
30
-    /**
31
-     * Initialize basic properties.
32
-     */
33
-    protected function _init_page_props()
34
-    {
35
-        $this->page_slug        = GEN_SET_PG_SLUG;
36
-        $this->page_label       = GEN_SET_LABEL;
37
-        $this->_admin_base_url  = GEN_SET_ADMIN_URL;
38
-        $this->_admin_base_path = GEN_SET_ADMIN;
39
-    }
40
-
41
-
42
-    /**
43
-     * Set ajax hooks
44
-     */
45
-    protected function _ajax_hooks()
46
-    {
47
-        add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
48
-        add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
49
-        add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
50
-        add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
51
-    }
52
-
53
-
54
-    /**
55
-     * More page properties initialization.
56
-     */
57
-    protected function _define_page_props()
58
-    {
59
-        $this->_admin_page_title = GEN_SET_LABEL;
60
-        $this->_labels           = [
61
-            'publishbox' => esc_html__('Update Settings', 'event_espresso'),
62
-        ];
63
-    }
64
-
65
-
66
-    /**
67
-     * Set page routes property.
68
-     */
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = [
72
-
73
-            'critical_pages'                => [
74
-                'func'       => '_espresso_page_settings',
75
-                'capability' => 'manage_options',
76
-            ],
77
-            'update_espresso_page_settings' => [
78
-                'func'       => '_update_espresso_page_settings',
79
-                'capability' => 'manage_options',
80
-                'noheader'   => true,
81
-            ],
82
-            'default'                       => [
83
-                'func'       => '_your_organization_settings',
84
-                'capability' => 'manage_options',
85
-            ],
86
-
87
-            'update_your_organization_settings' => [
88
-                'func'       => '_update_your_organization_settings',
89
-                'capability' => 'manage_options',
90
-                'noheader'   => true,
91
-            ],
92
-
93
-            'admin_option_settings' => [
94
-                'func'       => '_admin_option_settings',
95
-                'capability' => 'manage_options',
96
-            ],
97
-
98
-            'update_admin_option_settings' => [
99
-                'func'       => '_update_admin_option_settings',
100
-                'capability' => 'manage_options',
101
-                'noheader'   => true,
102
-            ],
103
-
104
-            'country_settings' => [
105
-                'func'       => '_country_settings',
106
-                'capability' => 'manage_options',
107
-            ],
108
-
109
-            'update_country_settings' => [
110
-                'func'       => '_update_country_settings',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-            ],
114
-
115
-            'display_country_settings' => [
116
-                'func'       => 'display_country_settings',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ],
120
-
121
-            'add_new_state' => [
122
-                'func'       => 'add_new_state',
123
-                'capability' => 'manage_options',
124
-                'noheader'   => true,
125
-            ],
126
-
127
-            'delete_state'            => [
128
-                'func'       => 'delete_state',
129
-                'capability' => 'manage_options',
130
-                'noheader'   => true,
131
-            ],
132
-            'privacy_settings'        => [
133
-                'func'       => 'privacySettings',
134
-                'capability' => 'manage_options',
135
-            ],
136
-            'update_privacy_settings' => [
137
-                'func'               => 'updatePrivacySettings',
138
-                'capability'         => 'manage_options',
139
-                'noheader'           => true,
140
-                'headers_sent_route' => 'privacy_settings',
141
-            ],
142
-        ];
143
-    }
144
-
145
-
146
-    /**
147
-     * Set page configuration property
148
-     */
149
-    protected function _set_page_config()
150
-    {
151
-        $this->_page_config = [
152
-            'critical_pages'        => [
153
-                'nav'           => [
154
-                    'label' => esc_html__('Critical Pages', 'event_espresso'),
155
-                    'order' => 50,
156
-                ],
157
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
158
-                'help_tabs'     => [
159
-                    'general_settings_critical_pages_help_tab' => [
160
-                        'title'    => esc_html__('Critical Pages', 'event_espresso'),
161
-                        'filename' => 'general_settings_critical_pages',
162
-                    ],
163
-                ],
164
-                'require_nonce' => false,
165
-            ],
166
-            'default'               => [
167
-                'nav'           => [
168
-                    'label' => esc_html__('Your Organization', 'event_espresso'),
169
-                    'order' => 20,
170
-                ],
171
-                'help_tabs'     => [
172
-                    'general_settings_your_organization_help_tab' => [
173
-                        'title'    => esc_html__('Your Organization', 'event_espresso'),
174
-                        'filename' => 'general_settings_your_organization',
175
-                    ],
176
-                ],
177
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
178
-                'require_nonce' => false,
179
-            ],
180
-            'admin_option_settings' => [
181
-                'nav'           => [
182
-                    'label' => esc_html__('Admin Options', 'event_espresso'),
183
-                    'order' => 60,
184
-                ],
185
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
-                'help_tabs'     => [
187
-                    'general_settings_admin_options_help_tab' => [
188
-                        'title'    => esc_html__('Admin Options', 'event_espresso'),
189
-                        'filename' => 'general_settings_admin_options',
190
-                    ],
191
-                ],
192
-                'require_nonce' => false,
193
-            ],
194
-            'country_settings'      => [
195
-                'nav'           => [
196
-                    'label' => esc_html__('Countries', 'event_espresso'),
197
-                    'order' => 70,
198
-                ],
199
-                'help_tabs'     => [
200
-                    'general_settings_countries_help_tab' => [
201
-                        'title'    => esc_html__('Countries', 'event_espresso'),
202
-                        'filename' => 'general_settings_countries',
203
-                    ],
204
-                ],
205
-                'require_nonce' => false,
206
-            ],
207
-            'privacy_settings'      => [
208
-                'nav'           => [
209
-                    'label' => esc_html__('Privacy', 'event_espresso'),
210
-                    'order' => 80,
211
-                ],
212
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
213
-                'require_nonce' => false,
214
-            ],
215
-        ];
216
-    }
217
-
218
-
219
-    protected function _add_screen_options()
220
-    {
221
-    }
222
-
223
-
224
-    protected function _add_feature_pointers()
225
-    {
226
-    }
227
-
228
-
229
-    /**
230
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
231
-     */
232
-    public function load_scripts_styles()
233
-    {
234
-        // styles
235
-        wp_enqueue_style('espresso-ui-theme');
236
-        // scripts
237
-        wp_enqueue_script('ee_admin_js');
238
-    }
239
-
240
-
241
-    /**
242
-     * Execute logic running on `admin_init`
243
-     */
244
-    public function admin_init()
245
-    {
246
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__(
247
-            '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.',
248
-            'event_espresso'
249
-        ));
250
-        EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(__(
251
-            'An error occurred! Please refresh the page and try again.',
252
-            'event_espresso'
253
-        ));
254
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(__(
255
-            'Are you sure you want to delete this State / Province?',
256
-            'event_espresso'
257
-        ));
258
-        $protocol                                                = is_ssl() ? 'https://' : 'http://';
259
-        EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
260
-            'admin-ajax.php?page=espresso_general_settings',
261
-            $protocol
262
-        );
263
-    }
264
-
265
-
266
-    public function admin_notices()
267
-    {
268
-    }
269
-
270
-
271
-    public function admin_footer_scripts()
272
-    {
273
-    }
274
-
275
-
276
-    /**
277
-     * Enqueue scripts and styles for the default route.
278
-     */
279
-    public function load_scripts_styles_default()
280
-    {
281
-        // styles
282
-        wp_enqueue_style('thickbox');
283
-        // scripts
284
-        wp_enqueue_script('media-upload');
285
-        wp_enqueue_script('thickbox');
286
-        wp_register_script(
287
-            'organization_settings',
288
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
289
-            ['jquery', 'media-upload', 'thickbox'],
290
-            EVENT_ESPRESSO_VERSION,
291
-            true
292
-        );
293
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
294
-        wp_enqueue_script('organization_settings');
295
-        wp_enqueue_style('organization-css');
296
-        $confirm_image_delete = [
297
-            'text' => wp_strip_all_tags(
298
-                __(
299
-                    'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
300
-                    'event_espresso'
301
-                )
302
-            ),
303
-        ];
304
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
305
-    }
306
-
307
-
308
-    /**
309
-     * Enqueue scripts and styles for the country settings route.
310
-     */
311
-    public function load_scripts_styles_country_settings()
312
-    {
313
-        // scripts
314
-        wp_register_script(
315
-            'gen_settings_countries',
316
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
317
-            ['ee_admin_js'],
318
-            EVENT_ESPRESSO_VERSION,
319
-            true
320
-        );
321
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
322
-        wp_enqueue_script('gen_settings_countries');
323
-        wp_enqueue_style('organization-css');
324
-    }
325
-
326
-
327
-    /*************        Espresso Pages        *************/
328
-    /**
329
-     * _espresso_page_settings
330
-     *
331
-     * @throws EE_Error
332
-     * @throws DomainException
333
-     * @throws DomainException
334
-     * @throws InvalidDataTypeException
335
-     * @throws InvalidArgumentException
336
-     */
337
-    protected function _espresso_page_settings()
338
-    {
339
-        // Check to make sure all of the main pages are set up properly,
340
-        // if not create the default pages and display an admin notice
341
-        EEH_Activation::verify_default_pages_exist();
342
-        $this->_transient_garbage_collection();
343
-        $this->_template_args['values']             = $this->_yes_no_values;
344
-        $this->_template_args['reg_page_id']        = isset(EE_Registry::instance()->CFG->core->reg_page_id)
345
-            ? EE_Registry::instance()->CFG->core->reg_page_id
346
-            : null;
347
-        $this->_template_args['reg_page_obj']       = isset(EE_Registry::instance()->CFG->core->reg_page_id)
348
-            ? get_post(EE_Registry::instance()->CFG->core->reg_page_id)
349
-            : false;
350
-        $this->_template_args['txn_page_id']        = isset(EE_Registry::instance()->CFG->core->txn_page_id)
351
-            ? EE_Registry::instance()->CFG->core->txn_page_id
352
-            : null;
353
-        $this->_template_args['txn_page_obj']       = isset(EE_Registry::instance()->CFG->core->txn_page_id)
354
-            ? get_post(EE_Registry::instance()->CFG->core->txn_page_id)
355
-            : false;
356
-        $this->_template_args['thank_you_page_id']  = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
357
-            ? EE_Registry::instance()->CFG->core->thank_you_page_id
358
-            : null;
359
-        $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
360
-            ? get_post(EE_Registry::instance()->CFG->core->thank_you_page_id)
361
-            : false;
362
-        $this->_template_args['cancel_page_id']     = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
363
-            ? EE_Registry::instance()->CFG->core->cancel_page_id
364
-            : null;
365
-        $this->_template_args['cancel_page_obj']    = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
366
-            ? get_post(EE_Registry::instance()->CFG->core->cancel_page_id)
367
-            : false;
368
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
369
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
370
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
371
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
372
-            $this->_template_args,
373
-            true
374
-        );
375
-        $this->display_admin_page_with_sidebar();
376
-    }
377
-
378
-
379
-    /**
380
-     * Handler for updating espresso page settings.
381
-     *
382
-     * @throws EE_Error
383
-     */
384
-    protected function _update_espresso_page_settings()
385
-    {
386
-        // capture incoming request data && set page IDs
387
-        EE_Registry::instance()->CFG->core->reg_page_id       = isset($this->_req_data['reg_page_id'])
388
-            ? absint($this->_req_data['reg_page_id'])
389
-            : EE_Registry::instance()->CFG->core->reg_page_id;
390
-        EE_Registry::instance()->CFG->core->txn_page_id       = isset($this->_req_data['txn_page_id'])
391
-            ? absint($this->_req_data['txn_page_id'])
392
-            : EE_Registry::instance()->CFG->core->txn_page_id;
393
-        EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
394
-            ? absint($this->_req_data['thank_you_page_id'])
395
-            : EE_Registry::instance()->CFG->core->thank_you_page_id;
396
-        EE_Registry::instance()->CFG->core->cancel_page_id    = isset($this->_req_data['cancel_page_id'])
397
-            ? absint($this->_req_data['cancel_page_id'])
398
-            : EE_Registry::instance()->CFG->core->cancel_page_id;
399
-
400
-        EE_Registry::instance()->CFG->core = apply_filters(
401
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
402
-            EE_Registry::instance()->CFG->core,
403
-            $this->_req_data
404
-        );
405
-        $what                              = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
406
-        $this->_redirect_after_action(
407
-            $this->_update_espresso_configuration(
408
-                $what,
409
-                EE_Registry::instance()->CFG->core,
410
-                __FILE__,
411
-                __FUNCTION__,
412
-                __LINE__
413
-            ),
414
-            $what,
415
-            '',
416
-            [
417
-                'action' => 'critical_pages',
418
-            ],
419
-            true
420
-        );
421
-    }
422
-
423
-
424
-    /*************        Your Organization        *************/
425
-
426
-
427
-    /**
428
-     * @throws DomainException
429
-     * @throws EE_Error
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidDataTypeException
432
-     * @throws InvalidInterfaceException
433
-     */
434
-    protected function _your_organization_settings()
435
-    {
436
-        $this->_template_args['admin_page_content'] = '';
437
-        try {
438
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
439
-            $organization_settings_form                 = $this->loader->getShared(
440
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
441
-            );
442
-            $this->_template_args['admin_page_content'] = $organization_settings_form->display();
443
-        } catch (Exception $e) {
444
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
445
-        }
446
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
447
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
448
-        $this->display_admin_page_with_sidebar();
449
-    }
450
-
451
-
452
-    /**
453
-     * Handler for updating organization settings.
454
-     *
455
-     * @throws EE_Error
456
-     */
457
-    protected function _update_your_organization_settings()
458
-    {
459
-        try {
460
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
461
-            $organization_settings_form  = $this->loader->getShared(
462
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
463
-            );
464
-            $success                     = $organization_settings_form->process($this->_req_data);
465
-            EE_Registry::instance()->CFG = apply_filters(
466
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
467
-                EE_Registry::instance()->CFG
468
-            );
469
-        } catch (Exception $e) {
470
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
471
-            $success = false;
472
-        }
473
-
474
-        if ($success) {
475
-            $success = $this->_update_espresso_configuration(
476
-                esc_html__('Your Organization Settings', 'event_espresso'),
477
-                EE_Registry::instance()->CFG,
478
-                __FILE__,
479
-                __FUNCTION__,
480
-                __LINE__
481
-            );
482
-        }
483
-
484
-        $this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
485
-    }
486
-
487
-
488
-
489
-    /*************        Admin Options        *************/
490
-
491
-
492
-    /**
493
-     * _admin_option_settings
494
-     *
495
-     * @throws EE_Error
496
-     * @throws LogicException
497
-     */
498
-    protected function _admin_option_settings()
499
-    {
500
-        $this->_template_args['admin_page_content'] = '';
501
-        try {
502
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
503
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
504
-            $this->_template_args['values'] = $this->_yes_no_values;
505
-            // also need to account for the do_action that was in the old template
506
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
507
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
508
-        } catch (Exception $e) {
509
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
510
-        }
511
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
512
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
513
-        $this->display_admin_page_with_sidebar();
514
-    }
515
-
516
-
517
-    /**
518
-     * _update_admin_option_settings
519
-     *
520
-     * @throws EE_Error
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidFormSubmissionException
523
-     * @throws InvalidArgumentException
524
-     * @throws LogicException
525
-     */
526
-    protected function _update_admin_option_settings()
527
-    {
528
-        try {
529
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
530
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
531
-            EE_Registry::instance()->CFG->admin = apply_filters(
532
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
533
-                EE_Registry::instance()->CFG->admin
534
-            );
535
-        } catch (Exception $e) {
536
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
-        }
538
-        $this->_redirect_after_action(
539
-            apply_filters(
540
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
541
-                $this->_update_espresso_configuration(
542
-                    'Admin Options',
543
-                    EE_Registry::instance()->CFG->admin,
544
-                    __FILE__,
545
-                    __FUNCTION__,
546
-                    __LINE__
547
-                )
548
-            ),
549
-            'Admin Options',
550
-            'updated',
551
-            ['action' => 'admin_option_settings']
552
-        );
553
-    }
554
-
555
-
556
-    /*************        Countries        *************/
557
-
558
-
559
-    /**
560
-     * @return string
561
-     */
562
-    protected function getCountryIsoForSite()
563
-    {
564
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
565
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
566
-            : 'US';
567
-    }
568
-
569
-
570
-    /**
571
-     * @param string          $CNT_ISO
572
-     * @param EE_Country|null $country
573
-     * @return EE_Base_Class|EE_Country
574
-     * @throws EE_Error
575
-     * @throws InvalidArgumentException
576
-     * @throws InvalidDataTypeException
577
-     * @throws InvalidInterfaceException
578
-     * @throws ReflectionException
579
-     */
580
-    protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
581
-    {
582
-        /** @var EE_Country $country */
583
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
584
-            ? $country
585
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
586
-    }
587
-
588
-
589
-    /**
590
-     * Output Country Settings view.
591
-     *
592
-     * @throws DomainException
593
-     * @throws EE_Error
594
-     * @throws InvalidArgumentException
595
-     * @throws InvalidDataTypeException
596
-     * @throws InvalidInterfaceException
597
-     * @throws ReflectionException
598
-     */
599
-    protected function _country_settings()
600
-    {
601
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
602
-        $CNT_ISO          = isset($this->_req_data['country'])
603
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
604
-            : $CNT_ISO_for_site;
605
-
606
-        // load field generator helper
607
-
608
-        $this->_template_args['values'] = $this->_yes_no_values;
609
-
610
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
611
-            EE_Question::new_instance(
612
-                [
613
-                    'QST_ID'           => 0,
614
-                    'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
615
-                    'QST_system'       => 'admin-country',
616
-                ]
617
-            ),
618
-            EE_Answer::new_instance(
619
-                [
620
-                    'ANS_ID'    => 0,
621
-                    'ANS_value' => $CNT_ISO,
622
-                ]
623
-            ),
624
-            [
625
-                'input_id'       => 'country',
626
-                'input_name'     => 'country',
627
-                'input_prefix'   => '',
628
-                'append_qstn_id' => false,
629
-            ]
630
-        );
631
-        $country                           = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
632
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
633
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
634
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
635
-            $country->ID(),
636
-            $country
637
-        );
638
-        $this->_template_args['country_states_settings']  = $this->display_country_states(
639
-            $country->ID(),
640
-            $country
641
-        );
642
-        $this->_template_args['CNT_name_for_site']        = $country->name();
643
-
644
-        $this->_set_add_edit_form_tags('update_country_settings');
645
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
646
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
647
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
648
-            $this->_template_args,
649
-            true
650
-        );
651
-        $this->display_admin_page_with_no_sidebar();
652
-    }
653
-
654
-
655
-    /**
656
-     * @param string          $CNT_ISO
657
-     * @param EE_Country|null $country
658
-     * @return string
659
-     * @throws DomainException
660
-     * @throws EE_Error
661
-     * @throws InvalidArgumentException
662
-     * @throws InvalidDataTypeException
663
-     * @throws InvalidInterfaceException
664
-     * @throws ReflectionException
665
-     */
666
-    public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
667
-    {
668
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
669
-
670
-        $CNT_ISO = isset($this->_req_data['country'])
671
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
672
-            : $CNT_ISO;
673
-        if (! $CNT_ISO) {
674
-            return '';
675
-        }
676
-
677
-        // for ajax
678
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
679
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
680
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
681
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
682
-        $country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
683
-        $CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
684
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
685
-
686
-        $country_input_types            = [
687
-            'CNT_active'      => [
688
-                'type'             => 'RADIO_BTN',
689
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
690
-                'class'            => '',
691
-                'options'          => $this->_yes_no_values,
692
-                'use_desc_4_label' => true,
693
-            ],
694
-            'CNT_ISO'         => [
695
-                'type'       => 'TEXT',
696
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
697
-                'class'      => 'small-text',
698
-            ],
699
-            'CNT_ISO3'        => [
700
-                'type'       => 'TEXT',
701
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
702
-                'class'      => 'small-text',
703
-            ],
704
-            'RGN_ID'          => [
705
-                'type'       => 'TEXT',
706
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
707
-                'class'      => 'small-text',
708
-            ],
709
-            'CNT_name'        => [
710
-                'type'       => 'TEXT',
711
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
712
-                'class'      => 'regular-text',
713
-            ],
714
-            'CNT_cur_code'    => [
715
-                'type'       => 'TEXT',
716
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
717
-                'class'      => 'small-text',
718
-                'disabled'   => $CNT_cur_disabled,
719
-            ],
720
-            'CNT_cur_single'  => [
721
-                'type'       => 'TEXT',
722
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
723
-                'class'      => 'medium-text',
724
-                'disabled'   => $CNT_cur_disabled,
725
-            ],
726
-            'CNT_cur_plural'  => [
727
-                'type'       => 'TEXT',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
729
-                'class'      => 'medium-text',
730
-                'disabled'   => $CNT_cur_disabled,
731
-            ],
732
-            'CNT_cur_sign'    => [
733
-                'type'         => 'TEXT',
734
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
735
-                'class'        => 'small-text',
736
-                'htmlentities' => false,
737
-                'disabled'     => $CNT_cur_disabled,
738
-            ],
739
-            'CNT_cur_sign_b4' => [
740
-                'type'             => 'RADIO_BTN',
741
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
742
-                'class'            => '',
743
-                'options'          => $this->_yes_no_values,
744
-                'use_desc_4_label' => true,
745
-                'disabled'         => $CNT_cur_disabled,
746
-            ],
747
-            'CNT_cur_dec_plc' => [
748
-                'type'       => 'RADIO_BTN',
749
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
750
-                'class'      => '',
751
-                'options'    => [
752
-                    ['id' => 0, 'text' => ''],
753
-                    ['id' => 1, 'text' => ''],
754
-                    ['id' => 2, 'text' => ''],
755
-                    ['id' => 3, 'text' => ''],
756
-                ],
757
-                'disabled'   => $CNT_cur_disabled,
758
-            ],
759
-            'CNT_cur_dec_mrk' => [
760
-                'type'             => 'RADIO_BTN',
761
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
762
-                'class'            => '',
763
-                'options'          => [
764
-                    [
765
-                        'id'   => ',',
766
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
767
-                    ],
768
-                    ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
769
-                ],
770
-                'use_desc_4_label' => true,
771
-                'disabled'         => $CNT_cur_disabled,
772
-            ],
773
-            'CNT_cur_thsnds'  => [
774
-                'type'             => 'RADIO_BTN',
775
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
776
-                'class'            => '',
777
-                'options'          => [
778
-                    [
779
-                        'id'   => ',',
780
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
781
-                    ],
782
-                    [
783
-                        'id'   => '.',
784
-                        'text' => esc_html__('. (decimal)', 'event_espresso'),
785
-                    ],
786
-                    [
787
-                        'id'   => '&nbsp;',
788
-                        'text' => esc_html__('(space)', 'event_espresso'),
789
-                    ],
790
-                ],
791
-                'use_desc_4_label' => true,
792
-                'disabled'         => $CNT_cur_disabled,
793
-            ],
794
-            'CNT_tel_code'    => [
795
-                'type'       => 'TEXT',
796
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
797
-                'class'      => 'small-text',
798
-            ],
799
-            'CNT_is_EU'       => [
800
-                'type'             => 'RADIO_BTN',
801
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
802
-                'class'            => '',
803
-                'options'          => $this->_yes_no_values,
804
-                'use_desc_4_label' => true,
805
-            ],
806
-        ];
807
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
808
-            $country,
809
-            $country_input_types
810
-        );
811
-        $country_details_settings       = EEH_Template::display_template(
812
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
813
-            $this->_template_args,
814
-            true
815
-        );
816
-
817
-        if (defined('DOING_AJAX')) {
818
-            $notices = EE_Error::get_notices(false, false, false);
819
-            echo wp_json_encode(
820
-                [
821
-                    'return_data' => $country_details_settings,
822
-                    'success'     => $notices['success'],
823
-                    'errors'      => $notices['errors'],
824
-                ]
825
-            );
826
-            die();
827
-        } else {
828
-            return $country_details_settings;
829
-        }
830
-    }
831
-
832
-
833
-    /**
834
-     * @param string          $CNT_ISO
835
-     * @param EE_Country|null $country
836
-     * @return string
837
-     * @throws DomainException
838
-     * @throws EE_Error
839
-     * @throws InvalidArgumentException
840
-     * @throws InvalidDataTypeException
841
-     * @throws InvalidInterfaceException
842
-     * @throws ReflectionException
843
-     */
844
-    public function display_country_states($CNT_ISO = '', EE_Country $country = null)
845
-    {
846
-
847
-        $CNT_ISO = isset($this->_req_data['country'])
848
-            ? sanitize_text_field($this->_req_data['country'])
849
-            : $CNT_ISO;
850
-        if (! $CNT_ISO) {
851
-            return '';
852
-        }
853
-        // for ajax
854
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
855
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
856
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
857
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10, 2);
858
-        $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
859
-        if (empty($states)) {
860
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
861
-            $countrySubRegionDao = $this->loader->getShared(
862
-                'EventEspresso\core\services\address\CountrySubRegionDao'
863
-            );
864
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
865
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
866
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
867
-                    $states = EEM_State::instance()->get_all_states_for_these_countries(
868
-                        [$CNT_ISO => $CNT_ISO]
869
-                    );
870
-                }
871
-            }
872
-        }
873
-        if (is_array($states)) {
874
-            foreach ($states as $STA_ID => $state) {
875
-                if ($state instanceof EE_State) {
876
-                    // STA_abbrev    STA_name    STA_active
877
-                    $state_input_types                                             = [
878
-                        'STA_abbrev' => [
879
-                            'type'       => 'TEXT',
880
-                            'input_name' => 'states[' . $STA_ID . ']',
881
-                            'class'      => 'small-text',
882
-                        ],
883
-                        'STA_name'   => [
884
-                            'type'       => 'TEXT',
885
-                            'input_name' => 'states[' . $STA_ID . ']',
886
-                            'class'      => 'regular-text',
887
-                        ],
888
-                        'STA_active' => [
889
-                            'type'             => 'RADIO_BTN',
890
-                            'input_name'       => 'states[' . $STA_ID . ']',
891
-                            'options'          => $this->_yes_no_values,
892
-                            'use_desc_4_label' => true,
893
-                        ],
894
-                    ];
895
-                    $this->_template_args['states'][ $STA_ID ]['inputs']           =
896
-                        EE_Question_Form_Input::generate_question_form_inputs_for_object(
897
-                            $state,
898
-                            $state_input_types
899
-                        );
900
-                    $query_args                                                    = [
901
-                        'action'     => 'delete_state',
902
-                        'STA_ID'     => $STA_ID,
903
-                        'CNT_ISO'    => $CNT_ISO,
904
-                        'STA_abbrev' => $state->abbrev(),
905
-                    ];
906
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
907
-                        EE_Admin_Page::add_query_args_and_nonce(
908
-                            $query_args,
909
-                            GEN_SET_ADMIN_URL
910
-                        );
911
-                }
912
-            }
913
-        } else {
914
-            $this->_template_args['states'] = false;
915
-        }
916
-
917
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
918
-            ['action' => 'add_new_state'],
919
-            GEN_SET_ADMIN_URL
920
-        );
921
-
922
-        $state_details_settings = EEH_Template::display_template(
923
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
924
-            $this->_template_args,
925
-            true
926
-        );
927
-
928
-        if (defined('DOING_AJAX')) {
929
-            $notices = EE_Error::get_notices(false, false, false);
930
-            echo wp_json_encode(
931
-                [
932
-                    'return_data' => $state_details_settings,
933
-                    'success'     => $notices['success'],
934
-                    'errors'      => $notices['errors'],
935
-                ]
936
-            );
937
-            die();
938
-        } else {
939
-            return $state_details_settings;
940
-        }
941
-    }
942
-
943
-
944
-    /**
945
-     *        add_new_state
946
-     *
947
-     * @access    public
948
-     * @return void
949
-     * @throws EE_Error
950
-     * @throws InvalidArgumentException
951
-     * @throws InvalidDataTypeException
952
-     * @throws InvalidInterfaceException
953
-     */
954
-    public function add_new_state()
955
-    {
956
-
957
-        $success = true;
958
-
959
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
960
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
961
-            : false;
962
-        if (! $CNT_ISO) {
963
-            EE_Error::add_error(
964
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
965
-                __FILE__,
966
-                __FUNCTION__,
967
-                __LINE__
968
-            );
969
-            $success = false;
970
-        }
971
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
972
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
973
-            : false;
974
-        if (! $STA_abbrev) {
975
-            EE_Error::add_error(
976
-                esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
977
-                __FILE__,
978
-                __FUNCTION__,
979
-                __LINE__
980
-            );
981
-            $success = false;
982
-        }
983
-        $STA_name = isset($this->_req_data['STA_name'])
984
-            ? sanitize_text_field($this->_req_data['STA_name'])
985
-            : false;
986
-        if (! $STA_name) {
987
-            EE_Error::add_error(
988
-                esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
989
-                __FILE__,
990
-                __FUNCTION__,
991
-                __LINE__
992
-            );
993
-            $success = false;
994
-        }
995
-
996
-        if ($success) {
997
-            $cols_n_values = [
998
-                'CNT_ISO'    => $CNT_ISO,
999
-                'STA_abbrev' => $STA_abbrev,
1000
-                'STA_name'   => $STA_name,
1001
-                'STA_active' => true,
1002
-            ];
1003
-            $success       = EEM_State::instance()->insert($cols_n_values);
1004
-            EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1005
-        }
1006
-
1007
-        if (defined('DOING_AJAX')) {
1008
-            $notices = EE_Error::get_notices(false, false, false);
1009
-            echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1010
-            die();
1011
-        } else {
1012
-            $this->_redirect_after_action($success, 'State', 'added', ['action' => 'country_settings']);
1013
-        }
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * @return void
1019
-     * @throws EE_Error
1020
-     * @throws InvalidArgumentException
1021
-     * @throws InvalidDataTypeException
1022
-     * @throws InvalidInterfaceException
1023
-     */
1024
-    public function delete_state()
1025
-    {
1026
-        $CNT_ISO    = isset($this->_req_data['CNT_ISO'])
1027
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1028
-            : false;
1029
-        $STA_ID     = isset($this->_req_data['STA_ID'])
1030
-            ? sanitize_text_field($this->_req_data['STA_ID'])
1031
-            : false;
1032
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1033
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
1034
-            : false;
1035
-        if (! $STA_ID) {
1036
-            EE_Error::add_error(
1037
-                esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1038
-                __FILE__,
1039
-                __FUNCTION__,
1040
-                __LINE__
1041
-            );
1042
-            return;
1043
-        }
1044
-
1045
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1046
-        if ($success !== false) {
1047
-            do_action(
1048
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1049
-                $CNT_ISO,
1050
-                $STA_ID,
1051
-                ['STA_abbrev' => $STA_abbrev]
1052
-            );
1053
-            EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1054
-        }
1055
-        if (defined('DOING_AJAX')) {
1056
-            $notices                = EE_Error::get_notices(false);
1057
-            $notices['return_data'] = true;
1058
-            echo wp_json_encode($notices);
1059
-            die();
1060
-        } else {
1061
-            $this->_redirect_after_action(
1062
-                $success,
1063
-                'State',
1064
-                'deleted',
1065
-                ['action' => 'country_settings']
1066
-            );
1067
-        }
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     *        _update_country_settings
1073
-     *
1074
-     * @return void
1075
-     * @throws EE_Error
1076
-     * @throws InvalidArgumentException
1077
-     * @throws InvalidDataTypeException
1078
-     * @throws InvalidInterfaceException
1079
-     */
1080
-    protected function _update_country_settings()
1081
-    {
1082
-        // grab the country ISO code
1083
-        $CNT_ISO = isset($this->_req_data['country'])
1084
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
1085
-            : false;
1086
-        if (! $CNT_ISO) {
1087
-            EE_Error::add_error(
1088
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1089
-                __FILE__,
1090
-                __FUNCTION__,
1091
-                __LINE__
1092
-            );
1093
-
1094
-            return;
1095
-        }
1096
-        $cols_n_values             = [];
1097
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1098
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1099
-            : false;
1100
-        $cols_n_values['RGN_ID']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1101
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1102
-            : null;
1103
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1104
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1105
-            : null;
1106
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1107
-            $cols_n_values['CNT_cur_code'] = strtoupper(
1108
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1109
-            );
1110
-        }
1111
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1112
-            $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1113
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1114
-            );
1115
-        }
1116
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1117
-            $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1118
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1119
-            );
1120
-        }
1121
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1122
-            $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1123
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1124
-            );
1125
-        }
1126
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1127
-            $cols_n_values['CNT_cur_sign_b4'] = absint(
1128
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1129
-            );
1130
-        }
1131
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1132
-            $cols_n_values['CNT_cur_dec_plc'] = absint(
1133
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1134
-            );
1135
-        }
1136
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1137
-            $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1138
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1139
-            );
1140
-        }
1141
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1142
-            $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1143
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1144
-            );
1145
-        }
1146
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1147
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1148
-            : null;
1149
-        $cols_n_values['CNT_is_EU']    = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1150
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1151
-            : false;
1152
-        $cols_n_values['CNT_active']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1153
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1154
-            : false;
1155
-        // allow filtering of country data
1156
-        $cols_n_values = apply_filters(
1157
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1158
-            $cols_n_values
1159
-        );
1160
-
1161
-        // where values
1162
-        $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1163
-        // run the update
1164
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1165
-
1166
-        if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1167
-            // allow filtering of states data
1168
-            $states = apply_filters(
1169
-                'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1170
-                $this->_req_data['states']
1171
-            );
1172
-
1173
-            // loop thru state data ( looks like : states[75][STA_name] )
1174
-            foreach ($states as $STA_ID => $state) {
1175
-                $cols_n_values = [
1176
-                    'CNT_ISO'    => $CNT_ISO,
1177
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1178
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1179
-                    'STA_active' => (bool) absint($state['STA_active']),
1180
-                ];
1181
-                // where values
1182
-                $where_cols_n_values = [['STA_ID' => $STA_ID]];
1183
-                // run the update
1184
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1185
-                if ($success !== false) {
1186
-                    do_action(
1187
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1188
-                        $CNT_ISO,
1189
-                        $STA_ID,
1190
-                        $cols_n_values
1191
-                    );
1192
-                }
1193
-            }
1194
-        }
1195
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1196
-        if (
1197
-            isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1198
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1199
-        ) {
1200
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1201
-            EE_Registry::instance()->CFG->update_espresso_config();
1202
-        }
1203
-
1204
-        if ($success !== false) {
1205
-            EE_Error::add_success(
1206
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1207
-            );
1208
-        }
1209
-        $this->_redirect_after_action(
1210
-            $success,
1211
-            '',
1212
-            '',
1213
-            ['action' => 'country_settings', 'country' => $CNT_ISO],
1214
-            true
1215
-        );
1216
-    }
1217
-
1218
-
1219
-    /**
1220
-     *        form_form_field_label_wrap
1221
-     *
1222
-     * @param string $label
1223
-     * @return        string
1224
-     */
1225
-    public function country_form_field_label_wrap($label, $required_text)
1226
-    {
1227
-        return '
21
+	/**
22
+	 * _question_group
23
+	 * holds the specific question group object for the question group details screen
24
+	 *
25
+	 * @var object
26
+	 */
27
+	protected $_question_group;
28
+
29
+
30
+	/**
31
+	 * Initialize basic properties.
32
+	 */
33
+	protected function _init_page_props()
34
+	{
35
+		$this->page_slug        = GEN_SET_PG_SLUG;
36
+		$this->page_label       = GEN_SET_LABEL;
37
+		$this->_admin_base_url  = GEN_SET_ADMIN_URL;
38
+		$this->_admin_base_path = GEN_SET_ADMIN;
39
+	}
40
+
41
+
42
+	/**
43
+	 * Set ajax hooks
44
+	 */
45
+	protected function _ajax_hooks()
46
+	{
47
+		add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
48
+		add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
49
+		add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
50
+		add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
51
+	}
52
+
53
+
54
+	/**
55
+	 * More page properties initialization.
56
+	 */
57
+	protected function _define_page_props()
58
+	{
59
+		$this->_admin_page_title = GEN_SET_LABEL;
60
+		$this->_labels           = [
61
+			'publishbox' => esc_html__('Update Settings', 'event_espresso'),
62
+		];
63
+	}
64
+
65
+
66
+	/**
67
+	 * Set page routes property.
68
+	 */
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = [
72
+
73
+			'critical_pages'                => [
74
+				'func'       => '_espresso_page_settings',
75
+				'capability' => 'manage_options',
76
+			],
77
+			'update_espresso_page_settings' => [
78
+				'func'       => '_update_espresso_page_settings',
79
+				'capability' => 'manage_options',
80
+				'noheader'   => true,
81
+			],
82
+			'default'                       => [
83
+				'func'       => '_your_organization_settings',
84
+				'capability' => 'manage_options',
85
+			],
86
+
87
+			'update_your_organization_settings' => [
88
+				'func'       => '_update_your_organization_settings',
89
+				'capability' => 'manage_options',
90
+				'noheader'   => true,
91
+			],
92
+
93
+			'admin_option_settings' => [
94
+				'func'       => '_admin_option_settings',
95
+				'capability' => 'manage_options',
96
+			],
97
+
98
+			'update_admin_option_settings' => [
99
+				'func'       => '_update_admin_option_settings',
100
+				'capability' => 'manage_options',
101
+				'noheader'   => true,
102
+			],
103
+
104
+			'country_settings' => [
105
+				'func'       => '_country_settings',
106
+				'capability' => 'manage_options',
107
+			],
108
+
109
+			'update_country_settings' => [
110
+				'func'       => '_update_country_settings',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+			],
114
+
115
+			'display_country_settings' => [
116
+				'func'       => 'display_country_settings',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			],
120
+
121
+			'add_new_state' => [
122
+				'func'       => 'add_new_state',
123
+				'capability' => 'manage_options',
124
+				'noheader'   => true,
125
+			],
126
+
127
+			'delete_state'            => [
128
+				'func'       => 'delete_state',
129
+				'capability' => 'manage_options',
130
+				'noheader'   => true,
131
+			],
132
+			'privacy_settings'        => [
133
+				'func'       => 'privacySettings',
134
+				'capability' => 'manage_options',
135
+			],
136
+			'update_privacy_settings' => [
137
+				'func'               => 'updatePrivacySettings',
138
+				'capability'         => 'manage_options',
139
+				'noheader'           => true,
140
+				'headers_sent_route' => 'privacy_settings',
141
+			],
142
+		];
143
+	}
144
+
145
+
146
+	/**
147
+	 * Set page configuration property
148
+	 */
149
+	protected function _set_page_config()
150
+	{
151
+		$this->_page_config = [
152
+			'critical_pages'        => [
153
+				'nav'           => [
154
+					'label' => esc_html__('Critical Pages', 'event_espresso'),
155
+					'order' => 50,
156
+				],
157
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
158
+				'help_tabs'     => [
159
+					'general_settings_critical_pages_help_tab' => [
160
+						'title'    => esc_html__('Critical Pages', 'event_espresso'),
161
+						'filename' => 'general_settings_critical_pages',
162
+					],
163
+				],
164
+				'require_nonce' => false,
165
+			],
166
+			'default'               => [
167
+				'nav'           => [
168
+					'label' => esc_html__('Your Organization', 'event_espresso'),
169
+					'order' => 20,
170
+				],
171
+				'help_tabs'     => [
172
+					'general_settings_your_organization_help_tab' => [
173
+						'title'    => esc_html__('Your Organization', 'event_espresso'),
174
+						'filename' => 'general_settings_your_organization',
175
+					],
176
+				],
177
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
178
+				'require_nonce' => false,
179
+			],
180
+			'admin_option_settings' => [
181
+				'nav'           => [
182
+					'label' => esc_html__('Admin Options', 'event_espresso'),
183
+					'order' => 60,
184
+				],
185
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
+				'help_tabs'     => [
187
+					'general_settings_admin_options_help_tab' => [
188
+						'title'    => esc_html__('Admin Options', 'event_espresso'),
189
+						'filename' => 'general_settings_admin_options',
190
+					],
191
+				],
192
+				'require_nonce' => false,
193
+			],
194
+			'country_settings'      => [
195
+				'nav'           => [
196
+					'label' => esc_html__('Countries', 'event_espresso'),
197
+					'order' => 70,
198
+				],
199
+				'help_tabs'     => [
200
+					'general_settings_countries_help_tab' => [
201
+						'title'    => esc_html__('Countries', 'event_espresso'),
202
+						'filename' => 'general_settings_countries',
203
+					],
204
+				],
205
+				'require_nonce' => false,
206
+			],
207
+			'privacy_settings'      => [
208
+				'nav'           => [
209
+					'label' => esc_html__('Privacy', 'event_espresso'),
210
+					'order' => 80,
211
+				],
212
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
213
+				'require_nonce' => false,
214
+			],
215
+		];
216
+	}
217
+
218
+
219
+	protected function _add_screen_options()
220
+	{
221
+	}
222
+
223
+
224
+	protected function _add_feature_pointers()
225
+	{
226
+	}
227
+
228
+
229
+	/**
230
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
231
+	 */
232
+	public function load_scripts_styles()
233
+	{
234
+		// styles
235
+		wp_enqueue_style('espresso-ui-theme');
236
+		// scripts
237
+		wp_enqueue_script('ee_admin_js');
238
+	}
239
+
240
+
241
+	/**
242
+	 * Execute logic running on `admin_init`
243
+	 */
244
+	public function admin_init()
245
+	{
246
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(__(
247
+			'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.',
248
+			'event_espresso'
249
+		));
250
+		EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(__(
251
+			'An error occurred! Please refresh the page and try again.',
252
+			'event_espresso'
253
+		));
254
+		EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(__(
255
+			'Are you sure you want to delete this State / Province?',
256
+			'event_espresso'
257
+		));
258
+		$protocol                                                = is_ssl() ? 'https://' : 'http://';
259
+		EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
260
+			'admin-ajax.php?page=espresso_general_settings',
261
+			$protocol
262
+		);
263
+	}
264
+
265
+
266
+	public function admin_notices()
267
+	{
268
+	}
269
+
270
+
271
+	public function admin_footer_scripts()
272
+	{
273
+	}
274
+
275
+
276
+	/**
277
+	 * Enqueue scripts and styles for the default route.
278
+	 */
279
+	public function load_scripts_styles_default()
280
+	{
281
+		// styles
282
+		wp_enqueue_style('thickbox');
283
+		// scripts
284
+		wp_enqueue_script('media-upload');
285
+		wp_enqueue_script('thickbox');
286
+		wp_register_script(
287
+			'organization_settings',
288
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
289
+			['jquery', 'media-upload', 'thickbox'],
290
+			EVENT_ESPRESSO_VERSION,
291
+			true
292
+		);
293
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
294
+		wp_enqueue_script('organization_settings');
295
+		wp_enqueue_style('organization-css');
296
+		$confirm_image_delete = [
297
+			'text' => wp_strip_all_tags(
298
+				__(
299
+					'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
300
+					'event_espresso'
301
+				)
302
+			),
303
+		];
304
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
305
+	}
306
+
307
+
308
+	/**
309
+	 * Enqueue scripts and styles for the country settings route.
310
+	 */
311
+	public function load_scripts_styles_country_settings()
312
+	{
313
+		// scripts
314
+		wp_register_script(
315
+			'gen_settings_countries',
316
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
317
+			['ee_admin_js'],
318
+			EVENT_ESPRESSO_VERSION,
319
+			true
320
+		);
321
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
322
+		wp_enqueue_script('gen_settings_countries');
323
+		wp_enqueue_style('organization-css');
324
+	}
325
+
326
+
327
+	/*************        Espresso Pages        *************/
328
+	/**
329
+	 * _espresso_page_settings
330
+	 *
331
+	 * @throws EE_Error
332
+	 * @throws DomainException
333
+	 * @throws DomainException
334
+	 * @throws InvalidDataTypeException
335
+	 * @throws InvalidArgumentException
336
+	 */
337
+	protected function _espresso_page_settings()
338
+	{
339
+		// Check to make sure all of the main pages are set up properly,
340
+		// if not create the default pages and display an admin notice
341
+		EEH_Activation::verify_default_pages_exist();
342
+		$this->_transient_garbage_collection();
343
+		$this->_template_args['values']             = $this->_yes_no_values;
344
+		$this->_template_args['reg_page_id']        = isset(EE_Registry::instance()->CFG->core->reg_page_id)
345
+			? EE_Registry::instance()->CFG->core->reg_page_id
346
+			: null;
347
+		$this->_template_args['reg_page_obj']       = isset(EE_Registry::instance()->CFG->core->reg_page_id)
348
+			? get_post(EE_Registry::instance()->CFG->core->reg_page_id)
349
+			: false;
350
+		$this->_template_args['txn_page_id']        = isset(EE_Registry::instance()->CFG->core->txn_page_id)
351
+			? EE_Registry::instance()->CFG->core->txn_page_id
352
+			: null;
353
+		$this->_template_args['txn_page_obj']       = isset(EE_Registry::instance()->CFG->core->txn_page_id)
354
+			? get_post(EE_Registry::instance()->CFG->core->txn_page_id)
355
+			: false;
356
+		$this->_template_args['thank_you_page_id']  = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
357
+			? EE_Registry::instance()->CFG->core->thank_you_page_id
358
+			: null;
359
+		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
360
+			? get_post(EE_Registry::instance()->CFG->core->thank_you_page_id)
361
+			: false;
362
+		$this->_template_args['cancel_page_id']     = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
363
+			? EE_Registry::instance()->CFG->core->cancel_page_id
364
+			: null;
365
+		$this->_template_args['cancel_page_obj']    = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
366
+			? get_post(EE_Registry::instance()->CFG->core->cancel_page_id)
367
+			: false;
368
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
369
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
370
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
371
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
372
+			$this->_template_args,
373
+			true
374
+		);
375
+		$this->display_admin_page_with_sidebar();
376
+	}
377
+
378
+
379
+	/**
380
+	 * Handler for updating espresso page settings.
381
+	 *
382
+	 * @throws EE_Error
383
+	 */
384
+	protected function _update_espresso_page_settings()
385
+	{
386
+		// capture incoming request data && set page IDs
387
+		EE_Registry::instance()->CFG->core->reg_page_id       = isset($this->_req_data['reg_page_id'])
388
+			? absint($this->_req_data['reg_page_id'])
389
+			: EE_Registry::instance()->CFG->core->reg_page_id;
390
+		EE_Registry::instance()->CFG->core->txn_page_id       = isset($this->_req_data['txn_page_id'])
391
+			? absint($this->_req_data['txn_page_id'])
392
+			: EE_Registry::instance()->CFG->core->txn_page_id;
393
+		EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
394
+			? absint($this->_req_data['thank_you_page_id'])
395
+			: EE_Registry::instance()->CFG->core->thank_you_page_id;
396
+		EE_Registry::instance()->CFG->core->cancel_page_id    = isset($this->_req_data['cancel_page_id'])
397
+			? absint($this->_req_data['cancel_page_id'])
398
+			: EE_Registry::instance()->CFG->core->cancel_page_id;
399
+
400
+		EE_Registry::instance()->CFG->core = apply_filters(
401
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
402
+			EE_Registry::instance()->CFG->core,
403
+			$this->_req_data
404
+		);
405
+		$what                              = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
406
+		$this->_redirect_after_action(
407
+			$this->_update_espresso_configuration(
408
+				$what,
409
+				EE_Registry::instance()->CFG->core,
410
+				__FILE__,
411
+				__FUNCTION__,
412
+				__LINE__
413
+			),
414
+			$what,
415
+			'',
416
+			[
417
+				'action' => 'critical_pages',
418
+			],
419
+			true
420
+		);
421
+	}
422
+
423
+
424
+	/*************        Your Organization        *************/
425
+
426
+
427
+	/**
428
+	 * @throws DomainException
429
+	 * @throws EE_Error
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidDataTypeException
432
+	 * @throws InvalidInterfaceException
433
+	 */
434
+	protected function _your_organization_settings()
435
+	{
436
+		$this->_template_args['admin_page_content'] = '';
437
+		try {
438
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
439
+			$organization_settings_form                 = $this->loader->getShared(
440
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
441
+			);
442
+			$this->_template_args['admin_page_content'] = $organization_settings_form->display();
443
+		} catch (Exception $e) {
444
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
445
+		}
446
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
447
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
448
+		$this->display_admin_page_with_sidebar();
449
+	}
450
+
451
+
452
+	/**
453
+	 * Handler for updating organization settings.
454
+	 *
455
+	 * @throws EE_Error
456
+	 */
457
+	protected function _update_your_organization_settings()
458
+	{
459
+		try {
460
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
461
+			$organization_settings_form  = $this->loader->getShared(
462
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
463
+			);
464
+			$success                     = $organization_settings_form->process($this->_req_data);
465
+			EE_Registry::instance()->CFG = apply_filters(
466
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
467
+				EE_Registry::instance()->CFG
468
+			);
469
+		} catch (Exception $e) {
470
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
471
+			$success = false;
472
+		}
473
+
474
+		if ($success) {
475
+			$success = $this->_update_espresso_configuration(
476
+				esc_html__('Your Organization Settings', 'event_espresso'),
477
+				EE_Registry::instance()->CFG,
478
+				__FILE__,
479
+				__FUNCTION__,
480
+				__LINE__
481
+			);
482
+		}
483
+
484
+		$this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
485
+	}
486
+
487
+
488
+
489
+	/*************        Admin Options        *************/
490
+
491
+
492
+	/**
493
+	 * _admin_option_settings
494
+	 *
495
+	 * @throws EE_Error
496
+	 * @throws LogicException
497
+	 */
498
+	protected function _admin_option_settings()
499
+	{
500
+		$this->_template_args['admin_page_content'] = '';
501
+		try {
502
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
503
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
504
+			$this->_template_args['values'] = $this->_yes_no_values;
505
+			// also need to account for the do_action that was in the old template
506
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
507
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
508
+		} catch (Exception $e) {
509
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
510
+		}
511
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
512
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
513
+		$this->display_admin_page_with_sidebar();
514
+	}
515
+
516
+
517
+	/**
518
+	 * _update_admin_option_settings
519
+	 *
520
+	 * @throws EE_Error
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidFormSubmissionException
523
+	 * @throws InvalidArgumentException
524
+	 * @throws LogicException
525
+	 */
526
+	protected function _update_admin_option_settings()
527
+	{
528
+		try {
529
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
530
+			$admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
531
+			EE_Registry::instance()->CFG->admin = apply_filters(
532
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
533
+				EE_Registry::instance()->CFG->admin
534
+			);
535
+		} catch (Exception $e) {
536
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
+		}
538
+		$this->_redirect_after_action(
539
+			apply_filters(
540
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
541
+				$this->_update_espresso_configuration(
542
+					'Admin Options',
543
+					EE_Registry::instance()->CFG->admin,
544
+					__FILE__,
545
+					__FUNCTION__,
546
+					__LINE__
547
+				)
548
+			),
549
+			'Admin Options',
550
+			'updated',
551
+			['action' => 'admin_option_settings']
552
+		);
553
+	}
554
+
555
+
556
+	/*************        Countries        *************/
557
+
558
+
559
+	/**
560
+	 * @return string
561
+	 */
562
+	protected function getCountryIsoForSite()
563
+	{
564
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
565
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
566
+			: 'US';
567
+	}
568
+
569
+
570
+	/**
571
+	 * @param string          $CNT_ISO
572
+	 * @param EE_Country|null $country
573
+	 * @return EE_Base_Class|EE_Country
574
+	 * @throws EE_Error
575
+	 * @throws InvalidArgumentException
576
+	 * @throws InvalidDataTypeException
577
+	 * @throws InvalidInterfaceException
578
+	 * @throws ReflectionException
579
+	 */
580
+	protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
581
+	{
582
+		/** @var EE_Country $country */
583
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
584
+			? $country
585
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
586
+	}
587
+
588
+
589
+	/**
590
+	 * Output Country Settings view.
591
+	 *
592
+	 * @throws DomainException
593
+	 * @throws EE_Error
594
+	 * @throws InvalidArgumentException
595
+	 * @throws InvalidDataTypeException
596
+	 * @throws InvalidInterfaceException
597
+	 * @throws ReflectionException
598
+	 */
599
+	protected function _country_settings()
600
+	{
601
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
602
+		$CNT_ISO          = isset($this->_req_data['country'])
603
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
604
+			: $CNT_ISO_for_site;
605
+
606
+		// load field generator helper
607
+
608
+		$this->_template_args['values'] = $this->_yes_no_values;
609
+
610
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
611
+			EE_Question::new_instance(
612
+				[
613
+					'QST_ID'           => 0,
614
+					'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
615
+					'QST_system'       => 'admin-country',
616
+				]
617
+			),
618
+			EE_Answer::new_instance(
619
+				[
620
+					'ANS_ID'    => 0,
621
+					'ANS_value' => $CNT_ISO,
622
+				]
623
+			),
624
+			[
625
+				'input_id'       => 'country',
626
+				'input_name'     => 'country',
627
+				'input_prefix'   => '',
628
+				'append_qstn_id' => false,
629
+			]
630
+		);
631
+		$country                           = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
632
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
633
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
634
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
635
+			$country->ID(),
636
+			$country
637
+		);
638
+		$this->_template_args['country_states_settings']  = $this->display_country_states(
639
+			$country->ID(),
640
+			$country
641
+		);
642
+		$this->_template_args['CNT_name_for_site']        = $country->name();
643
+
644
+		$this->_set_add_edit_form_tags('update_country_settings');
645
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
646
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
647
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
648
+			$this->_template_args,
649
+			true
650
+		);
651
+		$this->display_admin_page_with_no_sidebar();
652
+	}
653
+
654
+
655
+	/**
656
+	 * @param string          $CNT_ISO
657
+	 * @param EE_Country|null $country
658
+	 * @return string
659
+	 * @throws DomainException
660
+	 * @throws EE_Error
661
+	 * @throws InvalidArgumentException
662
+	 * @throws InvalidDataTypeException
663
+	 * @throws InvalidInterfaceException
664
+	 * @throws ReflectionException
665
+	 */
666
+	public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
667
+	{
668
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
669
+
670
+		$CNT_ISO = isset($this->_req_data['country'])
671
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
672
+			: $CNT_ISO;
673
+		if (! $CNT_ISO) {
674
+			return '';
675
+		}
676
+
677
+		// for ajax
678
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
679
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
680
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
681
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
682
+		$country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
683
+		$CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
684
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
685
+
686
+		$country_input_types            = [
687
+			'CNT_active'      => [
688
+				'type'             => 'RADIO_BTN',
689
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
690
+				'class'            => '',
691
+				'options'          => $this->_yes_no_values,
692
+				'use_desc_4_label' => true,
693
+			],
694
+			'CNT_ISO'         => [
695
+				'type'       => 'TEXT',
696
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
697
+				'class'      => 'small-text',
698
+			],
699
+			'CNT_ISO3'        => [
700
+				'type'       => 'TEXT',
701
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
702
+				'class'      => 'small-text',
703
+			],
704
+			'RGN_ID'          => [
705
+				'type'       => 'TEXT',
706
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
707
+				'class'      => 'small-text',
708
+			],
709
+			'CNT_name'        => [
710
+				'type'       => 'TEXT',
711
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
712
+				'class'      => 'regular-text',
713
+			],
714
+			'CNT_cur_code'    => [
715
+				'type'       => 'TEXT',
716
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
717
+				'class'      => 'small-text',
718
+				'disabled'   => $CNT_cur_disabled,
719
+			],
720
+			'CNT_cur_single'  => [
721
+				'type'       => 'TEXT',
722
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
723
+				'class'      => 'medium-text',
724
+				'disabled'   => $CNT_cur_disabled,
725
+			],
726
+			'CNT_cur_plural'  => [
727
+				'type'       => 'TEXT',
728
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
729
+				'class'      => 'medium-text',
730
+				'disabled'   => $CNT_cur_disabled,
731
+			],
732
+			'CNT_cur_sign'    => [
733
+				'type'         => 'TEXT',
734
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
735
+				'class'        => 'small-text',
736
+				'htmlentities' => false,
737
+				'disabled'     => $CNT_cur_disabled,
738
+			],
739
+			'CNT_cur_sign_b4' => [
740
+				'type'             => 'RADIO_BTN',
741
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
742
+				'class'            => '',
743
+				'options'          => $this->_yes_no_values,
744
+				'use_desc_4_label' => true,
745
+				'disabled'         => $CNT_cur_disabled,
746
+			],
747
+			'CNT_cur_dec_plc' => [
748
+				'type'       => 'RADIO_BTN',
749
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
750
+				'class'      => '',
751
+				'options'    => [
752
+					['id' => 0, 'text' => ''],
753
+					['id' => 1, 'text' => ''],
754
+					['id' => 2, 'text' => ''],
755
+					['id' => 3, 'text' => ''],
756
+				],
757
+				'disabled'   => $CNT_cur_disabled,
758
+			],
759
+			'CNT_cur_dec_mrk' => [
760
+				'type'             => 'RADIO_BTN',
761
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
762
+				'class'            => '',
763
+				'options'          => [
764
+					[
765
+						'id'   => ',',
766
+						'text' => esc_html__(', (comma)', 'event_espresso'),
767
+					],
768
+					['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
769
+				],
770
+				'use_desc_4_label' => true,
771
+				'disabled'         => $CNT_cur_disabled,
772
+			],
773
+			'CNT_cur_thsnds'  => [
774
+				'type'             => 'RADIO_BTN',
775
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
776
+				'class'            => '',
777
+				'options'          => [
778
+					[
779
+						'id'   => ',',
780
+						'text' => esc_html__(', (comma)', 'event_espresso'),
781
+					],
782
+					[
783
+						'id'   => '.',
784
+						'text' => esc_html__('. (decimal)', 'event_espresso'),
785
+					],
786
+					[
787
+						'id'   => '&nbsp;',
788
+						'text' => esc_html__('(space)', 'event_espresso'),
789
+					],
790
+				],
791
+				'use_desc_4_label' => true,
792
+				'disabled'         => $CNT_cur_disabled,
793
+			],
794
+			'CNT_tel_code'    => [
795
+				'type'       => 'TEXT',
796
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
797
+				'class'      => 'small-text',
798
+			],
799
+			'CNT_is_EU'       => [
800
+				'type'             => 'RADIO_BTN',
801
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
802
+				'class'            => '',
803
+				'options'          => $this->_yes_no_values,
804
+				'use_desc_4_label' => true,
805
+			],
806
+		];
807
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
808
+			$country,
809
+			$country_input_types
810
+		);
811
+		$country_details_settings       = EEH_Template::display_template(
812
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
813
+			$this->_template_args,
814
+			true
815
+		);
816
+
817
+		if (defined('DOING_AJAX')) {
818
+			$notices = EE_Error::get_notices(false, false, false);
819
+			echo wp_json_encode(
820
+				[
821
+					'return_data' => $country_details_settings,
822
+					'success'     => $notices['success'],
823
+					'errors'      => $notices['errors'],
824
+				]
825
+			);
826
+			die();
827
+		} else {
828
+			return $country_details_settings;
829
+		}
830
+	}
831
+
832
+
833
+	/**
834
+	 * @param string          $CNT_ISO
835
+	 * @param EE_Country|null $country
836
+	 * @return string
837
+	 * @throws DomainException
838
+	 * @throws EE_Error
839
+	 * @throws InvalidArgumentException
840
+	 * @throws InvalidDataTypeException
841
+	 * @throws InvalidInterfaceException
842
+	 * @throws ReflectionException
843
+	 */
844
+	public function display_country_states($CNT_ISO = '', EE_Country $country = null)
845
+	{
846
+
847
+		$CNT_ISO = isset($this->_req_data['country'])
848
+			? sanitize_text_field($this->_req_data['country'])
849
+			: $CNT_ISO;
850
+		if (! $CNT_ISO) {
851
+			return '';
852
+		}
853
+		// for ajax
854
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
855
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
856
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
857
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10, 2);
858
+		$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
859
+		if (empty($states)) {
860
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
861
+			$countrySubRegionDao = $this->loader->getShared(
862
+				'EventEspresso\core\services\address\CountrySubRegionDao'
863
+			);
864
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
865
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
866
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
867
+					$states = EEM_State::instance()->get_all_states_for_these_countries(
868
+						[$CNT_ISO => $CNT_ISO]
869
+					);
870
+				}
871
+			}
872
+		}
873
+		if (is_array($states)) {
874
+			foreach ($states as $STA_ID => $state) {
875
+				if ($state instanceof EE_State) {
876
+					// STA_abbrev    STA_name    STA_active
877
+					$state_input_types                                             = [
878
+						'STA_abbrev' => [
879
+							'type'       => 'TEXT',
880
+							'input_name' => 'states[' . $STA_ID . ']',
881
+							'class'      => 'small-text',
882
+						],
883
+						'STA_name'   => [
884
+							'type'       => 'TEXT',
885
+							'input_name' => 'states[' . $STA_ID . ']',
886
+							'class'      => 'regular-text',
887
+						],
888
+						'STA_active' => [
889
+							'type'             => 'RADIO_BTN',
890
+							'input_name'       => 'states[' . $STA_ID . ']',
891
+							'options'          => $this->_yes_no_values,
892
+							'use_desc_4_label' => true,
893
+						],
894
+					];
895
+					$this->_template_args['states'][ $STA_ID ]['inputs']           =
896
+						EE_Question_Form_Input::generate_question_form_inputs_for_object(
897
+							$state,
898
+							$state_input_types
899
+						);
900
+					$query_args                                                    = [
901
+						'action'     => 'delete_state',
902
+						'STA_ID'     => $STA_ID,
903
+						'CNT_ISO'    => $CNT_ISO,
904
+						'STA_abbrev' => $state->abbrev(),
905
+					];
906
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
907
+						EE_Admin_Page::add_query_args_and_nonce(
908
+							$query_args,
909
+							GEN_SET_ADMIN_URL
910
+						);
911
+				}
912
+			}
913
+		} else {
914
+			$this->_template_args['states'] = false;
915
+		}
916
+
917
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
918
+			['action' => 'add_new_state'],
919
+			GEN_SET_ADMIN_URL
920
+		);
921
+
922
+		$state_details_settings = EEH_Template::display_template(
923
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
924
+			$this->_template_args,
925
+			true
926
+		);
927
+
928
+		if (defined('DOING_AJAX')) {
929
+			$notices = EE_Error::get_notices(false, false, false);
930
+			echo wp_json_encode(
931
+				[
932
+					'return_data' => $state_details_settings,
933
+					'success'     => $notices['success'],
934
+					'errors'      => $notices['errors'],
935
+				]
936
+			);
937
+			die();
938
+		} else {
939
+			return $state_details_settings;
940
+		}
941
+	}
942
+
943
+
944
+	/**
945
+	 *        add_new_state
946
+	 *
947
+	 * @access    public
948
+	 * @return void
949
+	 * @throws EE_Error
950
+	 * @throws InvalidArgumentException
951
+	 * @throws InvalidDataTypeException
952
+	 * @throws InvalidInterfaceException
953
+	 */
954
+	public function add_new_state()
955
+	{
956
+
957
+		$success = true;
958
+
959
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
960
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
961
+			: false;
962
+		if (! $CNT_ISO) {
963
+			EE_Error::add_error(
964
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
965
+				__FILE__,
966
+				__FUNCTION__,
967
+				__LINE__
968
+			);
969
+			$success = false;
970
+		}
971
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
972
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
973
+			: false;
974
+		if (! $STA_abbrev) {
975
+			EE_Error::add_error(
976
+				esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
977
+				__FILE__,
978
+				__FUNCTION__,
979
+				__LINE__
980
+			);
981
+			$success = false;
982
+		}
983
+		$STA_name = isset($this->_req_data['STA_name'])
984
+			? sanitize_text_field($this->_req_data['STA_name'])
985
+			: false;
986
+		if (! $STA_name) {
987
+			EE_Error::add_error(
988
+				esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
989
+				__FILE__,
990
+				__FUNCTION__,
991
+				__LINE__
992
+			);
993
+			$success = false;
994
+		}
995
+
996
+		if ($success) {
997
+			$cols_n_values = [
998
+				'CNT_ISO'    => $CNT_ISO,
999
+				'STA_abbrev' => $STA_abbrev,
1000
+				'STA_name'   => $STA_name,
1001
+				'STA_active' => true,
1002
+			];
1003
+			$success       = EEM_State::instance()->insert($cols_n_values);
1004
+			EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1005
+		}
1006
+
1007
+		if (defined('DOING_AJAX')) {
1008
+			$notices = EE_Error::get_notices(false, false, false);
1009
+			echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1010
+			die();
1011
+		} else {
1012
+			$this->_redirect_after_action($success, 'State', 'added', ['action' => 'country_settings']);
1013
+		}
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * @return void
1019
+	 * @throws EE_Error
1020
+	 * @throws InvalidArgumentException
1021
+	 * @throws InvalidDataTypeException
1022
+	 * @throws InvalidInterfaceException
1023
+	 */
1024
+	public function delete_state()
1025
+	{
1026
+		$CNT_ISO    = isset($this->_req_data['CNT_ISO'])
1027
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1028
+			: false;
1029
+		$STA_ID     = isset($this->_req_data['STA_ID'])
1030
+			? sanitize_text_field($this->_req_data['STA_ID'])
1031
+			: false;
1032
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
1033
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
1034
+			: false;
1035
+		if (! $STA_ID) {
1036
+			EE_Error::add_error(
1037
+				esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1038
+				__FILE__,
1039
+				__FUNCTION__,
1040
+				__LINE__
1041
+			);
1042
+			return;
1043
+		}
1044
+
1045
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1046
+		if ($success !== false) {
1047
+			do_action(
1048
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1049
+				$CNT_ISO,
1050
+				$STA_ID,
1051
+				['STA_abbrev' => $STA_abbrev]
1052
+			);
1053
+			EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1054
+		}
1055
+		if (defined('DOING_AJAX')) {
1056
+			$notices                = EE_Error::get_notices(false);
1057
+			$notices['return_data'] = true;
1058
+			echo wp_json_encode($notices);
1059
+			die();
1060
+		} else {
1061
+			$this->_redirect_after_action(
1062
+				$success,
1063
+				'State',
1064
+				'deleted',
1065
+				['action' => 'country_settings']
1066
+			);
1067
+		}
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 *        _update_country_settings
1073
+	 *
1074
+	 * @return void
1075
+	 * @throws EE_Error
1076
+	 * @throws InvalidArgumentException
1077
+	 * @throws InvalidDataTypeException
1078
+	 * @throws InvalidInterfaceException
1079
+	 */
1080
+	protected function _update_country_settings()
1081
+	{
1082
+		// grab the country ISO code
1083
+		$CNT_ISO = isset($this->_req_data['country'])
1084
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
1085
+			: false;
1086
+		if (! $CNT_ISO) {
1087
+			EE_Error::add_error(
1088
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1089
+				__FILE__,
1090
+				__FUNCTION__,
1091
+				__LINE__
1092
+			);
1093
+
1094
+			return;
1095
+		}
1096
+		$cols_n_values             = [];
1097
+		$cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1098
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1099
+			: false;
1100
+		$cols_n_values['RGN_ID']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1101
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1102
+			: null;
1103
+		$cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1104
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1105
+			: null;
1106
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1107
+			$cols_n_values['CNT_cur_code'] = strtoupper(
1108
+				sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1109
+			);
1110
+		}
1111
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1112
+			$cols_n_values['CNT_cur_single'] = sanitize_text_field(
1113
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1114
+			);
1115
+		}
1116
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1117
+			$cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1118
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1119
+			);
1120
+		}
1121
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1122
+			$cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1123
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1124
+			);
1125
+		}
1126
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1127
+			$cols_n_values['CNT_cur_sign_b4'] = absint(
1128
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1129
+			);
1130
+		}
1131
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1132
+			$cols_n_values['CNT_cur_dec_plc'] = absint(
1133
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1134
+			);
1135
+		}
1136
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1137
+			$cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1138
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1139
+			);
1140
+		}
1141
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1142
+			$cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1143
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1144
+			);
1145
+		}
1146
+		$cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1147
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1148
+			: null;
1149
+		$cols_n_values['CNT_is_EU']    = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1150
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1151
+			: false;
1152
+		$cols_n_values['CNT_active']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1153
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1154
+			: false;
1155
+		// allow filtering of country data
1156
+		$cols_n_values = apply_filters(
1157
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1158
+			$cols_n_values
1159
+		);
1160
+
1161
+		// where values
1162
+		$where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1163
+		// run the update
1164
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1165
+
1166
+		if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1167
+			// allow filtering of states data
1168
+			$states = apply_filters(
1169
+				'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1170
+				$this->_req_data['states']
1171
+			);
1172
+
1173
+			// loop thru state data ( looks like : states[75][STA_name] )
1174
+			foreach ($states as $STA_ID => $state) {
1175
+				$cols_n_values = [
1176
+					'CNT_ISO'    => $CNT_ISO,
1177
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1178
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1179
+					'STA_active' => (bool) absint($state['STA_active']),
1180
+				];
1181
+				// where values
1182
+				$where_cols_n_values = [['STA_ID' => $STA_ID]];
1183
+				// run the update
1184
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1185
+				if ($success !== false) {
1186
+					do_action(
1187
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1188
+						$CNT_ISO,
1189
+						$STA_ID,
1190
+						$cols_n_values
1191
+					);
1192
+				}
1193
+			}
1194
+		}
1195
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1196
+		if (
1197
+			isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1198
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1199
+		) {
1200
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1201
+			EE_Registry::instance()->CFG->update_espresso_config();
1202
+		}
1203
+
1204
+		if ($success !== false) {
1205
+			EE_Error::add_success(
1206
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1207
+			);
1208
+		}
1209
+		$this->_redirect_after_action(
1210
+			$success,
1211
+			'',
1212
+			'',
1213
+			['action' => 'country_settings', 'country' => $CNT_ISO],
1214
+			true
1215
+		);
1216
+	}
1217
+
1218
+
1219
+	/**
1220
+	 *        form_form_field_label_wrap
1221
+	 *
1222
+	 * @param string $label
1223
+	 * @return        string
1224
+	 */
1225
+	public function country_form_field_label_wrap($label, $required_text)
1226
+	{
1227
+		return '
1228 1228
 			<tr>
1229 1229
 				<th>
1230 1230
 					' . $label . '
1231 1231
 				</th>';
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     *        form_form_field_input__wrap
1237
-     *
1238
-     * @param string $label
1239
-     * @return        string
1240
-     */
1241
-    public function country_form_field_input__wrap($input, $label)
1242
-    {
1243
-        return '
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 *        form_form_field_input__wrap
1237
+	 *
1238
+	 * @param string $label
1239
+	 * @return        string
1240
+	 */
1241
+	public function country_form_field_input__wrap($input, $label)
1242
+	{
1243
+		return '
1244 1244
 				<td class="general-settings-country-input-td">
1245 1245
 					' . $input . '
1246 1246
 				</td>
1247 1247
 			</tr>';
1248
-    }
1249
-
1250
-
1251
-    /**
1252
-     *        form_form_field_label_wrap
1253
-     *
1254
-     * @param string $label
1255
-     * @param string $required_text
1256
-     * @return        string
1257
-     */
1258
-    public function state_form_field_label_wrap($label, $required_text)
1259
-    {
1260
-        return $required_text;
1261
-    }
1262
-
1263
-
1264
-    /**
1265
-     *        form_form_field_input__wrap
1266
-     *
1267
-     * @param string $label
1268
-     * @return        string
1269
-     */
1270
-    public function state_form_field_input__wrap($input, $label)
1271
-    {
1272
-        return '
1248
+	}
1249
+
1250
+
1251
+	/**
1252
+	 *        form_form_field_label_wrap
1253
+	 *
1254
+	 * @param string $label
1255
+	 * @param string $required_text
1256
+	 * @return        string
1257
+	 */
1258
+	public function state_form_field_label_wrap($label, $required_text)
1259
+	{
1260
+		return $required_text;
1261
+	}
1262
+
1263
+
1264
+	/**
1265
+	 *        form_form_field_input__wrap
1266
+	 *
1267
+	 * @param string $label
1268
+	 * @return        string
1269
+	 */
1270
+	public function state_form_field_input__wrap($input, $label)
1271
+	{
1272
+		return '
1273 1273
 				<td class="general-settings-country-state-input-td">
1274 1274
 					' . $input . '
1275 1275
 				</td>';
1276
-    }
1277
-
1278
-
1279
-    /***********/
1280
-
1281
-
1282
-    /**
1283
-     * displays edit and view links for critical EE pages
1284
-     *
1285
-     * @param int $ee_page_id
1286
-     * @return string
1287
-     */
1288
-    public static function edit_view_links($ee_page_id)
1289
-    {
1290
-        $links = '<a href="'
1291
-                 . add_query_arg(
1292
-                     ['post' => $ee_page_id, 'action' => 'edit'],
1293
-                     admin_url('post.php')
1294
-                 )
1295
-                 . '" >'
1296
-                 . esc_html__('Edit', 'event_espresso')
1297
-                 . '</a>';
1298
-        $links .= ' &nbsp;|&nbsp; ';
1299
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1300
-
1301
-        return $links;
1302
-    }
1303
-
1304
-
1305
-    /**
1306
-     * displays page and shortcode status for critical EE pages
1307
-     *
1308
-     * @param WP page object $ee_page
1309
-     * @return string
1310
-     */
1311
-    public static function page_and_shortcode_status($ee_page, $shortcode)
1312
-    {
1313
-
1314
-        // page status
1315
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1316
-            $pg_colour = 'green';
1317
-            $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1318
-        } else {
1319
-            $pg_colour = 'red';
1320
-            $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1321
-        }
1322
-
1323
-        // shortcode status
1324
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1325
-            $sc_colour = 'green';
1326
-            $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1327
-        } else {
1328
-            $sc_colour = 'red';
1329
-            $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1330
-        }
1331
-
1332
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1333
-               . $pg_status
1334
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1335
-    }
1336
-
1337
-
1338
-    /**
1339
-     * generates a dropdown of all parent pages - copied from WP core
1340
-     *
1341
-     * @param int  $default
1342
-     * @param int  $parent
1343
-     * @param int  $level
1344
-     * @param bool $echo
1345
-     * @return string;
1346
-     */
1347
-    public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0, $echo = true)
1348
-    {
1349
-        global $wpdb;
1350
-        $items  = $wpdb->get_results(
1351
-            $wpdb->prepare(
1352
-                "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",
1353
-                $parent
1354
-            )
1355
-        );
1356
-        $output = '';
1357
-
1358
-        if ($items) {
1359
-            $level = absint($level);
1360
-            foreach ($items as $item) {
1361
-                $ID = absint($item->ID);
1362
-                $post_title = wp_strip_all_tags($item->post_title);
1363
-                $pad    = str_repeat('&nbsp;', $level * 3);
1364
-                $option = "\n\t";
1365
-                $option .= '<option class="level-' . $level . '" ';
1366
-                $option .= 'value="' . $ID . '" ';
1367
-                $option .= $ID === absint($default) ? ' selected' : '';
1368
-                $option .= '>';
1369
-                $option .= "$pad {$post_title}";
1370
-                $option .= '</option>';
1371
-                $output .= $option;
1372
-                ob_start();
1373
-                parent_dropdown($default, $item->ID, $level + 1);
1374
-                $output .= ob_get_clean();
1375
-            }
1376
-        }
1377
-        if ($echo) {
1378
-            echo wp_kses($output, AllowedTags::getAllowedTags());
1379
-            return '';
1380
-        }
1381
-        return $output;
1382
-    }
1383
-
1384
-
1385
-    /**
1386
-     * Loads the scripts for the privacy settings form
1387
-     */
1388
-    public function load_scripts_styles_privacy_settings()
1389
-    {
1390
-        $form_handler =
1391
-            $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1392
-        $form_handler->enqueueStylesAndScripts();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * display the privacy settings form
1398
-     *
1399
-     * @throws EE_Error
1400
-     */
1401
-    public function privacySettings()
1402
-    {
1403
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1404
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1405
-        $form_handler                               =
1406
-            $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1407
-        $this->_template_args['admin_page_content'] = $form_handler->display();
1408
-        $this->display_admin_page_with_sidebar();
1409
-    }
1410
-
1411
-
1412
-    /**
1413
-     * Update the privacy settings from form data
1414
-     *
1415
-     * @throws EE_Error
1416
-     */
1417
-    public function updatePrivacySettings()
1418
-    {
1419
-        $form_handler =
1420
-            $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1421
-        $success      = $form_handler->process($this->get_request_data());
1422
-        $this->_redirect_after_action(
1423
-            $success,
1424
-            esc_html__('Registration Form Options', 'event_espresso'),
1425
-            'updated',
1426
-            ['action' => 'privacy_settings']
1427
-        );
1428
-    }
1276
+	}
1277
+
1278
+
1279
+	/***********/
1280
+
1281
+
1282
+	/**
1283
+	 * displays edit and view links for critical EE pages
1284
+	 *
1285
+	 * @param int $ee_page_id
1286
+	 * @return string
1287
+	 */
1288
+	public static function edit_view_links($ee_page_id)
1289
+	{
1290
+		$links = '<a href="'
1291
+				 . add_query_arg(
1292
+					 ['post' => $ee_page_id, 'action' => 'edit'],
1293
+					 admin_url('post.php')
1294
+				 )
1295
+				 . '" >'
1296
+				 . esc_html__('Edit', 'event_espresso')
1297
+				 . '</a>';
1298
+		$links .= ' &nbsp;|&nbsp; ';
1299
+		$links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1300
+
1301
+		return $links;
1302
+	}
1303
+
1304
+
1305
+	/**
1306
+	 * displays page and shortcode status for critical EE pages
1307
+	 *
1308
+	 * @param WP page object $ee_page
1309
+	 * @return string
1310
+	 */
1311
+	public static function page_and_shortcode_status($ee_page, $shortcode)
1312
+	{
1313
+
1314
+		// page status
1315
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1316
+			$pg_colour = 'green';
1317
+			$pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1318
+		} else {
1319
+			$pg_colour = 'red';
1320
+			$pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1321
+		}
1322
+
1323
+		// shortcode status
1324
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1325
+			$sc_colour = 'green';
1326
+			$sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1327
+		} else {
1328
+			$sc_colour = 'red';
1329
+			$sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1330
+		}
1331
+
1332
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1333
+			   . $pg_status
1334
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1335
+	}
1336
+
1337
+
1338
+	/**
1339
+	 * generates a dropdown of all parent pages - copied from WP core
1340
+	 *
1341
+	 * @param int  $default
1342
+	 * @param int  $parent
1343
+	 * @param int  $level
1344
+	 * @param bool $echo
1345
+	 * @return string;
1346
+	 */
1347
+	public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0, $echo = true)
1348
+	{
1349
+		global $wpdb;
1350
+		$items  = $wpdb->get_results(
1351
+			$wpdb->prepare(
1352
+				"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",
1353
+				$parent
1354
+			)
1355
+		);
1356
+		$output = '';
1357
+
1358
+		if ($items) {
1359
+			$level = absint($level);
1360
+			foreach ($items as $item) {
1361
+				$ID = absint($item->ID);
1362
+				$post_title = wp_strip_all_tags($item->post_title);
1363
+				$pad    = str_repeat('&nbsp;', $level * 3);
1364
+				$option = "\n\t";
1365
+				$option .= '<option class="level-' . $level . '" ';
1366
+				$option .= 'value="' . $ID . '" ';
1367
+				$option .= $ID === absint($default) ? ' selected' : '';
1368
+				$option .= '>';
1369
+				$option .= "$pad {$post_title}";
1370
+				$option .= '</option>';
1371
+				$output .= $option;
1372
+				ob_start();
1373
+				parent_dropdown($default, $item->ID, $level + 1);
1374
+				$output .= ob_get_clean();
1375
+			}
1376
+		}
1377
+		if ($echo) {
1378
+			echo wp_kses($output, AllowedTags::getAllowedTags());
1379
+			return '';
1380
+		}
1381
+		return $output;
1382
+	}
1383
+
1384
+
1385
+	/**
1386
+	 * Loads the scripts for the privacy settings form
1387
+	 */
1388
+	public function load_scripts_styles_privacy_settings()
1389
+	{
1390
+		$form_handler =
1391
+			$this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1392
+		$form_handler->enqueueStylesAndScripts();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * display the privacy settings form
1398
+	 *
1399
+	 * @throws EE_Error
1400
+	 */
1401
+	public function privacySettings()
1402
+	{
1403
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1404
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1405
+		$form_handler                               =
1406
+			$this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1407
+		$this->_template_args['admin_page_content'] = $form_handler->display();
1408
+		$this->display_admin_page_with_sidebar();
1409
+	}
1410
+
1411
+
1412
+	/**
1413
+	 * Update the privacy settings from form data
1414
+	 *
1415
+	 * @throws EE_Error
1416
+	 */
1417
+	public function updatePrivacySettings()
1418
+	{
1419
+		$form_handler =
1420
+			$this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1421
+		$success      = $form_handler->process($this->get_request_data());
1422
+		$this->_redirect_after_action(
1423
+			$success,
1424
+			esc_html__('Registration Form Options', 'event_espresso'),
1425
+			'updated',
1426
+			['action' => 'privacy_settings']
1427
+		);
1428
+	}
1429 1429
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
             '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.',
248 248
             'event_espresso'
249 249
         ));
250
-        EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(__(
250
+        EE_Registry::$i18n_js_strings['error_occurred'] = wp_strip_all_tags(__(
251 251
             'An error occurred! Please refresh the page and try again.',
252 252
             'event_espresso'
253 253
         ));
254
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(__(
254
+        EE_Registry::$i18n_js_strings['confirm_delete_state'] = wp_strip_all_tags(__(
255 255
             'Are you sure you want to delete this State / Province?',
256 256
             'event_espresso'
257 257
         ));
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
         wp_enqueue_script('thickbox');
286 286
         wp_register_script(
287 287
             'organization_settings',
288
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
288
+            GEN_SET_ASSETS_URL.'your_organization_settings.js',
289 289
             ['jquery', 'media-upload', 'thickbox'],
290 290
             EVENT_ESPRESSO_VERSION,
291 291
             true
292 292
         );
293
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
293
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', [], EVENT_ESPRESSO_VERSION);
294 294
         wp_enqueue_script('organization_settings');
295 295
         wp_enqueue_style('organization-css');
296 296
         $confirm_image_delete = [
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
         // scripts
314 314
         wp_register_script(
315 315
             'gen_settings_countries',
316
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
316
+            GEN_SET_ASSETS_URL.'gen_settings_countries.js',
317 317
             ['ee_admin_js'],
318 318
             EVENT_ESPRESSO_VERSION,
319 319
             true
320 320
         );
321
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
321
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', [], EVENT_ESPRESSO_VERSION);
322 322
         wp_enqueue_script('gen_settings_countries');
323 323
         wp_enqueue_style('organization-css');
324 324
     }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         $this->_set_add_edit_form_tags('update_espresso_page_settings');
369 369
         $this->_set_publish_post_box_vars(null, false, false, null, false);
370 370
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
371
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
371
+            GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php',
372 372
             $this->_template_args,
373 373
             true
374 374
         );
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
             EE_Registry::instance()->CFG->core,
403 403
             $this->_req_data
404 404
         );
405
-        $what                              = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
405
+        $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
406 406
         $this->_redirect_after_action(
407 407
             $this->_update_espresso_configuration(
408 408
                 $what,
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     {
528 528
         try {
529 529
             $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
530
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
530
+            $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]);
531 531
             EE_Registry::instance()->CFG->admin = apply_filters(
532 532
                 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
533 533
                 EE_Registry::instance()->CFG->admin
@@ -628,23 +628,23 @@  discard block
 block discarded – undo
628 628
                 'append_qstn_id' => false,
629 629
             ]
630 630
         );
631
-        $country                           = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
631
+        $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
632 632
         add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
633 633
         add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
634 634
         $this->_template_args['country_details_settings'] = $this->display_country_settings(
635 635
             $country->ID(),
636 636
             $country
637 637
         );
638
-        $this->_template_args['country_states_settings']  = $this->display_country_states(
638
+        $this->_template_args['country_states_settings'] = $this->display_country_states(
639 639
             $country->ID(),
640 640
             $country
641 641
         );
642
-        $this->_template_args['CNT_name_for_site']        = $country->name();
642
+        $this->_template_args['CNT_name_for_site'] = $country->name();
643 643
 
644 644
         $this->_set_add_edit_form_tags('update_country_settings');
645 645
         $this->_set_publish_post_box_vars(null, false, false, null, false);
646 646
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
647
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
647
+            GEN_SET_TEMPLATE_PATH.'countries_settings.template.php',
648 648
             $this->_template_args,
649 649
             true
650 650
         );
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
         $CNT_ISO = isset($this->_req_data['country'])
671 671
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
672 672
             : $CNT_ISO;
673
-        if (! $CNT_ISO) {
673
+        if ( ! $CNT_ISO) {
674 674
             return '';
675 675
         }
676 676
 
@@ -683,62 +683,62 @@  discard block
 block discarded – undo
683 683
         $CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
684 684
         $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
685 685
 
686
-        $country_input_types            = [
686
+        $country_input_types = [
687 687
             'CNT_active'      => [
688 688
                 'type'             => 'RADIO_BTN',
689
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
689
+                'input_name'       => 'cntry['.$CNT_ISO.']',
690 690
                 'class'            => '',
691 691
                 'options'          => $this->_yes_no_values,
692 692
                 'use_desc_4_label' => true,
693 693
             ],
694 694
             'CNT_ISO'         => [
695 695
                 'type'       => 'TEXT',
696
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
696
+                'input_name' => 'cntry['.$CNT_ISO.']',
697 697
                 'class'      => 'small-text',
698 698
             ],
699 699
             'CNT_ISO3'        => [
700 700
                 'type'       => 'TEXT',
701
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
701
+                'input_name' => 'cntry['.$CNT_ISO.']',
702 702
                 'class'      => 'small-text',
703 703
             ],
704 704
             'RGN_ID'          => [
705 705
                 'type'       => 'TEXT',
706
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
706
+                'input_name' => 'cntry['.$CNT_ISO.']',
707 707
                 'class'      => 'small-text',
708 708
             ],
709 709
             'CNT_name'        => [
710 710
                 'type'       => 'TEXT',
711
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
711
+                'input_name' => 'cntry['.$CNT_ISO.']',
712 712
                 'class'      => 'regular-text',
713 713
             ],
714 714
             'CNT_cur_code'    => [
715 715
                 'type'       => 'TEXT',
716
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
716
+                'input_name' => 'cntry['.$CNT_ISO.']',
717 717
                 'class'      => 'small-text',
718 718
                 'disabled'   => $CNT_cur_disabled,
719 719
             ],
720 720
             'CNT_cur_single'  => [
721 721
                 'type'       => 'TEXT',
722
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
722
+                'input_name' => 'cntry['.$CNT_ISO.']',
723 723
                 'class'      => 'medium-text',
724 724
                 'disabled'   => $CNT_cur_disabled,
725 725
             ],
726 726
             'CNT_cur_plural'  => [
727 727
                 'type'       => 'TEXT',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
728
+                'input_name' => 'cntry['.$CNT_ISO.']',
729 729
                 'class'      => 'medium-text',
730 730
                 'disabled'   => $CNT_cur_disabled,
731 731
             ],
732 732
             'CNT_cur_sign'    => [
733 733
                 'type'         => 'TEXT',
734
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
734
+                'input_name'   => 'cntry['.$CNT_ISO.']',
735 735
                 'class'        => 'small-text',
736 736
                 'htmlentities' => false,
737 737
                 'disabled'     => $CNT_cur_disabled,
738 738
             ],
739 739
             'CNT_cur_sign_b4' => [
740 740
                 'type'             => 'RADIO_BTN',
741
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
741
+                'input_name'       => 'cntry['.$CNT_ISO.']',
742 742
                 'class'            => '',
743 743
                 'options'          => $this->_yes_no_values,
744 744
                 'use_desc_4_label' => true,
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
             ],
747 747
             'CNT_cur_dec_plc' => [
748 748
                 'type'       => 'RADIO_BTN',
749
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
749
+                'input_name' => 'cntry['.$CNT_ISO.']',
750 750
                 'class'      => '',
751 751
                 'options'    => [
752 752
                     ['id' => 0, 'text' => ''],
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
             ],
759 759
             'CNT_cur_dec_mrk' => [
760 760
                 'type'             => 'RADIO_BTN',
761
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
761
+                'input_name'       => 'cntry['.$CNT_ISO.']',
762 762
                 'class'            => '',
763 763
                 'options'          => [
764 764
                     [
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
             ],
773 773
             'CNT_cur_thsnds'  => [
774 774
                 'type'             => 'RADIO_BTN',
775
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
775
+                'input_name'       => 'cntry['.$CNT_ISO.']',
776 776
                 'class'            => '',
777 777
                 'options'          => [
778 778
                     [
@@ -793,12 +793,12 @@  discard block
 block discarded – undo
793 793
             ],
794 794
             'CNT_tel_code'    => [
795 795
                 'type'       => 'TEXT',
796
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
796
+                'input_name' => 'cntry['.$CNT_ISO.']',
797 797
                 'class'      => 'small-text',
798 798
             ],
799 799
             'CNT_is_EU'       => [
800 800
                 'type'             => 'RADIO_BTN',
801
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
+                'input_name'       => 'cntry['.$CNT_ISO.']',
802 802
                 'class'            => '',
803 803
                 'options'          => $this->_yes_no_values,
804 804
                 'use_desc_4_label' => true,
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
             $country,
809 809
             $country_input_types
810 810
         );
811
-        $country_details_settings       = EEH_Template::display_template(
812
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
811
+        $country_details_settings = EEH_Template::display_template(
812
+            GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php',
813 813
             $this->_template_args,
814 814
             true
815 815
         );
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
         $CNT_ISO = isset($this->_req_data['country'])
848 848
             ? sanitize_text_field($this->_req_data['country'])
849 849
             : $CNT_ISO;
850
-        if (! $CNT_ISO) {
850
+        if ( ! $CNT_ISO) {
851 851
             return '';
852 852
         }
853 853
         // for ajax
@@ -874,36 +874,36 @@  discard block
 block discarded – undo
874 874
             foreach ($states as $STA_ID => $state) {
875 875
                 if ($state instanceof EE_State) {
876 876
                     // STA_abbrev    STA_name    STA_active
877
-                    $state_input_types                                             = [
877
+                    $state_input_types = [
878 878
                         'STA_abbrev' => [
879 879
                             'type'       => 'TEXT',
880
-                            'input_name' => 'states[' . $STA_ID . ']',
880
+                            'input_name' => 'states['.$STA_ID.']',
881 881
                             'class'      => 'small-text',
882 882
                         ],
883 883
                         'STA_name'   => [
884 884
                             'type'       => 'TEXT',
885
-                            'input_name' => 'states[' . $STA_ID . ']',
885
+                            'input_name' => 'states['.$STA_ID.']',
886 886
                             'class'      => 'regular-text',
887 887
                         ],
888 888
                         'STA_active' => [
889 889
                             'type'             => 'RADIO_BTN',
890
-                            'input_name'       => 'states[' . $STA_ID . ']',
890
+                            'input_name'       => 'states['.$STA_ID.']',
891 891
                             'options'          => $this->_yes_no_values,
892 892
                             'use_desc_4_label' => true,
893 893
                         ],
894 894
                     ];
895
-                    $this->_template_args['states'][ $STA_ID ]['inputs']           =
895
+                    $this->_template_args['states'][$STA_ID]['inputs'] =
896 896
                         EE_Question_Form_Input::generate_question_form_inputs_for_object(
897 897
                             $state,
898 898
                             $state_input_types
899 899
                         );
900
-                    $query_args                                                    = [
900
+                    $query_args = [
901 901
                         'action'     => 'delete_state',
902 902
                         'STA_ID'     => $STA_ID,
903 903
                         'CNT_ISO'    => $CNT_ISO,
904 904
                         'STA_abbrev' => $state->abbrev(),
905 905
                     ];
906
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
906
+                    $this->_template_args['states'][$STA_ID]['delete_state_url'] =
907 907
                         EE_Admin_Page::add_query_args_and_nonce(
908 908
                             $query_args,
909 909
                             GEN_SET_ADMIN_URL
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
         );
921 921
 
922 922
         $state_details_settings = EEH_Template::display_template(
923
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
923
+            GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php',
924 924
             $this->_template_args,
925 925
             true
926 926
         );
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
         $CNT_ISO = isset($this->_req_data['CNT_ISO'])
960 960
             ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
961 961
             : false;
962
-        if (! $CNT_ISO) {
962
+        if ( ! $CNT_ISO) {
963 963
             EE_Error::add_error(
964 964
                 esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
965 965
                 __FILE__,
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
972 972
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
973 973
             : false;
974
-        if (! $STA_abbrev) {
974
+        if ( ! $STA_abbrev) {
975 975
             EE_Error::add_error(
976 976
                 esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
977 977
                 __FILE__,
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
         $STA_name = isset($this->_req_data['STA_name'])
984 984
             ? sanitize_text_field($this->_req_data['STA_name'])
985 985
             : false;
986
-        if (! $STA_name) {
986
+        if ( ! $STA_name) {
987 987
             EE_Error::add_error(
988 988
                 esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
989 989
                 __FILE__,
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
                 'STA_name'   => $STA_name,
1001 1001
                 'STA_active' => true,
1002 1002
             ];
1003
-            $success       = EEM_State::instance()->insert($cols_n_values);
1003
+            $success = EEM_State::instance()->insert($cols_n_values);
1004 1004
             EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1005 1005
         }
1006 1006
 
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1033 1033
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
1034 1034
             : false;
1035
-        if (! $STA_ID) {
1035
+        if ( ! $STA_ID) {
1036 1036
             EE_Error::add_error(
1037 1037
                 esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1038 1038
                 __FILE__,
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
         $CNT_ISO = isset($this->_req_data['country'])
1084 1084
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
1085 1085
             : false;
1086
-        if (! $CNT_ISO) {
1086
+        if ( ! $CNT_ISO) {
1087 1087
             EE_Error::add_error(
1088 1088
                 esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1089 1089
                 __FILE__,
@@ -1094,63 +1094,63 @@  discard block
 block discarded – undo
1094 1094
             return;
1095 1095
         }
1096 1096
         $cols_n_values             = [];
1097
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1098
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1097
+        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])
1098
+            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']))
1099 1099
             : false;
1100
-        $cols_n_values['RGN_ID']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1101
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1100
+        $cols_n_values['RGN_ID']   = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1101
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1102 1102
             : null;
1103
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1104
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1103
+        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1104
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1105 1105
             : null;
1106
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1106
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) {
1107 1107
             $cols_n_values['CNT_cur_code'] = strtoupper(
1108
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1108
+                sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])
1109 1109
             );
1110 1110
         }
1111
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1111
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) {
1112 1112
             $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1113
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1113
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']
1114 1114
             );
1115 1115
         }
1116
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1116
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) {
1117 1117
             $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1118
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1118
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']
1119 1119
             );
1120 1120
         }
1121
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1121
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) {
1122 1122
             $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1123
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1123
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']
1124 1124
             );
1125 1125
         }
1126
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1126
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) {
1127 1127
             $cols_n_values['CNT_cur_sign_b4'] = absint(
1128
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1128
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']
1129 1129
             );
1130 1130
         }
1131
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1131
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) {
1132 1132
             $cols_n_values['CNT_cur_dec_plc'] = absint(
1133
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1133
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']
1134 1134
             );
1135 1135
         }
1136
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1136
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) {
1137 1137
             $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1138
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1138
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']
1139 1139
             );
1140 1140
         }
1141
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1141
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) {
1142 1142
             $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1143
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1143
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']
1144 1144
             );
1145 1145
         }
1146
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1147
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1146
+        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1147
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1148 1148
             : null;
1149
-        $cols_n_values['CNT_is_EU']    = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1150
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1149
+        $cols_n_values['CNT_is_EU']    = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1150
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1151 1151
             : false;
1152
-        $cols_n_values['CNT_active']   = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1153
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1152
+        $cols_n_values['CNT_active']   = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1153
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1154 1154
             : false;
1155 1155
         // allow filtering of country data
1156 1156
         $cols_n_values = apply_filters(
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
         return '
1228 1228
 			<tr>
1229 1229
 				<th>
1230
-					' . $label . '
1230
+					' . $label.'
1231 1231
 				</th>';
1232 1232
     }
1233 1233
 
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
     {
1243 1243
         return '
1244 1244
 				<td class="general-settings-country-input-td">
1245
-					' . $input . '
1245
+					' . $input.'
1246 1246
 				</td>
1247 1247
 			</tr>';
1248 1248
     }
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
     {
1272 1272
         return '
1273 1273
 				<td class="general-settings-country-state-input-td">
1274
-					' . $input . '
1274
+					' . $input.'
1275 1275
 				</td>';
1276 1276
     }
1277 1277
 
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
                  . esc_html__('Edit', 'event_espresso')
1297 1297
                  . '</a>';
1298 1298
         $links .= ' &nbsp;|&nbsp; ';
1299
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1299
+        $links .= '<a href="'.get_permalink($ee_page_id).'" >'.esc_html__('View', 'event_espresso').'</a>';
1300 1300
 
1301 1301
         return $links;
1302 1302
     }
@@ -1329,9 +1329,9 @@  discard block
 block discarded – undo
1329 1329
             $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1330 1330
         }
1331 1331
 
1332
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1332
+        return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>'
1333 1333
                . $pg_status
1334
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1334
+               . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>';
1335 1335
     }
1336 1336
 
1337 1337
 
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
     public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0, $echo = true)
1348 1348
     {
1349 1349
         global $wpdb;
1350
-        $items  = $wpdb->get_results(
1350
+        $items = $wpdb->get_results(
1351 1351
             $wpdb->prepare(
1352 1352
                 "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",
1353 1353
                 $parent
@@ -1362,8 +1362,8 @@  discard block
 block discarded – undo
1362 1362
                 $post_title = wp_strip_all_tags($item->post_title);
1363 1363
                 $pad    = str_repeat('&nbsp;', $level * 3);
1364 1364
                 $option = "\n\t";
1365
-                $option .= '<option class="level-' . $level . '" ';
1366
-                $option .= 'value="' . $ID . '" ';
1365
+                $option .= '<option class="level-'.$level.'" ';
1366
+                $option .= 'value="'.$ID.'" ';
1367 1367
                 $option .= $ID === absint($default) ? ' selected' : '';
1368 1368
                 $option .= '>';
1369 1369
                 $option .= "$pad {$post_title}";
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Indentation   +2521 added lines, -2521 removed lines patch added patch discarded remove patch
@@ -13,2525 +13,2525 @@
 block discarded – undo
13 13
 class Transactions_Admin_Page extends EE_Admin_Page
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Transaction
18
-     */
19
-    private $_transaction;
20
-
21
-    /**
22
-     * @var EE_Session
23
-     */
24
-    private $_session;
25
-
26
-    /**
27
-     * @var array $_txn_status
28
-     */
29
-    private static $_txn_status;
30
-
31
-    /**
32
-     * @var array $_pay_status
33
-     */
34
-    private static $_pay_status;
35
-
36
-    /**
37
-     * @var array $_existing_reg_payment_REG_IDs
38
-     */
39
-    protected $_existing_reg_payment_REG_IDs;
40
-
41
-
42
-    /**
43
-     *    _init_page_props
44
-     *
45
-     * @return void
46
-     */
47
-    protected function _init_page_props()
48
-    {
49
-        $this->page_slug        = TXN_PG_SLUG;
50
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
51
-        $this->_admin_base_url  = TXN_ADMIN_URL;
52
-        $this->_admin_base_path = TXN_ADMIN;
53
-    }
54
-
55
-
56
-    /**
57
-     *    _ajax_hooks
58
-     *
59
-     * @return void
60
-     */
61
-    protected function _ajax_hooks()
62
-    {
63
-        add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
-        add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
-        add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
-    }
67
-
68
-
69
-    /**
70
-     *    _define_page_props
71
-     *
72
-     * @return void
73
-     */
74
-    protected function _define_page_props()
75
-    {
76
-        $this->_admin_page_title = $this->page_label;
77
-        $this->_labels           = [
78
-            'buttons' => [
79
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
-            ],
83
-        ];
84
-    }
85
-
86
-
87
-    /**
88
-     *        grab url requests and route them
89
-     *
90
-     * @access private
91
-     * @return void
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function _set_page_routes()
98
-    {
99
-
100
-        $this->_set_transaction_status_array();
101
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
-
103
-        $this->_page_routes = [
104
-
105
-            'default' => [
106
-                'func'       => '_transactions_overview_list_table',
107
-                'capability' => 'ee_read_transactions',
108
-            ],
109
-
110
-            'view_transaction' => [
111
-                'func'       => '_transaction_details',
112
-                'capability' => 'ee_read_transaction',
113
-                'obj_id'     => $TXN_ID,
114
-            ],
115
-
116
-            'send_payment_reminder' => [
117
-                'func'       => '_send_payment_reminder',
118
-                'noheader'   => true,
119
-                'capability' => 'ee_send_message',
120
-            ],
121
-
122
-            'espresso_apply_payment' => [
123
-                'func'       => 'apply_payments_or_refunds',
124
-                'noheader'   => true,
125
-                'capability' => 'ee_edit_payments',
126
-            ],
127
-
128
-            'espresso_apply_refund' => [
129
-                'func'       => 'apply_payments_or_refunds',
130
-                'noheader'   => true,
131
-                'capability' => 'ee_edit_payments',
132
-            ],
133
-
134
-            'espresso_delete_payment' => [
135
-                'func'       => 'delete_payment',
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_payments',
138
-            ],
139
-
140
-            'espresso_recalculate_line_items' => [
141
-                'func'       => 'recalculateLineItems',
142
-                'noheader'   => true,
143
-                'capability' => 'ee_edit_payments',
144
-            ],
145
-
146
-        ];
147
-    }
148
-
149
-
150
-    protected function _set_page_config()
151
-    {
152
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
-        $this->_page_config = [
154
-            'default'          => [
155
-                'nav'           => [
156
-                    'label' => esc_html__('Overview', 'event_espresso'),
157
-                    'order' => 10,
158
-                ],
159
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
160
-                'help_tabs'     => [
161
-                    'transactions_overview_help_tab'                       => [
162
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
-                        'filename' => 'transactions_overview',
164
-                    ],
165
-                    'transactions_overview_table_column_headings_help_tab' => [
166
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
-                        'filename' => 'transactions_overview_table_column_headings',
168
-                    ],
169
-                    'transactions_overview_views_filters_help_tab'         => [
170
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
-                        'filename' => 'transactions_overview_views_filters_search',
172
-                    ],
173
-                ],
174
-                /**
175
-                 * commented out because currently we are not displaying tips for transaction list table status but this
176
-                 * may change in a later iteration so want to keep the code for then.
177
-                 */
178
-                // 'qtips' => array( 'Transactions_List_Table_Tips' ),
179
-                'require_nonce' => false,
180
-            ],
181
-            'view_transaction' => [
182
-                'nav'       => [
183
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
184
-                    'order'      => 5,
185
-                    'url'        => $TXN_ID
186
-                        ? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
187
-                        : $this->_admin_base_url,
188
-                    'persistent' => false,
189
-                ],
190
-                'help_tabs' => [
191
-                    'transactions_view_transaction_help_tab'                                              => [
192
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
193
-                        'filename' => 'transactions_view_transaction',
194
-                    ],
195
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => [
196
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
197
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
198
-                    ],
199
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => [
200
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
201
-                        'filename' => 'transactions_view_transaction_attendees_registered',
202
-                    ],
203
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
204
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
205
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
206
-                    ],
207
-                ],
208
-                'qtips'     => ['Transaction_Details_Tips'],
209
-                'metaboxes' => ['_transaction_details_metaboxes'],
210
-
211
-                'require_nonce' => false,
212
-            ],
213
-        ];
214
-    }
215
-
216
-
217
-    /**
218
-     * The below methods aren't used by this class currently
219
-     */
220
-    protected function _add_screen_options()
221
-    {
222
-        // noop
223
-    }
224
-
225
-
226
-    protected function _add_feature_pointers()
227
-    {
228
-        // noop
229
-    }
230
-
231
-
232
-    public function admin_init()
233
-    {
234
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
235
-        $event_name = $this->request->getRequestParam('event_name');
236
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
237
-        // IF a registration was JUST added via the admin...
238
-        if ($EVT_ID && $event_name && $redirect_from) {
239
-            // then set a cookie so that we can block any attempts to use
240
-            // the back button as a way to enter another registration.
241
-            setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
242
-            // and update the global
243
-            $_COOKIE['ee_registration_added'] = $EVT_ID;
244
-        }
245
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
246
-            '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.',
247
-            'event_espresso'
248
-        );
249
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
250
-            'An error occurred! Please refresh the page and try again.',
251
-            'event_espresso'
252
-        );
253
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
254
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
255
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
256
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
257
-            'This transaction has been overpaid ! Payments Total',
258
-            'event_espresso'
259
-        );
260
-    }
261
-
262
-
263
-    public function admin_notices()
264
-    {
265
-        // noop
266
-    }
267
-
268
-
269
-    public function admin_footer_scripts()
270
-    {
271
-        // noop
272
-    }
273
-
274
-
275
-    /**
276
-     * _set_transaction_status_array
277
-     * sets list of transaction statuses
278
-     *
279
-     * @access private
280
-     * @return void
281
-     * @throws EE_Error
282
-     * @throws InvalidArgumentException
283
-     * @throws InvalidDataTypeException
284
-     * @throws InvalidInterfaceException
285
-     */
286
-    private function _set_transaction_status_array()
287
-    {
288
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
289
-    }
290
-
291
-
292
-    /**
293
-     * get_transaction_status_array
294
-     * return the transaction status array for wp_list_table
295
-     *
296
-     * @access public
297
-     * @return array
298
-     */
299
-    public function get_transaction_status_array()
300
-    {
301
-        return self::$_txn_status;
302
-    }
303
-
304
-
305
-    /**
306
-     *    get list of payment statuses
307
-     *
308
-     * @access private
309
-     * @return void
310
-     * @throws EE_Error
311
-     * @throws InvalidArgumentException
312
-     * @throws InvalidDataTypeException
313
-     * @throws InvalidInterfaceException
314
-     */
315
-    private function _get_payment_status_array()
316
-    {
317
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
318
-        $this->_template_args['payment_status'] = self::$_pay_status;
319
-    }
320
-
321
-
322
-    /**
323
-     *    _add_screen_options_default
324
-     *
325
-     * @access protected
326
-     * @return void
327
-     * @throws InvalidArgumentException
328
-     * @throws InvalidDataTypeException
329
-     * @throws InvalidInterfaceException
330
-     */
331
-    protected function _add_screen_options_default()
332
-    {
333
-        $this->_per_page_screen_option();
334
-    }
335
-
336
-
337
-    /**
338
-     * load_scripts_styles
339
-     *
340
-     * @access public
341
-     * @return void
342
-     */
343
-    public function load_scripts_styles()
344
-    {
345
-        // enqueue style
346
-        wp_register_style(
347
-            'espresso_txn',
348
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
349
-            [],
350
-            EVENT_ESPRESSO_VERSION
351
-        );
352
-        wp_enqueue_style('espresso_txn');
353
-        // scripts
354
-        wp_register_script(
355
-            'espresso_txn',
356
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
357
-            [
358
-                'ee_admin_js',
359
-                'ee-datepicker',
360
-                'jquery-ui-datepicker',
361
-                'jquery-ui-draggable',
362
-                'ee-dialog',
363
-                'ee-accounting',
364
-                'ee-serialize-full-array',
365
-            ],
366
-            EVENT_ESPRESSO_VERSION,
367
-            true
368
-        );
369
-        wp_enqueue_script('espresso_txn');
370
-    }
371
-
372
-
373
-    /**
374
-     *    load_scripts_styles_view_transaction
375
-     *
376
-     * @access public
377
-     * @return void
378
-     */
379
-    public function load_scripts_styles_view_transaction()
380
-    {
381
-        // styles
382
-        wp_enqueue_style('espresso-ui-theme');
383
-    }
384
-
385
-
386
-    /**
387
-     *    load_scripts_styles_default
388
-     *
389
-     * @access public
390
-     * @return void
391
-     */
392
-    public function load_scripts_styles_default()
393
-    {
394
-        // styles
395
-        wp_enqueue_style('espresso-ui-theme');
396
-    }
397
-
398
-
399
-    /**
400
-     *    _set_list_table_views_default
401
-     *
402
-     * @access protected
403
-     * @return void
404
-     */
405
-    protected function _set_list_table_views_default()
406
-    {
407
-        $this->_views = [
408
-            'all'        => [
409
-                'slug'  => 'all',
410
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
411
-                'count' => 0,
412
-            ],
413
-            'abandoned'  => [
414
-                'slug'  => 'abandoned',
415
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
416
-                'count' => 0,
417
-            ],
418
-            'incomplete' => [
419
-                'slug'  => 'incomplete',
420
-                'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
421
-                'count' => 0,
422
-            ],
423
-        ];
424
-        if (
425
-            /**
426
-             * Filters whether a link to the "Failed Transactions" list table
427
-             * appears on the Transactions Admin Page list table.
428
-             * List display can be turned back on via the following:
429
-             * add_filter(
430
-             *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
431
-             *     '__return_true'
432
-             * );
433
-             *
434
-             * @param boolean                 $display_failed_txns_list
435
-             * @param Transactions_Admin_Page $this
436
-             * @since 4.9.70.p
437
-             */
438
-            apply_filters(
439
-                'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
440
-                false,
441
-                $this
442
-            )
443
-        ) {
444
-            $this->_views['failed'] = [
445
-                'slug'  => 'failed',
446
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
447
-                'count' => 0,
448
-            ];
449
-        }
450
-    }
451
-
452
-
453
-    /**
454
-     * _set_transaction_object
455
-     * This sets the _transaction property for the transaction details screen
456
-     *
457
-     * @access private
458
-     * @return void
459
-     * @throws EE_Error
460
-     * @throws InvalidArgumentException
461
-     * @throws RuntimeException
462
-     * @throws InvalidDataTypeException
463
-     * @throws InvalidInterfaceException
464
-     * @throws ReflectionException
465
-     */
466
-    private function _set_transaction_object()
467
-    {
468
-        if ($this->_transaction instanceof EE_Transaction) {
469
-            return;
470
-        } //get out we've already set the object
471
-
472
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
473
-
474
-        // get transaction object
475
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
476
-        $this->_session     = $this->_transaction instanceof EE_Transaction
477
-            ? $this->_transaction->session_data()
478
-            : null;
479
-        if ($this->_transaction instanceof EE_Transaction) {
480
-            $this->_transaction->verify_abandoned_transaction_status();
481
-        }
482
-
483
-        if (! $this->_transaction instanceof EE_Transaction) {
484
-            $error_msg = sprintf(
485
-                esc_html__(
486
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
487
-                    'event_espresso'
488
-                ),
489
-                $TXN_ID
490
-            );
491
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
492
-        }
493
-    }
494
-
495
-
496
-    /**
497
-     *    _transaction_legend_items
498
-     *
499
-     * @access protected
500
-     * @return array
501
-     * @throws EE_Error
502
-     * @throws InvalidArgumentException
503
-     * @throws ReflectionException
504
-     * @throws InvalidDataTypeException
505
-     * @throws InvalidInterfaceException
506
-     */
507
-    protected function _transaction_legend_items()
508
-    {
509
-        EE_Registry::instance()->load_helper('MSG_Template');
510
-        $items = [];
511
-
512
-        if (
513
-            EE_Registry::instance()->CAP->current_user_can(
514
-                'ee_read_global_messages',
515
-                'view_filtered_messages'
516
-            )
517
-        ) {
518
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
519
-            if (
520
-                is_array($related_for_icon)
521
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
522
-            ) {
523
-                $items['view_related_messages'] = [
524
-                    'class' => $related_for_icon['css_class'],
525
-                    'desc'  => $related_for_icon['label'],
526
-                ];
527
-            }
528
-        }
529
-
530
-        $items = apply_filters(
531
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
532
-            array_merge(
533
-                $items,
534
-                [
535
-                    'view_details'          => [
536
-                        'class' => 'dashicons dashicons-cart',
537
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
538
-                    ],
539
-                    'view_invoice'          => [
540
-                        'class' => 'dashicons dashicons-media-spreadsheet',
541
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
542
-                    ],
543
-                    'view_receipt'          => [
544
-                        'class' => 'dashicons dashicons-media-default',
545
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
546
-                    ],
547
-                    'view_registration'     => [
548
-                        'class' => 'dashicons dashicons-clipboard',
549
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
550
-                    ],
551
-                    'payment_overview_link' => [
552
-                        'class' => 'dashicons dashicons-money',
553
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
554
-                    ],
555
-                ]
556
-            )
557
-        );
558
-
559
-        if (
560
-            EEH_MSG_Template::is_mt_active('payment_reminder')
561
-            && EE_Registry::instance()->CAP->current_user_can(
562
-                'ee_send_message',
563
-                'espresso_transactions_send_payment_reminder'
564
-            )
565
-        ) {
566
-            $items['send_payment_reminder'] = [
567
-                'class' => 'dashicons dashicons-email-alt',
568
-                'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
569
-            ];
570
-        } else {
571
-            $items['blank*'] = [
572
-                'class' => '',
573
-                'desc'  => '',
574
-            ];
575
-        }
576
-        $more_items = apply_filters(
577
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
578
-            [
579
-                'overpaid'   => [
580
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
581
-                    'desc'  => EEH_Template::pretty_status(
582
-                        EEM_Transaction::overpaid_status_code,
583
-                        false,
584
-                        'sentence'
585
-                    ),
586
-                ],
587
-                'complete'   => [
588
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
589
-                    'desc'  => EEH_Template::pretty_status(
590
-                        EEM_Transaction::complete_status_code,
591
-                        false,
592
-                        'sentence'
593
-                    ),
594
-                ],
595
-                'incomplete' => [
596
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
597
-                    'desc'  => EEH_Template::pretty_status(
598
-                        EEM_Transaction::incomplete_status_code,
599
-                        false,
600
-                        'sentence'
601
-                    ),
602
-                ],
603
-                'abandoned'  => [
604
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
605
-                    'desc'  => EEH_Template::pretty_status(
606
-                        EEM_Transaction::abandoned_status_code,
607
-                        false,
608
-                        'sentence'
609
-                    ),
610
-                ],
611
-                'failed'     => [
612
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
613
-                    'desc'  => EEH_Template::pretty_status(
614
-                        EEM_Transaction::failed_status_code,
615
-                        false,
616
-                        'sentence'
617
-                    ),
618
-                ],
619
-            ]
620
-        );
621
-
622
-        return array_merge($items, $more_items);
623
-    }
624
-
625
-
626
-    /**
627
-     *    _transactions_overview_list_table
628
-     *
629
-     * @access protected
630
-     * @return void
631
-     * @throws DomainException
632
-     * @throws EE_Error
633
-     * @throws InvalidArgumentException
634
-     * @throws InvalidDataTypeException
635
-     * @throws InvalidInterfaceException
636
-     * @throws ReflectionException
637
-     */
638
-    protected function _transactions_overview_list_table()
639
-    {
640
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
641
-
642
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
643
-        $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
644
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
645
-            ? sprintf(
646
-                esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
647
-                '<h3>',
648
-                '<a href="'
649
-                . EE_Admin_Page::add_query_args_and_nonce(
650
-                    ['action' => 'edit', 'post' => $event->ID()],
651
-                    EVENTS_ADMIN_URL
652
-                )
653
-                . '" title="'
654
-                . esc_attr__('Click to Edit event', 'event_espresso')
655
-                . '">' . $event->name() . '</a>',
656
-                '</h3>'
657
-            )
658
-            : '';
659
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
660
-        $this->display_admin_list_table_page_with_no_sidebar();
661
-    }
662
-
663
-
664
-    /**
665
-     *    _transaction_details
666
-     * generates HTML for the View Transaction Details Admin page
667
-     *
668
-     * @access protected
669
-     * @return void
670
-     * @throws DomainException
671
-     * @throws EE_Error
672
-     * @throws InvalidArgumentException
673
-     * @throws InvalidDataTypeException
674
-     * @throws InvalidInterfaceException
675
-     * @throws RuntimeException
676
-     * @throws ReflectionException
677
-     */
678
-    protected function _transaction_details()
679
-    {
680
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
681
-
682
-        $this->_set_transaction_status_array();
683
-
684
-        $this->_template_args                      = [];
685
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
686
-
687
-        $this->_set_transaction_object();
688
-
689
-        if (! $this->_transaction instanceof EE_Transaction) {
690
-            return;
691
-        }
692
-
693
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
694
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
695
-
696
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
697
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
698
-
699
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
700
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
701
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
702
-
703
-        $this->_template_args['grand_total'] = $this->_transaction->total();
704
-        $this->_template_args['total_paid']  = $this->_transaction->paid();
705
-
706
-        $amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
707
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
708
-            $amount_due,
709
-            true
710
-        );
711
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
712
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
713
-                                                  . $this->_template_args['amount_due'];
714
-        } else {
715
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
716
-        }
717
-        $this->_template_args['amount_due_class'] = '';
718
-
719
-        if ($this->_transaction->paid() === $this->_transaction->total()) {
720
-            // paid in full
721
-            $this->_template_args['amount_due'] = false;
722
-        } elseif ($this->_transaction->paid() > $this->_transaction->total()) {
723
-            // overpaid
724
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
725
-        } elseif ($this->_transaction->total() > (float) 0) {
726
-            if ($this->_transaction->paid() > (float) 0) {
727
-                // monies owing
728
-                $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
729
-            } elseif ($this->_transaction->paid() === (float) 0) {
730
-                // no payments made yet
731
-                $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
732
-            }
733
-        } elseif ($this->_transaction->total() === (float) 0) {
734
-            // free event
735
-            $this->_template_args['amount_due'] = false;
736
-        }
737
-
738
-        $payment_method = $this->_transaction->payment_method();
739
-
740
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
741
-            ? $payment_method->admin_name()
742
-            : esc_html__('Unknown', 'event_espresso');
743
-
744
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
745
-        // link back to overview
746
-        $this->_template_args['txn_overview_url'] = $this->request->getServerParam(
747
-            'HTTP_REFERER',
748
-            TXN_ADMIN_URL
749
-        );
750
-
751
-
752
-        // next link
753
-        $next_txn                                 = $this->_transaction->next(
754
-            null,
755
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
756
-            'TXN_ID'
757
-        );
758
-        $this->_template_args['next_transaction'] = $next_txn
759
-            ? $this->_next_link(
760
-                EE_Admin_Page::add_query_args_and_nonce(
761
-                    ['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
762
-                    TXN_ADMIN_URL
763
-                ),
764
-                'dashicons dashicons-arrow-right ee-icon-size-22'
765
-            )
766
-            : '';
767
-        // previous link
768
-        $previous_txn                                 = $this->_transaction->previous(
769
-            null,
770
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
771
-            'TXN_ID'
772
-        );
773
-        $this->_template_args['previous_transaction'] = $previous_txn
774
-            ? $this->_previous_link(
775
-                EE_Admin_Page::add_query_args_and_nonce(
776
-                    ['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
777
-                    TXN_ADMIN_URL
778
-                ),
779
-                'dashicons dashicons-arrow-left ee-icon-size-22'
780
-            )
781
-            : '';
782
-
783
-        $EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
784
-        $event_name    = $this->request->getRequestParam('event_name');
785
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
786
-
787
-        // were we just redirected here after adding a new registration ???
788
-        if ($EVT_ID && $event_name && $redirect_from) {
789
-            if (
790
-                EE_Registry::instance()->CAP->current_user_can(
791
-                    'ee_edit_registrations',
792
-                    'espresso_registrations_new_registration',
793
-                    $EVT_ID
794
-                )
795
-            ) {
796
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
797
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
798
-                    [
799
-                        'page'     => 'espresso_registrations',
800
-                        'action'   => 'new_registration',
801
-                        'return'   => 'default',
802
-                        'TXN_ID'   => $this->_transaction->ID(),
803
-                        'event_id' => $EVT_ID,
804
-                    ],
805
-                    REG_ADMIN_URL
806
-                );
807
-                $this->_admin_page_title .= '">';
808
-
809
-                $this->_admin_page_title .= sprintf(
810
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
811
-                    htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
812
-                );
813
-                $this->_admin_page_title .= '</a>';
814
-            }
815
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
816
-        }
817
-        // grab messages at the last second
818
-        $this->_template_args['notices'] = EE_Error::get_notices();
819
-        // path to template
820
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
821
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
822
-            $template_path,
823
-            $this->_template_args,
824
-            true
825
-        );
826
-
827
-        // the details template wrapper
828
-        $this->display_admin_page_with_sidebar();
829
-    }
830
-
831
-
832
-    /**
833
-     *        _transaction_details_metaboxes
834
-     *
835
-     * @access protected
836
-     * @return void
837
-     * @throws EE_Error
838
-     * @throws InvalidArgumentException
839
-     * @throws InvalidDataTypeException
840
-     * @throws InvalidInterfaceException
841
-     * @throws RuntimeException
842
-     * @throws ReflectionException
843
-     */
844
-    protected function _transaction_details_metaboxes()
845
-    {
846
-
847
-        $this->_set_transaction_object();
848
-
849
-        if (! $this->_transaction instanceof EE_Transaction) {
850
-            return;
851
-        }
852
-        add_meta_box(
853
-            'edit-txn-details-mbox',
854
-            esc_html__('Transaction Details', 'event_espresso'),
855
-            [$this, 'txn_details_meta_box'],
856
-            $this->_wp_page_slug,
857
-            'normal',
858
-            'high'
859
-        );
860
-        add_meta_box(
861
-            'edit-txn-attendees-mbox',
862
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
863
-            [$this, 'txn_attendees_meta_box'],
864
-            $this->_wp_page_slug,
865
-            'normal',
866
-            'high',
867
-            ['TXN_ID' => $this->_transaction->ID()]
868
-        );
869
-        add_meta_box(
870
-            'edit-txn-registrant-mbox',
871
-            esc_html__('Primary Contact', 'event_espresso'),
872
-            [$this, 'txn_registrant_side_meta_box'],
873
-            $this->_wp_page_slug,
874
-            'side',
875
-            'high'
876
-        );
877
-        add_meta_box(
878
-            'edit-txn-billing-info-mbox',
879
-            esc_html__('Billing Information', 'event_espresso'),
880
-            [$this, 'txn_billing_info_side_meta_box'],
881
-            $this->_wp_page_slug,
882
-            'side',
883
-            'high'
884
-        );
885
-    }
886
-
887
-
888
-    /**
889
-     * Callback for transaction actions metabox.
890
-     *
891
-     * @param EE_Transaction|null $transaction
892
-     * @return string
893
-     * @throws DomainException
894
-     * @throws EE_Error
895
-     * @throws InvalidArgumentException
896
-     * @throws InvalidDataTypeException
897
-     * @throws InvalidInterfaceException
898
-     * @throws ReflectionException
899
-     * @throws RuntimeException
900
-     */
901
-    public function getActionButtons(EE_Transaction $transaction = null)
902
-    {
903
-        $content = '';
904
-        $actions = [];
905
-        if (! $transaction instanceof EE_Transaction) {
906
-            return $content;
907
-        }
908
-        /** @var EE_Registration $primary_registration */
909
-        $primary_registration = $transaction->primary_registration();
910
-        $attendee             = $primary_registration instanceof EE_Registration
911
-            ? $primary_registration->attendee()
912
-            : null;
913
-
914
-        if (
915
-            $attendee instanceof EE_Attendee
916
-            && EE_Registry::instance()->CAP->current_user_can(
917
-                'ee_send_message',
918
-                'espresso_transactions_send_payment_reminder'
919
-            )
920
-        ) {
921
-            $actions['payment_reminder'] =
922
-                EEH_MSG_Template::is_mt_active('payment_reminder')
923
-                && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
924
-                && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
925
-                    ? EEH_Template::get_button_or_link(
926
-                        EE_Admin_Page::add_query_args_and_nonce(
927
-                            [
928
-                            'action'      => 'send_payment_reminder',
929
-                            'TXN_ID'      => $this->_transaction->ID(),
930
-                            'redirect_to' => 'view_transaction',
931
-                            ],
932
-                            TXN_ADMIN_URL
933
-                        ),
934
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
935
-                        'button secondary-button',
936
-                        'dashicons dashicons-email-alt'
937
-                    )
938
-                    : '';
939
-        }
940
-
941
-        if (
942
-            EE_Registry::instance()->CAP->current_user_can(
943
-                'ee_edit_payments',
944
-                'espresso_transactions_recalculate_line_items'
945
-            )
946
-        ) {
947
-            $actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
948
-                EE_Admin_Page::add_query_args_and_nonce(
949
-                    [
950
-                        'action'      => 'espresso_recalculate_line_items',
951
-                        'TXN_ID'      => $this->_transaction->ID(),
952
-                        'redirect_to' => 'view_transaction',
953
-                    ],
954
-                    TXN_ADMIN_URL
955
-                ),
956
-                esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
957
-                'button secondary-button',
958
-                'dashicons dashicons-update'
959
-            );
960
-        }
961
-
962
-        if (
963
-            $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 (
975
-            $primary_registration instanceof EE_Registration
976
-            && EEH_MSG_Template::is_mt_active('invoice')
977
-        ) {
978
-            $actions['invoice'] = EEH_Template::get_button_or_link(
979
-                $primary_registration->invoice_url(),
980
-                esc_html__('View Invoice', 'event_espresso'),
981
-                'button secondary-button',
982
-                'dashicons dashicons-media-spreadsheet'
983
-            );
984
-        }
985
-        $actions = array_filter(
986
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
987
-        );
988
-        if ($actions) {
989
-            $content = '<ul>';
990
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
991
-            $content .= '</uL>';
992
-        }
993
-        return $content;
994
-    }
995
-
996
-
997
-    /**
998
-     * txn_details_meta_box
999
-     * generates HTML for the Transaction main meta box
1000
-     *
1001
-     * @return void
1002
-     * @throws DomainException
1003
-     * @throws EE_Error
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws RuntimeException
1008
-     * @throws ReflectionException
1009
-     */
1010
-    public function txn_details_meta_box()
1011
-    {
1012
-        $this->_set_transaction_object();
1013
-        $this->_template_args['TXN_ID']              = $this->_transaction->ID();
1014
-        $this->_template_args['attendee']            =
1015
-            $this->_transaction->primary_registration() instanceof EE_Registration
1016
-                ? $this->_transaction->primary_registration()->attendee()
1017
-                : null;
1018
-        $this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1019
-            'ee_edit_payments',
1020
-            'apply_payment_or_refund_from_registration_details'
1021
-        );
1022
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1023
-            'ee_delete_payments',
1024
-            'delete_payment_from_registration_details'
1025
-        );
1026
-
1027
-        // get line table
1028
-        EEH_Autoloader::register_line_item_display_autoloaders();
1029
-        $Line_Item_Display                       = new EE_Line_Item_Display(
1030
-            'admin_table',
1031
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1032
-        );
1033
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1034
-            $this->_transaction->total_line_item()
1035
-        );
1036
-        $this->_template_args['REG_code']        =
1037
-            $this->_transaction->primary_registration() instanceof EE_Registration
1038
-                ? $this->_transaction->primary_registration()->reg_code()
1039
-                : null;
1040
-        // process taxes
1041
-        $taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1042
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
-
1044
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1045
-            $this->_transaction->total(),
1046
-            false,
1047
-            false
1048
-        );
1049
-        $this->_template_args['grand_raw_total'] = $this->_transaction->total();
1050
-        $this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1051
-
1052
-        // process payment details
1053
-        $payments = $this->_transaction->payments();
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'] = [];
1060
-        }
1061
-
1062
-        $this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1063
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1064
-            ['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'] =
1077
-            $this->_transaction->primary_registration() instanceof EE_Registration
1078
-                ? $this->_transaction->primary_registration()->session_ID()
1079
-                : null;
1080
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1081
-            'Registration Session',
1082
-            'event_espresso'
1083
-        );
1084
-
1085
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1086
-            ? $this->_session['ip_address']
1087
-            : '';
1088
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1089
-            'Transaction placed from IP',
1090
-            'event_espresso'
1091
-        );
1092
-
1093
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1094
-            ? $this->_session['user_agent']
1095
-            : '';
1096
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1097
-            'Registrant User Agent',
1098
-            'event_espresso'
1099
-        );
1100
-
1101
-        $reg_steps = '<ul>';
1102
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1103
-            if ($reg_step_status === true) {
1104
-                $reg_steps .= '<li style="color:#70cc50">'
1105
-                              . sprintf(
1106
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1107
-                                  ucwords(str_replace('_', ' ', $reg_step))
1108
-                              )
1109
-                              . '</li>';
1110
-            } elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1111
-                $reg_steps .= '<li style="color:#2EA2CC">'
1112
-                              . sprintf(
1113
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1114
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1115
-                                  date(
1116
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1117
-                                      $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1118
-                                  )
1119
-                              )
1120
-                              . '</li>';
1121
-            } else {
1122
-                $reg_steps .= '<li style="color:#E76700">'
1123
-                              . sprintf(
1124
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1125
-                                  ucwords(str_replace('_', ' ', $reg_step))
1126
-                              )
1127
-                              . '</li>';
1128
-            }
1129
-        }
1130
-        $reg_steps                                                 .= '</ul>';
1131
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1132
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1133
-            'Registration Step Progress',
1134
-            'event_espresso'
1135
-        );
1136
-
1137
-
1138
-        $this->_get_registrations_to_apply_payment_to();
1139
-        $this->_get_payment_methods($payments);
1140
-        $this->_get_payment_status_array();
1141
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1142
-
1143
-        $this->_template_args['transaction_form_url']    = add_query_arg(
1144
-            [
1145
-                'action'  => 'edit_transaction',
1146
-                'process' => 'transaction',
1147
-            ],
1148
-            TXN_ADMIN_URL
1149
-        );
1150
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(
1151
-            [
1152
-                'page'   => 'espresso_transactions',
1153
-                'action' => 'espresso_apply_payment',
1154
-            ],
1155
-            WP_AJAX_URL
1156
-        );
1157
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1158
-            [
1159
-                'page'   => 'espresso_transactions',
1160
-                'action' => 'espresso_delete_payment',
1161
-            ],
1162
-            WP_AJAX_URL
1163
-        );
1164
-
1165
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1166
-
1167
-        // 'espresso_delete_payment_nonce'
1168
-
1169
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1170
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * _get_registration_payment_IDs
1176
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1177
-     *
1178
-     * @access protected
1179
-     * @param EE_Payment[] $payments
1180
-     * @return array
1181
-     * @throws EE_Error
1182
-     * @throws InvalidArgumentException
1183
-     * @throws InvalidDataTypeException
1184
-     * @throws InvalidInterfaceException
1185
-     * @throws ReflectionException
1186
-     */
1187
-    protected function _get_registration_payment_IDs($payments = [])
1188
-    {
1189
-        $existing_reg_payments = [];
1190
-        // get all reg payments for these payments
1191
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1192
-            [
1193
-                [
1194
-                    'PAY_ID' => [
1195
-                        'IN',
1196
-                        array_keys($payments),
1197
-                    ],
1198
-                ],
1199
-            ]
1200
-        );
1201
-        if (! empty($reg_payments)) {
1202
-            foreach ($payments as $payment) {
1203
-                if (! $payment instanceof EE_Payment) {
1204
-                    continue;
1205
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1206
-                    $existing_reg_payments[ $payment->ID() ] = [];
1207
-                }
1208
-                foreach ($reg_payments as $reg_payment) {
1209
-                    if (
1210
-                        $reg_payment instanceof EE_Registration_Payment
1211
-                        && $reg_payment->payment_ID() === $payment->ID()
1212
-                    ) {
1213
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1214
-                    }
1215
-                }
1216
-            }
1217
-        }
1218
-
1219
-        return $existing_reg_payments;
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * _get_registrations_to_apply_payment_to
1225
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1226
-     * which allows the admin to only apply the payment to the specific registrations
1227
-     *
1228
-     * @access protected
1229
-     * @return void
1230
-     * @throws EE_Error
1231
-     * @throws InvalidArgumentException
1232
-     * @throws InvalidDataTypeException
1233
-     * @throws InvalidInterfaceException
1234
-     * @throws ReflectionException
1235
-     */
1236
-    protected function _get_registrations_to_apply_payment_to()
1237
-    {
1238
-        // we want any registration with an active status (ie: not deleted or cancelled)
1239
-        $query_params                      = [
1240
-            [
1241
-                'STS_ID' => [
1242
-                    'IN',
1243
-                    [
1244
-                        EEM_Registration::status_id_approved,
1245
-                        EEM_Registration::status_id_pending_payment,
1246
-                        EEM_Registration::status_id_not_approved,
1247
-                    ],
1248
-                ],
1249
-            ],
1250
-        ];
1251
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1252
-            '',
1253
-            'txn-admin-apply-payment-to-registrations-dv',
1254
-            '',
1255
-            'clear: both; margin: 1.5em 0 0; display: none;'
1256
-        );
1257
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
-            EEH_HTML::tr(
1261
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
-            )
1269
-        );
1270
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
-        // get registrations for TXN
1272
-        $registrations         = $this->_transaction->registrations($query_params);
1273
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
-        foreach ($registrations as $registration) {
1275
-            if ($registration instanceof EE_Registration) {
1276
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1277
-                    ? $registration->attendee()->full_name()
1278
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1279
-                $owing                             = $registration->final_price() - $registration->paid();
1280
-                $taxable                           = $registration->ticket()->taxable()
1281
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
-                    : '';
1283
-                $checked                           = empty($existing_reg_payments)
1284
-                                                     || in_array($registration->ID(), $existing_reg_payments, true)
1285
-                    ? ' checked'
1286
-                    : '';
1287
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1288
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1289
-                    EEH_HTML::td($registration->ID()) .
1290
-                    EEH_HTML::td($attendee_name) .
1291
-                    EEH_HTML::td(
1292
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1293
-                    ) .
1294
-                    EEH_HTML::td($registration->event_name()) .
1295
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1296
-                    EEH_HTML::td(
1297
-                        EEH_Template::format_currency($owing),
1298
-                        '',
1299
-                        'txn-admin-payment-owing-td jst-cntr'
1300
-                    ) .
1301
-                    EEH_HTML::td(
1302
-                        '<input type="checkbox" value="' . $registration->ID()
1303
-                        . '" name="txn_admin_payment[registrations]"'
1304
-                        . $checked . $disabled . '>',
1305
-                        '',
1306
-                        'jst-cntr'
1307
-                    ),
1308
-                    'apply-payment-registration-row-' . $registration->ID()
1309
-                );
1310
-            }
1311
-        }
1312
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1313
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1314
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1315
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1316
-            esc_html__(
1317
-                '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.',
1318
-                'event_espresso'
1319
-            ),
1320
-            '',
1321
-            'clear description'
1322
-        );
1323
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1324
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * _get_reg_status_selection
1330
-     *
1331
-     * @return void
1332
-     * @throws EE_Error
1333
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1334
-     *         instead of events.
1335
-     * @access protected
1336
-     */
1337
-    protected function _get_reg_status_selection()
1338
-    {
1339
-        // first get all possible statuses
1340
-        $statuses = EEM_Registration::reg_status_array([], true);
1341
-        // let's add a "don't change" option.
1342
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1343
-        $status_array                                        = array_merge($status_array, $statuses);
1344
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1345
-            'txn_reg_status_change[reg_status]',
1346
-            $status_array,
1347
-            'NAN',
1348
-            'id="txn-admin-payment-reg-status-inp"',
1349
-            'txn-reg-status-change-reg-status'
1350
-        );
1351
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1352
-            'delete_txn_reg_status_change[reg_status]',
1353
-            $status_array,
1354
-            'NAN',
1355
-            'delete-txn-admin-payment-reg-status-inp',
1356
-            'delete-txn-reg-status-change-reg-status'
1357
-        );
1358
-    }
1359
-
1360
-
1361
-    /**
1362
-     *    _get_payment_methods
1363
-     * Gets all the payment methods available generally, or the ones that are already
1364
-     * selected on these payments (in case their payment methods are no longer active).
1365
-     * Has the side-effect of updating the template args' payment_methods item
1366
-     *
1367
-     * @access private
1368
-     * @param EE_Payment[] to show on this page
1369
-     * @return void
1370
-     * @throws EE_Error
1371
-     * @throws InvalidArgumentException
1372
-     * @throws InvalidDataTypeException
1373
-     * @throws InvalidInterfaceException
1374
-     * @throws ReflectionException
1375
-     */
1376
-    private function _get_payment_methods($payments = [])
1377
-    {
1378
-        $payment_methods_of_payments = [];
1379
-        foreach ($payments as $payment) {
1380
-            if ($payment instanceof EE_Payment) {
1381
-                $payment_methods_of_payments[] = $payment->ID();
1382
-            }
1383
-        }
1384
-        if ($payment_methods_of_payments) {
1385
-            $query_args = [
1386
-                [
1387
-                    'OR*payment_method_for_payment' => [
1388
-                        'PMD_ID'    => ['IN', $payment_methods_of_payments],
1389
-                        'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1390
-                    ],
1391
-                ],
1392
-            ];
1393
-        } else {
1394
-            $query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1395
-        }
1396
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1397
-    }
1398
-
1399
-
1400
-    /**
1401
-     * txn_attendees_meta_box
1402
-     *    generates HTML for the Attendees Transaction main meta box
1403
-     *
1404
-     * @access public
1405
-     * @param WP_Post $post
1406
-     * @param array   $metabox
1407
-     * @return void
1408
-     * @throws DomainException
1409
-     * @throws EE_Error
1410
-     * @throws InvalidArgumentException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws InvalidInterfaceException
1413
-     * @throws ReflectionException
1414
-     */
1415
-    public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1416
-    {
1417
-
1418
-        /** @noinspection NonSecureExtractUsageInspection */
1419
-        extract($metabox['args']);
1420
-        $this->_template_args['post']            = $post;
1421
-        $this->_template_args['event_attendees'] = [];
1422
-        // process items in cart
1423
-        $line_items = $this->_transaction->get_many_related(
1424
-            'Line_Item',
1425
-            [['LIN_type' => 'line-item']]
1426
-        );
1427
-        if (! empty($line_items)) {
1428
-            foreach ($line_items as $item) {
1429
-                if ($item instanceof EE_Line_Item) {
1430
-                    switch ($item->OBJ_type()) {
1431
-                        case 'Event':
1432
-                            break;
1433
-                        case 'Ticket':
1434
-                            $ticket = $item->ticket();
1435
-                            // right now we're only handling tickets here.
1436
-                            // Cause its expected that only tickets will have attendees right?
1437
-                            if (! $ticket instanceof EE_Ticket) {
1438
-                                break;
1439
-                            }
1440
-                            try {
1441
-                                $event_name = $ticket->get_event_name();
1442
-                            } catch (Exception $e) {
1443
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1444
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1445
-                            }
1446
-                            $event_name   .= ' - ' . $item->name();
1447
-                            $ticket_price = EEH_Template::format_currency($item->unit_price());
1448
-                            // now get all of the registrations for this transaction that use this ticket
1449
-                            $registrations = $ticket->registrations(
1450
-                                [['TXN_ID' => $this->_transaction->ID()]]
1451
-                            );
1452
-                            foreach ($registrations as $registration) {
1453
-                                if (! $registration instanceof EE_Registration) {
1454
-                                    break;
1455
-                                }
1456
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1457
-                                    = $registration->status_ID();
1458
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1459
-                                    = $registration->count();
1460
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1461
-                                    = $event_name;
1462
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1463
-                                    = $ticket_price;
1464
-                                // attendee info
1465
-                                $attendee = $registration->get_first_related('Attendee');
1466
-                                if ($attendee instanceof EE_Attendee) {
1467
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1468
-                                        = $attendee->ID();
1469
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1470
-                                        = $attendee->full_name();
1471
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1472
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1473
-                                          . esc_html__(
1474
-                                              ' Event',
1475
-                                              'event_espresso'
1476
-                                          )
1477
-                                          . '">' . $attendee->email() . '</a>';
1478
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1479
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1480
-                                } else {
1481
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1482
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1483
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1485
-                                }
1486
-                            }
1487
-                            break;
1488
-                    }
1489
-                }
1490
-            }
1491
-
1492
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1493
-                [
1494
-                    'action'  => 'edit_transaction',
1495
-                    'process' => 'attendees',
1496
-                ],
1497
-                TXN_ADMIN_URL
1498
-            );
1499
-            echo EEH_Template::display_template(
1500
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1501
-                $this->_template_args,
1502
-                true
1503
-            );
1504
-        } else {
1505
-            printf(
1506
-                esc_html__(
1507
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1508
-                    'event_espresso'
1509
-                ),
1510
-                '<p class="important-notice">',
1511
-                '</p>'
1512
-            );
1513
-        }
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * txn_registrant_side_meta_box
1519
-     * generates HTML for the Edit Transaction side meta box
1520
-     *
1521
-     * @access public
1522
-     * @return void
1523
-     * @throws DomainException
1524
-     * @throws EE_Error
1525
-     * @throws InvalidArgumentException
1526
-     * @throws InvalidDataTypeException
1527
-     * @throws InvalidInterfaceException
1528
-     * @throws ReflectionException
1529
-     */
1530
-    public function txn_registrant_side_meta_box()
1531
-    {
1532
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1533
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1534
-            : null;
1535
-        if (! $primary_att instanceof EE_Attendee) {
1536
-            $this->_template_args['no_attendee_message'] = esc_html__(
1537
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1538
-                'event_espresso'
1539
-            );
1540
-            $primary_att                           = EEM_Attendee::instance()->create_default_object();
1541
-        }
1542
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1543
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1544
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1545
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1546
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1547
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1548
-            [
1549
-                'action' => 'edit_attendee',
1550
-                'post'   => $primary_att->ID(),
1551
-            ],
1552
-            REG_ADMIN_URL
1553
-        );
1554
-        // get formatted address for registrant
1555
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1556
-        echo EEH_Template::display_template(
1557
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1558
-            $this->_template_args,
1559
-            true
1560
-        );
1561
-    }
1562
-
1563
-
1564
-    /**
1565
-     * txn_billing_info_side_meta_box
1566
-     *    generates HTML for the Edit Transaction side meta box
1567
-     *
1568
-     * @access public
1569
-     * @return void
1570
-     * @throws DomainException
1571
-     * @throws EE_Error
1572
-     * @throws ReflectionException
1573
-     */
1574
-    public function txn_billing_info_side_meta_box()
1575
-    {
1576
-
1577
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1578
-        $this->_template_args['billing_form_url'] = add_query_arg(
1579
-            ['action' => 'edit_transaction', 'process' => 'billing'],
1580
-            TXN_ADMIN_URL
1581
-        );
1582
-
1583
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     * apply_payments_or_refunds
1590
-     *    registers a payment or refund made towards a transaction
1591
-     *
1592
-     * @access public
1593
-     * @return void
1594
-     * @throws EE_Error
1595
-     * @throws InvalidArgumentException
1596
-     * @throws ReflectionException
1597
-     * @throws RuntimeException
1598
-     * @throws InvalidDataTypeException
1599
-     * @throws InvalidInterfaceException
1600
-     */
1601
-    public function apply_payments_or_refunds()
1602
-    {
1603
-        $json_response_data = ['return_data' => false];
1604
-        $valid_data         = $this->_validate_payment_request_data();
1605
-        $has_access         = EE_Registry::instance()->CAP->current_user_can(
1606
-            'ee_edit_payments',
1607
-            'apply_payment_or_refund_from_registration_details'
1608
-        );
1609
-        if (! empty($valid_data) && $has_access) {
1610
-            $PAY_ID = $valid_data['PAY_ID'];
1611
-            // save  the new payment
1612
-            $payment = $this->_create_payment_from_request_data($valid_data);
1613
-            // get the TXN for this payment
1614
-            $transaction = $payment->transaction();
1615
-            // verify transaction
1616
-            if ($transaction instanceof EE_Transaction) {
1617
-                // calculate_total_payments_and_update_status
1618
-                $this->_process_transaction_payments($transaction);
1619
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
-                // apply payment to registrations (if applicable)
1622
-                if (! empty($REG_IDs)) {
1623
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
-                    $this->_maybe_send_notifications();
1625
-                    // now process status changes for the same registrations
1626
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1627
-                }
1628
-                $this->_maybe_send_notifications($payment);
1629
-                // prepare to render page
1630
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
-                do_action(
1632
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
-                    $transaction,
1634
-                    $payment
1635
-                );
1636
-            } else {
1637
-                EE_Error::add_error(
1638
-                    esc_html__(
1639
-                        'A valid Transaction for this payment could not be retrieved.',
1640
-                        'event_espresso'
1641
-                    ),
1642
-                    __FILE__,
1643
-                    __FUNCTION__,
1644
-                    __LINE__
1645
-                );
1646
-            }
1647
-        } elseif ($has_access) {
1648
-            EE_Error::add_error(
1649
-                esc_html__(
1650
-                    'The payment form data could not be processed. Please try again.',
1651
-                    'event_espresso'
1652
-                ),
1653
-                __FILE__,
1654
-                __FUNCTION__,
1655
-                __LINE__
1656
-            );
1657
-        } else {
1658
-            EE_Error::add_error(
1659
-                esc_html__(
1660
-                    'You do not have access to apply payments or refunds to a registration.',
1661
-                    'event_espresso'
1662
-                ),
1663
-                __FILE__,
1664
-                __FUNCTION__,
1665
-                __LINE__
1666
-            );
1667
-        }
1668
-        $notices              = EE_Error::get_notices(
1669
-            false,
1670
-            false,
1671
-            false
1672
-        );
1673
-        $this->_template_args = [
1674
-            'data'    => $json_response_data,
1675
-            'error'   => $notices['errors'],
1676
-            'success' => $notices['success'],
1677
-        ];
1678
-        $this->_return_json();
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * _validate_payment_request_data
1684
-     *
1685
-     * @return array
1686
-     * @throws EE_Error
1687
-     * @throws InvalidArgumentException
1688
-     * @throws InvalidDataTypeException
1689
-     * @throws InvalidInterfaceException
1690
-     */
1691
-    protected function _validate_payment_request_data()
1692
-    {
1693
-        if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1694
-            return [];
1695
-        }
1696
-        $payment_form = $this->_generate_payment_form_section();
1697
-        try {
1698
-            if ($payment_form->was_submitted()) {
1699
-                $payment_form->receive_form_submission();
1700
-                if (! $payment_form->is_valid()) {
1701
-                    $submission_error_messages = [];
1702
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
-                        if ($validation_error instanceof EE_Validation_Error) {
1704
-                            $form_input = $validation_error->get_form_section();
1705
-                            $submission_error_messages[] = sprintf(
1706
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1707
-                                $form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1708
-                                $validation_error->getMessage()
1709
-                            );
1710
-                        }
1711
-                    }
1712
-                    EE_Error::add_error(
1713
-                        implode('<br />', $submission_error_messages),
1714
-                        __FILE__,
1715
-                        __FUNCTION__,
1716
-                        __LINE__
1717
-                    );
1718
-                    return [];
1719
-                }
1720
-            }
1721
-        } catch (EE_Error $e) {
1722
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1723
-            return [];
1724
-        }
1725
-
1726
-        return $payment_form->valid_data();
1727
-    }
1728
-
1729
-
1730
-    /**
1731
-     * _generate_payment_form_section
1732
-     *
1733
-     * @return EE_Form_Section_Proper
1734
-     * @throws EE_Error
1735
-     */
1736
-    protected function _generate_payment_form_section()
1737
-    {
1738
-        return new EE_Form_Section_Proper(
1739
-            [
1740
-                'name'        => 'txn_admin_payment',
1741
-                'subsections' => [
1742
-                    'PAY_ID'          => new EE_Text_Input(
1743
-                        [
1744
-                            'default'               => 0,
1745
-                            'required'              => false,
1746
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1747
-                            'validation_strategies' => [new EE_Int_Normalization()],
1748
-                        ]
1749
-                    ),
1750
-                    'TXN_ID'          => new EE_Text_Input(
1751
-                        [
1752
-                            'default'               => 0,
1753
-                            'required'              => true,
1754
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1755
-                            'validation_strategies' => [new EE_Int_Normalization()],
1756
-                        ]
1757
-                    ),
1758
-                    'type'            => new EE_Text_Input(
1759
-                        [
1760
-                            'default'               => 1,
1761
-                            'required'              => true,
1762
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1763
-                            'validation_strategies' => [new EE_Int_Normalization()],
1764
-                        ]
1765
-                    ),
1766
-                    'amount'          => new EE_Text_Input(
1767
-                        [
1768
-                            'default'               => 0,
1769
-                            'required'              => true,
1770
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1771
-                            'validation_strategies' => [new EE_Float_Normalization()],
1772
-                        ]
1773
-                    ),
1774
-                    'status'          => new EE_Text_Input(
1775
-                        [
1776
-                            'default'         => EEM_Payment::status_id_approved,
1777
-                            'required'        => true,
1778
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1779
-                        ]
1780
-                    ),
1781
-                    'PMD_ID'          => new EE_Text_Input(
1782
-                        [
1783
-                            'default'               => 2,
1784
-                            'required'              => true,
1785
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1786
-                            'validation_strategies' => [new EE_Int_Normalization()],
1787
-                        ]
1788
-                    ),
1789
-                    'date'            => new EE_Text_Input(
1790
-                        [
1791
-                            'default'         => time(),
1792
-                            'required'        => true,
1793
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1794
-                        ]
1795
-                    ),
1796
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1797
-                        [
1798
-                            'default'               => '',
1799
-                            'required'              => false,
1800
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1801
-                            'validation_strategies' => [
1802
-                                new EE_Max_Length_Validation_Strategy(
1803
-                                    esc_html__('Input too long', 'event_espresso'),
1804
-                                    100
1805
-                                ),
1806
-                            ],
1807
-                        ]
1808
-                    ),
1809
-                    'po_number'       => new EE_Text_Input(
1810
-                        [
1811
-                            'default'               => '',
1812
-                            'required'              => false,
1813
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1814
-                            'validation_strategies' => [
1815
-                                new EE_Max_Length_Validation_Strategy(
1816
-                                    esc_html__('Input too long', 'event_espresso'),
1817
-                                    100
1818
-                                ),
1819
-                            ],
1820
-                        ]
1821
-                    ),
1822
-                    'accounting'      => new EE_Text_Input(
1823
-                        [
1824
-                            'default'               => '',
1825
-                            'required'              => false,
1826
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1827
-                            'validation_strategies' => [
1828
-                                new EE_Max_Length_Validation_Strategy(
1829
-                                    esc_html__('Input too long', 'event_espresso'),
1830
-                                    100
1831
-                                ),
1832
-                            ],
1833
-                        ]
1834
-                    ),
1835
-                ],
1836
-            ]
1837
-        );
1838
-    }
1839
-
1840
-
1841
-    /**
1842
-     * _create_payment_from_request_data
1843
-     *
1844
-     * @param array $valid_data
1845
-     * @return EE_Payment
1846
-     * @throws EE_Error
1847
-     * @throws InvalidArgumentException
1848
-     * @throws InvalidDataTypeException
1849
-     * @throws InvalidInterfaceException
1850
-     * @throws ReflectionException
1851
-     */
1852
-    protected function _create_payment_from_request_data($valid_data)
1853
-    {
1854
-        $PAY_ID = $valid_data['PAY_ID'];
1855
-        // get payment amount
1856
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1857
-        // payments have a type value of 1 and refunds have a type value of -1
1858
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1859
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1860
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1861
-        $date    = $valid_data['date']
1862
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1863
-            : date('Y-m-d g:i a', current_time('timestamp'));
1864
-        $payment = EE_Payment::new_instance(
1865
-            [
1866
-                'TXN_ID'              => $valid_data['TXN_ID'],
1867
-                'STS_ID'              => $valid_data['status'],
1868
-                'PAY_timestamp'       => $date,
1869
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1870
-                'PMD_ID'              => $valid_data['PMD_ID'],
1871
-                'PAY_amount'          => $amount,
1872
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1873
-                'PAY_po_number'       => $valid_data['po_number'],
1874
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1875
-                'PAY_details'         => $valid_data,
1876
-                'PAY_ID'              => $PAY_ID,
1877
-            ],
1878
-            '',
1879
-            ['Y-m-d', 'g:i a']
1880
-        );
1881
-
1882
-        if (! $payment->save()) {
1883
-            EE_Error::add_error(
1884
-                sprintf(
1885
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1886
-                    $payment->ID()
1887
-                ),
1888
-                __FILE__,
1889
-                __FUNCTION__,
1890
-                __LINE__
1891
-            );
1892
-        }
1893
-
1894
-        return $payment;
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * _process_transaction_payments
1900
-     *
1901
-     * @param EE_Transaction $transaction
1902
-     * @return void
1903
-     * @throws EE_Error
1904
-     * @throws InvalidArgumentException
1905
-     * @throws ReflectionException
1906
-     * @throws InvalidDataTypeException
1907
-     * @throws InvalidInterfaceException
1908
-     */
1909
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1910
-    {
1911
-        /** @type EE_Transaction_Payments $transaction_payments */
1912
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1913
-        // update the transaction with this payment
1914
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1915
-            EE_Error::add_success(
1916
-                esc_html__(
1917
-                    'The payment has been processed successfully.',
1918
-                    'event_espresso'
1919
-                ),
1920
-                __FILE__,
1921
-                __FUNCTION__,
1922
-                __LINE__
1923
-            );
1924
-        } else {
1925
-            EE_Error::add_error(
1926
-                esc_html__(
1927
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1928
-                    'event_espresso'
1929
-                ),
1930
-                __FILE__,
1931
-                __FUNCTION__,
1932
-                __LINE__
1933
-            );
1934
-        }
1935
-    }
1936
-
1937
-
1938
-    /**
1939
-     * _get_REG_IDs_to_apply_payment_to
1940
-     * returns a list of registration IDs that the payment will apply to
1941
-     *
1942
-     * @param EE_Payment $payment
1943
-     * @return array
1944
-     * @throws EE_Error
1945
-     * @throws InvalidArgumentException
1946
-     * @throws InvalidDataTypeException
1947
-     * @throws InvalidInterfaceException
1948
-     * @throws ReflectionException
1949
-     */
1950
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1951
-    {
1952
-        // grab array of IDs for specific registrations to apply changes to
1953
-        $REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1954
-        // nothing specified ? then get all reg IDs
1955
-        if (empty($REG_IDs)) {
1956
-            $registrations = $payment->transaction()->registrations();
1957
-            $REG_IDs       = ! empty($registrations)
1958
-                ? array_keys($registrations)
1959
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1960
-        }
1961
-
1962
-        // ensure that REG_IDs are integers and NOT strings
1963
-        return array_map('intval', $REG_IDs);
1964
-    }
1965
-
1966
-
1967
-    /**
1968
-     * @return array
1969
-     */
1970
-    public function existing_reg_payment_REG_IDs()
1971
-    {
1972
-        return $this->_existing_reg_payment_REG_IDs;
1973
-    }
1974
-
1975
-
1976
-    /**
1977
-     * @param array $existing_reg_payment_REG_IDs
1978
-     */
1979
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1980
-    {
1981
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1982
-    }
1983
-
1984
-
1985
-    /**
1986
-     * _get_existing_reg_payment_REG_IDs
1987
-     * returns a list of registration IDs that the payment is currently related to
1988
-     * as recorded in the database
1989
-     *
1990
-     * @param EE_Payment $payment
1991
-     * @return array
1992
-     * @throws EE_Error
1993
-     * @throws InvalidArgumentException
1994
-     * @throws InvalidDataTypeException
1995
-     * @throws InvalidInterfaceException
1996
-     * @throws ReflectionException
1997
-     */
1998
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1999
-    {
2000
-        if ($this->existing_reg_payment_REG_IDs() === null) {
2001
-            // let's get any existing reg payment records for this payment
2002
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2003
-            // but we only want the REG IDs, so grab the array keys
2004
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2005
-                ? array_keys($existing_reg_payment_REG_IDs)
2006
-                : [];
2007
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2008
-        }
2009
-
2010
-        return $this->existing_reg_payment_REG_IDs();
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     * _remove_existing_registration_payments
2016
-     * this calculates the difference between existing relations
2017
-     * to the supplied payment and the new list registration IDs,
2018
-     * removes any related registrations that no longer apply,
2019
-     * and then updates the registration paid fields
2020
-     *
2021
-     * @param EE_Payment $payment
2022
-     * @param int        $PAY_ID
2023
-     * @return bool;
2024
-     * @throws EE_Error
2025
-     * @throws InvalidArgumentException
2026
-     * @throws ReflectionException
2027
-     * @throws InvalidDataTypeException
2028
-     * @throws InvalidInterfaceException
2029
-     */
2030
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2031
-    {
2032
-        // newly created payments will have nothing recorded for $PAY_ID
2033
-        if (absint($PAY_ID) === 0) {
2034
-            return false;
2035
-        }
2036
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2037
-        if (empty($existing_reg_payment_REG_IDs)) {
2038
-            return false;
2039
-        }
2040
-        /** @type EE_Transaction_Payments $transaction_payments */
2041
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2042
-
2043
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2044
-            $payment,
2045
-            [
2046
-                [
2047
-                    'PAY_ID' => $payment->ID(),
2048
-                    'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2049
-                ],
2050
-            ]
2051
-        );
2052
-    }
2053
-
2054
-
2055
-    /**
2056
-     * _update_registration_payments
2057
-     * this applies the payments to the selected registrations
2058
-     * but only if they have not already been paid for
2059
-     *
2060
-     * @param EE_Transaction $transaction
2061
-     * @param EE_Payment     $payment
2062
-     * @param array          $REG_IDs
2063
-     * @return void
2064
-     * @throws EE_Error
2065
-     * @throws InvalidArgumentException
2066
-     * @throws ReflectionException
2067
-     * @throws RuntimeException
2068
-     * @throws InvalidDataTypeException
2069
-     * @throws InvalidInterfaceException
2070
-     */
2071
-    protected function _update_registration_payments(
2072
-        EE_Transaction $transaction,
2073
-        EE_Payment $payment,
2074
-        $REG_IDs = []
2075
-    ) {
2076
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2077
-        // so let's do that using our set of REG_IDs from the form
2078
-        $registration_query_where_params = [
2079
-            'REG_ID' => ['IN', $REG_IDs],
2080
-        ];
2081
-        // but add in some conditions regarding payment,
2082
-        // so that we don't apply payments to registrations that are free or have already been paid for
2083
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2084
-        if (! $payment->is_a_refund()) {
2085
-            $registration_query_where_params['REG_final_price']  = ['!=', 0];
2086
-            $registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2087
-        }
2088
-        $registrations = $transaction->registrations([$registration_query_where_params]);
2089
-        if (! empty($registrations)) {
2090
-            /** @type EE_Payment_Processor $payment_processor */
2091
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2092
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2093
-        }
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * _process_registration_status_change
2099
-     * This processes requested registration status changes for all the registrations
2100
-     * on a given transaction and (optionally) sends out notifications for the changes.
2101
-     *
2102
-     * @param EE_Transaction $transaction
2103
-     * @param array          $REG_IDs
2104
-     * @return bool
2105
-     * @throws EE_Error
2106
-     * @throws InvalidArgumentException
2107
-     * @throws ReflectionException
2108
-     * @throws InvalidDataTypeException
2109
-     * @throws InvalidInterfaceException
2110
-     */
2111
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2112
-    {
2113
-        // first if there is no change in status then we get out.
2114
-        $reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2115
-        if ($reg_status === 'NAN') {
2116
-            // no error message, no change requested, just nothing to do man.
2117
-            return false;
2118
-        }
2119
-        /** @type EE_Transaction_Processor $transaction_processor */
2120
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2121
-
2122
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2123
-        return $transaction_processor->manually_update_registration_statuses(
2124
-            $transaction,
2125
-            $reg_status,
2126
-            [['REG_ID' => ['IN', $REG_IDs]]]
2127
-        );
2128
-    }
2129
-
2130
-
2131
-    /**
2132
-     * _build_payment_json_response
2133
-     *
2134
-     * @access public
2135
-     * @param EE_Payment  $payment
2136
-     * @param array       $REG_IDs
2137
-     * @param bool | null $delete_txn_reg_status_change
2138
-     * @return array
2139
-     * @throws EE_Error
2140
-     * @throws InvalidArgumentException
2141
-     * @throws InvalidDataTypeException
2142
-     * @throws InvalidInterfaceException
2143
-     * @throws ReflectionException
2144
-     */
2145
-    protected function _build_payment_json_response(
2146
-        EE_Payment $payment,
2147
-        $REG_IDs = [],
2148
-        $delete_txn_reg_status_change = null
2149
-    ) {
2150
-        // was the payment deleted ?
2151
-        if (is_bool($delete_txn_reg_status_change)) {
2152
-            return [
2153
-                'PAY_ID'                       => $payment->ID(),
2154
-                'amount'                       => $payment->amount(),
2155
-                'total_paid'                   => $payment->transaction()->paid(),
2156
-                'txn_status'                   => $payment->transaction()->status_ID(),
2157
-                'pay_status'                   => $payment->STS_ID(),
2158
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2159
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2160
-            ];
2161
-        }
2162
-
2163
-        $this->_get_payment_status_array();
2164
-        return [
2165
-            'amount'           => $payment->amount(),
2166
-            'total_paid'       => $payment->transaction()->paid(),
2167
-            'txn_status'       => $payment->transaction()->status_ID(),
2168
-            'pay_status'       => $payment->STS_ID(),
2169
-            'PAY_ID'           => $payment->ID(),
2170
-            'STS_ID'           => $payment->STS_ID(),
2171
-            'status'           => self::$_pay_status[ $payment->STS_ID() ],
2172
-            'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2173
-            'method'           => strtoupper($payment->source()),
2174
-            'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2175
-            'gateway'          => $payment->payment_method()
2176
-                ? $payment->payment_method()->admin_name()
2177
-                : esc_html__('Unknown', 'event_espresso'),
2178
-            'gateway_response' => $payment->gateway_response(),
2179
-            'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2180
-            'po_number'        => $payment->po_number(),
2181
-            'extra_accntng'    => $payment->extra_accntng(),
2182
-            'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2183
-        ];
2184
-    }
2185
-
2186
-
2187
-    /**
2188
-     * delete_payment
2189
-     *    delete a payment or refund made towards a transaction
2190
-     *
2191
-     * @access public
2192
-     * @return void
2193
-     * @throws EE_Error
2194
-     * @throws InvalidArgumentException
2195
-     * @throws ReflectionException
2196
-     * @throws InvalidDataTypeException
2197
-     * @throws InvalidInterfaceException
2198
-     */
2199
-    public function delete_payment()
2200
-    {
2201
-        $json_response_data = ['return_data' => false];
2202
-        $PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2203
-
2204
-        $can_delete         = EE_Registry::instance()->CAP->current_user_can(
2205
-            'ee_delete_payments',
2206
-            'delete_payment_from_registration_details'
2207
-        );
2208
-        if ($PAY_ID && $can_delete) {
2209
-            $delete_txn_reg_status_change = $this->request->getRequestParam(
2210
-                'delete_txn_reg_status_change',
2211
-                false,
2212
-                'bool'
2213
-            );
2214
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2215
-            if ($payment instanceof EE_Payment) {
2216
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2217
-                /** @type EE_Transaction_Payments $transaction_payments */
2218
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2219
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2220
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2221
-                        $payment,
2222
-                        $REG_IDs,
2223
-                        $delete_txn_reg_status_change
2224
-                    );
2225
-                    if ($delete_txn_reg_status_change) {
2226
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2227
-                        // request data because that's how messages will be looking for it.
2228
-                        $this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2229
-                        $this->_maybe_send_notifications();
2230
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2231
-                    }
2232
-                }
2233
-            } else {
2234
-                EE_Error::add_error(
2235
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2236
-                    __FILE__,
2237
-                    __FUNCTION__,
2238
-                    __LINE__
2239
-                );
2240
-            }
2241
-        } elseif ($can_delete) {
2242
-            EE_Error::add_error(
2243
-                esc_html__(
2244
-                    'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2245
-                    'event_espresso'
2246
-                ),
2247
-                __FILE__,
2248
-                __FUNCTION__,
2249
-                __LINE__
2250
-            );
2251
-        } else {
2252
-            EE_Error::add_error(
2253
-                esc_html__(
2254
-                    'You do not have access to delete a payment.',
2255
-                    'event_espresso'
2256
-                ),
2257
-                __FILE__,
2258
-                __FUNCTION__,
2259
-                __LINE__
2260
-            );
2261
-        }
2262
-        $notices              = EE_Error::get_notices(false, false, false);
2263
-        $this->_template_args = [
2264
-            'data'      => $json_response_data,
2265
-            'success'   => $notices['success'],
2266
-            'error'     => $notices['errors'],
2267
-            'attention' => $notices['attention'],
2268
-        ];
2269
-        $this->_return_json();
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * _registration_payment_data_array
2275
-     * adds info for 'owing' and 'paid' for each registration to the json response
2276
-     *
2277
-     * @access protected
2278
-     * @param array $REG_IDs
2279
-     * @return array
2280
-     * @throws EE_Error
2281
-     * @throws InvalidArgumentException
2282
-     * @throws InvalidDataTypeException
2283
-     * @throws InvalidInterfaceException
2284
-     * @throws ReflectionException
2285
-     */
2286
-    protected function _registration_payment_data_array($REG_IDs)
2287
-    {
2288
-        $registration_payment_data = [];
2289
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2290
-        if (! empty($REG_IDs)) {
2291
-            $registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2292
-            foreach ($registrations as $registration) {
2293
-                if ($registration instanceof EE_Registration) {
2294
-                    $registration_payment_data[ $registration->ID() ] = [
2295
-                        'paid'  => $registration->pretty_paid(),
2296
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2297
-                    ];
2298
-                }
2299
-            }
2300
-        }
2301
-
2302
-        return $registration_payment_data;
2303
-    }
2304
-
2305
-
2306
-    /**
2307
-     * _maybe_send_notifications
2308
-     * determines whether or not the admin has indicated that notifications should be sent.
2309
-     * If so, will toggle a filter switch for delivering registration notices.
2310
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2311
-     *
2312
-     * @access protected
2313
-     * @param EE_Payment | null $payment
2314
-     */
2315
-    protected function _maybe_send_notifications($payment = null)
2316
-    {
2317
-        switch ($payment instanceof EE_Payment) {
2318
-            // payment notifications
2319
-            case true:
2320
-                if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2321
-                    $this->_process_payment_notification($payment);
2322
-                }
2323
-                break;
2324
-            // registration notifications
2325
-            case false:
2326
-                if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2327
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2328
-                }
2329
-                break;
2330
-        }
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * _send_payment_reminder
2336
-     *    generates HTML for the View Transaction Details Admin page
2337
-     *
2338
-     * @access protected
2339
-     * @return void
2340
-     * @throws EE_Error
2341
-     * @throws InvalidArgumentException
2342
-     * @throws InvalidDataTypeException
2343
-     * @throws InvalidInterfaceException
2344
-     */
2345
-    protected function _send_payment_reminder()
2346
-    {
2347
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2348
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2349
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2350
-        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2351
-        do_action(
2352
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2353
-            $transaction
2354
-        );
2355
-        $this->_redirect_after_action(
2356
-            false,
2357
-            esc_html__('payment reminder', 'event_espresso'),
2358
-            esc_html__('sent', 'event_espresso'),
2359
-            $query_args,
2360
-            true
2361
-        );
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     *  get_transactions
2367
-     *    get transactions for given parameters (used by list table)
2368
-     *
2369
-     * @param int     $per_page how many transactions displayed per page
2370
-     * @param boolean $count   return the count or objects
2371
-     * @param string  $view
2372
-     * @return EE_Transaction[]|int int = count || array of transaction objects
2373
-     * @throws EE_Error
2374
-     * @throws InvalidArgumentException
2375
-     * @throws InvalidDataTypeException
2376
-     * @throws InvalidInterfaceException
2377
-     */
2378
-    public function get_transactions($per_page, $count = false, $view = '')
2379
-    {
2380
-        $start_date = wp_strip_all_tags(
2381
-            $this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2382
-        );
2383
-        $end_date = wp_strip_all_tags(
2384
-            $this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2385
-        );
2386
-
2387
-        // make sure our timestamps start and end right at the boundaries for each day
2388
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2389
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2390
-
2391
-
2392
-        // convert to timestamps
2393
-        $start_date = strtotime($start_date);
2394
-        $end_date   = strtotime($end_date);
2395
-
2396
-        // makes sure start date is the lowest value and vice versa
2397
-        $start_date = min($start_date, $end_date);
2398
-        $end_date   = max($start_date, $end_date);
2399
-
2400
-        // convert to correct format for query
2401
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2402
-            'TXN_timestamp',
2403
-            date('Y-m-d H:i:s', $start_date),
2404
-            'Y-m-d H:i:s'
2405
-        );
2406
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2407
-            'TXN_timestamp',
2408
-            date('Y-m-d H:i:s', $end_date),
2409
-            'Y-m-d H:i:s'
2410
-        );
2411
-
2412
-
2413
-        // set orderby
2414
-        $orderby = $this->request->getRequestParam('orderby');
2415
-
2416
-        switch ($orderby) {
2417
-            case '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         = $this->request->getRequestParam('order', 'DESC');
2430
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
2431
-
2432
-        $per_page = absint($per_page) ? $per_page : 10;
2433
-        $per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2434
-
2435
-        $offset = ($current_page - 1) * $per_page;
2436
-        $limit  = [$offset, $per_page];
2437
-
2438
-        $_where = [
2439
-            'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2440
-            'Registration.REG_count' => 1,
2441
-        ];
2442
-
2443
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2444
-        if ($EVT_ID) {
2445
-            $_where['Registration.EVT_ID'] = $EVT_ID;
2446
-        }
2447
-
2448
-        $search_term = $this->request->getRequestParam('s');
2449
-        if ($search_term) {
2450
-            $search_term = '%' . $search_term . '%';
2451
-            $_where['OR']  = [
2452
-                'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2453
-                'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2454
-                'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2455
-                'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2456
-                'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2457
-                'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2458
-                'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2459
-                'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2460
-                'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2461
-                'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2462
-                'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2463
-                'Registration.REG_final_price'        => ['LIKE', $search_term],
2464
-                'Registration.REG_code'               => ['LIKE', $search_term],
2465
-                'Registration.REG_count'              => ['LIKE', $search_term],
2466
-                'Registration.REG_group_size'         => ['LIKE', $search_term],
2467
-                'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2468
-                'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2469
-                'Payment.PAY_source'                  => ['LIKE', $search_term],
2470
-                'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2471
-                'TXN_session_data'                    => ['LIKE', $search_term],
2472
-                'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2473
-            ];
2474
-        }
2475
-
2476
-        $status = $this->request->getRequestParam('status');
2477
-        // failed transactions
2478
-        $failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
-        $abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
-        $incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2481
-
2482
-        if ($failed) {
2483
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2484
-        } elseif ($abandoned) {
2485
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2486
-        } elseif ($incomplete) {
2487
-            $_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2488
-        } else {
2489
-            $_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2490
-            $_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2491
-        }
2492
-
2493
-        $query_params = apply_filters(
2494
-            'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2495
-            [
2496
-                $_where,
2497
-                'order_by'                 => [$orderby => $sort],
2498
-                'limit'                    => $limit,
2499
-                'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2500
-            ],
2501
-            $this->request->requestParams(),
2502
-            $view,
2503
-            $count
2504
-        );
2505
-
2506
-        return $count
2507
-            ? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2508
-            : EEM_Transaction::instance()->get_all($query_params);
2509
-    }
2510
-
2511
-
2512
-    /**
2513
-     * @throws EE_Error
2514
-     * @throws InvalidArgumentException
2515
-     * @throws InvalidDataTypeException
2516
-     * @throws InvalidInterfaceException
2517
-     * @throws ReflectionException
2518
-     * @throws RuntimeException
2519
-     * @since 4.9.79.p
2520
-     */
2521
-    public function recalculateLineItems()
2522
-    {
2523
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2524
-        /** @var EE_Transaction $transaction */
2525
-        $transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2526
-        $success         = $transaction->recalculateLineItems();
2527
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2528
-        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2529
-        $this->_redirect_after_action(
2530
-            $success,
2531
-            esc_html__('Transaction taxes and totals', 'event_espresso'),
2532
-            esc_html__('recalculated', 'event_espresso'),
2533
-            $query_args,
2534
-            true
2535
-        );
2536
-    }
16
+	/**
17
+	 * @var EE_Transaction
18
+	 */
19
+	private $_transaction;
20
+
21
+	/**
22
+	 * @var EE_Session
23
+	 */
24
+	private $_session;
25
+
26
+	/**
27
+	 * @var array $_txn_status
28
+	 */
29
+	private static $_txn_status;
30
+
31
+	/**
32
+	 * @var array $_pay_status
33
+	 */
34
+	private static $_pay_status;
35
+
36
+	/**
37
+	 * @var array $_existing_reg_payment_REG_IDs
38
+	 */
39
+	protected $_existing_reg_payment_REG_IDs;
40
+
41
+
42
+	/**
43
+	 *    _init_page_props
44
+	 *
45
+	 * @return void
46
+	 */
47
+	protected function _init_page_props()
48
+	{
49
+		$this->page_slug        = TXN_PG_SLUG;
50
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
51
+		$this->_admin_base_url  = TXN_ADMIN_URL;
52
+		$this->_admin_base_path = TXN_ADMIN;
53
+	}
54
+
55
+
56
+	/**
57
+	 *    _ajax_hooks
58
+	 *
59
+	 * @return void
60
+	 */
61
+	protected function _ajax_hooks()
62
+	{
63
+		add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
+		add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
+		add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
+	}
67
+
68
+
69
+	/**
70
+	 *    _define_page_props
71
+	 *
72
+	 * @return void
73
+	 */
74
+	protected function _define_page_props()
75
+	{
76
+		$this->_admin_page_title = $this->page_label;
77
+		$this->_labels           = [
78
+			'buttons' => [
79
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
+			],
83
+		];
84
+	}
85
+
86
+
87
+	/**
88
+	 *        grab url requests and route them
89
+	 *
90
+	 * @access private
91
+	 * @return void
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function _set_page_routes()
98
+	{
99
+
100
+		$this->_set_transaction_status_array();
101
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
+
103
+		$this->_page_routes = [
104
+
105
+			'default' => [
106
+				'func'       => '_transactions_overview_list_table',
107
+				'capability' => 'ee_read_transactions',
108
+			],
109
+
110
+			'view_transaction' => [
111
+				'func'       => '_transaction_details',
112
+				'capability' => 'ee_read_transaction',
113
+				'obj_id'     => $TXN_ID,
114
+			],
115
+
116
+			'send_payment_reminder' => [
117
+				'func'       => '_send_payment_reminder',
118
+				'noheader'   => true,
119
+				'capability' => 'ee_send_message',
120
+			],
121
+
122
+			'espresso_apply_payment' => [
123
+				'func'       => 'apply_payments_or_refunds',
124
+				'noheader'   => true,
125
+				'capability' => 'ee_edit_payments',
126
+			],
127
+
128
+			'espresso_apply_refund' => [
129
+				'func'       => 'apply_payments_or_refunds',
130
+				'noheader'   => true,
131
+				'capability' => 'ee_edit_payments',
132
+			],
133
+
134
+			'espresso_delete_payment' => [
135
+				'func'       => 'delete_payment',
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_payments',
138
+			],
139
+
140
+			'espresso_recalculate_line_items' => [
141
+				'func'       => 'recalculateLineItems',
142
+				'noheader'   => true,
143
+				'capability' => 'ee_edit_payments',
144
+			],
145
+
146
+		];
147
+	}
148
+
149
+
150
+	protected function _set_page_config()
151
+	{
152
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
+		$this->_page_config = [
154
+			'default'          => [
155
+				'nav'           => [
156
+					'label' => esc_html__('Overview', 'event_espresso'),
157
+					'order' => 10,
158
+				],
159
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
160
+				'help_tabs'     => [
161
+					'transactions_overview_help_tab'                       => [
162
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
+						'filename' => 'transactions_overview',
164
+					],
165
+					'transactions_overview_table_column_headings_help_tab' => [
166
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
+						'filename' => 'transactions_overview_table_column_headings',
168
+					],
169
+					'transactions_overview_views_filters_help_tab'         => [
170
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
+						'filename' => 'transactions_overview_views_filters_search',
172
+					],
173
+				],
174
+				/**
175
+				 * commented out because currently we are not displaying tips for transaction list table status but this
176
+				 * may change in a later iteration so want to keep the code for then.
177
+				 */
178
+				// 'qtips' => array( 'Transactions_List_Table_Tips' ),
179
+				'require_nonce' => false,
180
+			],
181
+			'view_transaction' => [
182
+				'nav'       => [
183
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
184
+					'order'      => 5,
185
+					'url'        => $TXN_ID
186
+						? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
187
+						: $this->_admin_base_url,
188
+					'persistent' => false,
189
+				],
190
+				'help_tabs' => [
191
+					'transactions_view_transaction_help_tab'                                              => [
192
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
193
+						'filename' => 'transactions_view_transaction',
194
+					],
195
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => [
196
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
197
+						'filename' => 'transactions_view_transaction_transaction_details_table',
198
+					],
199
+					'transactions_view_transaction_attendees_registered_help_tab'                         => [
200
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
201
+						'filename' => 'transactions_view_transaction_attendees_registered',
202
+					],
203
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
204
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
205
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
206
+					],
207
+				],
208
+				'qtips'     => ['Transaction_Details_Tips'],
209
+				'metaboxes' => ['_transaction_details_metaboxes'],
210
+
211
+				'require_nonce' => false,
212
+			],
213
+		];
214
+	}
215
+
216
+
217
+	/**
218
+	 * The below methods aren't used by this class currently
219
+	 */
220
+	protected function _add_screen_options()
221
+	{
222
+		// noop
223
+	}
224
+
225
+
226
+	protected function _add_feature_pointers()
227
+	{
228
+		// noop
229
+	}
230
+
231
+
232
+	public function admin_init()
233
+	{
234
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
235
+		$event_name = $this->request->getRequestParam('event_name');
236
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
237
+		// IF a registration was JUST added via the admin...
238
+		if ($EVT_ID && $event_name && $redirect_from) {
239
+			// then set a cookie so that we can block any attempts to use
240
+			// the back button as a way to enter another registration.
241
+			setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
242
+			// and update the global
243
+			$_COOKIE['ee_registration_added'] = $EVT_ID;
244
+		}
245
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
246
+			'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.',
247
+			'event_espresso'
248
+		);
249
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
250
+			'An error occurred! Please refresh the page and try again.',
251
+			'event_espresso'
252
+		);
253
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
254
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
255
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
256
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
257
+			'This transaction has been overpaid ! Payments Total',
258
+			'event_espresso'
259
+		);
260
+	}
261
+
262
+
263
+	public function admin_notices()
264
+	{
265
+		// noop
266
+	}
267
+
268
+
269
+	public function admin_footer_scripts()
270
+	{
271
+		// noop
272
+	}
273
+
274
+
275
+	/**
276
+	 * _set_transaction_status_array
277
+	 * sets list of transaction statuses
278
+	 *
279
+	 * @access private
280
+	 * @return void
281
+	 * @throws EE_Error
282
+	 * @throws InvalidArgumentException
283
+	 * @throws InvalidDataTypeException
284
+	 * @throws InvalidInterfaceException
285
+	 */
286
+	private function _set_transaction_status_array()
287
+	{
288
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
289
+	}
290
+
291
+
292
+	/**
293
+	 * get_transaction_status_array
294
+	 * return the transaction status array for wp_list_table
295
+	 *
296
+	 * @access public
297
+	 * @return array
298
+	 */
299
+	public function get_transaction_status_array()
300
+	{
301
+		return self::$_txn_status;
302
+	}
303
+
304
+
305
+	/**
306
+	 *    get list of payment statuses
307
+	 *
308
+	 * @access private
309
+	 * @return void
310
+	 * @throws EE_Error
311
+	 * @throws InvalidArgumentException
312
+	 * @throws InvalidDataTypeException
313
+	 * @throws InvalidInterfaceException
314
+	 */
315
+	private function _get_payment_status_array()
316
+	{
317
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
318
+		$this->_template_args['payment_status'] = self::$_pay_status;
319
+	}
320
+
321
+
322
+	/**
323
+	 *    _add_screen_options_default
324
+	 *
325
+	 * @access protected
326
+	 * @return void
327
+	 * @throws InvalidArgumentException
328
+	 * @throws InvalidDataTypeException
329
+	 * @throws InvalidInterfaceException
330
+	 */
331
+	protected function _add_screen_options_default()
332
+	{
333
+		$this->_per_page_screen_option();
334
+	}
335
+
336
+
337
+	/**
338
+	 * load_scripts_styles
339
+	 *
340
+	 * @access public
341
+	 * @return void
342
+	 */
343
+	public function load_scripts_styles()
344
+	{
345
+		// enqueue style
346
+		wp_register_style(
347
+			'espresso_txn',
348
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
349
+			[],
350
+			EVENT_ESPRESSO_VERSION
351
+		);
352
+		wp_enqueue_style('espresso_txn');
353
+		// scripts
354
+		wp_register_script(
355
+			'espresso_txn',
356
+			TXN_ASSETS_URL . 'espresso_transactions_admin.js',
357
+			[
358
+				'ee_admin_js',
359
+				'ee-datepicker',
360
+				'jquery-ui-datepicker',
361
+				'jquery-ui-draggable',
362
+				'ee-dialog',
363
+				'ee-accounting',
364
+				'ee-serialize-full-array',
365
+			],
366
+			EVENT_ESPRESSO_VERSION,
367
+			true
368
+		);
369
+		wp_enqueue_script('espresso_txn');
370
+	}
371
+
372
+
373
+	/**
374
+	 *    load_scripts_styles_view_transaction
375
+	 *
376
+	 * @access public
377
+	 * @return void
378
+	 */
379
+	public function load_scripts_styles_view_transaction()
380
+	{
381
+		// styles
382
+		wp_enqueue_style('espresso-ui-theme');
383
+	}
384
+
385
+
386
+	/**
387
+	 *    load_scripts_styles_default
388
+	 *
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	public function load_scripts_styles_default()
393
+	{
394
+		// styles
395
+		wp_enqueue_style('espresso-ui-theme');
396
+	}
397
+
398
+
399
+	/**
400
+	 *    _set_list_table_views_default
401
+	 *
402
+	 * @access protected
403
+	 * @return void
404
+	 */
405
+	protected function _set_list_table_views_default()
406
+	{
407
+		$this->_views = [
408
+			'all'        => [
409
+				'slug'  => 'all',
410
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
411
+				'count' => 0,
412
+			],
413
+			'abandoned'  => [
414
+				'slug'  => 'abandoned',
415
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
416
+				'count' => 0,
417
+			],
418
+			'incomplete' => [
419
+				'slug'  => 'incomplete',
420
+				'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
421
+				'count' => 0,
422
+			],
423
+		];
424
+		if (
425
+			/**
426
+			 * Filters whether a link to the "Failed Transactions" list table
427
+			 * appears on the Transactions Admin Page list table.
428
+			 * List display can be turned back on via the following:
429
+			 * add_filter(
430
+			 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
431
+			 *     '__return_true'
432
+			 * );
433
+			 *
434
+			 * @param boolean                 $display_failed_txns_list
435
+			 * @param Transactions_Admin_Page $this
436
+			 * @since 4.9.70.p
437
+			 */
438
+			apply_filters(
439
+				'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
440
+				false,
441
+				$this
442
+			)
443
+		) {
444
+			$this->_views['failed'] = [
445
+				'slug'  => 'failed',
446
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
447
+				'count' => 0,
448
+			];
449
+		}
450
+	}
451
+
452
+
453
+	/**
454
+	 * _set_transaction_object
455
+	 * This sets the _transaction property for the transaction details screen
456
+	 *
457
+	 * @access private
458
+	 * @return void
459
+	 * @throws EE_Error
460
+	 * @throws InvalidArgumentException
461
+	 * @throws RuntimeException
462
+	 * @throws InvalidDataTypeException
463
+	 * @throws InvalidInterfaceException
464
+	 * @throws ReflectionException
465
+	 */
466
+	private function _set_transaction_object()
467
+	{
468
+		if ($this->_transaction instanceof EE_Transaction) {
469
+			return;
470
+		} //get out we've already set the object
471
+
472
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
473
+
474
+		// get transaction object
475
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
476
+		$this->_session     = $this->_transaction instanceof EE_Transaction
477
+			? $this->_transaction->session_data()
478
+			: null;
479
+		if ($this->_transaction instanceof EE_Transaction) {
480
+			$this->_transaction->verify_abandoned_transaction_status();
481
+		}
482
+
483
+		if (! $this->_transaction instanceof EE_Transaction) {
484
+			$error_msg = sprintf(
485
+				esc_html__(
486
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
487
+					'event_espresso'
488
+				),
489
+				$TXN_ID
490
+			);
491
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
492
+		}
493
+	}
494
+
495
+
496
+	/**
497
+	 *    _transaction_legend_items
498
+	 *
499
+	 * @access protected
500
+	 * @return array
501
+	 * @throws EE_Error
502
+	 * @throws InvalidArgumentException
503
+	 * @throws ReflectionException
504
+	 * @throws InvalidDataTypeException
505
+	 * @throws InvalidInterfaceException
506
+	 */
507
+	protected function _transaction_legend_items()
508
+	{
509
+		EE_Registry::instance()->load_helper('MSG_Template');
510
+		$items = [];
511
+
512
+		if (
513
+			EE_Registry::instance()->CAP->current_user_can(
514
+				'ee_read_global_messages',
515
+				'view_filtered_messages'
516
+			)
517
+		) {
518
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
519
+			if (
520
+				is_array($related_for_icon)
521
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
522
+			) {
523
+				$items['view_related_messages'] = [
524
+					'class' => $related_for_icon['css_class'],
525
+					'desc'  => $related_for_icon['label'],
526
+				];
527
+			}
528
+		}
529
+
530
+		$items = apply_filters(
531
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
532
+			array_merge(
533
+				$items,
534
+				[
535
+					'view_details'          => [
536
+						'class' => 'dashicons dashicons-cart',
537
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
538
+					],
539
+					'view_invoice'          => [
540
+						'class' => 'dashicons dashicons-media-spreadsheet',
541
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
542
+					],
543
+					'view_receipt'          => [
544
+						'class' => 'dashicons dashicons-media-default',
545
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
546
+					],
547
+					'view_registration'     => [
548
+						'class' => 'dashicons dashicons-clipboard',
549
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
550
+					],
551
+					'payment_overview_link' => [
552
+						'class' => 'dashicons dashicons-money',
553
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
554
+					],
555
+				]
556
+			)
557
+		);
558
+
559
+		if (
560
+			EEH_MSG_Template::is_mt_active('payment_reminder')
561
+			&& EE_Registry::instance()->CAP->current_user_can(
562
+				'ee_send_message',
563
+				'espresso_transactions_send_payment_reminder'
564
+			)
565
+		) {
566
+			$items['send_payment_reminder'] = [
567
+				'class' => 'dashicons dashicons-email-alt',
568
+				'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
569
+			];
570
+		} else {
571
+			$items['blank*'] = [
572
+				'class' => '',
573
+				'desc'  => '',
574
+			];
575
+		}
576
+		$more_items = apply_filters(
577
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
578
+			[
579
+				'overpaid'   => [
580
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
581
+					'desc'  => EEH_Template::pretty_status(
582
+						EEM_Transaction::overpaid_status_code,
583
+						false,
584
+						'sentence'
585
+					),
586
+				],
587
+				'complete'   => [
588
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
589
+					'desc'  => EEH_Template::pretty_status(
590
+						EEM_Transaction::complete_status_code,
591
+						false,
592
+						'sentence'
593
+					),
594
+				],
595
+				'incomplete' => [
596
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
597
+					'desc'  => EEH_Template::pretty_status(
598
+						EEM_Transaction::incomplete_status_code,
599
+						false,
600
+						'sentence'
601
+					),
602
+				],
603
+				'abandoned'  => [
604
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
605
+					'desc'  => EEH_Template::pretty_status(
606
+						EEM_Transaction::abandoned_status_code,
607
+						false,
608
+						'sentence'
609
+					),
610
+				],
611
+				'failed'     => [
612
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
613
+					'desc'  => EEH_Template::pretty_status(
614
+						EEM_Transaction::failed_status_code,
615
+						false,
616
+						'sentence'
617
+					),
618
+				],
619
+			]
620
+		);
621
+
622
+		return array_merge($items, $more_items);
623
+	}
624
+
625
+
626
+	/**
627
+	 *    _transactions_overview_list_table
628
+	 *
629
+	 * @access protected
630
+	 * @return void
631
+	 * @throws DomainException
632
+	 * @throws EE_Error
633
+	 * @throws InvalidArgumentException
634
+	 * @throws InvalidDataTypeException
635
+	 * @throws InvalidInterfaceException
636
+	 * @throws ReflectionException
637
+	 */
638
+	protected function _transactions_overview_list_table()
639
+	{
640
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
641
+
642
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
643
+		$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
644
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
645
+			? sprintf(
646
+				esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
647
+				'<h3>',
648
+				'<a href="'
649
+				. EE_Admin_Page::add_query_args_and_nonce(
650
+					['action' => 'edit', 'post' => $event->ID()],
651
+					EVENTS_ADMIN_URL
652
+				)
653
+				. '" title="'
654
+				. esc_attr__('Click to Edit event', 'event_espresso')
655
+				. '">' . $event->name() . '</a>',
656
+				'</h3>'
657
+			)
658
+			: '';
659
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
660
+		$this->display_admin_list_table_page_with_no_sidebar();
661
+	}
662
+
663
+
664
+	/**
665
+	 *    _transaction_details
666
+	 * generates HTML for the View Transaction Details Admin page
667
+	 *
668
+	 * @access protected
669
+	 * @return void
670
+	 * @throws DomainException
671
+	 * @throws EE_Error
672
+	 * @throws InvalidArgumentException
673
+	 * @throws InvalidDataTypeException
674
+	 * @throws InvalidInterfaceException
675
+	 * @throws RuntimeException
676
+	 * @throws ReflectionException
677
+	 */
678
+	protected function _transaction_details()
679
+	{
680
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
681
+
682
+		$this->_set_transaction_status_array();
683
+
684
+		$this->_template_args                      = [];
685
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
686
+
687
+		$this->_set_transaction_object();
688
+
689
+		if (! $this->_transaction instanceof EE_Transaction) {
690
+			return;
691
+		}
692
+
693
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
694
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
695
+
696
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
697
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
698
+
699
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
700
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
701
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
702
+
703
+		$this->_template_args['grand_total'] = $this->_transaction->total();
704
+		$this->_template_args['total_paid']  = $this->_transaction->paid();
705
+
706
+		$amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
707
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
708
+			$amount_due,
709
+			true
710
+		);
711
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
712
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
713
+												  . $this->_template_args['amount_due'];
714
+		} else {
715
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
716
+		}
717
+		$this->_template_args['amount_due_class'] = '';
718
+
719
+		if ($this->_transaction->paid() === $this->_transaction->total()) {
720
+			// paid in full
721
+			$this->_template_args['amount_due'] = false;
722
+		} elseif ($this->_transaction->paid() > $this->_transaction->total()) {
723
+			// overpaid
724
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
725
+		} elseif ($this->_transaction->total() > (float) 0) {
726
+			if ($this->_transaction->paid() > (float) 0) {
727
+				// monies owing
728
+				$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
729
+			} elseif ($this->_transaction->paid() === (float) 0) {
730
+				// no payments made yet
731
+				$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
732
+			}
733
+		} elseif ($this->_transaction->total() === (float) 0) {
734
+			// free event
735
+			$this->_template_args['amount_due'] = false;
736
+		}
737
+
738
+		$payment_method = $this->_transaction->payment_method();
739
+
740
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
741
+			? $payment_method->admin_name()
742
+			: esc_html__('Unknown', 'event_espresso');
743
+
744
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
745
+		// link back to overview
746
+		$this->_template_args['txn_overview_url'] = $this->request->getServerParam(
747
+			'HTTP_REFERER',
748
+			TXN_ADMIN_URL
749
+		);
750
+
751
+
752
+		// next link
753
+		$next_txn                                 = $this->_transaction->next(
754
+			null,
755
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
756
+			'TXN_ID'
757
+		);
758
+		$this->_template_args['next_transaction'] = $next_txn
759
+			? $this->_next_link(
760
+				EE_Admin_Page::add_query_args_and_nonce(
761
+					['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
762
+					TXN_ADMIN_URL
763
+				),
764
+				'dashicons dashicons-arrow-right ee-icon-size-22'
765
+			)
766
+			: '';
767
+		// previous link
768
+		$previous_txn                                 = $this->_transaction->previous(
769
+			null,
770
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
771
+			'TXN_ID'
772
+		);
773
+		$this->_template_args['previous_transaction'] = $previous_txn
774
+			? $this->_previous_link(
775
+				EE_Admin_Page::add_query_args_and_nonce(
776
+					['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
777
+					TXN_ADMIN_URL
778
+				),
779
+				'dashicons dashicons-arrow-left ee-icon-size-22'
780
+			)
781
+			: '';
782
+
783
+		$EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
784
+		$event_name    = $this->request->getRequestParam('event_name');
785
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
786
+
787
+		// were we just redirected here after adding a new registration ???
788
+		if ($EVT_ID && $event_name && $redirect_from) {
789
+			if (
790
+				EE_Registry::instance()->CAP->current_user_can(
791
+					'ee_edit_registrations',
792
+					'espresso_registrations_new_registration',
793
+					$EVT_ID
794
+				)
795
+			) {
796
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
797
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
798
+					[
799
+						'page'     => 'espresso_registrations',
800
+						'action'   => 'new_registration',
801
+						'return'   => 'default',
802
+						'TXN_ID'   => $this->_transaction->ID(),
803
+						'event_id' => $EVT_ID,
804
+					],
805
+					REG_ADMIN_URL
806
+				);
807
+				$this->_admin_page_title .= '">';
808
+
809
+				$this->_admin_page_title .= sprintf(
810
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
811
+					htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
812
+				);
813
+				$this->_admin_page_title .= '</a>';
814
+			}
815
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
816
+		}
817
+		// grab messages at the last second
818
+		$this->_template_args['notices'] = EE_Error::get_notices();
819
+		// path to template
820
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
821
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
822
+			$template_path,
823
+			$this->_template_args,
824
+			true
825
+		);
826
+
827
+		// the details template wrapper
828
+		$this->display_admin_page_with_sidebar();
829
+	}
830
+
831
+
832
+	/**
833
+	 *        _transaction_details_metaboxes
834
+	 *
835
+	 * @access protected
836
+	 * @return void
837
+	 * @throws EE_Error
838
+	 * @throws InvalidArgumentException
839
+	 * @throws InvalidDataTypeException
840
+	 * @throws InvalidInterfaceException
841
+	 * @throws RuntimeException
842
+	 * @throws ReflectionException
843
+	 */
844
+	protected function _transaction_details_metaboxes()
845
+	{
846
+
847
+		$this->_set_transaction_object();
848
+
849
+		if (! $this->_transaction instanceof EE_Transaction) {
850
+			return;
851
+		}
852
+		add_meta_box(
853
+			'edit-txn-details-mbox',
854
+			esc_html__('Transaction Details', 'event_espresso'),
855
+			[$this, 'txn_details_meta_box'],
856
+			$this->_wp_page_slug,
857
+			'normal',
858
+			'high'
859
+		);
860
+		add_meta_box(
861
+			'edit-txn-attendees-mbox',
862
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
863
+			[$this, 'txn_attendees_meta_box'],
864
+			$this->_wp_page_slug,
865
+			'normal',
866
+			'high',
867
+			['TXN_ID' => $this->_transaction->ID()]
868
+		);
869
+		add_meta_box(
870
+			'edit-txn-registrant-mbox',
871
+			esc_html__('Primary Contact', 'event_espresso'),
872
+			[$this, 'txn_registrant_side_meta_box'],
873
+			$this->_wp_page_slug,
874
+			'side',
875
+			'high'
876
+		);
877
+		add_meta_box(
878
+			'edit-txn-billing-info-mbox',
879
+			esc_html__('Billing Information', 'event_espresso'),
880
+			[$this, 'txn_billing_info_side_meta_box'],
881
+			$this->_wp_page_slug,
882
+			'side',
883
+			'high'
884
+		);
885
+	}
886
+
887
+
888
+	/**
889
+	 * Callback for transaction actions metabox.
890
+	 *
891
+	 * @param EE_Transaction|null $transaction
892
+	 * @return string
893
+	 * @throws DomainException
894
+	 * @throws EE_Error
895
+	 * @throws InvalidArgumentException
896
+	 * @throws InvalidDataTypeException
897
+	 * @throws InvalidInterfaceException
898
+	 * @throws ReflectionException
899
+	 * @throws RuntimeException
900
+	 */
901
+	public function getActionButtons(EE_Transaction $transaction = null)
902
+	{
903
+		$content = '';
904
+		$actions = [];
905
+		if (! $transaction instanceof EE_Transaction) {
906
+			return $content;
907
+		}
908
+		/** @var EE_Registration $primary_registration */
909
+		$primary_registration = $transaction->primary_registration();
910
+		$attendee             = $primary_registration instanceof EE_Registration
911
+			? $primary_registration->attendee()
912
+			: null;
913
+
914
+		if (
915
+			$attendee instanceof EE_Attendee
916
+			&& EE_Registry::instance()->CAP->current_user_can(
917
+				'ee_send_message',
918
+				'espresso_transactions_send_payment_reminder'
919
+			)
920
+		) {
921
+			$actions['payment_reminder'] =
922
+				EEH_MSG_Template::is_mt_active('payment_reminder')
923
+				&& $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
924
+				&& $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
925
+					? EEH_Template::get_button_or_link(
926
+						EE_Admin_Page::add_query_args_and_nonce(
927
+							[
928
+							'action'      => 'send_payment_reminder',
929
+							'TXN_ID'      => $this->_transaction->ID(),
930
+							'redirect_to' => 'view_transaction',
931
+							],
932
+							TXN_ADMIN_URL
933
+						),
934
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
935
+						'button secondary-button',
936
+						'dashicons dashicons-email-alt'
937
+					)
938
+					: '';
939
+		}
940
+
941
+		if (
942
+			EE_Registry::instance()->CAP->current_user_can(
943
+				'ee_edit_payments',
944
+				'espresso_transactions_recalculate_line_items'
945
+			)
946
+		) {
947
+			$actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
948
+				EE_Admin_Page::add_query_args_and_nonce(
949
+					[
950
+						'action'      => 'espresso_recalculate_line_items',
951
+						'TXN_ID'      => $this->_transaction->ID(),
952
+						'redirect_to' => 'view_transaction',
953
+					],
954
+					TXN_ADMIN_URL
955
+				),
956
+				esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
957
+				'button secondary-button',
958
+				'dashicons dashicons-update'
959
+			);
960
+		}
961
+
962
+		if (
963
+			$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 (
975
+			$primary_registration instanceof EE_Registration
976
+			&& EEH_MSG_Template::is_mt_active('invoice')
977
+		) {
978
+			$actions['invoice'] = EEH_Template::get_button_or_link(
979
+				$primary_registration->invoice_url(),
980
+				esc_html__('View Invoice', 'event_espresso'),
981
+				'button secondary-button',
982
+				'dashicons dashicons-media-spreadsheet'
983
+			);
984
+		}
985
+		$actions = array_filter(
986
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
987
+		);
988
+		if ($actions) {
989
+			$content = '<ul>';
990
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
991
+			$content .= '</uL>';
992
+		}
993
+		return $content;
994
+	}
995
+
996
+
997
+	/**
998
+	 * txn_details_meta_box
999
+	 * generates HTML for the Transaction main meta box
1000
+	 *
1001
+	 * @return void
1002
+	 * @throws DomainException
1003
+	 * @throws EE_Error
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws RuntimeException
1008
+	 * @throws ReflectionException
1009
+	 */
1010
+	public function txn_details_meta_box()
1011
+	{
1012
+		$this->_set_transaction_object();
1013
+		$this->_template_args['TXN_ID']              = $this->_transaction->ID();
1014
+		$this->_template_args['attendee']            =
1015
+			$this->_transaction->primary_registration() instanceof EE_Registration
1016
+				? $this->_transaction->primary_registration()->attendee()
1017
+				: null;
1018
+		$this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1019
+			'ee_edit_payments',
1020
+			'apply_payment_or_refund_from_registration_details'
1021
+		);
1022
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1023
+			'ee_delete_payments',
1024
+			'delete_payment_from_registration_details'
1025
+		);
1026
+
1027
+		// get line table
1028
+		EEH_Autoloader::register_line_item_display_autoloaders();
1029
+		$Line_Item_Display                       = new EE_Line_Item_Display(
1030
+			'admin_table',
1031
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1032
+		);
1033
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1034
+			$this->_transaction->total_line_item()
1035
+		);
1036
+		$this->_template_args['REG_code']        =
1037
+			$this->_transaction->primary_registration() instanceof EE_Registration
1038
+				? $this->_transaction->primary_registration()->reg_code()
1039
+				: null;
1040
+		// process taxes
1041
+		$taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1042
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
+
1044
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
1045
+			$this->_transaction->total(),
1046
+			false,
1047
+			false
1048
+		);
1049
+		$this->_template_args['grand_raw_total'] = $this->_transaction->total();
1050
+		$this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1051
+
1052
+		// process payment details
1053
+		$payments = $this->_transaction->payments();
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'] = [];
1060
+		}
1061
+
1062
+		$this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1063
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1064
+			['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'] =
1077
+			$this->_transaction->primary_registration() instanceof EE_Registration
1078
+				? $this->_transaction->primary_registration()->session_ID()
1079
+				: null;
1080
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1081
+			'Registration Session',
1082
+			'event_espresso'
1083
+		);
1084
+
1085
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1086
+			? $this->_session['ip_address']
1087
+			: '';
1088
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1089
+			'Transaction placed from IP',
1090
+			'event_espresso'
1091
+		);
1092
+
1093
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1094
+			? $this->_session['user_agent']
1095
+			: '';
1096
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1097
+			'Registrant User Agent',
1098
+			'event_espresso'
1099
+		);
1100
+
1101
+		$reg_steps = '<ul>';
1102
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1103
+			if ($reg_step_status === true) {
1104
+				$reg_steps .= '<li style="color:#70cc50">'
1105
+							  . sprintf(
1106
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1107
+								  ucwords(str_replace('_', ' ', $reg_step))
1108
+							  )
1109
+							  . '</li>';
1110
+			} elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1111
+				$reg_steps .= '<li style="color:#2EA2CC">'
1112
+							  . sprintf(
1113
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1114
+								  ucwords(str_replace('_', ' ', $reg_step)),
1115
+								  date(
1116
+									  get_option('date_format') . ' ' . get_option('time_format'),
1117
+									  $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1118
+								  )
1119
+							  )
1120
+							  . '</li>';
1121
+			} else {
1122
+				$reg_steps .= '<li style="color:#E76700">'
1123
+							  . sprintf(
1124
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1125
+								  ucwords(str_replace('_', ' ', $reg_step))
1126
+							  )
1127
+							  . '</li>';
1128
+			}
1129
+		}
1130
+		$reg_steps                                                 .= '</ul>';
1131
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1132
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1133
+			'Registration Step Progress',
1134
+			'event_espresso'
1135
+		);
1136
+
1137
+
1138
+		$this->_get_registrations_to_apply_payment_to();
1139
+		$this->_get_payment_methods($payments);
1140
+		$this->_get_payment_status_array();
1141
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1142
+
1143
+		$this->_template_args['transaction_form_url']    = add_query_arg(
1144
+			[
1145
+				'action'  => 'edit_transaction',
1146
+				'process' => 'transaction',
1147
+			],
1148
+			TXN_ADMIN_URL
1149
+		);
1150
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(
1151
+			[
1152
+				'page'   => 'espresso_transactions',
1153
+				'action' => 'espresso_apply_payment',
1154
+			],
1155
+			WP_AJAX_URL
1156
+		);
1157
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1158
+			[
1159
+				'page'   => 'espresso_transactions',
1160
+				'action' => 'espresso_delete_payment',
1161
+			],
1162
+			WP_AJAX_URL
1163
+		);
1164
+
1165
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1166
+
1167
+		// 'espresso_delete_payment_nonce'
1168
+
1169
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1170
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * _get_registration_payment_IDs
1176
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1177
+	 *
1178
+	 * @access protected
1179
+	 * @param EE_Payment[] $payments
1180
+	 * @return array
1181
+	 * @throws EE_Error
1182
+	 * @throws InvalidArgumentException
1183
+	 * @throws InvalidDataTypeException
1184
+	 * @throws InvalidInterfaceException
1185
+	 * @throws ReflectionException
1186
+	 */
1187
+	protected function _get_registration_payment_IDs($payments = [])
1188
+	{
1189
+		$existing_reg_payments = [];
1190
+		// get all reg payments for these payments
1191
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1192
+			[
1193
+				[
1194
+					'PAY_ID' => [
1195
+						'IN',
1196
+						array_keys($payments),
1197
+					],
1198
+				],
1199
+			]
1200
+		);
1201
+		if (! empty($reg_payments)) {
1202
+			foreach ($payments as $payment) {
1203
+				if (! $payment instanceof EE_Payment) {
1204
+					continue;
1205
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1206
+					$existing_reg_payments[ $payment->ID() ] = [];
1207
+				}
1208
+				foreach ($reg_payments as $reg_payment) {
1209
+					if (
1210
+						$reg_payment instanceof EE_Registration_Payment
1211
+						&& $reg_payment->payment_ID() === $payment->ID()
1212
+					) {
1213
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1214
+					}
1215
+				}
1216
+			}
1217
+		}
1218
+
1219
+		return $existing_reg_payments;
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * _get_registrations_to_apply_payment_to
1225
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1226
+	 * which allows the admin to only apply the payment to the specific registrations
1227
+	 *
1228
+	 * @access protected
1229
+	 * @return void
1230
+	 * @throws EE_Error
1231
+	 * @throws InvalidArgumentException
1232
+	 * @throws InvalidDataTypeException
1233
+	 * @throws InvalidInterfaceException
1234
+	 * @throws ReflectionException
1235
+	 */
1236
+	protected function _get_registrations_to_apply_payment_to()
1237
+	{
1238
+		// we want any registration with an active status (ie: not deleted or cancelled)
1239
+		$query_params                      = [
1240
+			[
1241
+				'STS_ID' => [
1242
+					'IN',
1243
+					[
1244
+						EEM_Registration::status_id_approved,
1245
+						EEM_Registration::status_id_pending_payment,
1246
+						EEM_Registration::status_id_not_approved,
1247
+					],
1248
+				],
1249
+			],
1250
+		];
1251
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1252
+			'',
1253
+			'txn-admin-apply-payment-to-registrations-dv',
1254
+			'',
1255
+			'clear: both; margin: 1.5em 0 0; display: none;'
1256
+		);
1257
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
+			EEH_HTML::tr(
1261
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
+			)
1269
+		);
1270
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
+		// get registrations for TXN
1272
+		$registrations         = $this->_transaction->registrations($query_params);
1273
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
+		foreach ($registrations as $registration) {
1275
+			if ($registration instanceof EE_Registration) {
1276
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1277
+					? $registration->attendee()->full_name()
1278
+					: esc_html__('Unknown Attendee', 'event_espresso');
1279
+				$owing                             = $registration->final_price() - $registration->paid();
1280
+				$taxable                           = $registration->ticket()->taxable()
1281
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
+					: '';
1283
+				$checked                           = empty($existing_reg_payments)
1284
+													 || in_array($registration->ID(), $existing_reg_payments, true)
1285
+					? ' checked'
1286
+					: '';
1287
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1288
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1289
+					EEH_HTML::td($registration->ID()) .
1290
+					EEH_HTML::td($attendee_name) .
1291
+					EEH_HTML::td(
1292
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1293
+					) .
1294
+					EEH_HTML::td($registration->event_name()) .
1295
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1296
+					EEH_HTML::td(
1297
+						EEH_Template::format_currency($owing),
1298
+						'',
1299
+						'txn-admin-payment-owing-td jst-cntr'
1300
+					) .
1301
+					EEH_HTML::td(
1302
+						'<input type="checkbox" value="' . $registration->ID()
1303
+						. '" name="txn_admin_payment[registrations]"'
1304
+						. $checked . $disabled . '>',
1305
+						'',
1306
+						'jst-cntr'
1307
+					),
1308
+					'apply-payment-registration-row-' . $registration->ID()
1309
+				);
1310
+			}
1311
+		}
1312
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1313
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1314
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1315
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1316
+			esc_html__(
1317
+				'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.',
1318
+				'event_espresso'
1319
+			),
1320
+			'',
1321
+			'clear description'
1322
+		);
1323
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1324
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * _get_reg_status_selection
1330
+	 *
1331
+	 * @return void
1332
+	 * @throws EE_Error
1333
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1334
+	 *         instead of events.
1335
+	 * @access protected
1336
+	 */
1337
+	protected function _get_reg_status_selection()
1338
+	{
1339
+		// first get all possible statuses
1340
+		$statuses = EEM_Registration::reg_status_array([], true);
1341
+		// let's add a "don't change" option.
1342
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1343
+		$status_array                                        = array_merge($status_array, $statuses);
1344
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1345
+			'txn_reg_status_change[reg_status]',
1346
+			$status_array,
1347
+			'NAN',
1348
+			'id="txn-admin-payment-reg-status-inp"',
1349
+			'txn-reg-status-change-reg-status'
1350
+		);
1351
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1352
+			'delete_txn_reg_status_change[reg_status]',
1353
+			$status_array,
1354
+			'NAN',
1355
+			'delete-txn-admin-payment-reg-status-inp',
1356
+			'delete-txn-reg-status-change-reg-status'
1357
+		);
1358
+	}
1359
+
1360
+
1361
+	/**
1362
+	 *    _get_payment_methods
1363
+	 * Gets all the payment methods available generally, or the ones that are already
1364
+	 * selected on these payments (in case their payment methods are no longer active).
1365
+	 * Has the side-effect of updating the template args' payment_methods item
1366
+	 *
1367
+	 * @access private
1368
+	 * @param EE_Payment[] to show on this page
1369
+	 * @return void
1370
+	 * @throws EE_Error
1371
+	 * @throws InvalidArgumentException
1372
+	 * @throws InvalidDataTypeException
1373
+	 * @throws InvalidInterfaceException
1374
+	 * @throws ReflectionException
1375
+	 */
1376
+	private function _get_payment_methods($payments = [])
1377
+	{
1378
+		$payment_methods_of_payments = [];
1379
+		foreach ($payments as $payment) {
1380
+			if ($payment instanceof EE_Payment) {
1381
+				$payment_methods_of_payments[] = $payment->ID();
1382
+			}
1383
+		}
1384
+		if ($payment_methods_of_payments) {
1385
+			$query_args = [
1386
+				[
1387
+					'OR*payment_method_for_payment' => [
1388
+						'PMD_ID'    => ['IN', $payment_methods_of_payments],
1389
+						'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1390
+					],
1391
+				],
1392
+			];
1393
+		} else {
1394
+			$query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1395
+		}
1396
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1397
+	}
1398
+
1399
+
1400
+	/**
1401
+	 * txn_attendees_meta_box
1402
+	 *    generates HTML for the Attendees Transaction main meta box
1403
+	 *
1404
+	 * @access public
1405
+	 * @param WP_Post $post
1406
+	 * @param array   $metabox
1407
+	 * @return void
1408
+	 * @throws DomainException
1409
+	 * @throws EE_Error
1410
+	 * @throws InvalidArgumentException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws InvalidInterfaceException
1413
+	 * @throws ReflectionException
1414
+	 */
1415
+	public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1416
+	{
1417
+
1418
+		/** @noinspection NonSecureExtractUsageInspection */
1419
+		extract($metabox['args']);
1420
+		$this->_template_args['post']            = $post;
1421
+		$this->_template_args['event_attendees'] = [];
1422
+		// process items in cart
1423
+		$line_items = $this->_transaction->get_many_related(
1424
+			'Line_Item',
1425
+			[['LIN_type' => 'line-item']]
1426
+		);
1427
+		if (! empty($line_items)) {
1428
+			foreach ($line_items as $item) {
1429
+				if ($item instanceof EE_Line_Item) {
1430
+					switch ($item->OBJ_type()) {
1431
+						case 'Event':
1432
+							break;
1433
+						case 'Ticket':
1434
+							$ticket = $item->ticket();
1435
+							// right now we're only handling tickets here.
1436
+							// Cause its expected that only tickets will have attendees right?
1437
+							if (! $ticket instanceof EE_Ticket) {
1438
+								break;
1439
+							}
1440
+							try {
1441
+								$event_name = $ticket->get_event_name();
1442
+							} catch (Exception $e) {
1443
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1444
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1445
+							}
1446
+							$event_name   .= ' - ' . $item->name();
1447
+							$ticket_price = EEH_Template::format_currency($item->unit_price());
1448
+							// now get all of the registrations for this transaction that use this ticket
1449
+							$registrations = $ticket->registrations(
1450
+								[['TXN_ID' => $this->_transaction->ID()]]
1451
+							);
1452
+							foreach ($registrations as $registration) {
1453
+								if (! $registration instanceof EE_Registration) {
1454
+									break;
1455
+								}
1456
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1457
+									= $registration->status_ID();
1458
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1459
+									= $registration->count();
1460
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1461
+									= $event_name;
1462
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1463
+									= $ticket_price;
1464
+								// attendee info
1465
+								$attendee = $registration->get_first_related('Attendee');
1466
+								if ($attendee instanceof EE_Attendee) {
1467
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1468
+										= $attendee->ID();
1469
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1470
+										= $attendee->full_name();
1471
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1472
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1473
+										  . esc_html__(
1474
+											  ' Event',
1475
+											  'event_espresso'
1476
+										  )
1477
+										  . '">' . $attendee->email() . '</a>';
1478
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1479
+										= EEH_Address::format($attendee, 'inline', false, false);
1480
+								} else {
1481
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1482
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1483
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1484
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1485
+								}
1486
+							}
1487
+							break;
1488
+					}
1489
+				}
1490
+			}
1491
+
1492
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1493
+				[
1494
+					'action'  => 'edit_transaction',
1495
+					'process' => 'attendees',
1496
+				],
1497
+				TXN_ADMIN_URL
1498
+			);
1499
+			echo EEH_Template::display_template(
1500
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1501
+				$this->_template_args,
1502
+				true
1503
+			);
1504
+		} else {
1505
+			printf(
1506
+				esc_html__(
1507
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1508
+					'event_espresso'
1509
+				),
1510
+				'<p class="important-notice">',
1511
+				'</p>'
1512
+			);
1513
+		}
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * txn_registrant_side_meta_box
1519
+	 * generates HTML for the Edit Transaction side meta box
1520
+	 *
1521
+	 * @access public
1522
+	 * @return void
1523
+	 * @throws DomainException
1524
+	 * @throws EE_Error
1525
+	 * @throws InvalidArgumentException
1526
+	 * @throws InvalidDataTypeException
1527
+	 * @throws InvalidInterfaceException
1528
+	 * @throws ReflectionException
1529
+	 */
1530
+	public function txn_registrant_side_meta_box()
1531
+	{
1532
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1533
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1534
+			: null;
1535
+		if (! $primary_att instanceof EE_Attendee) {
1536
+			$this->_template_args['no_attendee_message'] = esc_html__(
1537
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1538
+				'event_espresso'
1539
+			);
1540
+			$primary_att                           = EEM_Attendee::instance()->create_default_object();
1541
+		}
1542
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1543
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1544
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1545
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1546
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1547
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1548
+			[
1549
+				'action' => 'edit_attendee',
1550
+				'post'   => $primary_att->ID(),
1551
+			],
1552
+			REG_ADMIN_URL
1553
+		);
1554
+		// get formatted address for registrant
1555
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1556
+		echo EEH_Template::display_template(
1557
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1558
+			$this->_template_args,
1559
+			true
1560
+		);
1561
+	}
1562
+
1563
+
1564
+	/**
1565
+	 * txn_billing_info_side_meta_box
1566
+	 *    generates HTML for the Edit Transaction side meta box
1567
+	 *
1568
+	 * @access public
1569
+	 * @return void
1570
+	 * @throws DomainException
1571
+	 * @throws EE_Error
1572
+	 * @throws ReflectionException
1573
+	 */
1574
+	public function txn_billing_info_side_meta_box()
1575
+	{
1576
+
1577
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1578
+		$this->_template_args['billing_form_url'] = add_query_arg(
1579
+			['action' => 'edit_transaction', 'process' => 'billing'],
1580
+			TXN_ADMIN_URL
1581
+		);
1582
+
1583
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 * apply_payments_or_refunds
1590
+	 *    registers a payment or refund made towards a transaction
1591
+	 *
1592
+	 * @access public
1593
+	 * @return void
1594
+	 * @throws EE_Error
1595
+	 * @throws InvalidArgumentException
1596
+	 * @throws ReflectionException
1597
+	 * @throws RuntimeException
1598
+	 * @throws InvalidDataTypeException
1599
+	 * @throws InvalidInterfaceException
1600
+	 */
1601
+	public function apply_payments_or_refunds()
1602
+	{
1603
+		$json_response_data = ['return_data' => false];
1604
+		$valid_data         = $this->_validate_payment_request_data();
1605
+		$has_access         = EE_Registry::instance()->CAP->current_user_can(
1606
+			'ee_edit_payments',
1607
+			'apply_payment_or_refund_from_registration_details'
1608
+		);
1609
+		if (! empty($valid_data) && $has_access) {
1610
+			$PAY_ID = $valid_data['PAY_ID'];
1611
+			// save  the new payment
1612
+			$payment = $this->_create_payment_from_request_data($valid_data);
1613
+			// get the TXN for this payment
1614
+			$transaction = $payment->transaction();
1615
+			// verify transaction
1616
+			if ($transaction instanceof EE_Transaction) {
1617
+				// calculate_total_payments_and_update_status
1618
+				$this->_process_transaction_payments($transaction);
1619
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
+				// apply payment to registrations (if applicable)
1622
+				if (! empty($REG_IDs)) {
1623
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
+					$this->_maybe_send_notifications();
1625
+					// now process status changes for the same registrations
1626
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1627
+				}
1628
+				$this->_maybe_send_notifications($payment);
1629
+				// prepare to render page
1630
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
+				do_action(
1632
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
+					$transaction,
1634
+					$payment
1635
+				);
1636
+			} else {
1637
+				EE_Error::add_error(
1638
+					esc_html__(
1639
+						'A valid Transaction for this payment could not be retrieved.',
1640
+						'event_espresso'
1641
+					),
1642
+					__FILE__,
1643
+					__FUNCTION__,
1644
+					__LINE__
1645
+				);
1646
+			}
1647
+		} elseif ($has_access) {
1648
+			EE_Error::add_error(
1649
+				esc_html__(
1650
+					'The payment form data could not be processed. Please try again.',
1651
+					'event_espresso'
1652
+				),
1653
+				__FILE__,
1654
+				__FUNCTION__,
1655
+				__LINE__
1656
+			);
1657
+		} else {
1658
+			EE_Error::add_error(
1659
+				esc_html__(
1660
+					'You do not have access to apply payments or refunds to a registration.',
1661
+					'event_espresso'
1662
+				),
1663
+				__FILE__,
1664
+				__FUNCTION__,
1665
+				__LINE__
1666
+			);
1667
+		}
1668
+		$notices              = EE_Error::get_notices(
1669
+			false,
1670
+			false,
1671
+			false
1672
+		);
1673
+		$this->_template_args = [
1674
+			'data'    => $json_response_data,
1675
+			'error'   => $notices['errors'],
1676
+			'success' => $notices['success'],
1677
+		];
1678
+		$this->_return_json();
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * _validate_payment_request_data
1684
+	 *
1685
+	 * @return array
1686
+	 * @throws EE_Error
1687
+	 * @throws InvalidArgumentException
1688
+	 * @throws InvalidDataTypeException
1689
+	 * @throws InvalidInterfaceException
1690
+	 */
1691
+	protected function _validate_payment_request_data()
1692
+	{
1693
+		if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1694
+			return [];
1695
+		}
1696
+		$payment_form = $this->_generate_payment_form_section();
1697
+		try {
1698
+			if ($payment_form->was_submitted()) {
1699
+				$payment_form->receive_form_submission();
1700
+				if (! $payment_form->is_valid()) {
1701
+					$submission_error_messages = [];
1702
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
+						if ($validation_error instanceof EE_Validation_Error) {
1704
+							$form_input = $validation_error->get_form_section();
1705
+							$submission_error_messages[] = sprintf(
1706
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1707
+								$form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1708
+								$validation_error->getMessage()
1709
+							);
1710
+						}
1711
+					}
1712
+					EE_Error::add_error(
1713
+						implode('<br />', $submission_error_messages),
1714
+						__FILE__,
1715
+						__FUNCTION__,
1716
+						__LINE__
1717
+					);
1718
+					return [];
1719
+				}
1720
+			}
1721
+		} catch (EE_Error $e) {
1722
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1723
+			return [];
1724
+		}
1725
+
1726
+		return $payment_form->valid_data();
1727
+	}
1728
+
1729
+
1730
+	/**
1731
+	 * _generate_payment_form_section
1732
+	 *
1733
+	 * @return EE_Form_Section_Proper
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	protected function _generate_payment_form_section()
1737
+	{
1738
+		return new EE_Form_Section_Proper(
1739
+			[
1740
+				'name'        => 'txn_admin_payment',
1741
+				'subsections' => [
1742
+					'PAY_ID'          => new EE_Text_Input(
1743
+						[
1744
+							'default'               => 0,
1745
+							'required'              => false,
1746
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1747
+							'validation_strategies' => [new EE_Int_Normalization()],
1748
+						]
1749
+					),
1750
+					'TXN_ID'          => new EE_Text_Input(
1751
+						[
1752
+							'default'               => 0,
1753
+							'required'              => true,
1754
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1755
+							'validation_strategies' => [new EE_Int_Normalization()],
1756
+						]
1757
+					),
1758
+					'type'            => new EE_Text_Input(
1759
+						[
1760
+							'default'               => 1,
1761
+							'required'              => true,
1762
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1763
+							'validation_strategies' => [new EE_Int_Normalization()],
1764
+						]
1765
+					),
1766
+					'amount'          => new EE_Text_Input(
1767
+						[
1768
+							'default'               => 0,
1769
+							'required'              => true,
1770
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1771
+							'validation_strategies' => [new EE_Float_Normalization()],
1772
+						]
1773
+					),
1774
+					'status'          => new EE_Text_Input(
1775
+						[
1776
+							'default'         => EEM_Payment::status_id_approved,
1777
+							'required'        => true,
1778
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1779
+						]
1780
+					),
1781
+					'PMD_ID'          => new EE_Text_Input(
1782
+						[
1783
+							'default'               => 2,
1784
+							'required'              => true,
1785
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1786
+							'validation_strategies' => [new EE_Int_Normalization()],
1787
+						]
1788
+					),
1789
+					'date'            => new EE_Text_Input(
1790
+						[
1791
+							'default'         => time(),
1792
+							'required'        => true,
1793
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1794
+						]
1795
+					),
1796
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1797
+						[
1798
+							'default'               => '',
1799
+							'required'              => false,
1800
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1801
+							'validation_strategies' => [
1802
+								new EE_Max_Length_Validation_Strategy(
1803
+									esc_html__('Input too long', 'event_espresso'),
1804
+									100
1805
+								),
1806
+							],
1807
+						]
1808
+					),
1809
+					'po_number'       => new EE_Text_Input(
1810
+						[
1811
+							'default'               => '',
1812
+							'required'              => false,
1813
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1814
+							'validation_strategies' => [
1815
+								new EE_Max_Length_Validation_Strategy(
1816
+									esc_html__('Input too long', 'event_espresso'),
1817
+									100
1818
+								),
1819
+							],
1820
+						]
1821
+					),
1822
+					'accounting'      => new EE_Text_Input(
1823
+						[
1824
+							'default'               => '',
1825
+							'required'              => false,
1826
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1827
+							'validation_strategies' => [
1828
+								new EE_Max_Length_Validation_Strategy(
1829
+									esc_html__('Input too long', 'event_espresso'),
1830
+									100
1831
+								),
1832
+							],
1833
+						]
1834
+					),
1835
+				],
1836
+			]
1837
+		);
1838
+	}
1839
+
1840
+
1841
+	/**
1842
+	 * _create_payment_from_request_data
1843
+	 *
1844
+	 * @param array $valid_data
1845
+	 * @return EE_Payment
1846
+	 * @throws EE_Error
1847
+	 * @throws InvalidArgumentException
1848
+	 * @throws InvalidDataTypeException
1849
+	 * @throws InvalidInterfaceException
1850
+	 * @throws ReflectionException
1851
+	 */
1852
+	protected function _create_payment_from_request_data($valid_data)
1853
+	{
1854
+		$PAY_ID = $valid_data['PAY_ID'];
1855
+		// get payment amount
1856
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1857
+		// payments have a type value of 1 and refunds have a type value of -1
1858
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1859
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1860
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1861
+		$date    = $valid_data['date']
1862
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1863
+			: date('Y-m-d g:i a', current_time('timestamp'));
1864
+		$payment = EE_Payment::new_instance(
1865
+			[
1866
+				'TXN_ID'              => $valid_data['TXN_ID'],
1867
+				'STS_ID'              => $valid_data['status'],
1868
+				'PAY_timestamp'       => $date,
1869
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1870
+				'PMD_ID'              => $valid_data['PMD_ID'],
1871
+				'PAY_amount'          => $amount,
1872
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1873
+				'PAY_po_number'       => $valid_data['po_number'],
1874
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1875
+				'PAY_details'         => $valid_data,
1876
+				'PAY_ID'              => $PAY_ID,
1877
+			],
1878
+			'',
1879
+			['Y-m-d', 'g:i a']
1880
+		);
1881
+
1882
+		if (! $payment->save()) {
1883
+			EE_Error::add_error(
1884
+				sprintf(
1885
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1886
+					$payment->ID()
1887
+				),
1888
+				__FILE__,
1889
+				__FUNCTION__,
1890
+				__LINE__
1891
+			);
1892
+		}
1893
+
1894
+		return $payment;
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * _process_transaction_payments
1900
+	 *
1901
+	 * @param EE_Transaction $transaction
1902
+	 * @return void
1903
+	 * @throws EE_Error
1904
+	 * @throws InvalidArgumentException
1905
+	 * @throws ReflectionException
1906
+	 * @throws InvalidDataTypeException
1907
+	 * @throws InvalidInterfaceException
1908
+	 */
1909
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1910
+	{
1911
+		/** @type EE_Transaction_Payments $transaction_payments */
1912
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1913
+		// update the transaction with this payment
1914
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1915
+			EE_Error::add_success(
1916
+				esc_html__(
1917
+					'The payment has been processed successfully.',
1918
+					'event_espresso'
1919
+				),
1920
+				__FILE__,
1921
+				__FUNCTION__,
1922
+				__LINE__
1923
+			);
1924
+		} else {
1925
+			EE_Error::add_error(
1926
+				esc_html__(
1927
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1928
+					'event_espresso'
1929
+				),
1930
+				__FILE__,
1931
+				__FUNCTION__,
1932
+				__LINE__
1933
+			);
1934
+		}
1935
+	}
1936
+
1937
+
1938
+	/**
1939
+	 * _get_REG_IDs_to_apply_payment_to
1940
+	 * returns a list of registration IDs that the payment will apply to
1941
+	 *
1942
+	 * @param EE_Payment $payment
1943
+	 * @return array
1944
+	 * @throws EE_Error
1945
+	 * @throws InvalidArgumentException
1946
+	 * @throws InvalidDataTypeException
1947
+	 * @throws InvalidInterfaceException
1948
+	 * @throws ReflectionException
1949
+	 */
1950
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1951
+	{
1952
+		// grab array of IDs for specific registrations to apply changes to
1953
+		$REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1954
+		// nothing specified ? then get all reg IDs
1955
+		if (empty($REG_IDs)) {
1956
+			$registrations = $payment->transaction()->registrations();
1957
+			$REG_IDs       = ! empty($registrations)
1958
+				? array_keys($registrations)
1959
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1960
+		}
1961
+
1962
+		// ensure that REG_IDs are integers and NOT strings
1963
+		return array_map('intval', $REG_IDs);
1964
+	}
1965
+
1966
+
1967
+	/**
1968
+	 * @return array
1969
+	 */
1970
+	public function existing_reg_payment_REG_IDs()
1971
+	{
1972
+		return $this->_existing_reg_payment_REG_IDs;
1973
+	}
1974
+
1975
+
1976
+	/**
1977
+	 * @param array $existing_reg_payment_REG_IDs
1978
+	 */
1979
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1980
+	{
1981
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1982
+	}
1983
+
1984
+
1985
+	/**
1986
+	 * _get_existing_reg_payment_REG_IDs
1987
+	 * returns a list of registration IDs that the payment is currently related to
1988
+	 * as recorded in the database
1989
+	 *
1990
+	 * @param EE_Payment $payment
1991
+	 * @return array
1992
+	 * @throws EE_Error
1993
+	 * @throws InvalidArgumentException
1994
+	 * @throws InvalidDataTypeException
1995
+	 * @throws InvalidInterfaceException
1996
+	 * @throws ReflectionException
1997
+	 */
1998
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1999
+	{
2000
+		if ($this->existing_reg_payment_REG_IDs() === null) {
2001
+			// let's get any existing reg payment records for this payment
2002
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2003
+			// but we only want the REG IDs, so grab the array keys
2004
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2005
+				? array_keys($existing_reg_payment_REG_IDs)
2006
+				: [];
2007
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2008
+		}
2009
+
2010
+		return $this->existing_reg_payment_REG_IDs();
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 * _remove_existing_registration_payments
2016
+	 * this calculates the difference between existing relations
2017
+	 * to the supplied payment and the new list registration IDs,
2018
+	 * removes any related registrations that no longer apply,
2019
+	 * and then updates the registration paid fields
2020
+	 *
2021
+	 * @param EE_Payment $payment
2022
+	 * @param int        $PAY_ID
2023
+	 * @return bool;
2024
+	 * @throws EE_Error
2025
+	 * @throws InvalidArgumentException
2026
+	 * @throws ReflectionException
2027
+	 * @throws InvalidDataTypeException
2028
+	 * @throws InvalidInterfaceException
2029
+	 */
2030
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2031
+	{
2032
+		// newly created payments will have nothing recorded for $PAY_ID
2033
+		if (absint($PAY_ID) === 0) {
2034
+			return false;
2035
+		}
2036
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2037
+		if (empty($existing_reg_payment_REG_IDs)) {
2038
+			return false;
2039
+		}
2040
+		/** @type EE_Transaction_Payments $transaction_payments */
2041
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2042
+
2043
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2044
+			$payment,
2045
+			[
2046
+				[
2047
+					'PAY_ID' => $payment->ID(),
2048
+					'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2049
+				],
2050
+			]
2051
+		);
2052
+	}
2053
+
2054
+
2055
+	/**
2056
+	 * _update_registration_payments
2057
+	 * this applies the payments to the selected registrations
2058
+	 * but only if they have not already been paid for
2059
+	 *
2060
+	 * @param EE_Transaction $transaction
2061
+	 * @param EE_Payment     $payment
2062
+	 * @param array          $REG_IDs
2063
+	 * @return void
2064
+	 * @throws EE_Error
2065
+	 * @throws InvalidArgumentException
2066
+	 * @throws ReflectionException
2067
+	 * @throws RuntimeException
2068
+	 * @throws InvalidDataTypeException
2069
+	 * @throws InvalidInterfaceException
2070
+	 */
2071
+	protected function _update_registration_payments(
2072
+		EE_Transaction $transaction,
2073
+		EE_Payment $payment,
2074
+		$REG_IDs = []
2075
+	) {
2076
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2077
+		// so let's do that using our set of REG_IDs from the form
2078
+		$registration_query_where_params = [
2079
+			'REG_ID' => ['IN', $REG_IDs],
2080
+		];
2081
+		// but add in some conditions regarding payment,
2082
+		// so that we don't apply payments to registrations that are free or have already been paid for
2083
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2084
+		if (! $payment->is_a_refund()) {
2085
+			$registration_query_where_params['REG_final_price']  = ['!=', 0];
2086
+			$registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2087
+		}
2088
+		$registrations = $transaction->registrations([$registration_query_where_params]);
2089
+		if (! empty($registrations)) {
2090
+			/** @type EE_Payment_Processor $payment_processor */
2091
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2092
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2093
+		}
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * _process_registration_status_change
2099
+	 * This processes requested registration status changes for all the registrations
2100
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2101
+	 *
2102
+	 * @param EE_Transaction $transaction
2103
+	 * @param array          $REG_IDs
2104
+	 * @return bool
2105
+	 * @throws EE_Error
2106
+	 * @throws InvalidArgumentException
2107
+	 * @throws ReflectionException
2108
+	 * @throws InvalidDataTypeException
2109
+	 * @throws InvalidInterfaceException
2110
+	 */
2111
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2112
+	{
2113
+		// first if there is no change in status then we get out.
2114
+		$reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2115
+		if ($reg_status === 'NAN') {
2116
+			// no error message, no change requested, just nothing to do man.
2117
+			return false;
2118
+		}
2119
+		/** @type EE_Transaction_Processor $transaction_processor */
2120
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2121
+
2122
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2123
+		return $transaction_processor->manually_update_registration_statuses(
2124
+			$transaction,
2125
+			$reg_status,
2126
+			[['REG_ID' => ['IN', $REG_IDs]]]
2127
+		);
2128
+	}
2129
+
2130
+
2131
+	/**
2132
+	 * _build_payment_json_response
2133
+	 *
2134
+	 * @access public
2135
+	 * @param EE_Payment  $payment
2136
+	 * @param array       $REG_IDs
2137
+	 * @param bool | null $delete_txn_reg_status_change
2138
+	 * @return array
2139
+	 * @throws EE_Error
2140
+	 * @throws InvalidArgumentException
2141
+	 * @throws InvalidDataTypeException
2142
+	 * @throws InvalidInterfaceException
2143
+	 * @throws ReflectionException
2144
+	 */
2145
+	protected function _build_payment_json_response(
2146
+		EE_Payment $payment,
2147
+		$REG_IDs = [],
2148
+		$delete_txn_reg_status_change = null
2149
+	) {
2150
+		// was the payment deleted ?
2151
+		if (is_bool($delete_txn_reg_status_change)) {
2152
+			return [
2153
+				'PAY_ID'                       => $payment->ID(),
2154
+				'amount'                       => $payment->amount(),
2155
+				'total_paid'                   => $payment->transaction()->paid(),
2156
+				'txn_status'                   => $payment->transaction()->status_ID(),
2157
+				'pay_status'                   => $payment->STS_ID(),
2158
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2159
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2160
+			];
2161
+		}
2162
+
2163
+		$this->_get_payment_status_array();
2164
+		return [
2165
+			'amount'           => $payment->amount(),
2166
+			'total_paid'       => $payment->transaction()->paid(),
2167
+			'txn_status'       => $payment->transaction()->status_ID(),
2168
+			'pay_status'       => $payment->STS_ID(),
2169
+			'PAY_ID'           => $payment->ID(),
2170
+			'STS_ID'           => $payment->STS_ID(),
2171
+			'status'           => self::$_pay_status[ $payment->STS_ID() ],
2172
+			'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2173
+			'method'           => strtoupper($payment->source()),
2174
+			'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2175
+			'gateway'          => $payment->payment_method()
2176
+				? $payment->payment_method()->admin_name()
2177
+				: esc_html__('Unknown', 'event_espresso'),
2178
+			'gateway_response' => $payment->gateway_response(),
2179
+			'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2180
+			'po_number'        => $payment->po_number(),
2181
+			'extra_accntng'    => $payment->extra_accntng(),
2182
+			'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2183
+		];
2184
+	}
2185
+
2186
+
2187
+	/**
2188
+	 * delete_payment
2189
+	 *    delete a payment or refund made towards a transaction
2190
+	 *
2191
+	 * @access public
2192
+	 * @return void
2193
+	 * @throws EE_Error
2194
+	 * @throws InvalidArgumentException
2195
+	 * @throws ReflectionException
2196
+	 * @throws InvalidDataTypeException
2197
+	 * @throws InvalidInterfaceException
2198
+	 */
2199
+	public function delete_payment()
2200
+	{
2201
+		$json_response_data = ['return_data' => false];
2202
+		$PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2203
+
2204
+		$can_delete         = EE_Registry::instance()->CAP->current_user_can(
2205
+			'ee_delete_payments',
2206
+			'delete_payment_from_registration_details'
2207
+		);
2208
+		if ($PAY_ID && $can_delete) {
2209
+			$delete_txn_reg_status_change = $this->request->getRequestParam(
2210
+				'delete_txn_reg_status_change',
2211
+				false,
2212
+				'bool'
2213
+			);
2214
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2215
+			if ($payment instanceof EE_Payment) {
2216
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2217
+				/** @type EE_Transaction_Payments $transaction_payments */
2218
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2219
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2220
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2221
+						$payment,
2222
+						$REG_IDs,
2223
+						$delete_txn_reg_status_change
2224
+					);
2225
+					if ($delete_txn_reg_status_change) {
2226
+						// MAKE sure we also add the delete_txn_req_status_change to the
2227
+						// request data because that's how messages will be looking for it.
2228
+						$this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2229
+						$this->_maybe_send_notifications();
2230
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2231
+					}
2232
+				}
2233
+			} else {
2234
+				EE_Error::add_error(
2235
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2236
+					__FILE__,
2237
+					__FUNCTION__,
2238
+					__LINE__
2239
+				);
2240
+			}
2241
+		} elseif ($can_delete) {
2242
+			EE_Error::add_error(
2243
+				esc_html__(
2244
+					'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2245
+					'event_espresso'
2246
+				),
2247
+				__FILE__,
2248
+				__FUNCTION__,
2249
+				__LINE__
2250
+			);
2251
+		} else {
2252
+			EE_Error::add_error(
2253
+				esc_html__(
2254
+					'You do not have access to delete a payment.',
2255
+					'event_espresso'
2256
+				),
2257
+				__FILE__,
2258
+				__FUNCTION__,
2259
+				__LINE__
2260
+			);
2261
+		}
2262
+		$notices              = EE_Error::get_notices(false, false, false);
2263
+		$this->_template_args = [
2264
+			'data'      => $json_response_data,
2265
+			'success'   => $notices['success'],
2266
+			'error'     => $notices['errors'],
2267
+			'attention' => $notices['attention'],
2268
+		];
2269
+		$this->_return_json();
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * _registration_payment_data_array
2275
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2276
+	 *
2277
+	 * @access protected
2278
+	 * @param array $REG_IDs
2279
+	 * @return array
2280
+	 * @throws EE_Error
2281
+	 * @throws InvalidArgumentException
2282
+	 * @throws InvalidDataTypeException
2283
+	 * @throws InvalidInterfaceException
2284
+	 * @throws ReflectionException
2285
+	 */
2286
+	protected function _registration_payment_data_array($REG_IDs)
2287
+	{
2288
+		$registration_payment_data = [];
2289
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2290
+		if (! empty($REG_IDs)) {
2291
+			$registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2292
+			foreach ($registrations as $registration) {
2293
+				if ($registration instanceof EE_Registration) {
2294
+					$registration_payment_data[ $registration->ID() ] = [
2295
+						'paid'  => $registration->pretty_paid(),
2296
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2297
+					];
2298
+				}
2299
+			}
2300
+		}
2301
+
2302
+		return $registration_payment_data;
2303
+	}
2304
+
2305
+
2306
+	/**
2307
+	 * _maybe_send_notifications
2308
+	 * determines whether or not the admin has indicated that notifications should be sent.
2309
+	 * If so, will toggle a filter switch for delivering registration notices.
2310
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2311
+	 *
2312
+	 * @access protected
2313
+	 * @param EE_Payment | null $payment
2314
+	 */
2315
+	protected function _maybe_send_notifications($payment = null)
2316
+	{
2317
+		switch ($payment instanceof EE_Payment) {
2318
+			// payment notifications
2319
+			case true:
2320
+				if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2321
+					$this->_process_payment_notification($payment);
2322
+				}
2323
+				break;
2324
+			// registration notifications
2325
+			case false:
2326
+				if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2327
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2328
+				}
2329
+				break;
2330
+		}
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * _send_payment_reminder
2336
+	 *    generates HTML for the View Transaction Details Admin page
2337
+	 *
2338
+	 * @access protected
2339
+	 * @return void
2340
+	 * @throws EE_Error
2341
+	 * @throws InvalidArgumentException
2342
+	 * @throws InvalidDataTypeException
2343
+	 * @throws InvalidInterfaceException
2344
+	 */
2345
+	protected function _send_payment_reminder()
2346
+	{
2347
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2348
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2349
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2350
+		$query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2351
+		do_action(
2352
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2353
+			$transaction
2354
+		);
2355
+		$this->_redirect_after_action(
2356
+			false,
2357
+			esc_html__('payment reminder', 'event_espresso'),
2358
+			esc_html__('sent', 'event_espresso'),
2359
+			$query_args,
2360
+			true
2361
+		);
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 *  get_transactions
2367
+	 *    get transactions for given parameters (used by list table)
2368
+	 *
2369
+	 * @param int     $per_page how many transactions displayed per page
2370
+	 * @param boolean $count   return the count or objects
2371
+	 * @param string  $view
2372
+	 * @return EE_Transaction[]|int int = count || array of transaction objects
2373
+	 * @throws EE_Error
2374
+	 * @throws InvalidArgumentException
2375
+	 * @throws InvalidDataTypeException
2376
+	 * @throws InvalidInterfaceException
2377
+	 */
2378
+	public function get_transactions($per_page, $count = false, $view = '')
2379
+	{
2380
+		$start_date = wp_strip_all_tags(
2381
+			$this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2382
+		);
2383
+		$end_date = wp_strip_all_tags(
2384
+			$this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2385
+		);
2386
+
2387
+		// make sure our timestamps start and end right at the boundaries for each day
2388
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2389
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2390
+
2391
+
2392
+		// convert to timestamps
2393
+		$start_date = strtotime($start_date);
2394
+		$end_date   = strtotime($end_date);
2395
+
2396
+		// makes sure start date is the lowest value and vice versa
2397
+		$start_date = min($start_date, $end_date);
2398
+		$end_date   = max($start_date, $end_date);
2399
+
2400
+		// convert to correct format for query
2401
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2402
+			'TXN_timestamp',
2403
+			date('Y-m-d H:i:s', $start_date),
2404
+			'Y-m-d H:i:s'
2405
+		);
2406
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2407
+			'TXN_timestamp',
2408
+			date('Y-m-d H:i:s', $end_date),
2409
+			'Y-m-d H:i:s'
2410
+		);
2411
+
2412
+
2413
+		// set orderby
2414
+		$orderby = $this->request->getRequestParam('orderby');
2415
+
2416
+		switch ($orderby) {
2417
+			case '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         = $this->request->getRequestParam('order', 'DESC');
2430
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
2431
+
2432
+		$per_page = absint($per_page) ? $per_page : 10;
2433
+		$per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2434
+
2435
+		$offset = ($current_page - 1) * $per_page;
2436
+		$limit  = [$offset, $per_page];
2437
+
2438
+		$_where = [
2439
+			'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2440
+			'Registration.REG_count' => 1,
2441
+		];
2442
+
2443
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2444
+		if ($EVT_ID) {
2445
+			$_where['Registration.EVT_ID'] = $EVT_ID;
2446
+		}
2447
+
2448
+		$search_term = $this->request->getRequestParam('s');
2449
+		if ($search_term) {
2450
+			$search_term = '%' . $search_term . '%';
2451
+			$_where['OR']  = [
2452
+				'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2453
+				'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2454
+				'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2455
+				'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2456
+				'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2457
+				'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2458
+				'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2459
+				'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2460
+				'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2461
+				'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2462
+				'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2463
+				'Registration.REG_final_price'        => ['LIKE', $search_term],
2464
+				'Registration.REG_code'               => ['LIKE', $search_term],
2465
+				'Registration.REG_count'              => ['LIKE', $search_term],
2466
+				'Registration.REG_group_size'         => ['LIKE', $search_term],
2467
+				'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2468
+				'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2469
+				'Payment.PAY_source'                  => ['LIKE', $search_term],
2470
+				'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2471
+				'TXN_session_data'                    => ['LIKE', $search_term],
2472
+				'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2473
+			];
2474
+		}
2475
+
2476
+		$status = $this->request->getRequestParam('status');
2477
+		// failed transactions
2478
+		$failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
+		$abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
+		$incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2481
+
2482
+		if ($failed) {
2483
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2484
+		} elseif ($abandoned) {
2485
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2486
+		} elseif ($incomplete) {
2487
+			$_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2488
+		} else {
2489
+			$_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2490
+			$_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2491
+		}
2492
+
2493
+		$query_params = apply_filters(
2494
+			'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2495
+			[
2496
+				$_where,
2497
+				'order_by'                 => [$orderby => $sort],
2498
+				'limit'                    => $limit,
2499
+				'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2500
+			],
2501
+			$this->request->requestParams(),
2502
+			$view,
2503
+			$count
2504
+		);
2505
+
2506
+		return $count
2507
+			? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2508
+			: EEM_Transaction::instance()->get_all($query_params);
2509
+	}
2510
+
2511
+
2512
+	/**
2513
+	 * @throws EE_Error
2514
+	 * @throws InvalidArgumentException
2515
+	 * @throws InvalidDataTypeException
2516
+	 * @throws InvalidInterfaceException
2517
+	 * @throws ReflectionException
2518
+	 * @throws RuntimeException
2519
+	 * @since 4.9.79.p
2520
+	 */
2521
+	public function recalculateLineItems()
2522
+	{
2523
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2524
+		/** @var EE_Transaction $transaction */
2525
+		$transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2526
+		$success         = $transaction->recalculateLineItems();
2527
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2528
+		$query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2529
+		$this->_redirect_after_action(
2530
+			$success,
2531
+			esc_html__('Transaction taxes and totals', 'event_espresso'),
2532
+			esc_html__('recalculated', 'event_espresso'),
2533
+			$query_args,
2534
+			true
2535
+		);
2536
+	}
2537 2537
 }
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
             '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.',
247 247
             'event_espresso'
248 248
         );
249
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
249
+        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
250 250
             'An error occurred! Please refresh the page and try again.',
251 251
             'event_espresso'
252 252
         );
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         // enqueue style
346 346
         wp_register_style(
347 347
             'espresso_txn',
348
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
348
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
349 349
             [],
350 350
             EVENT_ESPRESSO_VERSION
351 351
         );
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
         // scripts
354 354
         wp_register_script(
355 355
             'espresso_txn',
356
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
356
+            TXN_ASSETS_URL.'espresso_transactions_admin.js',
357 357
             [
358 358
                 'ee_admin_js',
359 359
                 'ee-datepicker',
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
             $this->_transaction->verify_abandoned_transaction_status();
481 481
         }
482 482
 
483
-        if (! $this->_transaction instanceof EE_Transaction) {
483
+        if ( ! $this->_transaction instanceof EE_Transaction) {
484 484
             $error_msg = sprintf(
485 485
                 esc_html__(
486 486
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
578 578
             [
579 579
                 'overpaid'   => [
580
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
580
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
581 581
                     'desc'  => EEH_Template::pretty_status(
582 582
                         EEM_Transaction::overpaid_status_code,
583 583
                         false,
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
                     ),
586 586
                 ],
587 587
                 'complete'   => [
588
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
588
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
589 589
                     'desc'  => EEH_Template::pretty_status(
590 590
                         EEM_Transaction::complete_status_code,
591 591
                         false,
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
                     ),
594 594
                 ],
595 595
                 'incomplete' => [
596
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
596
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
597 597
                     'desc'  => EEH_Template::pretty_status(
598 598
                         EEM_Transaction::incomplete_status_code,
599 599
                         false,
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
                     ),
602 602
                 ],
603 603
                 'abandoned'  => [
604
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
604
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
605 605
                     'desc'  => EEH_Template::pretty_status(
606 606
                         EEM_Transaction::abandoned_status_code,
607 607
                         false,
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
                     ),
610 610
                 ],
611 611
                 'failed'     => [
612
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
612
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
613 613
                     'desc'  => EEH_Template::pretty_status(
614 614
                         EEM_Transaction::failed_status_code,
615 615
                         false,
@@ -652,11 +652,11 @@  discard block
 block discarded – undo
652 652
                 )
653 653
                 . '" title="'
654 654
                 . esc_attr__('Click to Edit event', 'event_espresso')
655
-                . '">' . $event->name() . '</a>',
655
+                . '">'.$event->name().'</a>',
656 656
                 '</h3>'
657 657
             )
658 658
             : '';
659
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
659
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
660 660
         $this->display_admin_list_table_page_with_no_sidebar();
661 661
     }
662 662
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 
687 687
         $this->_set_transaction_object();
688 688
 
689
-        if (! $this->_transaction instanceof EE_Transaction) {
689
+        if ( ! $this->_transaction instanceof EE_Transaction) {
690 690
             return;
691 691
         }
692 692
 
@@ -696,9 +696,9 @@  discard block
 block discarded – undo
696 696
         $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
697 697
         $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
698 698
 
699
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
699
+        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->status_ID()];
700 700
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
701
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
701
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->status_ID();
702 702
 
703 703
         $this->_template_args['grand_total'] = $this->_transaction->total();
704 704
         $this->_template_args['total_paid']  = $this->_transaction->paid();
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 
751 751
 
752 752
         // next link
753
-        $next_txn                                 = $this->_transaction->next(
753
+        $next_txn = $this->_transaction->next(
754 754
             null,
755 755
             [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
756 756
             'TXN_ID'
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
             )
766 766
             : '';
767 767
         // previous link
768
-        $previous_txn                                 = $this->_transaction->previous(
768
+        $previous_txn = $this->_transaction->previous(
769 769
             null,
770 770
             [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
771 771
             'TXN_ID'
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
         // grab messages at the last second
818 818
         $this->_template_args['notices'] = EE_Error::get_notices();
819 819
         // path to template
820
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
820
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
821 821
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
822 822
             $template_path,
823 823
             $this->_template_args,
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 
847 847
         $this->_set_transaction_object();
848 848
 
849
-        if (! $this->_transaction instanceof EE_Transaction) {
849
+        if ( ! $this->_transaction instanceof EE_Transaction) {
850 850
             return;
851 851
         }
852 852
         add_meta_box(
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
     {
903 903
         $content = '';
904 904
         $actions = [];
905
-        if (! $transaction instanceof EE_Transaction) {
905
+        if ( ! $transaction instanceof EE_Transaction) {
906 906
             return $content;
907 907
         }
908 908
         /** @var EE_Registration $primary_registration */
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
         );
988 988
         if ($actions) {
989 989
             $content = '<ul>';
990
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
990
+            $content .= '<li>'.implode('</li><li>', $actions).'</li>';
991 991
             $content .= '</uL>';
992 992
         }
993 993
         return $content;
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
             $this->_transaction->primary_registration() instanceof EE_Registration
1016 1016
                 ? $this->_transaction->primary_registration()->attendee()
1017 1017
                 : null;
1018
-        $this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1018
+        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1019 1019
             'ee_edit_payments',
1020 1020
             'apply_payment_or_refund_from_registration_details'
1021 1021
         );
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 
1027 1027
         // get line table
1028 1028
         EEH_Autoloader::register_line_item_display_autoloaders();
1029
-        $Line_Item_Display                       = new EE_Line_Item_Display(
1029
+        $Line_Item_Display = new EE_Line_Item_Display(
1030 1030
             'admin_table',
1031 1031
             'EE_Admin_Table_Line_Item_Display_Strategy'
1032 1032
         );
@@ -1041,7 +1041,7 @@  discard block
 block discarded – undo
1041 1041
         $taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1042 1042
         $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043 1043
 
1044
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1044
+        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1045 1045
             $this->_transaction->total(),
1046 1046
             false,
1047 1047
             false
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 
1052 1052
         // process payment details
1053 1053
         $payments = $this->_transaction->payments();
1054
-        if (! empty($payments)) {
1054
+        if ( ! empty($payments)) {
1055 1055
             $this->_template_args['payments']              = $payments;
1056 1056
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1057 1057
         } else {
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1114 1114
                                   ucwords(str_replace('_', ' ', $reg_step)),
1115 1115
                                   date(
1116
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1116
+                                      get_option('date_format').' '.get_option('time_format'),
1117 1117
                                       $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1118 1118
                                   )
1119 1119
                               )
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
                               . '</li>';
1128 1128
             }
1129 1129
         }
1130
-        $reg_steps                                                 .= '</ul>';
1130
+        $reg_steps .= '</ul>';
1131 1131
         $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1132 1132
         $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1133 1133
             'Registration Step Progress',
@@ -1140,14 +1140,14 @@  discard block
 block discarded – undo
1140 1140
         $this->_get_payment_status_array();
1141 1141
         $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1142 1142
 
1143
-        $this->_template_args['transaction_form_url']    = add_query_arg(
1143
+        $this->_template_args['transaction_form_url'] = add_query_arg(
1144 1144
             [
1145 1145
                 'action'  => 'edit_transaction',
1146 1146
                 'process' => 'transaction',
1147 1147
             ],
1148 1148
             TXN_ADMIN_URL
1149 1149
         );
1150
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(
1150
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(
1151 1151
             [
1152 1152
                 'page'   => 'espresso_transactions',
1153 1153
                 'action' => 'espresso_apply_payment',
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 
1167 1167
         // 'espresso_delete_payment_nonce'
1168 1168
 
1169
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1169
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1170 1170
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1171 1171
     }
1172 1172
 
@@ -1198,19 +1198,19 @@  discard block
 block discarded – undo
1198 1198
                 ],
1199 1199
             ]
1200 1200
         );
1201
-        if (! empty($reg_payments)) {
1201
+        if ( ! empty($reg_payments)) {
1202 1202
             foreach ($payments as $payment) {
1203
-                if (! $payment instanceof EE_Payment) {
1203
+                if ( ! $payment instanceof EE_Payment) {
1204 1204
                     continue;
1205
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1206
-                    $existing_reg_payments[ $payment->ID() ] = [];
1205
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1206
+                    $existing_reg_payments[$payment->ID()] = [];
1207 1207
                 }
1208 1208
                 foreach ($reg_payments as $reg_payment) {
1209 1209
                     if (
1210 1210
                         $reg_payment instanceof EE_Registration_Payment
1211 1211
                         && $reg_payment->payment_ID() === $payment->ID()
1212 1212
                     ) {
1213
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1213
+                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1214 1214
                     }
1215 1215
                 }
1216 1216
             }
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
     protected function _get_registrations_to_apply_payment_to()
1237 1237
     {
1238 1238
         // we want any registration with an active status (ie: not deleted or cancelled)
1239
-        $query_params                      = [
1239
+        $query_params = [
1240 1240
             [
1241 1241
                 'STS_ID' => [
1242 1242
                     'IN',
@@ -1248,22 +1248,22 @@  discard block
 block discarded – undo
1248 1248
                 ],
1249 1249
             ],
1250 1250
         ];
1251
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1251
+        $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div(
1252 1252
             '',
1253 1253
             'txn-admin-apply-payment-to-registrations-dv',
1254 1254
             '',
1255 1255
             'clear: both; margin: 1.5em 0 0; display: none;'
1256 1256
         );
1257
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1257
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258 1258
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259 1259
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1260 1260
             EEH_HTML::tr(
1261
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1261
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1262
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1263
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1264
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1265
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1266
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1267 1267
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268 1268
             )
1269 1269
         );
@@ -1278,34 +1278,34 @@  discard block
 block discarded – undo
1278 1278
                     : esc_html__('Unknown Attendee', 'event_espresso');
1279 1279
                 $owing                             = $registration->final_price() - $registration->paid();
1280 1280
                 $taxable                           = $registration->ticket()->taxable()
1281
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1281
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1282 1282
                     : '';
1283 1283
                 $checked                           = empty($existing_reg_payments)
1284 1284
                                                      || in_array($registration->ID(), $existing_reg_payments, true)
1285 1285
                     ? ' checked'
1286 1286
                     : '';
1287
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1287
+                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1288 1288
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1289
-                    EEH_HTML::td($registration->ID()) .
1290
-                    EEH_HTML::td($attendee_name) .
1289
+                    EEH_HTML::td($registration->ID()).
1290
+                    EEH_HTML::td($attendee_name).
1291 1291
                     EEH_HTML::td(
1292
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1293
-                    ) .
1294
-                    EEH_HTML::td($registration->event_name()) .
1295
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1292
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1293
+                    ).
1294
+                    EEH_HTML::td($registration->event_name()).
1295
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1296 1296
                     EEH_HTML::td(
1297 1297
                         EEH_Template::format_currency($owing),
1298 1298
                         '',
1299 1299
                         'txn-admin-payment-owing-td jst-cntr'
1300
-                    ) .
1300
+                    ).
1301 1301
                     EEH_HTML::td(
1302
-                        '<input type="checkbox" value="' . $registration->ID()
1302
+                        '<input type="checkbox" value="'.$registration->ID()
1303 1303
                         . '" name="txn_admin_payment[registrations]"'
1304
-                        . $checked . $disabled . '>',
1304
+                        . $checked.$disabled.'>',
1305 1305
                         '',
1306 1306
                         'jst-cntr'
1307 1307
                     ),
1308
-                    'apply-payment-registration-row-' . $registration->ID()
1308
+                    'apply-payment-registration-row-'.$registration->ID()
1309 1309
                 );
1310 1310
             }
1311 1311
         }
@@ -1320,7 +1320,7 @@  discard block
 block discarded – undo
1320 1320
             '',
1321 1321
             'clear description'
1322 1322
         );
1323
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1323
+        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1324 1324
         $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1325 1325
     }
1326 1326
 
@@ -1386,12 +1386,12 @@  discard block
 block discarded – undo
1386 1386
                 [
1387 1387
                     'OR*payment_method_for_payment' => [
1388 1388
                         'PMD_ID'    => ['IN', $payment_methods_of_payments],
1389
-                        'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1389
+                        'PMD_scope' => ['LIKE', '%'.EEM_Payment_Method::scope_admin.'%'],
1390 1390
                     ],
1391 1391
                 ],
1392 1392
             ];
1393 1393
         } else {
1394
-            $query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1394
+            $query_args = [['PMD_scope' => ['LIKE', '%'.EEM_Payment_Method::scope_admin.'%']]];
1395 1395
         }
1396 1396
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1397 1397
     }
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
             'Line_Item',
1425 1425
             [['LIN_type' => 'line-item']]
1426 1426
         );
1427
-        if (! empty($line_items)) {
1427
+        if ( ! empty($line_items)) {
1428 1428
             foreach ($line_items as $item) {
1429 1429
                 if ($item instanceof EE_Line_Item) {
1430 1430
                     switch ($item->OBJ_type()) {
@@ -1434,7 +1434,7 @@  discard block
 block discarded – undo
1434 1434
                             $ticket = $item->ticket();
1435 1435
                             // right now we're only handling tickets here.
1436 1436
                             // Cause its expected that only tickets will have attendees right?
1437
-                            if (! $ticket instanceof EE_Ticket) {
1437
+                            if ( ! $ticket instanceof EE_Ticket) {
1438 1438
                                 break;
1439 1439
                             }
1440 1440
                             try {
@@ -1443,45 +1443,45 @@  discard block
 block discarded – undo
1443 1443
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1444 1444
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1445 1445
                             }
1446
-                            $event_name   .= ' - ' . $item->name();
1446
+                            $event_name   .= ' - '.$item->name();
1447 1447
                             $ticket_price = EEH_Template::format_currency($item->unit_price());
1448 1448
                             // now get all of the registrations for this transaction that use this ticket
1449 1449
                             $registrations = $ticket->registrations(
1450 1450
                                 [['TXN_ID' => $this->_transaction->ID()]]
1451 1451
                             );
1452 1452
                             foreach ($registrations as $registration) {
1453
-                                if (! $registration instanceof EE_Registration) {
1453
+                                if ( ! $registration instanceof EE_Registration) {
1454 1454
                                     break;
1455 1455
                                 }
1456
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1456
+                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1457 1457
                                     = $registration->status_ID();
1458
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1458
+                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1459 1459
                                     = $registration->count();
1460
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1460
+                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1461 1461
                                     = $event_name;
1462
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1462
+                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1463 1463
                                     = $ticket_price;
1464 1464
                                 // attendee info
1465 1465
                                 $attendee = $registration->get_first_related('Attendee');
1466 1466
                                 if ($attendee instanceof EE_Attendee) {
1467
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1467
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1468 1468
                                         = $attendee->ID();
1469
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1469
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1470 1470
                                         = $attendee->full_name();
1471
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1472
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1471
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1472
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1473 1473
                                           . esc_html__(
1474 1474
                                               ' Event',
1475 1475
                                               'event_espresso'
1476 1476
                                           )
1477
-                                          . '">' . $attendee->email() . '</a>';
1478
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1477
+                                          . '">'.$attendee->email().'</a>';
1478
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1479 1479
                                         = EEH_Address::format($attendee, 'inline', false, false);
1480 1480
                                 } else {
1481
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1482
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1483
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1481
+                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1482
+                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1483
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1484
+                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1485 1485
                                 }
1486 1486
                             }
1487 1487
                             break;
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
                 TXN_ADMIN_URL
1498 1498
             );
1499 1499
             echo EEH_Template::display_template(
1500
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1500
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1501 1501
                 $this->_template_args,
1502 1502
                 true
1503 1503
             );
@@ -1532,7 +1532,7 @@  discard block
 block discarded – undo
1532 1532
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1533 1533
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1534 1534
             : null;
1535
-        if (! $primary_att instanceof EE_Attendee) {
1535
+        if ( ! $primary_att instanceof EE_Attendee) {
1536 1536
             $this->_template_args['no_attendee_message'] = esc_html__(
1537 1537
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1538 1538
                 'event_espresso'
@@ -1554,7 +1554,7 @@  discard block
 block discarded – undo
1554 1554
         // get formatted address for registrant
1555 1555
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1556 1556
         echo EEH_Template::display_template(
1557
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1557
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1558 1558
             $this->_template_args,
1559 1559
             true
1560 1560
         );
@@ -1580,7 +1580,7 @@  discard block
 block discarded – undo
1580 1580
             TXN_ADMIN_URL
1581 1581
         );
1582 1582
 
1583
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1583
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1584 1584
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585 1585
     }
1586 1586
 
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
             'ee_edit_payments',
1607 1607
             'apply_payment_or_refund_from_registration_details'
1608 1608
         );
1609
-        if (! empty($valid_data) && $has_access) {
1609
+        if ( ! empty($valid_data) && $has_access) {
1610 1610
             $PAY_ID = $valid_data['PAY_ID'];
1611 1611
             // save  the new payment
1612 1612
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1619,7 +1619,7 @@  discard block
 block discarded – undo
1619 1619
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620 1620
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1621 1621
                 // apply payment to registrations (if applicable)
1622
-                if (! empty($REG_IDs)) {
1622
+                if ( ! empty($REG_IDs)) {
1623 1623
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624 1624
                     $this->_maybe_send_notifications();
1625 1625
                     // now process status changes for the same registrations
@@ -1665,7 +1665,7 @@  discard block
 block discarded – undo
1665 1665
                 __LINE__
1666 1666
             );
1667 1667
         }
1668
-        $notices              = EE_Error::get_notices(
1668
+        $notices = EE_Error::get_notices(
1669 1669
             false,
1670 1670
             false,
1671 1671
             false
@@ -1690,14 +1690,14 @@  discard block
 block discarded – undo
1690 1690
      */
1691 1691
     protected function _validate_payment_request_data()
1692 1692
     {
1693
-        if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1693
+        if ( ! $this->request->requestParamIsSet('txn_admin_payment')) {
1694 1694
             return [];
1695 1695
         }
1696 1696
         $payment_form = $this->_generate_payment_form_section();
1697 1697
         try {
1698 1698
             if ($payment_form->was_submitted()) {
1699 1699
                 $payment_form->receive_form_submission();
1700
-                if (! $payment_form->is_valid()) {
1700
+                if ( ! $payment_form->is_valid()) {
1701 1701
                     $submission_error_messages = [];
1702 1702
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703 1703
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1879,7 +1879,7 @@  discard block
 block discarded – undo
1879 1879
             ['Y-m-d', 'g:i a']
1880 1880
         );
1881 1881
 
1882
-        if (! $payment->save()) {
1882
+        if ( ! $payment->save()) {
1883 1883
             EE_Error::add_error(
1884 1884
                 sprintf(
1885 1885
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -2081,12 +2081,12 @@  discard block
 block discarded – undo
2081 2081
         // but add in some conditions regarding payment,
2082 2082
         // so that we don't apply payments to registrations that are free or have already been paid for
2083 2083
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2084
-        if (! $payment->is_a_refund()) {
2084
+        if ( ! $payment->is_a_refund()) {
2085 2085
             $registration_query_where_params['REG_final_price']  = ['!=', 0];
2086 2086
             $registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2087 2087
         }
2088 2088
         $registrations = $transaction->registrations([$registration_query_where_params]);
2089
-        if (! empty($registrations)) {
2089
+        if ( ! empty($registrations)) {
2090 2090
             /** @type EE_Payment_Processor $payment_processor */
2091 2091
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2092 2092
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
             'pay_status'       => $payment->STS_ID(),
2169 2169
             'PAY_ID'           => $payment->ID(),
2170 2170
             'STS_ID'           => $payment->STS_ID(),
2171
-            'status'           => self::$_pay_status[ $payment->STS_ID() ],
2171
+            'status'           => self::$_pay_status[$payment->STS_ID()],
2172 2172
             'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2173 2173
             'method'           => strtoupper($payment->source()),
2174 2174
             'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
@@ -2287,11 +2287,11 @@  discard block
 block discarded – undo
2287 2287
     {
2288 2288
         $registration_payment_data = [];
2289 2289
         // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2290
-        if (! empty($REG_IDs)) {
2290
+        if ( ! empty($REG_IDs)) {
2291 2291
             $registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2292 2292
             foreach ($registrations as $registration) {
2293 2293
                 if ($registration instanceof EE_Registration) {
2294
-                    $registration_payment_data[ $registration->ID() ] = [
2294
+                    $registration_payment_data[$registration->ID()] = [
2295 2295
                         'paid'  => $registration->pretty_paid(),
2296 2296
                         'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2297 2297
                     ];
@@ -2347,7 +2347,7 @@  discard block
 block discarded – undo
2347 2347
         $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2348 2348
         $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2349 2349
         $redirect_to = $this->request->getRequestParam('redirect_to');
2350
-        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2350
+        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID, ] : [];
2351 2351
         do_action(
2352 2352
             'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2353 2353
             $transaction
@@ -2385,8 +2385,8 @@  discard block
 block discarded – undo
2385 2385
         );
2386 2386
 
2387 2387
         // make sure our timestamps start and end right at the boundaries for each day
2388
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2389
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2388
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2389
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2390 2390
 
2391 2391
 
2392 2392
         // convert to timestamps
@@ -2403,7 +2403,7 @@  discard block
 block discarded – undo
2403 2403
             date('Y-m-d H:i:s', $start_date),
2404 2404
             'Y-m-d H:i:s'
2405 2405
         );
2406
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2406
+        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2407 2407
             'TXN_timestamp',
2408 2408
             date('Y-m-d H:i:s', $end_date),
2409 2409
             'Y-m-d H:i:s'
@@ -2447,8 +2447,8 @@  discard block
 block discarded – undo
2447 2447
 
2448 2448
         $search_term = $this->request->getRequestParam('s');
2449 2449
         if ($search_term) {
2450
-            $search_term = '%' . $search_term . '%';
2451
-            $_where['OR']  = [
2450
+            $search_term = '%'.$search_term.'%';
2451
+            $_where['OR'] = [
2452 2452
                 'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2453 2453
                 'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2454 2454
                 'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
@@ -2475,9 +2475,9 @@  discard block
 block discarded – undo
2475 2475
 
2476 2476
         $status = $this->request->getRequestParam('status');
2477 2477
         // failed transactions
2478
-        $failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
-        $abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
-        $incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2478
+        $failed     = ( ! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
+        $abandoned  = ( ! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
+        $incomplete = ( ! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2481 2481
 
2482 2482
         if ($failed) {
2483 2483
             $_where['STS_ID'] = EEM_Transaction::failed_status_code;
@@ -2525,7 +2525,7 @@  discard block
 block discarded – undo
2525 2525
         $transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2526 2526
         $success         = $transaction->recalculateLineItems();
2527 2527
         $redirect_to = $this->request->getRequestParam('redirect_to');
2528
-        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2528
+        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID, ] : [];
2529 2529
         $this->_redirect_after_action(
2530 2530
             $success,
2531 2531
             esc_html__('Transaction taxes and totals', 'event_espresso'),
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_migration_page.template.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -36,55 +36,55 @@  discard block
 block discarded – undo
36 36
             <h3 class="espresso-header">
37 37
                 <span class="dashicons dashicons-flag ee-icon-size-22"></span>
38 38
                 <?php
39
-                echo esc_html(
40
-                    apply_filters(
41
-                        'FHEE__ee_migration_page__header',
42
-                        sprintf(
43
-                            __("Your Event Espresso data needs to be updated.", "event_espresso"),
44
-                            $current_db_state,
45
-                            $next_db_state
46
-                        ),
47
-                        $current_db_state,
48
-                        $next_db_state
49
-                    )
50
-                );
51
-                ?>
39
+				echo esc_html(
40
+					apply_filters(
41
+						'FHEE__ee_migration_page__header',
42
+						sprintf(
43
+							__("Your Event Espresso data needs to be updated.", "event_espresso"),
44
+							$current_db_state,
45
+							$next_db_state
46
+						),
47
+						$current_db_state,
48
+						$next_db_state
49
+					)
50
+				);
51
+				?>
52 52
             </h3>
53 53
         <?php } elseif ($show_most_recent_migration) { ?>
54 54
             <h3 class="espresso-header">
55 55
                 <span class="dashicons dashicons-awards ee-icon-size-22"></span>
56 56
                 <?php echo esc_html(
57
-                    apply_filters(
58
-                        'FHEE__ee_migration_page__done_migration_header',
59
-                        sprintf(
60
-                            __(
61
-                                'Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
62
-                                "event_espresso"
63
-                            ),
64
-                            $ultimate_db_state
65
-                        )
66
-                    )
67
-                ); ?>
57
+					apply_filters(
58
+						'FHEE__ee_migration_page__done_migration_header',
59
+						sprintf(
60
+							__(
61
+								'Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
62
+								"event_espresso"
63
+							),
64
+							$ultimate_db_state
65
+						)
66
+					)
67
+				); ?>
68 68
             </h3>
69 69
             <p>
70 70
                 <?php echo esc_html(
71
-                    apply_filters(
72
-                        'FHEE__ee_migration_page__p_after_done_migration_header',
73
-                        sprintf(
74
-                            __(
75
-                                "Time to find out about all the great new features %s has to offer.",
76
-                                "event_espresso"
77
-                            ),
78
-                            $ultimate_db_state
79
-                        )
80
-                    )
81
-                ); ?> &nbsp;
71
+					apply_filters(
72
+						'FHEE__ee_migration_page__p_after_done_migration_header',
73
+						sprintf(
74
+							__(
75
+								"Time to find out about all the great new features %s has to offer.",
76
+								"event_espresso"
77
+							),
78
+							$ultimate_db_state
79
+						)
80
+					)
81
+				); ?> &nbsp;
82 82
                 <b>
83 83
                     <a class="button-primary"
84 84
                        id='get-started-after-migrate'
85 85
                        href="<?php
86
-                        echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php')));
87
-                        ?>"
86
+						echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php')));
87
+						?>"
88 88
                     >
89 89
                         <?php esc_html_e("Let's Get Started", "event_espresso"); ?>&nbsp;
90 90
                         <span class="dashicons dashicons-arrow-right ee-icon-size-22" style="margin:0;"></span>
@@ -95,46 +95,46 @@  discard block
 block discarded – undo
95 95
 
96 96
 
97 97
         <?php
98
-        if ($show_backup_db_text) {
99
-            echo wp_kses($migration_options_html, AllowedTags::getAllowedTags());
100
-        } ?>
98
+		if ($show_backup_db_text) {
99
+			echo wp_kses($migration_options_html, AllowedTags::getAllowedTags());
100
+		} ?>
101 101
 
102 102
         <?php
103
-        if ($show_most_recent_migration) {
104
-            if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) {
105
-                if ($most_recent_migration->can_continue()) {
106
-                    // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
103
+		if ($show_most_recent_migration) {
104
+			if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) {
105
+				if ($most_recent_migration->can_continue()) {
106
+					// tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
107 107
                     <h3 class="espresso-header">
108 108
                         <span class="dashicons dashicons-star-half ee-icon-size-22"></span>
109 109
                         <?php printf(
110
-                            esc_html__(
111
-                                "It appears that your previous Database Update (%s) is incomplete, and should be resumed",
112
-                                "event_espresso"
113
-                            ),
114
-                            $most_recent_migration->pretty_name()
115
-                        ); ?>
110
+							esc_html__(
111
+								"It appears that your previous Database Update (%s) is incomplete, and should be resumed",
112
+								"event_espresso"
113
+							),
114
+							$most_recent_migration->pretty_name()
115
+						); ?>
116 116
                     </h3>
117 117
                     <?php
118
-                } elseif ($most_recent_migration->is_broken()) {
119
-                    // tell the user the migration failed, and they should notify EE?>
118
+				} elseif ($most_recent_migration->is_broken()) {
119
+					// tell the user the migration failed, and they should notify EE?>
120 120
                     <h3 class="espresso-header">
121 121
                         <span class="dashicons dashicons-no ee-icon-size-22"></span>
122 122
                         <?php echo esc_html($most_recent_migration->get_feedback_message()) ?>
123 123
                     </h3>
124 124
                     <?php
125
-                }
126
-                // display errors or not of the most recent migration ran
127
-                if ($most_recent_migration->get_errors()) {
128
-                    ?>
125
+				}
126
+				// display errors or not of the most recent migration ran
127
+				if ($most_recent_migration->get_errors()) {
128
+					?>
129 129
                     <div class="ee-attention">
130 130
                         <strong>
131 131
                             <?php printf(
132
-                                esc_html__(
133
-                                    "Warnings occurred during your last Database Update (%s):",
134
-                                    'event_espresso'
135
-                                ),
136
-                                $most_recent_migration->pretty_name()
137
-                            ); ?>
132
+								esc_html__(
133
+									"Warnings occurred during your last Database Update (%s):",
134
+									'event_espresso'
135
+								),
136
+								$most_recent_migration->pretty_name()
137
+							); ?>
138 138
                         </strong>
139 139
                         <a id="show-hide-migration-warnings" class="display-the-hidden">
140 140
                             <?php esc_html_e("Show Warnings", 'event_espresso'); ?>
@@ -146,32 +146,32 @@  discard block
 block discarded – undo
146 146
                         </ul>
147 147
                     </div>
148 148
                     <?php
149
-                } else {
150
-                    // there were no errors during the last migration, just say so?>
149
+				} else {
150
+					// there were no errors during the last migration, just say so?>
151 151
                     <h2>
152 152
                         <?php printf(
153
-                            esc_html__(
154
-                                "The last Database Update (%s) ran successfully without errors.",
155
-                                "event_espresso"
156
-                            ),
157
-                            $most_recent_migration->pretty_name()
158
-                        ); ?>
153
+							esc_html__(
154
+								"The last Database Update (%s) ran successfully without errors.",
155
+								"event_espresso"
156
+							),
157
+							$most_recent_migration->pretty_name()
158
+						); ?>
159 159
                     </h2>
160 160
                     <?php
161
-                }
162
-            }
163
-        }
164
-        // end of: if ( $show_most_recent_migration )
165
-        ?>
161
+				}
162
+			}
163
+		}
164
+		// end of: if ( $show_most_recent_migration )
165
+		?>
166 166
 
167 167
     </div>
168 168
     <!--end of #migration-prep-->
169 169
 
170 170
     <?php
171
-    if ($show_migration_progress) { ?>
171
+	if ($show_migration_progress) { ?>
172 172
         <div id='migration-monitor' <?php echo ($show_backup_db_text ? "style='display:none'" : ''); ?>>
173 173
             <?php
174
-            if ($show_backup_db_text) { ?>
174
+			if ($show_backup_db_text) { ?>
175 175
                 <p>
176 176
                     <a class="toggle-migration-monitor small-text" style="cursor: pointer;">
177 177
                         <span class="dashicons dashicons-arrow-left-alt2" style="top:0;"></span>
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
 
182 182
                 </p>
183 183
                 <?php
184
-            } ?>
184
+			} ?>
185 185
             <div id='progress-area'>
186 186
                 <h3 class="espresso-header">
187 187
                     <?php
188
-                    echo sprintf(
189
-                        _n(
190
-                            "The following task needs to be performed:",
191
-                            "The following %s tasks need to be performed:",
192
-                            count($script_names),
193
-                            "event_espresso"
194
-                        ),
195
-                        count($script_names)
196
-                    ); ?>
188
+					echo sprintf(
189
+						_n(
190
+							"The following task needs to be performed:",
191
+							"The following %s tasks need to be performed:",
192
+							count($script_names),
193
+							"event_espresso"
194
+						),
195
+						count($script_names)
196
+					); ?>
197 197
                 </h3>
198 198
                 <ul style="list-style: inside;">
199 199
                     <?php foreach ($script_names as $script_name) { ?>
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
                 <?php if (count($script_names) > 1) { ?>
205 205
                     <p>
206 206
                         <?php esc_html_e(
207
-                            "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.",
208
-                            "event_espresso"
209
-                        ); ?>
207
+							"Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.",
208
+							"event_espresso"
209
+						); ?>
210 210
                     </p>
211 211
                 <?php } ?>
212 212
 
@@ -217,19 +217,19 @@  discard block
 block discarded – undo
217 217
                         </span>
218 218
                         <br />
219 219
                         <?php esc_html_e(
220
-                            "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.",
221
-                            "event_espresso"
222
-                        ); ?>
220
+							"Depending on the number of events and the complexity of the information in your database, this could take a few minutes.",
221
+							"event_espresso"
222
+						); ?>
223 223
                     </p>
224 224
                     <p>
225 225
                         <?php printf(
226
-                            esc_html__(
227
-                                "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.",
228
-                                "event_espresso"
229
-                            ),
230
-                            '<strong>',
231
-                            '</strong>'
232
-                        ); ?>
226
+							esc_html__(
227
+								"%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.",
228
+								"event_espresso"
229
+							),
230
+							'<strong>',
231
+							'</strong>'
232
+						); ?>
233 233
                     </p>
234 234
                     <p>
235 235
                         <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?>
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 
246 246
                 <button id='start-migration' class='button-primary'>
247 247
                     <?php echo ($show_continue_current_migration_script
248
-                        ? esc_html__("Continue Database Update", "event_espresso")
249
-                        : esc_html__("Begin Database Update", "event_espresso")); ?>
248
+						? esc_html__("Continue Database Update", "event_espresso")
249
+						: esc_html__("Begin Database Update", "event_espresso")); ?>
250 250
                 </button>
251 251
                 <br class="clear" />
252 252
 
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
         </div>
263 263
 
264 264
         <?php
265
-    }
266
-    if ($show_maintenance_switch) {
267
-        ?>
265
+	}
266
+	if ($show_maintenance_switch) {
267
+		?>
268 268
         <h2>
269 269
             <span class="dashicons dashicons-admin-tools"></span>
270 270
             <?php esc_html_e('Set Event Espresso Maintenance Mode', 'event_espresso'); ?>
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
                                    type='radio'
280 280
                                    value="0"
281 281
                                 <?php echo ($mMode_level === EE_Maintenance_Mode::level_0_not_in_maintenance
282
-                                    ? 'checked'
283
-                                    : '');
284
-                                ?>
282
+									? 'checked'
283
+									: '');
284
+								?>
285 285
                             />
286 286
                         </td>
287 287
                         <th align="left">
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
                             </label>
291 291
                             <p class='description' style="font-weight: normal;">
292 292
                                 <?php esc_html_e(
293
-                                    "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.",
294
-                                    "event_espresso"
295
-                                ); ?>
293
+									"This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.",
294
+									"event_espresso"
295
+								); ?>
296 296
                             </p>
297 297
                         </th>
298 298
                     </tr>
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
                                    type='radio'
304 304
                                    value="1"
305 305
                                 <?php echo ($mMode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance
306
-                                    ? 'checked'
307
-                                    : '');
308
-                                ?>
306
+									? 'checked'
307
+									: '');
308
+								?>
309 309
                             />
310 310
                         </td>
311 311
                         <th align="left">
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
                             </label>
315 315
                             <p class='description' style="font-weight: normal;">
316 316
                                 <?php esc_html_e(
317
-                                    "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.",
318
-                                    "event_espresso"
319
-                                ); ?>
317
+									"This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.",
318
+									"event_espresso"
319
+								); ?>
320 320
                             </p>
321 321
                         </th>
322 322
                     </tr>
@@ -330,6 +330,6 @@  discard block
 block discarded – undo
330 330
             </p>
331 331
         </form>
332 332
         <?php
333
-    } ?>
333
+	} ?>
334 334
 
335 335
 </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -17,2682 +17,2682 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Messages_Admin_Page extends EE_Admin_Page
19 19
 {
20
-    /**
21
-     * @var EEM_Message
22
-     */
23
-    private $MSG_MODEL;
24
-
25
-    /**
26
-     * @var EEM_Message_Template
27
-     */
28
-    private $MTP_MODEL;
29
-
30
-    /**
31
-     * @var EEM_Message_Template_Group
32
-     */
33
-    private $MTG_MODEL;
34
-
35
-    /**
36
-     * @var EE_Message_Resource_Manager $_message_resource_manager
37
-     */
38
-    protected $_message_resource_manager;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $_active_message_type_name = '';
44
-
45
-    /**
46
-     * @var string
47
-     */
48
-    protected $_active_messenger_name = '';
49
-
50
-    /**
51
-     * @var EE_messenger $_active_messenger
52
-     */
53
-    protected $_active_messenger;
54
-
55
-    protected $_activate_meta_box_type;
56
-
57
-    protected $_current_message_meta_box;
58
-
59
-    protected $_current_message_meta_box_object;
60
-
61
-    protected $_context_switcher;
62
-
63
-    protected $_shortcodes           = [];
64
-
65
-    protected $_active_messengers    = [];
66
-
67
-    protected $_active_message_types = [];
68
-
69
-    /**
70
-     * @var EE_Message_Template_Group $_message_template_group
71
-     */
72
-    protected $_message_template_group;
73
-
74
-    protected $_m_mt_settings = [];
75
-
76
-
77
-    /**
78
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
-     * IF there is no group then it gets automatically set to the Default template pack.
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @var EE_Messages_Template_Pack
84
-     */
85
-    protected $_template_pack;
86
-
87
-
88
-    /**
89
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
-     * group is.  If there is no group then it automatically gets set to default.
91
-     *
92
-     * @since 4.5.0
93
-     *
94
-     * @var string
95
-     */
96
-    protected $_variation;
97
-
98
-
99
-    /**
100
-     * @param bool $routing
101
-     * @throws EE_Error
102
-     * @throws ReflectionException
103
-     */
104
-    public function __construct($routing = true)
105
-    {
106
-        // make sure messages autoloader is running
107
-        EED_Messages::set_autoloaders();
108
-        parent::__construct($routing);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Message
114
-     * @throws EE_Error
115
-     */
116
-    public function getMsgModel()
117
-    {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
119
-            $this->MSG_MODEL = EEM_Message::instance();
120
-        }
121
-        return $this->MSG_MODEL;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return EEM_Message_Template
127
-     * @throws EE_Error
128
-     */
129
-    public function getMtpModel()
130
-    {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
-            $this->MTP_MODEL = EEM_Message_Template::instance();
133
-        }
134
-        return $this->MTP_MODEL;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EEM_Message_Template_Group
140
-     * @throws EE_Error
141
-     */
142
-    public function getMtgModel()
143
-    {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
-        }
147
-        return $this->MTG_MODEL;
148
-    }
149
-
150
-
151
-    /**
152
-     * @throws EE_Error
153
-     * @throws ReflectionException
154
-     */
155
-    protected function _init_page_props()
156
-    {
157
-        $this->page_slug        = EE_MSG_PG_SLUG;
158
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
-        $this->_admin_base_path = EE_MSG_ADMIN;
161
-
162
-        $messenger    = $this->request->getRequestParam('messenger', '');
163
-        $message_type = $this->request->getRequestParam('message_type', '');
164
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
-
167
-        $this->_load_message_resource_manager();
168
-    }
169
-
170
-
171
-    /**
172
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
-     *
174
-     * @throws EE_Error
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidInterfaceException
177
-     * @throws InvalidArgumentException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _load_message_resource_manager()
181
-    {
182
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
-    }
184
-
185
-
186
-    /**
187
-     * @return array
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     * @deprecated 4.9.9.rc.014
193
-     */
194
-    public function get_messengers_for_list_table()
195
-    {
196
-        EE_Error::doing_it_wrong(
197
-            __METHOD__,
198
-            sprintf(
199
-                esc_html__(
200
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
-                    'event_espresso'
202
-                ),
203
-                'Messages_Admin_Page::get_messengers_select_input()'
204
-            ),
205
-            '4.9.9.rc.014'
206
-        );
207
-
208
-        $m_values          = [];
209
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
-        // setup messengers for selects
211
-        $i = 1;
212
-        foreach ($active_messengers as $active_messenger) {
213
-            if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
-                $i++;
217
-            }
218
-        }
219
-
220
-        return $m_values;
221
-    }
222
-
223
-
224
-    /**
225
-     * @return array
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @deprecated 4.9.9.rc.014
231
-     */
232
-    public function get_message_types_for_list_table()
233
-    {
234
-        EE_Error::doing_it_wrong(
235
-            __METHOD__,
236
-            sprintf(
237
-                esc_html__(
238
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
-                    'event_espresso'
240
-                ),
241
-                'Messages_Admin_Page::get_message_types_select_input()'
242
-            ),
243
-            '4.9.9.rc.014'
244
-        );
245
-
246
-        $mt_values       = [];
247
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
-        $i               = 1;
249
-        foreach ($active_messages as $active_message) {
250
-            if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
-                $i++;
254
-            }
255
-        }
256
-
257
-        return $mt_values;
258
-    }
259
-
260
-
261
-    /**
262
-     * @return array
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @deprecated 4.9.9.rc.014
268
-     */
269
-    public function get_contexts_for_message_types_for_list_table()
270
-    {
271
-        EE_Error::doing_it_wrong(
272
-            __METHOD__,
273
-            sprintf(
274
-                esc_html__(
275
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
-                    'event_espresso'
277
-                ),
278
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
-            ),
280
-            '4.9.9.rc.014'
281
-        );
282
-
283
-        $contexts                = [];
284
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
-        foreach ($active_message_contexts as $active_message) {
286
-            if ($active_message instanceof EE_Message) {
287
-                $message_type = $active_message->message_type_object();
288
-                if ($message_type instanceof EE_message_type) {
289
-                    $message_type_contexts = $message_type->get_contexts();
290
-                    foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
292
-                    }
293
-                }
294
-            }
295
-        }
296
-
297
-        return $contexts;
298
-    }
299
-
300
-
301
-    /**
302
-     * Generate select input with provided messenger options array.
303
-     *
304
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
-     *                                 labels.
306
-     * @return string
307
-     * @throws EE_Error
308
-     */
309
-    public function get_messengers_select_input($messenger_options)
310
-    {
311
-        // if empty or just one value then just return an empty string
312
-        if (
313
-            empty($messenger_options)
314
-            || ! is_array($messenger_options)
315
-            || count($messenger_options) === 1
316
-        ) {
317
-            return '';
318
-        }
319
-        // merge in default
320
-        $messenger_options = array_merge(
321
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
-            $messenger_options
323
-        );
324
-        $input             = new EE_Select_Input(
325
-            $messenger_options,
326
-            [
327
-                'html_name'  => 'ee_messenger_filter_by',
328
-                'html_id'    => 'ee_messenger_filter_by',
329
-                'html_class' => 'wide',
330
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
-            ]
332
-        );
333
-
334
-        return $input->get_html_for_input();
335
-    }
336
-
337
-
338
-    /**
339
-     * Generate select input with provided message type options array.
340
-     *
341
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
-     *                                    message type labels
343
-     * @return string
344
-     * @throws EE_Error
345
-     */
346
-    public function get_message_types_select_input($message_type_options)
347
-    {
348
-        // if empty or count of options is 1 then just return an empty string
349
-        if (
350
-            empty($message_type_options)
351
-            || ! is_array($message_type_options)
352
-            || count($message_type_options) === 1
353
-        ) {
354
-            return '';
355
-        }
356
-        // merge in default
357
-        $message_type_options = array_merge(
358
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
-            $message_type_options
360
-        );
361
-        $input                = new EE_Select_Input(
362
-            $message_type_options,
363
-            [
364
-                'html_name'  => 'ee_message_type_filter_by',
365
-                'html_id'    => 'ee_message_type_filter_by',
366
-                'html_class' => 'wide',
367
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
-            ]
369
-        );
370
-
371
-        return $input->get_html_for_input();
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate select input with provide message type contexts array.
377
-     *
378
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
-     *                               context label.
380
-     * @return string
381
-     * @throws EE_Error
382
-     */
383
-    public function get_contexts_for_message_types_select_input($context_options)
384
-    {
385
-        // if empty or count of options is one then just return empty string
386
-        if (
387
-            empty($context_options)
388
-            || ! is_array($context_options)
389
-            || count($context_options) === 1
390
-        ) {
391
-            return '';
392
-        }
393
-        // merge in default
394
-        $context_options = array_merge(
395
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
-            $context_options
397
-        );
398
-        $input           = new EE_Select_Input(
399
-            $context_options,
400
-            [
401
-                'html_name'  => 'ee_context_filter_by',
402
-                'html_id'    => 'ee_context_filter_by',
403
-                'html_class' => 'wide',
404
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
-            ]
406
-        );
407
-
408
-        return $input->get_html_for_input();
409
-    }
410
-
411
-
412
-    protected function _ajax_hooks()
413
-    {
414
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
-    }
421
-
422
-
423
-    protected function _define_page_props()
424
-    {
425
-        $this->_admin_page_title = $this->page_label;
426
-        $this->_labels           = [
427
-            'buttons'    => [
428
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
-            ],
432
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
-        ];
434
-    }
435
-
436
-
437
-    /**
438
-     *        an array for storing key => value pairs of request actions and their corresponding methods
439
-     *
440
-     * @access protected
441
-     * @return void
442
-     */
443
-    protected function _set_page_routes()
444
-    {
445
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
-
449
-        $this->_page_routes = [
450
-            'default'                          => [
451
-                'func'       => '_message_queue_list_table',
452
-                'capability' => 'ee_read_global_messages',
453
-            ],
454
-            'global_mtps'                      => [
455
-                'func'       => '_ee_default_messages_overview_list_table',
456
-                'capability' => 'ee_read_global_messages',
457
-            ],
458
-            'custom_mtps'                      => [
459
-                'func'       => '_custom_mtps_preview',
460
-                'capability' => 'ee_read_messages',
461
-            ],
462
-            'add_new_message_template'         => [
463
-                'func'       => 'add_message_template',
464
-                'capability' => 'ee_edit_messages',
465
-                'noheader'   => true,
466
-            ],
467
-            'edit_message_template'            => [
468
-                'func'       => '_edit_message_template',
469
-                'capability' => 'ee_edit_message',
470
-                'obj_id'     => $GRP_ID,
471
-            ],
472
-            'preview_message'                  => [
473
-                'func'               => '_preview_message',
474
-                'capability'         => 'ee_read_message',
475
-                'obj_id'             => $GRP_ID,
476
-                'noheader'           => true,
477
-                'headers_sent_route' => 'display_preview_message',
478
-            ],
479
-            'display_preview_message'          => [
480
-                'func'       => '_display_preview_message',
481
-                'capability' => 'ee_read_message',
482
-                'obj_id'     => $GRP_ID,
483
-            ],
484
-            'insert_message_template'          => [
485
-                'func'       => '_insert_or_update_message_template',
486
-                'capability' => 'ee_edit_messages',
487
-                'args'       => ['new' => true],
488
-                'noheader'   => true,
489
-            ],
490
-            'update_message_template'          => [
491
-                'func'       => '_insert_or_update_message_template',
492
-                'capability' => 'ee_edit_message',
493
-                'obj_id'     => $GRP_ID,
494
-                'args'       => ['new' => false],
495
-                'noheader'   => true,
496
-            ],
497
-            'trash_message_template'           => [
498
-                'func'       => '_trash_or_restore_message_template',
499
-                'capability' => 'ee_delete_message',
500
-                'obj_id'     => $GRP_ID,
501
-                'args'       => ['trash' => true, 'all' => true],
502
-                'noheader'   => true,
503
-            ],
504
-            'trash_message_template_context'   => [
505
-                'func'       => '_trash_or_restore_message_template',
506
-                'capability' => 'ee_delete_message',
507
-                'obj_id'     => $GRP_ID,
508
-                'args'       => ['trash' => true],
509
-                'noheader'   => true,
510
-            ],
511
-            'restore_message_template'         => [
512
-                'func'       => '_trash_or_restore_message_template',
513
-                'capability' => 'ee_delete_message',
514
-                'obj_id'     => $GRP_ID,
515
-                'args'       => ['trash' => false, 'all' => true],
516
-                'noheader'   => true,
517
-            ],
518
-            'restore_message_template_context' => [
519
-                'func'       => '_trash_or_restore_message_template',
520
-                'capability' => 'ee_delete_message',
521
-                'obj_id'     => $GRP_ID,
522
-                'args'       => ['trash' => false],
523
-                'noheader'   => true,
524
-            ],
525
-            'delete_message_template'          => [
526
-                'func'       => '_delete_message_template',
527
-                'capability' => 'ee_delete_message',
528
-                'obj_id'     => $GRP_ID,
529
-                'noheader'   => true,
530
-            ],
531
-            'reset_to_default'                 => [
532
-                'func'       => '_reset_to_default_template',
533
-                'capability' => 'ee_edit_message',
534
-                'obj_id'     => $GRP_ID,
535
-                'noheader'   => true,
536
-            ],
537
-            'settings'                         => [
538
-                'func'       => '_settings',
539
-                'capability' => 'manage_options',
540
-            ],
541
-            'update_global_settings'           => [
542
-                'func'       => '_update_global_settings',
543
-                'capability' => 'manage_options',
544
-                'noheader'   => true,
545
-            ],
546
-            'generate_now'                     => [
547
-                'func'       => '_generate_now',
548
-                'capability' => 'ee_send_message',
549
-                'noheader'   => true,
550
-            ],
551
-            'generate_and_send_now'            => [
552
-                'func'       => '_generate_and_send_now',
553
-                'capability' => 'ee_send_message',
554
-                'noheader'   => true,
555
-            ],
556
-            'queue_for_resending'              => [
557
-                'func'       => '_queue_for_resending',
558
-                'capability' => 'ee_send_message',
559
-                'noheader'   => true,
560
-            ],
561
-            'send_now'                         => [
562
-                'func'       => '_send_now',
563
-                'capability' => 'ee_send_message',
564
-                'noheader'   => true,
565
-            ],
566
-            'delete_ee_message'                => [
567
-                'func'       => '_delete_ee_messages',
568
-                'capability' => 'ee_delete_messages',
569
-                'noheader'   => true,
570
-            ],
571
-            'delete_ee_messages'               => [
572
-                'func'       => '_delete_ee_messages',
573
-                'capability' => 'ee_delete_messages',
574
-                'noheader'   => true,
575
-                'obj_id'     => $MSG_ID,
576
-            ],
577
-        ];
578
-    }
579
-
580
-
581
-    protected function _set_page_config()
582
-    {
583
-        $this->_page_config = [
584
-            'default'                  => [
585
-                'nav'           => [
586
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
587
-                    'order' => 10,
588
-                ],
589
-                'list_table'    => 'EE_Message_List_Table',
590
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
-                'require_nonce' => false,
592
-            ],
593
-            'global_mtps'              => [
594
-                'nav'           => [
595
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
-                    'order' => 20,
597
-                ],
598
-                'list_table'    => 'Messages_Template_List_Table',
599
-                'help_tabs'     => [
600
-                    'messages_overview_help_tab'                                => [
601
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
-                        'filename' => 'messages_overview',
603
-                    ],
604
-                    'messages_overview_messages_table_column_headings_help_tab' => [
605
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
-                        'filename' => 'messages_overview_table_column_headings',
607
-                    ],
608
-                    'messages_overview_messages_filters_help_tab'               => [
609
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
610
-                        'filename' => 'messages_overview_filters',
611
-                    ],
612
-                    'messages_overview_messages_views_help_tab'                 => [
613
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
614
-                        'filename' => 'messages_overview_views',
615
-                    ],
616
-                    'message_overview_message_types_help_tab'                   => [
617
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
618
-                        'filename' => 'messages_overview_types',
619
-                    ],
620
-                    'messages_overview_messengers_help_tab'                     => [
621
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
622
-                        'filename' => 'messages_overview_messengers',
623
-                    ],
624
-                ],
625
-                'require_nonce' => false,
626
-            ],
627
-            'custom_mtps'              => [
628
-                'nav'           => [
629
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
-                    'order' => 30,
631
-                ],
632
-                'help_tabs'     => [],
633
-                'require_nonce' => false,
634
-            ],
635
-            'add_new_message_template' => [
636
-                'nav'           => [
637
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
-                    'order'      => 5,
639
-                    'persistent' => false,
640
-                ],
641
-                'require_nonce' => false,
642
-            ],
643
-            'edit_message_template'    => [
644
-                'labels'        => [
645
-                    'buttons'    => [
646
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
-                    ],
648
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
-                ],
650
-                'nav'           => [
651
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
-                    'order'      => 5,
653
-                    'persistent' => false,
654
-                    'url'        => '',
655
-                ],
656
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
-                'has_metaboxes' => true,
658
-                'help_tabs'     => [
659
-                    'edit_message_template'            => [
660
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
-                        'callback' => 'edit_message_template_help_tab',
662
-                    ],
663
-                    'message_templates_help_tab'       => [
664
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
665
-                        'filename' => 'messages_templates',
666
-                    ],
667
-                    'message_template_shortcodes'      => [
668
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
-                        'callback' => 'message_template_shortcodes_help_tab',
670
-                    ],
671
-                    'message_preview_help_tab'         => [
672
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
673
-                        'filename' => 'messages_preview',
674
-                    ],
675
-                    'messages_overview_other_help_tab' => [
676
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
677
-                        'filename' => 'messages_overview_other',
678
-                    ],
679
-                ],
680
-                'require_nonce' => false,
681
-            ],
682
-            'display_preview_message'  => [
683
-                'nav'           => [
684
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
685
-                    'order'      => 5,
686
-                    'url'        => '',
687
-                    'persistent' => false,
688
-                ],
689
-                'help_tabs'     => [
690
-                    'preview_message' => [
691
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
692
-                        'callback' => 'preview_message_help_tab',
693
-                    ],
694
-                ],
695
-                'require_nonce' => false,
696
-            ],
697
-            'settings'                 => [
698
-                'nav'           => [
699
-                    'label' => esc_html__('Settings', 'event_espresso'),
700
-                    'order' => 40,
701
-                ],
702
-                'metaboxes'     => ['_messages_settings_metaboxes'],
703
-                'help_tabs'     => [
704
-                    'messages_settings_help_tab'               => [
705
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
-                        'filename' => 'messages_settings',
707
-                    ],
708
-                    'messages_settings_message_types_help_tab' => [
709
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
-                        'filename' => 'messages_settings_message_types',
711
-                    ],
712
-                    'messages_settings_messengers_help_tab'    => [
713
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
-                        'filename' => 'messages_settings_messengers',
715
-                    ],
716
-                ],
717
-                'require_nonce' => false,
718
-            ],
719
-        ];
720
-    }
721
-
722
-
723
-    protected function _add_screen_options()
724
-    {
725
-        // todo
726
-    }
727
-
728
-
729
-    protected function _add_screen_options_global_mtps()
730
-    {
731
-        /**
732
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
734
-         */
735
-        $page_title              = $this->_admin_page_title;
736
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
-        $this->_per_page_screen_option();
738
-        $this->_admin_page_title = $page_title;
739
-    }
740
-
741
-
742
-    protected function _add_screen_options_default()
743
-    {
744
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
-        $this->_per_page_screen_option();
746
-    }
747
-
748
-
749
-    // none of the below group are currently used for Messages
750
-    protected function _add_feature_pointers()
751
-    {
752
-    }
753
-
754
-
755
-    public function admin_init()
756
-    {
757
-    }
758
-
759
-
760
-    public function admin_notices()
761
-    {
762
-    }
763
-
764
-
765
-    public function admin_footer_scripts()
766
-    {
767
-    }
768
-
769
-
770
-    public function messages_help_tab()
771
-    {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
-    }
774
-
775
-
776
-    public function messengers_help_tab()
777
-    {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
-    }
780
-
781
-
782
-    public function message_types_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function messages_overview_help_tab()
789
-    {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
-    }
792
-
793
-
794
-    public function message_templates_help_tab()
795
-    {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
-    }
798
-
799
-
800
-    public function edit_message_template_help_tab()
801
-    {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
-                        . esc_attr__('Editor Title', 'event_espresso')
804
-                        . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
807
-                        . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
810
-                        . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
813
-                        . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
-                        . esc_attr__('Publish Metabox', 'event_espresso')
816
-                        . '" />';
817
-        EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
-            $args
820
-        );
821
-    }
822
-
823
-
824
-    /**
825
-     * @throws ReflectionException
826
-     * @throws EE_Error
827
-     */
828
-    public function message_template_shortcodes_help_tab()
829
-    {
830
-        $this->_set_shortcodes();
831
-        $args['shortcodes'] = $this->_shortcodes;
832
-        EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
-            $args
835
-        );
836
-    }
837
-
838
-
839
-    public function preview_message_help_tab()
840
-    {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
-    }
843
-
844
-
845
-    public function settings_help_tab()
846
-    {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
-        $args['img3'] = '<div class="switch">'
852
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
-                        . ' type="checkbox" checked>'
854
-                        . '<label for="ee-on-off-toggle-on"></label>'
855
-                        . '</div>';
856
-        $args['img4'] = '<div class="switch">'
857
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
-                        . ' type="checkbox">'
859
-                        . '<label for="ee-on-off-toggle-on"></label>'
860
-                        . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
-    }
863
-
864
-
865
-    public function load_scripts_styles()
866
-    {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
-        wp_enqueue_style('espresso_ee_msg');
869
-
870
-        wp_register_script(
871
-            'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
874
-            EVENT_ESPRESSO_VERSION,
875
-            true
876
-        );
877
-        wp_register_script(
878
-            'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
-            ['ee-dialog'],
881
-            EVENT_ESPRESSO_VERSION
882
-        );
883
-    }
884
-
885
-
886
-    public function load_scripts_styles_default()
887
-    {
888
-        wp_enqueue_script('ee-msg-list-table-js');
889
-    }
890
-
891
-
892
-    public function wp_editor_css($mce_css)
893
-    {
894
-        // if we're on the edit_message_template route
895
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
-            $message_type_name = $this->_active_message_type_name;
897
-
898
-            // we're going to REPLACE the existing mce css
899
-            // we need to get the css file location from the active messenger
900
-            $mce_css = $this->_active_messenger->get_variation(
901
-                $this->_template_pack,
902
-                $message_type_name,
903
-                true,
904
-                'wpeditor',
905
-                $this->_variation
906
-            );
907
-        }
908
-
909
-        return $mce_css;
910
-    }
911
-
912
-
913
-    /**
914
-     * @throws EE_Error
915
-     * @throws ReflectionException
916
-     */
917
-    public function load_scripts_styles_edit_message_template()
918
-    {
919
-
920
-        $this->_set_shortcodes();
921
-
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
-            esc_html__(
924
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
-                'event_espresso'
926
-            ),
927
-            $this->_message_template_group->messenger_obj()->label['singular'],
928
-            $this->_message_template_group->message_type_obj()->label['singular']
929
-        );
930
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
-            'event_espresso'
933
-        );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
-            'event_espresso'
937
-        );
938
-
939
-        wp_register_script(
940
-            'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
-            ['jquery'],
943
-            EVENT_ESPRESSO_VERSION
944
-        );
945
-
946
-        wp_enqueue_script('ee_admin_js');
947
-        wp_enqueue_script('ee_msgs_edit_js');
948
-
949
-        // add in special css for tiny_mce
950
-        add_filter('mce_css', [$this, 'wp_editor_css']);
951
-    }
952
-
953
-
954
-    /**
955
-     * @throws EE_Error
956
-     * @throws ReflectionException
957
-     */
958
-    public function load_scripts_styles_display_preview_message()
959
-    {
960
-        $this->_set_message_template_group();
961
-        if ($this->_active_messenger_name) {
962
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
-                $this->_active_messenger_name
964
-            );
965
-        }
966
-
967
-        wp_enqueue_style(
968
-            'espresso_preview_css',
969
-            $this->_active_messenger->get_variation(
970
-                $this->_template_pack,
971
-                $this->_active_message_type_name,
972
-                true,
973
-                'preview',
974
-                $this->_variation
975
-            )
976
-        );
977
-    }
978
-
979
-
980
-    public function load_scripts_styles_settings()
981
-    {
982
-        wp_register_style(
983
-            'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
-            [],
986
-            EVENT_ESPRESSO_VERSION
987
-        );
988
-        wp_enqueue_style('ee-text-links');
989
-        wp_enqueue_style('ee-message-settings');
990
-        wp_enqueue_script('ee-messages-settings');
991
-    }
992
-
993
-
994
-    /**
995
-     * set views array for List Table
996
-     */
997
-    public function _set_list_table_views_global_mtps()
998
-    {
999
-        $this->_views = [
1000
-            'in_use' => [
1001
-                'slug'  => 'in_use',
1002
-                'label' => esc_html__('In Use', 'event_espresso'),
1003
-                'count' => 0,
1004
-            ],
1005
-        ];
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Set views array for the Custom Template List Table
1011
-     */
1012
-    public function _set_list_table_views_custom_mtps()
1013
-    {
1014
-        $this->_set_list_table_views_global_mtps();
1015
-        $this->_views['in_use']['bulk_action'] = [
1016
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
-        ];
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * set views array for message queue list table
1023
-     *
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidInterfaceException
1026
-     * @throws InvalidArgumentException
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function _set_list_table_views_default()
1031
-    {
1032
-        EE_Registry::instance()->load_helper('Template');
1033
-
1034
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
-            'ee_send_message',
1036
-            'message_list_table_bulk_actions'
1037
-        )
1038
-            ? [
1039
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
-            ]
1044
-            : [];
1045
-
1046
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_delete_messages',
1048
-            'message_list_table_bulk_actions'
1049
-        )
1050
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
-            : [];
1052
-
1053
-
1054
-        $this->_views = [
1055
-            'all' => [
1056
-                'slug'        => 'all',
1057
-                'label'       => esc_html__('All', 'event_espresso'),
1058
-                'count'       => 0,
1059
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
-            ],
1061
-        ];
1062
-
1063
-
1064
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
-                continue;
1067
-            }
1068
-            $status_bulk_actions = $common_bulk_actions;
1069
-            // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1071
-                switch ($status) {
1072
-                    case EEM_Message::status_idle:
1073
-                    case EEM_Message::status_resend:
1074
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
-                        break;
1076
-
1077
-                    case EEM_Message::status_failed:
1078
-                    case EEM_Message::status_debug_only:
1079
-                    case EEM_Message::status_messenger_executing:
1080
-                        $status_bulk_actions = [];
1081
-                        break;
1082
-
1083
-                    case EEM_Message::status_incomplete:
1084
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
-                        break;
1086
-
1087
-                    case EEM_Message::status_retry:
1088
-                    case EEM_Message::status_sent:
1089
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
-                        break;
1091
-                }
1092
-            }
1093
-
1094
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1095
-            if ($status === EEM_Message::status_messenger_executing) {
1096
-                continue;
1097
-            }
1098
-
1099
-            $this->_views[ strtolower($status) ] = [
1100
-                'slug'        => strtolower($status),
1101
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
-                'count'       => 0,
1103
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
-            ];
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * @throws EE_Error
1111
-     */
1112
-    protected function _ee_default_messages_overview_list_table()
1113
-    {
1114
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * @throws EE_Error
1121
-     * @throws ReflectionException
1122
-     */
1123
-    protected function _message_queue_list_table()
1124
-    {
1125
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
-        $this->_template_args['per_column']        = 6;
1127
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
-        $this->_template_args['before_list_table'] = '<h3>'
1129
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1130
-                                                     . '</h3>';
1131
-        $this->display_admin_list_table_page_with_no_sidebar();
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * @throws EE_Error
1137
-     */
1138
-    protected function _message_legend_items()
1139
-    {
1140
-
1141
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
-        $action_items       = [];
1143
-
1144
-        foreach ($action_css_classes as $action_item => $action_details) {
1145
-            if ($action_item === 'see_notifications_for') {
1146
-                continue;
1147
-            }
1148
-            $action_items[ $action_item ] = [
1149
-                'class' => $action_details['css_class'],
1150
-                'desc'  => $action_details['label'],
1151
-            ];
1152
-        }
1153
-
1154
-        /** @var array $status_items status legend setup */
1155
-        $status_items = [
1156
-            'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
-            ],
1160
-            'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
-            ],
1164
-            'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
-            ],
1168
-            'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
-            ],
1172
-            'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
-            ],
1176
-            'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
-            ],
1180
-            'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
-            ],
1184
-        ];
1185
-        if (EEM_Message::debug()) {
1186
-            $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
-            ];
1190
-        }
1191
-
1192
-        return array_merge($action_items, $status_items);
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @throws EE_Error
1198
-     */
1199
-    protected function _custom_mtps_preview()
1200
-    {
1201
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1204
-                                                    'Preview Custom Message Templates screenshot',
1205
-                                                    'event_espresso'
1206
-                                                ) . '" />';
1207
-        $this->_template_args['preview_text'] = '<strong>'
1208
-                                                . esc_html__(
1209
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
-                                                    'event_espresso'
1211
-                                                )
1212
-                                                . '</strong>';
1213
-
1214
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * get_message_templates
1220
-     * This gets all the message templates for listing on the overview list.
1221
-     *
1222
-     * @access public
1223
-     * @param int    $per_page the amount of templates groups to show per page
1224
-     * @param string $type     the current _view we're getting templates for
1225
-     * @param bool   $count    return count?
1226
-     * @param bool   $all      disregard any paging info (get all data);
1227
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws InvalidArgumentException
1231
-     * @throws InvalidDataTypeException
1232
-     * @throws InvalidInterfaceException
1233
-     */
1234
-    public function get_message_templates(
1235
-        $per_page = 10,
1236
-        $type = 'in_use',
1237
-        $count = false,
1238
-        $all = false,
1239
-        $global = true
1240
-    ) {
1241
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
-        $this->request->setRequestParam('orderby', $orderby);
1243
-
1244
-        $order        = $this->request->getRequestParam('order', 'ASC');
1245
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
-
1248
-        $offset = ($current_page - 1) * $per_page;
1249
-        $limit  = $all ? null : [$offset, $per_page];
1250
-
1251
-        // options will match what is in the _views array property
1252
-        return $type === 'in_use'
1253
-            ? $this->getMtgModel()->get_all_active_message_templates(
1254
-                $orderby,
1255
-                $order,
1256
-                $limit,
1257
-                $count,
1258
-                $global,
1259
-                true
1260
-            )
1261
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
-                $orderby,
1263
-                $order,
1264
-                $limit,
1265
-                $count,
1266
-                $global
1267
-            );
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * filters etc might need a list of installed message_types
1273
-     *
1274
-     * @return array an array of message type objects
1275
-     */
1276
-    public function get_installed_message_types()
1277
-    {
1278
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
-        $installed               = [];
1280
-
1281
-        foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1283
-        }
1284
-
1285
-        return $installed;
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1291
-     *
1292
-     * @param string $message_type
1293
-     * @param string $messenger
1294
-     * @param string $GRP_ID
1295
-     *
1296
-     * @throws EE_error
1297
-     * @throws ReflectionException
1298
-     */
1299
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
-    {
1301
-        // set values override any request data
1302
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
-
1306
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
-        if (empty($message_type) || empty($messenger)) {
1308
-            throw new EE_Error(
1309
-                esc_html__(
1310
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
-                    'event_espresso'
1312
-                )
1313
-            );
1314
-        }
1315
-
1316
-        // we need the GRP_ID for the template being used as the base for the new template
1317
-        if (empty($GRP_ID)) {
1318
-            throw new EE_Error(
1319
-                esc_html__(
1320
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
-                    'event_espresso'
1322
-                )
1323
-            );
1324
-        }
1325
-
1326
-        // let's just make sure the template gets generated!
1327
-
1328
-        // we need to reassign some variables for what the insert is expecting
1329
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1330
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1331
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
-
1333
-        $this->_insert_or_update_message_template(true);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * @param string $message_type     message type slug
1339
-     * @param string $messenger        messenger slug
1340
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
-     *                                 off of.
1342
-     * @throws EE_error
1343
-     * @throws ReflectionException
1344
-     * @deprecated 4.10.29.p
1345
-     */
1346
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
-    {
1348
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1349
-    }
1350
-
1351
-
1352
-    /**
1353
-     * _edit_message_template
1354
-     *
1355
-     * @access protected
1356
-     * @return void
1357
-     * @throws InvalidIdentifierException
1358
-     * @throws DomainException
1359
-     * @throws EE_Error
1360
-     * @throws InvalidArgumentException
1361
-     * @throws ReflectionException
1362
-     * @throws InvalidDataTypeException
1363
-     * @throws InvalidInterfaceException
1364
-     */
1365
-    protected function _edit_message_template()
1366
-    {
1367
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
-        $template_fields = '';
1369
-        $sidebar_fields  = '';
1370
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
-        // valid html in the templates.
1372
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
-
1374
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
-
1377
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1378
-        $message_template_group = $this->_message_template_group;
1379
-        $c_label                = $message_template_group->context_label();
1380
-        $c_config               = $message_template_group->contexts_config();
1381
-
1382
-        reset($c_config);
1383
-        $context = $this->request->getRequestParam('context', key($c_config));
1384
-        $context = strtolower($context);
1385
-
1386
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
-
1388
-        $edit_message_template_form_url = add_query_arg(
1389
-            ['action' => $action, 'noheader' => true],
1390
-            EE_MSG_ADMIN_URL
1391
-        );
1392
-
1393
-        // set active messenger for this view
1394
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
-            $message_template_group->messenger()
1396
-        );
1397
-        $this->_active_message_type_name = $message_template_group->message_type();
1398
-
1399
-
1400
-        // Do we have any validation errors?
1401
-        $validators = $this->_get_transient();
1402
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
-
1404
-
1405
-        // we need to assemble the title from Various details
1406
-        $context_label = sprintf(
1407
-            esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1409
-            ucwords($c_label['label'])
1410
-        );
1411
-
1412
-        $title = sprintf(
1413
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1414
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1415
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1416
-            $context_label
1417
-        );
1418
-
1419
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1420
-        $this->_template_args['message_template'] = $message_template_group;
1421
-        $this->_template_args['is_extra_fields']  = false;
1422
-
1423
-
1424
-        // let's get EEH_MSG_Template so we can get template form fields
1425
-        $template_field_structure = EEH_MSG_Template::get_fields(
1426
-            $message_template_group->messenger(),
1427
-            $message_template_group->message_type()
1428
-        );
1429
-
1430
-        if (! $template_field_structure) {
1431
-            $template_field_structure = false;
1432
-            $template_fields          = esc_html__(
1433
-                'There was an error in assembling the fields for this display (you should see an error message)',
1434
-                'event_espresso'
1435
-            );
1436
-        }
1437
-
1438
-
1439
-        $message_templates = $message_template_group->context_templates();
1440
-
1441
-
1442
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
-        // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1447
-            }
1448
-        }
1449
-
1450
-        // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
-                // the extra array and reset them.
1455
-                if ($template_field === 'extra') {
1456
-                    $this->_template_args['is_extra_fields'] = true;
1457
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1459
-                        $content          = $message_template instanceof EE_Message_Template
1460
-                            ? $message_template->get('MTP_content')
1461
-                            : '';
1462
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1463
-                            // let's verify if we need this extra field via the shortcodes parameter.
1464
-                            $continue = false;
1465
-                            if (isset($extra_array['shortcodes_required'])) {
1466
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
-                                        $continue = true;
1469
-                                    }
1470
-                                }
1471
-                                if ($continue) {
1472
-                                    continue;
1473
-                                }
1474
-                            }
1475
-
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1477
-
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
-                                                                         . $reference_field
1481
-                                                                         . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1484
-                                ? $extra_array['css_class']
1485
-                                : '';
1486
-
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
-                                                                              && in_array($extra_field, $v_fields, true)
1489
-                                                                              && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1492
-                                                                              )
1493
-                                ? 'validate-error ' . $css_class
1494
-                                : $css_class;
1495
-
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1499
-                                : '';
1500
-
1501
-                            // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1505
-
1506
-
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
-
1509
-                            // shortcode selector
1510
-                            $field_name_to_use                                   = $extra_field === 'main'
1511
-                                ? 'content'
1512
-                                : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
-                                $field_name_to_use,
1515
-                                $field_id
1516
-                            );
1517
-                        }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1520
-
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
-                            'label'      => null,
1524
-                            'input'      => 'hidden',
1525
-                            'type'       => 'int',
1526
-                            'required'   => false,
1527
-                            'validation' => false,
1528
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
-                            'css_class'  => '',
1530
-                            'format'     => '%d',
1531
-                            'db-col'     => 'MTP_ID',
1532
-                        ];
1533
-
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
-                            'label'      => null,
1537
-                            'input'      => 'hidden',
1538
-                            'type'       => 'string',
1539
-                            'required'   => false,
1540
-                            'validation' => true,
1541
-                            'value'      => $reference_field,
1542
-                            'css_class'  => '',
1543
-                            'format'     => '%s',
1544
-                            'db-col'     => 'MTP_template_field',
1545
-                        ];
1546
-                    }
1547
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
-                } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1553
-                    $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1556
-                            : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1559
-                                                                  && $message_template instanceof EE_Message_Template
1560
-                        ? $message_template->get('MTP_content')
1561
-                        : '';
1562
-
1563
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1567
-
1568
-
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
-                    $css_class                                      = isset($field_setup_array['css_class'])
1571
-                        ? $field_setup_array['css_class']
1572
-                        : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
-                                                                      && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1577
-                        : $css_class;
1578
-
1579
-                    // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
-                        $template_field,
1582
-                        $field_id
1583
-                    );
1584
-                }
1585
-
1586
-                // k took care of content field(s) now let's take care of others.
1587
-
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1590
-
1591
-                // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
-                    'label'      => null,
1595
-                    'input'      => 'hidden',
1596
-                    'type'       => 'int',
1597
-                    'required'   => false,
1598
-                    'validation' => true,
1599
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
-                    'css_class'  => '',
1601
-                    'format'     => '%d',
1602
-                    'db-col'     => 'MTP_ID',
1603
-                ];
1604
-
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
-                    'label'      => null,
1608
-                    'input'      => 'hidden',
1609
-                    'type'       => 'string',
1610
-                    'required'   => false,
1611
-                    'validation' => true,
1612
-                    'value'      => $template_field,
1613
-                    'css_class'  => '',
1614
-                    'format'     => '%s',
1615
-                    'db-col'     => 'MTP_template_field',
1616
-                ];
1617
-            }
1618
-
1619
-            // add other fields
1620
-            $template_form_fields['ee-msg-current-context'] = [
1621
-                'name'       => 'MTP_context',
1622
-                'label'      => null,
1623
-                'input'      => 'hidden',
1624
-                'type'       => 'string',
1625
-                'required'   => false,
1626
-                'validation' => true,
1627
-                'value'      => $context,
1628
-                'css_class'  => '',
1629
-                'format'     => '%s',
1630
-                'db-col'     => 'MTP_context',
1631
-            ];
1632
-
1633
-            $template_form_fields['ee-msg-grp-id'] = [
1634
-                'name'       => 'GRP_ID',
1635
-                'label'      => null,
1636
-                'input'      => 'hidden',
1637
-                'type'       => 'int',
1638
-                'required'   => false,
1639
-                'validation' => true,
1640
-                'value'      => $GRP_ID,
1641
-                'css_class'  => '',
1642
-                'format'     => '%d',
1643
-                'db-col'     => 'GRP_ID',
1644
-            ];
1645
-
1646
-            $template_form_fields['ee-msg-messenger'] = [
1647
-                'name'       => 'MTP_messenger',
1648
-                'label'      => null,
1649
-                'input'      => 'hidden',
1650
-                'type'       => 'string',
1651
-                'required'   => false,
1652
-                'validation' => true,
1653
-                'value'      => $message_template_group->messenger(),
1654
-                'css_class'  => '',
1655
-                'format'     => '%s',
1656
-                'db-col'     => 'MTP_messenger',
1657
-            ];
1658
-
1659
-            $template_form_fields['ee-msg-message-type'] = [
1660
-                'name'       => 'MTP_message_type',
1661
-                'label'      => null,
1662
-                'input'      => 'hidden',
1663
-                'type'       => 'string',
1664
-                'required'   => false,
1665
-                'validation' => true,
1666
-                'value'      => $message_template_group->message_type(),
1667
-                'css_class'  => '',
1668
-                'format'     => '%s',
1669
-                'db-col'     => 'MTP_message_type',
1670
-            ];
1671
-
1672
-            $sidebar_form_fields['ee-msg-is-global'] = [
1673
-                'name'       => 'MTP_is_global',
1674
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1675
-                'input'      => 'hidden',
1676
-                'type'       => 'int',
1677
-                'required'   => false,
1678
-                'validation' => true,
1679
-                'value'      => $message_template_group->get('MTP_is_global'),
1680
-                'css_class'  => '',
1681
-                'format'     => '%d',
1682
-                'db-col'     => 'MTP_is_global',
1683
-            ];
1684
-
1685
-            $sidebar_form_fields['ee-msg-is-override'] = [
1686
-                'name'       => 'MTP_is_override',
1687
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
-                'type'       => 'int',
1690
-                'required'   => false,
1691
-                'validation' => true,
1692
-                'value'      => $message_template_group->get('MTP_is_override'),
1693
-                'css_class'  => '',
1694
-                'format'     => '%d',
1695
-                'db-col'     => 'MTP_is_override',
1696
-            ];
1697
-
1698
-            $sidebar_form_fields['ee-msg-is-active'] = [
1699
-                'name'       => 'MTP_is_active',
1700
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1701
-                'input'      => 'hidden',
1702
-                'type'       => 'int',
1703
-                'required'   => false,
1704
-                'validation' => true,
1705
-                'value'      => $message_template_group->is_active(),
1706
-                'css_class'  => '',
1707
-                'format'     => '%d',
1708
-                'db-col'     => 'MTP_is_active',
1709
-            ];
1710
-
1711
-            $sidebar_form_fields['ee-msg-deleted'] = [
1712
-                'name'       => 'MTP_deleted',
1713
-                'label'      => null,
1714
-                'input'      => 'hidden',
1715
-                'type'       => 'int',
1716
-                'required'   => false,
1717
-                'validation' => true,
1718
-                'value'      => $message_template_group->get('MTP_deleted'),
1719
-                'css_class'  => '',
1720
-                'format'     => '%d',
1721
-                'db-col'     => 'MTP_deleted',
1722
-            ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1724
-                'name'       => 'MTP_user_id',
1725
-                'label'      => esc_html__('Author', 'event_espresso'),
1726
-                'input'      => 'hidden',
1727
-                'type'       => 'int',
1728
-                'required'   => false,
1729
-                'validation' => false,
1730
-                'value'      => $message_template_group->user(),
1731
-                'format'     => '%d',
1732
-                'db-col'     => 'MTP_user_id',
1733
-            ];
1734
-
1735
-            $sidebar_form_fields['ee-msg-route'] = [
1736
-                'name'  => 'action',
1737
-                'input' => 'hidden',
1738
-                'type'  => 'string',
1739
-                'value' => $action,
1740
-            ];
1741
-
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1743
-                'name'  => 'id',
1744
-                'input' => 'hidden',
1745
-                'type'  => 'int',
1746
-                'value' => $GRP_ID,
1747
-            ];
1748
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1750
-                'input' => 'hidden',
1751
-                'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1753
-            ];
1754
-
1755
-            $template_switch = $this->request->getRequestParam('template_switch');
1756
-            if ($template_switch) {
1757
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1758
-                    'name'  => 'template_switch',
1759
-                    'input' => 'hidden',
1760
-                    'type'  => 'int',
1761
-                    'value' => 1,
1762
-                ];
1763
-            }
1764
-
1765
-
1766
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
-        } //end if ( !empty($template_field_structure) )
1769
-
1770
-        // set extra content for publish box
1771
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
-        $this->_set_publish_post_box_vars(
1773
-            'id',
1774
-            $GRP_ID,
1775
-            false,
1776
-            add_query_arg(
1777
-                ['action' => 'global_mtps'],
1778
-                $this->_admin_base_url
1779
-            )
1780
-        );
1781
-
1782
-        // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1784
-            [
1785
-                'message_type' => $message_template_group->message_type(),
1786
-                'messenger'    => $message_template_group->messenger(),
1787
-                'context'      => $context,
1788
-                'GRP_ID'       => $GRP_ID,
1789
-                'evt_id'       => $EVT_ID ?: false,
1790
-                'action'       => 'preview_message',
1791
-            ],
1792
-            $this->_admin_base_url
1793
-        );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
-                          . esc_html__('Preview', 'event_espresso')
1796
-                          . '</a>';
1797
-
1798
-
1799
-        // setup context switcher
1800
-        $this->_set_context_switcher(
1801
-            $message_template_group,
1802
-            [
1803
-                'page'    => 'espresso_messages',
1804
-                'action'  => 'edit_message_template',
1805
-                'id'      => $GRP_ID,
1806
-                'evt_id'  => $EVT_ID,
1807
-                'context' => $context,
1808
-                'extra'   => $preview_button,
1809
-            ]
1810
-        );
1811
-
1812
-
1813
-        // main box
1814
-        $this->_template_args['template_fields']                         = $template_fields;
1815
-        $this->_template_args['sidebar_box_id']                          = 'details';
1816
-        $this->_template_args['action']                                  = $action;
1817
-        $this->_template_args['context']                                 = $context;
1818
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
-        $this->_template_args['learn_more_about_message_templates_link'] =
1820
-            $this->_learn_more_about_message_templates_link();
1821
-
1822
-
1823
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
-            $message_template_group,
1826
-            $context,
1827
-            $context_label
1828
-        );
1829
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
-
1832
-        $this->_template_path = $this->_template_args['GRP_ID']
1833
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
-
1836
-        // send along EE_Message_Template_Group object for further template use.
1837
-        $this->_template_args['MTP'] = $message_template_group;
1838
-
1839
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
-            $this->_template_path,
1841
-            $this->_template_args,
1842
-            true
1843
-        );
1844
-
1845
-
1846
-        // finally, let's set the admin_page title
1847
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
-
1849
-
1850
-        // we need to take care of setting the shortcodes property for use elsewhere.
1851
-        $this->_set_shortcodes();
1852
-
1853
-
1854
-        // final template wrapper
1855
-        $this->display_admin_page_with_sidebar();
1856
-    }
1857
-
1858
-
1859
-    public function filter_tinymce_init($mceInit, $editor_id)
1860
-    {
1861
-        return $mceInit;
1862
-    }
1863
-
1864
-
1865
-    public function add_context_switcher()
1866
-    {
1867
-        return $this->_context_switcher;
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * Adds the activation/deactivation toggle for the message template context.
1873
-     *
1874
-     * @param EE_Message_Template_Group $message_template_group
1875
-     * @param string                    $context
1876
-     * @param string                    $context_label
1877
-     * @return string
1878
-     * @throws DomainException
1879
-     * @throws EE_Error
1880
-     * @throws InvalidIdentifierException
1881
-     * @throws ReflectionException
1882
-     */
1883
-    protected function add_active_context_element(
1884
-        EE_Message_Template_Group $message_template_group,
1885
-        $context,
1886
-        $context_label
1887
-    ) {
1888
-        $template_args = [
1889
-            'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
-            'is_active'                 => $message_template_group->is_context_active($context),
1892
-            'on_off_action'             => $message_template_group->is_context_active($context)
1893
-                ? 'context-off'
1894
-                : 'context-on',
1895
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
-            'message_template_group_id' => $message_template_group->ID(),
1897
-        ];
1898
-        return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
-            $template_args,
1901
-            true
1902
-        );
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * Ajax callback for `toggle_context_template` ajax action.
1908
-     * Handles toggling the message context on or off.
1909
-     *
1910
-     * @throws EE_Error
1911
-     * @throws InvalidArgumentException
1912
-     * @throws InvalidDataTypeException
1913
-     * @throws InvalidIdentifierException
1914
-     * @throws InvalidInterfaceException
1915
-     */
1916
-    public function toggle_context_template()
1917
-    {
1918
-        $success = true;
1919
-        // check for required data
1920
-        if (
1921
-            ! (
1922
-                $this->request->requestParamIsSet('message_template_group_id')
1923
-                && $this->request->requestParamIsSet('context')
1924
-                && $this->request->requestParamIsSet('status')
1925
-            )
1926
-        ) {
1927
-            EE_Error::add_error(
1928
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
-                __FILE__,
1930
-                __FUNCTION__,
1931
-                __LINE__
1932
-            );
1933
-            $success = false;
1934
-        }
1935
-
1936
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
-        $context = $this->request->getRequestParam('context', '');
1938
-        $status  = $this->request->getRequestParam('status', '');
1939
-
1940
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
-
1942
-        if ($status !== 'off' && $status !== 'on') {
1943
-            EE_Error::add_error(
1944
-                sprintf(
1945
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
-                    $status
1947
-                ),
1948
-                __FILE__,
1949
-                __FUNCTION__,
1950
-                __LINE__
1951
-            );
1952
-            $success = false;
1953
-        }
1954
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
-            EE_Error::add_error(
1958
-                sprintf(
1959
-                    esc_html__(
1960
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
-                        'event_espresso'
1962
-                    ),
1963
-                    $message_template_group_id,
1964
-                    'EE_Message_Template_Group'
1965
-                ),
1966
-                __FILE__,
1967
-                __FUNCTION__,
1968
-                __LINE__
1969
-            );
1970
-            $success = false;
1971
-        }
1972
-        if ($success) {
1973
-            $success = $status === 'off'
1974
-                ? $message_template_group->deactivate_context($context)
1975
-                : $message_template_group->activate_context($context);
1976
-        }
1977
-        $this->_template_args['success'] = $success;
1978
-        $this->_return_json();
1979
-    }
1980
-
1981
-
1982
-    public function _add_form_element_before()
1983
-    {
1984
-        return '<form method="post" action="'
1985
-               . $this->_template_args['edit_message_template_form_url']
1986
-               . '" id="ee-msg-edit-frm">';
1987
-    }
1988
-
1989
-
1990
-    public function _add_form_element_after()
1991
-    {
1992
-        return '</form>';
1993
-    }
1994
-
1995
-
1996
-    /**
1997
-     * This executes switching the template pack for a message template.
1998
-     *
1999
-     * @throws EE_Error
2000
-     * @throws InvalidDataTypeException
2001
-     * @throws InvalidInterfaceException
2002
-     * @throws InvalidArgumentException
2003
-     * @throws ReflectionException
2004
-     * @since 4.5.0
2005
-     */
2006
-    public function switch_template_pack()
2007
-    {
2008
-
2009
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2011
-
2012
-        // verify we have needed values.
2013
-        if (empty($GRP_ID) || empty($template_pack)) {
2014
-            $this->_template_args['error'] = true;
2015
-            EE_Error::add_error(
2016
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
-                __FILE__,
2018
-                __FUNCTION__,
2019
-                __LINE__
2020
-            );
2021
-        } else {
2022
-            // get template, set the new template_pack and then reset to default
2023
-            /** @var EE_Message_Template_Group $message_template_group */
2024
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
-
2026
-            $message_template_group->set_template_pack_name($template_pack);
2027
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2029
-
2030
-            $query_args = $this->_reset_to_default_template();
2031
-
2032
-            if (empty($query_args['id'])) {
2033
-                EE_Error::add_error(
2034
-                    esc_html__(
2035
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
-                        'event_espresso'
2037
-                    ),
2038
-                    __FILE__,
2039
-                    __FUNCTION__,
2040
-                    __LINE__
2041
-                );
2042
-                $this->_template_args['error'] = true;
2043
-            } else {
2044
-                $template_label       = $message_template_group->get_template_pack()->label;
2045
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
-                EE_Error::add_success(
2047
-                    sprintf(
2048
-                        esc_html__(
2049
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
-                            'event_espresso'
2051
-                        ),
2052
-                        $template_label,
2053
-                        $template_pack_labels->template_pack
2054
-                    )
2055
-                );
2056
-                // generate the redirect url for js.
2057
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
-
2059
-                $this->_template_args['data']['redirect_url'] = $url;
2060
-                $this->_template_args['success']              = true;
2061
-            }
2062
-
2063
-            $this->_return_json();
2064
-        }
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
-     * they want.
2071
-     *
2072
-     * @access protected
2073
-     * @return array|void
2074
-     * @throws EE_Error
2075
-     * @throws InvalidArgumentException
2076
-     * @throws InvalidDataTypeException
2077
-     * @throws InvalidInterfaceException
2078
-     * @throws ReflectionException
2079
-     */
2080
-    protected function _reset_to_default_template()
2081
-    {
2082
-        $templates    = [];
2083
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
-        $messenger    = $this->request->getRequestParam('msgr');
2085
-        $message_type = $this->request->getRequestParam('mt');
2086
-        // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2088
-            EE_Error::add_error(
2089
-                esc_html__(
2090
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
-                    'event_espresso'
2092
-                ),
2093
-                __FILE__,
2094
-                __FUNCTION__,
2095
-                __LINE__
2096
-            );
2097
-        }
2098
-
2099
-        // all templates will be reset to whatever the defaults are
2100
-        // for the global template matching the messenger and message type.
2101
-        $success = ! empty($GRP_ID);
2102
-
2103
-        if ($success) {
2104
-            // let's first determine if the incoming template is a global template,
2105
-            // if it isn't then we need to get the global template matching messenger and message type.
2106
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
-
2108
-
2109
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
-
2112
-            if ($success) {
2113
-                // if successfully deleted, lets generate the new ones.
2114
-                // Note. We set GLOBAL to true, because resets on ANY template
2115
-                // will use the related global template defaults for regeneration.
2116
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2117
-                // HOWEVER, we DO keep the template pack and template variation set
2118
-                // for the current custom template when resetting.
2119
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
-            }
2121
-        }
2122
-
2123
-        // any error messages?
2124
-        if (! $success) {
2125
-            EE_Error::add_error(
2126
-                esc_html__(
2127
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2128
-                    'event_espresso'
2129
-                ),
2130
-                __FILE__,
2131
-                __FUNCTION__,
2132
-                __LINE__
2133
-            );
2134
-        }
2135
-
2136
-        // all good, let's add a success message!
2137
-        if ($success && ! empty($templates)) {
2138
-            // the info for the template we generated is the first element in the returned array
2139
-            EE_Error::overwrite_success();
2140
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
-        }
2142
-
2143
-
2144
-        $query_args = [
2145
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
-        ];
2149
-
2150
-        // if called via ajax then we return query args otherwise redirect
2151
-        if ($this->request->isAjax()) {
2152
-            return $query_args;
2153
-        }
2154
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     * Retrieve and set the message preview for display.
2160
-     *
2161
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
-     * @return string
2163
-     * @throws ReflectionException
2164
-     * @throws EE_Error
2165
-     * @throws InvalidArgumentException
2166
-     * @throws InvalidDataTypeException
2167
-     * @throws InvalidInterfaceException
2168
-     */
2169
-    public function _preview_message($send = false)
2170
-    {
2171
-        // first make sure we've got the necessary parameters
2172
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
-            EE_Error::add_error(
2175
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
-                __FILE__,
2177
-                __FUNCTION__,
2178
-                __LINE__
2179
-            );
2180
-        }
2181
-
2182
-        $context = $this->request->getRequestParam('context');
2183
-        // get the preview!
2184
-        $preview = EED_Messages::preview_message(
2185
-            $this->_active_message_type_name,
2186
-            $context,
2187
-            $this->_active_messenger_name,
2188
-            $send
2189
-        );
2190
-
2191
-        if ($send) {
2192
-            return $preview;
2193
-        }
2194
-
2195
-        // if we have an evt_id set on the request, use it.
2196
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
-
2198
-        // let's add a button to go back to the edit view
2199
-        $query_args             = [
2200
-            'id'      => $GRP_ID,
2201
-            'evt_id'  => $EVT_ID,
2202
-            'context' => $context,
2203
-            'action'  => 'edit_message_template',
2204
-        ];
2205
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
-        $preview_button         = '<a href="'
2207
-                                  . $go_back_url
2208
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2209
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2210
-                                  . '</a>';
2211
-        $message_types          = $this->get_installed_message_types();
2212
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2214
-            ? ucwords($active_messenger->label['singular'])
2215
-            : esc_html__('Unknown Messenger', 'event_espresso');
2216
-        // let's provide a helpful title for context
2217
-        $preview_title = sprintf(
2218
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
-            $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
-        );
2222
-        if (empty($preview)) {
2223
-            $this->noEventsErrorMessage();
2224
-        }
2225
-        // setup display of preview.
2226
-        $this->_admin_page_title                    = $preview_title;
2227
-        $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
-        $this->_template_args['data']['force_json'] = true;
2230
-
2231
-        return '';
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * Used to set an error if there are no events available for generating a preview/test send.
2237
-     *
2238
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
-     */
2240
-    protected function noEventsErrorMessage($test_send = false)
2241
-    {
2242
-        $events_url = parent::add_query_args_and_nonce(
2243
-            [
2244
-                'action' => 'default',
2245
-                'page'   => 'espresso_events',
2246
-            ],
2247
-            admin_url('admin.php')
2248
-        );
2249
-        $message    = $test_send
2250
-            ? esc_html__(
2251
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
-                'event_espresso'
2253
-            )
2254
-            : esc_html__(
2255
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
-                'event_espresso'
2257
-            );
2258
-
2259
-        EE_Error::add_attention(
2260
-            sprintf(
2261
-                $message,
2262
-                "<a href='{$events_url}'>",
2263
-                '</a>'
2264
-            )
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    /**
2270
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
-     * gets called automatically.
2272
-     *
2273
-     * @return void
2274
-     * @throws EE_Error
2275
-     * @since 4.5.0
2276
-     *
2277
-     */
2278
-    protected function _display_preview_message()
2279
-    {
2280
-        $this->display_admin_page_with_no_sidebar();
2281
-    }
2282
-
2283
-
2284
-    /**
2285
-     * registers metaboxes that should show up on the "edit_message_template" page
2286
-     *
2287
-     * @access protected
2288
-     * @return void
2289
-     */
2290
-    protected function _register_edit_meta_boxes()
2291
-    {
2292
-        add_meta_box(
2293
-            'mtp_valid_shortcodes',
2294
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2295
-            [$this, 'shortcode_meta_box'],
2296
-            $this->_current_screen->id,
2297
-            'side'
2298
-        );
2299
-        add_meta_box(
2300
-            'mtp_extra_actions',
2301
-            esc_html__('Extra Actions', 'event_espresso'),
2302
-            [$this, 'extra_actions_meta_box'],
2303
-            $this->_current_screen->id,
2304
-            'side',
2305
-            'high'
2306
-        );
2307
-        add_meta_box(
2308
-            'mtp_templates',
2309
-            esc_html__('Template Styles', 'event_espresso'),
2310
-            [$this, 'template_pack_meta_box'],
2311
-            $this->_current_screen->id,
2312
-            'side',
2313
-            'high'
2314
-        );
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * metabox content for all template pack and variation selection.
2320
-     *
2321
-     * @return void
2322
-     * @throws DomainException
2323
-     * @throws EE_Error
2324
-     * @throws InvalidArgumentException
2325
-     * @throws ReflectionException
2326
-     * @throws InvalidDataTypeException
2327
-     * @throws InvalidInterfaceException
2328
-     * @since 4.5.0
2329
-     */
2330
-    public function template_pack_meta_box()
2331
-    {
2332
-        $this->_set_message_template_group();
2333
-
2334
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
-
2336
-        $tp_select_values = [];
2337
-
2338
-        foreach ($tp_collection as $tp) {
2339
-            // only include template packs that support this messenger and message type!
2340
-            $supports = $tp->get_supports();
2341
-            if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2343
-                || ! in_array(
2344
-                    $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2346
-                    true
2347
-                )
2348
-            ) {
2349
-                // not supported
2350
-                continue;
2351
-            }
2352
-
2353
-            $tp_select_values[] = [
2354
-                'text' => $tp->label,
2355
-                'id'   => $tp->dbref,
2356
-            ];
2357
-        }
2358
-
2359
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
-        // the default template pack.  This still allows for the odd template pack to override.
2361
-        if (empty($tp_select_values)) {
2362
-            $tp_select_values[] = [
2363
-                'text' => esc_html__('Default', 'event_espresso'),
2364
-                'id'   => 'default',
2365
-            ];
2366
-        }
2367
-
2368
-        // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
-            $this->_message_template_group->messenger(),
2371
-            $this->_message_template_group->message_type()
2372
-        );
2373
-        $variations_select_values = [];
2374
-        foreach ($variations as $variation => $label) {
2375
-            $variations_select_values[] = [
2376
-                'text' => $label,
2377
-                'id'   => $variation,
2378
-            ];
2379
-        }
2380
-
2381
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
-
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
-            'MTP_template_pack',
2385
-            $tp_select_values,
2386
-            $this->_message_template_group->get_template_pack_name()
2387
-        );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
-            'MTP_template_variation',
2390
-            $variations_select_values,
2391
-            $this->_message_template_group->get_template_pack_variation()
2392
-        );
2393
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
-
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
-
2400
-        EEH_Template::display_template($template, $template_args);
2401
-    }
2402
-
2403
-
2404
-    /**
2405
-     * This meta box holds any extra actions related to Message Templates
2406
-     * For now, this includes Resetting templates to defaults and sending a test email.
2407
-     *
2408
-     * @access  public
2409
-     * @return void
2410
-     * @throws EE_Error
2411
-     */
2412
-    public function extra_actions_meta_box()
2413
-    {
2414
-        $template_form_fields = [];
2415
-
2416
-        $extra_args = [
2417
-            'msgr'   => $this->_message_template_group->messenger(),
2418
-            'mt'     => $this->_message_template_group->message_type(),
2419
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
-        ];
2421
-        // first we need to see if there are any fields
2422
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
-
2424
-        if (! empty($fields)) {
2425
-            // yup there be fields
2426
-            foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
-                $default  = isset($config['default']) ? $config['default'] : '';
2430
-                $default  = isset($config['value']) ? $config['value'] : $default;
2431
-
2432
-                // if type is hidden and the value is empty
2433
-                // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2437
-                    ? $default
2438
-                    : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2441
-                    : $fix;
2442
-
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2445
-                    'label'      => $config['label'],
2446
-                    'input'      => $config['input'],
2447
-                    'type'       => $config['type'],
2448
-                    'required'   => $config['required'],
2449
-                    'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
-                    'css_class'  => $config['css_class'],
2452
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2453
-                    'default'    => $default,
2454
-                    'format'     => $config['format'],
2455
-                ];
2456
-            }
2457
-        }
2458
-
2459
-        $test_settings_html = ! empty($template_form_fields)
2460
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
-            : '';
2462
-
2463
-        // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2465
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
-            $test_settings_html .= 'name="test_button" value="';
2467
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2469
-        }
2470
-
2471
-        // and button
2472
-        $test_settings_html .= '<p>';
2473
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
-        $test_settings_html .= '</p>';
2475
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
-        $test_settings_html .= $this->get_action_link_or_button(
2477
-            'reset_to_default',
2478
-            'reset',
2479
-            $extra_args,
2480
-            'button-primary reset-default-button'
2481
-        );
2482
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2483
-        echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
-    }
2485
-
2486
-
2487
-    /**
2488
-     * This returns the shortcode selector skeleton for a given context and field.
2489
-     *
2490
-     * @param string $field           The name of the field retrieving shortcodes for.
2491
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
-     * @return string
2493
-     * @throws DomainException
2494
-     * @throws EE_Error
2495
-     * @throws InvalidArgumentException
2496
-     * @throws ReflectionException
2497
-     * @throws InvalidDataTypeException
2498
-     * @throws InvalidInterfaceException
2499
-     * @since 4.9.rc.000
2500
-     */
2501
-    protected function _get_shortcode_selector($field, $linked_input_id)
2502
-    {
2503
-        $template_args = [
2504
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2505
-            'fieldname'       => $field,
2506
-            'linked_input_id' => $linked_input_id,
2507
-        ];
2508
-
2509
-        return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
-            $template_args,
2512
-            true
2513
-        );
2514
-    }
2515
-
2516
-
2517
-    /**
2518
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
-     * page)
2520
-     *
2521
-     * @access public
2522
-     * @return void
2523
-     * @throws EE_Error
2524
-     * @throws InvalidArgumentException
2525
-     * @throws ReflectionException
2526
-     * @throws InvalidDataTypeException
2527
-     * @throws InvalidInterfaceException
2528
-     */
2529
-    public function shortcode_meta_box()
2530
-    {
2531
-        $shortcodes = $this->_get_shortcodes([], false);
2532
-        // just make sure the shortcodes property is set
2533
-        // $messenger = $this->_message_template_group->messenger_obj();
2534
-        // now let's set the content depending on the status of the shortcodes array
2535
-        if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
-            return;
2538
-        }
2539
-        ?>
20
+	/**
21
+	 * @var EEM_Message
22
+	 */
23
+	private $MSG_MODEL;
24
+
25
+	/**
26
+	 * @var EEM_Message_Template
27
+	 */
28
+	private $MTP_MODEL;
29
+
30
+	/**
31
+	 * @var EEM_Message_Template_Group
32
+	 */
33
+	private $MTG_MODEL;
34
+
35
+	/**
36
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
37
+	 */
38
+	protected $_message_resource_manager;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $_active_message_type_name = '';
44
+
45
+	/**
46
+	 * @var string
47
+	 */
48
+	protected $_active_messenger_name = '';
49
+
50
+	/**
51
+	 * @var EE_messenger $_active_messenger
52
+	 */
53
+	protected $_active_messenger;
54
+
55
+	protected $_activate_meta_box_type;
56
+
57
+	protected $_current_message_meta_box;
58
+
59
+	protected $_current_message_meta_box_object;
60
+
61
+	protected $_context_switcher;
62
+
63
+	protected $_shortcodes           = [];
64
+
65
+	protected $_active_messengers    = [];
66
+
67
+	protected $_active_message_types = [];
68
+
69
+	/**
70
+	 * @var EE_Message_Template_Group $_message_template_group
71
+	 */
72
+	protected $_message_template_group;
73
+
74
+	protected $_m_mt_settings = [];
75
+
76
+
77
+	/**
78
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
79
+	 * IF there is no group then it gets automatically set to the Default template pack.
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @var EE_Messages_Template_Pack
84
+	 */
85
+	protected $_template_pack;
86
+
87
+
88
+	/**
89
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
90
+	 * group is.  If there is no group then it automatically gets set to default.
91
+	 *
92
+	 * @since 4.5.0
93
+	 *
94
+	 * @var string
95
+	 */
96
+	protected $_variation;
97
+
98
+
99
+	/**
100
+	 * @param bool $routing
101
+	 * @throws EE_Error
102
+	 * @throws ReflectionException
103
+	 */
104
+	public function __construct($routing = true)
105
+	{
106
+		// make sure messages autoloader is running
107
+		EED_Messages::set_autoloaders();
108
+		parent::__construct($routing);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Message
114
+	 * @throws EE_Error
115
+	 */
116
+	public function getMsgModel()
117
+	{
118
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
119
+			$this->MSG_MODEL = EEM_Message::instance();
120
+		}
121
+		return $this->MSG_MODEL;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return EEM_Message_Template
127
+	 * @throws EE_Error
128
+	 */
129
+	public function getMtpModel()
130
+	{
131
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
132
+			$this->MTP_MODEL = EEM_Message_Template::instance();
133
+		}
134
+		return $this->MTP_MODEL;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EEM_Message_Template_Group
140
+	 * @throws EE_Error
141
+	 */
142
+	public function getMtgModel()
143
+	{
144
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
146
+		}
147
+		return $this->MTG_MODEL;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @throws EE_Error
153
+	 * @throws ReflectionException
154
+	 */
155
+	protected function _init_page_props()
156
+	{
157
+		$this->page_slug        = EE_MSG_PG_SLUG;
158
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
159
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
160
+		$this->_admin_base_path = EE_MSG_ADMIN;
161
+
162
+		$messenger    = $this->request->getRequestParam('messenger', '');
163
+		$message_type = $this->request->getRequestParam('message_type', '');
164
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
165
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
166
+
167
+		$this->_load_message_resource_manager();
168
+	}
169
+
170
+
171
+	/**
172
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
173
+	 *
174
+	 * @throws EE_Error
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidInterfaceException
177
+	 * @throws InvalidArgumentException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _load_message_resource_manager()
181
+	{
182
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return array
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 * @deprecated 4.9.9.rc.014
193
+	 */
194
+	public function get_messengers_for_list_table()
195
+	{
196
+		EE_Error::doing_it_wrong(
197
+			__METHOD__,
198
+			sprintf(
199
+				esc_html__(
200
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
201
+					'event_espresso'
202
+				),
203
+				'Messages_Admin_Page::get_messengers_select_input()'
204
+			),
205
+			'4.9.9.rc.014'
206
+		);
207
+
208
+		$m_values          = [];
209
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
210
+		// setup messengers for selects
211
+		$i = 1;
212
+		foreach ($active_messengers as $active_messenger) {
213
+			if ($active_messenger instanceof EE_Message) {
214
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
215
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
216
+				$i++;
217
+			}
218
+		}
219
+
220
+		return $m_values;
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return array
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @deprecated 4.9.9.rc.014
231
+	 */
232
+	public function get_message_types_for_list_table()
233
+	{
234
+		EE_Error::doing_it_wrong(
235
+			__METHOD__,
236
+			sprintf(
237
+				esc_html__(
238
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
239
+					'event_espresso'
240
+				),
241
+				'Messages_Admin_Page::get_message_types_select_input()'
242
+			),
243
+			'4.9.9.rc.014'
244
+		);
245
+
246
+		$mt_values       = [];
247
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
248
+		$i               = 1;
249
+		foreach ($active_messages as $active_message) {
250
+			if ($active_message instanceof EE_Message) {
251
+				$mt_values[ $i ]['id']   = $active_message->message_type();
252
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
253
+				$i++;
254
+			}
255
+		}
256
+
257
+		return $mt_values;
258
+	}
259
+
260
+
261
+	/**
262
+	 * @return array
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @deprecated 4.9.9.rc.014
268
+	 */
269
+	public function get_contexts_for_message_types_for_list_table()
270
+	{
271
+		EE_Error::doing_it_wrong(
272
+			__METHOD__,
273
+			sprintf(
274
+				esc_html__(
275
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
276
+					'event_espresso'
277
+				),
278
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
279
+			),
280
+			'4.9.9.rc.014'
281
+		);
282
+
283
+		$contexts                = [];
284
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
285
+		foreach ($active_message_contexts as $active_message) {
286
+			if ($active_message instanceof EE_Message) {
287
+				$message_type = $active_message->message_type_object();
288
+				if ($message_type instanceof EE_message_type) {
289
+					$message_type_contexts = $message_type->get_contexts();
290
+					foreach ($message_type_contexts as $context => $context_details) {
291
+						$contexts[ $context ] = $context_details['label'];
292
+					}
293
+				}
294
+			}
295
+		}
296
+
297
+		return $contexts;
298
+	}
299
+
300
+
301
+	/**
302
+	 * Generate select input with provided messenger options array.
303
+	 *
304
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
305
+	 *                                 labels.
306
+	 * @return string
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_messengers_select_input($messenger_options)
310
+	{
311
+		// if empty or just one value then just return an empty string
312
+		if (
313
+			empty($messenger_options)
314
+			|| ! is_array($messenger_options)
315
+			|| count($messenger_options) === 1
316
+		) {
317
+			return '';
318
+		}
319
+		// merge in default
320
+		$messenger_options = array_merge(
321
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322
+			$messenger_options
323
+		);
324
+		$input             = new EE_Select_Input(
325
+			$messenger_options,
326
+			[
327
+				'html_name'  => 'ee_messenger_filter_by',
328
+				'html_id'    => 'ee_messenger_filter_by',
329
+				'html_class' => 'wide',
330
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
331
+			]
332
+		);
333
+
334
+		return $input->get_html_for_input();
335
+	}
336
+
337
+
338
+	/**
339
+	 * Generate select input with provided message type options array.
340
+	 *
341
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
342
+	 *                                    message type labels
343
+	 * @return string
344
+	 * @throws EE_Error
345
+	 */
346
+	public function get_message_types_select_input($message_type_options)
347
+	{
348
+		// if empty or count of options is 1 then just return an empty string
349
+		if (
350
+			empty($message_type_options)
351
+			|| ! is_array($message_type_options)
352
+			|| count($message_type_options) === 1
353
+		) {
354
+			return '';
355
+		}
356
+		// merge in default
357
+		$message_type_options = array_merge(
358
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359
+			$message_type_options
360
+		);
361
+		$input                = new EE_Select_Input(
362
+			$message_type_options,
363
+			[
364
+				'html_name'  => 'ee_message_type_filter_by',
365
+				'html_id'    => 'ee_message_type_filter_by',
366
+				'html_class' => 'wide',
367
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
368
+			]
369
+		);
370
+
371
+		return $input->get_html_for_input();
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate select input with provide message type contexts array.
377
+	 *
378
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
379
+	 *                               context label.
380
+	 * @return string
381
+	 * @throws EE_Error
382
+	 */
383
+	public function get_contexts_for_message_types_select_input($context_options)
384
+	{
385
+		// if empty or count of options is one then just return empty string
386
+		if (
387
+			empty($context_options)
388
+			|| ! is_array($context_options)
389
+			|| count($context_options) === 1
390
+		) {
391
+			return '';
392
+		}
393
+		// merge in default
394
+		$context_options = array_merge(
395
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396
+			$context_options
397
+		);
398
+		$input           = new EE_Select_Input(
399
+			$context_options,
400
+			[
401
+				'html_name'  => 'ee_context_filter_by',
402
+				'html_id'    => 'ee_context_filter_by',
403
+				'html_class' => 'wide',
404
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
405
+			]
406
+		);
407
+
408
+		return $input->get_html_for_input();
409
+	}
410
+
411
+
412
+	protected function _ajax_hooks()
413
+	{
414
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
415
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
416
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
417
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
418
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
419
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
420
+	}
421
+
422
+
423
+	protected function _define_page_props()
424
+	{
425
+		$this->_admin_page_title = $this->page_label;
426
+		$this->_labels           = [
427
+			'buttons'    => [
428
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
429
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
430
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
431
+			],
432
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
433
+		];
434
+	}
435
+
436
+
437
+	/**
438
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
439
+	 *
440
+	 * @access protected
441
+	 * @return void
442
+	 */
443
+	protected function _set_page_routes()
444
+	{
445
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
446
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
447
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
448
+
449
+		$this->_page_routes = [
450
+			'default'                          => [
451
+				'func'       => '_message_queue_list_table',
452
+				'capability' => 'ee_read_global_messages',
453
+			],
454
+			'global_mtps'                      => [
455
+				'func'       => '_ee_default_messages_overview_list_table',
456
+				'capability' => 'ee_read_global_messages',
457
+			],
458
+			'custom_mtps'                      => [
459
+				'func'       => '_custom_mtps_preview',
460
+				'capability' => 'ee_read_messages',
461
+			],
462
+			'add_new_message_template'         => [
463
+				'func'       => 'add_message_template',
464
+				'capability' => 'ee_edit_messages',
465
+				'noheader'   => true,
466
+			],
467
+			'edit_message_template'            => [
468
+				'func'       => '_edit_message_template',
469
+				'capability' => 'ee_edit_message',
470
+				'obj_id'     => $GRP_ID,
471
+			],
472
+			'preview_message'                  => [
473
+				'func'               => '_preview_message',
474
+				'capability'         => 'ee_read_message',
475
+				'obj_id'             => $GRP_ID,
476
+				'noheader'           => true,
477
+				'headers_sent_route' => 'display_preview_message',
478
+			],
479
+			'display_preview_message'          => [
480
+				'func'       => '_display_preview_message',
481
+				'capability' => 'ee_read_message',
482
+				'obj_id'     => $GRP_ID,
483
+			],
484
+			'insert_message_template'          => [
485
+				'func'       => '_insert_or_update_message_template',
486
+				'capability' => 'ee_edit_messages',
487
+				'args'       => ['new' => true],
488
+				'noheader'   => true,
489
+			],
490
+			'update_message_template'          => [
491
+				'func'       => '_insert_or_update_message_template',
492
+				'capability' => 'ee_edit_message',
493
+				'obj_id'     => $GRP_ID,
494
+				'args'       => ['new' => false],
495
+				'noheader'   => true,
496
+			],
497
+			'trash_message_template'           => [
498
+				'func'       => '_trash_or_restore_message_template',
499
+				'capability' => 'ee_delete_message',
500
+				'obj_id'     => $GRP_ID,
501
+				'args'       => ['trash' => true, 'all' => true],
502
+				'noheader'   => true,
503
+			],
504
+			'trash_message_template_context'   => [
505
+				'func'       => '_trash_or_restore_message_template',
506
+				'capability' => 'ee_delete_message',
507
+				'obj_id'     => $GRP_ID,
508
+				'args'       => ['trash' => true],
509
+				'noheader'   => true,
510
+			],
511
+			'restore_message_template'         => [
512
+				'func'       => '_trash_or_restore_message_template',
513
+				'capability' => 'ee_delete_message',
514
+				'obj_id'     => $GRP_ID,
515
+				'args'       => ['trash' => false, 'all' => true],
516
+				'noheader'   => true,
517
+			],
518
+			'restore_message_template_context' => [
519
+				'func'       => '_trash_or_restore_message_template',
520
+				'capability' => 'ee_delete_message',
521
+				'obj_id'     => $GRP_ID,
522
+				'args'       => ['trash' => false],
523
+				'noheader'   => true,
524
+			],
525
+			'delete_message_template'          => [
526
+				'func'       => '_delete_message_template',
527
+				'capability' => 'ee_delete_message',
528
+				'obj_id'     => $GRP_ID,
529
+				'noheader'   => true,
530
+			],
531
+			'reset_to_default'                 => [
532
+				'func'       => '_reset_to_default_template',
533
+				'capability' => 'ee_edit_message',
534
+				'obj_id'     => $GRP_ID,
535
+				'noheader'   => true,
536
+			],
537
+			'settings'                         => [
538
+				'func'       => '_settings',
539
+				'capability' => 'manage_options',
540
+			],
541
+			'update_global_settings'           => [
542
+				'func'       => '_update_global_settings',
543
+				'capability' => 'manage_options',
544
+				'noheader'   => true,
545
+			],
546
+			'generate_now'                     => [
547
+				'func'       => '_generate_now',
548
+				'capability' => 'ee_send_message',
549
+				'noheader'   => true,
550
+			],
551
+			'generate_and_send_now'            => [
552
+				'func'       => '_generate_and_send_now',
553
+				'capability' => 'ee_send_message',
554
+				'noheader'   => true,
555
+			],
556
+			'queue_for_resending'              => [
557
+				'func'       => '_queue_for_resending',
558
+				'capability' => 'ee_send_message',
559
+				'noheader'   => true,
560
+			],
561
+			'send_now'                         => [
562
+				'func'       => '_send_now',
563
+				'capability' => 'ee_send_message',
564
+				'noheader'   => true,
565
+			],
566
+			'delete_ee_message'                => [
567
+				'func'       => '_delete_ee_messages',
568
+				'capability' => 'ee_delete_messages',
569
+				'noheader'   => true,
570
+			],
571
+			'delete_ee_messages'               => [
572
+				'func'       => '_delete_ee_messages',
573
+				'capability' => 'ee_delete_messages',
574
+				'noheader'   => true,
575
+				'obj_id'     => $MSG_ID,
576
+			],
577
+		];
578
+	}
579
+
580
+
581
+	protected function _set_page_config()
582
+	{
583
+		$this->_page_config = [
584
+			'default'                  => [
585
+				'nav'           => [
586
+					'label' => esc_html__('Message Activity', 'event_espresso'),
587
+					'order' => 10,
588
+				],
589
+				'list_table'    => 'EE_Message_List_Table',
590
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
591
+				'require_nonce' => false,
592
+			],
593
+			'global_mtps'              => [
594
+				'nav'           => [
595
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
596
+					'order' => 20,
597
+				],
598
+				'list_table'    => 'Messages_Template_List_Table',
599
+				'help_tabs'     => [
600
+					'messages_overview_help_tab'                                => [
601
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
602
+						'filename' => 'messages_overview',
603
+					],
604
+					'messages_overview_messages_table_column_headings_help_tab' => [
605
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
606
+						'filename' => 'messages_overview_table_column_headings',
607
+					],
608
+					'messages_overview_messages_filters_help_tab'               => [
609
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
610
+						'filename' => 'messages_overview_filters',
611
+					],
612
+					'messages_overview_messages_views_help_tab'                 => [
613
+						'title'    => esc_html__('Message Views', 'event_espresso'),
614
+						'filename' => 'messages_overview_views',
615
+					],
616
+					'message_overview_message_types_help_tab'                   => [
617
+						'title'    => esc_html__('Message Types', 'event_espresso'),
618
+						'filename' => 'messages_overview_types',
619
+					],
620
+					'messages_overview_messengers_help_tab'                     => [
621
+						'title'    => esc_html__('Messengers', 'event_espresso'),
622
+						'filename' => 'messages_overview_messengers',
623
+					],
624
+				],
625
+				'require_nonce' => false,
626
+			],
627
+			'custom_mtps'              => [
628
+				'nav'           => [
629
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
630
+					'order' => 30,
631
+				],
632
+				'help_tabs'     => [],
633
+				'require_nonce' => false,
634
+			],
635
+			'add_new_message_template' => [
636
+				'nav'           => [
637
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
638
+					'order'      => 5,
639
+					'persistent' => false,
640
+				],
641
+				'require_nonce' => false,
642
+			],
643
+			'edit_message_template'    => [
644
+				'labels'        => [
645
+					'buttons'    => [
646
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
647
+					],
648
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
649
+				],
650
+				'nav'           => [
651
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
652
+					'order'      => 5,
653
+					'persistent' => false,
654
+					'url'        => '',
655
+				],
656
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
657
+				'has_metaboxes' => true,
658
+				'help_tabs'     => [
659
+					'edit_message_template'            => [
660
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
661
+						'callback' => 'edit_message_template_help_tab',
662
+					],
663
+					'message_templates_help_tab'       => [
664
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
665
+						'filename' => 'messages_templates',
666
+					],
667
+					'message_template_shortcodes'      => [
668
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
669
+						'callback' => 'message_template_shortcodes_help_tab',
670
+					],
671
+					'message_preview_help_tab'         => [
672
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
673
+						'filename' => 'messages_preview',
674
+					],
675
+					'messages_overview_other_help_tab' => [
676
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
677
+						'filename' => 'messages_overview_other',
678
+					],
679
+				],
680
+				'require_nonce' => false,
681
+			],
682
+			'display_preview_message'  => [
683
+				'nav'           => [
684
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
685
+					'order'      => 5,
686
+					'url'        => '',
687
+					'persistent' => false,
688
+				],
689
+				'help_tabs'     => [
690
+					'preview_message' => [
691
+						'title'    => esc_html__('About Previews', 'event_espresso'),
692
+						'callback' => 'preview_message_help_tab',
693
+					],
694
+				],
695
+				'require_nonce' => false,
696
+			],
697
+			'settings'                 => [
698
+				'nav'           => [
699
+					'label' => esc_html__('Settings', 'event_espresso'),
700
+					'order' => 40,
701
+				],
702
+				'metaboxes'     => ['_messages_settings_metaboxes'],
703
+				'help_tabs'     => [
704
+					'messages_settings_help_tab'               => [
705
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
706
+						'filename' => 'messages_settings',
707
+					],
708
+					'messages_settings_message_types_help_tab' => [
709
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
710
+						'filename' => 'messages_settings_message_types',
711
+					],
712
+					'messages_settings_messengers_help_tab'    => [
713
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
714
+						'filename' => 'messages_settings_messengers',
715
+					],
716
+				],
717
+				'require_nonce' => false,
718
+			],
719
+		];
720
+	}
721
+
722
+
723
+	protected function _add_screen_options()
724
+	{
725
+		// todo
726
+	}
727
+
728
+
729
+	protected function _add_screen_options_global_mtps()
730
+	{
731
+		/**
732
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
733
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
734
+		 */
735
+		$page_title              = $this->_admin_page_title;
736
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
737
+		$this->_per_page_screen_option();
738
+		$this->_admin_page_title = $page_title;
739
+	}
740
+
741
+
742
+	protected function _add_screen_options_default()
743
+	{
744
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
745
+		$this->_per_page_screen_option();
746
+	}
747
+
748
+
749
+	// none of the below group are currently used for Messages
750
+	protected function _add_feature_pointers()
751
+	{
752
+	}
753
+
754
+
755
+	public function admin_init()
756
+	{
757
+	}
758
+
759
+
760
+	public function admin_notices()
761
+	{
762
+	}
763
+
764
+
765
+	public function admin_footer_scripts()
766
+	{
767
+	}
768
+
769
+
770
+	public function messages_help_tab()
771
+	{
772
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
773
+	}
774
+
775
+
776
+	public function messengers_help_tab()
777
+	{
778
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
779
+	}
780
+
781
+
782
+	public function message_types_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function messages_overview_help_tab()
789
+	{
790
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
791
+	}
792
+
793
+
794
+	public function message_templates_help_tab()
795
+	{
796
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
797
+	}
798
+
799
+
800
+	public function edit_message_template_help_tab()
801
+	{
802
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
803
+						. esc_attr__('Editor Title', 'event_espresso')
804
+						. '" />';
805
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
806
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
807
+						. '" />';
808
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
809
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
810
+						. '" />';
811
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
812
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
813
+						. '" />';
814
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
815
+						. esc_attr__('Publish Metabox', 'event_espresso')
816
+						. '" />';
817
+		EEH_Template::display_template(
818
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
819
+			$args
820
+		);
821
+	}
822
+
823
+
824
+	/**
825
+	 * @throws ReflectionException
826
+	 * @throws EE_Error
827
+	 */
828
+	public function message_template_shortcodes_help_tab()
829
+	{
830
+		$this->_set_shortcodes();
831
+		$args['shortcodes'] = $this->_shortcodes;
832
+		EEH_Template::display_template(
833
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
834
+			$args
835
+		);
836
+	}
837
+
838
+
839
+	public function preview_message_help_tab()
840
+	{
841
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
842
+	}
843
+
844
+
845
+	public function settings_help_tab()
846
+	{
847
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
851
+		$args['img3'] = '<div class="switch">'
852
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853
+						. ' type="checkbox" checked>'
854
+						. '<label for="ee-on-off-toggle-on"></label>'
855
+						. '</div>';
856
+		$args['img4'] = '<div class="switch">'
857
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
858
+						. ' type="checkbox">'
859
+						. '<label for="ee-on-off-toggle-on"></label>'
860
+						. '</div>';
861
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
862
+	}
863
+
864
+
865
+	public function load_scripts_styles()
866
+	{
867
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868
+		wp_enqueue_style('espresso_ee_msg');
869
+
870
+		wp_register_script(
871
+			'ee-messages-settings',
872
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
873
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
874
+			EVENT_ESPRESSO_VERSION,
875
+			true
876
+		);
877
+		wp_register_script(
878
+			'ee-msg-list-table-js',
879
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
880
+			['ee-dialog'],
881
+			EVENT_ESPRESSO_VERSION
882
+		);
883
+	}
884
+
885
+
886
+	public function load_scripts_styles_default()
887
+	{
888
+		wp_enqueue_script('ee-msg-list-table-js');
889
+	}
890
+
891
+
892
+	public function wp_editor_css($mce_css)
893
+	{
894
+		// if we're on the edit_message_template route
895
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
896
+			$message_type_name = $this->_active_message_type_name;
897
+
898
+			// we're going to REPLACE the existing mce css
899
+			// we need to get the css file location from the active messenger
900
+			$mce_css = $this->_active_messenger->get_variation(
901
+				$this->_template_pack,
902
+				$message_type_name,
903
+				true,
904
+				'wpeditor',
905
+				$this->_variation
906
+			);
907
+		}
908
+
909
+		return $mce_css;
910
+	}
911
+
912
+
913
+	/**
914
+	 * @throws EE_Error
915
+	 * @throws ReflectionException
916
+	 */
917
+	public function load_scripts_styles_edit_message_template()
918
+	{
919
+
920
+		$this->_set_shortcodes();
921
+
922
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
923
+			esc_html__(
924
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925
+				'event_espresso'
926
+			),
927
+			$this->_message_template_group->messenger_obj()->label['singular'],
928
+			$this->_message_template_group->message_type_obj()->label['singular']
929
+		);
930
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
931
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932
+			'event_espresso'
933
+		);
934
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
935
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936
+			'event_espresso'
937
+		);
938
+
939
+		wp_register_script(
940
+			'ee_msgs_edit_js',
941
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
942
+			['jquery'],
943
+			EVENT_ESPRESSO_VERSION
944
+		);
945
+
946
+		wp_enqueue_script('ee_admin_js');
947
+		wp_enqueue_script('ee_msgs_edit_js');
948
+
949
+		// add in special css for tiny_mce
950
+		add_filter('mce_css', [$this, 'wp_editor_css']);
951
+	}
952
+
953
+
954
+	/**
955
+	 * @throws EE_Error
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function load_scripts_styles_display_preview_message()
959
+	{
960
+		$this->_set_message_template_group();
961
+		if ($this->_active_messenger_name) {
962
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
963
+				$this->_active_messenger_name
964
+			);
965
+		}
966
+
967
+		wp_enqueue_style(
968
+			'espresso_preview_css',
969
+			$this->_active_messenger->get_variation(
970
+				$this->_template_pack,
971
+				$this->_active_message_type_name,
972
+				true,
973
+				'preview',
974
+				$this->_variation
975
+			)
976
+		);
977
+	}
978
+
979
+
980
+	public function load_scripts_styles_settings()
981
+	{
982
+		wp_register_style(
983
+			'ee-message-settings',
984
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
985
+			[],
986
+			EVENT_ESPRESSO_VERSION
987
+		);
988
+		wp_enqueue_style('ee-text-links');
989
+		wp_enqueue_style('ee-message-settings');
990
+		wp_enqueue_script('ee-messages-settings');
991
+	}
992
+
993
+
994
+	/**
995
+	 * set views array for List Table
996
+	 */
997
+	public function _set_list_table_views_global_mtps()
998
+	{
999
+		$this->_views = [
1000
+			'in_use' => [
1001
+				'slug'  => 'in_use',
1002
+				'label' => esc_html__('In Use', 'event_espresso'),
1003
+				'count' => 0,
1004
+			],
1005
+		];
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Set views array for the Custom Template List Table
1011
+	 */
1012
+	public function _set_list_table_views_custom_mtps()
1013
+	{
1014
+		$this->_set_list_table_views_global_mtps();
1015
+		$this->_views['in_use']['bulk_action'] = [
1016
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1017
+		];
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * set views array for message queue list table
1023
+	 *
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidInterfaceException
1026
+	 * @throws InvalidArgumentException
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function _set_list_table_views_default()
1031
+	{
1032
+		EE_Registry::instance()->load_helper('Template');
1033
+
1034
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1035
+			'ee_send_message',
1036
+			'message_list_table_bulk_actions'
1037
+		)
1038
+			? [
1039
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1040
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1041
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1042
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1043
+			]
1044
+			: [];
1045
+
1046
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_delete_messages',
1048
+			'message_list_table_bulk_actions'
1049
+		)
1050
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1051
+			: [];
1052
+
1053
+
1054
+		$this->_views = [
1055
+			'all' => [
1056
+				'slug'        => 'all',
1057
+				'label'       => esc_html__('All', 'event_espresso'),
1058
+				'count'       => 0,
1059
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1060
+			],
1061
+		];
1062
+
1063
+
1064
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1065
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1066
+				continue;
1067
+			}
1068
+			$status_bulk_actions = $common_bulk_actions;
1069
+			// unset bulk actions not applying to status
1070
+			if (! empty($status_bulk_actions)) {
1071
+				switch ($status) {
1072
+					case EEM_Message::status_idle:
1073
+					case EEM_Message::status_resend:
1074
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1075
+						break;
1076
+
1077
+					case EEM_Message::status_failed:
1078
+					case EEM_Message::status_debug_only:
1079
+					case EEM_Message::status_messenger_executing:
1080
+						$status_bulk_actions = [];
1081
+						break;
1082
+
1083
+					case EEM_Message::status_incomplete:
1084
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1085
+						break;
1086
+
1087
+					case EEM_Message::status_retry:
1088
+					case EEM_Message::status_sent:
1089
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1090
+						break;
1091
+				}
1092
+			}
1093
+
1094
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1095
+			if ($status === EEM_Message::status_messenger_executing) {
1096
+				continue;
1097
+			}
1098
+
1099
+			$this->_views[ strtolower($status) ] = [
1100
+				'slug'        => strtolower($status),
1101
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102
+				'count'       => 0,
1103
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1104
+			];
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	protected function _ee_default_messages_overview_list_table()
1113
+	{
1114
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * @throws EE_Error
1121
+	 * @throws ReflectionException
1122
+	 */
1123
+	protected function _message_queue_list_table()
1124
+	{
1125
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1126
+		$this->_template_args['per_column']        = 6;
1127
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1128
+		$this->_template_args['before_list_table'] = '<h3>'
1129
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1130
+													 . '</h3>';
1131
+		$this->display_admin_list_table_page_with_no_sidebar();
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * @throws EE_Error
1137
+	 */
1138
+	protected function _message_legend_items()
1139
+	{
1140
+
1141
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1142
+		$action_items       = [];
1143
+
1144
+		foreach ($action_css_classes as $action_item => $action_details) {
1145
+			if ($action_item === 'see_notifications_for') {
1146
+				continue;
1147
+			}
1148
+			$action_items[ $action_item ] = [
1149
+				'class' => $action_details['css_class'],
1150
+				'desc'  => $action_details['label'],
1151
+			];
1152
+		}
1153
+
1154
+		/** @var array $status_items status legend setup */
1155
+		$status_items = [
1156
+			'sent_status'                => [
1157
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1158
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159
+			],
1160
+			'idle_status'                => [
1161
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1162
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163
+			],
1164
+			'failed_status'              => [
1165
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1166
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167
+			],
1168
+			'messenger_executing_status' => [
1169
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1170
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171
+			],
1172
+			'resend_status'              => [
1173
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1174
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175
+			],
1176
+			'incomplete_status'          => [
1177
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1178
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179
+			],
1180
+			'retry_status'               => [
1181
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1182
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183
+			],
1184
+		];
1185
+		if (EEM_Message::debug()) {
1186
+			$status_items['debug_only_status'] = [
1187
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1188
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189
+			];
1190
+		}
1191
+
1192
+		return array_merge($action_items, $status_items);
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	protected function _custom_mtps_preview()
1200
+	{
1201
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
+												. ' alt="' . esc_attr__(
1204
+													'Preview Custom Message Templates screenshot',
1205
+													'event_espresso'
1206
+												) . '" />';
1207
+		$this->_template_args['preview_text'] = '<strong>'
1208
+												. esc_html__(
1209
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1210
+													'event_espresso'
1211
+												)
1212
+												. '</strong>';
1213
+
1214
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * get_message_templates
1220
+	 * This gets all the message templates for listing on the overview list.
1221
+	 *
1222
+	 * @access public
1223
+	 * @param int    $per_page the amount of templates groups to show per page
1224
+	 * @param string $type     the current _view we're getting templates for
1225
+	 * @param bool   $count    return count?
1226
+	 * @param bool   $all      disregard any paging info (get all data);
1227
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws InvalidArgumentException
1231
+	 * @throws InvalidDataTypeException
1232
+	 * @throws InvalidInterfaceException
1233
+	 */
1234
+	public function get_message_templates(
1235
+		$per_page = 10,
1236
+		$type = 'in_use',
1237
+		$count = false,
1238
+		$all = false,
1239
+		$global = true
1240
+	) {
1241
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1242
+		$this->request->setRequestParam('orderby', $orderby);
1243
+
1244
+		$order        = $this->request->getRequestParam('order', 'ASC');
1245
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1246
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1247
+
1248
+		$offset = ($current_page - 1) * $per_page;
1249
+		$limit  = $all ? null : [$offset, $per_page];
1250
+
1251
+		// options will match what is in the _views array property
1252
+		return $type === 'in_use'
1253
+			? $this->getMtgModel()->get_all_active_message_templates(
1254
+				$orderby,
1255
+				$order,
1256
+				$limit,
1257
+				$count,
1258
+				$global,
1259
+				true
1260
+			)
1261
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1262
+				$orderby,
1263
+				$order,
1264
+				$limit,
1265
+				$count,
1266
+				$global
1267
+			);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * filters etc might need a list of installed message_types
1273
+	 *
1274
+	 * @return array an array of message type objects
1275
+	 */
1276
+	public function get_installed_message_types()
1277
+	{
1278
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1279
+		$installed               = [];
1280
+
1281
+		foreach ($installed_message_types as $message_type) {
1282
+			$installed[ $message_type->name ] = $message_type;
1283
+		}
1284
+
1285
+		return $installed;
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1291
+	 *
1292
+	 * @param string $message_type
1293
+	 * @param string $messenger
1294
+	 * @param string $GRP_ID
1295
+	 *
1296
+	 * @throws EE_error
1297
+	 * @throws ReflectionException
1298
+	 */
1299
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1300
+	{
1301
+		// set values override any request data
1302
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1303
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1304
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1305
+
1306
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1307
+		if (empty($message_type) || empty($messenger)) {
1308
+			throw new EE_Error(
1309
+				esc_html__(
1310
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1311
+					'event_espresso'
1312
+				)
1313
+			);
1314
+		}
1315
+
1316
+		// we need the GRP_ID for the template being used as the base for the new template
1317
+		if (empty($GRP_ID)) {
1318
+			throw new EE_Error(
1319
+				esc_html__(
1320
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1321
+					'event_espresso'
1322
+				)
1323
+			);
1324
+		}
1325
+
1326
+		// let's just make sure the template gets generated!
1327
+
1328
+		// we need to reassign some variables for what the insert is expecting
1329
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1330
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1331
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1332
+
1333
+		$this->_insert_or_update_message_template(true);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * @param string $message_type     message type slug
1339
+	 * @param string $messenger        messenger slug
1340
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1341
+	 *                                 off of.
1342
+	 * @throws EE_error
1343
+	 * @throws ReflectionException
1344
+	 * @deprecated 4.10.29.p
1345
+	 */
1346
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1347
+	{
1348
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1349
+	}
1350
+
1351
+
1352
+	/**
1353
+	 * _edit_message_template
1354
+	 *
1355
+	 * @access protected
1356
+	 * @return void
1357
+	 * @throws InvalidIdentifierException
1358
+	 * @throws DomainException
1359
+	 * @throws EE_Error
1360
+	 * @throws InvalidArgumentException
1361
+	 * @throws ReflectionException
1362
+	 * @throws InvalidDataTypeException
1363
+	 * @throws InvalidInterfaceException
1364
+	 */
1365
+	protected function _edit_message_template()
1366
+	{
1367
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1368
+		$template_fields = '';
1369
+		$sidebar_fields  = '';
1370
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1371
+		// valid html in the templates.
1372
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1373
+
1374
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1375
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1376
+
1377
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1378
+		$message_template_group = $this->_message_template_group;
1379
+		$c_label                = $message_template_group->context_label();
1380
+		$c_config               = $message_template_group->contexts_config();
1381
+
1382
+		reset($c_config);
1383
+		$context = $this->request->getRequestParam('context', key($c_config));
1384
+		$context = strtolower($context);
1385
+
1386
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1387
+
1388
+		$edit_message_template_form_url = add_query_arg(
1389
+			['action' => $action, 'noheader' => true],
1390
+			EE_MSG_ADMIN_URL
1391
+		);
1392
+
1393
+		// set active messenger for this view
1394
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1395
+			$message_template_group->messenger()
1396
+		);
1397
+		$this->_active_message_type_name = $message_template_group->message_type();
1398
+
1399
+
1400
+		// Do we have any validation errors?
1401
+		$validators = $this->_get_transient();
1402
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1403
+
1404
+
1405
+		// we need to assemble the title from Various details
1406
+		$context_label = sprintf(
1407
+			esc_html__('(%s %s)', 'event_espresso'),
1408
+			$c_config[ $context ]['label'],
1409
+			ucwords($c_label['label'])
1410
+		);
1411
+
1412
+		$title = sprintf(
1413
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1414
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1415
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1416
+			$context_label
1417
+		);
1418
+
1419
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1420
+		$this->_template_args['message_template'] = $message_template_group;
1421
+		$this->_template_args['is_extra_fields']  = false;
1422
+
1423
+
1424
+		// let's get EEH_MSG_Template so we can get template form fields
1425
+		$template_field_structure = EEH_MSG_Template::get_fields(
1426
+			$message_template_group->messenger(),
1427
+			$message_template_group->message_type()
1428
+		);
1429
+
1430
+		if (! $template_field_structure) {
1431
+			$template_field_structure = false;
1432
+			$template_fields          = esc_html__(
1433
+				'There was an error in assembling the fields for this display (you should see an error message)',
1434
+				'event_espresso'
1435
+			);
1436
+		}
1437
+
1438
+
1439
+		$message_templates = $message_template_group->context_templates();
1440
+
1441
+
1442
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443
+		// will get handled in the "extra" array.
1444
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
+				unset($template_field_structure[ $context ][ $reference_field ]);
1447
+			}
1448
+		}
1449
+
1450
+		// let's loop through the template_field_structure and actually assemble the input fields!
1451
+		if (! empty($template_field_structure)) {
1452
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1453
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454
+				// the extra array and reset them.
1455
+				if ($template_field === 'extra') {
1456
+					$this->_template_args['is_extra_fields'] = true;
1457
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
+						$message_template = $message_templates[ $context ][ $reference_field ];
1459
+						$content          = $message_template instanceof EE_Message_Template
1460
+							? $message_template->get('MTP_content')
1461
+							: '';
1462
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1463
+							// let's verify if we need this extra field via the shortcodes parameter.
1464
+							$continue = false;
1465
+							if (isset($extra_array['shortcodes_required'])) {
1466
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1468
+										$continue = true;
1469
+									}
1470
+								}
1471
+								if ($continue) {
1472
+									continue;
1473
+								}
1474
+							}
1475
+
1476
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1477
+
1478
+							$template_form_fields[ $field_id ]         = $extra_array;
1479
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1480
+																		 . $reference_field
1481
+																		 . '][content]['
1482
+																		 . $extra_field . ']';
1483
+							$css_class                                 = isset($extra_array['css_class'])
1484
+								? $extra_array['css_class']
1485
+								: '';
1486
+
1487
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1488
+																			  && in_array($extra_field, $v_fields, true)
1489
+																			  && (
1490
+																				  is_array($validators[ $extra_field ])
1491
+																				  && isset($validators[ $extra_field ]['msg'])
1492
+																			  )
1493
+								? 'validate-error ' . $css_class
1494
+								: $css_class;
1495
+
1496
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
+																		  && isset($content[ $extra_field ])
1498
+								? $content[ $extra_field ]
1499
+								: '';
1500
+
1501
+							// do we have a validation error?  if we do then let's use that value instead
1502
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
+								? $validators[ $extra_field ]['value']
1504
+								: $template_form_fields[ $field_id ]['value'];
1505
+
1506
+
1507
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1508
+
1509
+							// shortcode selector
1510
+							$field_name_to_use                                   = $extra_field === 'main'
1511
+								? 'content'
1512
+								: $extra_field;
1513
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1514
+								$field_name_to_use,
1515
+								$field_id
1516
+							);
1517
+						}
1518
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
+						$template_field_template_name_id = $reference_field . '-name';
1520
+
1521
+						$template_form_fields[ $template_field_MTP_id ] = [
1522
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1523
+							'label'      => null,
1524
+							'input'      => 'hidden',
1525
+							'type'       => 'int',
1526
+							'required'   => false,
1527
+							'validation' => false,
1528
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1529
+							'css_class'  => '',
1530
+							'format'     => '%d',
1531
+							'db-col'     => 'MTP_ID',
1532
+						];
1533
+
1534
+						$template_form_fields[ $template_field_template_name_id ] = [
1535
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1536
+							'label'      => null,
1537
+							'input'      => 'hidden',
1538
+							'type'       => 'string',
1539
+							'required'   => false,
1540
+							'validation' => true,
1541
+							'value'      => $reference_field,
1542
+							'css_class'  => '',
1543
+							'format'     => '%s',
1544
+							'db-col'     => 'MTP_template_field',
1545
+						];
1546
+					}
1547
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548
+				} else {
1549
+					$field_id                                   = $template_field . '-content';
1550
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1551
+					$template_form_fields[ $field_id ]['name']  =
1552
+						'MTP_template_fields[' . $template_field . '][content]';
1553
+					$message_template                           =
1554
+						isset($message_templates[ $context ][ $template_field ])
1555
+							? $message_templates[ $context ][ $template_field ]
1556
+							: null;
1557
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
+																  && is_array($message_templates[ $context ])
1559
+																  && $message_template instanceof EE_Message_Template
1560
+						? $message_template->get('MTP_content')
1561
+						: '';
1562
+
1563
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1564
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
+						? $validators[ $template_field ]['value']
1566
+						: $template_form_fields[ $field_id ]['value'];
1567
+
1568
+
1569
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1570
+					$css_class                                      = isset($field_setup_array['css_class'])
1571
+						? $field_setup_array['css_class']
1572
+						: '';
1573
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1574
+																	  && in_array($template_field, $v_fields, true)
1575
+																	  && isset($validators[ $template_field ]['msg'])
1576
+						? 'validate-error ' . $css_class
1577
+						: $css_class;
1578
+
1579
+					// shortcode selector
1580
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1581
+						$template_field,
1582
+						$field_id
1583
+					);
1584
+				}
1585
+
1586
+				// k took care of content field(s) now let's take care of others.
1587
+
1588
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
+				$template_field_field_template_name_id = $template_field . '-name';
1590
+
1591
+				// foreach template field there are actually two form fields created
1592
+				$template_form_fields[ $template_field_MTP_id ] = [
1593
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1594
+					'label'      => null,
1595
+					'input'      => 'hidden',
1596
+					'type'       => 'int',
1597
+					'required'   => false,
1598
+					'validation' => true,
1599
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1600
+					'css_class'  => '',
1601
+					'format'     => '%d',
1602
+					'db-col'     => 'MTP_ID',
1603
+				];
1604
+
1605
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1606
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1607
+					'label'      => null,
1608
+					'input'      => 'hidden',
1609
+					'type'       => 'string',
1610
+					'required'   => false,
1611
+					'validation' => true,
1612
+					'value'      => $template_field,
1613
+					'css_class'  => '',
1614
+					'format'     => '%s',
1615
+					'db-col'     => 'MTP_template_field',
1616
+				];
1617
+			}
1618
+
1619
+			// add other fields
1620
+			$template_form_fields['ee-msg-current-context'] = [
1621
+				'name'       => 'MTP_context',
1622
+				'label'      => null,
1623
+				'input'      => 'hidden',
1624
+				'type'       => 'string',
1625
+				'required'   => false,
1626
+				'validation' => true,
1627
+				'value'      => $context,
1628
+				'css_class'  => '',
1629
+				'format'     => '%s',
1630
+				'db-col'     => 'MTP_context',
1631
+			];
1632
+
1633
+			$template_form_fields['ee-msg-grp-id'] = [
1634
+				'name'       => 'GRP_ID',
1635
+				'label'      => null,
1636
+				'input'      => 'hidden',
1637
+				'type'       => 'int',
1638
+				'required'   => false,
1639
+				'validation' => true,
1640
+				'value'      => $GRP_ID,
1641
+				'css_class'  => '',
1642
+				'format'     => '%d',
1643
+				'db-col'     => 'GRP_ID',
1644
+			];
1645
+
1646
+			$template_form_fields['ee-msg-messenger'] = [
1647
+				'name'       => 'MTP_messenger',
1648
+				'label'      => null,
1649
+				'input'      => 'hidden',
1650
+				'type'       => 'string',
1651
+				'required'   => false,
1652
+				'validation' => true,
1653
+				'value'      => $message_template_group->messenger(),
1654
+				'css_class'  => '',
1655
+				'format'     => '%s',
1656
+				'db-col'     => 'MTP_messenger',
1657
+			];
1658
+
1659
+			$template_form_fields['ee-msg-message-type'] = [
1660
+				'name'       => 'MTP_message_type',
1661
+				'label'      => null,
1662
+				'input'      => 'hidden',
1663
+				'type'       => 'string',
1664
+				'required'   => false,
1665
+				'validation' => true,
1666
+				'value'      => $message_template_group->message_type(),
1667
+				'css_class'  => '',
1668
+				'format'     => '%s',
1669
+				'db-col'     => 'MTP_message_type',
1670
+			];
1671
+
1672
+			$sidebar_form_fields['ee-msg-is-global'] = [
1673
+				'name'       => 'MTP_is_global',
1674
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1675
+				'input'      => 'hidden',
1676
+				'type'       => 'int',
1677
+				'required'   => false,
1678
+				'validation' => true,
1679
+				'value'      => $message_template_group->get('MTP_is_global'),
1680
+				'css_class'  => '',
1681
+				'format'     => '%d',
1682
+				'db-col'     => 'MTP_is_global',
1683
+			];
1684
+
1685
+			$sidebar_form_fields['ee-msg-is-override'] = [
1686
+				'name'       => 'MTP_is_override',
1687
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1688
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1689
+				'type'       => 'int',
1690
+				'required'   => false,
1691
+				'validation' => true,
1692
+				'value'      => $message_template_group->get('MTP_is_override'),
1693
+				'css_class'  => '',
1694
+				'format'     => '%d',
1695
+				'db-col'     => 'MTP_is_override',
1696
+			];
1697
+
1698
+			$sidebar_form_fields['ee-msg-is-active'] = [
1699
+				'name'       => 'MTP_is_active',
1700
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1701
+				'input'      => 'hidden',
1702
+				'type'       => 'int',
1703
+				'required'   => false,
1704
+				'validation' => true,
1705
+				'value'      => $message_template_group->is_active(),
1706
+				'css_class'  => '',
1707
+				'format'     => '%d',
1708
+				'db-col'     => 'MTP_is_active',
1709
+			];
1710
+
1711
+			$sidebar_form_fields['ee-msg-deleted'] = [
1712
+				'name'       => 'MTP_deleted',
1713
+				'label'      => null,
1714
+				'input'      => 'hidden',
1715
+				'type'       => 'int',
1716
+				'required'   => false,
1717
+				'validation' => true,
1718
+				'value'      => $message_template_group->get('MTP_deleted'),
1719
+				'css_class'  => '',
1720
+				'format'     => '%d',
1721
+				'db-col'     => 'MTP_deleted',
1722
+			];
1723
+			$sidebar_form_fields['ee-msg-author']  = [
1724
+				'name'       => 'MTP_user_id',
1725
+				'label'      => esc_html__('Author', 'event_espresso'),
1726
+				'input'      => 'hidden',
1727
+				'type'       => 'int',
1728
+				'required'   => false,
1729
+				'validation' => false,
1730
+				'value'      => $message_template_group->user(),
1731
+				'format'     => '%d',
1732
+				'db-col'     => 'MTP_user_id',
1733
+			];
1734
+
1735
+			$sidebar_form_fields['ee-msg-route'] = [
1736
+				'name'  => 'action',
1737
+				'input' => 'hidden',
1738
+				'type'  => 'string',
1739
+				'value' => $action,
1740
+			];
1741
+
1742
+			$sidebar_form_fields['ee-msg-id']        = [
1743
+				'name'  => 'id',
1744
+				'input' => 'hidden',
1745
+				'type'  => 'int',
1746
+				'value' => $GRP_ID,
1747
+			];
1748
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
+				'name'  => $action . '_nonce',
1750
+				'input' => 'hidden',
1751
+				'type'  => 'string',
1752
+				'value' => wp_create_nonce($action . '_nonce'),
1753
+			];
1754
+
1755
+			$template_switch = $this->request->getRequestParam('template_switch');
1756
+			if ($template_switch) {
1757
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1758
+					'name'  => 'template_switch',
1759
+					'input' => 'hidden',
1760
+					'type'  => 'int',
1761
+					'value' => 1,
1762
+				];
1763
+			}
1764
+
1765
+
1766
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1767
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1768
+		} //end if ( !empty($template_field_structure) )
1769
+
1770
+		// set extra content for publish box
1771
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1772
+		$this->_set_publish_post_box_vars(
1773
+			'id',
1774
+			$GRP_ID,
1775
+			false,
1776
+			add_query_arg(
1777
+				['action' => 'global_mtps'],
1778
+				$this->_admin_base_url
1779
+			)
1780
+		);
1781
+
1782
+		// add preview button
1783
+		$preview_url    = parent::add_query_args_and_nonce(
1784
+			[
1785
+				'message_type' => $message_template_group->message_type(),
1786
+				'messenger'    => $message_template_group->messenger(),
1787
+				'context'      => $context,
1788
+				'GRP_ID'       => $GRP_ID,
1789
+				'evt_id'       => $EVT_ID ?: false,
1790
+				'action'       => 'preview_message',
1791
+			],
1792
+			$this->_admin_base_url
1793
+		);
1794
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1795
+						  . esc_html__('Preview', 'event_espresso')
1796
+						  . '</a>';
1797
+
1798
+
1799
+		// setup context switcher
1800
+		$this->_set_context_switcher(
1801
+			$message_template_group,
1802
+			[
1803
+				'page'    => 'espresso_messages',
1804
+				'action'  => 'edit_message_template',
1805
+				'id'      => $GRP_ID,
1806
+				'evt_id'  => $EVT_ID,
1807
+				'context' => $context,
1808
+				'extra'   => $preview_button,
1809
+			]
1810
+		);
1811
+
1812
+
1813
+		// main box
1814
+		$this->_template_args['template_fields']                         = $template_fields;
1815
+		$this->_template_args['sidebar_box_id']                          = 'details';
1816
+		$this->_template_args['action']                                  = $action;
1817
+		$this->_template_args['context']                                 = $context;
1818
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1819
+		$this->_template_args['learn_more_about_message_templates_link'] =
1820
+			$this->_learn_more_about_message_templates_link();
1821
+
1822
+
1823
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1824
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1825
+			$message_template_group,
1826
+			$context,
1827
+			$context_label
1828
+		);
1829
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1831
+
1832
+		$this->_template_path = $this->_template_args['GRP_ID']
1833
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1835
+
1836
+		// send along EE_Message_Template_Group object for further template use.
1837
+		$this->_template_args['MTP'] = $message_template_group;
1838
+
1839
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1840
+			$this->_template_path,
1841
+			$this->_template_args,
1842
+			true
1843
+		);
1844
+
1845
+
1846
+		// finally, let's set the admin_page title
1847
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1848
+
1849
+
1850
+		// we need to take care of setting the shortcodes property for use elsewhere.
1851
+		$this->_set_shortcodes();
1852
+
1853
+
1854
+		// final template wrapper
1855
+		$this->display_admin_page_with_sidebar();
1856
+	}
1857
+
1858
+
1859
+	public function filter_tinymce_init($mceInit, $editor_id)
1860
+	{
1861
+		return $mceInit;
1862
+	}
1863
+
1864
+
1865
+	public function add_context_switcher()
1866
+	{
1867
+		return $this->_context_switcher;
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * Adds the activation/deactivation toggle for the message template context.
1873
+	 *
1874
+	 * @param EE_Message_Template_Group $message_template_group
1875
+	 * @param string                    $context
1876
+	 * @param string                    $context_label
1877
+	 * @return string
1878
+	 * @throws DomainException
1879
+	 * @throws EE_Error
1880
+	 * @throws InvalidIdentifierException
1881
+	 * @throws ReflectionException
1882
+	 */
1883
+	protected function add_active_context_element(
1884
+		EE_Message_Template_Group $message_template_group,
1885
+		$context,
1886
+		$context_label
1887
+	) {
1888
+		$template_args = [
1889
+			'context'                   => $context,
1890
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1891
+			'is_active'                 => $message_template_group->is_context_active($context),
1892
+			'on_off_action'             => $message_template_group->is_context_active($context)
1893
+				? 'context-off'
1894
+				: 'context-on',
1895
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1896
+			'message_template_group_id' => $message_template_group->ID(),
1897
+		];
1898
+		return EEH_Template::display_template(
1899
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1900
+			$template_args,
1901
+			true
1902
+		);
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * Ajax callback for `toggle_context_template` ajax action.
1908
+	 * Handles toggling the message context on or off.
1909
+	 *
1910
+	 * @throws EE_Error
1911
+	 * @throws InvalidArgumentException
1912
+	 * @throws InvalidDataTypeException
1913
+	 * @throws InvalidIdentifierException
1914
+	 * @throws InvalidInterfaceException
1915
+	 */
1916
+	public function toggle_context_template()
1917
+	{
1918
+		$success = true;
1919
+		// check for required data
1920
+		if (
1921
+			! (
1922
+				$this->request->requestParamIsSet('message_template_group_id')
1923
+				&& $this->request->requestParamIsSet('context')
1924
+				&& $this->request->requestParamIsSet('status')
1925
+			)
1926
+		) {
1927
+			EE_Error::add_error(
1928
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1929
+				__FILE__,
1930
+				__FUNCTION__,
1931
+				__LINE__
1932
+			);
1933
+			$success = false;
1934
+		}
1935
+
1936
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1937
+		$context = $this->request->getRequestParam('context', '');
1938
+		$status  = $this->request->getRequestParam('status', '');
1939
+
1940
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1941
+
1942
+		if ($status !== 'off' && $status !== 'on') {
1943
+			EE_Error::add_error(
1944
+				sprintf(
1945
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1946
+					$status
1947
+				),
1948
+				__FILE__,
1949
+				__FUNCTION__,
1950
+				__LINE__
1951
+			);
1952
+			$success = false;
1953
+		}
1954
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1957
+			EE_Error::add_error(
1958
+				sprintf(
1959
+					esc_html__(
1960
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1961
+						'event_espresso'
1962
+					),
1963
+					$message_template_group_id,
1964
+					'EE_Message_Template_Group'
1965
+				),
1966
+				__FILE__,
1967
+				__FUNCTION__,
1968
+				__LINE__
1969
+			);
1970
+			$success = false;
1971
+		}
1972
+		if ($success) {
1973
+			$success = $status === 'off'
1974
+				? $message_template_group->deactivate_context($context)
1975
+				: $message_template_group->activate_context($context);
1976
+		}
1977
+		$this->_template_args['success'] = $success;
1978
+		$this->_return_json();
1979
+	}
1980
+
1981
+
1982
+	public function _add_form_element_before()
1983
+	{
1984
+		return '<form method="post" action="'
1985
+			   . $this->_template_args['edit_message_template_form_url']
1986
+			   . '" id="ee-msg-edit-frm">';
1987
+	}
1988
+
1989
+
1990
+	public function _add_form_element_after()
1991
+	{
1992
+		return '</form>';
1993
+	}
1994
+
1995
+
1996
+	/**
1997
+	 * This executes switching the template pack for a message template.
1998
+	 *
1999
+	 * @throws EE_Error
2000
+	 * @throws InvalidDataTypeException
2001
+	 * @throws InvalidInterfaceException
2002
+	 * @throws InvalidArgumentException
2003
+	 * @throws ReflectionException
2004
+	 * @since 4.5.0
2005
+	 */
2006
+	public function switch_template_pack()
2007
+	{
2008
+
2009
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2010
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2011
+
2012
+		// verify we have needed values.
2013
+		if (empty($GRP_ID) || empty($template_pack)) {
2014
+			$this->_template_args['error'] = true;
2015
+			EE_Error::add_error(
2016
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2017
+				__FILE__,
2018
+				__FUNCTION__,
2019
+				__LINE__
2020
+			);
2021
+		} else {
2022
+			// get template, set the new template_pack and then reset to default
2023
+			/** @var EE_Message_Template_Group $message_template_group */
2024
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2025
+
2026
+			$message_template_group->set_template_pack_name($template_pack);
2027
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2028
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2029
+
2030
+			$query_args = $this->_reset_to_default_template();
2031
+
2032
+			if (empty($query_args['id'])) {
2033
+				EE_Error::add_error(
2034
+					esc_html__(
2035
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2036
+						'event_espresso'
2037
+					),
2038
+					__FILE__,
2039
+					__FUNCTION__,
2040
+					__LINE__
2041
+				);
2042
+				$this->_template_args['error'] = true;
2043
+			} else {
2044
+				$template_label       = $message_template_group->get_template_pack()->label;
2045
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2046
+				EE_Error::add_success(
2047
+					sprintf(
2048
+						esc_html__(
2049
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2050
+							'event_espresso'
2051
+						),
2052
+						$template_label,
2053
+						$template_pack_labels->template_pack
2054
+					)
2055
+				);
2056
+				// generate the redirect url for js.
2057
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2058
+
2059
+				$this->_template_args['data']['redirect_url'] = $url;
2060
+				$this->_template_args['success']              = true;
2061
+			}
2062
+
2063
+			$this->_return_json();
2064
+		}
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2070
+	 * they want.
2071
+	 *
2072
+	 * @access protected
2073
+	 * @return array|void
2074
+	 * @throws EE_Error
2075
+	 * @throws InvalidArgumentException
2076
+	 * @throws InvalidDataTypeException
2077
+	 * @throws InvalidInterfaceException
2078
+	 * @throws ReflectionException
2079
+	 */
2080
+	protected function _reset_to_default_template()
2081
+	{
2082
+		$templates    = [];
2083
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2084
+		$messenger    = $this->request->getRequestParam('msgr');
2085
+		$message_type = $this->request->getRequestParam('mt');
2086
+		// we need to make sure we've got the info we need.
2087
+		if (! ($GRP_ID && $messenger && $message_type)) {
2088
+			EE_Error::add_error(
2089
+				esc_html__(
2090
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2091
+					'event_espresso'
2092
+				),
2093
+				__FILE__,
2094
+				__FUNCTION__,
2095
+				__LINE__
2096
+			);
2097
+		}
2098
+
2099
+		// all templates will be reset to whatever the defaults are
2100
+		// for the global template matching the messenger and message type.
2101
+		$success = ! empty($GRP_ID);
2102
+
2103
+		if ($success) {
2104
+			// let's first determine if the incoming template is a global template,
2105
+			// if it isn't then we need to get the global template matching messenger and message type.
2106
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2107
+
2108
+
2109
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2110
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2111
+
2112
+			if ($success) {
2113
+				// if successfully deleted, lets generate the new ones.
2114
+				// Note. We set GLOBAL to true, because resets on ANY template
2115
+				// will use the related global template defaults for regeneration.
2116
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2117
+				// HOWEVER, we DO keep the template pack and template variation set
2118
+				// for the current custom template when resetting.
2119
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2120
+			}
2121
+		}
2122
+
2123
+		// any error messages?
2124
+		if (! $success) {
2125
+			EE_Error::add_error(
2126
+				esc_html__(
2127
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2128
+					'event_espresso'
2129
+				),
2130
+				__FILE__,
2131
+				__FUNCTION__,
2132
+				__LINE__
2133
+			);
2134
+		}
2135
+
2136
+		// all good, let's add a success message!
2137
+		if ($success && ! empty($templates)) {
2138
+			// the info for the template we generated is the first element in the returned array
2139
+			EE_Error::overwrite_success();
2140
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2141
+		}
2142
+
2143
+
2144
+		$query_args = [
2145
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2146
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2147
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2148
+		];
2149
+
2150
+		// if called via ajax then we return query args otherwise redirect
2151
+		if ($this->request->isAjax()) {
2152
+			return $query_args;
2153
+		}
2154
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 * Retrieve and set the message preview for display.
2160
+	 *
2161
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2162
+	 * @return string
2163
+	 * @throws ReflectionException
2164
+	 * @throws EE_Error
2165
+	 * @throws InvalidArgumentException
2166
+	 * @throws InvalidDataTypeException
2167
+	 * @throws InvalidInterfaceException
2168
+	 */
2169
+	public function _preview_message($send = false)
2170
+	{
2171
+		// first make sure we've got the necessary parameters
2172
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174
+			EE_Error::add_error(
2175
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176
+				__FILE__,
2177
+				__FUNCTION__,
2178
+				__LINE__
2179
+			);
2180
+		}
2181
+
2182
+		$context = $this->request->getRequestParam('context');
2183
+		// get the preview!
2184
+		$preview = EED_Messages::preview_message(
2185
+			$this->_active_message_type_name,
2186
+			$context,
2187
+			$this->_active_messenger_name,
2188
+			$send
2189
+		);
2190
+
2191
+		if ($send) {
2192
+			return $preview;
2193
+		}
2194
+
2195
+		// if we have an evt_id set on the request, use it.
2196
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197
+
2198
+		// let's add a button to go back to the edit view
2199
+		$query_args             = [
2200
+			'id'      => $GRP_ID,
2201
+			'evt_id'  => $EVT_ID,
2202
+			'context' => $context,
2203
+			'action'  => 'edit_message_template',
2204
+		];
2205
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2206
+		$preview_button         = '<a href="'
2207
+								  . $go_back_url
2208
+								  . '" class="button-secondary messages-preview-go-back-button">'
2209
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2210
+								  . '</a>';
2211
+		$message_types          = $this->get_installed_message_types();
2212
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2213
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2214
+			? ucwords($active_messenger->label['singular'])
2215
+			: esc_html__('Unknown Messenger', 'event_espresso');
2216
+		// let's provide a helpful title for context
2217
+		$preview_title = sprintf(
2218
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219
+			$active_messenger_label,
2220
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2221
+		);
2222
+		if (empty($preview)) {
2223
+			$this->noEventsErrorMessage();
2224
+		}
2225
+		// setup display of preview.
2226
+		$this->_admin_page_title                    = $preview_title;
2227
+		$this->_template_args['admin_page_title']   = $preview_title;
2228
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2229
+		$this->_template_args['data']['force_json'] = true;
2230
+
2231
+		return '';
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * Used to set an error if there are no events available for generating a preview/test send.
2237
+	 *
2238
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2239
+	 */
2240
+	protected function noEventsErrorMessage($test_send = false)
2241
+	{
2242
+		$events_url = parent::add_query_args_and_nonce(
2243
+			[
2244
+				'action' => 'default',
2245
+				'page'   => 'espresso_events',
2246
+			],
2247
+			admin_url('admin.php')
2248
+		);
2249
+		$message    = $test_send
2250
+			? esc_html__(
2251
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252
+				'event_espresso'
2253
+			)
2254
+			: esc_html__(
2255
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2256
+				'event_espresso'
2257
+			);
2258
+
2259
+		EE_Error::add_attention(
2260
+			sprintf(
2261
+				$message,
2262
+				"<a href='{$events_url}'>",
2263
+				'</a>'
2264
+			)
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	/**
2270
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2271
+	 * gets called automatically.
2272
+	 *
2273
+	 * @return void
2274
+	 * @throws EE_Error
2275
+	 * @since 4.5.0
2276
+	 *
2277
+	 */
2278
+	protected function _display_preview_message()
2279
+	{
2280
+		$this->display_admin_page_with_no_sidebar();
2281
+	}
2282
+
2283
+
2284
+	/**
2285
+	 * registers metaboxes that should show up on the "edit_message_template" page
2286
+	 *
2287
+	 * @access protected
2288
+	 * @return void
2289
+	 */
2290
+	protected function _register_edit_meta_boxes()
2291
+	{
2292
+		add_meta_box(
2293
+			'mtp_valid_shortcodes',
2294
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2295
+			[$this, 'shortcode_meta_box'],
2296
+			$this->_current_screen->id,
2297
+			'side'
2298
+		);
2299
+		add_meta_box(
2300
+			'mtp_extra_actions',
2301
+			esc_html__('Extra Actions', 'event_espresso'),
2302
+			[$this, 'extra_actions_meta_box'],
2303
+			$this->_current_screen->id,
2304
+			'side',
2305
+			'high'
2306
+		);
2307
+		add_meta_box(
2308
+			'mtp_templates',
2309
+			esc_html__('Template Styles', 'event_espresso'),
2310
+			[$this, 'template_pack_meta_box'],
2311
+			$this->_current_screen->id,
2312
+			'side',
2313
+			'high'
2314
+		);
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * metabox content for all template pack and variation selection.
2320
+	 *
2321
+	 * @return void
2322
+	 * @throws DomainException
2323
+	 * @throws EE_Error
2324
+	 * @throws InvalidArgumentException
2325
+	 * @throws ReflectionException
2326
+	 * @throws InvalidDataTypeException
2327
+	 * @throws InvalidInterfaceException
2328
+	 * @since 4.5.0
2329
+	 */
2330
+	public function template_pack_meta_box()
2331
+	{
2332
+		$this->_set_message_template_group();
2333
+
2334
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2335
+
2336
+		$tp_select_values = [];
2337
+
2338
+		foreach ($tp_collection as $tp) {
2339
+			// only include template packs that support this messenger and message type!
2340
+			$supports = $tp->get_supports();
2341
+			if (
2342
+				! isset($supports[ $this->_message_template_group->messenger() ])
2343
+				|| ! in_array(
2344
+					$this->_message_template_group->message_type(),
2345
+					$supports[ $this->_message_template_group->messenger() ],
2346
+					true
2347
+				)
2348
+			) {
2349
+				// not supported
2350
+				continue;
2351
+			}
2352
+
2353
+			$tp_select_values[] = [
2354
+				'text' => $tp->label,
2355
+				'id'   => $tp->dbref,
2356
+			];
2357
+		}
2358
+
2359
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2360
+		// the default template pack.  This still allows for the odd template pack to override.
2361
+		if (empty($tp_select_values)) {
2362
+			$tp_select_values[] = [
2363
+				'text' => esc_html__('Default', 'event_espresso'),
2364
+				'id'   => 'default',
2365
+			];
2366
+		}
2367
+
2368
+		// setup variation select values for the currently selected template.
2369
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2370
+			$this->_message_template_group->messenger(),
2371
+			$this->_message_template_group->message_type()
2372
+		);
2373
+		$variations_select_values = [];
2374
+		foreach ($variations as $variation => $label) {
2375
+			$variations_select_values[] = [
2376
+				'text' => $label,
2377
+				'id'   => $variation,
2378
+			];
2379
+		}
2380
+
2381
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382
+
2383
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2384
+			'MTP_template_pack',
2385
+			$tp_select_values,
2386
+			$this->_message_template_group->get_template_pack_name()
2387
+		);
2388
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2389
+			'MTP_template_variation',
2390
+			$variations_select_values,
2391
+			$this->_message_template_group->get_template_pack_variation()
2392
+		);
2393
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2394
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2395
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397
+
2398
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2399
+
2400
+		EEH_Template::display_template($template, $template_args);
2401
+	}
2402
+
2403
+
2404
+	/**
2405
+	 * This meta box holds any extra actions related to Message Templates
2406
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2407
+	 *
2408
+	 * @access  public
2409
+	 * @return void
2410
+	 * @throws EE_Error
2411
+	 */
2412
+	public function extra_actions_meta_box()
2413
+	{
2414
+		$template_form_fields = [];
2415
+
2416
+		$extra_args = [
2417
+			'msgr'   => $this->_message_template_group->messenger(),
2418
+			'mt'     => $this->_message_template_group->message_type(),
2419
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2420
+		];
2421
+		// first we need to see if there are any fields
2422
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423
+
2424
+		if (! empty($fields)) {
2425
+			// yup there be fields
2426
+			foreach ($fields as $field => $config) {
2427
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2428
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429
+				$default  = isset($config['default']) ? $config['default'] : '';
2430
+				$default  = isset($config['value']) ? $config['value'] : $default;
2431
+
2432
+				// if type is hidden and the value is empty
2433
+				// something may have gone wrong so let's correct with the defaults
2434
+				$fix                = $config['input'] === 'hidden'
2435
+									  && isset($existing[ $field ])
2436
+									  && empty($existing[ $field ])
2437
+					? $default
2438
+					: '';
2439
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
+					? $existing[ $field ]
2441
+					: $fix;
2442
+
2443
+				$template_form_fields[ $field_id ] = [
2444
+					'name'       => 'test_settings_fld[' . $field . ']',
2445
+					'label'      => $config['label'],
2446
+					'input'      => $config['input'],
2447
+					'type'       => $config['type'],
2448
+					'required'   => $config['required'],
2449
+					'validation' => $config['validation'],
2450
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2451
+					'css_class'  => $config['css_class'],
2452
+					'options'    => isset($config['options']) ? $config['options'] : [],
2453
+					'default'    => $default,
2454
+					'format'     => $config['format'],
2455
+				];
2456
+			}
2457
+		}
2458
+
2459
+		$test_settings_html = ! empty($template_form_fields)
2460
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2461
+			: '';
2462
+
2463
+		// print out $test_settings_fields
2464
+		if (! empty($test_settings_html)) {
2465
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466
+			$test_settings_html .= 'name="test_button" value="';
2467
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2468
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2469
+		}
2470
+
2471
+		// and button
2472
+		$test_settings_html .= '<p>';
2473
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2474
+		$test_settings_html .= '</p>';
2475
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2476
+		$test_settings_html .= $this->get_action_link_or_button(
2477
+			'reset_to_default',
2478
+			'reset',
2479
+			$extra_args,
2480
+			'button-primary reset-default-button'
2481
+		);
2482
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2483
+		echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());
2484
+	}
2485
+
2486
+
2487
+	/**
2488
+	 * This returns the shortcode selector skeleton for a given context and field.
2489
+	 *
2490
+	 * @param string $field           The name of the field retrieving shortcodes for.
2491
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2492
+	 * @return string
2493
+	 * @throws DomainException
2494
+	 * @throws EE_Error
2495
+	 * @throws InvalidArgumentException
2496
+	 * @throws ReflectionException
2497
+	 * @throws InvalidDataTypeException
2498
+	 * @throws InvalidInterfaceException
2499
+	 * @since 4.9.rc.000
2500
+	 */
2501
+	protected function _get_shortcode_selector($field, $linked_input_id)
2502
+	{
2503
+		$template_args = [
2504
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2505
+			'fieldname'       => $field,
2506
+			'linked_input_id' => $linked_input_id,
2507
+		];
2508
+
2509
+		return EEH_Template::display_template(
2510
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2511
+			$template_args,
2512
+			true
2513
+		);
2514
+	}
2515
+
2516
+
2517
+	/**
2518
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2519
+	 * page)
2520
+	 *
2521
+	 * @access public
2522
+	 * @return void
2523
+	 * @throws EE_Error
2524
+	 * @throws InvalidArgumentException
2525
+	 * @throws ReflectionException
2526
+	 * @throws InvalidDataTypeException
2527
+	 * @throws InvalidInterfaceException
2528
+	 */
2529
+	public function shortcode_meta_box()
2530
+	{
2531
+		$shortcodes = $this->_get_shortcodes([], false);
2532
+		// just make sure the shortcodes property is set
2533
+		// $messenger = $this->_message_template_group->messenger_obj();
2534
+		// now let's set the content depending on the status of the shortcodes array
2535
+		if (empty($shortcodes)) {
2536
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2537
+			return;
2538
+		}
2539
+		?>
2540 2540
         <div style="float:right; margin-top:10px">
2541 2541
             <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags());
2542
-            ?>
2542
+			?>
2543 2543
         </div>
2544 2544
         <p class="small-text">
2545 2545
             <?php printf(
2546
-                esc_html__(
2547
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
-                    'event_espresso'
2549
-                ),
2550
-                '<span class="dashicons dashicons-menu"></span>'
2551
-            ); ?>
2546
+				esc_html__(
2547
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2548
+					'event_espresso'
2549
+				),
2550
+				'<span class="dashicons dashicons-menu"></span>'
2551
+			); ?>
2552 2552
         </p>
2553 2553
         <?php
2554
-    }
2555
-
2556
-
2557
-    /**
2558
-     * used to set the $_shortcodes property for when its needed elsewhere.
2559
-     *
2560
-     * @access protected
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     * @throws InvalidArgumentException
2564
-     * @throws ReflectionException
2565
-     * @throws InvalidDataTypeException
2566
-     * @throws InvalidInterfaceException
2567
-     */
2568
-    protected function _set_shortcodes()
2569
-    {
2570
-
2571
-        // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2573
-            return;
2574
-        }
2575
-
2576
-        $this->_shortcodes = $this->_get_shortcodes();
2577
-    }
2578
-
2579
-
2580
-    /**
2581
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
-     * property)
2583
-     *
2584
-     * @access  protected
2585
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
-     *                         for. Defaults to all (for the given context)
2587
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
-     *                         true just an array of shortcode/label pairs.
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws ReflectionException
2593
-     * @throws InvalidDataTypeException
2594
-     * @throws InvalidInterfaceException
2595
-     */
2596
-    protected function _get_shortcodes($fields = [], $merged = true)
2597
-    {
2598
-        $this->_set_message_template_group();
2599
-
2600
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2601
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
-        if (empty($GRP_ID)) {
2603
-            return [];
2604
-        }
2605
-        $context = $this->request->getRequestParam(
2606
-            'messenger',
2607
-            key($this->_message_template_group->contexts_config())
2608
-        );
2609
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * This sets the _message_template property (containing the called message_template object)
2615
-     *
2616
-     * @access protected
2617
-     * @return void
2618
-     * @throws EE_Error
2619
-     * @throws InvalidArgumentException
2620
-     * @throws ReflectionException
2621
-     * @throws InvalidDataTypeException
2622
-     * @throws InvalidInterfaceException
2623
-     */
2624
-    protected function _set_message_template_group()
2625
-    {
2626
-        // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2628
-            return;
2629
-        }
2630
-
2631
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
-
2634
-        // let's get the message templates
2635
-        $this->_message_template_group = ! empty($GRP_ID)
2636
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
-            : $this->getMtgModel()->create_default_object();
2638
-
2639
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2640
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * sets up a context switcher for edit forms
2646
-     *
2647
-     * @access  protected
2648
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
-     * @param array                     $args                  various things the context switcher needs.
2650
-     * @throws EE_Error
2651
-     */
2652
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
-    {
2654
-        $context_details = $template_group_object->contexts_config();
2655
-        $context_label   = $template_group_object->context_label();
2656
-        ob_start();
2657
-        ?>
2554
+	}
2555
+
2556
+
2557
+	/**
2558
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2559
+	 *
2560
+	 * @access protected
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 * @throws InvalidArgumentException
2564
+	 * @throws ReflectionException
2565
+	 * @throws InvalidDataTypeException
2566
+	 * @throws InvalidInterfaceException
2567
+	 */
2568
+	protected function _set_shortcodes()
2569
+	{
2570
+
2571
+		// no need to run this if the property is already set
2572
+		if (! empty($this->_shortcodes)) {
2573
+			return;
2574
+		}
2575
+
2576
+		$this->_shortcodes = $this->_get_shortcodes();
2577
+	}
2578
+
2579
+
2580
+	/**
2581
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2582
+	 * property)
2583
+	 *
2584
+	 * @access  protected
2585
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2586
+	 *                         for. Defaults to all (for the given context)
2587
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2588
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2589
+	 *                         true just an array of shortcode/label pairs.
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws ReflectionException
2593
+	 * @throws InvalidDataTypeException
2594
+	 * @throws InvalidInterfaceException
2595
+	 */
2596
+	protected function _get_shortcodes($fields = [], $merged = true)
2597
+	{
2598
+		$this->_set_message_template_group();
2599
+
2600
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2601
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2602
+		if (empty($GRP_ID)) {
2603
+			return [];
2604
+		}
2605
+		$context = $this->request->getRequestParam(
2606
+			'messenger',
2607
+			key($this->_message_template_group->contexts_config())
2608
+		);
2609
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * This sets the _message_template property (containing the called message_template object)
2615
+	 *
2616
+	 * @access protected
2617
+	 * @return void
2618
+	 * @throws EE_Error
2619
+	 * @throws InvalidArgumentException
2620
+	 * @throws ReflectionException
2621
+	 * @throws InvalidDataTypeException
2622
+	 * @throws InvalidInterfaceException
2623
+	 */
2624
+	protected function _set_message_template_group()
2625
+	{
2626
+		// get out if this is already set.
2627
+		if (! empty($this->_message_template_group)) {
2628
+			return;
2629
+		}
2630
+
2631
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2632
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2633
+
2634
+		// let's get the message templates
2635
+		$this->_message_template_group = ! empty($GRP_ID)
2636
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2637
+			: $this->getMtgModel()->create_default_object();
2638
+
2639
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2640
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * sets up a context switcher for edit forms
2646
+	 *
2647
+	 * @access  protected
2648
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2649
+	 * @param array                     $args                  various things the context switcher needs.
2650
+	 * @throws EE_Error
2651
+	 */
2652
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2653
+	{
2654
+		$context_details = $template_group_object->contexts_config();
2655
+		$context_label   = $template_group_object->context_label();
2656
+		ob_start();
2657
+		?>
2658 2658
         <div class="ee-msg-switcher-container">
2659 2659
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2660 2660
                 <?php
2661
-                foreach ($args as $name => $value) {
2662
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2663
-                        continue;
2664
-                    }
2665
-                    ?>
2661
+				foreach ($args as $name => $value) {
2662
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2663
+						continue;
2664
+					}
2665
+					?>
2666 2666
                     <input type="hidden"
2667 2667
                            name="<?php echo esc_attr($name); ?>"
2668 2668
                            value="<?php echo esc_attr($value); ?>"
2669 2669
                     />
2670 2670
                     <?php
2671
-                }
2672
-                // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
-                ?>
2671
+				}
2672
+				// setup nonce_url
2673
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2675
+				?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2678 2678
                 </label>
2679 2679
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2680 2680
                     <?php
2681
-                    $context_templates = $template_group_object->context_templates();
2682
-                    if (is_array($context_templates)) :
2683
-                        foreach ($context_templates as $context => $template_fields) :
2684
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2685
-                            ?>
2681
+					$context_templates = $template_group_object->context_templates();
2682
+					if (is_array($context_templates)) :
2683
+						foreach ($context_templates as $context => $template_fields) :
2684
+							$checked = ($context === $args['context']) ? 'selected' : '';
2685
+							?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687 2687
                                 <?php echo esc_html($context_details[ $context ]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690
-                    endif; ?>
2690
+					endif; ?>
2691 2691
                 </select>
2692 2692
                 <?php $button_text = sprintf(
2693
-                    esc_html__('Switch %s', 'event_espresso'),
2694
-                    ucwords($context_label['label'])
2695
-                ); ?>
2693
+					esc_html__('Switch %s', 'event_espresso'),
2694
+					ucwords($context_label['label'])
2695
+				); ?>
2696 2696
                 <input class='button-secondary'
2697 2697
                        id="submit-msg-context-switcher-sbmt"
2698 2698
                        type="submit"
@@ -2702,1994 +2702,1994 @@  discard block
 block discarded – undo
2702 2702
             <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>
2703 2703
         </div> <!-- end .ee-msg-switcher-container -->
2704 2704
         <?php
2705
-        $this->_context_switcher = ob_get_clean();
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * @param bool $new
2711
-     * @throws EE_Error
2712
-     * @throws ReflectionException
2713
-     */
2714
-    protected function _insert_or_update_message_template($new = false)
2715
-    {
2716
-        $form_data    = $this->getMessageTemplateFormData();
2717
-        $GRP_ID       = $form_data['GRP_ID'];
2718
-        $messenger    = $form_data['MTP_messenger'];
2719
-        $message_type = $form_data['MTP_message_type'];
2720
-        $context      = $form_data['MTP_context'];
2721
-
2722
-        // if this is "new" then we need to generate the default contexts
2723
-        // for the selected messenger/message_type for user to edit.
2724
-        list($success, $query_args) = $new
2725
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
-
2728
-        $success     = $success ? 1 : 0;
2729
-        $action_desc = $new ? 'created' : 'updated';
2730
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
-
2733
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * retrieve and sanitize form data
2739
-     *
2740
-     * @return array
2741
-     * @since 4.10.29.p
2742
-     */
2743
-    protected function getMessageTemplateFormData()
2744
-    {
2745
-        return [
2746
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
-        ];
2756
-    }
2757
-
2758
-
2759
-    /**
2760
-     * @param int    $GRP_ID
2761
-     * @param string $messenger
2762
-     * @param string $message_type
2763
-     * @return array no return on AJAX requests
2764
-     * @throws EE_Error
2765
-     * @throws ReflectionException
2766
-     * @since 4.10.29.p
2767
-     */
2768
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
-    {
2770
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
-        $success       = ! empty($new_templates);
2772
-
2773
-        // we return things differently if doing ajax
2774
-        if ($this->request->isAjax()) {
2775
-            $this->_template_args['success'] = $success;
2776
-            $this->_template_args['error']   = ! $success;
2777
-            $this->_template_args['content'] = '';
2778
-            $this->_template_args['data']    = [
2779
-                'grpID'        => $new_templates['GRP_ID'],
2780
-                'templateName' => $new_templates['template_name'],
2781
-            ];
2782
-            if ($success) {
2783
-                EE_Error::overwrite_success();
2784
-                EE_Error::add_success(
2785
-                    esc_html__(
2786
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
-                        'event_espresso'
2788
-                    )
2789
-                );
2790
-            }
2791
-            $this->_return_json();
2792
-        }
2793
-        return [
2794
-            $success,
2795
-            // 'query_args'
2796
-            [
2797
-                'id'      => $new_templates['GRP_ID'],
2798
-                'context' => $new_templates['MTP_context'],
2799
-                'action'  => 'edit_message_template',
2800
-            ],
2801
-        ];
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * @param int    $GRP_ID
2807
-     * @param string $messenger
2808
-     * @param string $message_type
2809
-     * @param string $context
2810
-     * @param array  $form_data
2811
-     * @return array
2812
-     * @throws EE_Error
2813
-     * @since 4.10.29.p
2814
-     */
2815
-    private function updateExistingTemplates(
2816
-        $GRP_ID,
2817
-        $messenger,
2818
-        $message_type,
2819
-        $context,
2820
-        array $form_data
2821
-    ) {
2822
-        $success         = false;
2823
-        $template_fields = $this->getTemplateFields();
2824
-        if ($template_fields) {
2825
-            // if field data is valid, then success will be true
2826
-            $success = $this->validateTemplateFields(
2827
-                $messenger,
2828
-                $message_type,
2829
-                $context,
2830
-                $template_fields
2831
-            );
2832
-            if ($success) {
2833
-                $field_data = [];
2834
-                foreach ($template_fields as $template_field => $content) {
2835
-                    // combine top-level form data with content for this field
2836
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
-                }
2839
-                // we can use the last set_column_values for the MTPG update
2840
-                // (because its the same for all of these specific MTPs)
2841
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
-            }
2843
-        }
2844
-
2845
-        return [
2846
-            $success,
2847
-            // 'query_args'
2848
-            [
2849
-                'id'      => $GRP_ID,
2850
-                'context' => $context,
2851
-                'action'  => 'edit_message_template',
2852
-            ],
2853
-        ];
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * @return array
2859
-     * @since 4.10.29.p
2860
-     */
2861
-    private function getTemplateFields()
2862
-    {
2863
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
-        if (empty($template_fields)) {
2865
-            EE_Error::add_error(
2866
-                esc_html__(
2867
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
-                    'event_espresso'
2869
-                ),
2870
-                __FILE__,
2871
-                __FUNCTION__,
2872
-                __LINE__
2873
-            );
2874
-            return null;
2875
-        }
2876
-        // messages content is expected to be escaped
2877
-        return EEH_Array::addSlashesRecursively($template_fields);
2878
-    }
2879
-
2880
-
2881
-    /**
2882
-     * @param string $messenger
2883
-     * @param string $message_type
2884
-     * @param string $context
2885
-     * @param array  $template_fields
2886
-     * @return bool
2887
-     * @throws EE_Error
2888
-     * @since   4.10.29.p
2889
-     */
2890
-    private function validateTemplateFields(
2891
-        $messenger,
2892
-        $message_type,
2893
-        $context,
2894
-        array $template_fields
2895
-    ) {
2896
-        // first validate all fields!
2897
-        // this filter allows client code to add its own validation to the template fields as well.
2898
-        // returning an empty array means everything passed validation.
2899
-        // errors in validation should be represented in an array with the following shape:
2900
-        // array(
2901
-        //   'fieldname' => array(
2902
-        //          'msg' => 'error message'
2903
-        //          'value' => 'value for field producing error'
2904
-        // )
2905
-        $custom_validation = (array) apply_filters(
2906
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
-            [],
2908
-            $template_fields,
2909
-            $context,
2910
-            $messenger,
2911
-            $message_type
2912
-        );
2913
-
2914
-        $system_validation = $this->getMtgModel()->validate(
2915
-            $template_fields,
2916
-            $context,
2917
-            $messenger,
2918
-            $message_type
2919
-        );
2920
-
2921
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
-        $validates         = array_merge($custom_validation, $system_validation);
2923
-
2924
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
-        //  WE need to make sure there is no actual error messages in validates.
2927
-        if (empty($validates)) {
2928
-            return true;
2929
-        }
2930
-
2931
-        // add the transient so when the form loads we know which fields to highlight
2932
-        $this->_add_transient('edit_message_template', $validates);
2933
-        // setup notices
2934
-        foreach ($validates as $error) {
2935
-            if (isset($error['msg'])) {
2936
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
-            }
2938
-        }
2939
-        return false;
2940
-    }
2941
-
2942
-
2943
-    /**
2944
-     * @param array $field_data
2945
-     * @param array $form_data
2946
-     * @return array
2947
-     * @since   4.10.29.p
2948
-     */
2949
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
-    {
2951
-        return $form_data + [
2952
-                'MTP_ID'             => $field_data['MTP_ID'],
2953
-                'MTP_template_field' => $field_data['name'],
2954
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2956
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
-                    : $field_data['content'],
2958
-            ];
2959
-    }
2960
-
2961
-
2962
-    /**
2963
-     * @param string $template_field
2964
-     * @param array  $form_data
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @since 4.10.29.p
2968
-     */
2969
-    private function updateMessageTemplates($template_field, array $form_data)
2970
-    {
2971
-        $MTP_ID                  = $form_data['MTP_ID'];
2972
-        $message_template_fields = [
2973
-            'GRP_ID'             => $form_data['GRP_ID'],
2974
-            'MTP_template_field' => $form_data['MTP_template_field'],
2975
-            'MTP_context'        => $form_data['MTP_context'],
2976
-            'MTP_content'        => $form_data['MTP_content'],
2977
-        ];
2978
-
2979
-        $hasMtpID = ! empty($MTP_ID);
2980
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2981
-        // this has already been through the template field validator and sanitized, so it will be
2982
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
-        // message template field in a messenger/message type and existing users don't have the
2984
-        // default setup for it.
2985
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
-        $updated = $hasMtpID
2987
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
-            : $this->getMtpModel()->insert($message_template_fields);
2989
-
2990
-        $insert_failed = ! $hasMtpID && ! $updated;
2991
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
-        $update_failed = $hasMtpID && $updated === false;
2994
-
2995
-        if ($insert_failed || $update_failed) {
2996
-            EE_Error::add_error(
2997
-                sprintf(
2998
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
-                    $template_field
3000
-                ),
3001
-                __FILE__,
3002
-                __FUNCTION__,
3003
-                __LINE__
3004
-            );
3005
-            return false;
3006
-        }
3007
-        return true;
3008
-    }
3009
-
3010
-
3011
-    /**
3012
-     * @param array $form_data
3013
-     * @return bool
3014
-     * @throws EE_Error
3015
-     * @since 4.10.29.p
3016
-     */
3017
-    private function updateMessageTemplateGroup(array $form_data)
3018
-    {
3019
-        $GRP_ID  = $form_data['GRP_ID'];
3020
-        $updated = $this->getMtgModel()->update(
3021
-        // fields and values
3022
-            [
3023
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3024
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3025
-                'MTP_message_type' => $form_data['MTP_message_type'],
3026
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3027
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3028
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3029
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3030
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
-                'MTP_description'  => $this->request->getRequestParam(
3032
-                    'ee_msg_non_global_fields[MTP_description]',
3033
-                    ''
3034
-                ),
3035
-            ],
3036
-            // where
3037
-            [['GRP_ID' => $GRP_ID]]
3038
-        );
3039
-
3040
-        if ($updated === false) {
3041
-            EE_Error::add_error(
3042
-                sprintf(
3043
-                    esc_html__(
3044
-                        'The Message Template Group (%d) was NOT updated for some reason',
3045
-                        'event_espresso'
3046
-                    ),
3047
-                    $form_data['GRP_ID']
3048
-                ),
3049
-                __FILE__,
3050
-                __FUNCTION__,
3051
-                __LINE__
3052
-            );
3053
-            return false;
3054
-        }
3055
-        // k now we need to ensure the template_pack and template_variation fields are set.
3056
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
-
3059
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3061
-            $message_template_group->set_template_pack_name($template_pack);
3062
-            $message_template_group->set_template_pack_variation($template_variation);
3063
-        }
3064
-        return true;
3065
-    }
3066
-
3067
-
3068
-    /**
3069
-     * recursively runs wp_kses() on message template content in a model safe manner
3070
-     *
3071
-     * @param array|string $content
3072
-     * @return array|string
3073
-     * @since   4.10.29.p
3074
-     */
3075
-    private function sanitizeMessageTemplateContent($content)
3076
-    {
3077
-        if (is_array($content)) {
3078
-            foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
-            }
3081
-            return $content;
3082
-        }
3083
-        // remove slashes so wp_kses() works properly
3084
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3085
-        // so attributes using single quotes always appear invalid.
3086
-        $content = stripslashes($content);
3087
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3088
-        // But currently the models expect slashed data, so after wp_kses()
3089
-        // runs we need to re-slash the data. Sheesh.
3090
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
-        return addslashes($content);
3092
-    }
3093
-
3094
-
3095
-    /**
3096
-     * @param string $messenger
3097
-     * @param string $message_type
3098
-     * @param string $context
3099
-     * @return string
3100
-     * @since 4.10.29.p
3101
-     */
3102
-    private function generateUpdateDescription($messenger, $message_type, $context)
3103
-    {
3104
-        // need the message type and messenger objects to be able to use the labels for the notices
3105
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
-        $messenger_label  = $messenger_object instanceof EE_messenger
3107
-            ? ucwords($messenger_object->label['singular'])
3108
-            : '';
3109
-
3110
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
-        $message_type_label  = $message_type_object instanceof EE_message_type
3112
-            ? ucwords($message_type_object->label['singular'])
3113
-            : '';
3114
-
3115
-        $context   = ucwords(str_replace('_', ' ', $context));
3116
-        $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
-            : '';
3119
-        $item_desc .= 'Message Template';
3120
-        return $item_desc;
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     * @param string $messenger
3126
-     * @param string $message_type
3127
-     * @param string $context
3128
-     * @return bool
3129
-     * @throws EE_Error
3130
-     * @throws ReflectionException
3131
-     * @since 4.10.29.p
3132
-     */
3133
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
-    {
3135
-        // was a test send triggered?
3136
-        if ($this->request->requestParamIsSet('test_button')) {
3137
-            EE_Error::overwrite_success();
3138
-            $this->_do_test_send($context, $messenger, $message_type);
3139
-            return true;
3140
-        }
3141
-        return false;
3142
-    }
3143
-
3144
-
3145
-    /**
3146
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
-     *
3148
-     * @param string $context      what context being tested
3149
-     * @param string $messenger    messenger being tested
3150
-     * @param string $message_type message type being tested
3151
-     * @throws EE_Error
3152
-     * @throws InvalidArgumentException
3153
-     * @throws InvalidDataTypeException
3154
-     * @throws InvalidInterfaceException
3155
-     * @throws ReflectionException
3156
-     */
3157
-    protected function _do_test_send($context, $messenger, $message_type)
3158
-    {
3159
-        // set things up for preview
3160
-        $this->request->setRequestParam('messenger', $messenger);
3161
-        $this->request->setRequestParam('message_type', $message_type);
3162
-        $this->request->setRequestParam('context', $context);
3163
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
-
3166
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
-
3169
-        // let's save any existing fields that might be required by the messenger
3170
-        if (
3171
-            ! empty($test_settings_fld)
3172
-            && $active_messenger instanceof EE_messenger
3173
-            && apply_filters(
3174
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
-                true,
3176
-                $test_settings_fld,
3177
-                $active_messenger
3178
-            )
3179
-        ) {
3180
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3181
-        }
3182
-
3183
-        /**
3184
-         * Use filter to add additional controls on whether message can send or not
3185
-         */
3186
-        if (
3187
-            apply_filters(
3188
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
-                true,
3190
-                $context,
3191
-                $this->request->requestParams(),
3192
-                $messenger,
3193
-                $message_type
3194
-            )
3195
-        ) {
3196
-            if (EEM_Event::instance()->count() > 0) {
3197
-                $success = $this->_preview_message(true);
3198
-                if ($success) {
3199
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
-                } else {
3201
-                    EE_Error::add_error(
3202
-                        esc_html__('The test message was not sent', 'event_espresso'),
3203
-                        __FILE__,
3204
-                        __FUNCTION__,
3205
-                        __LINE__
3206
-                    );
3207
-                }
3208
-            } else {
3209
-                $this->noEventsErrorMessage(true);
3210
-            }
3211
-        }
3212
-    }
3213
-
3214
-
3215
-    /**
3216
-     * _generate_new_templates
3217
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
-     * for the event.
3220
-     *
3221
-     *
3222
-     * @param string $messenger      the messenger we are generating templates for
3223
-     * @param array  $message_types  array of message types that the templates are generated for.
3224
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
-     *                               indicate the message_template_group being used as the base.
3226
-     *
3227
-     * @param bool   $global
3228
-     *
3229
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
-     *                               encountering problems.
3231
-     * @throws EE_Error
3232
-     * @throws ReflectionException
3233
-     */
3234
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
-    {
3236
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
-        // just don't generate any templates.
3238
-        if (empty($message_types)) {
3239
-            return [];
3240
-        }
3241
-
3242
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
-        return $templates[0];
3244
-    }
3245
-
3246
-
3247
-    /**
3248
-     * [_trash_or_restore_message_template]
3249
-     *
3250
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
-     *                        an individual context (FALSE).
3253
-     * @return void
3254
-     * @throws EE_Error
3255
-     * @throws InvalidArgumentException
3256
-     * @throws InvalidDataTypeException
3257
-     * @throws InvalidInterfaceException
3258
-     */
3259
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
-    {
3261
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
-
3263
-        $success = 1;
3264
-
3265
-        // incoming GRP_IDs
3266
-        if ($all) {
3267
-            // Checkboxes
3268
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3270
-                // if array has more than one element then success message should be plural.
3271
-                // todo: what about nonce?
3272
-                $success = count($checkboxes) > 1 ? 2 : 1;
3273
-
3274
-                // cycle through checkboxes
3275
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3276
-                    $trashed_or_restored = $trash
3277
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3280
-                        $success = 0;
3281
-                    }
3282
-                }
3283
-            } else {
3284
-                // grab single GRP_ID and handle
3285
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3287
-                    $trashed_or_restored = $trash
3288
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3291
-                        $success = 0;
3292
-                    }
3293
-                } else {
3294
-                    $success = 0;
3295
-                }
3296
-            }
3297
-        }
3298
-
3299
-        $action_desc = $trash
3300
-            ? esc_html__('moved to the trash', 'event_espresso')
3301
-            : esc_html__('restored', 'event_espresso');
3302
-
3303
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
-
3306
-        $item_desc = $all ? _n(
3307
-            'Message Template Group',
3308
-            'Message Template Groups',
3309
-            $success,
3310
-            'event_espresso'
3311
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
-
3313
-        $item_desc = $template_switch
3314
-            ? _n('template', 'templates', $success, 'event_espresso')
3315
-            : $item_desc;
3316
-
3317
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
-    }
3319
-
3320
-
3321
-    /**
3322
-     * [_delete_message_template]
3323
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
-     *
3325
-     * @return void
3326
-     * @throws EE_Error
3327
-     * @throws InvalidArgumentException
3328
-     * @throws InvalidDataTypeException
3329
-     * @throws InvalidInterfaceException
3330
-     * @throws ReflectionException
3331
-     */
3332
-    protected function _delete_message_template()
3333
-    {
3334
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
-
3336
-        // checkboxes
3337
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3339
-            // if array has more than one element then success message should be plural
3340
-            $success = count($checkboxes) > 1 ? 2 : 1;
3341
-
3342
-            // cycle through bulk action checkboxes
3343
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3344
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
-            }
3346
-        } else {
3347
-            // grab single grp_id and delete
3348
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3350
-        }
3351
-
3352
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
-    }
3354
-
3355
-
3356
-    /**
3357
-     * helper for permanently deleting a mtP group and all related message_templates
3358
-     *
3359
-     * @param int  $GRP_ID        The group being deleted
3360
-     * @param bool $include_group whether to delete the Message Template Group as well.
3361
-     * @return bool boolean to indicate the success of the deletes or not.
3362
-     * @throws EE_Error
3363
-     * @throws InvalidArgumentException
3364
-     * @throws InvalidDataTypeException
3365
-     * @throws InvalidInterfaceException
3366
-     * @throws ReflectionException
3367
-     * @throws ReflectionException
3368
-     */
3369
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
-    {
3371
-        $success = true;
3372
-        // first let's GET this group
3373
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
-        // then delete permanently all the related Message Templates
3375
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3376
-
3377
-        if ($deleted === 0) {
3378
-            $success = false;
3379
-        }
3380
-
3381
-        // now delete permanently this particular group
3382
-
3383
-        if ($include_group && ! $MTG->delete_permanently()) {
3384
-            $success = false;
3385
-        }
3386
-
3387
-        return $success;
3388
-    }
3389
-
3390
-
3391
-    /**
3392
-     *    _learn_more_about_message_templates_link
3393
-     *
3394
-     * @access protected
3395
-     * @return string
3396
-     */
3397
-    protected function _learn_more_about_message_templates_link()
3398
-    {
3399
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3401
-               . '</a>';
3402
-    }
3403
-
3404
-
3405
-    /**
3406
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
-     * ajax and other routes.
3408
-     *
3409
-     * @return void
3410
-     * @throws DomainException
3411
-     * @throws EE_Error
3412
-     */
3413
-    protected function _settings()
3414
-    {
3415
-        $this->_set_m_mt_settings();
3416
-
3417
-        // let's setup the messenger tabs
3418
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
-            $this->_m_mt_settings['messenger_tabs'],
3420
-            'messenger_links',
3421
-            '|',
3422
-            $this->request->getRequestParam('selected_messenger', 'email')
3423
-        );
3424
-
3425
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
-
3428
-        $this->display_admin_page_with_sidebar();
3429
-    }
3430
-
3431
-
3432
-    /**
3433
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
-     *
3435
-     * @access protected
3436
-     * @return void
3437
-     * @throws DomainException
3438
-     */
3439
-    protected function _set_m_mt_settings()
3440
-    {
3441
-        // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3443
-            return;
3444
-        }
3445
-
3446
-        // get all installed messengers and message_types
3447
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3448
-        $message_types = $this->_message_resource_manager->installed_message_types();
3449
-
3450
-
3451
-        // assemble the array for the _tab_text_links helper
3452
-
3453
-        foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
-                'label' => ucwords($messenger->label['singular']),
3456
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
-                    ? 'messenger-active'
3458
-                    : '',
3459
-                'href'  => $messenger->name,
3460
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
-                'slug'  => $messenger->name,
3462
-                'obj'   => $messenger,
3463
-            ];
3464
-
3465
-
3466
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3467
-
3468
-            foreach ($message_types as $message_type) {
3469
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
-                // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
-                    continue;
3473
-                }
3474
-
3475
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
-                    $messenger->name,
3477
-                    $message_type->name
3478
-                )
3479
-                    ? 'active'
3480
-                    : 'inactive';
3481
-
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
-                    'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
-                    'title'    => $a_or_i === 'active'
3489
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
-                    'content'  => $a_or_i === 'active'
3492
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3493
-                        : $this->_message_type_settings_content($message_type, $messenger),
3494
-                    'slug'     => $message_type->name,
3495
-                    'active'   => $a_or_i === 'active',
3496
-                    'obj'      => $message_type,
3497
-                ];
3498
-            }
3499
-        }
3500
-    }
3501
-
3502
-
3503
-    /**
3504
-     * This just prepares the content for the message type settings
3505
-     *
3506
-     * @param EE_message_type $message_type The message type object
3507
-     * @param EE_messenger    $messenger    The messenger object
3508
-     * @param boolean         $active       Whether the message type is active or not
3509
-     * @return string html output for the content
3510
-     * @throws DomainException
3511
-     */
3512
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
-    {
3514
-        // get message type fields
3515
-        $fields                                         = $message_type->get_admin_settings_fields();
3516
-        $settings_template_args['template_form_fields'] = '';
3517
-
3518
-        if (! empty($fields) && $active) {
3519
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
-            foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3524
-                    'label'      => $fldprops['label'],
3525
-                    'input'      => $fldprops['field_type'],
3526
-                    'type'       => $fldprops['value_type'],
3527
-                    'required'   => $fldprops['required'],
3528
-                    'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3531
-                        : $fldprops['default'],
3532
-                    'options'    => isset($fldprops['options'])
3533
-                        ? $fldprops['options']
3534
-                        : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3537
-                        : $fldprops['default'],
3538
-                    'css_class'  => 'no-drag',
3539
-                    'format'     => $fldprops['format'],
3540
-                ];
3541
-            }
3542
-
3543
-
3544
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
-                ? $this->_generate_admin_form_fields(
3546
-                    $template_form_field,
3547
-                    'string',
3548
-                    'ee_mt_activate_form'
3549
-                )
3550
-                : '';
3551
-        }
3552
-
3553
-        $settings_template_args['description'] = $message_type->description;
3554
-        // we also need some hidden fields
3555
-        $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
-                'type'  => 'hidden',
3558
-                'value' => $messenger->name,
3559
-            ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3561
-                'type'  => 'hidden',
3562
-                'value' => $message_type->name,
3563
-            ],
3564
-            'type' . $message_type->name                                => [
3565
-                'type'  => 'hidden',
3566
-                'value' => 'message_type',
3567
-            ],
3568
-        ];
3569
-
3570
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
-            $hidden_fields,
3572
-            'array'
3573
-        );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
-            ? ' hidden'
3576
-            : '';
3577
-
3578
-
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
-        return EEH_Template::display_template($template, $settings_template_args, true);
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
-     *
3587
-     * @access protected
3588
-     * @return void
3589
-     * @throws DomainException
3590
-     */
3591
-    protected function _messages_settings_metaboxes()
3592
-    {
3593
-        $this->_set_m_mt_settings();
3594
-        $m_boxes         = $mt_boxes = [];
3595
-        $m_template_args = $mt_template_args = [];
3596
-
3597
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
-
3599
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
-
3605
-                // messenger meta boxes
3606
-                $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
-                    : '';
3610
-
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
-                    esc_html__('%s Settings', 'event_espresso'),
3613
-                    $tab_array['label']
3614
-                );
3615
-
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
-                    'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
-                    )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
-                        : '',
3623
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
-                    'hidden'                 => $active ? '' : ' hidden',
3625
-                    'hide_on_message'        => $hide_on_message,
3626
-                    'messenger'              => $messenger,
3627
-                    'active'                 => $active,
3628
-                ];
3629
-
3630
-                // message type meta boxes
3631
-                // (which is really just the inactive container for each messenger
3632
-                // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3635
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
-                    'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
-                    )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
-                        : '',
3641
-                    'hidden'                 => $active ? '' : ' hidden',
3642
-                    'hide_on_message'        => $hide_on_message,
3643
-                    'hide_off_message'       => $hide_off_message,
3644
-                    'messenger'              => $messenger,
3645
-                    'active'                 => $active,
3646
-                ];
3647
-            }
3648
-        }
3649
-
3650
-
3651
-        // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
-        foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
-            $msgr          = str_replace('_a_box', '', $box);
3656
-            add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3658
-                $label,
3659
-                function ($post, $metabox) {
3660
-                    EEH_Template::display_template(
3661
-                        $metabox['args']['template_path'],
3662
-                        $metabox['args']['template_args']
3663
-                    );
3664
-                },
3665
-                $this->_current_screen->id,
3666
-                'normal',
3667
-                'high',
3668
-                $callback_args
3669
-            );
3670
-        }
3671
-
3672
-        // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
-        foreach ($mt_boxes as $box => $label) {
3675
-            $callback_args = [
3676
-                'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3678
-            ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3680
-            add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3682
-                $label,
3683
-                function ($post, $metabox) {
3684
-                    EEH_Template::display_template(
3685
-                        $metabox['args']['template_path'],
3686
-                        $metabox['args']['template_args']
3687
-                    );
3688
-                },
3689
-                $this->_current_screen->id,
3690
-                'side',
3691
-                'high',
3692
-                $callback_args
3693
-            );
3694
-        }
3695
-
3696
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3697
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
-        if (is_main_site()) {
3699
-            add_meta_box(
3700
-                'espresso_global_message_settings',
3701
-                esc_html__('Global Message Settings', 'event_espresso'),
3702
-                [$this, 'global_messages_settings_metabox_content'],
3703
-                $this->_current_screen->id,
3704
-                'normal',
3705
-                'low',
3706
-                []
3707
-            );
3708
-        }
3709
-    }
3710
-
3711
-
3712
-    /**
3713
-     *  This generates the content for the global messages settings metabox.
3714
-     *
3715
-     * @return void
3716
-     * @throws EE_Error
3717
-     * @throws InvalidArgumentException
3718
-     * @throws ReflectionException
3719
-     * @throws InvalidDataTypeException
3720
-     * @throws InvalidInterfaceException
3721
-     */
3722
-    public function global_messages_settings_metabox_content()
3723
-    {
3724
-        $form = $this->_generate_global_settings_form();
3725
-        echo wp_kses(
3726
-            $form->form_open(
3727
-                $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
-                'POST'
3729
-            ),
3730
-            AllowedTags::getWithFormTags()
3731
-        );
3732
-        echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
-        echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
-    }
3735
-
3736
-
3737
-    /**
3738
-     * This generates and returns the form object for the global messages settings.
3739
-     *
3740
-     * @return EE_Form_Section_Proper
3741
-     * @throws EE_Error
3742
-     * @throws InvalidArgumentException
3743
-     * @throws ReflectionException
3744
-     * @throws InvalidDataTypeException
3745
-     * @throws InvalidInterfaceException
3746
-     */
3747
-    protected function _generate_global_settings_form()
3748
-    {
3749
-        /** @var EE_Network_Core_Config $network_config */
3750
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3751
-
3752
-        return new EE_Form_Section_Proper(
3753
-            [
3754
-                'name'            => 'global_messages_settings',
3755
-                'html_id'         => 'global_messages_settings',
3756
-                'html_class'      => 'form-table',
3757
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
-                'subsections'     => apply_filters(
3759
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
-                    [
3761
-                        'do_messages_on_same_request' => new EE_Select_Input(
3762
-                            [
3763
-                                true  => esc_html__('On the same request', 'event_espresso'),
3764
-                                false => esc_html__('On a separate request', 'event_espresso'),
3765
-                            ],
3766
-                            [
3767
-                                'default'         => $network_config->do_messages_on_same_request,
3768
-                                'html_label_text' => esc_html__(
3769
-                                    'Generate and send all messages:',
3770
-                                    'event_espresso'
3771
-                                ),
3772
-                                'html_help_text'  => esc_html__(
3773
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
-                                    'event_espresso'
3775
-                                ),
3776
-                            ]
3777
-                        ),
3778
-                        'delete_threshold'            => new EE_Select_Input(
3779
-                            [
3780
-                                0  => esc_html__('Forever', 'event_espresso'),
3781
-                                3  => esc_html__('3 Months', 'event_espresso'),
3782
-                                6  => esc_html__('6 Months', 'event_espresso'),
3783
-                                9  => esc_html__('9 Months', 'event_espresso'),
3784
-                                12 => esc_html__('12 Months', 'event_espresso'),
3785
-                                24 => esc_html__('24 Months', 'event_espresso'),
3786
-                                36 => esc_html__('36 Months', 'event_espresso'),
3787
-                            ],
3788
-                            [
3789
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
-                                'html_help_text'  => esc_html__(
3792
-                                    'You can control how long a record of processed messages is kept via this option.',
3793
-                                    'event_espresso'
3794
-                                ),
3795
-                            ]
3796
-                        ),
3797
-                        'update_settings'             => new EE_Submit_Input(
3798
-                            [
3799
-                                'default'         => esc_html__('Update', 'event_espresso'),
3800
-                                'html_label_text' => '',
3801
-                            ]
3802
-                        ),
3803
-                    ]
3804
-                ),
3805
-            ]
3806
-        );
3807
-    }
3808
-
3809
-
3810
-    /**
3811
-     * This handles updating the global settings set on the admin page.
3812
-     *
3813
-     * @throws EE_Error
3814
-     * @throws InvalidDataTypeException
3815
-     * @throws InvalidInterfaceException
3816
-     * @throws InvalidArgumentException
3817
-     * @throws ReflectionException
3818
-     */
3819
-    protected function _update_global_settings()
3820
-    {
3821
-        /** @var EE_Network_Core_Config $network_config */
3822
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3823
-        $messages_config = EE_Registry::instance()->CFG->messages;
3824
-        $form            = $this->_generate_global_settings_form();
3825
-        if ($form->was_submitted()) {
3826
-            $form->receive_form_submission();
3827
-            if ($form->is_valid()) {
3828
-                $valid_data = $form->valid_data();
3829
-                foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3831
-                    if (method_exists($network_config, $setter)) {
3832
-                        $network_config->{$setter}($value);
3833
-                    } elseif (
3834
-                        property_exists($network_config, $property)
3835
-                        && $network_config->{$property} !== $value
3836
-                    ) {
3837
-                        $network_config->{$property} = $value;
3838
-                    } elseif (
3839
-                        property_exists($messages_config, $property)
3840
-                        && $messages_config->{$property} !== $value
3841
-                    ) {
3842
-                        $messages_config->{$property} = $value;
3843
-                    }
3844
-                }
3845
-                // only update if the form submission was valid!
3846
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
-                EE_Registry::instance()->CFG->update_espresso_config();
3848
-                EE_Error::overwrite_success();
3849
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
-            }
3851
-        }
3852
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
-     *
3859
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
-     * @return string html formatted tabs
3861
-     * @throws DomainException
3862
-     */
3863
-    protected function _get_mt_tabs($tab_array)
3864
-    {
3865
-        $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
-        $tabs      = '';
3868
-
3869
-        foreach ($tab_array as $tab) {
3870
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3871
-        }
3872
-
3873
-        return $tabs;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * This prepares the content of the messenger meta box admin settings
3879
-     *
3880
-     * @param EE_messenger $messenger The messenger we're setting up content for
3881
-     * @return string html formatted content
3882
-     * @throws DomainException
3883
-     */
3884
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3885
-    {
3886
-
3887
-        $fields                                         = $messenger->get_admin_settings_fields();
3888
-        $settings_template_args['template_form_fields'] = '';
3889
-
3890
-        // is $messenger active?
3891
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
-
3893
-
3894
-        if (! empty($fields)) {
3895
-            $existing_settings = $messenger->get_existing_admin_settings();
3896
-
3897
-            foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3901
-                    'label'      => $fldprops['label'],
3902
-                    'input'      => $fldprops['field_type'],
3903
-                    'type'       => $fldprops['value_type'],
3904
-                    'required'   => $fldprops['required'],
3905
-                    'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3908
-                        : $fldprops['default'],
3909
-                    'css_class'  => '',
3910
-                    'format'     => $fldprops['format'],
3911
-                ];
3912
-            }
3913
-
3914
-
3915
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
-                : '';
3918
-        }
3919
-
3920
-        // we also need some hidden fields
3921
-        $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3923
-                'type'  => 'hidden',
3924
-                'value' => $messenger->name,
3925
-            ],
3926
-            'type' . $messenger->name                          => [
3927
-                'type'  => 'hidden',
3928
-                'value' => 'messenger',
3929
-            ],
3930
-        ];
3931
-
3932
-        // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
-                    'type'  => 'hidden',
3937
-                    'value' => $mt,
3938
-                ];
3939
-            }
3940
-        }
3941
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
-            $settings_template_args['hidden_fields'],
3943
-            'array'
3944
-        );
3945
-        $active                                  =
3946
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3947
-
3948
-        $settings_template_args['messenger']           = $messenger->name;
3949
-        $settings_template_args['description']         = $messenger->description;
3950
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
-
3952
-
3953
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
-            $messenger->name
3955
-        )
3956
-            ? $settings_template_args['show_hide_edit_form']
3957
-            : ' hidden';
3958
-
3959
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
-            ? ' hidden'
3961
-            : $settings_template_args['show_hide_edit_form'];
3962
-
3963
-
3964
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
-        $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
-        return EEH_Template::display_template(
3969
-            $template,
3970
-            $settings_template_args,
3971
-            true
3972
-        );
3973
-    }
3974
-
3975
-
3976
-    /**
3977
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3978
-     *
3979
-     * @throws DomainException
3980
-     * @throws EE_Error
3981
-     * @throws InvalidDataTypeException
3982
-     * @throws InvalidInterfaceException
3983
-     * @throws InvalidArgumentException
3984
-     * @throws ReflectionException
3985
-     */
3986
-    public function activate_messenger_toggle()
3987
-    {
3988
-        $success = true;
3989
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
-        // let's check that we have required data
3991
-
3992
-        if (! $this->_active_messenger_name) {
3993
-            EE_Error::add_error(
3994
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
-                __FILE__,
3996
-                __FUNCTION__,
3997
-                __LINE__
3998
-            );
3999
-            $success = false;
4000
-        }
4001
-
4002
-        // do a nonce check here since we're not arriving via a normal route
4003
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
-
4006
-        $this->_verify_nonce($nonce, $nonce_ref);
4007
-
4008
-
4009
-        $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4011
-            EE_Error::add_error(
4012
-                esc_html__(
4013
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
-                    'event_espresso'
4015
-                ),
4016
-                __FILE__,
4017
-                __FUNCTION__,
4018
-                __LINE__
4019
-            );
4020
-            $success = false;
4021
-        }
4022
-
4023
-        // do check to verify we have a valid status.
4024
-        if ($status !== 'off' && $status !== 'on') {
4025
-            EE_Error::add_error(
4026
-                sprintf(
4027
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
-                    $status
4029
-                ),
4030
-                __FILE__,
4031
-                __FUNCTION__,
4032
-                __LINE__
4033
-            );
4034
-            $success = false;
4035
-        }
4036
-
4037
-        if ($success) {
4038
-            // made it here?  Stop dawdling then!!
4039
-            $success = $status === 'off'
4040
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4041
-                : $this->_activate_messenger($this->_active_messenger_name);
4042
-        }
4043
-
4044
-        $this->_template_args['success'] = $success;
4045
-
4046
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
-        $this->_return_json();
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * used by ajax from the messages settings page to activate|deactivate a message type
4053
-     *
4054
-     * @throws DomainException
4055
-     * @throws EE_Error
4056
-     * @throws ReflectionException
4057
-     * @throws InvalidDataTypeException
4058
-     * @throws InvalidInterfaceException
4059
-     * @throws InvalidArgumentException
4060
-     */
4061
-    public function activate_mt_toggle()
4062
-    {
4063
-        $success = true;
4064
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
-
4066
-        // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4068
-            EE_Error::add_error(
4069
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
-                __FILE__,
4071
-                __FUNCTION__,
4072
-                __LINE__
4073
-            );
4074
-            $success = false;
4075
-        }
4076
-
4077
-        if (! $this->_active_messenger_name) {
4078
-            EE_Error::add_error(
4079
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
-                __FILE__,
4081
-                __FUNCTION__,
4082
-                __LINE__
4083
-            );
4084
-            $success = false;
4085
-        }
4086
-
4087
-        $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4089
-            EE_Error::add_error(
4090
-                esc_html__(
4091
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
-                    'event_espresso'
4093
-                ),
4094
-                __FILE__,
4095
-                __FUNCTION__,
4096
-                __LINE__
4097
-            );
4098
-            $success = false;
4099
-        }
4100
-
4101
-
4102
-        // do check to verify we have a valid status.
4103
-        if ($status !== 'activate' && $status !== 'deactivate') {
4104
-            EE_Error::add_error(
4105
-                sprintf(
4106
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
-                    $status
4108
-                ),
4109
-                __FILE__,
4110
-                __FUNCTION__,
4111
-                __LINE__
4112
-            );
4113
-            $success = false;
4114
-        }
4115
-
4116
-
4117
-        // do a nonce check here since we're not arriving via a normal route
4118
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4119
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
-
4121
-        if ($success) {
4122
-            // made it here? um, what are you waiting for then?
4123
-            $success = $status === 'deactivate'
4124
-                ? $this->_deactivate_message_type_for_messenger(
4125
-                    $this->_active_messenger_name,
4126
-                    $this->_active_message_type_name
4127
-                )
4128
-                : $this->_activate_message_type_for_messenger(
4129
-                    $this->_active_messenger_name,
4130
-                    $this->_active_message_type_name
4131
-                );
4132
-        }
4133
-
4134
-        $this->_template_args['success'] = $success;
4135
-        $this->_return_json();
4136
-    }
4137
-
4138
-
4139
-    /**
4140
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4141
-     *
4142
-     * @param string $messenger_name The name of the messenger being activated
4143
-     * @return bool
4144
-     * @throws DomainException
4145
-     * @throws EE_Error
4146
-     * @throws InvalidArgumentException
4147
-     * @throws ReflectionException
4148
-     * @throws InvalidDataTypeException
4149
-     * @throws InvalidInterfaceException
4150
-     */
4151
-    protected function _activate_messenger($messenger_name)
4152
-    {
4153
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
-            ? $active_messenger->get_default_message_types()
4156
-            : [];
4157
-
4158
-        // ensure is active
4159
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
-
4161
-        // set response_data for reload
4162
-        foreach ($message_types_to_activate as $message_type_name) {
4163
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
-            if (
4165
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4166
-                    $messenger_name,
4167
-                    $message_type_name
4168
-                )
4169
-                && $message_type instanceof EE_message_type
4170
-            ) {
4171
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4172
-                if ($message_type->get_admin_settings_fields()) {
4173
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
-                }
4175
-            }
4176
-        }
4177
-
4178
-        // add success message for activating messenger
4179
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
-    }
4181
-
4182
-
4183
-    /**
4184
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
-     *
4186
-     * @param string $messenger_name The name of the messenger being activated
4187
-     * @return bool
4188
-     * @throws DomainException
4189
-     * @throws EE_Error
4190
-     * @throws InvalidArgumentException
4191
-     * @throws ReflectionException
4192
-     * @throws InvalidDataTypeException
4193
-     * @throws InvalidInterfaceException
4194
-     */
4195
-    protected function _deactivate_messenger($messenger_name)
4196
-    {
4197
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
-
4200
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
-    }
4202
-
4203
-
4204
-    /**
4205
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
-     *
4207
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
-     * @param string $message_type_name The name of the message type being activated for the messenger
4209
-     * @return bool
4210
-     * @throws DomainException
4211
-     * @throws EE_Error
4212
-     * @throws InvalidArgumentException
4213
-     * @throws ReflectionException
4214
-     * @throws InvalidDataTypeException
4215
-     * @throws InvalidInterfaceException
4216
-     */
4217
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
-    {
4219
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
-
4222
-        // ensure is active
4223
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
-
4225
-        // set response for load
4226
-        if (
4227
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4228
-                $messenger_name,
4229
-                $message_type_name
4230
-            )
4231
-        ) {
4232
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4233
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4234
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
-            }
4236
-        }
4237
-
4238
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
-            $active_messenger,
4240
-            $message_type_to_activate
4241
-        );
4242
-    }
4243
-
4244
-
4245
-    /**
4246
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
-     *
4248
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
-     * @return bool
4251
-     * @throws DomainException
4252
-     * @throws EE_Error
4253
-     * @throws InvalidArgumentException
4254
-     * @throws ReflectionException
4255
-     * @throws InvalidDataTypeException
4256
-     * @throws InvalidInterfaceException
4257
-     */
4258
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
-    {
4260
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
-
4265
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
-            $active_messenger,
4267
-            $message_type_to_deactivate
4268
-        );
4269
-    }
4270
-
4271
-
4272
-    /**
4273
-     * This just initializes the defaults for activating messenger and message type responses.
4274
-     */
4275
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
-    {
4277
-        $this->_template_args['data']['active_mts'] = [];
4278
-        $this->_template_args['data']['mt_reload']  = [];
4279
-    }
4280
-
4281
-
4282
-    /**
4283
-     * Setup appropriate response for activating a messenger and/or message types
4284
-     *
4285
-     * @param EE_messenger         $messenger
4286
-     * @param EE_message_type|null $message_type
4287
-     * @return bool
4288
-     * @throws DomainException
4289
-     * @throws EE_Error
4290
-     * @throws InvalidArgumentException
4291
-     * @throws ReflectionException
4292
-     * @throws InvalidDataTypeException
4293
-     * @throws InvalidInterfaceException
4294
-     */
4295
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
-        $messenger,
4297
-        EE_Message_Type $message_type = null
4298
-    ) {
4299
-        // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4301
-            EE_Error::add_error(
4302
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
-                __FILE__,
4304
-                __FUNCTION__,
4305
-                __LINE__
4306
-            );
4307
-            return false;
4308
-        }
4309
-        // activated
4310
-        if ($this->_template_args['data']['active_mts']) {
4311
-            EE_Error::overwrite_success();
4312
-            // activated a message type with the messenger
4313
-            if ($message_type instanceof EE_message_type) {
4314
-                EE_Error::add_success(
4315
-                    sprintf(
4316
-                        esc_html__(
4317
-                            '%s message type has been successfully activated with the %s messenger',
4318
-                            'event_espresso'
4319
-                        ),
4320
-                        ucwords($message_type->label['singular']),
4321
-                        ucwords($messenger->label['singular'])
4322
-                    )
4323
-                );
4324
-
4325
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4326
-                if ($message_type->name === 'invoice') {
4327
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
-                    if ($pm instanceof EE_Payment_Method) {
4330
-                        EE_Error::add_attention(
4331
-                            esc_html__(
4332
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
-                                'event_espresso'
4334
-                            )
4335
-                        );
4336
-                    }
4337
-                }
4338
-                // just toggles the entire messenger
4339
-            } else {
4340
-                EE_Error::add_success(
4341
-                    sprintf(
4342
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
-                        ucwords($messenger->label['singular'])
4344
-                    )
4345
-                );
4346
-            }
4347
-
4348
-            return true;
4349
-
4350
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
-            // in which case we just give a success message for the messenger being successfully activated.
4353
-        } else {
4354
-            if (! $messenger->get_default_message_types()) {
4355
-                // messenger doesn't have any default message types so still a success.
4356
-                EE_Error::add_success(
4357
-                    sprintf(
4358
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
-                        ucwords($messenger->label['singular'])
4360
-                    )
4361
-                );
4362
-
4363
-                return true;
4364
-            } else {
4365
-                EE_Error::add_error(
4366
-                    $message_type instanceof EE_message_type
4367
-                    ? sprintf(
4368
-                        esc_html__(
4369
-                            '%s message type was not successfully activated with the %s messenger',
4370
-                            'event_espresso'
4371
-                        ),
4372
-                        ucwords($message_type->label['singular']),
4373
-                        ucwords($messenger->label['singular'])
4374
-                    )
4375
-                    : sprintf(
4376
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
-                        ucwords($messenger->label['singular'])
4378
-                    ),
4379
-                    __FILE__,
4380
-                    __FUNCTION__,
4381
-                    __LINE__
4382
-                );
4383
-
4384
-                return false;
4385
-            }
4386
-        }
4387
-    }
4388
-
4389
-
4390
-    /**
4391
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
-     *
4393
-     * @param EE_messenger         $messenger
4394
-     * @param EE_message_type|null $message_type
4395
-     * @return bool
4396
-     * @throws DomainException
4397
-     * @throws EE_Error
4398
-     * @throws InvalidArgumentException
4399
-     * @throws ReflectionException
4400
-     * @throws InvalidDataTypeException
4401
-     * @throws InvalidInterfaceException
4402
-     */
4403
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
-        $messenger,
4405
-        EE_message_type $message_type = null
4406
-    ) {
4407
-        EE_Error::overwrite_success();
4408
-
4409
-        // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4411
-            EE_Error::add_error(
4412
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
-                __FILE__,
4414
-                __FUNCTION__,
4415
-                __LINE__
4416
-            );
4417
-
4418
-            return false;
4419
-        }
4420
-
4421
-        if ($message_type instanceof EE_message_type) {
4422
-            $message_type_name = $message_type->name;
4423
-            EE_Error::add_success(
4424
-                sprintf(
4425
-                    esc_html__(
4426
-                        '%s message type has been successfully deactivated for the %s messenger.',
4427
-                        'event_espresso'
4428
-                    ),
4429
-                    ucwords($message_type->label['singular']),
4430
-                    ucwords($messenger->label['singular'])
4431
-                )
4432
-            );
4433
-        } else {
4434
-            $message_type_name = '';
4435
-            EE_Error::add_success(
4436
-                sprintf(
4437
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
-                    ucwords($messenger->label['singular'])
4439
-                )
4440
-            );
4441
-        }
4442
-
4443
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
-        if (
4445
-            $messenger->name === 'html'
4446
-            && (
4447
-                is_null($message_type)
4448
-                || $message_type_name === 'invoice'
4449
-            )
4450
-        ) {
4451
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
-            if ($count_updated > 0) {
4454
-                $msg = $message_type_name === 'invoice'
4455
-                    ? esc_html__(
4456
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
-                        'event_espresso'
4458
-                    )
4459
-                    : esc_html__(
4460
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
-                        'event_espresso'
4462
-                    );
4463
-                EE_Error::add_attention($msg);
4464
-            }
4465
-        }
4466
-
4467
-        return true;
4468
-    }
4469
-
4470
-
4471
-    /**
4472
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
-     *
4474
-     * @throws DomainException
4475
-     * @throws EE_Error
4476
-     * @throws EE_Error
4477
-     */
4478
-    public function update_mt_form()
4479
-    {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
-            EE_Error::add_error(
4482
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
-                __FILE__,
4484
-                __FUNCTION__,
4485
-                __LINE__
4486
-            );
4487
-            $this->_return_json();
4488
-        }
4489
-
4490
-        $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4492
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
-
4495
-        $this->_template_args['success'] = true;
4496
-        $this->_template_args['content'] = $content;
4497
-        $this->_return_json();
4498
-    }
4499
-
4500
-
4501
-    /**
4502
-     * this handles saving the settings for a messenger or message type
4503
-     *
4504
-     * @throws EE_Error
4505
-     * @throws EE_Error
4506
-     */
4507
-    public function save_settings()
4508
-    {
4509
-        $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4511
-            EE_Error::add_error(
4512
-                esc_html__(
4513
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
-                    'event_espresso'
4515
-                ),
4516
-                __FILE__,
4517
-                __FUNCTION__,
4518
-                __LINE__
4519
-            );
4520
-            $this->_template_args['error'] = true;
4521
-            $this->_return_json();
4522
-        }
4523
-
4524
-
4525
-        if ($type === 'messenger') {
4526
-            // this should be an array.
4527
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
-            $messenger = $settings['messenger'];
4529
-            // remove messenger and message_types from settings array
4530
-            unset($settings['messenger'], $settings['message_types']);
4531
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
-        } elseif ($type === 'message_type') {
4533
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
-            $messenger    = $settings['messenger'];
4535
-            $message_type = $settings['message_type'];
4536
-            // remove messenger and message_types from settings array
4537
-            unset($settings['messenger'], $settings['message_types']);
4538
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
-        }
4540
-
4541
-        // okay we should have the data all setup.  Now we just update!
4542
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4543
-
4544
-        if ($success) {
4545
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
-        } else {
4547
-            EE_Error::add_error(
4548
-                esc_html__('Settings did not get updated', 'event_espresso'),
4549
-                __FILE__,
4550
-                __FUNCTION__,
4551
-                __LINE__
4552
-            );
4553
-        }
4554
-
4555
-        $this->_template_args['success'] = $success;
4556
-        $this->_return_json();
4557
-    }
4558
-
4559
-
4560
-
4561
-
4562
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4563
-
4564
-
4565
-    /**
4566
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
-     * However, this does not send immediately, it just queues for sending.
4568
-     *
4569
-     * @throws EE_Error
4570
-     * @throws InvalidDataTypeException
4571
-     * @throws InvalidInterfaceException
4572
-     * @throws InvalidArgumentException
4573
-     * @throws ReflectionException
4574
-     * @since 4.9.0
4575
-     */
4576
-    protected function _generate_now()
4577
-    {
4578
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
-        $this->_redirect_after_action(false, '', '', [], true);
4580
-    }
4581
-
4582
-
4583
-    /**
4584
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4586
-     *
4587
-     * @throws EE_Error
4588
-     * @throws InvalidDataTypeException
4589
-     * @throws InvalidInterfaceException
4590
-     * @throws InvalidArgumentException
4591
-     * @throws ReflectionException
4592
-     * @since 4.9.0
4593
-     */
4594
-    protected function _generate_and_send_now()
4595
-    {
4596
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
-        $this->_redirect_after_action(false, '', '', [], true);
4598
-    }
4599
-
4600
-
4601
-    /**
4602
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
-     *
4604
-     * @throws EE_Error
4605
-     * @throws InvalidDataTypeException
4606
-     * @throws InvalidInterfaceException
4607
-     * @throws InvalidArgumentException
4608
-     * @throws ReflectionException
4609
-     * @since 4.9.0
4610
-     */
4611
-    protected function _queue_for_resending()
4612
-    {
4613
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
-        $this->_redirect_after_action(false, '', '', [], true);
4615
-    }
4616
-
4617
-
4618
-    /**
4619
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
-     *
4621
-     * @throws EE_Error
4622
-     * @throws InvalidDataTypeException
4623
-     * @throws InvalidInterfaceException
4624
-     * @throws InvalidArgumentException
4625
-     * @throws ReflectionException
4626
-     * @since 4.9.0
4627
-     */
4628
-    protected function _send_now()
4629
-    {
4630
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
-        $this->_redirect_after_action(false, '', '', [], true);
4632
-    }
4633
-
4634
-
4635
-    /**
4636
-     * Deletes EE_messages for IDs in the request.
4637
-     *
4638
-     * @throws EE_Error
4639
-     * @throws InvalidDataTypeException
4640
-     * @throws InvalidInterfaceException
4641
-     * @throws InvalidArgumentException
4642
-     * @since 4.9.0
4643
-     */
4644
-    protected function _delete_ee_messages()
4645
-    {
4646
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4647
-        $deleted_count = 0;
4648
-        foreach ($MSG_IDs as $MSG_ID) {
4649
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
-                $deleted_count++;
4651
-            }
4652
-        }
4653
-        if ($deleted_count) {
4654
-            EE_Error::add_success(
4655
-                esc_html(
4656
-                    _n(
4657
-                        'Message successfully deleted',
4658
-                        'Messages successfully deleted',
4659
-                        $deleted_count,
4660
-                        'event_espresso'
4661
-                    )
4662
-                )
4663
-            );
4664
-        } else {
4665
-            EE_Error::add_error(
4666
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
-                __FILE__,
4668
-                __FUNCTION__,
4669
-                __LINE__
4670
-            );
4671
-        }
4672
-        $this->_redirect_after_action(false, '', '', [], true);
4673
-    }
4674
-
4675
-
4676
-    /**
4677
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
-     *
4679
-     * @return array
4680
-     * @since 4.9.0
4681
-     */
4682
-    protected function _get_msg_ids_from_request()
4683
-    {
4684
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
-        if (empty($MSG_IDs)) {
4686
-            return [];
4687
-        }
4688
-        // if 'MSG_ID' was just a single ID (not an array)
4689
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
-            ? $MSG_IDs
4693
-            : array_keys($MSG_IDs);
4694
-    }
2705
+		$this->_context_switcher = ob_get_clean();
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * @param bool $new
2711
+	 * @throws EE_Error
2712
+	 * @throws ReflectionException
2713
+	 */
2714
+	protected function _insert_or_update_message_template($new = false)
2715
+	{
2716
+		$form_data    = $this->getMessageTemplateFormData();
2717
+		$GRP_ID       = $form_data['GRP_ID'];
2718
+		$messenger    = $form_data['MTP_messenger'];
2719
+		$message_type = $form_data['MTP_message_type'];
2720
+		$context      = $form_data['MTP_context'];
2721
+
2722
+		// if this is "new" then we need to generate the default contexts
2723
+		// for the selected messenger/message_type for user to edit.
2724
+		list($success, $query_args) = $new
2725
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2726
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2727
+
2728
+		$success     = $success ? 1 : 0;
2729
+		$action_desc = $new ? 'created' : 'updated';
2730
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2731
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2732
+
2733
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * retrieve and sanitize form data
2739
+	 *
2740
+	 * @return array
2741
+	 * @since 4.10.29.p
2742
+	 */
2743
+	protected function getMessageTemplateFormData()
2744
+	{
2745
+		return [
2746
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2747
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2748
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2749
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2750
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2751
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2752
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2753
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2754
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2755
+		];
2756
+	}
2757
+
2758
+
2759
+	/**
2760
+	 * @param int    $GRP_ID
2761
+	 * @param string $messenger
2762
+	 * @param string $message_type
2763
+	 * @return array no return on AJAX requests
2764
+	 * @throws EE_Error
2765
+	 * @throws ReflectionException
2766
+	 * @since 4.10.29.p
2767
+	 */
2768
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2769
+	{
2770
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2771
+		$success       = ! empty($new_templates);
2772
+
2773
+		// we return things differently if doing ajax
2774
+		if ($this->request->isAjax()) {
2775
+			$this->_template_args['success'] = $success;
2776
+			$this->_template_args['error']   = ! $success;
2777
+			$this->_template_args['content'] = '';
2778
+			$this->_template_args['data']    = [
2779
+				'grpID'        => $new_templates['GRP_ID'],
2780
+				'templateName' => $new_templates['template_name'],
2781
+			];
2782
+			if ($success) {
2783
+				EE_Error::overwrite_success();
2784
+				EE_Error::add_success(
2785
+					esc_html__(
2786
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2787
+						'event_espresso'
2788
+					)
2789
+				);
2790
+			}
2791
+			$this->_return_json();
2792
+		}
2793
+		return [
2794
+			$success,
2795
+			// 'query_args'
2796
+			[
2797
+				'id'      => $new_templates['GRP_ID'],
2798
+				'context' => $new_templates['MTP_context'],
2799
+				'action'  => 'edit_message_template',
2800
+			],
2801
+		];
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * @param int    $GRP_ID
2807
+	 * @param string $messenger
2808
+	 * @param string $message_type
2809
+	 * @param string $context
2810
+	 * @param array  $form_data
2811
+	 * @return array
2812
+	 * @throws EE_Error
2813
+	 * @since 4.10.29.p
2814
+	 */
2815
+	private function updateExistingTemplates(
2816
+		$GRP_ID,
2817
+		$messenger,
2818
+		$message_type,
2819
+		$context,
2820
+		array $form_data
2821
+	) {
2822
+		$success         = false;
2823
+		$template_fields = $this->getTemplateFields();
2824
+		if ($template_fields) {
2825
+			// if field data is valid, then success will be true
2826
+			$success = $this->validateTemplateFields(
2827
+				$messenger,
2828
+				$message_type,
2829
+				$context,
2830
+				$template_fields
2831
+			);
2832
+			if ($success) {
2833
+				$field_data = [];
2834
+				foreach ($template_fields as $template_field => $content) {
2835
+					// combine top-level form data with content for this field
2836
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2837
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2838
+				}
2839
+				// we can use the last set_column_values for the MTPG update
2840
+				// (because its the same for all of these specific MTPs)
2841
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2842
+			}
2843
+		}
2844
+
2845
+		return [
2846
+			$success,
2847
+			// 'query_args'
2848
+			[
2849
+				'id'      => $GRP_ID,
2850
+				'context' => $context,
2851
+				'action'  => 'edit_message_template',
2852
+			],
2853
+		];
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * @return array
2859
+	 * @since 4.10.29.p
2860
+	 */
2861
+	private function getTemplateFields()
2862
+	{
2863
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2864
+		if (empty($template_fields)) {
2865
+			EE_Error::add_error(
2866
+				esc_html__(
2867
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2868
+					'event_espresso'
2869
+				),
2870
+				__FILE__,
2871
+				__FUNCTION__,
2872
+				__LINE__
2873
+			);
2874
+			return null;
2875
+		}
2876
+		// messages content is expected to be escaped
2877
+		return EEH_Array::addSlashesRecursively($template_fields);
2878
+	}
2879
+
2880
+
2881
+	/**
2882
+	 * @param string $messenger
2883
+	 * @param string $message_type
2884
+	 * @param string $context
2885
+	 * @param array  $template_fields
2886
+	 * @return bool
2887
+	 * @throws EE_Error
2888
+	 * @since   4.10.29.p
2889
+	 */
2890
+	private function validateTemplateFields(
2891
+		$messenger,
2892
+		$message_type,
2893
+		$context,
2894
+		array $template_fields
2895
+	) {
2896
+		// first validate all fields!
2897
+		// this filter allows client code to add its own validation to the template fields as well.
2898
+		// returning an empty array means everything passed validation.
2899
+		// errors in validation should be represented in an array with the following shape:
2900
+		// array(
2901
+		//   'fieldname' => array(
2902
+		//          'msg' => 'error message'
2903
+		//          'value' => 'value for field producing error'
2904
+		// )
2905
+		$custom_validation = (array) apply_filters(
2906
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2907
+			[],
2908
+			$template_fields,
2909
+			$context,
2910
+			$messenger,
2911
+			$message_type
2912
+		);
2913
+
2914
+		$system_validation = $this->getMtgModel()->validate(
2915
+			$template_fields,
2916
+			$context,
2917
+			$messenger,
2918
+			$message_type
2919
+		);
2920
+
2921
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2922
+		$validates         = array_merge($custom_validation, $system_validation);
2923
+
2924
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2925
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2926
+		//  WE need to make sure there is no actual error messages in validates.
2927
+		if (empty($validates)) {
2928
+			return true;
2929
+		}
2930
+
2931
+		// add the transient so when the form loads we know which fields to highlight
2932
+		$this->_add_transient('edit_message_template', $validates);
2933
+		// setup notices
2934
+		foreach ($validates as $error) {
2935
+			if (isset($error['msg'])) {
2936
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2937
+			}
2938
+		}
2939
+		return false;
2940
+	}
2941
+
2942
+
2943
+	/**
2944
+	 * @param array $field_data
2945
+	 * @param array $form_data
2946
+	 * @return array
2947
+	 * @since   4.10.29.p
2948
+	 */
2949
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2950
+	{
2951
+		return $form_data + [
2952
+				'MTP_ID'             => $field_data['MTP_ID'],
2953
+				'MTP_template_field' => $field_data['name'],
2954
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2955
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2956
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2957
+					: $field_data['content'],
2958
+			];
2959
+	}
2960
+
2961
+
2962
+	/**
2963
+	 * @param string $template_field
2964
+	 * @param array  $form_data
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @since 4.10.29.p
2968
+	 */
2969
+	private function updateMessageTemplates($template_field, array $form_data)
2970
+	{
2971
+		$MTP_ID                  = $form_data['MTP_ID'];
2972
+		$message_template_fields = [
2973
+			'GRP_ID'             => $form_data['GRP_ID'],
2974
+			'MTP_template_field' => $form_data['MTP_template_field'],
2975
+			'MTP_context'        => $form_data['MTP_context'],
2976
+			'MTP_content'        => $form_data['MTP_content'],
2977
+		];
2978
+
2979
+		$hasMtpID = ! empty($MTP_ID);
2980
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2981
+		// this has already been through the template field validator and sanitized, so it will be
2982
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2983
+		// message template field in a messenger/message type and existing users don't have the
2984
+		// default setup for it.
2985
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2986
+		$updated = $hasMtpID
2987
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2988
+			: $this->getMtpModel()->insert($message_template_fields);
2989
+
2990
+		$insert_failed = ! $hasMtpID && ! $updated;
2991
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2992
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2993
+		$update_failed = $hasMtpID && $updated === false;
2994
+
2995
+		if ($insert_failed || $update_failed) {
2996
+			EE_Error::add_error(
2997
+				sprintf(
2998
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2999
+					$template_field
3000
+				),
3001
+				__FILE__,
3002
+				__FUNCTION__,
3003
+				__LINE__
3004
+			);
3005
+			return false;
3006
+		}
3007
+		return true;
3008
+	}
3009
+
3010
+
3011
+	/**
3012
+	 * @param array $form_data
3013
+	 * @return bool
3014
+	 * @throws EE_Error
3015
+	 * @since 4.10.29.p
3016
+	 */
3017
+	private function updateMessageTemplateGroup(array $form_data)
3018
+	{
3019
+		$GRP_ID  = $form_data['GRP_ID'];
3020
+		$updated = $this->getMtgModel()->update(
3021
+		// fields and values
3022
+			[
3023
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3024
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3025
+				'MTP_message_type' => $form_data['MTP_message_type'],
3026
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3027
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3028
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3029
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3030
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3031
+				'MTP_description'  => $this->request->getRequestParam(
3032
+					'ee_msg_non_global_fields[MTP_description]',
3033
+					''
3034
+				),
3035
+			],
3036
+			// where
3037
+			[['GRP_ID' => $GRP_ID]]
3038
+		);
3039
+
3040
+		if ($updated === false) {
3041
+			EE_Error::add_error(
3042
+				sprintf(
3043
+					esc_html__(
3044
+						'The Message Template Group (%d) was NOT updated for some reason',
3045
+						'event_espresso'
3046
+					),
3047
+					$form_data['GRP_ID']
3048
+				),
3049
+				__FILE__,
3050
+				__FUNCTION__,
3051
+				__LINE__
3052
+			);
3053
+			return false;
3054
+		}
3055
+		// k now we need to ensure the template_pack and template_variation fields are set.
3056
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3057
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3058
+
3059
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3060
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3061
+			$message_template_group->set_template_pack_name($template_pack);
3062
+			$message_template_group->set_template_pack_variation($template_variation);
3063
+		}
3064
+		return true;
3065
+	}
3066
+
3067
+
3068
+	/**
3069
+	 * recursively runs wp_kses() on message template content in a model safe manner
3070
+	 *
3071
+	 * @param array|string $content
3072
+	 * @return array|string
3073
+	 * @since   4.10.29.p
3074
+	 */
3075
+	private function sanitizeMessageTemplateContent($content)
3076
+	{
3077
+		if (is_array($content)) {
3078
+			foreach ($content as $key => $value) {
3079
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+			}
3081
+			return $content;
3082
+		}
3083
+		// remove slashes so wp_kses() works properly
3084
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3085
+		// so attributes using single quotes always appear invalid.
3086
+		$content = stripslashes($content);
3087
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3088
+		// But currently the models expect slashed data, so after wp_kses()
3089
+		// runs we need to re-slash the data. Sheesh.
3090
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3091
+		return addslashes($content);
3092
+	}
3093
+
3094
+
3095
+	/**
3096
+	 * @param string $messenger
3097
+	 * @param string $message_type
3098
+	 * @param string $context
3099
+	 * @return string
3100
+	 * @since 4.10.29.p
3101
+	 */
3102
+	private function generateUpdateDescription($messenger, $message_type, $context)
3103
+	{
3104
+		// need the message type and messenger objects to be able to use the labels for the notices
3105
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3106
+		$messenger_label  = $messenger_object instanceof EE_messenger
3107
+			? ucwords($messenger_object->label['singular'])
3108
+			: '';
3109
+
3110
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3111
+		$message_type_label  = $message_type_object instanceof EE_message_type
3112
+			? ucwords($message_type_object->label['singular'])
3113
+			: '';
3114
+
3115
+		$context   = ucwords(str_replace('_', ' ', $context));
3116
+		$item_desc = $messenger_label && $message_type_label
3117
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+			: '';
3119
+		$item_desc .= 'Message Template';
3120
+		return $item_desc;
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 * @param string $messenger
3126
+	 * @param string $message_type
3127
+	 * @param string $context
3128
+	 * @return bool
3129
+	 * @throws EE_Error
3130
+	 * @throws ReflectionException
3131
+	 * @since 4.10.29.p
3132
+	 */
3133
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3134
+	{
3135
+		// was a test send triggered?
3136
+		if ($this->request->requestParamIsSet('test_button')) {
3137
+			EE_Error::overwrite_success();
3138
+			$this->_do_test_send($context, $messenger, $message_type);
3139
+			return true;
3140
+		}
3141
+		return false;
3142
+	}
3143
+
3144
+
3145
+	/**
3146
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3147
+	 *
3148
+	 * @param string $context      what context being tested
3149
+	 * @param string $messenger    messenger being tested
3150
+	 * @param string $message_type message type being tested
3151
+	 * @throws EE_Error
3152
+	 * @throws InvalidArgumentException
3153
+	 * @throws InvalidDataTypeException
3154
+	 * @throws InvalidInterfaceException
3155
+	 * @throws ReflectionException
3156
+	 */
3157
+	protected function _do_test_send($context, $messenger, $message_type)
3158
+	{
3159
+		// set things up for preview
3160
+		$this->request->setRequestParam('messenger', $messenger);
3161
+		$this->request->setRequestParam('message_type', $message_type);
3162
+		$this->request->setRequestParam('context', $context);
3163
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3164
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3165
+
3166
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3167
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3168
+
3169
+		// let's save any existing fields that might be required by the messenger
3170
+		if (
3171
+			! empty($test_settings_fld)
3172
+			&& $active_messenger instanceof EE_messenger
3173
+			&& apply_filters(
3174
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3175
+				true,
3176
+				$test_settings_fld,
3177
+				$active_messenger
3178
+			)
3179
+		) {
3180
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3181
+		}
3182
+
3183
+		/**
3184
+		 * Use filter to add additional controls on whether message can send or not
3185
+		 */
3186
+		if (
3187
+			apply_filters(
3188
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3189
+				true,
3190
+				$context,
3191
+				$this->request->requestParams(),
3192
+				$messenger,
3193
+				$message_type
3194
+			)
3195
+		) {
3196
+			if (EEM_Event::instance()->count() > 0) {
3197
+				$success = $this->_preview_message(true);
3198
+				if ($success) {
3199
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3200
+				} else {
3201
+					EE_Error::add_error(
3202
+						esc_html__('The test message was not sent', 'event_espresso'),
3203
+						__FILE__,
3204
+						__FUNCTION__,
3205
+						__LINE__
3206
+					);
3207
+				}
3208
+			} else {
3209
+				$this->noEventsErrorMessage(true);
3210
+			}
3211
+		}
3212
+	}
3213
+
3214
+
3215
+	/**
3216
+	 * _generate_new_templates
3217
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3218
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3219
+	 * for the event.
3220
+	 *
3221
+	 *
3222
+	 * @param string $messenger      the messenger we are generating templates for
3223
+	 * @param array  $message_types  array of message types that the templates are generated for.
3224
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3225
+	 *                               indicate the message_template_group being used as the base.
3226
+	 *
3227
+	 * @param bool   $global
3228
+	 *
3229
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3230
+	 *                               encountering problems.
3231
+	 * @throws EE_Error
3232
+	 * @throws ReflectionException
3233
+	 */
3234
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3235
+	{
3236
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3237
+		// just don't generate any templates.
3238
+		if (empty($message_types)) {
3239
+			return [];
3240
+		}
3241
+
3242
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3243
+		return $templates[0];
3244
+	}
3245
+
3246
+
3247
+	/**
3248
+	 * [_trash_or_restore_message_template]
3249
+	 *
3250
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3251
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3252
+	 *                        an individual context (FALSE).
3253
+	 * @return void
3254
+	 * @throws EE_Error
3255
+	 * @throws InvalidArgumentException
3256
+	 * @throws InvalidDataTypeException
3257
+	 * @throws InvalidInterfaceException
3258
+	 */
3259
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3260
+	{
3261
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3262
+
3263
+		$success = 1;
3264
+
3265
+		// incoming GRP_IDs
3266
+		if ($all) {
3267
+			// Checkboxes
3268
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
+			if (! empty($checkboxes)) {
3270
+				// if array has more than one element then success message should be plural.
3271
+				// todo: what about nonce?
3272
+				$success = count($checkboxes) > 1 ? 2 : 1;
3273
+
3274
+				// cycle through checkboxes
3275
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3276
+					$trashed_or_restored = $trash
3277
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
+					if (! $trashed_or_restored) {
3280
+						$success = 0;
3281
+					}
3282
+				}
3283
+			} else {
3284
+				// grab single GRP_ID and handle
3285
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
+				if (! empty($GRP_ID)) {
3287
+					$trashed_or_restored = $trash
3288
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
+					if (! $trashed_or_restored) {
3291
+						$success = 0;
3292
+					}
3293
+				} else {
3294
+					$success = 0;
3295
+				}
3296
+			}
3297
+		}
3298
+
3299
+		$action_desc = $trash
3300
+			? esc_html__('moved to the trash', 'event_espresso')
3301
+			: esc_html__('restored', 'event_espresso');
3302
+
3303
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3304
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3305
+
3306
+		$item_desc = $all ? _n(
3307
+			'Message Template Group',
3308
+			'Message Template Groups',
3309
+			$success,
3310
+			'event_espresso'
3311
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3312
+
3313
+		$item_desc = $template_switch
3314
+			? _n('template', 'templates', $success, 'event_espresso')
3315
+			: $item_desc;
3316
+
3317
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3318
+	}
3319
+
3320
+
3321
+	/**
3322
+	 * [_delete_message_template]
3323
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3324
+	 *
3325
+	 * @return void
3326
+	 * @throws EE_Error
3327
+	 * @throws InvalidArgumentException
3328
+	 * @throws InvalidDataTypeException
3329
+	 * @throws InvalidInterfaceException
3330
+	 * @throws ReflectionException
3331
+	 */
3332
+	protected function _delete_message_template()
3333
+	{
3334
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3335
+
3336
+		// checkboxes
3337
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
+		if (! empty($checkboxes)) {
3339
+			// if array has more than one element then success message should be plural
3340
+			$success = count($checkboxes) > 1 ? 2 : 1;
3341
+
3342
+			// cycle through bulk action checkboxes
3343
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3344
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3345
+			}
3346
+		} else {
3347
+			// grab single grp_id and delete
3348
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3349
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3350
+		}
3351
+
3352
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3353
+	}
3354
+
3355
+
3356
+	/**
3357
+	 * helper for permanently deleting a mtP group and all related message_templates
3358
+	 *
3359
+	 * @param int  $GRP_ID        The group being deleted
3360
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3361
+	 * @return bool boolean to indicate the success of the deletes or not.
3362
+	 * @throws EE_Error
3363
+	 * @throws InvalidArgumentException
3364
+	 * @throws InvalidDataTypeException
3365
+	 * @throws InvalidInterfaceException
3366
+	 * @throws ReflectionException
3367
+	 * @throws ReflectionException
3368
+	 */
3369
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3370
+	{
3371
+		$success = true;
3372
+		// first let's GET this group
3373
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3374
+		// then delete permanently all the related Message Templates
3375
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3376
+
3377
+		if ($deleted === 0) {
3378
+			$success = false;
3379
+		}
3380
+
3381
+		// now delete permanently this particular group
3382
+
3383
+		if ($include_group && ! $MTG->delete_permanently()) {
3384
+			$success = false;
3385
+		}
3386
+
3387
+		return $success;
3388
+	}
3389
+
3390
+
3391
+	/**
3392
+	 *    _learn_more_about_message_templates_link
3393
+	 *
3394
+	 * @access protected
3395
+	 * @return string
3396
+	 */
3397
+	protected function _learn_more_about_message_templates_link()
3398
+	{
3399
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3400
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3401
+			   . '</a>';
3402
+	}
3403
+
3404
+
3405
+	/**
3406
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3407
+	 * ajax and other routes.
3408
+	 *
3409
+	 * @return void
3410
+	 * @throws DomainException
3411
+	 * @throws EE_Error
3412
+	 */
3413
+	protected function _settings()
3414
+	{
3415
+		$this->_set_m_mt_settings();
3416
+
3417
+		// let's setup the messenger tabs
3418
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3419
+			$this->_m_mt_settings['messenger_tabs'],
3420
+			'messenger_links',
3421
+			'|',
3422
+			$this->request->getRequestParam('selected_messenger', 'email')
3423
+		);
3424
+
3425
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3426
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3427
+
3428
+		$this->display_admin_page_with_sidebar();
3429
+	}
3430
+
3431
+
3432
+	/**
3433
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3434
+	 *
3435
+	 * @access protected
3436
+	 * @return void
3437
+	 * @throws DomainException
3438
+	 */
3439
+	protected function _set_m_mt_settings()
3440
+	{
3441
+		// first if this is already set then lets get out no need to regenerate data.
3442
+		if (! empty($this->_m_mt_settings)) {
3443
+			return;
3444
+		}
3445
+
3446
+		// get all installed messengers and message_types
3447
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3448
+		$message_types = $this->_message_resource_manager->installed_message_types();
3449
+
3450
+
3451
+		// assemble the array for the _tab_text_links helper
3452
+
3453
+		foreach ($messengers as $messenger) {
3454
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+				'label' => ucwords($messenger->label['singular']),
3456
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457
+					? 'messenger-active'
3458
+					: '',
3459
+				'href'  => $messenger->name,
3460
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3461
+				'slug'  => $messenger->name,
3462
+				'obj'   => $messenger,
3463
+			];
3464
+
3465
+
3466
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3467
+
3468
+			foreach ($message_types as $message_type) {
3469
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470
+				// it shouldn't show in either the inactive OR active metabox.
3471
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+					continue;
3473
+				}
3474
+
3475
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3476
+					$messenger->name,
3477
+					$message_type->name
3478
+				)
3479
+					? 'active'
3480
+					: 'inactive';
3481
+
3482
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+					'label'    => ucwords($message_type->label['singular']),
3484
+					'class'    => 'message-type-' . $a_or_i,
3485
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3488
+					'title'    => $a_or_i === 'active'
3489
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3491
+					'content'  => $a_or_i === 'active'
3492
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3493
+						: $this->_message_type_settings_content($message_type, $messenger),
3494
+					'slug'     => $message_type->name,
3495
+					'active'   => $a_or_i === 'active',
3496
+					'obj'      => $message_type,
3497
+				];
3498
+			}
3499
+		}
3500
+	}
3501
+
3502
+
3503
+	/**
3504
+	 * This just prepares the content for the message type settings
3505
+	 *
3506
+	 * @param EE_message_type $message_type The message type object
3507
+	 * @param EE_messenger    $messenger    The messenger object
3508
+	 * @param boolean         $active       Whether the message type is active or not
3509
+	 * @return string html output for the content
3510
+	 * @throws DomainException
3511
+	 */
3512
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3513
+	{
3514
+		// get message type fields
3515
+		$fields                                         = $message_type->get_admin_settings_fields();
3516
+		$settings_template_args['template_form_fields'] = '';
3517
+
3518
+		if (! empty($fields) && $active) {
3519
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520
+			foreach ($fields as $fldname => $fldprops) {
3521
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
+				$template_form_field[ $field_id ] = [
3523
+					'name'       => 'message_type_settings[' . $fldname . ']',
3524
+					'label'      => $fldprops['label'],
3525
+					'input'      => $fldprops['field_type'],
3526
+					'type'       => $fldprops['value_type'],
3527
+					'required'   => $fldprops['required'],
3528
+					'validation' => $fldprops['validation'],
3529
+					'value'      => isset($existing_settings[ $fldname ])
3530
+						? $existing_settings[ $fldname ]
3531
+						: $fldprops['default'],
3532
+					'options'    => isset($fldprops['options'])
3533
+						? $fldprops['options']
3534
+						: [],
3535
+					'default'    => isset($existing_settings[ $fldname ])
3536
+						? $existing_settings[ $fldname ]
3537
+						: $fldprops['default'],
3538
+					'css_class'  => 'no-drag',
3539
+					'format'     => $fldprops['format'],
3540
+				];
3541
+			}
3542
+
3543
+
3544
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3545
+				? $this->_generate_admin_form_fields(
3546
+					$template_form_field,
3547
+					'string',
3548
+					'ee_mt_activate_form'
3549
+				)
3550
+				: '';
3551
+		}
3552
+
3553
+		$settings_template_args['description'] = $message_type->description;
3554
+		// we also need some hidden fields
3555
+		$hidden_fields = [
3556
+			'message_type_settings[messenger]' . $message_type->name    => [
3557
+				'type'  => 'hidden',
3558
+				'value' => $messenger->name,
3559
+			],
3560
+			'message_type_settings[message_type]' . $message_type->name => [
3561
+				'type'  => 'hidden',
3562
+				'value' => $message_type->name,
3563
+			],
3564
+			'type' . $message_type->name                                => [
3565
+				'type'  => 'hidden',
3566
+				'value' => 'message_type',
3567
+			],
3568
+		];
3569
+
3570
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3571
+			$hidden_fields,
3572
+			'array'
3573
+		);
3574
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+			? ' hidden'
3576
+			: '';
3577
+
3578
+
3579
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+		return EEH_Template::display_template($template, $settings_template_args, true);
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3586
+	 *
3587
+	 * @access protected
3588
+	 * @return void
3589
+	 * @throws DomainException
3590
+	 */
3591
+	protected function _messages_settings_metaboxes()
3592
+	{
3593
+		$this->_set_m_mt_settings();
3594
+		$m_boxes         = $mt_boxes = [];
3595
+		$m_template_args = $mt_template_args = [];
3596
+
3597
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3598
+
3599
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3600
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3601
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3602
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3603
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3604
+
3605
+				// messenger meta boxes
3606
+				$active         = $selected_messenger === $messenger;
3607
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3609
+					: '';
3610
+
3611
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+					esc_html__('%s Settings', 'event_espresso'),
3613
+					$tab_array['label']
3614
+				);
3615
+
3616
+				$m_template_args[ $messenger . '_a_box' ] = [
3617
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618
+					'inactive_message_types' => isset(
3619
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+					)
3621
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+						: '',
3623
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624
+					'hidden'                 => $active ? '' : ' hidden',
3625
+					'hide_on_message'        => $hide_on_message,
3626
+					'messenger'              => $messenger,
3627
+					'active'                 => $active,
3628
+				];
3629
+
3630
+				// message type meta boxes
3631
+				// (which is really just the inactive container for each messenger
3632
+				// showing inactive message types for that messenger)
3633
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+				$mt_template_args[ $messenger . '_i_box' ] = [
3635
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636
+					'inactive_message_types' => isset(
3637
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+					)
3639
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+						: '',
3641
+					'hidden'                 => $active ? '' : ' hidden',
3642
+					'hide_on_message'        => $hide_on_message,
3643
+					'hide_off_message'       => $hide_off_message,
3644
+					'messenger'              => $messenger,
3645
+					'active'                 => $active,
3646
+				];
3647
+			}
3648
+		}
3649
+
3650
+
3651
+		// register messenger metaboxes
3652
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+		foreach ($m_boxes as $box => $label) {
3654
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+			$msgr          = str_replace('_a_box', '', $box);
3656
+			add_meta_box(
3657
+				'espresso_' . $msgr . '_settings',
3658
+				$label,
3659
+				function ($post, $metabox) {
3660
+					EEH_Template::display_template(
3661
+						$metabox['args']['template_path'],
3662
+						$metabox['args']['template_args']
3663
+					);
3664
+				},
3665
+				$this->_current_screen->id,
3666
+				'normal',
3667
+				'high',
3668
+				$callback_args
3669
+			);
3670
+		}
3671
+
3672
+		// register message type metaboxes
3673
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+		foreach ($mt_boxes as $box => $label) {
3675
+			$callback_args = [
3676
+				'template_path' => $mt_template_path,
3677
+				'template_args' => $mt_template_args[ $box ],
3678
+			];
3679
+			$mt            = str_replace('_i_box', '', $box);
3680
+			add_meta_box(
3681
+				'espresso_' . $mt . '_inactive_mts',
3682
+				$label,
3683
+				function ($post, $metabox) {
3684
+					EEH_Template::display_template(
3685
+						$metabox['args']['template_path'],
3686
+						$metabox['args']['template_args']
3687
+					);
3688
+				},
3689
+				$this->_current_screen->id,
3690
+				'side',
3691
+				'high',
3692
+				$callback_args
3693
+			);
3694
+		}
3695
+
3696
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3697
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3698
+		if (is_main_site()) {
3699
+			add_meta_box(
3700
+				'espresso_global_message_settings',
3701
+				esc_html__('Global Message Settings', 'event_espresso'),
3702
+				[$this, 'global_messages_settings_metabox_content'],
3703
+				$this->_current_screen->id,
3704
+				'normal',
3705
+				'low',
3706
+				[]
3707
+			);
3708
+		}
3709
+	}
3710
+
3711
+
3712
+	/**
3713
+	 *  This generates the content for the global messages settings metabox.
3714
+	 *
3715
+	 * @return void
3716
+	 * @throws EE_Error
3717
+	 * @throws InvalidArgumentException
3718
+	 * @throws ReflectionException
3719
+	 * @throws InvalidDataTypeException
3720
+	 * @throws InvalidInterfaceException
3721
+	 */
3722
+	public function global_messages_settings_metabox_content()
3723
+	{
3724
+		$form = $this->_generate_global_settings_form();
3725
+		echo wp_kses(
3726
+			$form->form_open(
3727
+				$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3728
+				'POST'
3729
+			),
3730
+			AllowedTags::getWithFormTags()
3731
+		);
3732
+		echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());
3733
+		echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());
3734
+	}
3735
+
3736
+
3737
+	/**
3738
+	 * This generates and returns the form object for the global messages settings.
3739
+	 *
3740
+	 * @return EE_Form_Section_Proper
3741
+	 * @throws EE_Error
3742
+	 * @throws InvalidArgumentException
3743
+	 * @throws ReflectionException
3744
+	 * @throws InvalidDataTypeException
3745
+	 * @throws InvalidInterfaceException
3746
+	 */
3747
+	protected function _generate_global_settings_form()
3748
+	{
3749
+		/** @var EE_Network_Core_Config $network_config */
3750
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3751
+
3752
+		return new EE_Form_Section_Proper(
3753
+			[
3754
+				'name'            => 'global_messages_settings',
3755
+				'html_id'         => 'global_messages_settings',
3756
+				'html_class'      => 'form-table',
3757
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3758
+				'subsections'     => apply_filters(
3759
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3760
+					[
3761
+						'do_messages_on_same_request' => new EE_Select_Input(
3762
+							[
3763
+								true  => esc_html__('On the same request', 'event_espresso'),
3764
+								false => esc_html__('On a separate request', 'event_espresso'),
3765
+							],
3766
+							[
3767
+								'default'         => $network_config->do_messages_on_same_request,
3768
+								'html_label_text' => esc_html__(
3769
+									'Generate and send all messages:',
3770
+									'event_espresso'
3771
+								),
3772
+								'html_help_text'  => esc_html__(
3773
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3774
+									'event_espresso'
3775
+								),
3776
+							]
3777
+						),
3778
+						'delete_threshold'            => new EE_Select_Input(
3779
+							[
3780
+								0  => esc_html__('Forever', 'event_espresso'),
3781
+								3  => esc_html__('3 Months', 'event_espresso'),
3782
+								6  => esc_html__('6 Months', 'event_espresso'),
3783
+								9  => esc_html__('9 Months', 'event_espresso'),
3784
+								12 => esc_html__('12 Months', 'event_espresso'),
3785
+								24 => esc_html__('24 Months', 'event_espresso'),
3786
+								36 => esc_html__('36 Months', 'event_espresso'),
3787
+							],
3788
+							[
3789
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3790
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3791
+								'html_help_text'  => esc_html__(
3792
+									'You can control how long a record of processed messages is kept via this option.',
3793
+									'event_espresso'
3794
+								),
3795
+							]
3796
+						),
3797
+						'update_settings'             => new EE_Submit_Input(
3798
+							[
3799
+								'default'         => esc_html__('Update', 'event_espresso'),
3800
+								'html_label_text' => '',
3801
+							]
3802
+						),
3803
+					]
3804
+				),
3805
+			]
3806
+		);
3807
+	}
3808
+
3809
+
3810
+	/**
3811
+	 * This handles updating the global settings set on the admin page.
3812
+	 *
3813
+	 * @throws EE_Error
3814
+	 * @throws InvalidDataTypeException
3815
+	 * @throws InvalidInterfaceException
3816
+	 * @throws InvalidArgumentException
3817
+	 * @throws ReflectionException
3818
+	 */
3819
+	protected function _update_global_settings()
3820
+	{
3821
+		/** @var EE_Network_Core_Config $network_config */
3822
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3823
+		$messages_config = EE_Registry::instance()->CFG->messages;
3824
+		$form            = $this->_generate_global_settings_form();
3825
+		if ($form->was_submitted()) {
3826
+			$form->receive_form_submission();
3827
+			if ($form->is_valid()) {
3828
+				$valid_data = $form->valid_data();
3829
+				foreach ($valid_data as $property => $value) {
3830
+					$setter = 'set_' . $property;
3831
+					if (method_exists($network_config, $setter)) {
3832
+						$network_config->{$setter}($value);
3833
+					} elseif (
3834
+						property_exists($network_config, $property)
3835
+						&& $network_config->{$property} !== $value
3836
+					) {
3837
+						$network_config->{$property} = $value;
3838
+					} elseif (
3839
+						property_exists($messages_config, $property)
3840
+						&& $messages_config->{$property} !== $value
3841
+					) {
3842
+						$messages_config->{$property} = $value;
3843
+					}
3844
+				}
3845
+				// only update if the form submission was valid!
3846
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3847
+				EE_Registry::instance()->CFG->update_espresso_config();
3848
+				EE_Error::overwrite_success();
3849
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3850
+			}
3851
+		}
3852
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3858
+	 *
3859
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3860
+	 * @return string html formatted tabs
3861
+	 * @throws DomainException
3862
+	 */
3863
+	protected function _get_mt_tabs($tab_array)
3864
+	{
3865
+		$tab_array = (array) $tab_array;
3866
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3867
+		$tabs      = '';
3868
+
3869
+		foreach ($tab_array as $tab) {
3870
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3871
+		}
3872
+
3873
+		return $tabs;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * This prepares the content of the messenger meta box admin settings
3879
+	 *
3880
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3881
+	 * @return string html formatted content
3882
+	 * @throws DomainException
3883
+	 */
3884
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3885
+	{
3886
+
3887
+		$fields                                         = $messenger->get_admin_settings_fields();
3888
+		$settings_template_args['template_form_fields'] = '';
3889
+
3890
+		// is $messenger active?
3891
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892
+
3893
+
3894
+		if (! empty($fields)) {
3895
+			$existing_settings = $messenger->get_existing_admin_settings();
3896
+
3897
+			foreach ($fields as $fldname => $fldprops) {
3898
+				$field_id                         = $messenger->name . '-' . $fldname;
3899
+				$template_form_field[ $field_id ] = [
3900
+					'name'       => 'messenger_settings[' . $field_id . ']',
3901
+					'label'      => $fldprops['label'],
3902
+					'input'      => $fldprops['field_type'],
3903
+					'type'       => $fldprops['value_type'],
3904
+					'required'   => $fldprops['required'],
3905
+					'validation' => $fldprops['validation'],
3906
+					'value'      => isset($existing_settings[ $field_id ])
3907
+						? $existing_settings[ $field_id ]
3908
+						: $fldprops['default'],
3909
+					'css_class'  => '',
3910
+					'format'     => $fldprops['format'],
3911
+				];
3912
+			}
3913
+
3914
+
3915
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3916
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3917
+				: '';
3918
+		}
3919
+
3920
+		// we also need some hidden fields
3921
+		$settings_template_args['hidden_fields'] = [
3922
+			'messenger_settings[messenger]' . $messenger->name => [
3923
+				'type'  => 'hidden',
3924
+				'value' => $messenger->name,
3925
+			],
3926
+			'type' . $messenger->name                          => [
3927
+				'type'  => 'hidden',
3928
+				'value' => 'messenger',
3929
+			],
3930
+		];
3931
+
3932
+		// make sure any active message types that are existing are included in the hidden fields
3933
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3936
+					'type'  => 'hidden',
3937
+					'value' => $mt,
3938
+				];
3939
+			}
3940
+		}
3941
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3942
+			$settings_template_args['hidden_fields'],
3943
+			'array'
3944
+		);
3945
+		$active                                  =
3946
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3947
+
3948
+		$settings_template_args['messenger']           = $messenger->name;
3949
+		$settings_template_args['description']         = $messenger->description;
3950
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3951
+
3952
+
3953
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3954
+			$messenger->name
3955
+		)
3956
+			? $settings_template_args['show_hide_edit_form']
3957
+			: ' hidden';
3958
+
3959
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3960
+			? ' hidden'
3961
+			: $settings_template_args['show_hide_edit_form'];
3962
+
3963
+
3964
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3966
+		$settings_template_args['on_off_status'] = $active;
3967
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3968
+		return EEH_Template::display_template(
3969
+			$template,
3970
+			$settings_template_args,
3971
+			true
3972
+		);
3973
+	}
3974
+
3975
+
3976
+	/**
3977
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3978
+	 *
3979
+	 * @throws DomainException
3980
+	 * @throws EE_Error
3981
+	 * @throws InvalidDataTypeException
3982
+	 * @throws InvalidInterfaceException
3983
+	 * @throws InvalidArgumentException
3984
+	 * @throws ReflectionException
3985
+	 */
3986
+	public function activate_messenger_toggle()
3987
+	{
3988
+		$success = true;
3989
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3990
+		// let's check that we have required data
3991
+
3992
+		if (! $this->_active_messenger_name) {
3993
+			EE_Error::add_error(
3994
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995
+				__FILE__,
3996
+				__FUNCTION__,
3997
+				__LINE__
3998
+			);
3999
+			$success = false;
4000
+		}
4001
+
4002
+		// do a nonce check here since we're not arriving via a normal route
4003
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4004
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4005
+
4006
+		$this->_verify_nonce($nonce, $nonce_ref);
4007
+
4008
+
4009
+		$status = $this->request->getRequestParam('status');
4010
+		if (! $status) {
4011
+			EE_Error::add_error(
4012
+				esc_html__(
4013
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4014
+					'event_espresso'
4015
+				),
4016
+				__FILE__,
4017
+				__FUNCTION__,
4018
+				__LINE__
4019
+			);
4020
+			$success = false;
4021
+		}
4022
+
4023
+		// do check to verify we have a valid status.
4024
+		if ($status !== 'off' && $status !== 'on') {
4025
+			EE_Error::add_error(
4026
+				sprintf(
4027
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4028
+					$status
4029
+				),
4030
+				__FILE__,
4031
+				__FUNCTION__,
4032
+				__LINE__
4033
+			);
4034
+			$success = false;
4035
+		}
4036
+
4037
+		if ($success) {
4038
+			// made it here?  Stop dawdling then!!
4039
+			$success = $status === 'off'
4040
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4041
+				: $this->_activate_messenger($this->_active_messenger_name);
4042
+		}
4043
+
4044
+		$this->_template_args['success'] = $success;
4045
+
4046
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4047
+		$this->_return_json();
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4053
+	 *
4054
+	 * @throws DomainException
4055
+	 * @throws EE_Error
4056
+	 * @throws ReflectionException
4057
+	 * @throws InvalidDataTypeException
4058
+	 * @throws InvalidInterfaceException
4059
+	 * @throws InvalidArgumentException
4060
+	 */
4061
+	public function activate_mt_toggle()
4062
+	{
4063
+		$success = true;
4064
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4065
+
4066
+		// let's make sure we have the necessary data
4067
+		if (! $this->_active_message_type_name) {
4068
+			EE_Error::add_error(
4069
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070
+				__FILE__,
4071
+				__FUNCTION__,
4072
+				__LINE__
4073
+			);
4074
+			$success = false;
4075
+		}
4076
+
4077
+		if (! $this->_active_messenger_name) {
4078
+			EE_Error::add_error(
4079
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080
+				__FILE__,
4081
+				__FUNCTION__,
4082
+				__LINE__
4083
+			);
4084
+			$success = false;
4085
+		}
4086
+
4087
+		$status = $this->request->getRequestParam('status');
4088
+		if (! $status) {
4089
+			EE_Error::add_error(
4090
+				esc_html__(
4091
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4092
+					'event_espresso'
4093
+				),
4094
+				__FILE__,
4095
+				__FUNCTION__,
4096
+				__LINE__
4097
+			);
4098
+			$success = false;
4099
+		}
4100
+
4101
+
4102
+		// do check to verify we have a valid status.
4103
+		if ($status !== 'activate' && $status !== 'deactivate') {
4104
+			EE_Error::add_error(
4105
+				sprintf(
4106
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4107
+					$status
4108
+				),
4109
+				__FILE__,
4110
+				__FUNCTION__,
4111
+				__LINE__
4112
+			);
4113
+			$success = false;
4114
+		}
4115
+
4116
+
4117
+		// do a nonce check here since we're not arriving via a normal route
4118
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4119
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4120
+
4121
+		if ($success) {
4122
+			// made it here? um, what are you waiting for then?
4123
+			$success = $status === 'deactivate'
4124
+				? $this->_deactivate_message_type_for_messenger(
4125
+					$this->_active_messenger_name,
4126
+					$this->_active_message_type_name
4127
+				)
4128
+				: $this->_activate_message_type_for_messenger(
4129
+					$this->_active_messenger_name,
4130
+					$this->_active_message_type_name
4131
+				);
4132
+		}
4133
+
4134
+		$this->_template_args['success'] = $success;
4135
+		$this->_return_json();
4136
+	}
4137
+
4138
+
4139
+	/**
4140
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4141
+	 *
4142
+	 * @param string $messenger_name The name of the messenger being activated
4143
+	 * @return bool
4144
+	 * @throws DomainException
4145
+	 * @throws EE_Error
4146
+	 * @throws InvalidArgumentException
4147
+	 * @throws ReflectionException
4148
+	 * @throws InvalidDataTypeException
4149
+	 * @throws InvalidInterfaceException
4150
+	 */
4151
+	protected function _activate_messenger($messenger_name)
4152
+	{
4153
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4154
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4155
+			? $active_messenger->get_default_message_types()
4156
+			: [];
4157
+
4158
+		// ensure is active
4159
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4160
+
4161
+		// set response_data for reload
4162
+		foreach ($message_types_to_activate as $message_type_name) {
4163
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4164
+			if (
4165
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4166
+					$messenger_name,
4167
+					$message_type_name
4168
+				)
4169
+				&& $message_type instanceof EE_message_type
4170
+			) {
4171
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4172
+				if ($message_type->get_admin_settings_fields()) {
4173
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4174
+				}
4175
+			}
4176
+		}
4177
+
4178
+		// add success message for activating messenger
4179
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4180
+	}
4181
+
4182
+
4183
+	/**
4184
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4185
+	 *
4186
+	 * @param string $messenger_name The name of the messenger being activated
4187
+	 * @return bool
4188
+	 * @throws DomainException
4189
+	 * @throws EE_Error
4190
+	 * @throws InvalidArgumentException
4191
+	 * @throws ReflectionException
4192
+	 * @throws InvalidDataTypeException
4193
+	 * @throws InvalidInterfaceException
4194
+	 */
4195
+	protected function _deactivate_messenger($messenger_name)
4196
+	{
4197
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4198
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4199
+
4200
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4201
+	}
4202
+
4203
+
4204
+	/**
4205
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4206
+	 *
4207
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4208
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4209
+	 * @return bool
4210
+	 * @throws DomainException
4211
+	 * @throws EE_Error
4212
+	 * @throws InvalidArgumentException
4213
+	 * @throws ReflectionException
4214
+	 * @throws InvalidDataTypeException
4215
+	 * @throws InvalidInterfaceException
4216
+	 */
4217
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4218
+	{
4219
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4220
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4221
+
4222
+		// ensure is active
4223
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4224
+
4225
+		// set response for load
4226
+		if (
4227
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4228
+				$messenger_name,
4229
+				$message_type_name
4230
+			)
4231
+		) {
4232
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4233
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4234
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4235
+			}
4236
+		}
4237
+
4238
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4239
+			$active_messenger,
4240
+			$message_type_to_activate
4241
+		);
4242
+	}
4243
+
4244
+
4245
+	/**
4246
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4247
+	 *
4248
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4249
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4250
+	 * @return bool
4251
+	 * @throws DomainException
4252
+	 * @throws EE_Error
4253
+	 * @throws InvalidArgumentException
4254
+	 * @throws ReflectionException
4255
+	 * @throws InvalidDataTypeException
4256
+	 * @throws InvalidInterfaceException
4257
+	 */
4258
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4259
+	{
4260
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4261
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4262
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4263
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4264
+
4265
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4266
+			$active_messenger,
4267
+			$message_type_to_deactivate
4268
+		);
4269
+	}
4270
+
4271
+
4272
+	/**
4273
+	 * This just initializes the defaults for activating messenger and message type responses.
4274
+	 */
4275
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4276
+	{
4277
+		$this->_template_args['data']['active_mts'] = [];
4278
+		$this->_template_args['data']['mt_reload']  = [];
4279
+	}
4280
+
4281
+
4282
+	/**
4283
+	 * Setup appropriate response for activating a messenger and/or message types
4284
+	 *
4285
+	 * @param EE_messenger         $messenger
4286
+	 * @param EE_message_type|null $message_type
4287
+	 * @return bool
4288
+	 * @throws DomainException
4289
+	 * @throws EE_Error
4290
+	 * @throws InvalidArgumentException
4291
+	 * @throws ReflectionException
4292
+	 * @throws InvalidDataTypeException
4293
+	 * @throws InvalidInterfaceException
4294
+	 */
4295
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4296
+		$messenger,
4297
+		EE_Message_Type $message_type = null
4298
+	) {
4299
+		// if $messenger isn't a valid messenger object then get out.
4300
+		if (! $messenger instanceof EE_Messenger) {
4301
+			EE_Error::add_error(
4302
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303
+				__FILE__,
4304
+				__FUNCTION__,
4305
+				__LINE__
4306
+			);
4307
+			return false;
4308
+		}
4309
+		// activated
4310
+		if ($this->_template_args['data']['active_mts']) {
4311
+			EE_Error::overwrite_success();
4312
+			// activated a message type with the messenger
4313
+			if ($message_type instanceof EE_message_type) {
4314
+				EE_Error::add_success(
4315
+					sprintf(
4316
+						esc_html__(
4317
+							'%s message type has been successfully activated with the %s messenger',
4318
+							'event_espresso'
4319
+						),
4320
+						ucwords($message_type->label['singular']),
4321
+						ucwords($messenger->label['singular'])
4322
+					)
4323
+				);
4324
+
4325
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4326
+				if ($message_type->name === 'invoice') {
4327
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4328
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4329
+					if ($pm instanceof EE_Payment_Method) {
4330
+						EE_Error::add_attention(
4331
+							esc_html__(
4332
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4333
+								'event_espresso'
4334
+							)
4335
+						);
4336
+					}
4337
+				}
4338
+				// just toggles the entire messenger
4339
+			} else {
4340
+				EE_Error::add_success(
4341
+					sprintf(
4342
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4343
+						ucwords($messenger->label['singular'])
4344
+					)
4345
+				);
4346
+			}
4347
+
4348
+			return true;
4349
+
4350
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4351
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352
+			// in which case we just give a success message for the messenger being successfully activated.
4353
+		} else {
4354
+			if (! $messenger->get_default_message_types()) {
4355
+				// messenger doesn't have any default message types so still a success.
4356
+				EE_Error::add_success(
4357
+					sprintf(
4358
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4359
+						ucwords($messenger->label['singular'])
4360
+					)
4361
+				);
4362
+
4363
+				return true;
4364
+			} else {
4365
+				EE_Error::add_error(
4366
+					$message_type instanceof EE_message_type
4367
+					? sprintf(
4368
+						esc_html__(
4369
+							'%s message type was not successfully activated with the %s messenger',
4370
+							'event_espresso'
4371
+						),
4372
+						ucwords($message_type->label['singular']),
4373
+						ucwords($messenger->label['singular'])
4374
+					)
4375
+					: sprintf(
4376
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4377
+						ucwords($messenger->label['singular'])
4378
+					),
4379
+					__FILE__,
4380
+					__FUNCTION__,
4381
+					__LINE__
4382
+				);
4383
+
4384
+				return false;
4385
+			}
4386
+		}
4387
+	}
4388
+
4389
+
4390
+	/**
4391
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4392
+	 *
4393
+	 * @param EE_messenger         $messenger
4394
+	 * @param EE_message_type|null $message_type
4395
+	 * @return bool
4396
+	 * @throws DomainException
4397
+	 * @throws EE_Error
4398
+	 * @throws InvalidArgumentException
4399
+	 * @throws ReflectionException
4400
+	 * @throws InvalidDataTypeException
4401
+	 * @throws InvalidInterfaceException
4402
+	 */
4403
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4404
+		$messenger,
4405
+		EE_message_type $message_type = null
4406
+	) {
4407
+		EE_Error::overwrite_success();
4408
+
4409
+		// if $messenger isn't a valid messenger object then get out.
4410
+		if (! $messenger instanceof EE_Messenger) {
4411
+			EE_Error::add_error(
4412
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413
+				__FILE__,
4414
+				__FUNCTION__,
4415
+				__LINE__
4416
+			);
4417
+
4418
+			return false;
4419
+		}
4420
+
4421
+		if ($message_type instanceof EE_message_type) {
4422
+			$message_type_name = $message_type->name;
4423
+			EE_Error::add_success(
4424
+				sprintf(
4425
+					esc_html__(
4426
+						'%s message type has been successfully deactivated for the %s messenger.',
4427
+						'event_espresso'
4428
+					),
4429
+					ucwords($message_type->label['singular']),
4430
+					ucwords($messenger->label['singular'])
4431
+				)
4432
+			);
4433
+		} else {
4434
+			$message_type_name = '';
4435
+			EE_Error::add_success(
4436
+				sprintf(
4437
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4438
+					ucwords($messenger->label['singular'])
4439
+				)
4440
+			);
4441
+		}
4442
+
4443
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4444
+		if (
4445
+			$messenger->name === 'html'
4446
+			&& (
4447
+				is_null($message_type)
4448
+				|| $message_type_name === 'invoice'
4449
+			)
4450
+		) {
4451
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4452
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4453
+			if ($count_updated > 0) {
4454
+				$msg = $message_type_name === 'invoice'
4455
+					? esc_html__(
4456
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4457
+						'event_espresso'
4458
+					)
4459
+					: esc_html__(
4460
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4461
+						'event_espresso'
4462
+					);
4463
+				EE_Error::add_attention($msg);
4464
+			}
4465
+		}
4466
+
4467
+		return true;
4468
+	}
4469
+
4470
+
4471
+	/**
4472
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4473
+	 *
4474
+	 * @throws DomainException
4475
+	 * @throws EE_Error
4476
+	 * @throws EE_Error
4477
+	 */
4478
+	public function update_mt_form()
4479
+	{
4480
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481
+			EE_Error::add_error(
4482
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483
+				__FILE__,
4484
+				__FUNCTION__,
4485
+				__LINE__
4486
+			);
4487
+			$this->_return_json();
4488
+		}
4489
+
4490
+		$message_types = $this->get_installed_message_types();
4491
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4492
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494
+
4495
+		$this->_template_args['success'] = true;
4496
+		$this->_template_args['content'] = $content;
4497
+		$this->_return_json();
4498
+	}
4499
+
4500
+
4501
+	/**
4502
+	 * this handles saving the settings for a messenger or message type
4503
+	 *
4504
+	 * @throws EE_Error
4505
+	 * @throws EE_Error
4506
+	 */
4507
+	public function save_settings()
4508
+	{
4509
+		$type = $this->request->getRequestParam('type');
4510
+		if (! $type) {
4511
+			EE_Error::add_error(
4512
+				esc_html__(
4513
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4514
+					'event_espresso'
4515
+				),
4516
+				__FILE__,
4517
+				__FUNCTION__,
4518
+				__LINE__
4519
+			);
4520
+			$this->_template_args['error'] = true;
4521
+			$this->_return_json();
4522
+		}
4523
+
4524
+
4525
+		if ($type === 'messenger') {
4526
+			// this should be an array.
4527
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4528
+			$messenger = $settings['messenger'];
4529
+			// remove messenger and message_types from settings array
4530
+			unset($settings['messenger'], $settings['message_types']);
4531
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4532
+		} elseif ($type === 'message_type') {
4533
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4534
+			$messenger    = $settings['messenger'];
4535
+			$message_type = $settings['message_type'];
4536
+			// remove messenger and message_types from settings array
4537
+			unset($settings['messenger'], $settings['message_types']);
4538
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4539
+		}
4540
+
4541
+		// okay we should have the data all setup.  Now we just update!
4542
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4543
+
4544
+		if ($success) {
4545
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4546
+		} else {
4547
+			EE_Error::add_error(
4548
+				esc_html__('Settings did not get updated', 'event_espresso'),
4549
+				__FILE__,
4550
+				__FUNCTION__,
4551
+				__LINE__
4552
+			);
4553
+		}
4554
+
4555
+		$this->_template_args['success'] = $success;
4556
+		$this->_return_json();
4557
+	}
4558
+
4559
+
4560
+
4561
+
4562
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4563
+
4564
+
4565
+	/**
4566
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4567
+	 * However, this does not send immediately, it just queues for sending.
4568
+	 *
4569
+	 * @throws EE_Error
4570
+	 * @throws InvalidDataTypeException
4571
+	 * @throws InvalidInterfaceException
4572
+	 * @throws InvalidArgumentException
4573
+	 * @throws ReflectionException
4574
+	 * @since 4.9.0
4575
+	 */
4576
+	protected function _generate_now()
4577
+	{
4578
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4579
+		$this->_redirect_after_action(false, '', '', [], true);
4580
+	}
4581
+
4582
+
4583
+	/**
4584
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4585
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4586
+	 *
4587
+	 * @throws EE_Error
4588
+	 * @throws InvalidDataTypeException
4589
+	 * @throws InvalidInterfaceException
4590
+	 * @throws InvalidArgumentException
4591
+	 * @throws ReflectionException
4592
+	 * @since 4.9.0
4593
+	 */
4594
+	protected function _generate_and_send_now()
4595
+	{
4596
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4597
+		$this->_redirect_after_action(false, '', '', [], true);
4598
+	}
4599
+
4600
+
4601
+	/**
4602
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4603
+	 *
4604
+	 * @throws EE_Error
4605
+	 * @throws InvalidDataTypeException
4606
+	 * @throws InvalidInterfaceException
4607
+	 * @throws InvalidArgumentException
4608
+	 * @throws ReflectionException
4609
+	 * @since 4.9.0
4610
+	 */
4611
+	protected function _queue_for_resending()
4612
+	{
4613
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4614
+		$this->_redirect_after_action(false, '', '', [], true);
4615
+	}
4616
+
4617
+
4618
+	/**
4619
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4620
+	 *
4621
+	 * @throws EE_Error
4622
+	 * @throws InvalidDataTypeException
4623
+	 * @throws InvalidInterfaceException
4624
+	 * @throws InvalidArgumentException
4625
+	 * @throws ReflectionException
4626
+	 * @since 4.9.0
4627
+	 */
4628
+	protected function _send_now()
4629
+	{
4630
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4631
+		$this->_redirect_after_action(false, '', '', [], true);
4632
+	}
4633
+
4634
+
4635
+	/**
4636
+	 * Deletes EE_messages for IDs in the request.
4637
+	 *
4638
+	 * @throws EE_Error
4639
+	 * @throws InvalidDataTypeException
4640
+	 * @throws InvalidInterfaceException
4641
+	 * @throws InvalidArgumentException
4642
+	 * @since 4.9.0
4643
+	 */
4644
+	protected function _delete_ee_messages()
4645
+	{
4646
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4647
+		$deleted_count = 0;
4648
+		foreach ($MSG_IDs as $MSG_ID) {
4649
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4650
+				$deleted_count++;
4651
+			}
4652
+		}
4653
+		if ($deleted_count) {
4654
+			EE_Error::add_success(
4655
+				esc_html(
4656
+					_n(
4657
+						'Message successfully deleted',
4658
+						'Messages successfully deleted',
4659
+						$deleted_count,
4660
+						'event_espresso'
4661
+					)
4662
+				)
4663
+			);
4664
+		} else {
4665
+			EE_Error::add_error(
4666
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4667
+				__FILE__,
4668
+				__FUNCTION__,
4669
+				__LINE__
4670
+			);
4671
+		}
4672
+		$this->_redirect_after_action(false, '', '', [], true);
4673
+	}
4674
+
4675
+
4676
+	/**
4677
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4678
+	 *
4679
+	 * @return array
4680
+	 * @since 4.9.0
4681
+	 */
4682
+	protected function _get_msg_ids_from_request()
4683
+	{
4684
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4685
+		if (empty($MSG_IDs)) {
4686
+			return [];
4687
+		}
4688
+		// if 'MSG_ID' was just a single ID (not an array)
4689
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4690
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4691
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4692
+			? $MSG_IDs
4693
+			: array_keys($MSG_IDs);
4694
+	}
4695 4695
 }
Please login to merge, or discard this patch.
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getMsgModel()
117 117
     {
118
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
119 119
             $this->MSG_MODEL = EEM_Message::instance();
120 120
         }
121 121
         return $this->MSG_MODEL;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getMtpModel()
130 130
     {
131
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
132 132
             $this->MTP_MODEL = EEM_Message_Template::instance();
133 133
         }
134 134
         return $this->MTP_MODEL;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function getMtgModel()
143 143
     {
144
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
145 145
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
146 146
         }
147 147
         return $this->MTG_MODEL;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
         $i = 1;
212 212
         foreach ($active_messengers as $active_messenger) {
213 213
             if ($active_messenger instanceof EE_Message) {
214
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
215
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
214
+                $m_values[$i]['id']   = $active_messenger->messenger();
215
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
216 216
                 $i++;
217 217
             }
218 218
         }
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
         $i               = 1;
249 249
         foreach ($active_messages as $active_message) {
250 250
             if ($active_message instanceof EE_Message) {
251
-                $mt_values[ $i ]['id']   = $active_message->message_type();
252
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
251
+                $mt_values[$i]['id']   = $active_message->message_type();
252
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
253 253
                 $i++;
254 254
             }
255 255
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($message_type instanceof EE_message_type) {
289 289
                     $message_type_contexts = $message_type->get_contexts();
290 290
                     foreach ($message_type_contexts as $context => $context_details) {
291
-                        $contexts[ $context ] = $context_details['label'];
291
+                        $contexts[$context] = $context_details['label'];
292 292
                     }
293 293
                 }
294 294
             }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
322 322
             $messenger_options
323 323
         );
324
-        $input             = new EE_Select_Input(
324
+        $input = new EE_Select_Input(
325 325
             $messenger_options,
326 326
             [
327 327
                 'html_name'  => 'ee_messenger_filter_by',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
359 359
             $message_type_options
360 360
         );
361
-        $input                = new EE_Select_Input(
361
+        $input = new EE_Select_Input(
362 362
             $message_type_options,
363 363
             [
364 364
                 'html_name'  => 'ee_message_type_filter_by',
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
396 396
             $context_options
397 397
         );
398
-        $input           = new EE_Select_Input(
398
+        $input = new EE_Select_Input(
399 399
             $context_options,
400 400
             [
401 401
                 'html_name'  => 'ee_context_filter_by',
@@ -769,53 +769,53 @@  discard block
 block discarded – undo
769 769
 
770 770
     public function messages_help_tab()
771 771
     {
772
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
773 773
     }
774 774
 
775 775
 
776 776
     public function messengers_help_tab()
777 777
     {
778
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
779 779
     }
780 780
 
781 781
 
782 782
     public function message_types_help_tab()
783 783
     {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
785 785
     }
786 786
 
787 787
 
788 788
     public function messages_overview_help_tab()
789 789
     {
790
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
791 791
     }
792 792
 
793 793
 
794 794
     public function message_templates_help_tab()
795 795
     {
796
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
797 797
     }
798 798
 
799 799
 
800 800
     public function edit_message_template_help_tab()
801 801
     {
802
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
803 803
                         . esc_attr__('Editor Title', 'event_espresso')
804 804
                         . '" />';
805
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
806 806
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
807 807
                         . '" />';
808
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
809 809
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
810 810
                         . '" />';
811
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
812 812
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
813 813
                         . '" />';
814
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
815 815
                         . esc_attr__('Publish Metabox', 'event_espresso')
816 816
                         . '" />';
817 817
         EEH_Template::display_template(
818
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
819 819
             $args
820 820
         );
821 821
     }
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
         $this->_set_shortcodes();
831 831
         $args['shortcodes'] = $this->_shortcodes;
832 832
         EEH_Template::display_template(
833
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
834 834
             $args
835 835
         );
836 836
     }
@@ -838,16 +838,16 @@  discard block
 block discarded – undo
838 838
 
839 839
     public function preview_message_help_tab()
840 840
     {
841
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
842 842
     }
843 843
 
844 844
 
845 845
     public function settings_help_tab()
846 846
     {
847
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
848
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
849
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
850
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
847
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
848
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
849
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
850
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
851 851
         $args['img3'] = '<div class="switch">'
852 852
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
853 853
                         . ' type="checkbox" checked>'
@@ -858,25 +858,25 @@  discard block
 block discarded – undo
858 858
                         . ' type="checkbox">'
859 859
                         . '<label for="ee-on-off-toggle-on"></label>'
860 860
                         . '</div>';
861
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
862 862
     }
863 863
 
864 864
 
865 865
     public function load_scripts_styles()
866 866
     {
867
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
868 868
         wp_enqueue_style('espresso_ee_msg');
869 869
 
870 870
         wp_register_script(
871 871
             'ee-messages-settings',
872
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
873 873
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
874 874
             EVENT_ESPRESSO_VERSION,
875 875
             true
876 876
         );
877 877
         wp_register_script(
878 878
             'ee-msg-list-table-js',
879
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
880 880
             ['ee-dialog'],
881 881
             EVENT_ESPRESSO_VERSION
882 882
         );
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 
920 920
         $this->_set_shortcodes();
921 921
 
922
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
923 923
             esc_html__(
924 924
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
925 925
                 'event_espresso'
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
             'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
932 932
             'event_espresso'
933 933
         );
934
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
935 935
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
936 936
             'event_espresso'
937 937
         );
938 938
 
939 939
         wp_register_script(
940 940
             'ee_msgs_edit_js',
941
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
942 942
             ['jquery'],
943 943
             EVENT_ESPRESSO_VERSION
944 944
         );
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
     {
982 982
         wp_register_style(
983 983
             'ee-message-settings',
984
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
985 985
             [],
986 986
             EVENT_ESPRESSO_VERSION
987 987
         );
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
             }
1068 1068
             $status_bulk_actions = $common_bulk_actions;
1069 1069
             // unset bulk actions not applying to status
1070
-            if (! empty($status_bulk_actions)) {
1070
+            if ( ! empty($status_bulk_actions)) {
1071 1071
                 switch ($status) {
1072 1072
                     case EEM_Message::status_idle:
1073 1073
                     case EEM_Message::status_resend:
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
                 continue;
1097 1097
             }
1098 1098
 
1099
-            $this->_views[ strtolower($status) ] = [
1099
+            $this->_views[strtolower($status)] = [
1100 1100
                 'slug'        => strtolower($status),
1101 1101
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1102 1102
                 'count'       => 0,
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
             if ($action_item === 'see_notifications_for') {
1146 1146
                 continue;
1147 1147
             }
1148
-            $action_items[ $action_item ] = [
1148
+            $action_items[$action_item] = [
1149 1149
                 'class' => $action_details['css_class'],
1150 1150
                 'desc'  => $action_details['label'],
1151 1151
             ];
@@ -1154,37 +1154,37 @@  discard block
 block discarded – undo
1154 1154
         /** @var array $status_items status legend setup */
1155 1155
         $status_items = [
1156 1156
             'sent_status'                => [
1157
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1158 1158
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1159 1159
             ],
1160 1160
             'idle_status'                => [
1161
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1162 1162
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1163 1163
             ],
1164 1164
             'failed_status'              => [
1165
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1166 1166
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1167 1167
             ],
1168 1168
             'messenger_executing_status' => [
1169
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1170 1170
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1171 1171
             ],
1172 1172
             'resend_status'              => [
1173
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1174 1174
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1175 1175
             ],
1176 1176
             'incomplete_status'          => [
1177
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1178 1178
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1179 1179
             ],
1180 1180
             'retry_status'               => [
1181
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1182 1182
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1183 1183
             ],
1184 1184
         ];
1185 1185
         if (EEM_Message::debug()) {
1186 1186
             $status_items['debug_only_status'] = [
1187
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1188 1188
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1189 1189
             ];
1190 1190
         }
@@ -1199,11 +1199,11 @@  discard block
 block discarded – undo
1199 1199
     protected function _custom_mtps_preview()
1200 1200
     {
1201 1201
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1202
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1203
-                                                . ' alt="' . esc_attr__(
1202
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1203
+                                                . ' alt="'.esc_attr__(
1204 1204
                                                     'Preview Custom Message Templates screenshot',
1205 1205
                                                     'event_espresso'
1206
-                                                ) . '" />';
1206
+                                                ).'" />';
1207 1207
         $this->_template_args['preview_text'] = '<strong>'
1208 1208
                                                 . esc_html__(
1209 1209
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
         $installed               = [];
1280 1280
 
1281 1281
         foreach ($installed_message_types as $message_type) {
1282
-            $installed[ $message_type->name ] = $message_type;
1282
+            $installed[$message_type->name] = $message_type;
1283 1283
         }
1284 1284
 
1285 1285
         return $installed;
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
         // we need to assemble the title from Various details
1406 1406
         $context_label = sprintf(
1407 1407
             esc_html__('(%s %s)', 'event_espresso'),
1408
-            $c_config[ $context ]['label'],
1408
+            $c_config[$context]['label'],
1409 1409
             ucwords($c_label['label'])
1410 1410
         );
1411 1411
 
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
             $message_template_group->message_type()
1428 1428
         );
1429 1429
 
1430
-        if (! $template_field_structure) {
1430
+        if ( ! $template_field_structure) {
1431 1431
             $template_field_structure = false;
1432 1432
             $template_fields          = esc_html__(
1433 1433
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1441,21 +1441,21 @@  discard block
 block discarded – undo
1441 1441
 
1442 1442
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1443 1443
         // will get handled in the "extra" array.
1444
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1445
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1446
-                unset($template_field_structure[ $context ][ $reference_field ]);
1444
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1445
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1446
+                unset($template_field_structure[$context][$reference_field]);
1447 1447
             }
1448 1448
         }
1449 1449
 
1450 1450
         // let's loop through the template_field_structure and actually assemble the input fields!
1451
-        if (! empty($template_field_structure)) {
1452
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1451
+        if ( ! empty($template_field_structure)) {
1452
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1453 1453
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1454 1454
                 // the extra array and reset them.
1455 1455
                 if ($template_field === 'extra') {
1456 1456
                     $this->_template_args['is_extra_fields'] = true;
1457 1457
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1458
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
+                        $message_template = $message_templates[$context][$reference_field];
1459 1459
                         $content          = $message_template instanceof EE_Message_Template
1460 1460
                             ? $message_template->get('MTP_content')
1461 1461
                             : '';
@@ -1464,7 +1464,7 @@  discard block
 block discarded – undo
1464 1464
                             $continue = false;
1465 1465
                             if (isset($extra_array['shortcodes_required'])) {
1466 1466
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1467
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1468 1468
                                         $continue = true;
1469 1469
                                     }
1470 1470
                                 }
@@ -1473,53 +1473,53 @@  discard block
 block discarded – undo
1473 1473
                                 }
1474 1474
                             }
1475 1475
 
1476
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1477 1477
 
1478
-                            $template_form_fields[ $field_id ]         = $extra_array;
1479
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1478
+                            $template_form_fields[$field_id]         = $extra_array;
1479
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1480 1480
                                                                          . $reference_field
1481 1481
                                                                          . '][content]['
1482
-                                                                         . $extra_field . ']';
1483
-                            $css_class                                 = isset($extra_array['css_class'])
1482
+                                                                         . $extra_field.']';
1483
+                            $css_class = isset($extra_array['css_class'])
1484 1484
                                 ? $extra_array['css_class']
1485 1485
                                 : '';
1486 1486
 
1487
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1488 1488
                                                                               && in_array($extra_field, $v_fields, true)
1489 1489
                                                                               && (
1490
-                                                                                  is_array($validators[ $extra_field ])
1491
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1490
+                                                                                  is_array($validators[$extra_field])
1491
+                                                                                  && isset($validators[$extra_field]['msg'])
1492 1492
                                                                               )
1493
-                                ? 'validate-error ' . $css_class
1493
+                                ? 'validate-error '.$css_class
1494 1494
                                 : $css_class;
1495 1495
 
1496
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1497
-                                                                          && isset($content[ $extra_field ])
1498
-                                ? $content[ $extra_field ]
1496
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1497
+                                                                          && isset($content[$extra_field])
1498
+                                ? $content[$extra_field]
1499 1499
                                 : '';
1500 1500
 
1501 1501
                             // do we have a validation error?  if we do then let's use that value instead
1502
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1503
-                                ? $validators[ $extra_field ]['value']
1504
-                                : $template_form_fields[ $field_id ]['value'];
1502
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1503
+                                ? $validators[$extra_field]['value']
1504
+                                : $template_form_fields[$field_id]['value'];
1505 1505
 
1506 1506
 
1507
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1508 1508
 
1509 1509
                             // shortcode selector
1510 1510
                             $field_name_to_use                                   = $extra_field === 'main'
1511 1511
                                 ? 'content'
1512 1512
                                 : $extra_field;
1513
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1514 1514
                                 $field_name_to_use,
1515 1515
                                 $field_id
1516 1516
                             );
1517 1517
                         }
1518
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1519
-                        $template_field_template_name_id = $reference_field . '-name';
1518
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1519
+                        $template_field_template_name_id = $reference_field.'-name';
1520 1520
 
1521
-                        $template_form_fields[ $template_field_MTP_id ] = [
1522
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1521
+                        $template_form_fields[$template_field_MTP_id] = [
1522
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1523 1523
                             'label'      => null,
1524 1524
                             'input'      => 'hidden',
1525 1525
                             'type'       => 'int',
@@ -1531,8 +1531,8 @@  discard block
 block discarded – undo
1531 1531
                             'db-col'     => 'MTP_ID',
1532 1532
                         ];
1533 1533
 
1534
-                        $template_form_fields[ $template_field_template_name_id ] = [
1535
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1534
+                        $template_form_fields[$template_field_template_name_id] = [
1535
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1536 1536
                             'label'      => null,
1537 1537
                             'input'      => 'hidden',
1538 1538
                             'type'       => 'string',
@@ -1546,38 +1546,38 @@  discard block
 block discarded – undo
1546 1546
                     }
1547 1547
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1548 1548
                 } else {
1549
-                    $field_id                                   = $template_field . '-content';
1550
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1551
-                    $template_form_fields[ $field_id ]['name']  =
1552
-                        'MTP_template_fields[' . $template_field . '][content]';
1549
+                    $field_id                                   = $template_field.'-content';
1550
+                    $template_form_fields[$field_id]          = $field_setup_array;
1551
+                    $template_form_fields[$field_id]['name']  =
1552
+                        'MTP_template_fields['.$template_field.'][content]';
1553 1553
                     $message_template                           =
1554
-                        isset($message_templates[ $context ][ $template_field ])
1555
-                            ? $message_templates[ $context ][ $template_field ]
1554
+                        isset($message_templates[$context][$template_field])
1555
+                            ? $message_templates[$context][$template_field]
1556 1556
                             : null;
1557
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1558
-                                                                  && is_array($message_templates[ $context ])
1557
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1558
+                                                                  && is_array($message_templates[$context])
1559 1559
                                                                   && $message_template instanceof EE_Message_Template
1560 1560
                         ? $message_template->get('MTP_content')
1561 1561
                         : '';
1562 1562
 
1563 1563
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1564
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1565
-                        ? $validators[ $template_field ]['value']
1566
-                        : $template_form_fields[ $field_id ]['value'];
1564
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1565
+                        ? $validators[$template_field]['value']
1566
+                        : $template_form_fields[$field_id]['value'];
1567 1567
 
1568 1568
 
1569
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1570 1570
                     $css_class                                      = isset($field_setup_array['css_class'])
1571 1571
                         ? $field_setup_array['css_class']
1572 1572
                         : '';
1573
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1574 1574
                                                                       && in_array($template_field, $v_fields, true)
1575
-                                                                      && isset($validators[ $template_field ]['msg'])
1576
-                        ? 'validate-error ' . $css_class
1575
+                                                                      && isset($validators[$template_field]['msg'])
1576
+                        ? 'validate-error '.$css_class
1577 1577
                         : $css_class;
1578 1578
 
1579 1579
                     // shortcode selector
1580
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1581 1581
                         $template_field,
1582 1582
                         $field_id
1583 1583
                     );
@@ -1585,12 +1585,12 @@  discard block
 block discarded – undo
1585 1585
 
1586 1586
                 // k took care of content field(s) now let's take care of others.
1587 1587
 
1588
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1589
-                $template_field_field_template_name_id = $template_field . '-name';
1588
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1589
+                $template_field_field_template_name_id = $template_field.'-name';
1590 1590
 
1591 1591
                 // foreach template field there are actually two form fields created
1592
-                $template_form_fields[ $template_field_MTP_id ] = [
1593
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1592
+                $template_form_fields[$template_field_MTP_id] = [
1593
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1594 1594
                     'label'      => null,
1595 1595
                     'input'      => 'hidden',
1596 1596
                     'type'       => 'int',
@@ -1602,8 +1602,8 @@  discard block
 block discarded – undo
1602 1602
                     'db-col'     => 'MTP_ID',
1603 1603
                 ];
1604 1604
 
1605
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1606
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1605
+                $template_form_fields[$template_field_field_template_name_id] = [
1606
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1607 1607
                     'label'      => null,
1608 1608
                     'input'      => 'hidden',
1609 1609
                     'type'       => 'string',
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
                 'format'     => '%d',
1721 1721
                 'db-col'     => 'MTP_deleted',
1722 1722
             ];
1723
-            $sidebar_form_fields['ee-msg-author']  = [
1723
+            $sidebar_form_fields['ee-msg-author'] = [
1724 1724
                 'name'       => 'MTP_user_id',
1725 1725
                 'label'      => esc_html__('Author', 'event_espresso'),
1726 1726
                 'input'      => 'hidden',
@@ -1739,17 +1739,17 @@  discard block
 block discarded – undo
1739 1739
                 'value' => $action,
1740 1740
             ];
1741 1741
 
1742
-            $sidebar_form_fields['ee-msg-id']        = [
1742
+            $sidebar_form_fields['ee-msg-id'] = [
1743 1743
                 'name'  => 'id',
1744 1744
                 'input' => 'hidden',
1745 1745
                 'type'  => 'int',
1746 1746
                 'value' => $GRP_ID,
1747 1747
             ];
1748 1748
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1749
-                'name'  => $action . '_nonce',
1749
+                'name'  => $action.'_nonce',
1750 1750
                 'input' => 'hidden',
1751 1751
                 'type'  => 'string',
1752
-                'value' => wp_create_nonce($action . '_nonce'),
1752
+                'value' => wp_create_nonce($action.'_nonce'),
1753 1753
             ];
1754 1754
 
1755 1755
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1780,7 +1780,7 @@  discard block
 block discarded – undo
1780 1780
         );
1781 1781
 
1782 1782
         // add preview button
1783
-        $preview_url    = parent::add_query_args_and_nonce(
1783
+        $preview_url = parent::add_query_args_and_nonce(
1784 1784
             [
1785 1785
                 'message_type' => $message_template_group->message_type(),
1786 1786
                 'messenger'    => $message_template_group->messenger(),
@@ -1791,7 +1791,7 @@  discard block
 block discarded – undo
1791 1791
             ],
1792 1792
             $this->_admin_base_url
1793 1793
         );
1794
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1795 1795
                           . esc_html__('Preview', 'event_espresso')
1796 1796
                           . '</a>';
1797 1797
 
@@ -1827,11 +1827,11 @@  discard block
 block discarded – undo
1827 1827
             $context_label
1828 1828
         );
1829 1829
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1830
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1831 1831
 
1832 1832
         $this->_template_path = $this->_template_args['GRP_ID']
1833 1833
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1834
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1835 1835
 
1836 1836
         // send along EE_Message_Template_Group object for further template use.
1837 1837
         $this->_template_args['MTP'] = $message_template_group;
@@ -1887,7 +1887,7 @@  discard block
 block discarded – undo
1887 1887
     ) {
1888 1888
         $template_args = [
1889 1889
             'context'                   => $context,
1890
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1891 1891
             'is_active'                 => $message_template_group->is_context_active($context),
1892 1892
             'on_off_action'             => $message_template_group->is_context_active($context)
1893 1893
                 ? 'context-off'
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
             'message_template_group_id' => $message_template_group->ID(),
1897 1897
         ];
1898 1898
         return EEH_Template::display_template(
1899
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1900 1900
             $template_args,
1901 1901
             true
1902 1902
         );
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
         }
1954 1954
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1955 1955
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1956
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1957 1957
             EE_Error::add_error(
1958 1958
                 sprintf(
1959 1959
                     esc_html__(
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
         $messenger    = $this->request->getRequestParam('msgr');
2085 2085
         $message_type = $this->request->getRequestParam('mt');
2086 2086
         // we need to make sure we've got the info we need.
2087
-        if (! ($GRP_ID && $messenger && $message_type)) {
2087
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2088 2088
             EE_Error::add_error(
2089 2089
                 esc_html__(
2090 2090
                     'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
@@ -2121,7 +2121,7 @@  discard block
 block discarded – undo
2121 2121
         }
2122 2122
 
2123 2123
         // any error messages?
2124
-        if (! $success) {
2124
+        if ( ! $success) {
2125 2125
             EE_Error::add_error(
2126 2126
                 esc_html__(
2127 2127
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2170,7 +2170,7 @@  discard block
 block discarded – undo
2170 2170
     {
2171 2171
         // first make sure we've got the necessary parameters
2172 2172
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2173
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2174 2174
             EE_Error::add_error(
2175 2175
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2176 2176
                 __FILE__,
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2197 2197
 
2198 2198
         // let's add a button to go back to the edit view
2199
-        $query_args             = [
2199
+        $query_args = [
2200 2200
             'id'      => $GRP_ID,
2201 2201
             'evt_id'  => $EVT_ID,
2202 2202
             'context' => $context,
@@ -2217,7 +2217,7 @@  discard block
 block discarded – undo
2217 2217
         $preview_title = sprintf(
2218 2218
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2219 2219
             $active_messenger_label,
2220
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2221 2221
         );
2222 2222
         if (empty($preview)) {
2223 2223
             $this->noEventsErrorMessage();
@@ -2225,7 +2225,7 @@  discard block
 block discarded – undo
2225 2225
         // setup display of preview.
2226 2226
         $this->_admin_page_title                    = $preview_title;
2227 2227
         $this->_template_args['admin_page_title']   = $preview_title;
2228
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2229 2229
         $this->_template_args['data']['force_json'] = true;
2230 2230
 
2231 2231
         return '';
@@ -2246,7 +2246,7 @@  discard block
 block discarded – undo
2246 2246
             ],
2247 2247
             admin_url('admin.php')
2248 2248
         );
2249
-        $message    = $test_send
2249
+        $message = $test_send
2250 2250
             ? esc_html__(
2251 2251
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2252 2252
                 'event_espresso'
@@ -2339,10 +2339,10 @@  discard block
 block discarded – undo
2339 2339
             // only include template packs that support this messenger and message type!
2340 2340
             $supports = $tp->get_supports();
2341 2341
             if (
2342
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2342
+                ! isset($supports[$this->_message_template_group->messenger()])
2343 2343
                 || ! in_array(
2344 2344
                     $this->_message_template_group->message_type(),
2345
-                    $supports[ $this->_message_template_group->messenger() ],
2345
+                    $supports[$this->_message_template_group->messenger()],
2346 2346
                     true
2347 2347
                 )
2348 2348
             ) {
@@ -2366,7 +2366,7 @@  discard block
 block discarded – undo
2366 2366
         }
2367 2367
 
2368 2368
         // setup variation select values for the currently selected template.
2369
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2370 2370
             $this->_message_template_group->messenger(),
2371 2371
             $this->_message_template_group->message_type()
2372 2372
         );
@@ -2380,12 +2380,12 @@  discard block
 block discarded – undo
2380 2380
 
2381 2381
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2382 2382
 
2383
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2384 2384
             'MTP_template_pack',
2385 2385
             $tp_select_values,
2386 2386
             $this->_message_template_group->get_template_pack_name()
2387 2387
         );
2388
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2389 2389
             'MTP_template_variation',
2390 2390
             $variations_select_values,
2391 2391
             $this->_message_template_group->get_template_pack_variation()
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2396 2396
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2397 2397
 
2398
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2399 2399
 
2400 2400
         EEH_Template::display_template($template, $template_args);
2401 2401
     }
@@ -2421,33 +2421,33 @@  discard block
 block discarded – undo
2421 2421
         // first we need to see if there are any fields
2422 2422
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2423 2423
 
2424
-        if (! empty($fields)) {
2424
+        if ( ! empty($fields)) {
2425 2425
             // yup there be fields
2426 2426
             foreach ($fields as $field => $config) {
2427
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2428 2428
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2429 2429
                 $default  = isset($config['default']) ? $config['default'] : '';
2430 2430
                 $default  = isset($config['value']) ? $config['value'] : $default;
2431 2431
 
2432 2432
                 // if type is hidden and the value is empty
2433 2433
                 // something may have gone wrong so let's correct with the defaults
2434
-                $fix                = $config['input'] === 'hidden'
2435
-                                      && isset($existing[ $field ])
2436
-                                      && empty($existing[ $field ])
2434
+                $fix = $config['input'] === 'hidden'
2435
+                                      && isset($existing[$field])
2436
+                                      && empty($existing[$field])
2437 2437
                     ? $default
2438 2438
                     : '';
2439
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2440
-                    ? $existing[ $field ]
2439
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2440
+                    ? $existing[$field]
2441 2441
                     : $fix;
2442 2442
 
2443
-                $template_form_fields[ $field_id ] = [
2444
-                    'name'       => 'test_settings_fld[' . $field . ']',
2443
+                $template_form_fields[$field_id] = [
2444
+                    'name'       => 'test_settings_fld['.$field.']',
2445 2445
                     'label'      => $config['label'],
2446 2446
                     'input'      => $config['input'],
2447 2447
                     'type'       => $config['type'],
2448 2448
                     'required'   => $config['required'],
2449 2449
                     'validation' => $config['validation'],
2450
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2451 2451
                     'css_class'  => $config['css_class'],
2452 2452
                     'options'    => isset($config['options']) ? $config['options'] : [],
2453 2453
                     'default'    => $default,
@@ -2461,7 +2461,7 @@  discard block
 block discarded – undo
2461 2461
             : '';
2462 2462
 
2463 2463
         // print out $test_settings_fields
2464
-        if (! empty($test_settings_html)) {
2464
+        if ( ! empty($test_settings_html)) {
2465 2465
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2466 2466
             $test_settings_html .= 'name="test_button" value="';
2467 2467
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
         ];
2508 2508
 
2509 2509
         return EEH_Template::display_template(
2510
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2511 2511
             $template_args,
2512 2512
             true
2513 2513
         );
@@ -2533,7 +2533,7 @@  discard block
 block discarded – undo
2533 2533
         // $messenger = $this->_message_template_group->messenger_obj();
2534 2534
         // now let's set the content depending on the status of the shortcodes array
2535 2535
         if (empty($shortcodes)) {
2536
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2537 2537
             return;
2538 2538
         }
2539 2539
         ?>
@@ -2569,7 +2569,7 @@  discard block
 block discarded – undo
2569 2569
     {
2570 2570
 
2571 2571
         // no need to run this if the property is already set
2572
-        if (! empty($this->_shortcodes)) {
2572
+        if ( ! empty($this->_shortcodes)) {
2573 2573
             return;
2574 2574
         }
2575 2575
 
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
     protected function _set_message_template_group()
2625 2625
     {
2626 2626
         // get out if this is already set.
2627
-        if (! empty($this->_message_template_group)) {
2627
+        if ( ! empty($this->_message_template_group)) {
2628 2628
             return;
2629 2629
         }
2630 2630
 
@@ -2670,8 +2670,8 @@  discard block
 block discarded – undo
2670 2670
                     <?php
2671 2671
                 }
2672 2672
                 // setup nonce_url
2673
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2674
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2673
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2674
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2675 2675
                 ?>
2676 2676
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2677 2677
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2684,7 +2684,7 @@  discard block
 block discarded – undo
2684 2684
                             $checked = ($context === $args['context']) ? 'selected' : '';
2685 2685
                             ?>
2686 2686
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2687
-                                <?php echo esc_html($context_details[ $context ]['label']); ?>
2687
+                                <?php echo esc_html($context_details[$context]['label']); ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690 2690
                     endif; ?>
@@ -3076,7 +3076,7 @@  discard block
 block discarded – undo
3076 3076
     {
3077 3077
         if (is_array($content)) {
3078 3078
             foreach ($content as $key => $value) {
3079
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3079
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3080 3080
             }
3081 3081
             return $content;
3082 3082
         }
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
 
3115 3115
         $context   = ucwords(str_replace('_', ' ', $context));
3116 3116
         $item_desc = $messenger_label && $message_type_label
3117
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3117
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3118 3118
             : '';
3119 3119
         $item_desc .= 'Message Template';
3120 3120
         return $item_desc;
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
         if ($all) {
3267 3267
             // Checkboxes
3268 3268
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3269
-            if (! empty($checkboxes)) {
3269
+            if ( ! empty($checkboxes)) {
3270 3270
                 // if array has more than one element then success message should be plural.
3271 3271
                 // todo: what about nonce?
3272 3272
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3276,18 +3276,18 @@  discard block
 block discarded – undo
3276 3276
                     $trashed_or_restored = $trash
3277 3277
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3278 3278
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3279
-                    if (! $trashed_or_restored) {
3279
+                    if ( ! $trashed_or_restored) {
3280 3280
                         $success = 0;
3281 3281
                     }
3282 3282
                 }
3283 3283
             } else {
3284 3284
                 // grab single GRP_ID and handle
3285 3285
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3286
-                if (! empty($GRP_ID)) {
3286
+                if ( ! empty($GRP_ID)) {
3287 3287
                     $trashed_or_restored = $trash
3288 3288
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3289 3289
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3290
-                    if (! $trashed_or_restored) {
3290
+                    if ( ! $trashed_or_restored) {
3291 3291
                         $success = 0;
3292 3292
                     }
3293 3293
                 } else {
@@ -3335,7 +3335,7 @@  discard block
 block discarded – undo
3335 3335
 
3336 3336
         // checkboxes
3337 3337
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3338
-        if (! empty($checkboxes)) {
3338
+        if ( ! empty($checkboxes)) {
3339 3339
             // if array has more than one element then success message should be plural
3340 3340
             $success = count($checkboxes) > 1 ? 2 : 1;
3341 3341
 
@@ -3439,7 +3439,7 @@  discard block
 block discarded – undo
3439 3439
     protected function _set_m_mt_settings()
3440 3440
     {
3441 3441
         // first if this is already set then lets get out no need to regenerate data.
3442
-        if (! empty($this->_m_mt_settings)) {
3442
+        if ( ! empty($this->_m_mt_settings)) {
3443 3443
             return;
3444 3444
         }
3445 3445
 
@@ -3451,7 +3451,7 @@  discard block
 block discarded – undo
3451 3451
         // assemble the array for the _tab_text_links helper
3452 3452
 
3453 3453
         foreach ($messengers as $messenger) {
3454
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3454
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3455 3455
                 'label' => ucwords($messenger->label['singular']),
3456 3456
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3457 3457
                     ? 'messenger-active'
@@ -3468,7 +3468,7 @@  discard block
 block discarded – undo
3468 3468
             foreach ($message_types as $message_type) {
3469 3469
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3470 3470
                 // it shouldn't show in either the inactive OR active metabox.
3471
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3471
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3472 3472
                     continue;
3473 3473
                 }
3474 3474
 
@@ -3479,12 +3479,12 @@  discard block
 block discarded – undo
3479 3479
                     ? 'active'
3480 3480
                     : 'inactive';
3481 3481
 
3482
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3482
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3483 3483
                     'label'    => ucwords($message_type->label['singular']),
3484
-                    'class'    => 'message-type-' . $a_or_i,
3485
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3486
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3487
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3484
+                    'class'    => 'message-type-'.$a_or_i,
3485
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3486
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3487
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3488 3488
                     'title'    => $a_or_i === 'active'
3489 3489
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3490 3490
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3515,25 +3515,25 @@  discard block
 block discarded – undo
3515 3515
         $fields                                         = $message_type->get_admin_settings_fields();
3516 3516
         $settings_template_args['template_form_fields'] = '';
3517 3517
 
3518
-        if (! empty($fields) && $active) {
3518
+        if ( ! empty($fields) && $active) {
3519 3519
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3520 3520
             foreach ($fields as $fldname => $fldprops) {
3521
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3522
-                $template_form_field[ $field_id ] = [
3523
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3521
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3522
+                $template_form_field[$field_id] = [
3523
+                    'name'       => 'message_type_settings['.$fldname.']',
3524 3524
                     'label'      => $fldprops['label'],
3525 3525
                     'input'      => $fldprops['field_type'],
3526 3526
                     'type'       => $fldprops['value_type'],
3527 3527
                     'required'   => $fldprops['required'],
3528 3528
                     'validation' => $fldprops['validation'],
3529
-                    'value'      => isset($existing_settings[ $fldname ])
3530
-                        ? $existing_settings[ $fldname ]
3529
+                    'value'      => isset($existing_settings[$fldname])
3530
+                        ? $existing_settings[$fldname]
3531 3531
                         : $fldprops['default'],
3532 3532
                     'options'    => isset($fldprops['options'])
3533 3533
                         ? $fldprops['options']
3534 3534
                         : [],
3535
-                    'default'    => isset($existing_settings[ $fldname ])
3536
-                        ? $existing_settings[ $fldname ]
3535
+                    'default'    => isset($existing_settings[$fldname])
3536
+                        ? $existing_settings[$fldname]
3537 3537
                         : $fldprops['default'],
3538 3538
                     'css_class'  => 'no-drag',
3539 3539
                     'format'     => $fldprops['format'],
@@ -3553,15 +3553,15 @@  discard block
 block discarded – undo
3553 3553
         $settings_template_args['description'] = $message_type->description;
3554 3554
         // we also need some hidden fields
3555 3555
         $hidden_fields = [
3556
-            'message_type_settings[messenger]' . $message_type->name    => [
3556
+            'message_type_settings[messenger]'.$message_type->name    => [
3557 3557
                 'type'  => 'hidden',
3558 3558
                 'value' => $messenger->name,
3559 3559
             ],
3560
-            'message_type_settings[message_type]' . $message_type->name => [
3560
+            'message_type_settings[message_type]'.$message_type->name => [
3561 3561
                 'type'  => 'hidden',
3562 3562
                 'value' => $message_type->name,
3563 3563
             ],
3564
-            'type' . $message_type->name                                => [
3564
+            'type'.$message_type->name                                => [
3565 3565
                 'type'  => 'hidden',
3566 3566
                 'value' => 'message_type',
3567 3567
             ],
@@ -3571,12 +3571,12 @@  discard block
 block discarded – undo
3571 3571
             $hidden_fields,
3572 3572
             'array'
3573 3573
         );
3574
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3574
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3575 3575
             ? ' hidden'
3576 3576
             : '';
3577 3577
 
3578 3578
 
3579
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3579
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3580 3580
         return EEH_Template::display_template($template, $settings_template_args, true);
3581 3581
     }
3582 3582
 
@@ -3604,21 +3604,21 @@  discard block
 block discarded – undo
3604 3604
 
3605 3605
                 // messenger meta boxes
3606 3606
                 $active         = $selected_messenger === $messenger;
3607
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3608
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3607
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3608
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3609 3609
                     : '';
3610 3610
 
3611
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3611
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3612 3612
                     esc_html__('%s Settings', 'event_espresso'),
3613 3613
                     $tab_array['label']
3614 3614
                 );
3615 3615
 
3616
-                $m_template_args[ $messenger . '_a_box' ] = [
3616
+                $m_template_args[$messenger.'_a_box'] = [
3617 3617
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3618 3618
                     'inactive_message_types' => isset(
3619
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3619
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3620 3620
                     )
3621
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3621
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3622 3622
                         : '',
3623 3623
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3624 3624
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3630,13 +3630,13 @@  discard block
 block discarded – undo
3630 3630
                 // message type meta boxes
3631 3631
                 // (which is really just the inactive container for each messenger
3632 3632
                 // showing inactive message types for that messenger)
3633
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3634
-                $mt_template_args[ $messenger . '_i_box' ] = [
3633
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3634
+                $mt_template_args[$messenger.'_i_box'] = [
3635 3635
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3636 3636
                     'inactive_message_types' => isset(
3637
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3637
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3638 3638
                     )
3639
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3639
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3640 3640
                         : '',
3641 3641
                     'hidden'                 => $active ? '' : ' hidden',
3642 3642
                     'hide_on_message'        => $hide_on_message,
@@ -3649,14 +3649,14 @@  discard block
 block discarded – undo
3649 3649
 
3650 3650
 
3651 3651
         // register messenger metaboxes
3652
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3652
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3653 3653
         foreach ($m_boxes as $box => $label) {
3654
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3654
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3655 3655
             $msgr          = str_replace('_a_box', '', $box);
3656 3656
             add_meta_box(
3657
-                'espresso_' . $msgr . '_settings',
3657
+                'espresso_'.$msgr.'_settings',
3658 3658
                 $label,
3659
-                function ($post, $metabox) {
3659
+                function($post, $metabox) {
3660 3660
                     EEH_Template::display_template(
3661 3661
                         $metabox['args']['template_path'],
3662 3662
                         $metabox['args']['template_args']
@@ -3670,17 +3670,17 @@  discard block
 block discarded – undo
3670 3670
         }
3671 3671
 
3672 3672
         // register message type metaboxes
3673
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3673
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3674 3674
         foreach ($mt_boxes as $box => $label) {
3675 3675
             $callback_args = [
3676 3676
                 'template_path' => $mt_template_path,
3677
-                'template_args' => $mt_template_args[ $box ],
3677
+                'template_args' => $mt_template_args[$box],
3678 3678
             ];
3679
-            $mt            = str_replace('_i_box', '', $box);
3679
+            $mt = str_replace('_i_box', '', $box);
3680 3680
             add_meta_box(
3681
-                'espresso_' . $mt . '_inactive_mts',
3681
+                'espresso_'.$mt.'_inactive_mts',
3682 3682
                 $label,
3683
-                function ($post, $metabox) {
3683
+                function($post, $metabox) {
3684 3684
                     EEH_Template::display_template(
3685 3685
                         $metabox['args']['template_path'],
3686 3686
                         $metabox['args']['template_args']
@@ -3827,7 +3827,7 @@  discard block
 block discarded – undo
3827 3827
             if ($form->is_valid()) {
3828 3828
                 $valid_data = $form->valid_data();
3829 3829
                 foreach ($valid_data as $property => $value) {
3830
-                    $setter = 'set_' . $property;
3830
+                    $setter = 'set_'.$property;
3831 3831
                     if (method_exists($network_config, $setter)) {
3832 3832
                         $network_config->{$setter}($value);
3833 3833
                     } elseif (
@@ -3863,7 +3863,7 @@  discard block
 block discarded – undo
3863 3863
     protected function _get_mt_tabs($tab_array)
3864 3864
     {
3865 3865
         $tab_array = (array) $tab_array;
3866
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3867 3867
         $tabs      = '';
3868 3868
 
3869 3869
         foreach ($tab_array as $tab) {
@@ -3891,20 +3891,20 @@  discard block
 block discarded – undo
3891 3891
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3892 3892
 
3893 3893
 
3894
-        if (! empty($fields)) {
3894
+        if ( ! empty($fields)) {
3895 3895
             $existing_settings = $messenger->get_existing_admin_settings();
3896 3896
 
3897 3897
             foreach ($fields as $fldname => $fldprops) {
3898
-                $field_id                         = $messenger->name . '-' . $fldname;
3899
-                $template_form_field[ $field_id ] = [
3900
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3898
+                $field_id                         = $messenger->name.'-'.$fldname;
3899
+                $template_form_field[$field_id] = [
3900
+                    'name'       => 'messenger_settings['.$field_id.']',
3901 3901
                     'label'      => $fldprops['label'],
3902 3902
                     'input'      => $fldprops['field_type'],
3903 3903
                     'type'       => $fldprops['value_type'],
3904 3904
                     'required'   => $fldprops['required'],
3905 3905
                     'validation' => $fldprops['validation'],
3906
-                    'value'      => isset($existing_settings[ $field_id ])
3907
-                        ? $existing_settings[ $field_id ]
3906
+                    'value'      => isset($existing_settings[$field_id])
3907
+                        ? $existing_settings[$field_id]
3908 3908
                         : $fldprops['default'],
3909 3909
                     'css_class'  => '',
3910 3910
                     'format'     => $fldprops['format'],
@@ -3919,20 +3919,20 @@  discard block
 block discarded – undo
3919 3919
 
3920 3920
         // we also need some hidden fields
3921 3921
         $settings_template_args['hidden_fields'] = [
3922
-            'messenger_settings[messenger]' . $messenger->name => [
3922
+            'messenger_settings[messenger]'.$messenger->name => [
3923 3923
                 'type'  => 'hidden',
3924 3924
                 'value' => $messenger->name,
3925 3925
             ],
3926
-            'type' . $messenger->name                          => [
3926
+            'type'.$messenger->name                          => [
3927 3927
                 'type'  => 'hidden',
3928 3928
                 'value' => 'messenger',
3929 3929
             ],
3930 3930
         ];
3931 3931
 
3932 3932
         // make sure any active message types that are existing are included in the hidden fields
3933
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3934
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3935
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3933
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3934
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3935
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3936 3936
                     'type'  => 'hidden',
3937 3937
                     'value' => $mt,
3938 3938
                 ];
@@ -3942,7 +3942,7 @@  discard block
 block discarded – undo
3942 3942
             $settings_template_args['hidden_fields'],
3943 3943
             'array'
3944 3944
         );
3945
-        $active                                  =
3945
+        $active =
3946 3946
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3947 3947
 
3948 3948
         $settings_template_args['messenger']           = $messenger->name;
@@ -3962,9 +3962,9 @@  discard block
 block discarded – undo
3962 3962
 
3963 3963
 
3964 3964
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3965
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3966 3966
         $settings_template_args['on_off_status'] = $active;
3967
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3968 3968
         return EEH_Template::display_template(
3969 3969
             $template,
3970 3970
             $settings_template_args,
@@ -3989,7 +3989,7 @@  discard block
 block discarded – undo
3989 3989
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3990 3990
         // let's check that we have required data
3991 3991
 
3992
-        if (! $this->_active_messenger_name) {
3992
+        if ( ! $this->_active_messenger_name) {
3993 3993
             EE_Error::add_error(
3994 3994
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3995 3995
                 __FILE__,
@@ -4007,7 +4007,7 @@  discard block
 block discarded – undo
4007 4007
 
4008 4008
 
4009 4009
         $status = $this->request->getRequestParam('status');
4010
-        if (! $status) {
4010
+        if ( ! $status) {
4011 4011
             EE_Error::add_error(
4012 4012
                 esc_html__(
4013 4013
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4064,7 +4064,7 @@  discard block
 block discarded – undo
4064 4064
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4065 4065
 
4066 4066
         // let's make sure we have the necessary data
4067
-        if (! $this->_active_message_type_name) {
4067
+        if ( ! $this->_active_message_type_name) {
4068 4068
             EE_Error::add_error(
4069 4069
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4070 4070
                 __FILE__,
@@ -4074,7 +4074,7 @@  discard block
 block discarded – undo
4074 4074
             $success = false;
4075 4075
         }
4076 4076
 
4077
-        if (! $this->_active_messenger_name) {
4077
+        if ( ! $this->_active_messenger_name) {
4078 4078
             EE_Error::add_error(
4079 4079
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4080 4080
                 __FILE__,
@@ -4085,7 +4085,7 @@  discard block
 block discarded – undo
4085 4085
         }
4086 4086
 
4087 4087
         $status = $this->request->getRequestParam('status');
4088
-        if (! $status) {
4088
+        if ( ! $status) {
4089 4089
             EE_Error::add_error(
4090 4090
                 esc_html__(
4091 4091
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4297,7 +4297,7 @@  discard block
 block discarded – undo
4297 4297
         EE_Message_Type $message_type = null
4298 4298
     ) {
4299 4299
         // if $messenger isn't a valid messenger object then get out.
4300
-        if (! $messenger instanceof EE_Messenger) {
4300
+        if ( ! $messenger instanceof EE_Messenger) {
4301 4301
             EE_Error::add_error(
4302 4302
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4303 4303
                 __FILE__,
@@ -4351,7 +4351,7 @@  discard block
 block discarded – undo
4351 4351
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4352 4352
             // in which case we just give a success message for the messenger being successfully activated.
4353 4353
         } else {
4354
-            if (! $messenger->get_default_message_types()) {
4354
+            if ( ! $messenger->get_default_message_types()) {
4355 4355
                 // messenger doesn't have any default message types so still a success.
4356 4356
                 EE_Error::add_success(
4357 4357
                     sprintf(
@@ -4407,7 +4407,7 @@  discard block
 block discarded – undo
4407 4407
         EE_Error::overwrite_success();
4408 4408
 
4409 4409
         // if $messenger isn't a valid messenger object then get out.
4410
-        if (! $messenger instanceof EE_Messenger) {
4410
+        if ( ! $messenger instanceof EE_Messenger) {
4411 4411
             EE_Error::add_error(
4412 4412
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4413 4413
                 __FILE__,
@@ -4477,7 +4477,7 @@  discard block
 block discarded – undo
4477 4477
      */
4478 4478
     public function update_mt_form()
4479 4479
     {
4480
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4481 4481
             EE_Error::add_error(
4482 4482
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4483 4483
                 __FILE__,
@@ -4488,7 +4488,7 @@  discard block
 block discarded – undo
4488 4488
         }
4489 4489
 
4490 4490
         $message_types = $this->get_installed_message_types();
4491
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4491
+        $message_type  = $message_types[$this->_active_message_type_name];
4492 4492
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4493 4493
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4494 4494
 
@@ -4507,7 +4507,7 @@  discard block
 block discarded – undo
4507 4507
     public function save_settings()
4508 4508
     {
4509 4509
         $type = $this->request->getRequestParam('type');
4510
-        if (! $type) {
4510
+        if ( ! $type) {
4511 4511
             EE_Error::add_error(
4512 4512
                 esc_html__(
4513 4513
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_settings_messengers.help_tab.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,79 +3,79 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <?php esc_html_e(
12
-        'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
-        'event_espresso'
14
-    ); ?>
12
+		'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
+		'event_espresso'
14
+	); ?>
15 15
 </p>
16 16
 <p>
17 17
     <?php printf(
18
-        esc_html__(
19
-            'The green colored gear %s indicates that this messenger is currently active.',
20
-            'event_espresso'
21
-        ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
-    );
25
-    printf(
26
-        esc_html__(
27
-            ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
-            'event_espresso'
29
-        ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
-    ); ?>
18
+		esc_html__(
19
+			'The green colored gear %s indicates that this messenger is currently active.',
20
+			'event_espresso'
21
+		),
22
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
+		. ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
+	);
25
+	printf(
26
+		esc_html__(
27
+			' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
+			'event_espresso'
29
+		),
30
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
+		. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
+	); ?>
33 33
 </p>
34 34
 <p>
35 35
     <?php esc_html_e(
36
-        'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
-        'event_espresso'
38
-    ); ?>
36
+		'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
+		'event_espresso'
38
+	); ?>
39 39
 </p>
40 40
 <p>
41 41
     <?php printf(
42
-        esc_html__(
43
-            '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
-            'event_espresso'
45
-        ),
46
-        '<div class="switch">'
47
-        . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked disabled>'
48
-        . '<label for="ee-on-off-toggle-on"></label>'
49
-        . '</div>',
50
-        '<div class="switch">'
51
-        . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
-        . '<label for="ee-on-off-toggle-on"></label>'
53
-        . '</div>'
54
-    ); ?>
42
+		esc_html__(
43
+			'%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
+			'event_espresso'
45
+		),
46
+		'<div class="switch">'
47
+		. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked disabled>'
48
+		. '<label for="ee-on-off-toggle-on"></label>'
49
+		. '</div>',
50
+		'<div class="switch">'
51
+		. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
+		. '<label for="ee-on-off-toggle-on"></label>'
53
+		. '</div>'
54
+	); ?>
55 55
 </p>
56 56
 <p>
57 57
     <?php
58
-    esc_html_e(
59
-        'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
-        'event_espresso'
61
-    ); ?>
58
+	esc_html_e(
59
+		'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
+		'event_espresso'
61
+	); ?>
62 62
 </p>
63 63
 <p>
64 64
     <?php esc_html_e(
65
-        'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <?php esc_html_e(
71
-        'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
-        'event_espresso'
73
-    ); ?>
71
+		'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
+		'event_espresso'
73
+	); ?>
74 74
 </p>
75 75
 <p>
76 76
     <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br />
77 77
     <?php esc_html_e(
78
-        'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
-        'event_espresso'
80
-    ); ?>
78
+		'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
+		'event_espresso'
80
+	); ?>
81 81
 </p>
Please login to merge, or discard this patch.