Completed
Branch dev (d8d615)
by
unknown
04:34 queued 02:19
created
registration_form/templates/questions_main_meta_box.template.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -26,21 +26,21 @@  discard block
 block discarded – undo
26 26
 $has_answers = $question->has_answers();
27 27
 
28 28
 if ($QST_system === 'country') {
29
-    // already escaped
30
-    echo EEH_HTML::div(
31
-        EEH_HTML::h4(
32
-            '<span class="dashicons dashicons-info"></span>'
33
-            . esc_html__('Did you know...', 'event_espresso')
34
-        ) .
35
-        EEH_HTML::p(
36
-            esc_html__(
37
-                '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.',
38
-                'event_espresso'
39
-            )
40
-        ),
41
-        '',
42
-        'ee-info-box'
43
-    );
29
+	// already escaped
30
+	echo EEH_HTML::div(
31
+		EEH_HTML::h4(
32
+			'<span class="dashicons dashicons-info"></span>'
33
+			. esc_html__('Did you know...', 'event_espresso')
34
+		) .
35
+		EEH_HTML::p(
36
+			esc_html__(
37
+				'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.',
38
+				'event_espresso'
39
+			)
40
+		),
41
+		'',
42
+		'ee-info-box'
43
+	);
44 44
 }
45 45
 ?>
46 46
 
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
                     </th>
77 77
                     <td>
78 78
                         <?php
79
-                        $id            = ! empty($QST_system) ? '_disabled' : '';
80
-                        $disabled_attr = ! empty($QST_system) ? 'disabled' : '';
81
-                        ?>
79
+						$id            = ! empty($QST_system) ? '_disabled' : '';
80
+						$disabled_attr = ! empty($QST_system) ? 'disabled' : '';
81
+						?>
82 82
                         <input class='regular-text'
83 83
                                id="QST_admin_label<?php echo absint($id); ?>"
84 84
                                name="QST_admin_label<?php echo absint($id); ?>"
@@ -120,30 +120,30 @@  discard block
 block discarded – undo
120 120
                     </th>
121 121
                     <td>
122 122
                         <?php
123
-                        $id            = ! empty($QST_system) ? '_disabled' : '';
124
-                        $disabled_attr = ! empty($QST_system) ? 'disabled' : '';
125
-                        $admin_only    = $question->get('QST_admin_only');
126
-                        $checked       = ! empty($admin_only) ? ' checked' : '';
127
-                        ?>
123
+						$id            = ! empty($QST_system) ? '_disabled' : '';
124
+						$disabled_attr = ! empty($QST_system) ? 'disabled' : '';
125
+						$admin_only    = $question->get('QST_admin_only');
126
+						$checked       = ! empty($admin_only) ? ' checked' : '';
127
+						?>
128 128
                         <input class="QST_admin_only"
129 129
                                id="QST_admin_only<?php echo absint($id); ?>"
130 130
                                name="QST_admin_only<?php echo absint($id); ?>"
131 131
                                type="checkbox"
132 132
                                value="1"
133 133
                             <?php
134
-                            echo esc_attr($disabled_attr);
135
-                            echo esc_attr($checked);
136
-                            ?>
134
+							echo esc_attr($disabled_attr);
135
+							echo esc_attr($checked);
136
+							?>
137 137
                         />
138 138
                         <br />
139 139
                         <p class="description">
140 140
                             <?php
141
-                            if (! empty($QST_system)) { ?>
141
+							if (! empty($QST_system)) { ?>
142 142
                                 <span class="description" style="color:#D54E21;">
143 143
                                     <?php esc_html_e(
144
-                                        'System question! This field cannot be changed.',
145
-                                        'event_espresso'
146
-                                    ); ?>
144
+										'System question! This field cannot be changed.',
145
+										'event_espresso'
146
+									); ?>
147 147
                                 </span>
148 148
                             <?php } ?>
149 149
                         </p>
@@ -159,44 +159,44 @@  discard block
 block discarded – undo
159 159
                     </th>
160 160
                     <td>
161 161
                         <?php
162
-                        $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone;
163
-                        if ($disabled) {
164
-                            $disabled_attr = 'disabled="disabled"';
165
-                            $id            = '_disabled';
166
-                        } else {
167
-                            $disabled_attr = '';
168
-                            $id            = '';
169
-                        }
162
+						$disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone;
163
+						if ($disabled) {
164
+							$disabled_attr = 'disabled="disabled"';
165
+							$id            = '_disabled';
166
+						} else {
167
+							$disabled_attr = '';
168
+							$id            = '';
169
+						}
170 170
 
171
-                        // Only display Confirm email for
172
-                        if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) {
173
-                            unset($question_types[ EEM_Question::QST_type_email_confirm ]);
174
-                        }
171
+						// Only display Confirm email for
172
+						if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) {
173
+							unset($question_types[ EEM_Question::QST_type_email_confirm ]);
174
+						}
175 175
 
176
-                        echo EEH_Form_Fields::select_input(
177
-                            'QST_type' . $id,
178
-                            $question_types,
179
-                            $question->type(),
180
-                            'id="QST_type' . $id . '"' . $disabled_attr
181
-                        ); // already escaped
182
-                        if ($disabled) { ?>
176
+						echo EEH_Form_Fields::select_input(
177
+							'QST_type' . $id,
178
+							$question_types,
179
+							$question->type(),
180
+							'id="QST_type' . $id . '"' . $disabled_attr
181
+						); // already escaped
182
+						if ($disabled) { ?>
183 183
                             <input id='QST_type'
184 184
                                    name="QST_type"
185 185
                                    type="hidden"
186 186
                                    value="<?php echo esc_attr($question->type()); ?>"
187 187
                             />
188 188
                             <?php
189
-                            $explanatory_text = esc_html__(
190
-                                'System question! This field cannot be changed.',
191
-                                'event_espresso'
192
-                            );
193
-                        } else {
194
-                            $explanatory_text = esc_html__(
195
-                                'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.',
196
-                                'event_espresso'
197
-                            );
198
-                        }
199
-                        if ($disabled || $has_answers) { ?>
189
+							$explanatory_text = esc_html__(
190
+								'System question! This field cannot be changed.',
191
+								'event_espresso'
192
+							);
193
+						} else {
194
+							$explanatory_text = esc_html__(
195
+								'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.',
196
+								'event_espresso'
197
+							);
198
+						}
199
+						if ($disabled || $has_answers) { ?>
200 200
                             <p>
201 201
                                 <span class="description" style="color:#D54E21;">
202 202
                                     <?php echo esc_html($explanatory_text); ?>
@@ -225,21 +225,21 @@  discard block
 block discarded – undo
225 225
                         <p>
226 226
                             <span class="description">
227 227
                                 <?php esc_html_e(
228
-                                    'Maximum number of characters allowed when answering this question',
229
-                                    'event_espresso'
230
-                                ); ?>
228
+									'Maximum number of characters allowed when answering this question',
229
+									'event_espresso'
230
+								); ?>
231 231
                             </span>
232 232
                         </p>
233 233
                         <?php if ($QST_system) { ?>
234 234
                         <p>
235 235
                             <span class="description" style="color:#D54E21;">
236 236
                                 <?php printf(
237
-                                    esc_html__(
238
-                                        'System question! The maximum number of characters that can be used for this question is %1$s',
239
-                                        'event_espresso'
240
-                                    ),
241
-                                    $max_max
242
-                                ); ?>
237
+									esc_html__(
238
+										'System question! The maximum number of characters that can be used for this question is %1$s',
239
+										'event_espresso'
240
+									),
241
+									$max_max
242
+								); ?>
243 243
                             </span>
244 244
                         </p>
245 245
                         <?php } ?>
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
                                     </th>
262 262
                                     <th class="option-desc-header">
263 263
                                         <?php esc_html_e(
264
-                                            'Description (optional, only shown on registration form)',
265
-                                            'event_espresso'
266
-                                        ) ?>
264
+											'Description (optional, only shown on registration form)',
265
+											'event_espresso'
266
+										) ?>
267 267
                                     </th>
268 268
                                     <th>
269 269
                                     </th>
@@ -298,14 +298,14 @@  discard block
 block discarded – undo
298 298
                                 </tr>
299 299
 
300 300
                                 <?php
301
-                                $count            = 0;
302
-                                $question_options = $question->options();
303
-                                if (! empty($question_options)) {
304
-                                    foreach ($question_options as $option_id => $option) {
305
-                                        $disabled_attr = $has_answers || $option->get('QSO_system')
306
-                                            ? 'disabled'
307
-                                            : '';
308
-                                        ?>
301
+								$count            = 0;
302
+								$question_options = $question->options();
303
+								if (! empty($question_options)) {
304
+									foreach ($question_options as $option_id => $option) {
305
+										$disabled_attr = $has_answers || $option->get('QSO_system')
306
+											? 'disabled'
307
+											: '';
308
+										?>
309 309
                                         <tr class="question-option ee-options-sortable">
310 310
                                             <td class="option-value-cell">
311 311
                                                 <input type="hidden"
@@ -342,21 +342,21 @@  discard block
 block discarded – undo
342 342
                                     </span>
343 343
                                             </td>
344 344
                                             <?php
345
-                                            echo EEH_Form_Fields::hidden_input(
346
-                                                "question_options[{$count}][QST_ID])",
347
-                                                $option->question_ID()
348
-                                            ); // already escaped
349
-                                            echo EEH_Form_Fields::hidden_input(
350
-                                                "question_options[{$count}][QSO_ID])",
351
-                                                $option->ID()
352
-                                            ); // already escaped
353
-                                            $count++;
354
-                                            ?>
345
+											echo EEH_Form_Fields::hidden_input(
346
+												"question_options[{$count}][QST_ID])",
347
+												$option->question_ID()
348
+											); // already escaped
349
+											echo EEH_Form_Fields::hidden_input(
350
+												"question_options[{$count}][QSO_ID])",
351
+												$option->ID()
352
+											); // already escaped
353
+											$count++;
354
+											?>
355 355
                                         </tr>
356 356
                                         <?php
357
-                                    }
358
-                                } else {
359
-                                    ?>
357
+									}
358
+								} else {
359
+									?>
360 360
                                     <tr class="question-option ee-options-sortable">
361 361
                                         <td class="option-value-cell">
362 362
                                             <input type="hidden"
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
                                         </td>
381 381
                                     </tr>
382 382
                                     <?php
383
-                                }
384
-                                ?>
383
+								}
384
+								?>
385 385
                                 <tr style="display:none">
386 386
                                     <td colspan="3">
387 387
                                         <?php echo EEH_Form_Fields::hidden_input("question_options_count", $count); // already escaped ?>
@@ -400,16 +400,16 @@  discard block
 block discarded – undo
400 400
 
401 401
                         <p class="description">
402 402
                             <?php esc_html_e(
403
-                                'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.',
404
-                                'event_espresso'
405
-                            ) ?>
403
+								'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.',
404
+								'event_espresso'
405
+							) ?>
406 406
                         </p>
407 407
                         <?php if ($has_answers) : ?>
408 408
                             <p class="description" style="color:#D54E21;">
409 409
                                 <?php esc_html_e(
410
-                                    'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question.  If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes.  This will ensure that the existing registrations that chose the original answer will preserve that answer.',
411
-                                    'event_espresso'
412
-                                ); ?>
410
+									'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question.  If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes.  This will ensure that the existing registrations that chose the original answer will preserve that answer.',
411
+									'event_espresso'
412
+								); ?>
413 413
                             </p>
414 414
 
415 415
                         <?php endif; ?>
@@ -425,40 +425,40 @@  discard block
 block discarded – undo
425 425
                     </th>
426 426
                     <td>
427 427
                         <?php
428
-                        $system_required   = ['fname', 'email'];
429
-                        $disabled_attr     = in_array($QST_system, $system_required) ? ' disabled="disabled"' : '';
430
-                        $required_on       = $question->get('QST_admin_only');
431
-                        $show_required_msg = $required_on ? '' : ' display:none;';
432
-                        $disabled_attr     = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : '';
433
-                        $id                =
434
-                            ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : '';
435
-                        $requiredOptions   = [
436
-                            ['text' => esc_html__('Optional', 'event_espresso'), 'id' => 0],
437
-                            ['text' => esc_html__('Required', 'event_espresso'), 'id' => 1],
438
-                        ];
439
-                        echo EEH_Form_Fields::select_input(
440
-                            'QST_required' . $id,
441
-                            $requiredOptions,
442
-                            $question->required(),
443
-                            'id="QST_required' . $id . '"' . $disabled_attr
444
-                        ); // already escaped
445
-                        ?>
428
+						$system_required   = ['fname', 'email'];
429
+						$disabled_attr     = in_array($QST_system, $system_required) ? ' disabled="disabled"' : '';
430
+						$required_on       = $question->get('QST_admin_only');
431
+						$show_required_msg = $required_on ? '' : ' display:none;';
432
+						$disabled_attr     = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : '';
433
+						$id                =
434
+							! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : '';
435
+						$requiredOptions   = [
436
+							['text' => esc_html__('Optional', 'event_espresso'), 'id' => 0],
437
+							['text' => esc_html__('Required', 'event_espresso'), 'id' => 1],
438
+						];
439
+						echo EEH_Form_Fields::select_input(
440
+							'QST_required' . $id,
441
+							$requiredOptions,
442
+							$question->required(),
443
+							'id="QST_required' . $id . '"' . $disabled_attr
444
+						); // already escaped
445
+						?>
446 446
                         <p>
447 447
                             <span id="required_toggled_on" class="description"
448 448
                                   style="color:#D54E21;<?php echo esc_attr($show_required_msg); ?>"
449 449
                             >
450 450
                                 <?php esc_html_e(
451
-                                    'Required is set to optional, and this field is disabled, because the question is Admin-Only.',
452
-                                    'event_espresso'
453
-                                ) ?>
451
+									'Required is set to optional, and this field is disabled, because the question is Admin-Only.',
452
+									'event_espresso'
453
+								) ?>
454 454
                             </span
455 455
                         </p>
456 456
                         <p>
457 457
                             <span id="required_toggled_off" class="description" style="color:#D54E21; display: none;">
458 458
                                 <?php esc_html_e(
459
-                                    'Required option field is no longer disabled because the question is not Admin-Only',
460
-                                    'event_espresso'
461
-                                ) ?>
459
+									'Required option field is no longer disabled because the question is not Admin-Only',
460
+									'event_espresso'
461
+								) ?>
462 462
                             </span>
463 463
                         </p>
464 464
                         <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
@@ -491,8 +491,8 @@  discard block
 block discarded – undo
491 491
                     </td>
492 492
                 </tr>
493 493
                 <?php
494
-                do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question);
495
-                ?>
494
+				do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question);
495
+				?>
496 496
             </tbody>
497 497
         </table>
498 498
 
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         EEH_HTML::h4(
32 32
             '<span class="dashicons dashicons-info"></span>'
33 33
             . esc_html__('Did you know...', 'event_espresso')
34
-        ) .
34
+        ).
35 35
         EEH_HTML::p(
36 36
             esc_html__(
37 37
                 '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.',
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                                type="hidden"
93 93
                                value="<?php echo esc_attr($question->get('QST_order')); ?>"
94 94
                         />
95
-                        <?php if (! empty($QST_system)) { ?>
95
+                        <?php if ( ! empty($QST_system)) { ?>
96 96
                             <input id='QST_admin_label'
97 97
                                    name="QST_admin_label"
98 98
                                    type="hidden"
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
                         <?php } ?>
102 102
                         <br />
103 103
                         <p class="description">
104
-                            <?php if (! empty($QST_system)) { ?>
104
+                            <?php if ( ! empty($QST_system)) { ?>
105 105
                                 <span class="description" style="color:#D54E21;">
106 106
                                 <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?>
107 107
                         </span>
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                         <br />
139 139
                         <p class="description">
140 140
                             <?php
141
-                            if (! empty($QST_system)) { ?>
141
+                            if ( ! empty($QST_system)) { ?>
142 142
                                 <span class="description" style="color:#D54E21;">
143 143
                                     <?php esc_html_e(
144 144
                                         'System question! This field cannot be changed.',
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
 
171 171
                         // Only display Confirm email for
172 172
                         if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) {
173
-                            unset($question_types[ EEM_Question::QST_type_email_confirm ]);
173
+                            unset($question_types[EEM_Question::QST_type_email_confirm]);
174 174
                         }
175 175
 
176 176
                         echo EEH_Form_Fields::select_input(
177
-                            'QST_type' . $id,
177
+                            'QST_type'.$id,
178 178
                             $question_types,
179 179
                             $question->type(),
180
-                            'id="QST_type' . $id . '"' . $disabled_attr
180
+                            'id="QST_type'.$id.'"'.$disabled_attr
181 181
                         ); // already escaped
182 182
                         if ($disabled) { ?>
183 183
                             <input id='QST_type'
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
                     </th>
217 217
                     <td>
218 218
                         <input id="QST_max"
219
-                            <?php echo $max_max === EE_INF ? '' : 'max="' . esc_attr($max_max) . '"'; ?>
219
+                            <?php echo $max_max === EE_INF ? '' : 'max="'.esc_attr($max_max).'"'; ?>
220 220
                                min="1"
221 221
                                name="QST_max"
222 222
                                type="number"
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
                                 <?php
301 301
                                 $count            = 0;
302 302
                                 $question_options = $question->options();
303
-                                if (! empty($question_options)) {
303
+                                if ( ! empty($question_options)) {
304 304
                                     foreach ($question_options as $option_id => $option) {
305 305
                                         $disabled_attr = $has_answers || $option->get('QSO_system')
306 306
                                             ? 'disabled'
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
                                                 />
335 335
                                             </td>
336 336
                                             <td>
337
-                                                <?php if (! $option->system()) { ?>
337
+                                                <?php if ( ! $option->system()) { ?>
338 338
                                                     <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item">
339 339
                                         </span>
340 340
                                                 <?php } ?>
@@ -437,10 +437,10 @@  discard block
 block discarded – undo
437 437
                             ['text' => esc_html__('Required', 'event_espresso'), 'id' => 1],
438 438
                         ];
439 439
                         echo EEH_Form_Fields::select_input(
440
-                            'QST_required' . $id,
440
+                            'QST_required'.$id,
441 441
                             $requiredOptions,
442 442
                             $question->required(),
443
-                            'id="QST_required' . $id . '"' . $disabled_attr
443
+                            'id="QST_required'.$id.'"'.$disabled_attr
444 444
                         ); // already escaped
445 445
                         ?>
446 446
                         <p>
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
                                 ) ?>
462 462
                             </span>
463 463
                         </p>
464
-                        <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
464
+                        <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
465 465
                             <input type="hidden" id="QST_required" name="QST_required" value="1" />
466 466
                             <p>
467 467
                             <span class="description" style="color:#D54E21;">
Please login to merge, or discard this patch.
admin_pages/venues/templates/google_map.template.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@  discard block
 block discarded – undo
16 16
                 </th>
17 17
                 <td>
18 18
                     <?php echo EEH_Form_Fields::select_input(
19
-                        'use_google_maps',
20
-                        $values,
21
-                        $map_settings->use_google_maps,
22
-                        'id="ee-display-map-no-shortcodes"'
23
-                    ); ?>
19
+						'use_google_maps',
20
+						$values,
21
+						$map_settings->use_google_maps,
22
+						'id="ee-display-map-no-shortcodes"'
23
+					); ?>
24 24
                     <p class="description">
25 25
                         <?php esc_html_e(
26
-                            'Turn Google maps on or off site wide for Event Espresso.',
27
-                            'event_espresso'
28
-                        ); ?>
26
+							'Turn Google maps on or off site wide for Event Espresso.',
27
+							'event_espresso'
28
+						); ?>
29 29
                     </p>
30 30
                 </td>
31 31
             </tr>
32 32
             <?php
33
-            if (apply_filters('FHEE__google_map__show_api_key_input', true)) { ?>
33
+			if (apply_filters('FHEE__google_map__show_api_key_input', true)) { ?>
34 34
                 <tr>
35 35
                     <th>
36 36
                         <label for="ee-google-map-api-key">
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
                         />
47 47
                         <p class="description">
48 48
                             <?php printf(
49
-                                esc_html__(
50
-                                    'An API key is now required to use the Google Maps API: %1$sclick here to get an API key%2$s',
51
-                                    'event_espresso'
52
-                                ),
53
-                                '<a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,static_maps_backend&keyType=CLIENT_SIDE&reusekey=true" target="_blank" rel="noopener noreferrer">',
54
-                                '</a>'
55
-                            );
56
-                            ?>
49
+								esc_html__(
50
+									'An API key is now required to use the Google Maps API: %1$sclick here to get an API key%2$s',
51
+									'event_espresso'
52
+								),
53
+								'<a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,static_maps_backend&keyType=CLIENT_SIDE&reusekey=true" target="_blank" rel="noopener noreferrer">',
54
+								'</a>'
55
+							);
56
+							?>
57 57
                         </p>
58 58
                     </td>
59 59
                 </tr>
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
                 </th>
126 126
                 <td>
127 127
                     <?php echo EEH_Form_Fields::select_input(
128
-                        'event_details_display_nav',
129
-                        $values,
130
-                        $map_settings->event_details_display_nav,
131
-                        'id="event_details_display_nav" '
132
-                    ); ?>
128
+						'event_details_display_nav',
129
+						$values,
130
+						$map_settings->event_details_display_nav,
131
+						'id="event_details_display_nav" '
132
+					); ?>
133 133
                 </td>
134 134
             </tr>
135 135
 
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
                 </th>
142 142
                 <td>
143 143
                     <?php echo EEH_Form_Fields::select_input(
144
-                        'event_details_nav_size',
145
-                        $values,
146
-                        $map_settings->event_details_nav_size,
147
-                        'id="event_details_nav_size"'
148
-                    ); ?>
144
+						'event_details_nav_size',
145
+						$values,
146
+						$map_settings->event_details_nav_size,
147
+						'id="event_details_nav_size"'
148
+					); ?>
149 149
                 </td>
150 150
             </tr>
151 151
 
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
                 <td>
157 157
                     <label for="event_details_control_type-default" class="ee-admin-radio-lbl">
158 158
                         <?php $checked = $map_settings->event_details_control_type == 'default'
159
-                            ? 'checked'
160
-                            : ''; ?>
159
+							? 'checked'
160
+							: ''; ?>
161 161
                         <input id="event_details_control_type-default"
162 162
                                type="radio"
163 163
                                name="event_details_control_type"
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 
170 170
                     <label for="event_details_control_type-horizontal" class="ee-admin-radio-lbl">
171 171
                         <?php $checked = $map_settings->event_details_control_type == 'horizontal'
172
-                            ? 'checked'
173
-                            : ''; ?>
172
+							? 'checked'
173
+							: ''; ?>
174 174
                         <input id="event_details_control_type-horizontal"
175 175
                                type="radio"
176 176
                                name="event_details_control_type"
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 
183 183
                     <label for="event_details_control_type-dropdown" class="ee-admin-radio-lbl">
184 184
                         <?php $checked = $map_settings->event_details_control_type == 'dropdown'
185
-                            ? 'checked'
186
-                            : ''; ?>
185
+							? 'checked'
186
+							: ''; ?>
187 187
                         <input id="event_details_control_type-dropdown"
188 188
                                type="radio"
189 189
                                name="event_details_control_type"
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
                 <td>
202 202
                     <label for="event_details_map_align-none" class="ee-admin-radio-lbl">
203 203
                         <?php $checked = $map_settings->event_details_map_align == 'none'
204
-                            ? 'checked'
205
-                            : ''; ?>
204
+							? 'checked'
205
+							: ''; ?>
206 206
                         <input id="event_details_map_align-none"
207 207
                                type="radio"
208 208
                                name="event_details_map_align"
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 
215 215
                     <label for="event_details_map_align-left" class="ee-admin-radio-lbl">
216 216
                         <?php $checked = $map_settings->event_details_map_align == 'left'
217
-                            ? 'checked'
218
-                            : ''; ?>
217
+							? 'checked'
218
+							: ''; ?>
219 219
                         <input id="event_details_map_align-left"
220 220
                                type="radio"
221 221
                                name="event_details_map_align"
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 
228 228
                     <label for="event_details_map_align-center" class="ee-admin-radio-lbl">
229 229
                         <?php $checked = $map_settings->event_details_map_align == 'center'
230
-                            ? 'checked'
231
-                            : ''; ?>
230
+							? 'checked'
231
+							: ''; ?>
232 232
                         <input id="event_details_map_align-center"
233 233
                                type="radio"
234 234
                                name="event_details_map_align"
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 
241 241
                     <label for="event_details_map_align-right" class="ee-admin-radio-lbl">
242 242
                         <?php $checked = $map_settings->event_details_map_align == 'right'
243
-                            ? 'checked'
244
-                            : ''; ?>
243
+							? 'checked'
244
+							: ''; ?>
245 245
                         <input id="event_details_map_align-right"
246 246
                                type="radio"
247 247
                                name="event_details_map_align"
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
                 </th>
318 318
                 <td>
319 319
                     <?php echo EEH_Form_Fields::select_input(
320
-                        'event_list_display_nav',
321
-                        $values,
322
-                        $map_settings->event_list_display_nav,
323
-                        'id="event_list_display_nav"'
324
-                    ); ?>
320
+						'event_list_display_nav',
321
+						$values,
322
+						$map_settings->event_list_display_nav,
323
+						'id="event_list_display_nav"'
324
+					); ?>
325 325
                 </td>
326 326
             </tr>
327 327
 
@@ -333,11 +333,11 @@  discard block
 block discarded – undo
333 333
                 </th>
334 334
                 <td>
335 335
                     <?php echo EEH_Form_Fields::select_input(
336
-                        'event_list_nav_size',
337
-                        $values,
338
-                        $map_settings->event_list_nav_size,
339
-                        'id="event_list_nav_size"'
340
-                    ); ?>
336
+						'event_list_nav_size',
337
+						$values,
338
+						$map_settings->event_list_nav_size,
339
+						'id="event_list_nav_size"'
340
+					); ?>
341 341
                 </td>
342 342
             </tr>
343 343
 
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
                 <td>
349 349
                     <label for="event_list_control_type-default" class="ee-admin-radio-lbl">
350 350
                         <?php $checked = $map_settings->event_list_control_type == 'default'
351
-                            ? 'checked'
352
-                            : ''; ?>
351
+							? 'checked'
352
+							: ''; ?>
353 353
                         <input id="event_list_control_type-default"
354 354
                                type="radio"
355 355
                                name="event_list_control_type"
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 
362 362
                     <label for="event_list_control_type-horizontal" class="ee-admin-radio-lbl">
363 363
                         <?php $checked = $map_settings->event_list_control_type == 'horizontal'
364
-                            ? 'checked'
365
-                            : ''; ?>
364
+							? 'checked'
365
+							: ''; ?>
366 366
                         <input id="event_list_control_type-horizontal"
367 367
                                type="radio"
368 368
                                name="event_list_control_type"
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
 
375 375
                     <label for="event_list_control_type-dropdown" class="ee-admin-radio-lbl">
376 376
                         <?php $checked =
377
-                            $map_settings->event_list_control_type == 'dropdown'
378
-                                ? 'checked'
379
-                                : ''; ?>
377
+							$map_settings->event_list_control_type == 'dropdown'
378
+								? 'checked'
379
+								: ''; ?>
380 380
                         <input id="event_list_control_type-dropdown"
381 381
                                type="radio"
382 382
                                name="event_list_control_type"
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
                 <td>
397 397
                     <label for="event_list_map_align-none" class="ee-admin-radio-lbl">
398 398
                         <?php $checked = $map_settings->event_list_map_align == 'none'
399
-                            ? 'checked'
400
-                            : ''; ?>
399
+							? 'checked'
400
+							: ''; ?>
401 401
                         <input id="event_list_map_align-none"
402 402
                                type="radio"
403 403
                                name="event_list_map_align"
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 
410 410
                     <label for="event_list_map_align-left" class="ee-admin-radio-lbl">
411 411
                         <?php $checked = $map_settings->event_list_map_align == 'left'
412
-                            ? 'checked'
413
-                            : ''; ?>
412
+							? 'checked'
413
+							: ''; ?>
414 414
                         <input id="event_list_map_align-left"
415 415
                                type="radio"
416 416
                                name="event_list_map_align"
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 
423 423
                     <label for="event_list_map_align-center" class="ee-admin-radio-lbl">
424 424
                         <?php $checked = $map_settings->event_list_map_align == 'center'
425
-                            ? 'checked'
426
-                            : ''; ?>
425
+							? 'checked'
426
+							: ''; ?>
427 427
                         <input id="event_list_map_align-center"
428 428
                                type="radio"
429 429
                                name="event_list_map_align"
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 
436 436
                     <label for="event_list_map_align-right" class="ee-admin-radio-lbl">
437 437
                         <?php $checked = $map_settings->event_list_map_align == 'right'
438
-                            ? 'checked'
439
-                            : ''; ?>
438
+							? 'checked'
439
+							: ''; ?>
440 440
                         <input id="event_list_map_align-right"
441 441
                                type="radio"
442 442
                                name="event_list_map_align"
Please login to merge, or discard this patch.
admin_pages/general_settings/templates/state_details_settings.template.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -12,26 +12,26 @@  discard block
 block discarded – undo
12 12
         <th colspan="2">
13 13
             <span class="small-text">
14 14
                 <?php printf(
15
-                    esc_html__('State Appears in%1$sDropdown Select Lists ', 'event_espresso'),
16
-                    '<br />'
17
-                ); ?>
15
+					esc_html__('State Appears in%1$sDropdown Select Lists ', 'event_espresso'),
16
+					'<br />'
17
+				); ?>
18 18
             </span>
19 19
         </th>
20 20
     </tr>
21 21
     </thead>
22 22
     <tbody>
23 23
     <?php
24
-    if ($states) {
25
-        foreach ($states as $STA_ID => $state) {
26
-            ?>
24
+	if ($states) {
25
+		foreach ($states as $STA_ID => $state) {
26
+			?>
27 27
         <tr id="state-<?php echo absint($STA_ID); ?>-tr" class="country-state-columns">
28 28
             <?php
29
-            foreach ($state['inputs'] as $ID => $input) {
30
-                if ($ID != 'STA_ID' && $ID != 'CNT_ISO') {
31
-                    echo EEH_Form_Fields::generate_form_input($input); // already escaped
32
-                }
33
-            }
34
-            ?>
29
+			foreach ($state['inputs'] as $ID => $input) {
30
+				if ($ID != 'STA_ID' && $ID != 'CNT_ISO') {
31
+					echo EEH_Form_Fields::generate_form_input($input); // already escaped
32
+				}
33
+			}
34
+			?>
35 35
             <td class="delete-state-td">
36 36
                 <a class="dashicons dashicons-post-trash ee-icon-size-20 delete-state-lnk"
37 37
                    id="delete-state-<?php echo absint($STA_ID); ?>-lnk"
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
             </td>
44 44
         </tr>
45 45
             <?php
46
-        }
47
-        ?>
46
+		}
47
+		?>
48 48
     </tbody>
49 49
 </table>
50 50
 <br/>
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 />
57 57
 <br/>
58 58
         <?php
59
-    }
60
-    ?>
59
+	}
60
+	?>
61 61
 <table class="form-table add-new-state-tbl">
62 62
     <tbody>
63 63
     <tr>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function getMsgModel()
116 116
     {
117
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
117
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
118 118
             $this->MSG_MODEL = EEM_Message::instance();
119 119
         }
120 120
         return $this->MSG_MODEL;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getMtpModel()
129 129
     {
130
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
130
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
131 131
             $this->MTP_MODEL = EEM_Message_Template::instance();
132 132
         }
133 133
         return $this->MTP_MODEL;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function getMtgModel()
142 142
     {
143
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
143
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144 144
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
145 145
         }
146 146
         return $this->MTG_MODEL;
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
         $i = 1;
211 211
         foreach ($active_messengers as $active_messenger) {
212 212
             if ($active_messenger instanceof EE_Message) {
213
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
214
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
213
+                $m_values[$i]['id']   = $active_messenger->messenger();
214
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
215 215
                 $i++;
216 216
             }
217 217
         }
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
         $i               = 1;
248 248
         foreach ($active_messages as $active_message) {
249 249
             if ($active_message instanceof EE_Message) {
250
-                $mt_values[ $i ]['id']   = $active_message->message_type();
251
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
250
+                $mt_values[$i]['id']   = $active_message->message_type();
251
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
252 252
                 $i++;
253 253
             }
254 254
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
                 if ($message_type instanceof EE_message_type) {
288 288
                     $message_type_contexts = $message_type->get_contexts();
289 289
                     foreach ($message_type_contexts as $context => $context_details) {
290
-                        $contexts[ $context ] = $context_details['label'];
290
+                        $contexts[$context] = $context_details['label'];
291 291
                     }
292 292
                 }
293 293
             }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321 321
             $messenger_options
322 322
         );
323
-        $input             = new EE_Select_Input(
323
+        $input = new EE_Select_Input(
324 324
             $messenger_options,
325 325
             [
326 326
                 'html_name'  => 'ee_messenger_filter_by',
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358 358
             $message_type_options
359 359
         );
360
-        $input                = new EE_Select_Input(
360
+        $input = new EE_Select_Input(
361 361
             $message_type_options,
362 362
             [
363 363
                 'html_name'  => 'ee_message_type_filter_by',
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395 395
             $context_options
396 396
         );
397
-        $input           = new EE_Select_Input(
397
+        $input = new EE_Select_Input(
398 398
             $context_options,
399 399
             [
400 400
                 'html_name'  => 'ee_context_filter_by',
@@ -768,53 +768,53 @@  discard block
 block discarded – undo
768 768
 
769 769
     public function messages_help_tab()
770 770
     {
771
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
771
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
772 772
     }
773 773
 
774 774
 
775 775
     public function messengers_help_tab()
776 776
     {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
777
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
778 778
     }
779 779
 
780 780
 
781 781
     public function message_types_help_tab()
782 782
     {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
783
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
784 784
     }
785 785
 
786 786
 
787 787
     public function messages_overview_help_tab()
788 788
     {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
789
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
790 790
     }
791 791
 
792 792
 
793 793
     public function message_templates_help_tab()
794 794
     {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
795
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
796 796
     }
797 797
 
798 798
 
799 799
     public function edit_message_template_help_tab()
800 800
     {
801
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
801
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
802 802
                         . esc_attr__('Editor Title', 'event_espresso')
803 803
                         . '" />';
804
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
804
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
805 805
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
806 806
                         . '" />';
807
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
807
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
808 808
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
809 809
                         . '" />';
810
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
810
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
811 811
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
812 812
                         . '" />';
813
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
813
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
814 814
                         . esc_attr__('Publish Metabox', 'event_espresso')
815 815
                         . '" />';
816 816
         EEH_Template::display_template(
817
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
817
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
818 818
             $args
819 819
         );
820 820
     }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
         $this->_set_shortcodes();
830 830
         $args['shortcodes'] = $this->_shortcodes;
831 831
         EEH_Template::display_template(
832
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
832
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
833 833
             $args
834 834
         );
835 835
     }
@@ -837,16 +837,16 @@  discard block
 block discarded – undo
837 837
 
838 838
     public function preview_message_help_tab()
839 839
     {
840
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
840
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
841 841
     }
842 842
 
843 843
 
844 844
     public function settings_help_tab()
845 845
     {
846
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
846
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
847
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
848
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
849
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
850 850
         $args['img3'] = '<div class="switch">'
851 851
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852 852
                         . ' type="checkbox" checked="checked">'
@@ -857,25 +857,25 @@  discard block
 block discarded – undo
857 857
                         . ' type="checkbox">'
858 858
                         . '<label for="ee-on-off-toggle-on"></label>'
859 859
                         . '</div>';
860
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
860
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
861 861
     }
862 862
 
863 863
 
864 864
     public function load_scripts_styles()
865 865
     {
866
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
866
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867 867
         wp_enqueue_style('espresso_ee_msg');
868 868
 
869 869
         wp_register_script(
870 870
             'ee-messages-settings',
871
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
871
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
872 872
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
873 873
             EVENT_ESPRESSO_VERSION,
874 874
             true
875 875
         );
876 876
         wp_register_script(
877 877
             'ee-msg-list-table-js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
878
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
879 879
             ['ee-dialog'],
880 880
             EVENT_ESPRESSO_VERSION
881 881
         );
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 
919 919
         $this->_set_shortcodes();
920 920
 
921
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
921
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
922 922
             esc_html__(
923 923
                 '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.',
924 924
                 'event_espresso'
@@ -930,14 +930,14 @@  discard block
 block discarded – undo
930 930
             '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?',
931 931
             'event_espresso'
932 932
         );
933
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
933
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
934 934
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935 935
             'event_espresso'
936 936
         );
937 937
 
938 938
         wp_register_script(
939 939
             'ee_msgs_edit_js',
940
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
940
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
941 941
             ['jquery'],
942 942
             EVENT_ESPRESSO_VERSION
943 943
         );
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
     {
981 981
         wp_register_style(
982 982
             'ee-message-settings',
983
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
983
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
984 984
             [],
985 985
             EVENT_ESPRESSO_VERSION
986 986
         );
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
             }
1067 1067
             $status_bulk_actions = $common_bulk_actions;
1068 1068
             // unset bulk actions not applying to status
1069
-            if (! empty($status_bulk_actions)) {
1069
+            if ( ! empty($status_bulk_actions)) {
1070 1070
                 switch ($status) {
1071 1071
                     case EEM_Message::status_idle:
1072 1072
                     case EEM_Message::status_resend:
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
                 continue;
1096 1096
             }
1097 1097
 
1098
-            $this->_views[ strtolower($status) ] = [
1098
+            $this->_views[strtolower($status)] = [
1099 1099
                 'slug'        => strtolower($status),
1100 1100
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101 1101
                 'count'       => 0,
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             if ($action_item === 'see_notifications_for') {
1145 1145
                 continue;
1146 1146
             }
1147
-            $action_items[ $action_item ] = [
1147
+            $action_items[$action_item] = [
1148 1148
                 'class' => $action_details['css_class'],
1149 1149
                 'desc'  => $action_details['label'],
1150 1150
             ];
@@ -1153,37 +1153,37 @@  discard block
 block discarded – undo
1153 1153
         /** @var array $status_items status legend setup */
1154 1154
         $status_items = [
1155 1155
             'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1156
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1157 1157
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158 1158
             ],
1159 1159
             'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1160
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1161 1161
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162 1162
             ],
1163 1163
             'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1164
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1165 1165
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166 1166
             ],
1167 1167
             'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1168
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1169 1169
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170 1170
             ],
1171 1171
             'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1172
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1173 1173
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174 1174
             ],
1175 1175
             'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1176
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1177 1177
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178 1178
             ],
1179 1179
             'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1180
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1181 1181
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182 1182
             ],
1183 1183
         ];
1184 1184
         if (EEM_Message::debug()) {
1185 1185
             $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1186
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1187 1187
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188 1188
             ];
1189 1189
         }
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
     protected function _custom_mtps_preview()
1199 1199
     {
1200 1200
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1201
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1202
+                                                . ' alt="'.esc_attr__(
1203 1203
                                                     'Preview Custom Message Templates screenshot',
1204 1204
                                                     'event_espresso'
1205
-                                                ) . '" />';
1205
+                                                ).'" />';
1206 1206
         $this->_template_args['preview_text'] = '<strong>'
1207 1207
                                                 . esc_html__(
1208 1208
                                                     '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.',
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
         $installed               = [];
1279 1279
 
1280 1280
         foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1281
+            $installed[$message_type->name] = $message_type;
1282 1282
         }
1283 1283
 
1284 1284
         return $installed;
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
         // we need to assemble the title from Various details
1405 1405
         $context_label = sprintf(
1406 1406
             esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1407
+            $c_config[$context]['label'],
1408 1408
             ucwords($c_label['label'])
1409 1409
         );
1410 1410
 
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
             $message_template_group->message_type()
1427 1427
         );
1428 1428
 
1429
-        if (! $template_field_structure) {
1429
+        if ( ! $template_field_structure) {
1430 1430
             $template_field_structure = false;
1431 1431
             $template_fields          = esc_html__(
1432 1432
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1440,21 +1440,21 @@  discard block
 block discarded – undo
1440 1440
 
1441 1441
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442 1442
         // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1443
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1444
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1445
+                unset($template_field_structure[$context][$reference_field]);
1446 1446
             }
1447 1447
         }
1448 1448
 
1449 1449
         // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1450
+        if ( ! empty($template_field_structure)) {
1451
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1452 1452
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453 1453
                 // the extra array and reset them.
1454 1454
                 if ($template_field === 'extra') {
1455 1455
                     $this->_template_args['is_extra_fields'] = true;
1456 1456
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1457
+                        $message_template = $message_templates[$context][$reference_field];
1458 1458
                         $content          = $message_template instanceof EE_Message_Template
1459 1459
                             ? $message_template->get('MTP_content')
1460 1460
                             : '';
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                             $continue = false;
1464 1464
                             if (isset($extra_array['shortcodes_required'])) {
1465 1465
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1466
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1467 1467
                                         $continue = true;
1468 1468
                                     }
1469 1469
                                 }
@@ -1472,53 +1472,53 @@  discard block
 block discarded – undo
1472 1472
                                 }
1473 1473
                             }
1474 1474
 
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1475
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1476 1476
 
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1477
+                            $template_form_fields[$field_id]         = $extra_array;
1478
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1479 1479
                                                                          . $reference_field
1480 1480
                                                                          . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1481
+                                                                         . $extra_field.']';
1482
+                            $css_class = isset($extra_array['css_class'])
1483 1483
                                 ? $extra_array['css_class']
1484 1484
                                 : '';
1485 1485
 
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1486
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1487 1487
                                                                               && in_array($extra_field, $v_fields, true)
1488 1488
                                                                               && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1489
+                                                                                  is_array($validators[$extra_field])
1490
+                                                                                  && isset($validators[$extra_field]['msg'])
1491 1491
                                                                               )
1492
-                                ? 'validate-error ' . $css_class
1492
+                                ? 'validate-error '.$css_class
1493 1493
                                 : $css_class;
1494 1494
 
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1495
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+                                                                          && isset($content[$extra_field])
1497
+                                ? $content[$extra_field]
1498 1498
                                 : '';
1499 1499
 
1500 1500
                             // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1501
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1502
+                                ? $validators[$extra_field]['value']
1503
+                                : $template_form_fields[$field_id]['value'];
1504 1504
 
1505 1505
 
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1506
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1507 1507
 
1508 1508
                             // shortcode selector
1509 1509
                             $field_name_to_use                                   = $extra_field === 'main'
1510 1510
                                 ? 'content'
1511 1511
                                 : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1512
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1513 1513
                                 $field_name_to_use,
1514 1514
                                 $field_id
1515 1515
                             );
1516 1516
                         }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1517
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1518
+                        $template_field_template_name_id = $reference_field.'-name';
1519 1519
 
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1520
+                        $template_form_fields[$template_field_MTP_id] = [
1521
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1522 1522
                             'label'      => null,
1523 1523
                             'input'      => 'hidden',
1524 1524
                             'type'       => 'int',
@@ -1530,8 +1530,8 @@  discard block
 block discarded – undo
1530 1530
                             'db-col'     => 'MTP_ID',
1531 1531
                         ];
1532 1532
 
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1533
+                        $template_form_fields[$template_field_template_name_id] = [
1534
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1535 1535
                             'label'      => null,
1536 1536
                             'input'      => 'hidden',
1537 1537
                             'type'       => 'string',
@@ -1545,38 +1545,38 @@  discard block
 block discarded – undo
1545 1545
                     }
1546 1546
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547 1547
                 } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1548
+                    $field_id                                   = $template_field.'-content';
1549
+                    $template_form_fields[$field_id]          = $field_setup_array;
1550
+                    $template_form_fields[$field_id]['name']  =
1551
+                        'MTP_template_fields['.$template_field.'][content]';
1552 1552
                     $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1553
+                        isset($message_templates[$context][$template_field])
1554
+                            ? $message_templates[$context][$template_field]
1555 1555
                             : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1556
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1557
+                                                                  && is_array($message_templates[$context])
1558 1558
                                                                   && $message_template instanceof EE_Message_Template
1559 1559
                         ? $message_template->get('MTP_content')
1560 1560
                         : '';
1561 1561
 
1562 1562
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1563
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1564
+                        ? $validators[$template_field]['value']
1565
+                        : $template_form_fields[$field_id]['value'];
1566 1566
 
1567 1567
 
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1568
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1569 1569
                     $css_class                                      = isset($field_setup_array['css_class'])
1570 1570
                         ? $field_setup_array['css_class']
1571 1571
                         : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1572
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1573 1573
                                                                       && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1574
+                                                                      && isset($validators[$template_field]['msg'])
1575
+                        ? 'validate-error '.$css_class
1576 1576
                         : $css_class;
1577 1577
 
1578 1578
                     // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1579
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1580 1580
                         $template_field,
1581 1581
                         $field_id
1582 1582
                     );
@@ -1584,12 +1584,12 @@  discard block
 block discarded – undo
1584 1584
 
1585 1585
                 // k took care of content field(s) now let's take care of others.
1586 1586
 
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1587
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1588
+                $template_field_field_template_name_id = $template_field.'-name';
1589 1589
 
1590 1590
                 // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1591
+                $template_form_fields[$template_field_MTP_id] = [
1592
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1593 1593
                     'label'      => null,
1594 1594
                     'input'      => 'hidden',
1595 1595
                     'type'       => 'int',
@@ -1601,8 +1601,8 @@  discard block
 block discarded – undo
1601 1601
                     'db-col'     => 'MTP_ID',
1602 1602
                 ];
1603 1603
 
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1604
+                $template_form_fields[$template_field_field_template_name_id] = [
1605
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1606 1606
                     'label'      => null,
1607 1607
                     'input'      => 'hidden',
1608 1608
                     'type'       => 'string',
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
                 'format'     => '%d',
1720 1720
                 'db-col'     => 'MTP_deleted',
1721 1721
             ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1722
+            $sidebar_form_fields['ee-msg-author'] = [
1723 1723
                 'name'       => 'MTP_user_id',
1724 1724
                 'label'      => esc_html__('Author', 'event_espresso'),
1725 1725
                 'input'      => 'hidden',
@@ -1738,17 +1738,17 @@  discard block
 block discarded – undo
1738 1738
                 'value' => $action,
1739 1739
             ];
1740 1740
 
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1741
+            $sidebar_form_fields['ee-msg-id'] = [
1742 1742
                 'name'  => 'id',
1743 1743
                 'input' => 'hidden',
1744 1744
                 'type'  => 'int',
1745 1745
                 'value' => $GRP_ID,
1746 1746
             ];
1747 1747
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1748
+                'name'  => $action.'_nonce',
1749 1749
                 'input' => 'hidden',
1750 1750
                 'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1751
+                'value' => wp_create_nonce($action.'_nonce'),
1752 1752
             ];
1753 1753
 
1754 1754
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         );
1780 1780
 
1781 1781
         // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1782
+        $preview_url = parent::add_query_args_and_nonce(
1783 1783
             [
1784 1784
                 'message_type' => $message_template_group->message_type(),
1785 1785
                 'messenger'    => $message_template_group->messenger(),
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
             ],
1791 1791
             $this->_admin_base_url
1792 1792
         );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1793
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1794 1794
                           . esc_html__('Preview', 'event_espresso')
1795 1795
                           . '</a>';
1796 1796
 
@@ -1826,11 +1826,11 @@  discard block
 block discarded – undo
1826 1826
             $context_label
1827 1827
         );
1828 1828
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1829
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1830 1830
 
1831 1831
         $this->_template_path = $this->_template_args['GRP_ID']
1832 1832
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1833
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1834 1834
 
1835 1835
         // send along EE_Message_Template_Group object for further template use.
1836 1836
         $this->_template_args['MTP'] = $message_template_group;
@@ -1886,7 +1886,7 @@  discard block
 block discarded – undo
1886 1886
     ) {
1887 1887
         $template_args = [
1888 1888
             'context'                   => $context,
1889
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1889
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1890 1890
             'is_active'                 => $message_template_group->is_context_active($context),
1891 1891
             'on_off_action'             => $message_template_group->is_context_active($context)
1892 1892
                 ? 'context-off'
@@ -1895,7 +1895,7 @@  discard block
 block discarded – undo
1895 1895
             'message_template_group_id' => $message_template_group->ID(),
1896 1896
         ];
1897 1897
         return EEH_Template::display_template(
1898
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1898
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1899 1899
             $template_args,
1900 1900
             true
1901 1901
         );
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
         }
1953 1953
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954 1954
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1955
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1956 1956
             EE_Error::add_error(
1957 1957
                 sprintf(
1958 1958
                     esc_html__(
@@ -2083,7 +2083,7 @@  discard block
 block discarded – undo
2083 2083
         $messenger    = $this->request->getRequestParam('msgr');
2084 2084
         $message_type = $this->request->getRequestParam('mt');
2085 2085
         // we need to make sure we've got the info we need.
2086
-        if (! ($GRP_ID && $messenger && $message_type)) {
2086
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2087 2087
             EE_Error::add_error(
2088 2088
                 esc_html__(
2089 2089
                     '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.',
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
         }
2121 2121
 
2122 2122
         // any error messages?
2123
-        if (! $success) {
2123
+        if ( ! $success) {
2124 2124
             EE_Error::add_error(
2125 2125
                 esc_html__(
2126 2126
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2169,7 +2169,7 @@  discard block
 block discarded – undo
2169 2169
     {
2170 2170
         // first make sure we've got the necessary parameters
2171 2171
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2172
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173 2173
             EE_Error::add_error(
2174 2174
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175 2175
                 __FILE__,
@@ -2195,7 +2195,7 @@  discard block
 block discarded – undo
2195 2195
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196 2196
 
2197 2197
         // let's add a button to go back to the edit view
2198
-        $query_args             = [
2198
+        $query_args = [
2199 2199
             'id'      => $GRP_ID,
2200 2200
             'evt_id'  => $EVT_ID,
2201 2201
             'context' => $context,
@@ -2216,7 +2216,7 @@  discard block
 block discarded – undo
2216 2216
         $preview_title = sprintf(
2217 2217
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218 2218
             $active_messenger_label,
2219
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2219
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2220 2220
         );
2221 2221
         if (empty($preview)) {
2222 2222
             $this->noEventsErrorMessage();
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
         // setup display of preview.
2225 2225
         $this->_admin_page_title                    = $preview_title;
2226 2226
         $this->_template_args['admin_page_title']   = $preview_title;
2227
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2227
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2228 2228
         $this->_template_args['data']['force_json'] = true;
2229 2229
 
2230 2230
         return '';
@@ -2245,7 +2245,7 @@  discard block
 block discarded – undo
2245 2245
             ],
2246 2246
             admin_url('admin.php')
2247 2247
         );
2248
-        $message    = $test_send
2248
+        $message = $test_send
2249 2249
             ? esc_html__(
2250 2250
                 '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!',
2251 2251
                 'event_espresso'
@@ -2338,10 +2338,10 @@  discard block
 block discarded – undo
2338 2338
             // only include template packs that support this messenger and message type!
2339 2339
             $supports = $tp->get_supports();
2340 2340
             if (
2341
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2341
+                ! isset($supports[$this->_message_template_group->messenger()])
2342 2342
                 || ! in_array(
2343 2343
                     $this->_message_template_group->message_type(),
2344
-                    $supports[ $this->_message_template_group->messenger() ],
2344
+                    $supports[$this->_message_template_group->messenger()],
2345 2345
                     true
2346 2346
                 )
2347 2347
             ) {
@@ -2365,7 +2365,7 @@  discard block
 block discarded – undo
2365 2365
         }
2366 2366
 
2367 2367
         // setup variation select values for the currently selected template.
2368
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2368
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2369 2369
             $this->_message_template_group->messenger(),
2370 2370
             $this->_message_template_group->message_type()
2371 2371
         );
@@ -2379,12 +2379,12 @@  discard block
 block discarded – undo
2379 2379
 
2380 2380
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381 2381
 
2382
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2382
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2383 2383
             'MTP_template_pack',
2384 2384
             $tp_select_values,
2385 2385
             $this->_message_template_group->get_template_pack_name()
2386 2386
         );
2387
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2387
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2388 2388
             'MTP_template_variation',
2389 2389
             $variations_select_values,
2390 2390
             $this->_message_template_group->get_template_pack_variation()
@@ -2394,7 +2394,7 @@  discard block
 block discarded – undo
2394 2394
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395 2395
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396 2396
 
2397
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2397
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2398 2398
 
2399 2399
         EEH_Template::display_template($template, $template_args);
2400 2400
     }
@@ -2420,33 +2420,33 @@  discard block
 block discarded – undo
2420 2420
         // first we need to see if there are any fields
2421 2421
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422 2422
 
2423
-        if (! empty($fields)) {
2423
+        if ( ! empty($fields)) {
2424 2424
             // yup there be fields
2425 2425
             foreach ($fields as $field => $config) {
2426
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2426
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2427 2427
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428 2428
                 $default  = isset($config['default']) ? $config['default'] : '';
2429 2429
                 $default  = isset($config['value']) ? $config['value'] : $default;
2430 2430
 
2431 2431
                 // if type is hidden and the value is empty
2432 2432
                 // something may have gone wrong so let's correct with the defaults
2433
-                $fix                = $config['input'] === 'hidden'
2434
-                                      && isset($existing[ $field ])
2435
-                                      && empty($existing[ $field ])
2433
+                $fix = $config['input'] === 'hidden'
2434
+                                      && isset($existing[$field])
2435
+                                      && empty($existing[$field])
2436 2436
                     ? $default
2437 2437
                     : '';
2438
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
-                    ? $existing[ $field ]
2438
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2439
+                    ? $existing[$field]
2440 2440
                     : $fix;
2441 2441
 
2442
-                $template_form_fields[ $field_id ] = [
2443
-                    'name'       => 'test_settings_fld[' . $field . ']',
2442
+                $template_form_fields[$field_id] = [
2443
+                    'name'       => 'test_settings_fld['.$field.']',
2444 2444
                     'label'      => $config['label'],
2445 2445
                     'input'      => $config['input'],
2446 2446
                     'type'       => $config['type'],
2447 2447
                     'required'   => $config['required'],
2448 2448
                     'validation' => $config['validation'],
2449
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2449
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2450 2450
                     'css_class'  => $config['css_class'],
2451 2451
                     'options'    => isset($config['options']) ? $config['options'] : [],
2452 2452
                     'default'    => $default,
@@ -2460,7 +2460,7 @@  discard block
 block discarded – undo
2460 2460
             : '';
2461 2461
 
2462 2462
         // print out $test_settings_fields
2463
-        if (! empty($test_settings_html)) {
2463
+        if ( ! empty($test_settings_html)) {
2464 2464
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465 2465
             $test_settings_html .= 'name="test_button" value="';
2466 2466
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2506,7 +2506,7 @@  discard block
 block discarded – undo
2506 2506
         ];
2507 2507
 
2508 2508
         return EEH_Template::display_template(
2509
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2509
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2510 2510
             $template_args,
2511 2511
             true
2512 2512
         );
@@ -2532,7 +2532,7 @@  discard block
 block discarded – undo
2532 2532
         // $messenger = $this->_message_template_group->messenger_obj();
2533 2533
         // now let's set the content depending on the status of the shortcodes array
2534 2534
         if (empty($shortcodes)) {
2535
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2535
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2536 2536
             return;
2537 2537
         }
2538 2538
         ?>
@@ -2568,7 +2568,7 @@  discard block
 block discarded – undo
2568 2568
     {
2569 2569
 
2570 2570
         // no need to run this if the property is already set
2571
-        if (! empty($this->_shortcodes)) {
2571
+        if ( ! empty($this->_shortcodes)) {
2572 2572
             return;
2573 2573
         }
2574 2574
 
@@ -2623,7 +2623,7 @@  discard block
 block discarded – undo
2623 2623
     protected function _set_message_template_group()
2624 2624
     {
2625 2625
         // get out if this is already set.
2626
-        if (! empty($this->_message_template_group)) {
2626
+        if ( ! empty($this->_message_template_group)) {
2627 2627
             return;
2628 2628
         }
2629 2629
 
@@ -2669,8 +2669,8 @@  discard block
 block discarded – undo
2669 2669
                     <?php
2670 2670
                 }
2671 2671
                 // setup nonce_url
2672
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2672
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2673
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2674 2674
                 ?>
2675 2675
                 <label for='<?php echo absint($id); ?>' class='screen-reader-text'>
2676 2676
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2683,7 +2683,7 @@  discard block
 block discarded – undo
2683 2683
                             $checked = ($context === $args['context']) ? 'selected' : '';
2684 2684
                             ?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2686
-                                <?php echo $context_details[ $context ]['label']; // already escaped
2686
+                                <?php echo $context_details[$context]['label']; // already escaped
2687 2687
                                 ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
@@ -3077,7 +3077,7 @@  discard block
 block discarded – undo
3077 3077
     {
3078 3078
         if (is_array($content)) {
3079 3079
             foreach ($content as $key => $value) {
3080
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3081 3081
             }
3082 3082
             return $content;
3083 3083
         }
@@ -3115,7 +3115,7 @@  discard block
 block discarded – undo
3115 3115
 
3116 3116
         $context   = ucwords(str_replace('_', ' ', $context));
3117 3117
         $item_desc = $messenger_label && $message_type_label
3118
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3119 3119
             : '';
3120 3120
         $item_desc .= 'Message Template';
3121 3121
         return $item_desc;
@@ -3267,7 +3267,7 @@  discard block
 block discarded – undo
3267 3267
         if ($all) {
3268 3268
             // Checkboxes
3269 3269
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
-            if (! empty($checkboxes)) {
3270
+            if ( ! empty($checkboxes)) {
3271 3271
                 // if array has more than one element then success message should be plural.
3272 3272
                 // todo: what about nonce?
3273 3273
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3277,18 +3277,18 @@  discard block
 block discarded – undo
3277 3277
                     $trashed_or_restored = $trash
3278 3278
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279 3279
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
-                    if (! $trashed_or_restored) {
3280
+                    if ( ! $trashed_or_restored) {
3281 3281
                         $success = 0;
3282 3282
                     }
3283 3283
                 }
3284 3284
             } else {
3285 3285
                 // grab single GRP_ID and handle
3286 3286
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
-                if (! empty($GRP_ID)) {
3287
+                if ( ! empty($GRP_ID)) {
3288 3288
                     $trashed_or_restored = $trash
3289 3289
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290 3290
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
-                    if (! $trashed_or_restored) {
3291
+                    if ( ! $trashed_or_restored) {
3292 3292
                         $success = 0;
3293 3293
                     }
3294 3294
                 } else {
@@ -3336,7 +3336,7 @@  discard block
 block discarded – undo
3336 3336
 
3337 3337
         // checkboxes
3338 3338
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
-        if (! empty($checkboxes)) {
3339
+        if ( ! empty($checkboxes)) {
3340 3340
             // if array has more than one element then success message should be plural
3341 3341
             $success = count($checkboxes) > 1 ? 2 : 1;
3342 3342
 
@@ -3440,7 +3440,7 @@  discard block
 block discarded – undo
3440 3440
     protected function _set_m_mt_settings()
3441 3441
     {
3442 3442
         // first if this is already set then lets get out no need to regenerate data.
3443
-        if (! empty($this->_m_mt_settings)) {
3443
+        if ( ! empty($this->_m_mt_settings)) {
3444 3444
             return;
3445 3445
         }
3446 3446
 
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
         // assemble the array for the _tab_text_links helper
3453 3453
 
3454 3454
         foreach ($messengers as $messenger) {
3455
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3456 3456
                 'label' => ucwords($messenger->label['singular']),
3457 3457
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458 3458
                     ? 'messenger-active'
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
             foreach ($message_types as $message_type) {
3470 3470
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471 3471
                 // it shouldn't show in either the inactive OR active metabox.
3472
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3473 3473
                     continue;
3474 3474
                 }
3475 3475
 
@@ -3480,12 +3480,12 @@  discard block
 block discarded – undo
3480 3480
                     ? 'active'
3481 3481
                     : 'inactive';
3482 3482
 
3483
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3484 3484
                     'label'    => ucwords($message_type->label['singular']),
3485
-                    'class'    => 'message-type-' . $a_or_i,
3486
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3485
+                    'class'    => 'message-type-'.$a_or_i,
3486
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3487
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3488
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3489 3489
                     'title'    => $a_or_i === 'active'
3490 3490
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491 3491
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3516,25 +3516,25 @@  discard block
 block discarded – undo
3516 3516
         $fields                                         = $message_type->get_admin_settings_fields();
3517 3517
         $settings_template_args['template_form_fields'] = '';
3518 3518
 
3519
-        if (! empty($fields) && $active) {
3519
+        if ( ! empty($fields) && $active) {
3520 3520
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521 3521
             foreach ($fields as $fldname => $fldprops) {
3522
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
-                $template_form_field[ $field_id ] = [
3524
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3522
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3523
+                $template_form_field[$field_id] = [
3524
+                    'name'       => 'message_type_settings['.$fldname.']',
3525 3525
                     'label'      => $fldprops['label'],
3526 3526
                     'input'      => $fldprops['field_type'],
3527 3527
                     'type'       => $fldprops['value_type'],
3528 3528
                     'required'   => $fldprops['required'],
3529 3529
                     'validation' => $fldprops['validation'],
3530
-                    'value'      => isset($existing_settings[ $fldname ])
3531
-                        ? $existing_settings[ $fldname ]
3530
+                    'value'      => isset($existing_settings[$fldname])
3531
+                        ? $existing_settings[$fldname]
3532 3532
                         : $fldprops['default'],
3533 3533
                     'options'    => isset($fldprops['options'])
3534 3534
                         ? $fldprops['options']
3535 3535
                         : [],
3536
-                    'default'    => isset($existing_settings[ $fldname ])
3537
-                        ? $existing_settings[ $fldname ]
3536
+                    'default'    => isset($existing_settings[$fldname])
3537
+                        ? $existing_settings[$fldname]
3538 3538
                         : $fldprops['default'],
3539 3539
                     'css_class'  => 'no-drag',
3540 3540
                     'format'     => $fldprops['format'],
@@ -3554,15 +3554,15 @@  discard block
 block discarded – undo
3554 3554
         $settings_template_args['description'] = $message_type->description;
3555 3555
         // we also need some hidden fields
3556 3556
         $hidden_fields = [
3557
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
+            'message_type_settings[messenger]'.$message_type->name    => [
3558 3558
                 'type'  => 'hidden',
3559 3559
                 'value' => $messenger->name,
3560 3560
             ],
3561
-            'message_type_settings[message_type]' . $message_type->name => [
3561
+            'message_type_settings[message_type]'.$message_type->name => [
3562 3562
                 'type'  => 'hidden',
3563 3563
                 'value' => $message_type->name,
3564 3564
             ],
3565
-            'type' . $message_type->name                                => [
3565
+            'type'.$message_type->name                                => [
3566 3566
                 'type'  => 'hidden',
3567 3567
                 'value' => 'message_type',
3568 3568
             ],
@@ -3572,12 +3572,12 @@  discard block
 block discarded – undo
3572 3572
             $hidden_fields,
3573 3573
             'array'
3574 3574
         );
3575
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3576 3576
             ? ' hidden'
3577 3577
             : '';
3578 3578
 
3579 3579
 
3580
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3581 3581
         return EEH_Template::display_template($template, $settings_template_args, true);
3582 3582
     }
3583 3583
 
@@ -3605,21 +3605,21 @@  discard block
 block discarded – undo
3605 3605
 
3606 3606
                 // messenger meta boxes
3607 3607
                 $active         = $selected_messenger === $messenger;
3608
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3608
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3609
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3610 3610
                     : '';
3611 3611
 
3612
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3613 3613
                     esc_html__('%s Settings', 'event_espresso'),
3614 3614
                     $tab_array['label']
3615 3615
                 );
3616 3616
 
3617
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
+                $m_template_args[$messenger.'_a_box'] = [
3618 3618
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619 3619
                     'inactive_message_types' => isset(
3620
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3621 3621
                     )
3622
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3623 3623
                         : '',
3624 3624
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625 3625
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3631,13 +3631,13 @@  discard block
 block discarded – undo
3631 3631
                 // message type meta boxes
3632 3632
                 // (which is really just the inactive container for each messenger
3633 3633
                 // showing inactive message types for that messenger)
3634
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
-                $mt_template_args[ $messenger . '_i_box' ] = [
3634
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3635
+                $mt_template_args[$messenger.'_i_box'] = [
3636 3636
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637 3637
                     'inactive_message_types' => isset(
3638
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3639 3639
                     )
3640
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3641 3641
                         : '',
3642 3642
                     'hidden'                 => $active ? '' : ' hidden',
3643 3643
                     'hide_on_message'        => $hide_on_message,
@@ -3650,14 +3650,14 @@  discard block
 block discarded – undo
3650 3650
 
3651 3651
 
3652 3652
         // register messenger metaboxes
3653
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3654 3654
         foreach ($m_boxes as $box => $label) {
3655
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3656 3656
             $msgr          = str_replace('_a_box', '', $box);
3657 3657
             add_meta_box(
3658
-                'espresso_' . $msgr . '_settings',
3658
+                'espresso_'.$msgr.'_settings',
3659 3659
                 $label,
3660
-                function ($post, $metabox) {
3660
+                function($post, $metabox) {
3661 3661
                     EEH_Template::display_template(
3662 3662
                         $metabox['args']['template_path'],
3663 3663
                         $metabox['args']['template_args']
@@ -3671,17 +3671,17 @@  discard block
 block discarded – undo
3671 3671
         }
3672 3672
 
3673 3673
         // register message type metaboxes
3674
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3675 3675
         foreach ($mt_boxes as $box => $label) {
3676 3676
             $callback_args = [
3677 3677
                 'template_path' => $mt_template_path,
3678
-                'template_args' => $mt_template_args[ $box ],
3678
+                'template_args' => $mt_template_args[$box],
3679 3679
             ];
3680
-            $mt            = str_replace('_i_box', '', $box);
3680
+            $mt = str_replace('_i_box', '', $box);
3681 3681
             add_meta_box(
3682
-                'espresso_' . $mt . '_inactive_mts',
3682
+                'espresso_'.$mt.'_inactive_mts',
3683 3683
                 $label,
3684
-                function ($post, $metabox) {
3684
+                function($post, $metabox) {
3685 3685
                     EEH_Template::display_template(
3686 3686
                         $metabox['args']['template_path'],
3687 3687
                         $metabox['args']['template_args']
@@ -3826,7 +3826,7 @@  discard block
 block discarded – undo
3826 3826
             if ($form->is_valid()) {
3827 3827
                 $valid_data = $form->valid_data();
3828 3828
                 foreach ($valid_data as $property => $value) {
3829
-                    $setter = 'set_' . $property;
3829
+                    $setter = 'set_'.$property;
3830 3830
                     if (method_exists($network_config, $setter)) {
3831 3831
                         $network_config->{$setter}($value);
3832 3832
                     } elseif (
@@ -3862,7 +3862,7 @@  discard block
 block discarded – undo
3862 3862
     protected function _get_mt_tabs($tab_array)
3863 3863
     {
3864 3864
         $tab_array = (array) $tab_array;
3865
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3865
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3866 3866
         $tabs      = '';
3867 3867
 
3868 3868
         foreach ($tab_array as $tab) {
@@ -3890,20 +3890,20 @@  discard block
 block discarded – undo
3890 3890
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891 3891
 
3892 3892
 
3893
-        if (! empty($fields)) {
3893
+        if ( ! empty($fields)) {
3894 3894
             $existing_settings = $messenger->get_existing_admin_settings();
3895 3895
 
3896 3896
             foreach ($fields as $fldname => $fldprops) {
3897
-                $field_id                         = $messenger->name . '-' . $fldname;
3898
-                $template_form_field[ $field_id ] = [
3899
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3897
+                $field_id                         = $messenger->name.'-'.$fldname;
3898
+                $template_form_field[$field_id] = [
3899
+                    'name'       => 'messenger_settings['.$field_id.']',
3900 3900
                     'label'      => $fldprops['label'],
3901 3901
                     'input'      => $fldprops['field_type'],
3902 3902
                     'type'       => $fldprops['value_type'],
3903 3903
                     'required'   => $fldprops['required'],
3904 3904
                     'validation' => $fldprops['validation'],
3905
-                    'value'      => isset($existing_settings[ $field_id ])
3906
-                        ? $existing_settings[ $field_id ]
3905
+                    'value'      => isset($existing_settings[$field_id])
3906
+                        ? $existing_settings[$field_id]
3907 3907
                         : $fldprops['default'],
3908 3908
                     'css_class'  => '',
3909 3909
                     'format'     => $fldprops['format'],
@@ -3918,20 +3918,20 @@  discard block
 block discarded – undo
3918 3918
 
3919 3919
         // we also need some hidden fields
3920 3920
         $settings_template_args['hidden_fields'] = [
3921
-            'messenger_settings[messenger]' . $messenger->name => [
3921
+            'messenger_settings[messenger]'.$messenger->name => [
3922 3922
                 'type'  => 'hidden',
3923 3923
                 'value' => $messenger->name,
3924 3924
             ],
3925
-            'type' . $messenger->name                          => [
3925
+            'type'.$messenger->name                          => [
3926 3926
                 'type'  => 'hidden',
3927 3927
                 'value' => 'messenger',
3928 3928
             ],
3929 3929
         ];
3930 3930
 
3931 3931
         // make sure any active message types that are existing are included in the hidden fields
3932
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3932
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3933
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3934
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3935 3935
                     'type'  => 'hidden',
3936 3936
                     'value' => $mt,
3937 3937
                 ];
@@ -3941,7 +3941,7 @@  discard block
 block discarded – undo
3941 3941
             $settings_template_args['hidden_fields'],
3942 3942
             'array'
3943 3943
         );
3944
-        $active                                  =
3944
+        $active =
3945 3945
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3946 3946
 
3947 3947
         $settings_template_args['messenger']           = $messenger->name;
@@ -3961,9 +3961,9 @@  discard block
 block discarded – undo
3961 3961
 
3962 3962
 
3963 3963
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3964
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3965 3965
         $settings_template_args['on_off_status'] = $active;
3966
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3966
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3967 3967
         return EEH_Template::display_template(
3968 3968
             $template,
3969 3969
             $settings_template_args,
@@ -3988,7 +3988,7 @@  discard block
 block discarded – undo
3988 3988
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3989 3989
         // let's check that we have required data
3990 3990
 
3991
-        if (! $this->_active_messenger_name) {
3991
+        if ( ! $this->_active_messenger_name) {
3992 3992
             EE_Error::add_error(
3993 3993
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994 3994
                 __FILE__,
@@ -4006,7 +4006,7 @@  discard block
 block discarded – undo
4006 4006
 
4007 4007
 
4008 4008
         $status = $this->request->getRequestParam('status');
4009
-        if (! $status) {
4009
+        if ( ! $status) {
4010 4010
             EE_Error::add_error(
4011 4011
                 esc_html__(
4012 4012
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4063,7 +4063,7 @@  discard block
 block discarded – undo
4063 4063
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4064 4064
 
4065 4065
         // let's make sure we have the necessary data
4066
-        if (! $this->_active_message_type_name) {
4066
+        if ( ! $this->_active_message_type_name) {
4067 4067
             EE_Error::add_error(
4068 4068
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069 4069
                 __FILE__,
@@ -4073,7 +4073,7 @@  discard block
 block discarded – undo
4073 4073
             $success = false;
4074 4074
         }
4075 4075
 
4076
-        if (! $this->_active_messenger_name) {
4076
+        if ( ! $this->_active_messenger_name) {
4077 4077
             EE_Error::add_error(
4078 4078
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079 4079
                 __FILE__,
@@ -4084,7 +4084,7 @@  discard block
 block discarded – undo
4084 4084
         }
4085 4085
 
4086 4086
         $status = $this->request->getRequestParam('status');
4087
-        if (! $status) {
4087
+        if ( ! $status) {
4088 4088
             EE_Error::add_error(
4089 4089
                 esc_html__(
4090 4090
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4296,7 +4296,7 @@  discard block
 block discarded – undo
4296 4296
         EE_Message_Type $message_type = null
4297 4297
     ) {
4298 4298
         // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4299
+        if ( ! $messenger instanceof EE_Messenger) {
4300 4300
             EE_Error::add_error(
4301 4301
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302 4302
                 __FILE__,
@@ -4350,7 +4350,7 @@  discard block
 block discarded – undo
4350 4350
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351 4351
             // in which case we just give a success message for the messenger being successfully activated.
4352 4352
         } else {
4353
-            if (! $messenger->get_default_message_types()) {
4353
+            if ( ! $messenger->get_default_message_types()) {
4354 4354
                 // messenger doesn't have any default message types so still a success.
4355 4355
                 EE_Error::add_success(
4356 4356
                     sprintf(
@@ -4406,7 +4406,7 @@  discard block
 block discarded – undo
4406 4406
         EE_Error::overwrite_success();
4407 4407
 
4408 4408
         // if $messenger isn't a valid messenger object then get out.
4409
-        if (! $messenger instanceof EE_Messenger) {
4409
+        if ( ! $messenger instanceof EE_Messenger) {
4410 4410
             EE_Error::add_error(
4411 4411
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412 4412
                 __FILE__,
@@ -4476,7 +4476,7 @@  discard block
 block discarded – undo
4476 4476
      */
4477 4477
     public function update_mt_form()
4478 4478
     {
4479
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4479
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480 4480
             EE_Error::add_error(
4481 4481
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482 4482
                 __FILE__,
@@ -4487,7 +4487,7 @@  discard block
 block discarded – undo
4487 4487
         }
4488 4488
 
4489 4489
         $message_types = $this->get_installed_message_types();
4490
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4490
+        $message_type  = $message_types[$this->_active_message_type_name];
4491 4491
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492 4492
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493 4493
 
@@ -4506,7 +4506,7 @@  discard block
 block discarded – undo
4506 4506
     public function save_settings()
4507 4507
     {
4508 4508
         $type = $this->request->getRequestParam('type');
4509
-        if (! $type) {
4509
+        if ( ! $type) {
4510 4510
             EE_Error::add_error(
4511 4511
                 esc_html__(
4512 4512
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -16,2683 +16,2683 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19
-    /**
20
-     * @var EEM_Message
21
-     */
22
-    private $MSG_MODEL;
23
-
24
-    /**
25
-     * @var EEM_Message_Template
26
-     */
27
-    private $MTP_MODEL;
28
-
29
-    /**
30
-     * @var EEM_Message_Template_Group
31
-     */
32
-    private $MTG_MODEL;
33
-
34
-    /**
35
-     * @var EE_Message_Resource_Manager $_message_resource_manager
36
-     */
37
-    protected $_message_resource_manager;
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected $_active_message_type_name = '';
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    protected $_active_messenger_name = '';
48
-
49
-    /**
50
-     * @var EE_messenger $_active_messenger
51
-     */
52
-    protected $_active_messenger;
53
-
54
-    protected $_activate_meta_box_type;
55
-
56
-    protected $_current_message_meta_box;
57
-
58
-    protected $_current_message_meta_box_object;
59
-
60
-    protected $_context_switcher;
61
-
62
-    protected $_shortcodes           = [];
63
-
64
-    protected $_active_messengers    = [];
65
-
66
-    protected $_active_message_types = [];
67
-
68
-    /**
69
-     * @var EE_Message_Template_Group $_message_template_group
70
-     */
71
-    protected $_message_template_group;
72
-
73
-    protected $_m_mt_settings = [];
74
-
75
-
76
-    /**
77
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
-     * IF there is no group then it gets automatically set to the Default template pack.
79
-     *
80
-     * @since 4.5.0
81
-     *
82
-     * @var EE_Messages_Template_Pack
83
-     */
84
-    protected $_template_pack;
85
-
86
-
87
-    /**
88
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
-     * group is.  If there is no group then it automatically gets set to default.
90
-     *
91
-     * @since 4.5.0
92
-     *
93
-     * @var string
94
-     */
95
-    protected $_variation;
96
-
97
-
98
-    /**
99
-     * @param bool $routing
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    public function __construct($routing = true)
104
-    {
105
-        // make sure messages autoloader is running
106
-        EED_Messages::set_autoloaders();
107
-        parent::__construct($routing);
108
-    }
109
-
110
-
111
-    /**
112
-     * @return EEM_Message
113
-     * @throws EE_Error
114
-     */
115
-    public function getMsgModel()
116
-    {
117
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
-            $this->MSG_MODEL = EEM_Message::instance();
119
-        }
120
-        return $this->MSG_MODEL;
121
-    }
122
-
123
-
124
-    /**
125
-     * @return EEM_Message_Template
126
-     * @throws EE_Error
127
-     */
128
-    public function getMtpModel()
129
-    {
130
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
-            $this->MTP_MODEL = EEM_Message_Template::instance();
132
-        }
133
-        return $this->MTP_MODEL;
134
-    }
135
-
136
-
137
-    /**
138
-     * @return EEM_Message_Template_Group
139
-     * @throws EE_Error
140
-     */
141
-    public function getMtgModel()
142
-    {
143
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
-        }
146
-        return $this->MTG_MODEL;
147
-    }
148
-
149
-
150
-    /**
151
-     * @throws EE_Error
152
-     * @throws ReflectionException
153
-     */
154
-    protected function _init_page_props()
155
-    {
156
-        $this->page_slug        = EE_MSG_PG_SLUG;
157
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
-        $this->_admin_base_path = EE_MSG_ADMIN;
160
-
161
-        $messenger    = $this->request->getRequestParam('messenger', '');
162
-        $message_type = $this->request->getRequestParam('message_type', '');
163
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
-
166
-        $this->_load_message_resource_manager();
167
-    }
168
-
169
-
170
-    /**
171
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
-     *
173
-     * @throws EE_Error
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws InvalidArgumentException
177
-     * @throws ReflectionException
178
-     */
179
-    protected function _load_message_resource_manager()
180
-    {
181
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
-    }
183
-
184
-
185
-    /**
186
-     * @return array
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidInterfaceException
191
-     * @deprecated 4.9.9.rc.014
192
-     */
193
-    public function get_messengers_for_list_table()
194
-    {
195
-        EE_Error::doing_it_wrong(
196
-            __METHOD__,
197
-            sprintf(
198
-                esc_html__(
199
-                    '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',
200
-                    'event_espresso'
201
-                ),
202
-                'Messages_Admin_Page::get_messengers_select_input()'
203
-            ),
204
-            '4.9.9.rc.014'
205
-        );
206
-
207
-        $m_values          = [];
208
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
-        // setup messengers for selects
210
-        $i = 1;
211
-        foreach ($active_messengers as $active_messenger) {
212
-            if ($active_messenger instanceof EE_Message) {
213
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
214
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
-                $i++;
216
-            }
217
-        }
218
-
219
-        return $m_values;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return array
225
-     * @throws EE_Error
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidInterfaceException
229
-     * @deprecated 4.9.9.rc.014
230
-     */
231
-    public function get_message_types_for_list_table()
232
-    {
233
-        EE_Error::doing_it_wrong(
234
-            __METHOD__,
235
-            sprintf(
236
-                esc_html__(
237
-                    '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',
238
-                    'event_espresso'
239
-                ),
240
-                'Messages_Admin_Page::get_message_types_select_input()'
241
-            ),
242
-            '4.9.9.rc.014'
243
-        );
244
-
245
-        $mt_values       = [];
246
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
-        $i               = 1;
248
-        foreach ($active_messages as $active_message) {
249
-            if ($active_message instanceof EE_Message) {
250
-                $mt_values[ $i ]['id']   = $active_message->message_type();
251
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
-                $i++;
253
-            }
254
-        }
255
-
256
-        return $mt_values;
257
-    }
258
-
259
-
260
-    /**
261
-     * @return array
262
-     * @throws EE_Error
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     * @deprecated 4.9.9.rc.014
267
-     */
268
-    public function get_contexts_for_message_types_for_list_table()
269
-    {
270
-        EE_Error::doing_it_wrong(
271
-            __METHOD__,
272
-            sprintf(
273
-                esc_html__(
274
-                    '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',
275
-                    'event_espresso'
276
-                ),
277
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
-            ),
279
-            '4.9.9.rc.014'
280
-        );
281
-
282
-        $contexts                = [];
283
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
-        foreach ($active_message_contexts as $active_message) {
285
-            if ($active_message instanceof EE_Message) {
286
-                $message_type = $active_message->message_type_object();
287
-                if ($message_type instanceof EE_message_type) {
288
-                    $message_type_contexts = $message_type->get_contexts();
289
-                    foreach ($message_type_contexts as $context => $context_details) {
290
-                        $contexts[ $context ] = $context_details['label'];
291
-                    }
292
-                }
293
-            }
294
-        }
295
-
296
-        return $contexts;
297
-    }
298
-
299
-
300
-    /**
301
-     * Generate select input with provided messenger options array.
302
-     *
303
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
-     *                                 labels.
305
-     * @return string
306
-     * @throws EE_Error
307
-     */
308
-    public function get_messengers_select_input($messenger_options)
309
-    {
310
-        // if empty or just one value then just return an empty string
311
-        if (
312
-            empty($messenger_options)
313
-            || ! is_array($messenger_options)
314
-            || count($messenger_options) === 1
315
-        ) {
316
-            return '';
317
-        }
318
-        // merge in default
319
-        $messenger_options = array_merge(
320
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
-            $messenger_options
322
-        );
323
-        $input             = new EE_Select_Input(
324
-            $messenger_options,
325
-            [
326
-                'html_name'  => 'ee_messenger_filter_by',
327
-                'html_id'    => 'ee_messenger_filter_by',
328
-                'html_class' => 'wide',
329
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
-            ]
331
-        );
332
-
333
-        return $input->get_html_for_input();
334
-    }
335
-
336
-
337
-    /**
338
-     * Generate select input with provided message type options array.
339
-     *
340
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
-     *                                    message type labels
342
-     * @return string
343
-     * @throws EE_Error
344
-     */
345
-    public function get_message_types_select_input($message_type_options)
346
-    {
347
-        // if empty or count of options is 1 then just return an empty string
348
-        if (
349
-            empty($message_type_options)
350
-            || ! is_array($message_type_options)
351
-            || count($message_type_options) === 1
352
-        ) {
353
-            return '';
354
-        }
355
-        // merge in default
356
-        $message_type_options = array_merge(
357
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
-            $message_type_options
359
-        );
360
-        $input                = new EE_Select_Input(
361
-            $message_type_options,
362
-            [
363
-                'html_name'  => 'ee_message_type_filter_by',
364
-                'html_id'    => 'ee_message_type_filter_by',
365
-                'html_class' => 'wide',
366
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
-            ]
368
-        );
369
-
370
-        return $input->get_html_for_input();
371
-    }
372
-
373
-
374
-    /**
375
-     * Generate select input with provide message type contexts array.
376
-     *
377
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
-     *                               context label.
379
-     * @return string
380
-     * @throws EE_Error
381
-     */
382
-    public function get_contexts_for_message_types_select_input($context_options)
383
-    {
384
-        // if empty or count of options is one then just return empty string
385
-        if (
386
-            empty($context_options)
387
-            || ! is_array($context_options)
388
-            || count($context_options) === 1
389
-        ) {
390
-            return '';
391
-        }
392
-        // merge in default
393
-        $context_options = array_merge(
394
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
-            $context_options
396
-        );
397
-        $input           = new EE_Select_Input(
398
-            $context_options,
399
-            [
400
-                'html_name'  => 'ee_context_filter_by',
401
-                'html_id'    => 'ee_context_filter_by',
402
-                'html_class' => 'wide',
403
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
-            ]
405
-        );
406
-
407
-        return $input->get_html_for_input();
408
-    }
409
-
410
-
411
-    protected function _ajax_hooks()
412
-    {
413
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
-    }
420
-
421
-
422
-    protected function _define_page_props()
423
-    {
424
-        $this->_admin_page_title = $this->page_label;
425
-        $this->_labels           = [
426
-            'buttons'    => [
427
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
-            ],
431
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
-        ];
433
-    }
434
-
435
-
436
-    /**
437
-     *        an array for storing key => value pairs of request actions and their corresponding methods
438
-     *
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _set_page_routes()
443
-    {
444
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
-
448
-        $this->_page_routes = [
449
-            'default'                          => [
450
-                'func'       => '_message_queue_list_table',
451
-                'capability' => 'ee_read_global_messages',
452
-            ],
453
-            'global_mtps'                      => [
454
-                'func'       => '_ee_default_messages_overview_list_table',
455
-                'capability' => 'ee_read_global_messages',
456
-            ],
457
-            'custom_mtps'                      => [
458
-                'func'       => '_custom_mtps_preview',
459
-                'capability' => 'ee_read_messages',
460
-            ],
461
-            'add_new_message_template'         => [
462
-                'func'       => 'add_message_template',
463
-                'capability' => 'ee_edit_messages',
464
-                'noheader'   => true,
465
-            ],
466
-            'edit_message_template'            => [
467
-                'func'       => '_edit_message_template',
468
-                'capability' => 'ee_edit_message',
469
-                'obj_id'     => $GRP_ID,
470
-            ],
471
-            'preview_message'                  => [
472
-                'func'               => '_preview_message',
473
-                'capability'         => 'ee_read_message',
474
-                'obj_id'             => $GRP_ID,
475
-                'noheader'           => true,
476
-                'headers_sent_route' => 'display_preview_message',
477
-            ],
478
-            'display_preview_message'          => [
479
-                'func'       => '_display_preview_message',
480
-                'capability' => 'ee_read_message',
481
-                'obj_id'     => $GRP_ID,
482
-            ],
483
-            'insert_message_template'          => [
484
-                'func'       => '_insert_or_update_message_template',
485
-                'capability' => 'ee_edit_messages',
486
-                'args'       => ['new' => true],
487
-                'noheader'   => true,
488
-            ],
489
-            'update_message_template'          => [
490
-                'func'       => '_insert_or_update_message_template',
491
-                'capability' => 'ee_edit_message',
492
-                'obj_id'     => $GRP_ID,
493
-                'args'       => ['new' => false],
494
-                'noheader'   => true,
495
-            ],
496
-            'trash_message_template'           => [
497
-                'func'       => '_trash_or_restore_message_template',
498
-                'capability' => 'ee_delete_message',
499
-                'obj_id'     => $GRP_ID,
500
-                'args'       => ['trash' => true, 'all' => true],
501
-                'noheader'   => true,
502
-            ],
503
-            'trash_message_template_context'   => [
504
-                'func'       => '_trash_or_restore_message_template',
505
-                'capability' => 'ee_delete_message',
506
-                'obj_id'     => $GRP_ID,
507
-                'args'       => ['trash' => true],
508
-                'noheader'   => true,
509
-            ],
510
-            'restore_message_template'         => [
511
-                'func'       => '_trash_or_restore_message_template',
512
-                'capability' => 'ee_delete_message',
513
-                'obj_id'     => $GRP_ID,
514
-                'args'       => ['trash' => false, 'all' => true],
515
-                'noheader'   => true,
516
-            ],
517
-            'restore_message_template_context' => [
518
-                'func'       => '_trash_or_restore_message_template',
519
-                'capability' => 'ee_delete_message',
520
-                'obj_id'     => $GRP_ID,
521
-                'args'       => ['trash' => false],
522
-                'noheader'   => true,
523
-            ],
524
-            'delete_message_template'          => [
525
-                'func'       => '_delete_message_template',
526
-                'capability' => 'ee_delete_message',
527
-                'obj_id'     => $GRP_ID,
528
-                'noheader'   => true,
529
-            ],
530
-            'reset_to_default'                 => [
531
-                'func'       => '_reset_to_default_template',
532
-                'capability' => 'ee_edit_message',
533
-                'obj_id'     => $GRP_ID,
534
-                'noheader'   => true,
535
-            ],
536
-            'settings'                         => [
537
-                'func'       => '_settings',
538
-                'capability' => 'manage_options',
539
-            ],
540
-            'update_global_settings'           => [
541
-                'func'       => '_update_global_settings',
542
-                'capability' => 'manage_options',
543
-                'noheader'   => true,
544
-            ],
545
-            'generate_now'                     => [
546
-                'func'       => '_generate_now',
547
-                'capability' => 'ee_send_message',
548
-                'noheader'   => true,
549
-            ],
550
-            'generate_and_send_now'            => [
551
-                'func'       => '_generate_and_send_now',
552
-                'capability' => 'ee_send_message',
553
-                'noheader'   => true,
554
-            ],
555
-            'queue_for_resending'              => [
556
-                'func'       => '_queue_for_resending',
557
-                'capability' => 'ee_send_message',
558
-                'noheader'   => true,
559
-            ],
560
-            'send_now'                         => [
561
-                'func'       => '_send_now',
562
-                'capability' => 'ee_send_message',
563
-                'noheader'   => true,
564
-            ],
565
-            'delete_ee_message'                => [
566
-                'func'       => '_delete_ee_messages',
567
-                'capability' => 'ee_delete_messages',
568
-                'noheader'   => true,
569
-            ],
570
-            'delete_ee_messages'               => [
571
-                'func'       => '_delete_ee_messages',
572
-                'capability' => 'ee_delete_messages',
573
-                'noheader'   => true,
574
-                'obj_id'     => $MSG_ID,
575
-            ],
576
-        ];
577
-    }
578
-
579
-
580
-    protected function _set_page_config()
581
-    {
582
-        $this->_page_config = [
583
-            'default'                  => [
584
-                'nav'           => [
585
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
586
-                    'order' => 10,
587
-                ],
588
-                'list_table'    => 'EE_Message_List_Table',
589
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
-                'require_nonce' => false,
591
-            ],
592
-            'global_mtps'              => [
593
-                'nav'           => [
594
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
-                    'order' => 20,
596
-                ],
597
-                'list_table'    => 'Messages_Template_List_Table',
598
-                'help_tabs'     => [
599
-                    'messages_overview_help_tab'                                => [
600
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
-                        'filename' => 'messages_overview',
602
-                    ],
603
-                    'messages_overview_messages_table_column_headings_help_tab' => [
604
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
-                        'filename' => 'messages_overview_table_column_headings',
606
-                    ],
607
-                    'messages_overview_messages_filters_help_tab'               => [
608
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
609
-                        'filename' => 'messages_overview_filters',
610
-                    ],
611
-                    'messages_overview_messages_views_help_tab'                 => [
612
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
613
-                        'filename' => 'messages_overview_views',
614
-                    ],
615
-                    'message_overview_message_types_help_tab'                   => [
616
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
617
-                        'filename' => 'messages_overview_types',
618
-                    ],
619
-                    'messages_overview_messengers_help_tab'                     => [
620
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
621
-                        'filename' => 'messages_overview_messengers',
622
-                    ],
623
-                ],
624
-                'require_nonce' => false,
625
-            ],
626
-            'custom_mtps'              => [
627
-                'nav'           => [
628
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
629
-                    'order' => 30,
630
-                ],
631
-                'help_tabs'     => [],
632
-                'require_nonce' => false,
633
-            ],
634
-            'add_new_message_template' => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
637
-                    'order'      => 5,
638
-                    'persistent' => false,
639
-                ],
640
-                'require_nonce' => false,
641
-            ],
642
-            'edit_message_template'    => [
643
-                'labels'        => [
644
-                    'buttons'    => [
645
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
646
-                    ],
647
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
648
-                ],
649
-                'nav'           => [
650
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
651
-                    'order'      => 5,
652
-                    'persistent' => false,
653
-                    'url'        => '',
654
-                ],
655
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
656
-                'has_metaboxes' => true,
657
-                'help_tabs'     => [
658
-                    'edit_message_template'            => [
659
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
660
-                        'callback' => 'edit_message_template_help_tab',
661
-                    ],
662
-                    'message_templates_help_tab'       => [
663
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
664
-                        'filename' => 'messages_templates',
665
-                    ],
666
-                    'message_template_shortcodes'      => [
667
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
668
-                        'callback' => 'message_template_shortcodes_help_tab',
669
-                    ],
670
-                    'message_preview_help_tab'         => [
671
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
672
-                        'filename' => 'messages_preview',
673
-                    ],
674
-                    'messages_overview_other_help_tab' => [
675
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
676
-                        'filename' => 'messages_overview_other',
677
-                    ],
678
-                ],
679
-                'require_nonce' => false,
680
-            ],
681
-            'display_preview_message'  => [
682
-                'nav'           => [
683
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
684
-                    'order'      => 5,
685
-                    'url'        => '',
686
-                    'persistent' => false,
687
-                ],
688
-                'help_tabs'     => [
689
-                    'preview_message' => [
690
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
691
-                        'callback' => 'preview_message_help_tab',
692
-                    ],
693
-                ],
694
-                'require_nonce' => false,
695
-            ],
696
-            'settings'                 => [
697
-                'nav'           => [
698
-                    'label' => esc_html__('Settings', 'event_espresso'),
699
-                    'order' => 40,
700
-                ],
701
-                'metaboxes'     => ['_messages_settings_metaboxes'],
702
-                'help_tabs'     => [
703
-                    'messages_settings_help_tab'               => [
704
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
705
-                        'filename' => 'messages_settings',
706
-                    ],
707
-                    'messages_settings_message_types_help_tab' => [
708
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
709
-                        'filename' => 'messages_settings_message_types',
710
-                    ],
711
-                    'messages_settings_messengers_help_tab'    => [
712
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
713
-                        'filename' => 'messages_settings_messengers',
714
-                    ],
715
-                ],
716
-                'require_nonce' => false,
717
-            ],
718
-        ];
719
-    }
720
-
721
-
722
-    protected function _add_screen_options()
723
-    {
724
-        // todo
725
-    }
726
-
727
-
728
-    protected function _add_screen_options_global_mtps()
729
-    {
730
-        /**
731
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
732
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
733
-         */
734
-        $page_title              = $this->_admin_page_title;
735
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
736
-        $this->_per_page_screen_option();
737
-        $this->_admin_page_title = $page_title;
738
-    }
739
-
740
-
741
-    protected function _add_screen_options_default()
742
-    {
743
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-    }
746
-
747
-
748
-    // none of the below group are currently used for Messages
749
-    protected function _add_feature_pointers()
750
-    {
751
-    }
752
-
753
-
754
-    public function admin_init()
755
-    {
756
-    }
757
-
758
-
759
-    public function admin_notices()
760
-    {
761
-    }
762
-
763
-
764
-    public function admin_footer_scripts()
765
-    {
766
-    }
767
-
768
-
769
-    public function messages_help_tab()
770
-    {
771
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
-    }
773
-
774
-
775
-    public function messengers_help_tab()
776
-    {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
-    }
779
-
780
-
781
-    public function message_types_help_tab()
782
-    {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
-    }
785
-
786
-
787
-    public function messages_overview_help_tab()
788
-    {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
-    }
791
-
792
-
793
-    public function message_templates_help_tab()
794
-    {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
-    }
797
-
798
-
799
-    public function edit_message_template_help_tab()
800
-    {
801
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
-                        . esc_attr__('Editor Title', 'event_espresso')
803
-                        . '" />';
804
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
806
-                        . '" />';
807
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
809
-                        . '" />';
810
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
812
-                        . '" />';
813
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
-                        . esc_attr__('Publish Metabox', 'event_espresso')
815
-                        . '" />';
816
-        EEH_Template::display_template(
817
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
-            $args
819
-        );
820
-    }
821
-
822
-
823
-    /**
824
-     * @throws ReflectionException
825
-     * @throws EE_Error
826
-     */
827
-    public function message_template_shortcodes_help_tab()
828
-    {
829
-        $this->_set_shortcodes();
830
-        $args['shortcodes'] = $this->_shortcodes;
831
-        EEH_Template::display_template(
832
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
-            $args
834
-        );
835
-    }
836
-
837
-
838
-    public function preview_message_help_tab()
839
-    {
840
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
-    }
842
-
843
-
844
-    public function settings_help_tab()
845
-    {
846
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
850
-        $args['img3'] = '<div class="switch">'
851
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852
-                        . ' type="checkbox" checked="checked">'
853
-                        . '<label for="ee-on-off-toggle-on"></label>'
854
-                        . '</div>';
855
-        $args['img4'] = '<div class="switch">'
856
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
857
-                        . ' type="checkbox">'
858
-                        . '<label for="ee-on-off-toggle-on"></label>'
859
-                        . '</div>';
860
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
-    }
862
-
863
-
864
-    public function load_scripts_styles()
865
-    {
866
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
-        wp_enqueue_style('espresso_ee_msg');
868
-
869
-        wp_register_script(
870
-            'ee-messages-settings',
871
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
873
-            EVENT_ESPRESSO_VERSION,
874
-            true
875
-        );
876
-        wp_register_script(
877
-            'ee-msg-list-table-js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
-            ['ee-dialog'],
880
-            EVENT_ESPRESSO_VERSION
881
-        );
882
-    }
883
-
884
-
885
-    public function load_scripts_styles_default()
886
-    {
887
-        wp_enqueue_script('ee-msg-list-table-js');
888
-    }
889
-
890
-
891
-    public function wp_editor_css($mce_css)
892
-    {
893
-        // if we're on the edit_message_template route
894
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
895
-            $message_type_name = $this->_active_message_type_name;
896
-
897
-            // we're going to REPLACE the existing mce css
898
-            // we need to get the css file location from the active messenger
899
-            $mce_css = $this->_active_messenger->get_variation(
900
-                $this->_template_pack,
901
-                $message_type_name,
902
-                true,
903
-                'wpeditor',
904
-                $this->_variation
905
-            );
906
-        }
907
-
908
-        return $mce_css;
909
-    }
910
-
911
-
912
-    /**
913
-     * @throws EE_Error
914
-     * @throws ReflectionException
915
-     */
916
-    public function load_scripts_styles_edit_message_template()
917
-    {
918
-
919
-        $this->_set_shortcodes();
920
-
921
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
-            esc_html__(
923
-                '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.',
924
-                'event_espresso'
925
-            ),
926
-            $this->_message_template_group->messenger_obj()->label['singular'],
927
-            $this->_message_template_group->message_type_obj()->label['singular']
928
-        );
929
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
930
-            '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?',
931
-            'event_espresso'
932
-        );
933
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935
-            'event_espresso'
936
-        );
937
-
938
-        wp_register_script(
939
-            'ee_msgs_edit_js',
940
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
-            ['jquery'],
942
-            EVENT_ESPRESSO_VERSION
943
-        );
944
-
945
-        wp_enqueue_script('ee_admin_js');
946
-        wp_enqueue_script('ee_msgs_edit_js');
947
-
948
-        // add in special css for tiny_mce
949
-        add_filter('mce_css', [$this, 'wp_editor_css']);
950
-    }
951
-
952
-
953
-    /**
954
-     * @throws EE_Error
955
-     * @throws ReflectionException
956
-     */
957
-    public function load_scripts_styles_display_preview_message()
958
-    {
959
-        $this->_set_message_template_group();
960
-        if ($this->_active_messenger_name) {
961
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
962
-                $this->_active_messenger_name
963
-            );
964
-        }
965
-
966
-        wp_enqueue_style(
967
-            'espresso_preview_css',
968
-            $this->_active_messenger->get_variation(
969
-                $this->_template_pack,
970
-                $this->_active_message_type_name,
971
-                true,
972
-                'preview',
973
-                $this->_variation
974
-            )
975
-        );
976
-    }
977
-
978
-
979
-    public function load_scripts_styles_settings()
980
-    {
981
-        wp_register_style(
982
-            'ee-message-settings',
983
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
-            [],
985
-            EVENT_ESPRESSO_VERSION
986
-        );
987
-        wp_enqueue_style('ee-text-links');
988
-        wp_enqueue_style('ee-message-settings');
989
-        wp_enqueue_script('ee-messages-settings');
990
-    }
991
-
992
-
993
-    /**
994
-     * set views array for List Table
995
-     */
996
-    public function _set_list_table_views_global_mtps()
997
-    {
998
-        $this->_views = [
999
-            'in_use' => [
1000
-                'slug'  => 'in_use',
1001
-                'label' => esc_html__('In Use', 'event_espresso'),
1002
-                'count' => 0,
1003
-            ],
1004
-        ];
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * Set views array for the Custom Template List Table
1010
-     */
1011
-    public function _set_list_table_views_custom_mtps()
1012
-    {
1013
-        $this->_set_list_table_views_global_mtps();
1014
-        $this->_views['in_use']['bulk_action'] = [
1015
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1016
-        ];
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * set views array for message queue list table
1022
-     *
1023
-     * @throws InvalidDataTypeException
1024
-     * @throws InvalidInterfaceException
1025
-     * @throws InvalidArgumentException
1026
-     * @throws EE_Error
1027
-     * @throws ReflectionException
1028
-     */
1029
-    public function _set_list_table_views_default()
1030
-    {
1031
-        EE_Registry::instance()->load_helper('Template');
1032
-
1033
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1034
-            'ee_send_message',
1035
-            'message_list_table_bulk_actions'
1036
-        )
1037
-            ? [
1038
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1039
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1040
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1041
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1042
-            ]
1043
-            : [];
1044
-
1045
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1046
-            'ee_delete_messages',
1047
-            'message_list_table_bulk_actions'
1048
-        )
1049
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1050
-            : [];
1051
-
1052
-
1053
-        $this->_views = [
1054
-            'all' => [
1055
-                'slug'        => 'all',
1056
-                'label'       => esc_html__('All', 'event_espresso'),
1057
-                'count'       => 0,
1058
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1059
-            ],
1060
-        ];
1061
-
1062
-
1063
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1064
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1065
-                continue;
1066
-            }
1067
-            $status_bulk_actions = $common_bulk_actions;
1068
-            // unset bulk actions not applying to status
1069
-            if (! empty($status_bulk_actions)) {
1070
-                switch ($status) {
1071
-                    case EEM_Message::status_idle:
1072
-                    case EEM_Message::status_resend:
1073
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1074
-                        break;
1075
-
1076
-                    case EEM_Message::status_failed:
1077
-                    case EEM_Message::status_debug_only:
1078
-                    case EEM_Message::status_messenger_executing:
1079
-                        $status_bulk_actions = [];
1080
-                        break;
1081
-
1082
-                    case EEM_Message::status_incomplete:
1083
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1084
-                        break;
1085
-
1086
-                    case EEM_Message::status_retry:
1087
-                    case EEM_Message::status_sent:
1088
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1089
-                        break;
1090
-                }
1091
-            }
1092
-
1093
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1094
-            if ($status === EEM_Message::status_messenger_executing) {
1095
-                continue;
1096
-            }
1097
-
1098
-            $this->_views[ strtolower($status) ] = [
1099
-                'slug'        => strtolower($status),
1100
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101
-                'count'       => 0,
1102
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1103
-            ];
1104
-        }
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * @throws EE_Error
1110
-     */
1111
-    protected function _ee_default_messages_overview_list_table()
1112
-    {
1113
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1114
-        $this->display_admin_list_table_page_with_no_sidebar();
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * @throws EE_Error
1120
-     * @throws ReflectionException
1121
-     */
1122
-    protected function _message_queue_list_table()
1123
-    {
1124
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1125
-        $this->_template_args['per_column']        = 6;
1126
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1127
-        $this->_template_args['before_list_table'] = '<h3>'
1128
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1129
-                                                     . '</h3>';
1130
-        $this->display_admin_list_table_page_with_no_sidebar();
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @throws EE_Error
1136
-     */
1137
-    protected function _message_legend_items()
1138
-    {
1139
-
1140
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
-        $action_items       = [];
1142
-
1143
-        foreach ($action_css_classes as $action_item => $action_details) {
1144
-            if ($action_item === 'see_notifications_for') {
1145
-                continue;
1146
-            }
1147
-            $action_items[ $action_item ] = [
1148
-                'class' => $action_details['css_class'],
1149
-                'desc'  => $action_details['label'],
1150
-            ];
1151
-        }
1152
-
1153
-        /** @var array $status_items status legend setup */
1154
-        $status_items = [
1155
-            'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
-            ],
1159
-            'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
-            ],
1163
-            'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
-            ],
1167
-            'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
-            ],
1171
-            'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
-            ],
1175
-            'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
-            ],
1179
-            'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
-            ],
1183
-        ];
1184
-        if (EEM_Message::debug()) {
1185
-            $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
-            ];
1189
-        }
1190
-
1191
-        return array_merge($action_items, $status_items);
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * @throws EE_Error
1197
-     */
1198
-    protected function _custom_mtps_preview()
1199
-    {
1200
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1203
-                                                    'Preview Custom Message Templates screenshot',
1204
-                                                    'event_espresso'
1205
-                                                ) . '" />';
1206
-        $this->_template_args['preview_text'] = '<strong>'
1207
-                                                . esc_html__(
1208
-                                                    '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.',
1209
-                                                    'event_espresso'
1210
-                                                )
1211
-                                                . '</strong>';
1212
-
1213
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * get_message_templates
1219
-     * This gets all the message templates for listing on the overview list.
1220
-     *
1221
-     * @access public
1222
-     * @param int    $per_page the amount of templates groups to show per page
1223
-     * @param string $type     the current _view we're getting templates for
1224
-     * @param bool   $count    return count?
1225
-     * @param bool   $all      disregard any paging info (get all data);
1226
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
-     * @return array
1228
-     * @throws EE_Error
1229
-     * @throws InvalidArgumentException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws InvalidInterfaceException
1232
-     */
1233
-    public function get_message_templates(
1234
-        $per_page = 10,
1235
-        $type = 'in_use',
1236
-        $count = false,
1237
-        $all = false,
1238
-        $global = true
1239
-    ) {
1240
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
-        $this->request->setRequestParam('orderby', $orderby);
1242
-
1243
-        $order        = $this->request->getRequestParam('order', 'ASC');
1244
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
-
1247
-        $offset = ($current_page - 1) * $per_page;
1248
-        $limit  = $all ? null : [$offset, $per_page];
1249
-
1250
-        // options will match what is in the _views array property
1251
-        return $type === 'in_use'
1252
-            ? $this->getMtgModel()->get_all_active_message_templates(
1253
-                $orderby,
1254
-                $order,
1255
-                $limit,
1256
-                $count,
1257
-                $global,
1258
-                true
1259
-            )
1260
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
-                $orderby,
1262
-                $order,
1263
-                $limit,
1264
-                $count,
1265
-                $global
1266
-            );
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * filters etc might need a list of installed message_types
1272
-     *
1273
-     * @return array an array of message type objects
1274
-     */
1275
-    public function get_installed_message_types()
1276
-    {
1277
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
-        $installed               = [];
1279
-
1280
-        foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1282
-        }
1283
-
1284
-        return $installed;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1290
-     *
1291
-     * @param string $message_type
1292
-     * @param string $messenger
1293
-     * @param string $GRP_ID
1294
-     *
1295
-     * @throws EE_error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
-    {
1300
-        // set values override any request data
1301
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
-
1305
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
-        if (empty($message_type) || empty($messenger)) {
1307
-            throw new EE_Error(
1308
-                esc_html__(
1309
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
-                    'event_espresso'
1311
-                )
1312
-            );
1313
-        }
1314
-
1315
-        // we need the GRP_ID for the template being used as the base for the new template
1316
-        if (empty($GRP_ID)) {
1317
-            throw new EE_Error(
1318
-                esc_html__(
1319
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
-                    'event_espresso'
1321
-                )
1322
-            );
1323
-        }
1324
-
1325
-        // let's just make sure the template gets generated!
1326
-
1327
-        // we need to reassign some variables for what the insert is expecting
1328
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1329
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1330
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
-
1332
-        $this->_insert_or_update_message_template(true);
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * @param string $message_type     message type slug
1338
-     * @param string $messenger        messenger slug
1339
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
-     *                                 off of.
1341
-     * @throws EE_error
1342
-     * @throws ReflectionException
1343
-     * @deprecated 4.10.29.p
1344
-     */
1345
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
-    {
1347
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * _edit_message_template
1353
-     *
1354
-     * @access protected
1355
-     * @return void
1356
-     * @throws InvalidIdentifierException
1357
-     * @throws DomainException
1358
-     * @throws EE_Error
1359
-     * @throws InvalidArgumentException
1360
-     * @throws ReflectionException
1361
-     * @throws InvalidDataTypeException
1362
-     * @throws InvalidInterfaceException
1363
-     */
1364
-    protected function _edit_message_template()
1365
-    {
1366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
-        $template_fields = '';
1368
-        $sidebar_fields  = '';
1369
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
-        // valid html in the templates.
1371
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
-
1373
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
-
1376
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1377
-        $message_template_group = $this->_message_template_group;
1378
-        $c_label                = $message_template_group->context_label();
1379
-        $c_config               = $message_template_group->contexts_config();
1380
-
1381
-        reset($c_config);
1382
-        $context = $this->request->getRequestParam('context', key($c_config));
1383
-        $context = strtolower($context);
1384
-
1385
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
-
1387
-        $edit_message_template_form_url = add_query_arg(
1388
-            ['action' => $action, 'noheader' => true],
1389
-            EE_MSG_ADMIN_URL
1390
-        );
1391
-
1392
-        // set active messenger for this view
1393
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
-            $message_template_group->messenger()
1395
-        );
1396
-        $this->_active_message_type_name = $message_template_group->message_type();
1397
-
1398
-
1399
-        // Do we have any validation errors?
1400
-        $validators = $this->_get_transient();
1401
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
-
1403
-
1404
-        // we need to assemble the title from Various details
1405
-        $context_label = sprintf(
1406
-            esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1408
-            ucwords($c_label['label'])
1409
-        );
1410
-
1411
-        $title = sprintf(
1412
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1413
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1414
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1415
-            $context_label
1416
-        );
1417
-
1418
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1419
-        $this->_template_args['message_template'] = $message_template_group;
1420
-        $this->_template_args['is_extra_fields']  = false;
1421
-
1422
-
1423
-        // let's get EEH_MSG_Template so we can get template form fields
1424
-        $template_field_structure = EEH_MSG_Template::get_fields(
1425
-            $message_template_group->messenger(),
1426
-            $message_template_group->message_type()
1427
-        );
1428
-
1429
-        if (! $template_field_structure) {
1430
-            $template_field_structure = false;
1431
-            $template_fields          = esc_html__(
1432
-                'There was an error in assembling the fields for this display (you should see an error message)',
1433
-                'event_espresso'
1434
-            );
1435
-        }
1436
-
1437
-
1438
-        $message_templates = $message_template_group->context_templates();
1439
-
1440
-
1441
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
-        // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1446
-            }
1447
-        }
1448
-
1449
-        // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
-                // the extra array and reset them.
1454
-                if ($template_field === 'extra') {
1455
-                    $this->_template_args['is_extra_fields'] = true;
1456
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
-                        $content          = $message_template instanceof EE_Message_Template
1459
-                            ? $message_template->get('MTP_content')
1460
-                            : '';
1461
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1462
-                            // let's verify if we need this extra field via the shortcodes parameter.
1463
-                            $continue = false;
1464
-                            if (isset($extra_array['shortcodes_required'])) {
1465
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
-                                        $continue = true;
1468
-                                    }
1469
-                                }
1470
-                                if ($continue) {
1471
-                                    continue;
1472
-                                }
1473
-                            }
1474
-
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
-
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
-                                                                         . $reference_field
1480
-                                                                         . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1483
-                                ? $extra_array['css_class']
1484
-                                : '';
1485
-
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
-                                                                              && in_array($extra_field, $v_fields, true)
1488
-                                                                              && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1491
-                                                                              )
1492
-                                ? 'validate-error ' . $css_class
1493
-                                : $css_class;
1494
-
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1498
-                                : '';
1499
-
1500
-                            // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1504
-
1505
-
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
-
1508
-                            // shortcode selector
1509
-                            $field_name_to_use                                   = $extra_field === 'main'
1510
-                                ? 'content'
1511
-                                : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
-                                $field_name_to_use,
1514
-                                $field_id
1515
-                            );
1516
-                        }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1519
-
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
-                            'label'      => null,
1523
-                            'input'      => 'hidden',
1524
-                            'type'       => 'int',
1525
-                            'required'   => false,
1526
-                            'validation' => false,
1527
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
-                            'css_class'  => '',
1529
-                            'format'     => '%d',
1530
-                            'db-col'     => 'MTP_ID',
1531
-                        ];
1532
-
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
-                            'label'      => null,
1536
-                            'input'      => 'hidden',
1537
-                            'type'       => 'string',
1538
-                            'required'   => false,
1539
-                            'validation' => true,
1540
-                            'value'      => $reference_field,
1541
-                            'css_class'  => '',
1542
-                            'format'     => '%s',
1543
-                            'db-col'     => 'MTP_template_field',
1544
-                        ];
1545
-                    }
1546
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
-                } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1552
-                    $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1555
-                            : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1558
-                                                                  && $message_template instanceof EE_Message_Template
1559
-                        ? $message_template->get('MTP_content')
1560
-                        : '';
1561
-
1562
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1566
-
1567
-
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
-                    $css_class                                      = isset($field_setup_array['css_class'])
1570
-                        ? $field_setup_array['css_class']
1571
-                        : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
-                                                                      && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1576
-                        : $css_class;
1577
-
1578
-                    // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
-                        $template_field,
1581
-                        $field_id
1582
-                    );
1583
-                }
1584
-
1585
-                // k took care of content field(s) now let's take care of others.
1586
-
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1589
-
1590
-                // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
-                    'label'      => null,
1594
-                    'input'      => 'hidden',
1595
-                    'type'       => 'int',
1596
-                    'required'   => false,
1597
-                    'validation' => true,
1598
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
-                    'css_class'  => '',
1600
-                    'format'     => '%d',
1601
-                    'db-col'     => 'MTP_ID',
1602
-                ];
1603
-
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
-                    'label'      => null,
1607
-                    'input'      => 'hidden',
1608
-                    'type'       => 'string',
1609
-                    'required'   => false,
1610
-                    'validation' => true,
1611
-                    'value'      => $template_field,
1612
-                    'css_class'  => '',
1613
-                    'format'     => '%s',
1614
-                    'db-col'     => 'MTP_template_field',
1615
-                ];
1616
-            }
1617
-
1618
-            // add other fields
1619
-            $template_form_fields['ee-msg-current-context'] = [
1620
-                'name'       => 'MTP_context',
1621
-                'label'      => null,
1622
-                'input'      => 'hidden',
1623
-                'type'       => 'string',
1624
-                'required'   => false,
1625
-                'validation' => true,
1626
-                'value'      => $context,
1627
-                'css_class'  => '',
1628
-                'format'     => '%s',
1629
-                'db-col'     => 'MTP_context',
1630
-            ];
1631
-
1632
-            $template_form_fields['ee-msg-grp-id'] = [
1633
-                'name'       => 'GRP_ID',
1634
-                'label'      => null,
1635
-                'input'      => 'hidden',
1636
-                'type'       => 'int',
1637
-                'required'   => false,
1638
-                'validation' => true,
1639
-                'value'      => $GRP_ID,
1640
-                'css_class'  => '',
1641
-                'format'     => '%d',
1642
-                'db-col'     => 'GRP_ID',
1643
-            ];
1644
-
1645
-            $template_form_fields['ee-msg-messenger'] = [
1646
-                'name'       => 'MTP_messenger',
1647
-                'label'      => null,
1648
-                'input'      => 'hidden',
1649
-                'type'       => 'string',
1650
-                'required'   => false,
1651
-                'validation' => true,
1652
-                'value'      => $message_template_group->messenger(),
1653
-                'css_class'  => '',
1654
-                'format'     => '%s',
1655
-                'db-col'     => 'MTP_messenger',
1656
-            ];
1657
-
1658
-            $template_form_fields['ee-msg-message-type'] = [
1659
-                'name'       => 'MTP_message_type',
1660
-                'label'      => null,
1661
-                'input'      => 'hidden',
1662
-                'type'       => 'string',
1663
-                'required'   => false,
1664
-                'validation' => true,
1665
-                'value'      => $message_template_group->message_type(),
1666
-                'css_class'  => '',
1667
-                'format'     => '%s',
1668
-                'db-col'     => 'MTP_message_type',
1669
-            ];
1670
-
1671
-            $sidebar_form_fields['ee-msg-is-global'] = [
1672
-                'name'       => 'MTP_is_global',
1673
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1674
-                'input'      => 'hidden',
1675
-                'type'       => 'int',
1676
-                'required'   => false,
1677
-                'validation' => true,
1678
-                'value'      => $message_template_group->get('MTP_is_global'),
1679
-                'css_class'  => '',
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_is_global',
1682
-            ];
1683
-
1684
-            $sidebar_form_fields['ee-msg-is-override'] = [
1685
-                'name'       => 'MTP_is_override',
1686
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
-                'type'       => 'int',
1689
-                'required'   => false,
1690
-                'validation' => true,
1691
-                'value'      => $message_template_group->get('MTP_is_override'),
1692
-                'css_class'  => '',
1693
-                'format'     => '%d',
1694
-                'db-col'     => 'MTP_is_override',
1695
-            ];
1696
-
1697
-            $sidebar_form_fields['ee-msg-is-active'] = [
1698
-                'name'       => 'MTP_is_active',
1699
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1700
-                'input'      => 'hidden',
1701
-                'type'       => 'int',
1702
-                'required'   => false,
1703
-                'validation' => true,
1704
-                'value'      => $message_template_group->is_active(),
1705
-                'css_class'  => '',
1706
-                'format'     => '%d',
1707
-                'db-col'     => 'MTP_is_active',
1708
-            ];
1709
-
1710
-            $sidebar_form_fields['ee-msg-deleted'] = [
1711
-                'name'       => 'MTP_deleted',
1712
-                'label'      => null,
1713
-                'input'      => 'hidden',
1714
-                'type'       => 'int',
1715
-                'required'   => false,
1716
-                'validation' => true,
1717
-                'value'      => $message_template_group->get('MTP_deleted'),
1718
-                'css_class'  => '',
1719
-                'format'     => '%d',
1720
-                'db-col'     => 'MTP_deleted',
1721
-            ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1723
-                'name'       => 'MTP_user_id',
1724
-                'label'      => esc_html__('Author', 'event_espresso'),
1725
-                'input'      => 'hidden',
1726
-                'type'       => 'int',
1727
-                'required'   => false,
1728
-                'validation' => false,
1729
-                'value'      => $message_template_group->user(),
1730
-                'format'     => '%d',
1731
-                'db-col'     => 'MTP_user_id',
1732
-            ];
1733
-
1734
-            $sidebar_form_fields['ee-msg-route'] = [
1735
-                'name'  => 'action',
1736
-                'input' => 'hidden',
1737
-                'type'  => 'string',
1738
-                'value' => $action,
1739
-            ];
1740
-
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1742
-                'name'  => 'id',
1743
-                'input' => 'hidden',
1744
-                'type'  => 'int',
1745
-                'value' => $GRP_ID,
1746
-            ];
1747
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1749
-                'input' => 'hidden',
1750
-                'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1752
-            ];
1753
-
1754
-            $template_switch = $this->request->getRequestParam('template_switch');
1755
-            if ($template_switch) {
1756
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1757
-                    'name'  => 'template_switch',
1758
-                    'input' => 'hidden',
1759
-                    'type'  => 'int',
1760
-                    'value' => 1,
1761
-                ];
1762
-            }
1763
-
1764
-
1765
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
-        } //end if ( !empty($template_field_structure) )
1768
-
1769
-        // set extra content for publish box
1770
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
-        $this->_set_publish_post_box_vars(
1772
-            'id',
1773
-            $GRP_ID,
1774
-            false,
1775
-            add_query_arg(
1776
-                ['action' => 'global_mtps'],
1777
-                $this->_admin_base_url
1778
-            )
1779
-        );
1780
-
1781
-        // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1783
-            [
1784
-                'message_type' => $message_template_group->message_type(),
1785
-                'messenger'    => $message_template_group->messenger(),
1786
-                'context'      => $context,
1787
-                'GRP_ID'       => $GRP_ID,
1788
-                'evt_id'       => $EVT_ID ?: false,
1789
-                'action'       => 'preview_message',
1790
-            ],
1791
-            $this->_admin_base_url
1792
-        );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
-                          . esc_html__('Preview', 'event_espresso')
1795
-                          . '</a>';
1796
-
1797
-
1798
-        // setup context switcher
1799
-        $this->_set_context_switcher(
1800
-            $message_template_group,
1801
-            [
1802
-                'page'    => 'espresso_messages',
1803
-                'action'  => 'edit_message_template',
1804
-                'id'      => $GRP_ID,
1805
-                'evt_id'  => $EVT_ID,
1806
-                'context' => $context,
1807
-                'extra'   => $preview_button,
1808
-            ]
1809
-        );
1810
-
1811
-
1812
-        // main box
1813
-        $this->_template_args['template_fields']                         = $template_fields;
1814
-        $this->_template_args['sidebar_box_id']                          = 'details';
1815
-        $this->_template_args['action']                                  = $action;
1816
-        $this->_template_args['context']                                 = $context;
1817
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
-        $this->_template_args['learn_more_about_message_templates_link'] =
1819
-            $this->_learn_more_about_message_templates_link();
1820
-
1821
-
1822
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1823
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
-            $message_template_group,
1825
-            $context,
1826
-            $context_label
1827
-        );
1828
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
-
1831
-        $this->_template_path = $this->_template_args['GRP_ID']
1832
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
-
1835
-        // send along EE_Message_Template_Group object for further template use.
1836
-        $this->_template_args['MTP'] = $message_template_group;
1837
-
1838
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1839
-            $this->_template_path,
1840
-            $this->_template_args,
1841
-            true
1842
-        );
1843
-
1844
-
1845
-        // finally, let's set the admin_page title
1846
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1847
-
1848
-
1849
-        // we need to take care of setting the shortcodes property for use elsewhere.
1850
-        $this->_set_shortcodes();
1851
-
1852
-
1853
-        // final template wrapper
1854
-        $this->display_admin_page_with_sidebar();
1855
-    }
1856
-
1857
-
1858
-    public function filter_tinymce_init($mceInit, $editor_id)
1859
-    {
1860
-        return $mceInit;
1861
-    }
1862
-
1863
-
1864
-    public function add_context_switcher()
1865
-    {
1866
-        return $this->_context_switcher;
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     * Adds the activation/deactivation toggle for the message template context.
1872
-     *
1873
-     * @param EE_Message_Template_Group $message_template_group
1874
-     * @param string                    $context
1875
-     * @param string                    $context_label
1876
-     * @return string
1877
-     * @throws DomainException
1878
-     * @throws EE_Error
1879
-     * @throws InvalidIdentifierException
1880
-     * @throws ReflectionException
1881
-     */
1882
-    protected function add_active_context_element(
1883
-        EE_Message_Template_Group $message_template_group,
1884
-        $context,
1885
-        $context_label
1886
-    ) {
1887
-        $template_args = [
1888
-            'context'                   => $context,
1889
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
-            'is_active'                 => $message_template_group->is_context_active($context),
1891
-            'on_off_action'             => $message_template_group->is_context_active($context)
1892
-                ? 'context-off'
1893
-                : 'context-on',
1894
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1895
-            'message_template_group_id' => $message_template_group->ID(),
1896
-        ];
1897
-        return EEH_Template::display_template(
1898
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
-            $template_args,
1900
-            true
1901
-        );
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * Ajax callback for `toggle_context_template` ajax action.
1907
-     * Handles toggling the message context on or off.
1908
-     *
1909
-     * @throws EE_Error
1910
-     * @throws InvalidArgumentException
1911
-     * @throws InvalidDataTypeException
1912
-     * @throws InvalidIdentifierException
1913
-     * @throws InvalidInterfaceException
1914
-     */
1915
-    public function toggle_context_template()
1916
-    {
1917
-        $success = true;
1918
-        // check for required data
1919
-        if (
1920
-            ! (
1921
-                $this->request->requestParamIsSet('message_template_group_id')
1922
-                && $this->request->requestParamIsSet('context')
1923
-                && $this->request->requestParamIsSet('status')
1924
-            )
1925
-        ) {
1926
-            EE_Error::add_error(
1927
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1928
-                __FILE__,
1929
-                __FUNCTION__,
1930
-                __LINE__
1931
-            );
1932
-            $success = false;
1933
-        }
1934
-
1935
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1936
-        $context = $this->request->getRequestParam('context', '');
1937
-        $status  = $this->request->getRequestParam('status', '');
1938
-
1939
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1940
-
1941
-        if ($status !== 'off' && $status !== 'on') {
1942
-            EE_Error::add_error(
1943
-                sprintf(
1944
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1945
-                    $status
1946
-                ),
1947
-                __FILE__,
1948
-                __FUNCTION__,
1949
-                __LINE__
1950
-            );
1951
-            $success = false;
1952
-        }
1953
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
-            EE_Error::add_error(
1957
-                sprintf(
1958
-                    esc_html__(
1959
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1960
-                        'event_espresso'
1961
-                    ),
1962
-                    $message_template_group_id,
1963
-                    'EE_Message_Template_Group'
1964
-                ),
1965
-                __FILE__,
1966
-                __FUNCTION__,
1967
-                __LINE__
1968
-            );
1969
-            $success = false;
1970
-        }
1971
-        if ($success) {
1972
-            $success = $status === 'off'
1973
-                ? $message_template_group->deactivate_context($context)
1974
-                : $message_template_group->activate_context($context);
1975
-        }
1976
-        $this->_template_args['success'] = $success;
1977
-        $this->_return_json();
1978
-    }
1979
-
1980
-
1981
-    public function _add_form_element_before()
1982
-    {
1983
-        return '<form method="post" action="'
1984
-               . $this->_template_args['edit_message_template_form_url']
1985
-               . '" id="ee-msg-edit-frm">';
1986
-    }
1987
-
1988
-
1989
-    public function _add_form_element_after()
1990
-    {
1991
-        return '</form>';
1992
-    }
1993
-
1994
-
1995
-    /**
1996
-     * This executes switching the template pack for a message template.
1997
-     *
1998
-     * @throws EE_Error
1999
-     * @throws InvalidDataTypeException
2000
-     * @throws InvalidInterfaceException
2001
-     * @throws InvalidArgumentException
2002
-     * @throws ReflectionException
2003
-     * @since 4.5.0
2004
-     */
2005
-    public function switch_template_pack()
2006
-    {
2007
-
2008
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2009
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2010
-
2011
-        // verify we have needed values.
2012
-        if (empty($GRP_ID) || empty($template_pack)) {
2013
-            $this->_template_args['error'] = true;
2014
-            EE_Error::add_error(
2015
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2016
-                __FILE__,
2017
-                __FUNCTION__,
2018
-                __LINE__
2019
-            );
2020
-        } else {
2021
-            // get template, set the new template_pack and then reset to default
2022
-            /** @var EE_Message_Template_Group $message_template_group */
2023
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2024
-
2025
-            $message_template_group->set_template_pack_name($template_pack);
2026
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2027
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2028
-
2029
-            $query_args = $this->_reset_to_default_template();
2030
-
2031
-            if (empty($query_args['id'])) {
2032
-                EE_Error::add_error(
2033
-                    esc_html__(
2034
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2035
-                        'event_espresso'
2036
-                    ),
2037
-                    __FILE__,
2038
-                    __FUNCTION__,
2039
-                    __LINE__
2040
-                );
2041
-                $this->_template_args['error'] = true;
2042
-            } else {
2043
-                $template_label       = $message_template_group->get_template_pack()->label;
2044
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2045
-                EE_Error::add_success(
2046
-                    sprintf(
2047
-                        esc_html__(
2048
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2049
-                            'event_espresso'
2050
-                        ),
2051
-                        $template_label,
2052
-                        $template_pack_labels->template_pack
2053
-                    )
2054
-                );
2055
-                // generate the redirect url for js.
2056
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2057
-
2058
-                $this->_template_args['data']['redirect_url'] = $url;
2059
-                $this->_template_args['success']              = true;
2060
-            }
2061
-
2062
-            $this->_return_json();
2063
-        }
2064
-    }
2065
-
2066
-
2067
-    /**
2068
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2069
-     * they want.
2070
-     *
2071
-     * @access protected
2072
-     * @return array|void
2073
-     * @throws EE_Error
2074
-     * @throws InvalidArgumentException
2075
-     * @throws InvalidDataTypeException
2076
-     * @throws InvalidInterfaceException
2077
-     * @throws ReflectionException
2078
-     */
2079
-    protected function _reset_to_default_template()
2080
-    {
2081
-        $templates    = [];
2082
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2083
-        $messenger    = $this->request->getRequestParam('msgr');
2084
-        $message_type = $this->request->getRequestParam('mt');
2085
-        // we need to make sure we've got the info we need.
2086
-        if (! ($GRP_ID && $messenger && $message_type)) {
2087
-            EE_Error::add_error(
2088
-                esc_html__(
2089
-                    '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.',
2090
-                    'event_espresso'
2091
-                ),
2092
-                __FILE__,
2093
-                __FUNCTION__,
2094
-                __LINE__
2095
-            );
2096
-        }
2097
-
2098
-        // all templates will be reset to whatever the defaults are
2099
-        // for the global template matching the messenger and message type.
2100
-        $success = ! empty($GRP_ID);
2101
-
2102
-        if ($success) {
2103
-            // let's first determine if the incoming template is a global template,
2104
-            // if it isn't then we need to get the global template matching messenger and message type.
2105
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2106
-
2107
-
2108
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2109
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2110
-
2111
-            if ($success) {
2112
-                // if successfully deleted, lets generate the new ones.
2113
-                // Note. We set GLOBAL to true, because resets on ANY template
2114
-                // will use the related global template defaults for regeneration.
2115
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2116
-                // HOWEVER, we DO keep the template pack and template variation set
2117
-                // for the current custom template when resetting.
2118
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2119
-            }
2120
-        }
2121
-
2122
-        // any error messages?
2123
-        if (! $success) {
2124
-            EE_Error::add_error(
2125
-                esc_html__(
2126
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2127
-                    'event_espresso'
2128
-                ),
2129
-                __FILE__,
2130
-                __FUNCTION__,
2131
-                __LINE__
2132
-            );
2133
-        }
2134
-
2135
-        // all good, let's add a success message!
2136
-        if ($success && ! empty($templates)) {
2137
-            // the info for the template we generated is the first element in the returned array
2138
-            EE_Error::overwrite_success();
2139
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2140
-        }
2141
-
2142
-
2143
-        $query_args = [
2144
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2145
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2146
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2147
-        ];
2148
-
2149
-        // if called via ajax then we return query args otherwise redirect
2150
-        if ($this->request->isAjax()) {
2151
-            return $query_args;
2152
-        }
2153
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2154
-    }
2155
-
2156
-
2157
-    /**
2158
-     * Retrieve and set the message preview for display.
2159
-     *
2160
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2161
-     * @return string
2162
-     * @throws ReflectionException
2163
-     * @throws EE_Error
2164
-     * @throws InvalidArgumentException
2165
-     * @throws InvalidDataTypeException
2166
-     * @throws InvalidInterfaceException
2167
-     */
2168
-    public function _preview_message($send = false)
2169
-    {
2170
-        // first make sure we've got the necessary parameters
2171
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
-            EE_Error::add_error(
2174
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175
-                __FILE__,
2176
-                __FUNCTION__,
2177
-                __LINE__
2178
-            );
2179
-        }
2180
-
2181
-        $context = $this->request->getRequestParam('context');
2182
-        // get the preview!
2183
-        $preview = EED_Messages::preview_message(
2184
-            $this->_active_message_type_name,
2185
-            $context,
2186
-            $this->_active_messenger_name,
2187
-            $send
2188
-        );
2189
-
2190
-        if ($send) {
2191
-            return $preview;
2192
-        }
2193
-
2194
-        // if we have an evt_id set on the request, use it.
2195
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196
-
2197
-        // let's add a button to go back to the edit view
2198
-        $query_args             = [
2199
-            'id'      => $GRP_ID,
2200
-            'evt_id'  => $EVT_ID,
2201
-            'context' => $context,
2202
-            'action'  => 'edit_message_template',
2203
-        ];
2204
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2205
-        $preview_button         = '<a href="'
2206
-                                  . $go_back_url
2207
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2208
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2209
-                                  . '</a>';
2210
-        $message_types          = $this->get_installed_message_types();
2211
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2212
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2213
-            ? ucwords($active_messenger->label['singular'])
2214
-            : esc_html__('Unknown Messenger', 'event_espresso');
2215
-        // let's provide a helpful title for context
2216
-        $preview_title = sprintf(
2217
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218
-            $active_messenger_label,
2219
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
-        );
2221
-        if (empty($preview)) {
2222
-            $this->noEventsErrorMessage();
2223
-        }
2224
-        // setup display of preview.
2225
-        $this->_admin_page_title                    = $preview_title;
2226
-        $this->_template_args['admin_page_title']   = $preview_title;
2227
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
-        $this->_template_args['data']['force_json'] = true;
2229
-
2230
-        return '';
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * Used to set an error if there are no events available for generating a preview/test send.
2236
-     *
2237
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2238
-     */
2239
-    protected function noEventsErrorMessage($test_send = false)
2240
-    {
2241
-        $events_url = parent::add_query_args_and_nonce(
2242
-            [
2243
-                'action' => 'default',
2244
-                'page'   => 'espresso_events',
2245
-            ],
2246
-            admin_url('admin.php')
2247
-        );
2248
-        $message    = $test_send
2249
-            ? esc_html__(
2250
-                '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!',
2251
-                'event_espresso'
2252
-            )
2253
-            : esc_html__(
2254
-                '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!',
2255
-                'event_espresso'
2256
-            );
2257
-
2258
-        EE_Error::add_attention(
2259
-            sprintf(
2260
-                $message,
2261
-                "<a href='{$events_url}'>",
2262
-                '</a>'
2263
-            )
2264
-        );
2265
-    }
2266
-
2267
-
2268
-    /**
2269
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2270
-     * gets called automatically.
2271
-     *
2272
-     * @return void
2273
-     * @throws EE_Error
2274
-     * @since 4.5.0
2275
-     *
2276
-     */
2277
-    protected function _display_preview_message()
2278
-    {
2279
-        $this->display_admin_page_with_no_sidebar();
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * registers metaboxes that should show up on the "edit_message_template" page
2285
-     *
2286
-     * @access protected
2287
-     * @return void
2288
-     */
2289
-    protected function _register_edit_meta_boxes()
2290
-    {
2291
-        add_meta_box(
2292
-            'mtp_valid_shortcodes',
2293
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2294
-            [$this, 'shortcode_meta_box'],
2295
-            $this->_current_screen->id,
2296
-            'side'
2297
-        );
2298
-        add_meta_box(
2299
-            'mtp_extra_actions',
2300
-            esc_html__('Extra Actions', 'event_espresso'),
2301
-            [$this, 'extra_actions_meta_box'],
2302
-            $this->_current_screen->id,
2303
-            'side',
2304
-            'high'
2305
-        );
2306
-        add_meta_box(
2307
-            'mtp_templates',
2308
-            esc_html__('Template Styles', 'event_espresso'),
2309
-            [$this, 'template_pack_meta_box'],
2310
-            $this->_current_screen->id,
2311
-            'side',
2312
-            'high'
2313
-        );
2314
-    }
2315
-
2316
-
2317
-    /**
2318
-     * metabox content for all template pack and variation selection.
2319
-     *
2320
-     * @return void
2321
-     * @throws DomainException
2322
-     * @throws EE_Error
2323
-     * @throws InvalidArgumentException
2324
-     * @throws ReflectionException
2325
-     * @throws InvalidDataTypeException
2326
-     * @throws InvalidInterfaceException
2327
-     * @since 4.5.0
2328
-     */
2329
-    public function template_pack_meta_box()
2330
-    {
2331
-        $this->_set_message_template_group();
2332
-
2333
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2334
-
2335
-        $tp_select_values = [];
2336
-
2337
-        foreach ($tp_collection as $tp) {
2338
-            // only include template packs that support this messenger and message type!
2339
-            $supports = $tp->get_supports();
2340
-            if (
2341
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2342
-                || ! in_array(
2343
-                    $this->_message_template_group->message_type(),
2344
-                    $supports[ $this->_message_template_group->messenger() ],
2345
-                    true
2346
-                )
2347
-            ) {
2348
-                // not supported
2349
-                continue;
2350
-            }
2351
-
2352
-            $tp_select_values[] = [
2353
-                'text' => $tp->label,
2354
-                'id'   => $tp->dbref,
2355
-            ];
2356
-        }
2357
-
2358
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2359
-        // the default template pack.  This still allows for the odd template pack to override.
2360
-        if (empty($tp_select_values)) {
2361
-            $tp_select_values[] = [
2362
-                'text' => esc_html__('Default', 'event_espresso'),
2363
-                'id'   => 'default',
2364
-            ];
2365
-        }
2366
-
2367
-        // setup variation select values for the currently selected template.
2368
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
-            $this->_message_template_group->messenger(),
2370
-            $this->_message_template_group->message_type()
2371
-        );
2372
-        $variations_select_values = [];
2373
-        foreach ($variations as $variation => $label) {
2374
-            $variations_select_values[] = [
2375
-                'text' => $label,
2376
-                'id'   => $variation,
2377
-            ];
2378
-        }
2379
-
2380
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381
-
2382
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
-            'MTP_template_pack',
2384
-            $tp_select_values,
2385
-            $this->_message_template_group->get_template_pack_name()
2386
-        );
2387
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
-            'MTP_template_variation',
2389
-            $variations_select_values,
2390
-            $this->_message_template_group->get_template_pack_variation()
2391
-        );
2392
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2393
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2394
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396
-
2397
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
-
2399
-        EEH_Template::display_template($template, $template_args);
2400
-    }
2401
-
2402
-
2403
-    /**
2404
-     * This meta box holds any extra actions related to Message Templates
2405
-     * For now, this includes Resetting templates to defaults and sending a test email.
2406
-     *
2407
-     * @access  public
2408
-     * @return void
2409
-     * @throws EE_Error
2410
-     */
2411
-    public function extra_actions_meta_box()
2412
-    {
2413
-        $template_form_fields = [];
2414
-
2415
-        $extra_args = [
2416
-            'msgr'   => $this->_message_template_group->messenger(),
2417
-            'mt'     => $this->_message_template_group->message_type(),
2418
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2419
-        ];
2420
-        // first we need to see if there are any fields
2421
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422
-
2423
-        if (! empty($fields)) {
2424
-            // yup there be fields
2425
-            foreach ($fields as $field => $config) {
2426
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428
-                $default  = isset($config['default']) ? $config['default'] : '';
2429
-                $default  = isset($config['value']) ? $config['value'] : $default;
2430
-
2431
-                // if type is hidden and the value is empty
2432
-                // something may have gone wrong so let's correct with the defaults
2433
-                $fix                = $config['input'] === 'hidden'
2434
-                                      && isset($existing[ $field ])
2435
-                                      && empty($existing[ $field ])
2436
-                    ? $default
2437
-                    : '';
2438
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
-                    ? $existing[ $field ]
2440
-                    : $fix;
2441
-
2442
-                $template_form_fields[ $field_id ] = [
2443
-                    'name'       => 'test_settings_fld[' . $field . ']',
2444
-                    'label'      => $config['label'],
2445
-                    'input'      => $config['input'],
2446
-                    'type'       => $config['type'],
2447
-                    'required'   => $config['required'],
2448
-                    'validation' => $config['validation'],
2449
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
-                    'css_class'  => $config['css_class'],
2451
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2452
-                    'default'    => $default,
2453
-                    'format'     => $config['format'],
2454
-                ];
2455
-            }
2456
-        }
2457
-
2458
-        $test_settings_html = ! empty($template_form_fields)
2459
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2460
-            : '';
2461
-
2462
-        // print out $test_settings_fields
2463
-        if (! empty($test_settings_html)) {
2464
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465
-            $test_settings_html .= 'name="test_button" value="';
2466
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2467
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2468
-        }
2469
-
2470
-        // and button
2471
-        $test_settings_html .= '<p>';
2472
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2473
-        $test_settings_html .= '</p>';
2474
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2475
-        $test_settings_html .= $this->get_action_link_or_button(
2476
-            'reset_to_default',
2477
-            'reset',
2478
-            $extra_args,
2479
-            'button-primary reset-default-button'
2480
-        );
2481
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2482
-        echo $test_settings_html; // already escaped
2483
-    }
2484
-
2485
-
2486
-    /**
2487
-     * This returns the shortcode selector skeleton for a given context and field.
2488
-     *
2489
-     * @param string $field           The name of the field retrieving shortcodes for.
2490
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2491
-     * @return string
2492
-     * @throws DomainException
2493
-     * @throws EE_Error
2494
-     * @throws InvalidArgumentException
2495
-     * @throws ReflectionException
2496
-     * @throws InvalidDataTypeException
2497
-     * @throws InvalidInterfaceException
2498
-     * @since 4.9.rc.000
2499
-     */
2500
-    protected function _get_shortcode_selector($field, $linked_input_id)
2501
-    {
2502
-        $template_args = [
2503
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2504
-            'fieldname'       => $field,
2505
-            'linked_input_id' => $linked_input_id,
2506
-        ];
2507
-
2508
-        return EEH_Template::display_template(
2509
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
-            $template_args,
2511
-            true
2512
-        );
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2518
-     * page)
2519
-     *
2520
-     * @access public
2521
-     * @return void
2522
-     * @throws EE_Error
2523
-     * @throws InvalidArgumentException
2524
-     * @throws ReflectionException
2525
-     * @throws InvalidDataTypeException
2526
-     * @throws InvalidInterfaceException
2527
-     */
2528
-    public function shortcode_meta_box()
2529
-    {
2530
-        $shortcodes = $this->_get_shortcodes([], false);
2531
-        // just make sure the shortcodes property is set
2532
-        // $messenger = $this->_message_template_group->messenger_obj();
2533
-        // now let's set the content depending on the status of the shortcodes array
2534
-        if (empty($shortcodes)) {
2535
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
-            return;
2537
-        }
2538
-        ?>
19
+	/**
20
+	 * @var EEM_Message
21
+	 */
22
+	private $MSG_MODEL;
23
+
24
+	/**
25
+	 * @var EEM_Message_Template
26
+	 */
27
+	private $MTP_MODEL;
28
+
29
+	/**
30
+	 * @var EEM_Message_Template_Group
31
+	 */
32
+	private $MTG_MODEL;
33
+
34
+	/**
35
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
36
+	 */
37
+	protected $_message_resource_manager;
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected $_active_message_type_name = '';
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	protected $_active_messenger_name = '';
48
+
49
+	/**
50
+	 * @var EE_messenger $_active_messenger
51
+	 */
52
+	protected $_active_messenger;
53
+
54
+	protected $_activate_meta_box_type;
55
+
56
+	protected $_current_message_meta_box;
57
+
58
+	protected $_current_message_meta_box_object;
59
+
60
+	protected $_context_switcher;
61
+
62
+	protected $_shortcodes           = [];
63
+
64
+	protected $_active_messengers    = [];
65
+
66
+	protected $_active_message_types = [];
67
+
68
+	/**
69
+	 * @var EE_Message_Template_Group $_message_template_group
70
+	 */
71
+	protected $_message_template_group;
72
+
73
+	protected $_m_mt_settings = [];
74
+
75
+
76
+	/**
77
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
+	 * IF there is no group then it gets automatically set to the Default template pack.
79
+	 *
80
+	 * @since 4.5.0
81
+	 *
82
+	 * @var EE_Messages_Template_Pack
83
+	 */
84
+	protected $_template_pack;
85
+
86
+
87
+	/**
88
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
+	 * group is.  If there is no group then it automatically gets set to default.
90
+	 *
91
+	 * @since 4.5.0
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $_variation;
96
+
97
+
98
+	/**
99
+	 * @param bool $routing
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	public function __construct($routing = true)
104
+	{
105
+		// make sure messages autoloader is running
106
+		EED_Messages::set_autoloaders();
107
+		parent::__construct($routing);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return EEM_Message
113
+	 * @throws EE_Error
114
+	 */
115
+	public function getMsgModel()
116
+	{
117
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+			$this->MSG_MODEL = EEM_Message::instance();
119
+		}
120
+		return $this->MSG_MODEL;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return EEM_Message_Template
126
+	 * @throws EE_Error
127
+	 */
128
+	public function getMtpModel()
129
+	{
130
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+			$this->MTP_MODEL = EEM_Message_Template::instance();
132
+		}
133
+		return $this->MTP_MODEL;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return EEM_Message_Template_Group
139
+	 * @throws EE_Error
140
+	 */
141
+	public function getMtgModel()
142
+	{
143
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
+		}
146
+		return $this->MTG_MODEL;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @throws EE_Error
152
+	 * @throws ReflectionException
153
+	 */
154
+	protected function _init_page_props()
155
+	{
156
+		$this->page_slug        = EE_MSG_PG_SLUG;
157
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
+		$this->_admin_base_path = EE_MSG_ADMIN;
160
+
161
+		$messenger    = $this->request->getRequestParam('messenger', '');
162
+		$message_type = $this->request->getRequestParam('message_type', '');
163
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
+
166
+		$this->_load_message_resource_manager();
167
+	}
168
+
169
+
170
+	/**
171
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
+	 *
173
+	 * @throws EE_Error
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws InvalidArgumentException
177
+	 * @throws ReflectionException
178
+	 */
179
+	protected function _load_message_resource_manager()
180
+	{
181
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return array
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidInterfaceException
191
+	 * @deprecated 4.9.9.rc.014
192
+	 */
193
+	public function get_messengers_for_list_table()
194
+	{
195
+		EE_Error::doing_it_wrong(
196
+			__METHOD__,
197
+			sprintf(
198
+				esc_html__(
199
+					'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',
200
+					'event_espresso'
201
+				),
202
+				'Messages_Admin_Page::get_messengers_select_input()'
203
+			),
204
+			'4.9.9.rc.014'
205
+		);
206
+
207
+		$m_values          = [];
208
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
+		// setup messengers for selects
210
+		$i = 1;
211
+		foreach ($active_messengers as $active_messenger) {
212
+			if ($active_messenger instanceof EE_Message) {
213
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
214
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
+				$i++;
216
+			}
217
+		}
218
+
219
+		return $m_values;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return array
225
+	 * @throws EE_Error
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidInterfaceException
229
+	 * @deprecated 4.9.9.rc.014
230
+	 */
231
+	public function get_message_types_for_list_table()
232
+	{
233
+		EE_Error::doing_it_wrong(
234
+			__METHOD__,
235
+			sprintf(
236
+				esc_html__(
237
+					'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',
238
+					'event_espresso'
239
+				),
240
+				'Messages_Admin_Page::get_message_types_select_input()'
241
+			),
242
+			'4.9.9.rc.014'
243
+		);
244
+
245
+		$mt_values       = [];
246
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
+		$i               = 1;
248
+		foreach ($active_messages as $active_message) {
249
+			if ($active_message instanceof EE_Message) {
250
+				$mt_values[ $i ]['id']   = $active_message->message_type();
251
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
+				$i++;
253
+			}
254
+		}
255
+
256
+		return $mt_values;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @return array
262
+	 * @throws EE_Error
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 * @deprecated 4.9.9.rc.014
267
+	 */
268
+	public function get_contexts_for_message_types_for_list_table()
269
+	{
270
+		EE_Error::doing_it_wrong(
271
+			__METHOD__,
272
+			sprintf(
273
+				esc_html__(
274
+					'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',
275
+					'event_espresso'
276
+				),
277
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
+			),
279
+			'4.9.9.rc.014'
280
+		);
281
+
282
+		$contexts                = [];
283
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
+		foreach ($active_message_contexts as $active_message) {
285
+			if ($active_message instanceof EE_Message) {
286
+				$message_type = $active_message->message_type_object();
287
+				if ($message_type instanceof EE_message_type) {
288
+					$message_type_contexts = $message_type->get_contexts();
289
+					foreach ($message_type_contexts as $context => $context_details) {
290
+						$contexts[ $context ] = $context_details['label'];
291
+					}
292
+				}
293
+			}
294
+		}
295
+
296
+		return $contexts;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Generate select input with provided messenger options array.
302
+	 *
303
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
+	 *                                 labels.
305
+	 * @return string
306
+	 * @throws EE_Error
307
+	 */
308
+	public function get_messengers_select_input($messenger_options)
309
+	{
310
+		// if empty or just one value then just return an empty string
311
+		if (
312
+			empty($messenger_options)
313
+			|| ! is_array($messenger_options)
314
+			|| count($messenger_options) === 1
315
+		) {
316
+			return '';
317
+		}
318
+		// merge in default
319
+		$messenger_options = array_merge(
320
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
+			$messenger_options
322
+		);
323
+		$input             = new EE_Select_Input(
324
+			$messenger_options,
325
+			[
326
+				'html_name'  => 'ee_messenger_filter_by',
327
+				'html_id'    => 'ee_messenger_filter_by',
328
+				'html_class' => 'wide',
329
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
+			]
331
+		);
332
+
333
+		return $input->get_html_for_input();
334
+	}
335
+
336
+
337
+	/**
338
+	 * Generate select input with provided message type options array.
339
+	 *
340
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
+	 *                                    message type labels
342
+	 * @return string
343
+	 * @throws EE_Error
344
+	 */
345
+	public function get_message_types_select_input($message_type_options)
346
+	{
347
+		// if empty or count of options is 1 then just return an empty string
348
+		if (
349
+			empty($message_type_options)
350
+			|| ! is_array($message_type_options)
351
+			|| count($message_type_options) === 1
352
+		) {
353
+			return '';
354
+		}
355
+		// merge in default
356
+		$message_type_options = array_merge(
357
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
+			$message_type_options
359
+		);
360
+		$input                = new EE_Select_Input(
361
+			$message_type_options,
362
+			[
363
+				'html_name'  => 'ee_message_type_filter_by',
364
+				'html_id'    => 'ee_message_type_filter_by',
365
+				'html_class' => 'wide',
366
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
+			]
368
+		);
369
+
370
+		return $input->get_html_for_input();
371
+	}
372
+
373
+
374
+	/**
375
+	 * Generate select input with provide message type contexts array.
376
+	 *
377
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
+	 *                               context label.
379
+	 * @return string
380
+	 * @throws EE_Error
381
+	 */
382
+	public function get_contexts_for_message_types_select_input($context_options)
383
+	{
384
+		// if empty or count of options is one then just return empty string
385
+		if (
386
+			empty($context_options)
387
+			|| ! is_array($context_options)
388
+			|| count($context_options) === 1
389
+		) {
390
+			return '';
391
+		}
392
+		// merge in default
393
+		$context_options = array_merge(
394
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
+			$context_options
396
+		);
397
+		$input           = new EE_Select_Input(
398
+			$context_options,
399
+			[
400
+				'html_name'  => 'ee_context_filter_by',
401
+				'html_id'    => 'ee_context_filter_by',
402
+				'html_class' => 'wide',
403
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
+			]
405
+		);
406
+
407
+		return $input->get_html_for_input();
408
+	}
409
+
410
+
411
+	protected function _ajax_hooks()
412
+	{
413
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
+	}
420
+
421
+
422
+	protected function _define_page_props()
423
+	{
424
+		$this->_admin_page_title = $this->page_label;
425
+		$this->_labels           = [
426
+			'buttons'    => [
427
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
+			],
431
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
+		];
433
+	}
434
+
435
+
436
+	/**
437
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
438
+	 *
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _set_page_routes()
443
+	{
444
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
+
448
+		$this->_page_routes = [
449
+			'default'                          => [
450
+				'func'       => '_message_queue_list_table',
451
+				'capability' => 'ee_read_global_messages',
452
+			],
453
+			'global_mtps'                      => [
454
+				'func'       => '_ee_default_messages_overview_list_table',
455
+				'capability' => 'ee_read_global_messages',
456
+			],
457
+			'custom_mtps'                      => [
458
+				'func'       => '_custom_mtps_preview',
459
+				'capability' => 'ee_read_messages',
460
+			],
461
+			'add_new_message_template'         => [
462
+				'func'       => 'add_message_template',
463
+				'capability' => 'ee_edit_messages',
464
+				'noheader'   => true,
465
+			],
466
+			'edit_message_template'            => [
467
+				'func'       => '_edit_message_template',
468
+				'capability' => 'ee_edit_message',
469
+				'obj_id'     => $GRP_ID,
470
+			],
471
+			'preview_message'                  => [
472
+				'func'               => '_preview_message',
473
+				'capability'         => 'ee_read_message',
474
+				'obj_id'             => $GRP_ID,
475
+				'noheader'           => true,
476
+				'headers_sent_route' => 'display_preview_message',
477
+			],
478
+			'display_preview_message'          => [
479
+				'func'       => '_display_preview_message',
480
+				'capability' => 'ee_read_message',
481
+				'obj_id'     => $GRP_ID,
482
+			],
483
+			'insert_message_template'          => [
484
+				'func'       => '_insert_or_update_message_template',
485
+				'capability' => 'ee_edit_messages',
486
+				'args'       => ['new' => true],
487
+				'noheader'   => true,
488
+			],
489
+			'update_message_template'          => [
490
+				'func'       => '_insert_or_update_message_template',
491
+				'capability' => 'ee_edit_message',
492
+				'obj_id'     => $GRP_ID,
493
+				'args'       => ['new' => false],
494
+				'noheader'   => true,
495
+			],
496
+			'trash_message_template'           => [
497
+				'func'       => '_trash_or_restore_message_template',
498
+				'capability' => 'ee_delete_message',
499
+				'obj_id'     => $GRP_ID,
500
+				'args'       => ['trash' => true, 'all' => true],
501
+				'noheader'   => true,
502
+			],
503
+			'trash_message_template_context'   => [
504
+				'func'       => '_trash_or_restore_message_template',
505
+				'capability' => 'ee_delete_message',
506
+				'obj_id'     => $GRP_ID,
507
+				'args'       => ['trash' => true],
508
+				'noheader'   => true,
509
+			],
510
+			'restore_message_template'         => [
511
+				'func'       => '_trash_or_restore_message_template',
512
+				'capability' => 'ee_delete_message',
513
+				'obj_id'     => $GRP_ID,
514
+				'args'       => ['trash' => false, 'all' => true],
515
+				'noheader'   => true,
516
+			],
517
+			'restore_message_template_context' => [
518
+				'func'       => '_trash_or_restore_message_template',
519
+				'capability' => 'ee_delete_message',
520
+				'obj_id'     => $GRP_ID,
521
+				'args'       => ['trash' => false],
522
+				'noheader'   => true,
523
+			],
524
+			'delete_message_template'          => [
525
+				'func'       => '_delete_message_template',
526
+				'capability' => 'ee_delete_message',
527
+				'obj_id'     => $GRP_ID,
528
+				'noheader'   => true,
529
+			],
530
+			'reset_to_default'                 => [
531
+				'func'       => '_reset_to_default_template',
532
+				'capability' => 'ee_edit_message',
533
+				'obj_id'     => $GRP_ID,
534
+				'noheader'   => true,
535
+			],
536
+			'settings'                         => [
537
+				'func'       => '_settings',
538
+				'capability' => 'manage_options',
539
+			],
540
+			'update_global_settings'           => [
541
+				'func'       => '_update_global_settings',
542
+				'capability' => 'manage_options',
543
+				'noheader'   => true,
544
+			],
545
+			'generate_now'                     => [
546
+				'func'       => '_generate_now',
547
+				'capability' => 'ee_send_message',
548
+				'noheader'   => true,
549
+			],
550
+			'generate_and_send_now'            => [
551
+				'func'       => '_generate_and_send_now',
552
+				'capability' => 'ee_send_message',
553
+				'noheader'   => true,
554
+			],
555
+			'queue_for_resending'              => [
556
+				'func'       => '_queue_for_resending',
557
+				'capability' => 'ee_send_message',
558
+				'noheader'   => true,
559
+			],
560
+			'send_now'                         => [
561
+				'func'       => '_send_now',
562
+				'capability' => 'ee_send_message',
563
+				'noheader'   => true,
564
+			],
565
+			'delete_ee_message'                => [
566
+				'func'       => '_delete_ee_messages',
567
+				'capability' => 'ee_delete_messages',
568
+				'noheader'   => true,
569
+			],
570
+			'delete_ee_messages'               => [
571
+				'func'       => '_delete_ee_messages',
572
+				'capability' => 'ee_delete_messages',
573
+				'noheader'   => true,
574
+				'obj_id'     => $MSG_ID,
575
+			],
576
+		];
577
+	}
578
+
579
+
580
+	protected function _set_page_config()
581
+	{
582
+		$this->_page_config = [
583
+			'default'                  => [
584
+				'nav'           => [
585
+					'label' => esc_html__('Message Activity', 'event_espresso'),
586
+					'order' => 10,
587
+				],
588
+				'list_table'    => 'EE_Message_List_Table',
589
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
+				'require_nonce' => false,
591
+			],
592
+			'global_mtps'              => [
593
+				'nav'           => [
594
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
+					'order' => 20,
596
+				],
597
+				'list_table'    => 'Messages_Template_List_Table',
598
+				'help_tabs'     => [
599
+					'messages_overview_help_tab'                                => [
600
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
+						'filename' => 'messages_overview',
602
+					],
603
+					'messages_overview_messages_table_column_headings_help_tab' => [
604
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
+						'filename' => 'messages_overview_table_column_headings',
606
+					],
607
+					'messages_overview_messages_filters_help_tab'               => [
608
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
609
+						'filename' => 'messages_overview_filters',
610
+					],
611
+					'messages_overview_messages_views_help_tab'                 => [
612
+						'title'    => esc_html__('Message Views', 'event_espresso'),
613
+						'filename' => 'messages_overview_views',
614
+					],
615
+					'message_overview_message_types_help_tab'                   => [
616
+						'title'    => esc_html__('Message Types', 'event_espresso'),
617
+						'filename' => 'messages_overview_types',
618
+					],
619
+					'messages_overview_messengers_help_tab'                     => [
620
+						'title'    => esc_html__('Messengers', 'event_espresso'),
621
+						'filename' => 'messages_overview_messengers',
622
+					],
623
+				],
624
+				'require_nonce' => false,
625
+			],
626
+			'custom_mtps'              => [
627
+				'nav'           => [
628
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
629
+					'order' => 30,
630
+				],
631
+				'help_tabs'     => [],
632
+				'require_nonce' => false,
633
+			],
634
+			'add_new_message_template' => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
637
+					'order'      => 5,
638
+					'persistent' => false,
639
+				],
640
+				'require_nonce' => false,
641
+			],
642
+			'edit_message_template'    => [
643
+				'labels'        => [
644
+					'buttons'    => [
645
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
646
+					],
647
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
648
+				],
649
+				'nav'           => [
650
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
651
+					'order'      => 5,
652
+					'persistent' => false,
653
+					'url'        => '',
654
+				],
655
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
656
+				'has_metaboxes' => true,
657
+				'help_tabs'     => [
658
+					'edit_message_template'            => [
659
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
660
+						'callback' => 'edit_message_template_help_tab',
661
+					],
662
+					'message_templates_help_tab'       => [
663
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
664
+						'filename' => 'messages_templates',
665
+					],
666
+					'message_template_shortcodes'      => [
667
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
668
+						'callback' => 'message_template_shortcodes_help_tab',
669
+					],
670
+					'message_preview_help_tab'         => [
671
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
672
+						'filename' => 'messages_preview',
673
+					],
674
+					'messages_overview_other_help_tab' => [
675
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
676
+						'filename' => 'messages_overview_other',
677
+					],
678
+				],
679
+				'require_nonce' => false,
680
+			],
681
+			'display_preview_message'  => [
682
+				'nav'           => [
683
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
684
+					'order'      => 5,
685
+					'url'        => '',
686
+					'persistent' => false,
687
+				],
688
+				'help_tabs'     => [
689
+					'preview_message' => [
690
+						'title'    => esc_html__('About Previews', 'event_espresso'),
691
+						'callback' => 'preview_message_help_tab',
692
+					],
693
+				],
694
+				'require_nonce' => false,
695
+			],
696
+			'settings'                 => [
697
+				'nav'           => [
698
+					'label' => esc_html__('Settings', 'event_espresso'),
699
+					'order' => 40,
700
+				],
701
+				'metaboxes'     => ['_messages_settings_metaboxes'],
702
+				'help_tabs'     => [
703
+					'messages_settings_help_tab'               => [
704
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
705
+						'filename' => 'messages_settings',
706
+					],
707
+					'messages_settings_message_types_help_tab' => [
708
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
709
+						'filename' => 'messages_settings_message_types',
710
+					],
711
+					'messages_settings_messengers_help_tab'    => [
712
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
713
+						'filename' => 'messages_settings_messengers',
714
+					],
715
+				],
716
+				'require_nonce' => false,
717
+			],
718
+		];
719
+	}
720
+
721
+
722
+	protected function _add_screen_options()
723
+	{
724
+		// todo
725
+	}
726
+
727
+
728
+	protected function _add_screen_options_global_mtps()
729
+	{
730
+		/**
731
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
732
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
733
+		 */
734
+		$page_title              = $this->_admin_page_title;
735
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
736
+		$this->_per_page_screen_option();
737
+		$this->_admin_page_title = $page_title;
738
+	}
739
+
740
+
741
+	protected function _add_screen_options_default()
742
+	{
743
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+	}
746
+
747
+
748
+	// none of the below group are currently used for Messages
749
+	protected function _add_feature_pointers()
750
+	{
751
+	}
752
+
753
+
754
+	public function admin_init()
755
+	{
756
+	}
757
+
758
+
759
+	public function admin_notices()
760
+	{
761
+	}
762
+
763
+
764
+	public function admin_footer_scripts()
765
+	{
766
+	}
767
+
768
+
769
+	public function messages_help_tab()
770
+	{
771
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+	}
773
+
774
+
775
+	public function messengers_help_tab()
776
+	{
777
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+	}
779
+
780
+
781
+	public function message_types_help_tab()
782
+	{
783
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+	}
785
+
786
+
787
+	public function messages_overview_help_tab()
788
+	{
789
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+	}
791
+
792
+
793
+	public function message_templates_help_tab()
794
+	{
795
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+	}
797
+
798
+
799
+	public function edit_message_template_help_tab()
800
+	{
801
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+						. esc_attr__('Editor Title', 'event_espresso')
803
+						. '" />';
804
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
806
+						. '" />';
807
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
809
+						. '" />';
810
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
812
+						. '" />';
813
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+						. esc_attr__('Publish Metabox', 'event_espresso')
815
+						. '" />';
816
+		EEH_Template::display_template(
817
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+			$args
819
+		);
820
+	}
821
+
822
+
823
+	/**
824
+	 * @throws ReflectionException
825
+	 * @throws EE_Error
826
+	 */
827
+	public function message_template_shortcodes_help_tab()
828
+	{
829
+		$this->_set_shortcodes();
830
+		$args['shortcodes'] = $this->_shortcodes;
831
+		EEH_Template::display_template(
832
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+			$args
834
+		);
835
+	}
836
+
837
+
838
+	public function preview_message_help_tab()
839
+	{
840
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+	}
842
+
843
+
844
+	public function settings_help_tab()
845
+	{
846
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
850
+		$args['img3'] = '<div class="switch">'
851
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852
+						. ' type="checkbox" checked="checked">'
853
+						. '<label for="ee-on-off-toggle-on"></label>'
854
+						. '</div>';
855
+		$args['img4'] = '<div class="switch">'
856
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
857
+						. ' type="checkbox">'
858
+						. '<label for="ee-on-off-toggle-on"></label>'
859
+						. '</div>';
860
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+	}
862
+
863
+
864
+	public function load_scripts_styles()
865
+	{
866
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+		wp_enqueue_style('espresso_ee_msg');
868
+
869
+		wp_register_script(
870
+			'ee-messages-settings',
871
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
873
+			EVENT_ESPRESSO_VERSION,
874
+			true
875
+		);
876
+		wp_register_script(
877
+			'ee-msg-list-table-js',
878
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+			['ee-dialog'],
880
+			EVENT_ESPRESSO_VERSION
881
+		);
882
+	}
883
+
884
+
885
+	public function load_scripts_styles_default()
886
+	{
887
+		wp_enqueue_script('ee-msg-list-table-js');
888
+	}
889
+
890
+
891
+	public function wp_editor_css($mce_css)
892
+	{
893
+		// if we're on the edit_message_template route
894
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
895
+			$message_type_name = $this->_active_message_type_name;
896
+
897
+			// we're going to REPLACE the existing mce css
898
+			// we need to get the css file location from the active messenger
899
+			$mce_css = $this->_active_messenger->get_variation(
900
+				$this->_template_pack,
901
+				$message_type_name,
902
+				true,
903
+				'wpeditor',
904
+				$this->_variation
905
+			);
906
+		}
907
+
908
+		return $mce_css;
909
+	}
910
+
911
+
912
+	/**
913
+	 * @throws EE_Error
914
+	 * @throws ReflectionException
915
+	 */
916
+	public function load_scripts_styles_edit_message_template()
917
+	{
918
+
919
+		$this->_set_shortcodes();
920
+
921
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+			esc_html__(
923
+				'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.',
924
+				'event_espresso'
925
+			),
926
+			$this->_message_template_group->messenger_obj()->label['singular'],
927
+			$this->_message_template_group->message_type_obj()->label['singular']
928
+		);
929
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
930
+			'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?',
931
+			'event_espresso'
932
+		);
933
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935
+			'event_espresso'
936
+		);
937
+
938
+		wp_register_script(
939
+			'ee_msgs_edit_js',
940
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+			['jquery'],
942
+			EVENT_ESPRESSO_VERSION
943
+		);
944
+
945
+		wp_enqueue_script('ee_admin_js');
946
+		wp_enqueue_script('ee_msgs_edit_js');
947
+
948
+		// add in special css for tiny_mce
949
+		add_filter('mce_css', [$this, 'wp_editor_css']);
950
+	}
951
+
952
+
953
+	/**
954
+	 * @throws EE_Error
955
+	 * @throws ReflectionException
956
+	 */
957
+	public function load_scripts_styles_display_preview_message()
958
+	{
959
+		$this->_set_message_template_group();
960
+		if ($this->_active_messenger_name) {
961
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
962
+				$this->_active_messenger_name
963
+			);
964
+		}
965
+
966
+		wp_enqueue_style(
967
+			'espresso_preview_css',
968
+			$this->_active_messenger->get_variation(
969
+				$this->_template_pack,
970
+				$this->_active_message_type_name,
971
+				true,
972
+				'preview',
973
+				$this->_variation
974
+			)
975
+		);
976
+	}
977
+
978
+
979
+	public function load_scripts_styles_settings()
980
+	{
981
+		wp_register_style(
982
+			'ee-message-settings',
983
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+			[],
985
+			EVENT_ESPRESSO_VERSION
986
+		);
987
+		wp_enqueue_style('ee-text-links');
988
+		wp_enqueue_style('ee-message-settings');
989
+		wp_enqueue_script('ee-messages-settings');
990
+	}
991
+
992
+
993
+	/**
994
+	 * set views array for List Table
995
+	 */
996
+	public function _set_list_table_views_global_mtps()
997
+	{
998
+		$this->_views = [
999
+			'in_use' => [
1000
+				'slug'  => 'in_use',
1001
+				'label' => esc_html__('In Use', 'event_espresso'),
1002
+				'count' => 0,
1003
+			],
1004
+		];
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * Set views array for the Custom Template List Table
1010
+	 */
1011
+	public function _set_list_table_views_custom_mtps()
1012
+	{
1013
+		$this->_set_list_table_views_global_mtps();
1014
+		$this->_views['in_use']['bulk_action'] = [
1015
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1016
+		];
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * set views array for message queue list table
1022
+	 *
1023
+	 * @throws InvalidDataTypeException
1024
+	 * @throws InvalidInterfaceException
1025
+	 * @throws InvalidArgumentException
1026
+	 * @throws EE_Error
1027
+	 * @throws ReflectionException
1028
+	 */
1029
+	public function _set_list_table_views_default()
1030
+	{
1031
+		EE_Registry::instance()->load_helper('Template');
1032
+
1033
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1034
+			'ee_send_message',
1035
+			'message_list_table_bulk_actions'
1036
+		)
1037
+			? [
1038
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1039
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1040
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1041
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1042
+			]
1043
+			: [];
1044
+
1045
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1046
+			'ee_delete_messages',
1047
+			'message_list_table_bulk_actions'
1048
+		)
1049
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1050
+			: [];
1051
+
1052
+
1053
+		$this->_views = [
1054
+			'all' => [
1055
+				'slug'        => 'all',
1056
+				'label'       => esc_html__('All', 'event_espresso'),
1057
+				'count'       => 0,
1058
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1059
+			],
1060
+		];
1061
+
1062
+
1063
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1064
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1065
+				continue;
1066
+			}
1067
+			$status_bulk_actions = $common_bulk_actions;
1068
+			// unset bulk actions not applying to status
1069
+			if (! empty($status_bulk_actions)) {
1070
+				switch ($status) {
1071
+					case EEM_Message::status_idle:
1072
+					case EEM_Message::status_resend:
1073
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1074
+						break;
1075
+
1076
+					case EEM_Message::status_failed:
1077
+					case EEM_Message::status_debug_only:
1078
+					case EEM_Message::status_messenger_executing:
1079
+						$status_bulk_actions = [];
1080
+						break;
1081
+
1082
+					case EEM_Message::status_incomplete:
1083
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1084
+						break;
1085
+
1086
+					case EEM_Message::status_retry:
1087
+					case EEM_Message::status_sent:
1088
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1089
+						break;
1090
+				}
1091
+			}
1092
+
1093
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1094
+			if ($status === EEM_Message::status_messenger_executing) {
1095
+				continue;
1096
+			}
1097
+
1098
+			$this->_views[ strtolower($status) ] = [
1099
+				'slug'        => strtolower($status),
1100
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101
+				'count'       => 0,
1102
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1103
+			];
1104
+		}
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * @throws EE_Error
1110
+	 */
1111
+	protected function _ee_default_messages_overview_list_table()
1112
+	{
1113
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1114
+		$this->display_admin_list_table_page_with_no_sidebar();
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * @throws EE_Error
1120
+	 * @throws ReflectionException
1121
+	 */
1122
+	protected function _message_queue_list_table()
1123
+	{
1124
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1125
+		$this->_template_args['per_column']        = 6;
1126
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1127
+		$this->_template_args['before_list_table'] = '<h3>'
1128
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1129
+													 . '</h3>';
1130
+		$this->display_admin_list_table_page_with_no_sidebar();
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @throws EE_Error
1136
+	 */
1137
+	protected function _message_legend_items()
1138
+	{
1139
+
1140
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
+		$action_items       = [];
1142
+
1143
+		foreach ($action_css_classes as $action_item => $action_details) {
1144
+			if ($action_item === 'see_notifications_for') {
1145
+				continue;
1146
+			}
1147
+			$action_items[ $action_item ] = [
1148
+				'class' => $action_details['css_class'],
1149
+				'desc'  => $action_details['label'],
1150
+			];
1151
+		}
1152
+
1153
+		/** @var array $status_items status legend setup */
1154
+		$status_items = [
1155
+			'sent_status'                => [
1156
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
+			],
1159
+			'idle_status'                => [
1160
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
+			],
1163
+			'failed_status'              => [
1164
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
+			],
1167
+			'messenger_executing_status' => [
1168
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
+			],
1171
+			'resend_status'              => [
1172
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
+			],
1175
+			'incomplete_status'          => [
1176
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
+			],
1179
+			'retry_status'               => [
1180
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
+			],
1183
+		];
1184
+		if (EEM_Message::debug()) {
1185
+			$status_items['debug_only_status'] = [
1186
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
+			];
1189
+		}
1190
+
1191
+		return array_merge($action_items, $status_items);
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * @throws EE_Error
1197
+	 */
1198
+	protected function _custom_mtps_preview()
1199
+	{
1200
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
+												. ' alt="' . esc_attr__(
1203
+													'Preview Custom Message Templates screenshot',
1204
+													'event_espresso'
1205
+												) . '" />';
1206
+		$this->_template_args['preview_text'] = '<strong>'
1207
+												. esc_html__(
1208
+													'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.',
1209
+													'event_espresso'
1210
+												)
1211
+												. '</strong>';
1212
+
1213
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * get_message_templates
1219
+	 * This gets all the message templates for listing on the overview list.
1220
+	 *
1221
+	 * @access public
1222
+	 * @param int    $per_page the amount of templates groups to show per page
1223
+	 * @param string $type     the current _view we're getting templates for
1224
+	 * @param bool   $count    return count?
1225
+	 * @param bool   $all      disregard any paging info (get all data);
1226
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
+	 * @return array
1228
+	 * @throws EE_Error
1229
+	 * @throws InvalidArgumentException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws InvalidInterfaceException
1232
+	 */
1233
+	public function get_message_templates(
1234
+		$per_page = 10,
1235
+		$type = 'in_use',
1236
+		$count = false,
1237
+		$all = false,
1238
+		$global = true
1239
+	) {
1240
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
+		$this->request->setRequestParam('orderby', $orderby);
1242
+
1243
+		$order        = $this->request->getRequestParam('order', 'ASC');
1244
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
+
1247
+		$offset = ($current_page - 1) * $per_page;
1248
+		$limit  = $all ? null : [$offset, $per_page];
1249
+
1250
+		// options will match what is in the _views array property
1251
+		return $type === 'in_use'
1252
+			? $this->getMtgModel()->get_all_active_message_templates(
1253
+				$orderby,
1254
+				$order,
1255
+				$limit,
1256
+				$count,
1257
+				$global,
1258
+				true
1259
+			)
1260
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
+				$orderby,
1262
+				$order,
1263
+				$limit,
1264
+				$count,
1265
+				$global
1266
+			);
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * filters etc might need a list of installed message_types
1272
+	 *
1273
+	 * @return array an array of message type objects
1274
+	 */
1275
+	public function get_installed_message_types()
1276
+	{
1277
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
+		$installed               = [];
1279
+
1280
+		foreach ($installed_message_types as $message_type) {
1281
+			$installed[ $message_type->name ] = $message_type;
1282
+		}
1283
+
1284
+		return $installed;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1290
+	 *
1291
+	 * @param string $message_type
1292
+	 * @param string $messenger
1293
+	 * @param string $GRP_ID
1294
+	 *
1295
+	 * @throws EE_error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
+	{
1300
+		// set values override any request data
1301
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
+
1305
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
+		if (empty($message_type) || empty($messenger)) {
1307
+			throw new EE_Error(
1308
+				esc_html__(
1309
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
+					'event_espresso'
1311
+				)
1312
+			);
1313
+		}
1314
+
1315
+		// we need the GRP_ID for the template being used as the base for the new template
1316
+		if (empty($GRP_ID)) {
1317
+			throw new EE_Error(
1318
+				esc_html__(
1319
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
+					'event_espresso'
1321
+				)
1322
+			);
1323
+		}
1324
+
1325
+		// let's just make sure the template gets generated!
1326
+
1327
+		// we need to reassign some variables for what the insert is expecting
1328
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1329
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1330
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
+
1332
+		$this->_insert_or_update_message_template(true);
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * @param string $message_type     message type slug
1338
+	 * @param string $messenger        messenger slug
1339
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
+	 *                                 off of.
1341
+	 * @throws EE_error
1342
+	 * @throws ReflectionException
1343
+	 * @deprecated 4.10.29.p
1344
+	 */
1345
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
+	{
1347
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * _edit_message_template
1353
+	 *
1354
+	 * @access protected
1355
+	 * @return void
1356
+	 * @throws InvalidIdentifierException
1357
+	 * @throws DomainException
1358
+	 * @throws EE_Error
1359
+	 * @throws InvalidArgumentException
1360
+	 * @throws ReflectionException
1361
+	 * @throws InvalidDataTypeException
1362
+	 * @throws InvalidInterfaceException
1363
+	 */
1364
+	protected function _edit_message_template()
1365
+	{
1366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
+		$template_fields = '';
1368
+		$sidebar_fields  = '';
1369
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
+		// valid html in the templates.
1371
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
+
1373
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
+
1376
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1377
+		$message_template_group = $this->_message_template_group;
1378
+		$c_label                = $message_template_group->context_label();
1379
+		$c_config               = $message_template_group->contexts_config();
1380
+
1381
+		reset($c_config);
1382
+		$context = $this->request->getRequestParam('context', key($c_config));
1383
+		$context = strtolower($context);
1384
+
1385
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
+
1387
+		$edit_message_template_form_url = add_query_arg(
1388
+			['action' => $action, 'noheader' => true],
1389
+			EE_MSG_ADMIN_URL
1390
+		);
1391
+
1392
+		// set active messenger for this view
1393
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
+			$message_template_group->messenger()
1395
+		);
1396
+		$this->_active_message_type_name = $message_template_group->message_type();
1397
+
1398
+
1399
+		// Do we have any validation errors?
1400
+		$validators = $this->_get_transient();
1401
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
+
1403
+
1404
+		// we need to assemble the title from Various details
1405
+		$context_label = sprintf(
1406
+			esc_html__('(%s %s)', 'event_espresso'),
1407
+			$c_config[ $context ]['label'],
1408
+			ucwords($c_label['label'])
1409
+		);
1410
+
1411
+		$title = sprintf(
1412
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1413
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1414
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1415
+			$context_label
1416
+		);
1417
+
1418
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1419
+		$this->_template_args['message_template'] = $message_template_group;
1420
+		$this->_template_args['is_extra_fields']  = false;
1421
+
1422
+
1423
+		// let's get EEH_MSG_Template so we can get template form fields
1424
+		$template_field_structure = EEH_MSG_Template::get_fields(
1425
+			$message_template_group->messenger(),
1426
+			$message_template_group->message_type()
1427
+		);
1428
+
1429
+		if (! $template_field_structure) {
1430
+			$template_field_structure = false;
1431
+			$template_fields          = esc_html__(
1432
+				'There was an error in assembling the fields for this display (you should see an error message)',
1433
+				'event_espresso'
1434
+			);
1435
+		}
1436
+
1437
+
1438
+		$message_templates = $message_template_group->context_templates();
1439
+
1440
+
1441
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
+		// will get handled in the "extra" array.
1443
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
+				unset($template_field_structure[ $context ][ $reference_field ]);
1446
+			}
1447
+		}
1448
+
1449
+		// let's loop through the template_field_structure and actually assemble the input fields!
1450
+		if (! empty($template_field_structure)) {
1451
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
+				// the extra array and reset them.
1454
+				if ($template_field === 'extra') {
1455
+					$this->_template_args['is_extra_fields'] = true;
1456
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
+						$message_template = $message_templates[ $context ][ $reference_field ];
1458
+						$content          = $message_template instanceof EE_Message_Template
1459
+							? $message_template->get('MTP_content')
1460
+							: '';
1461
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1462
+							// let's verify if we need this extra field via the shortcodes parameter.
1463
+							$continue = false;
1464
+							if (isset($extra_array['shortcodes_required'])) {
1465
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+										$continue = true;
1468
+									}
1469
+								}
1470
+								if ($continue) {
1471
+									continue;
1472
+								}
1473
+							}
1474
+
1475
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1476
+
1477
+							$template_form_fields[ $field_id ]         = $extra_array;
1478
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
+																		 . $reference_field
1480
+																		 . '][content]['
1481
+																		 . $extra_field . ']';
1482
+							$css_class                                 = isset($extra_array['css_class'])
1483
+								? $extra_array['css_class']
1484
+								: '';
1485
+
1486
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+																			  && in_array($extra_field, $v_fields, true)
1488
+																			  && (
1489
+																				  is_array($validators[ $extra_field ])
1490
+																				  && isset($validators[ $extra_field ]['msg'])
1491
+																			  )
1492
+								? 'validate-error ' . $css_class
1493
+								: $css_class;
1494
+
1495
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
+																		  && isset($content[ $extra_field ])
1497
+								? $content[ $extra_field ]
1498
+								: '';
1499
+
1500
+							// do we have a validation error?  if we do then let's use that value instead
1501
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
+								? $validators[ $extra_field ]['value']
1503
+								: $template_form_fields[ $field_id ]['value'];
1504
+
1505
+
1506
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+
1508
+							// shortcode selector
1509
+							$field_name_to_use                                   = $extra_field === 'main'
1510
+								? 'content'
1511
+								: $extra_field;
1512
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+								$field_name_to_use,
1514
+								$field_id
1515
+							);
1516
+						}
1517
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
+						$template_field_template_name_id = $reference_field . '-name';
1519
+
1520
+						$template_form_fields[ $template_field_MTP_id ] = [
1521
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
+							'label'      => null,
1523
+							'input'      => 'hidden',
1524
+							'type'       => 'int',
1525
+							'required'   => false,
1526
+							'validation' => false,
1527
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
+							'css_class'  => '',
1529
+							'format'     => '%d',
1530
+							'db-col'     => 'MTP_ID',
1531
+						];
1532
+
1533
+						$template_form_fields[ $template_field_template_name_id ] = [
1534
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
+							'label'      => null,
1536
+							'input'      => 'hidden',
1537
+							'type'       => 'string',
1538
+							'required'   => false,
1539
+							'validation' => true,
1540
+							'value'      => $reference_field,
1541
+							'css_class'  => '',
1542
+							'format'     => '%s',
1543
+							'db-col'     => 'MTP_template_field',
1544
+						];
1545
+					}
1546
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
+				} else {
1548
+					$field_id                                   = $template_field . '-content';
1549
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1550
+					$template_form_fields[ $field_id ]['name']  =
1551
+						'MTP_template_fields[' . $template_field . '][content]';
1552
+					$message_template                           =
1553
+						isset($message_templates[ $context ][ $template_field ])
1554
+							? $message_templates[ $context ][ $template_field ]
1555
+							: null;
1556
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
+																  && is_array($message_templates[ $context ])
1558
+																  && $message_template instanceof EE_Message_Template
1559
+						? $message_template->get('MTP_content')
1560
+						: '';
1561
+
1562
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1563
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
+						? $validators[ $template_field ]['value']
1565
+						: $template_form_fields[ $field_id ]['value'];
1566
+
1567
+
1568
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+					$css_class                                      = isset($field_setup_array['css_class'])
1570
+						? $field_setup_array['css_class']
1571
+						: '';
1572
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+																	  && in_array($template_field, $v_fields, true)
1574
+																	  && isset($validators[ $template_field ]['msg'])
1575
+						? 'validate-error ' . $css_class
1576
+						: $css_class;
1577
+
1578
+					// shortcode selector
1579
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+						$template_field,
1581
+						$field_id
1582
+					);
1583
+				}
1584
+
1585
+				// k took care of content field(s) now let's take care of others.
1586
+
1587
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
+				$template_field_field_template_name_id = $template_field . '-name';
1589
+
1590
+				// foreach template field there are actually two form fields created
1591
+				$template_form_fields[ $template_field_MTP_id ] = [
1592
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
+					'label'      => null,
1594
+					'input'      => 'hidden',
1595
+					'type'       => 'int',
1596
+					'required'   => false,
1597
+					'validation' => true,
1598
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
+					'css_class'  => '',
1600
+					'format'     => '%d',
1601
+					'db-col'     => 'MTP_ID',
1602
+				];
1603
+
1604
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1605
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
+					'label'      => null,
1607
+					'input'      => 'hidden',
1608
+					'type'       => 'string',
1609
+					'required'   => false,
1610
+					'validation' => true,
1611
+					'value'      => $template_field,
1612
+					'css_class'  => '',
1613
+					'format'     => '%s',
1614
+					'db-col'     => 'MTP_template_field',
1615
+				];
1616
+			}
1617
+
1618
+			// add other fields
1619
+			$template_form_fields['ee-msg-current-context'] = [
1620
+				'name'       => 'MTP_context',
1621
+				'label'      => null,
1622
+				'input'      => 'hidden',
1623
+				'type'       => 'string',
1624
+				'required'   => false,
1625
+				'validation' => true,
1626
+				'value'      => $context,
1627
+				'css_class'  => '',
1628
+				'format'     => '%s',
1629
+				'db-col'     => 'MTP_context',
1630
+			];
1631
+
1632
+			$template_form_fields['ee-msg-grp-id'] = [
1633
+				'name'       => 'GRP_ID',
1634
+				'label'      => null,
1635
+				'input'      => 'hidden',
1636
+				'type'       => 'int',
1637
+				'required'   => false,
1638
+				'validation' => true,
1639
+				'value'      => $GRP_ID,
1640
+				'css_class'  => '',
1641
+				'format'     => '%d',
1642
+				'db-col'     => 'GRP_ID',
1643
+			];
1644
+
1645
+			$template_form_fields['ee-msg-messenger'] = [
1646
+				'name'       => 'MTP_messenger',
1647
+				'label'      => null,
1648
+				'input'      => 'hidden',
1649
+				'type'       => 'string',
1650
+				'required'   => false,
1651
+				'validation' => true,
1652
+				'value'      => $message_template_group->messenger(),
1653
+				'css_class'  => '',
1654
+				'format'     => '%s',
1655
+				'db-col'     => 'MTP_messenger',
1656
+			];
1657
+
1658
+			$template_form_fields['ee-msg-message-type'] = [
1659
+				'name'       => 'MTP_message_type',
1660
+				'label'      => null,
1661
+				'input'      => 'hidden',
1662
+				'type'       => 'string',
1663
+				'required'   => false,
1664
+				'validation' => true,
1665
+				'value'      => $message_template_group->message_type(),
1666
+				'css_class'  => '',
1667
+				'format'     => '%s',
1668
+				'db-col'     => 'MTP_message_type',
1669
+			];
1670
+
1671
+			$sidebar_form_fields['ee-msg-is-global'] = [
1672
+				'name'       => 'MTP_is_global',
1673
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1674
+				'input'      => 'hidden',
1675
+				'type'       => 'int',
1676
+				'required'   => false,
1677
+				'validation' => true,
1678
+				'value'      => $message_template_group->get('MTP_is_global'),
1679
+				'css_class'  => '',
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_is_global',
1682
+			];
1683
+
1684
+			$sidebar_form_fields['ee-msg-is-override'] = [
1685
+				'name'       => 'MTP_is_override',
1686
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
+				'type'       => 'int',
1689
+				'required'   => false,
1690
+				'validation' => true,
1691
+				'value'      => $message_template_group->get('MTP_is_override'),
1692
+				'css_class'  => '',
1693
+				'format'     => '%d',
1694
+				'db-col'     => 'MTP_is_override',
1695
+			];
1696
+
1697
+			$sidebar_form_fields['ee-msg-is-active'] = [
1698
+				'name'       => 'MTP_is_active',
1699
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1700
+				'input'      => 'hidden',
1701
+				'type'       => 'int',
1702
+				'required'   => false,
1703
+				'validation' => true,
1704
+				'value'      => $message_template_group->is_active(),
1705
+				'css_class'  => '',
1706
+				'format'     => '%d',
1707
+				'db-col'     => 'MTP_is_active',
1708
+			];
1709
+
1710
+			$sidebar_form_fields['ee-msg-deleted'] = [
1711
+				'name'       => 'MTP_deleted',
1712
+				'label'      => null,
1713
+				'input'      => 'hidden',
1714
+				'type'       => 'int',
1715
+				'required'   => false,
1716
+				'validation' => true,
1717
+				'value'      => $message_template_group->get('MTP_deleted'),
1718
+				'css_class'  => '',
1719
+				'format'     => '%d',
1720
+				'db-col'     => 'MTP_deleted',
1721
+			];
1722
+			$sidebar_form_fields['ee-msg-author']  = [
1723
+				'name'       => 'MTP_user_id',
1724
+				'label'      => esc_html__('Author', 'event_espresso'),
1725
+				'input'      => 'hidden',
1726
+				'type'       => 'int',
1727
+				'required'   => false,
1728
+				'validation' => false,
1729
+				'value'      => $message_template_group->user(),
1730
+				'format'     => '%d',
1731
+				'db-col'     => 'MTP_user_id',
1732
+			];
1733
+
1734
+			$sidebar_form_fields['ee-msg-route'] = [
1735
+				'name'  => 'action',
1736
+				'input' => 'hidden',
1737
+				'type'  => 'string',
1738
+				'value' => $action,
1739
+			];
1740
+
1741
+			$sidebar_form_fields['ee-msg-id']        = [
1742
+				'name'  => 'id',
1743
+				'input' => 'hidden',
1744
+				'type'  => 'int',
1745
+				'value' => $GRP_ID,
1746
+			];
1747
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
+				'name'  => $action . '_nonce',
1749
+				'input' => 'hidden',
1750
+				'type'  => 'string',
1751
+				'value' => wp_create_nonce($action . '_nonce'),
1752
+			];
1753
+
1754
+			$template_switch = $this->request->getRequestParam('template_switch');
1755
+			if ($template_switch) {
1756
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1757
+					'name'  => 'template_switch',
1758
+					'input' => 'hidden',
1759
+					'type'  => 'int',
1760
+					'value' => 1,
1761
+				];
1762
+			}
1763
+
1764
+
1765
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
+		} //end if ( !empty($template_field_structure) )
1768
+
1769
+		// set extra content for publish box
1770
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
+		$this->_set_publish_post_box_vars(
1772
+			'id',
1773
+			$GRP_ID,
1774
+			false,
1775
+			add_query_arg(
1776
+				['action' => 'global_mtps'],
1777
+				$this->_admin_base_url
1778
+			)
1779
+		);
1780
+
1781
+		// add preview button
1782
+		$preview_url    = parent::add_query_args_and_nonce(
1783
+			[
1784
+				'message_type' => $message_template_group->message_type(),
1785
+				'messenger'    => $message_template_group->messenger(),
1786
+				'context'      => $context,
1787
+				'GRP_ID'       => $GRP_ID,
1788
+				'evt_id'       => $EVT_ID ?: false,
1789
+				'action'       => 'preview_message',
1790
+			],
1791
+			$this->_admin_base_url
1792
+		);
1793
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
+						  . esc_html__('Preview', 'event_espresso')
1795
+						  . '</a>';
1796
+
1797
+
1798
+		// setup context switcher
1799
+		$this->_set_context_switcher(
1800
+			$message_template_group,
1801
+			[
1802
+				'page'    => 'espresso_messages',
1803
+				'action'  => 'edit_message_template',
1804
+				'id'      => $GRP_ID,
1805
+				'evt_id'  => $EVT_ID,
1806
+				'context' => $context,
1807
+				'extra'   => $preview_button,
1808
+			]
1809
+		);
1810
+
1811
+
1812
+		// main box
1813
+		$this->_template_args['template_fields']                         = $template_fields;
1814
+		$this->_template_args['sidebar_box_id']                          = 'details';
1815
+		$this->_template_args['action']                                  = $action;
1816
+		$this->_template_args['context']                                 = $context;
1817
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
+		$this->_template_args['learn_more_about_message_templates_link'] =
1819
+			$this->_learn_more_about_message_templates_link();
1820
+
1821
+
1822
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1823
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
+			$message_template_group,
1825
+			$context,
1826
+			$context_label
1827
+		);
1828
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
+
1831
+		$this->_template_path = $this->_template_args['GRP_ID']
1832
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
+
1835
+		// send along EE_Message_Template_Group object for further template use.
1836
+		$this->_template_args['MTP'] = $message_template_group;
1837
+
1838
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1839
+			$this->_template_path,
1840
+			$this->_template_args,
1841
+			true
1842
+		);
1843
+
1844
+
1845
+		// finally, let's set the admin_page title
1846
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1847
+
1848
+
1849
+		// we need to take care of setting the shortcodes property for use elsewhere.
1850
+		$this->_set_shortcodes();
1851
+
1852
+
1853
+		// final template wrapper
1854
+		$this->display_admin_page_with_sidebar();
1855
+	}
1856
+
1857
+
1858
+	public function filter_tinymce_init($mceInit, $editor_id)
1859
+	{
1860
+		return $mceInit;
1861
+	}
1862
+
1863
+
1864
+	public function add_context_switcher()
1865
+	{
1866
+		return $this->_context_switcher;
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 * Adds the activation/deactivation toggle for the message template context.
1872
+	 *
1873
+	 * @param EE_Message_Template_Group $message_template_group
1874
+	 * @param string                    $context
1875
+	 * @param string                    $context_label
1876
+	 * @return string
1877
+	 * @throws DomainException
1878
+	 * @throws EE_Error
1879
+	 * @throws InvalidIdentifierException
1880
+	 * @throws ReflectionException
1881
+	 */
1882
+	protected function add_active_context_element(
1883
+		EE_Message_Template_Group $message_template_group,
1884
+		$context,
1885
+		$context_label
1886
+	) {
1887
+		$template_args = [
1888
+			'context'                   => $context,
1889
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+			'is_active'                 => $message_template_group->is_context_active($context),
1891
+			'on_off_action'             => $message_template_group->is_context_active($context)
1892
+				? 'context-off'
1893
+				: 'context-on',
1894
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1895
+			'message_template_group_id' => $message_template_group->ID(),
1896
+		];
1897
+		return EEH_Template::display_template(
1898
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
+			$template_args,
1900
+			true
1901
+		);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * Ajax callback for `toggle_context_template` ajax action.
1907
+	 * Handles toggling the message context on or off.
1908
+	 *
1909
+	 * @throws EE_Error
1910
+	 * @throws InvalidArgumentException
1911
+	 * @throws InvalidDataTypeException
1912
+	 * @throws InvalidIdentifierException
1913
+	 * @throws InvalidInterfaceException
1914
+	 */
1915
+	public function toggle_context_template()
1916
+	{
1917
+		$success = true;
1918
+		// check for required data
1919
+		if (
1920
+			! (
1921
+				$this->request->requestParamIsSet('message_template_group_id')
1922
+				&& $this->request->requestParamIsSet('context')
1923
+				&& $this->request->requestParamIsSet('status')
1924
+			)
1925
+		) {
1926
+			EE_Error::add_error(
1927
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1928
+				__FILE__,
1929
+				__FUNCTION__,
1930
+				__LINE__
1931
+			);
1932
+			$success = false;
1933
+		}
1934
+
1935
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1936
+		$context = $this->request->getRequestParam('context', '');
1937
+		$status  = $this->request->getRequestParam('status', '');
1938
+
1939
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1940
+
1941
+		if ($status !== 'off' && $status !== 'on') {
1942
+			EE_Error::add_error(
1943
+				sprintf(
1944
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1945
+					$status
1946
+				),
1947
+				__FILE__,
1948
+				__FUNCTION__,
1949
+				__LINE__
1950
+			);
1951
+			$success = false;
1952
+		}
1953
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
+			EE_Error::add_error(
1957
+				sprintf(
1958
+					esc_html__(
1959
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1960
+						'event_espresso'
1961
+					),
1962
+					$message_template_group_id,
1963
+					'EE_Message_Template_Group'
1964
+				),
1965
+				__FILE__,
1966
+				__FUNCTION__,
1967
+				__LINE__
1968
+			);
1969
+			$success = false;
1970
+		}
1971
+		if ($success) {
1972
+			$success = $status === 'off'
1973
+				? $message_template_group->deactivate_context($context)
1974
+				: $message_template_group->activate_context($context);
1975
+		}
1976
+		$this->_template_args['success'] = $success;
1977
+		$this->_return_json();
1978
+	}
1979
+
1980
+
1981
+	public function _add_form_element_before()
1982
+	{
1983
+		return '<form method="post" action="'
1984
+			   . $this->_template_args['edit_message_template_form_url']
1985
+			   . '" id="ee-msg-edit-frm">';
1986
+	}
1987
+
1988
+
1989
+	public function _add_form_element_after()
1990
+	{
1991
+		return '</form>';
1992
+	}
1993
+
1994
+
1995
+	/**
1996
+	 * This executes switching the template pack for a message template.
1997
+	 *
1998
+	 * @throws EE_Error
1999
+	 * @throws InvalidDataTypeException
2000
+	 * @throws InvalidInterfaceException
2001
+	 * @throws InvalidArgumentException
2002
+	 * @throws ReflectionException
2003
+	 * @since 4.5.0
2004
+	 */
2005
+	public function switch_template_pack()
2006
+	{
2007
+
2008
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2009
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2010
+
2011
+		// verify we have needed values.
2012
+		if (empty($GRP_ID) || empty($template_pack)) {
2013
+			$this->_template_args['error'] = true;
2014
+			EE_Error::add_error(
2015
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2016
+				__FILE__,
2017
+				__FUNCTION__,
2018
+				__LINE__
2019
+			);
2020
+		} else {
2021
+			// get template, set the new template_pack and then reset to default
2022
+			/** @var EE_Message_Template_Group $message_template_group */
2023
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2024
+
2025
+			$message_template_group->set_template_pack_name($template_pack);
2026
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2027
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2028
+
2029
+			$query_args = $this->_reset_to_default_template();
2030
+
2031
+			if (empty($query_args['id'])) {
2032
+				EE_Error::add_error(
2033
+					esc_html__(
2034
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2035
+						'event_espresso'
2036
+					),
2037
+					__FILE__,
2038
+					__FUNCTION__,
2039
+					__LINE__
2040
+				);
2041
+				$this->_template_args['error'] = true;
2042
+			} else {
2043
+				$template_label       = $message_template_group->get_template_pack()->label;
2044
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2045
+				EE_Error::add_success(
2046
+					sprintf(
2047
+						esc_html__(
2048
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2049
+							'event_espresso'
2050
+						),
2051
+						$template_label,
2052
+						$template_pack_labels->template_pack
2053
+					)
2054
+				);
2055
+				// generate the redirect url for js.
2056
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2057
+
2058
+				$this->_template_args['data']['redirect_url'] = $url;
2059
+				$this->_template_args['success']              = true;
2060
+			}
2061
+
2062
+			$this->_return_json();
2063
+		}
2064
+	}
2065
+
2066
+
2067
+	/**
2068
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2069
+	 * they want.
2070
+	 *
2071
+	 * @access protected
2072
+	 * @return array|void
2073
+	 * @throws EE_Error
2074
+	 * @throws InvalidArgumentException
2075
+	 * @throws InvalidDataTypeException
2076
+	 * @throws InvalidInterfaceException
2077
+	 * @throws ReflectionException
2078
+	 */
2079
+	protected function _reset_to_default_template()
2080
+	{
2081
+		$templates    = [];
2082
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2083
+		$messenger    = $this->request->getRequestParam('msgr');
2084
+		$message_type = $this->request->getRequestParam('mt');
2085
+		// we need to make sure we've got the info we need.
2086
+		if (! ($GRP_ID && $messenger && $message_type)) {
2087
+			EE_Error::add_error(
2088
+				esc_html__(
2089
+					'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.',
2090
+					'event_espresso'
2091
+				),
2092
+				__FILE__,
2093
+				__FUNCTION__,
2094
+				__LINE__
2095
+			);
2096
+		}
2097
+
2098
+		// all templates will be reset to whatever the defaults are
2099
+		// for the global template matching the messenger and message type.
2100
+		$success = ! empty($GRP_ID);
2101
+
2102
+		if ($success) {
2103
+			// let's first determine if the incoming template is a global template,
2104
+			// if it isn't then we need to get the global template matching messenger and message type.
2105
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2106
+
2107
+
2108
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2109
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2110
+
2111
+			if ($success) {
2112
+				// if successfully deleted, lets generate the new ones.
2113
+				// Note. We set GLOBAL to true, because resets on ANY template
2114
+				// will use the related global template defaults for regeneration.
2115
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2116
+				// HOWEVER, we DO keep the template pack and template variation set
2117
+				// for the current custom template when resetting.
2118
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2119
+			}
2120
+		}
2121
+
2122
+		// any error messages?
2123
+		if (! $success) {
2124
+			EE_Error::add_error(
2125
+				esc_html__(
2126
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2127
+					'event_espresso'
2128
+				),
2129
+				__FILE__,
2130
+				__FUNCTION__,
2131
+				__LINE__
2132
+			);
2133
+		}
2134
+
2135
+		// all good, let's add a success message!
2136
+		if ($success && ! empty($templates)) {
2137
+			// the info for the template we generated is the first element in the returned array
2138
+			EE_Error::overwrite_success();
2139
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2140
+		}
2141
+
2142
+
2143
+		$query_args = [
2144
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2145
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2146
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2147
+		];
2148
+
2149
+		// if called via ajax then we return query args otherwise redirect
2150
+		if ($this->request->isAjax()) {
2151
+			return $query_args;
2152
+		}
2153
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2154
+	}
2155
+
2156
+
2157
+	/**
2158
+	 * Retrieve and set the message preview for display.
2159
+	 *
2160
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2161
+	 * @return string
2162
+	 * @throws ReflectionException
2163
+	 * @throws EE_Error
2164
+	 * @throws InvalidArgumentException
2165
+	 * @throws InvalidDataTypeException
2166
+	 * @throws InvalidInterfaceException
2167
+	 */
2168
+	public function _preview_message($send = false)
2169
+	{
2170
+		// first make sure we've got the necessary parameters
2171
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
+			EE_Error::add_error(
2174
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175
+				__FILE__,
2176
+				__FUNCTION__,
2177
+				__LINE__
2178
+			);
2179
+		}
2180
+
2181
+		$context = $this->request->getRequestParam('context');
2182
+		// get the preview!
2183
+		$preview = EED_Messages::preview_message(
2184
+			$this->_active_message_type_name,
2185
+			$context,
2186
+			$this->_active_messenger_name,
2187
+			$send
2188
+		);
2189
+
2190
+		if ($send) {
2191
+			return $preview;
2192
+		}
2193
+
2194
+		// if we have an evt_id set on the request, use it.
2195
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196
+
2197
+		// let's add a button to go back to the edit view
2198
+		$query_args             = [
2199
+			'id'      => $GRP_ID,
2200
+			'evt_id'  => $EVT_ID,
2201
+			'context' => $context,
2202
+			'action'  => 'edit_message_template',
2203
+		];
2204
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2205
+		$preview_button         = '<a href="'
2206
+								  . $go_back_url
2207
+								  . '" class="button-secondary messages-preview-go-back-button">'
2208
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2209
+								  . '</a>';
2210
+		$message_types          = $this->get_installed_message_types();
2211
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2212
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2213
+			? ucwords($active_messenger->label['singular'])
2214
+			: esc_html__('Unknown Messenger', 'event_espresso');
2215
+		// let's provide a helpful title for context
2216
+		$preview_title = sprintf(
2217
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218
+			$active_messenger_label,
2219
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
+		);
2221
+		if (empty($preview)) {
2222
+			$this->noEventsErrorMessage();
2223
+		}
2224
+		// setup display of preview.
2225
+		$this->_admin_page_title                    = $preview_title;
2226
+		$this->_template_args['admin_page_title']   = $preview_title;
2227
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
+		$this->_template_args['data']['force_json'] = true;
2229
+
2230
+		return '';
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * Used to set an error if there are no events available for generating a preview/test send.
2236
+	 *
2237
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2238
+	 */
2239
+	protected function noEventsErrorMessage($test_send = false)
2240
+	{
2241
+		$events_url = parent::add_query_args_and_nonce(
2242
+			[
2243
+				'action' => 'default',
2244
+				'page'   => 'espresso_events',
2245
+			],
2246
+			admin_url('admin.php')
2247
+		);
2248
+		$message    = $test_send
2249
+			? esc_html__(
2250
+				'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!',
2251
+				'event_espresso'
2252
+			)
2253
+			: esc_html__(
2254
+				'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!',
2255
+				'event_espresso'
2256
+			);
2257
+
2258
+		EE_Error::add_attention(
2259
+			sprintf(
2260
+				$message,
2261
+				"<a href='{$events_url}'>",
2262
+				'</a>'
2263
+			)
2264
+		);
2265
+	}
2266
+
2267
+
2268
+	/**
2269
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2270
+	 * gets called automatically.
2271
+	 *
2272
+	 * @return void
2273
+	 * @throws EE_Error
2274
+	 * @since 4.5.0
2275
+	 *
2276
+	 */
2277
+	protected function _display_preview_message()
2278
+	{
2279
+		$this->display_admin_page_with_no_sidebar();
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * registers metaboxes that should show up on the "edit_message_template" page
2285
+	 *
2286
+	 * @access protected
2287
+	 * @return void
2288
+	 */
2289
+	protected function _register_edit_meta_boxes()
2290
+	{
2291
+		add_meta_box(
2292
+			'mtp_valid_shortcodes',
2293
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2294
+			[$this, 'shortcode_meta_box'],
2295
+			$this->_current_screen->id,
2296
+			'side'
2297
+		);
2298
+		add_meta_box(
2299
+			'mtp_extra_actions',
2300
+			esc_html__('Extra Actions', 'event_espresso'),
2301
+			[$this, 'extra_actions_meta_box'],
2302
+			$this->_current_screen->id,
2303
+			'side',
2304
+			'high'
2305
+		);
2306
+		add_meta_box(
2307
+			'mtp_templates',
2308
+			esc_html__('Template Styles', 'event_espresso'),
2309
+			[$this, 'template_pack_meta_box'],
2310
+			$this->_current_screen->id,
2311
+			'side',
2312
+			'high'
2313
+		);
2314
+	}
2315
+
2316
+
2317
+	/**
2318
+	 * metabox content for all template pack and variation selection.
2319
+	 *
2320
+	 * @return void
2321
+	 * @throws DomainException
2322
+	 * @throws EE_Error
2323
+	 * @throws InvalidArgumentException
2324
+	 * @throws ReflectionException
2325
+	 * @throws InvalidDataTypeException
2326
+	 * @throws InvalidInterfaceException
2327
+	 * @since 4.5.0
2328
+	 */
2329
+	public function template_pack_meta_box()
2330
+	{
2331
+		$this->_set_message_template_group();
2332
+
2333
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2334
+
2335
+		$tp_select_values = [];
2336
+
2337
+		foreach ($tp_collection as $tp) {
2338
+			// only include template packs that support this messenger and message type!
2339
+			$supports = $tp->get_supports();
2340
+			if (
2341
+				! isset($supports[ $this->_message_template_group->messenger() ])
2342
+				|| ! in_array(
2343
+					$this->_message_template_group->message_type(),
2344
+					$supports[ $this->_message_template_group->messenger() ],
2345
+					true
2346
+				)
2347
+			) {
2348
+				// not supported
2349
+				continue;
2350
+			}
2351
+
2352
+			$tp_select_values[] = [
2353
+				'text' => $tp->label,
2354
+				'id'   => $tp->dbref,
2355
+			];
2356
+		}
2357
+
2358
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2359
+		// the default template pack.  This still allows for the odd template pack to override.
2360
+		if (empty($tp_select_values)) {
2361
+			$tp_select_values[] = [
2362
+				'text' => esc_html__('Default', 'event_espresso'),
2363
+				'id'   => 'default',
2364
+			];
2365
+		}
2366
+
2367
+		// setup variation select values for the currently selected template.
2368
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
+			$this->_message_template_group->messenger(),
2370
+			$this->_message_template_group->message_type()
2371
+		);
2372
+		$variations_select_values = [];
2373
+		foreach ($variations as $variation => $label) {
2374
+			$variations_select_values[] = [
2375
+				'text' => $label,
2376
+				'id'   => $variation,
2377
+			];
2378
+		}
2379
+
2380
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381
+
2382
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
+			'MTP_template_pack',
2384
+			$tp_select_values,
2385
+			$this->_message_template_group->get_template_pack_name()
2386
+		);
2387
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
+			'MTP_template_variation',
2389
+			$variations_select_values,
2390
+			$this->_message_template_group->get_template_pack_variation()
2391
+		);
2392
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2393
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2394
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396
+
2397
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
+
2399
+		EEH_Template::display_template($template, $template_args);
2400
+	}
2401
+
2402
+
2403
+	/**
2404
+	 * This meta box holds any extra actions related to Message Templates
2405
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2406
+	 *
2407
+	 * @access  public
2408
+	 * @return void
2409
+	 * @throws EE_Error
2410
+	 */
2411
+	public function extra_actions_meta_box()
2412
+	{
2413
+		$template_form_fields = [];
2414
+
2415
+		$extra_args = [
2416
+			'msgr'   => $this->_message_template_group->messenger(),
2417
+			'mt'     => $this->_message_template_group->message_type(),
2418
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2419
+		];
2420
+		// first we need to see if there are any fields
2421
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422
+
2423
+		if (! empty($fields)) {
2424
+			// yup there be fields
2425
+			foreach ($fields as $field => $config) {
2426
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428
+				$default  = isset($config['default']) ? $config['default'] : '';
2429
+				$default  = isset($config['value']) ? $config['value'] : $default;
2430
+
2431
+				// if type is hidden and the value is empty
2432
+				// something may have gone wrong so let's correct with the defaults
2433
+				$fix                = $config['input'] === 'hidden'
2434
+									  && isset($existing[ $field ])
2435
+									  && empty($existing[ $field ])
2436
+					? $default
2437
+					: '';
2438
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
+					? $existing[ $field ]
2440
+					: $fix;
2441
+
2442
+				$template_form_fields[ $field_id ] = [
2443
+					'name'       => 'test_settings_fld[' . $field . ']',
2444
+					'label'      => $config['label'],
2445
+					'input'      => $config['input'],
2446
+					'type'       => $config['type'],
2447
+					'required'   => $config['required'],
2448
+					'validation' => $config['validation'],
2449
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
+					'css_class'  => $config['css_class'],
2451
+					'options'    => isset($config['options']) ? $config['options'] : [],
2452
+					'default'    => $default,
2453
+					'format'     => $config['format'],
2454
+				];
2455
+			}
2456
+		}
2457
+
2458
+		$test_settings_html = ! empty($template_form_fields)
2459
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2460
+			: '';
2461
+
2462
+		// print out $test_settings_fields
2463
+		if (! empty($test_settings_html)) {
2464
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465
+			$test_settings_html .= 'name="test_button" value="';
2466
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2467
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2468
+		}
2469
+
2470
+		// and button
2471
+		$test_settings_html .= '<p>';
2472
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2473
+		$test_settings_html .= '</p>';
2474
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2475
+		$test_settings_html .= $this->get_action_link_or_button(
2476
+			'reset_to_default',
2477
+			'reset',
2478
+			$extra_args,
2479
+			'button-primary reset-default-button'
2480
+		);
2481
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2482
+		echo $test_settings_html; // already escaped
2483
+	}
2484
+
2485
+
2486
+	/**
2487
+	 * This returns the shortcode selector skeleton for a given context and field.
2488
+	 *
2489
+	 * @param string $field           The name of the field retrieving shortcodes for.
2490
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2491
+	 * @return string
2492
+	 * @throws DomainException
2493
+	 * @throws EE_Error
2494
+	 * @throws InvalidArgumentException
2495
+	 * @throws ReflectionException
2496
+	 * @throws InvalidDataTypeException
2497
+	 * @throws InvalidInterfaceException
2498
+	 * @since 4.9.rc.000
2499
+	 */
2500
+	protected function _get_shortcode_selector($field, $linked_input_id)
2501
+	{
2502
+		$template_args = [
2503
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2504
+			'fieldname'       => $field,
2505
+			'linked_input_id' => $linked_input_id,
2506
+		];
2507
+
2508
+		return EEH_Template::display_template(
2509
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
+			$template_args,
2511
+			true
2512
+		);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2518
+	 * page)
2519
+	 *
2520
+	 * @access public
2521
+	 * @return void
2522
+	 * @throws EE_Error
2523
+	 * @throws InvalidArgumentException
2524
+	 * @throws ReflectionException
2525
+	 * @throws InvalidDataTypeException
2526
+	 * @throws InvalidInterfaceException
2527
+	 */
2528
+	public function shortcode_meta_box()
2529
+	{
2530
+		$shortcodes = $this->_get_shortcodes([], false);
2531
+		// just make sure the shortcodes property is set
2532
+		// $messenger = $this->_message_template_group->messenger_obj();
2533
+		// now let's set the content depending on the status of the shortcodes array
2534
+		if (empty($shortcodes)) {
2535
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
+			return;
2537
+		}
2538
+		?>
2539 2539
         <div style="float:right; margin-top:10px">
2540 2540
             <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped
2541
-            ?>
2541
+			?>
2542 2542
         </div>
2543 2543
         <p class="small-text">
2544 2544
             <?php printf(
2545
-                esc_html__(
2546
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2547
-                    'event_espresso'
2548
-                ),
2549
-                '<span class="dashicons dashicons-menu"></span>'
2550
-            ); ?>
2545
+				esc_html__(
2546
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2547
+					'event_espresso'
2548
+				),
2549
+				'<span class="dashicons dashicons-menu"></span>'
2550
+			); ?>
2551 2551
         </p>
2552 2552
         <?php
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * used to set the $_shortcodes property for when its needed elsewhere.
2558
-     *
2559
-     * @access protected
2560
-     * @return void
2561
-     * @throws EE_Error
2562
-     * @throws InvalidArgumentException
2563
-     * @throws ReflectionException
2564
-     * @throws InvalidDataTypeException
2565
-     * @throws InvalidInterfaceException
2566
-     */
2567
-    protected function _set_shortcodes()
2568
-    {
2569
-
2570
-        // no need to run this if the property is already set
2571
-        if (! empty($this->_shortcodes)) {
2572
-            return;
2573
-        }
2574
-
2575
-        $this->_shortcodes = $this->_get_shortcodes();
2576
-    }
2577
-
2578
-
2579
-    /**
2580
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2581
-     * property)
2582
-     *
2583
-     * @access  protected
2584
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2585
-     *                         for. Defaults to all (for the given context)
2586
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2587
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2588
-     *                         true just an array of shortcode/label pairs.
2589
-     * @throws EE_Error
2590
-     * @throws InvalidArgumentException
2591
-     * @throws ReflectionException
2592
-     * @throws InvalidDataTypeException
2593
-     * @throws InvalidInterfaceException
2594
-     */
2595
-    protected function _get_shortcodes($fields = [], $merged = true)
2596
-    {
2597
-        $this->_set_message_template_group();
2598
-
2599
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2600
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2601
-        if (empty($GRP_ID)) {
2602
-            return [];
2603
-        }
2604
-        $context = $this->request->getRequestParam(
2605
-            'messenger',
2606
-            key($this->_message_template_group->contexts_config())
2607
-        );
2608
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2609
-    }
2610
-
2611
-
2612
-    /**
2613
-     * This sets the _message_template property (containing the called message_template object)
2614
-     *
2615
-     * @access protected
2616
-     * @return void
2617
-     * @throws EE_Error
2618
-     * @throws InvalidArgumentException
2619
-     * @throws ReflectionException
2620
-     * @throws InvalidDataTypeException
2621
-     * @throws InvalidInterfaceException
2622
-     */
2623
-    protected function _set_message_template_group()
2624
-    {
2625
-        // get out if this is already set.
2626
-        if (! empty($this->_message_template_group)) {
2627
-            return;
2628
-        }
2629
-
2630
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2631
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2632
-
2633
-        // let's get the message templates
2634
-        $this->_message_template_group = ! empty($GRP_ID)
2635
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2636
-            : $this->getMtgModel()->create_default_object();
2637
-
2638
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2639
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2640
-    }
2641
-
2642
-
2643
-    /**
2644
-     * sets up a context switcher for edit forms
2645
-     *
2646
-     * @access  protected
2647
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2648
-     * @param array                     $args                  various things the context switcher needs.
2649
-     * @throws EE_Error
2650
-     */
2651
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2652
-    {
2653
-        $context_details = $template_group_object->contexts_config();
2654
-        $context_label   = $template_group_object->context_label();
2655
-        ob_start();
2656
-        ?>
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2558
+	 *
2559
+	 * @access protected
2560
+	 * @return void
2561
+	 * @throws EE_Error
2562
+	 * @throws InvalidArgumentException
2563
+	 * @throws ReflectionException
2564
+	 * @throws InvalidDataTypeException
2565
+	 * @throws InvalidInterfaceException
2566
+	 */
2567
+	protected function _set_shortcodes()
2568
+	{
2569
+
2570
+		// no need to run this if the property is already set
2571
+		if (! empty($this->_shortcodes)) {
2572
+			return;
2573
+		}
2574
+
2575
+		$this->_shortcodes = $this->_get_shortcodes();
2576
+	}
2577
+
2578
+
2579
+	/**
2580
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2581
+	 * property)
2582
+	 *
2583
+	 * @access  protected
2584
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2585
+	 *                         for. Defaults to all (for the given context)
2586
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2587
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2588
+	 *                         true just an array of shortcode/label pairs.
2589
+	 * @throws EE_Error
2590
+	 * @throws InvalidArgumentException
2591
+	 * @throws ReflectionException
2592
+	 * @throws InvalidDataTypeException
2593
+	 * @throws InvalidInterfaceException
2594
+	 */
2595
+	protected function _get_shortcodes($fields = [], $merged = true)
2596
+	{
2597
+		$this->_set_message_template_group();
2598
+
2599
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2600
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2601
+		if (empty($GRP_ID)) {
2602
+			return [];
2603
+		}
2604
+		$context = $this->request->getRequestParam(
2605
+			'messenger',
2606
+			key($this->_message_template_group->contexts_config())
2607
+		);
2608
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2609
+	}
2610
+
2611
+
2612
+	/**
2613
+	 * This sets the _message_template property (containing the called message_template object)
2614
+	 *
2615
+	 * @access protected
2616
+	 * @return void
2617
+	 * @throws EE_Error
2618
+	 * @throws InvalidArgumentException
2619
+	 * @throws ReflectionException
2620
+	 * @throws InvalidDataTypeException
2621
+	 * @throws InvalidInterfaceException
2622
+	 */
2623
+	protected function _set_message_template_group()
2624
+	{
2625
+		// get out if this is already set.
2626
+		if (! empty($this->_message_template_group)) {
2627
+			return;
2628
+		}
2629
+
2630
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2631
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2632
+
2633
+		// let's get the message templates
2634
+		$this->_message_template_group = ! empty($GRP_ID)
2635
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2636
+			: $this->getMtgModel()->create_default_object();
2637
+
2638
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2639
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2640
+	}
2641
+
2642
+
2643
+	/**
2644
+	 * sets up a context switcher for edit forms
2645
+	 *
2646
+	 * @access  protected
2647
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2648
+	 * @param array                     $args                  various things the context switcher needs.
2649
+	 * @throws EE_Error
2650
+	 */
2651
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2652
+	{
2653
+		$context_details = $template_group_object->contexts_config();
2654
+		$context_label   = $template_group_object->context_label();
2655
+		ob_start();
2656
+		?>
2657 2657
         <div class="ee-msg-switcher-container">
2658 2658
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2659 2659
                 <?php
2660
-                foreach ($args as $name => $value) {
2661
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2662
-                        continue;
2663
-                    }
2664
-                    ?>
2660
+				foreach ($args as $name => $value) {
2661
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2662
+						continue;
2663
+					}
2664
+					?>
2665 2665
                     <input type="hidden"
2666 2666
                            name="<?php echo esc_attr($name); ?>"
2667 2667
                            value="<?php echo esc_attr($value); ?>"
2668 2668
                     />
2669 2669
                     <?php
2670
-                }
2671
-                // setup nonce_url
2672
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
-                ?>
2670
+				}
2671
+				// setup nonce_url
2672
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
+				?>
2675 2675
                 <label for='<?php echo absint($id); ?>' class='screen-reader-text'>
2676 2676
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2677 2677
                 </label>
2678 2678
                 <select id="<?php echo absint($id); ?>" name="context">
2679 2679
                     <?php
2680
-                    $context_templates = $template_group_object->context_templates();
2681
-                    if (is_array($context_templates)) :
2682
-                        foreach ($context_templates as $context => $template_fields) :
2683
-                            $checked = ($context === $args['context']) ? 'selected' : '';
2684
-                            ?>
2680
+					$context_templates = $template_group_object->context_templates();
2681
+					if (is_array($context_templates)) :
2682
+						foreach ($context_templates as $context => $template_fields) :
2683
+							$checked = ($context === $args['context']) ? 'selected' : '';
2684
+							?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>
2686 2686
                                 <?php echo $context_details[ $context ]['label']; // already escaped
2687
-                                ?>
2687
+								?>
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"
@@ -2700,1995 +2700,1995 @@  discard block
 block discarded – undo
2700 2700
                 />
2701 2701
             </form>
2702 2702
             <?php echo $args['extra']; // already escaped
2703
-            ?>
2703
+			?>
2704 2704
         </div> <!-- end .ee-msg-switcher-container -->
2705 2705
         <?php
2706
-        $this->_context_switcher = ob_get_clean();
2707
-    }
2708
-
2709
-
2710
-    /**
2711
-     * @param bool $new
2712
-     * @throws EE_Error
2713
-     * @throws ReflectionException
2714
-     */
2715
-    protected function _insert_or_update_message_template($new = false)
2716
-    {
2717
-        $form_data    = $this->getMessageTemplateFormData();
2718
-        $GRP_ID       = $form_data['GRP_ID'];
2719
-        $messenger    = $form_data['MTP_messenger'];
2720
-        $message_type = $form_data['MTP_message_type'];
2721
-        $context      = $form_data['MTP_context'];
2722
-
2723
-        // if this is "new" then we need to generate the default contexts
2724
-        // for the selected messenger/message_type for user to edit.
2725
-        list($success, $query_args) = $new
2726
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2727
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2728
-
2729
-        $success     = $success ? 1 : 0;
2730
-        $action_desc = $new ? 'created' : 'updated';
2731
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2732
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2733
-
2734
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2735
-    }
2736
-
2737
-
2738
-    /**
2739
-     * retrieve and sanitize form data
2740
-     *
2741
-     * @return array
2742
-     * @since 4.10.29.p
2743
-     */
2744
-    protected function getMessageTemplateFormData()
2745
-    {
2746
-        return [
2747
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2748
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2749
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2750
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2751
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2752
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2753
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2754
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2755
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2756
-        ];
2757
-    }
2758
-
2759
-
2760
-    /**
2761
-     * @param int    $GRP_ID
2762
-     * @param string $messenger
2763
-     * @param string $message_type
2764
-     * @return array no return on AJAX requests
2765
-     * @throws EE_Error
2766
-     * @throws ReflectionException
2767
-     * @since 4.10.29.p
2768
-     */
2769
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2770
-    {
2771
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2772
-        $success       = ! empty($new_templates);
2773
-
2774
-        // we return things differently if doing ajax
2775
-        if ($this->request->isAjax()) {
2776
-            $this->_template_args['success'] = $success;
2777
-            $this->_template_args['error']   = ! $success;
2778
-            $this->_template_args['content'] = '';
2779
-            $this->_template_args['data']    = [
2780
-                'grpID'        => $new_templates['GRP_ID'],
2781
-                'templateName' => $new_templates['template_name'],
2782
-            ];
2783
-            if ($success) {
2784
-                EE_Error::overwrite_success();
2785
-                EE_Error::add_success(
2786
-                    esc_html__(
2787
-                        '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.',
2788
-                        'event_espresso'
2789
-                    )
2790
-                );
2791
-            }
2792
-            $this->_return_json();
2793
-        }
2794
-        return [
2795
-            $success,
2796
-            // 'query_args'
2797
-            [
2798
-                'id'      => $new_templates['GRP_ID'],
2799
-                'context' => $new_templates['MTP_context'],
2800
-                'action'  => 'edit_message_template',
2801
-            ],
2802
-        ];
2803
-    }
2804
-
2805
-
2806
-    /**
2807
-     * @param int    $GRP_ID
2808
-     * @param string $messenger
2809
-     * @param string $message_type
2810
-     * @param string $context
2811
-     * @param array  $form_data
2812
-     * @return array
2813
-     * @throws EE_Error
2814
-     * @since 4.10.29.p
2815
-     */
2816
-    private function updateExistingTemplates(
2817
-        $GRP_ID,
2818
-        $messenger,
2819
-        $message_type,
2820
-        $context,
2821
-        array $form_data
2822
-    ) {
2823
-        $success         = false;
2824
-        $template_fields = $this->getTemplateFields();
2825
-        if ($template_fields) {
2826
-            // if field data is valid, then success will be true
2827
-            $success = $this->validateTemplateFields(
2828
-                $messenger,
2829
-                $message_type,
2830
-                $context,
2831
-                $template_fields
2832
-            );
2833
-            if ($success) {
2834
-                $field_data = [];
2835
-                foreach ($template_fields as $template_field => $content) {
2836
-                    // combine top-level form data with content for this field
2837
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2838
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2839
-                }
2840
-                // we can use the last set_column_values for the MTPG update
2841
-                // (because its the same for all of these specific MTPs)
2842
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2843
-            }
2844
-        }
2845
-
2846
-        return [
2847
-            $success,
2848
-            // 'query_args'
2849
-            [
2850
-                'id'      => $GRP_ID,
2851
-                'context' => $context,
2852
-                'action'  => 'edit_message_template',
2853
-            ],
2854
-        ];
2855
-    }
2856
-
2857
-
2858
-    /**
2859
-     * @return array
2860
-     * @since 4.10.29.p
2861
-     */
2862
-    private function getTemplateFields()
2863
-    {
2864
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2865
-        if (empty($template_fields)) {
2866
-            EE_Error::add_error(
2867
-                esc_html__(
2868
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2869
-                    'event_espresso'
2870
-                ),
2871
-                __FILE__,
2872
-                __FUNCTION__,
2873
-                __LINE__
2874
-            );
2875
-            return null;
2876
-        }
2877
-        // messages content is expected to be escaped
2878
-        return EEH_Array::addSlashesRecursively($template_fields);
2879
-    }
2880
-
2881
-
2882
-    /**
2883
-     * @param string $messenger
2884
-     * @param string $message_type
2885
-     * @param string $context
2886
-     * @param array  $template_fields
2887
-     * @return bool
2888
-     * @throws EE_Error
2889
-     * @since   4.10.29.p
2890
-     */
2891
-    private function validateTemplateFields(
2892
-        $messenger,
2893
-        $message_type,
2894
-        $context,
2895
-        array $template_fields
2896
-    ) {
2897
-        // first validate all fields!
2898
-        // this filter allows client code to add its own validation to the template fields as well.
2899
-        // returning an empty array means everything passed validation.
2900
-        // errors in validation should be represented in an array with the following shape:
2901
-        // array(
2902
-        //   'fieldname' => array(
2903
-        //          'msg' => 'error message'
2904
-        //          'value' => 'value for field producing error'
2905
-        // )
2906
-        $custom_validation = (array) apply_filters(
2907
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2908
-            [],
2909
-            $template_fields,
2910
-            $context,
2911
-            $messenger,
2912
-            $message_type
2913
-        );
2914
-
2915
-        $system_validation = $this->getMtgModel()->validate(
2916
-            $template_fields,
2917
-            $context,
2918
-            $messenger,
2919
-            $message_type
2920
-        );
2921
-
2922
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2923
-        $validates         = array_merge($custom_validation, $system_validation);
2924
-
2925
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2926
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2927
-        //  WE need to make sure there is no actual error messages in validates.
2928
-        if (empty($validates)) {
2929
-            return true;
2930
-        }
2931
-
2932
-        // add the transient so when the form loads we know which fields to highlight
2933
-        $this->_add_transient('edit_message_template', $validates);
2934
-        // setup notices
2935
-        foreach ($validates as $error) {
2936
-            if (isset($error['msg'])) {
2937
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2938
-            }
2939
-        }
2940
-        return false;
2941
-    }
2942
-
2943
-
2944
-    /**
2945
-     * @param array $field_data
2946
-     * @param array $form_data
2947
-     * @return array
2948
-     * @since   4.10.29.p
2949
-     */
2950
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2951
-    {
2952
-        return $form_data + [
2953
-                'MTP_ID'             => $field_data['MTP_ID'],
2954
-                'MTP_template_field' => $field_data['name'],
2955
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2956
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2957
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2958
-                    : $field_data['content'],
2959
-            ];
2960
-    }
2961
-
2962
-
2963
-    /**
2964
-     * @param string $template_field
2965
-     * @param array  $form_data
2966
-     * @return bool
2967
-     * @throws EE_Error
2968
-     * @since 4.10.29.p
2969
-     */
2970
-    private function updateMessageTemplates($template_field, array $form_data)
2971
-    {
2972
-        $MTP_ID                  = $form_data['MTP_ID'];
2973
-        $message_template_fields = [
2974
-            'GRP_ID'             => $form_data['GRP_ID'],
2975
-            'MTP_template_field' => $form_data['MTP_template_field'],
2976
-            'MTP_context'        => $form_data['MTP_context'],
2977
-            'MTP_content'        => $form_data['MTP_content'],
2978
-        ];
2979
-
2980
-        $hasMtpID = ! empty($MTP_ID);
2981
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2982
-        // this has already been through the template field validator and sanitized, so it will be
2983
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2984
-        // message template field in a messenger/message type and existing users don't have the
2985
-        // default setup for it.
2986
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2987
-        $updated = $hasMtpID
2988
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2989
-            : $this->getMtpModel()->insert($message_template_fields);
2990
-
2991
-        $insert_failed = ! $hasMtpID && ! $updated;
2992
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2993
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2994
-        $update_failed = $hasMtpID && $updated === false;
2995
-
2996
-        if ($insert_failed || $update_failed) {
2997
-            EE_Error::add_error(
2998
-                sprintf(
2999
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3000
-                    $template_field
3001
-                ),
3002
-                __FILE__,
3003
-                __FUNCTION__,
3004
-                __LINE__
3005
-            );
3006
-            return false;
3007
-        }
3008
-        return true;
3009
-    }
3010
-
3011
-
3012
-    /**
3013
-     * @param array $form_data
3014
-     * @return bool
3015
-     * @throws EE_Error
3016
-     * @since 4.10.29.p
3017
-     */
3018
-    private function updateMessageTemplateGroup(array $form_data)
3019
-    {
3020
-        $GRP_ID  = $form_data['GRP_ID'];
3021
-        $updated = $this->getMtgModel()->update(
3022
-        // fields and values
3023
-            [
3024
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3025
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3026
-                'MTP_message_type' => $form_data['MTP_message_type'],
3027
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3028
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3029
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3030
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3031
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3032
-                'MTP_description'  => $this->request->getRequestParam(
3033
-                    'ee_msg_non_global_fields[MTP_description]',
3034
-                    ''
3035
-                ),
3036
-            ],
3037
-            // where
3038
-            [['GRP_ID' => $GRP_ID]]
3039
-        );
3040
-
3041
-        if ($updated === false) {
3042
-            EE_Error::add_error(
3043
-                sprintf(
3044
-                    esc_html__(
3045
-                        'The Message Template Group (%d) was NOT updated for some reason',
3046
-                        'event_espresso'
3047
-                    ),
3048
-                    $form_data['GRP_ID']
3049
-                ),
3050
-                __FILE__,
3051
-                __FUNCTION__,
3052
-                __LINE__
3053
-            );
3054
-            return false;
3055
-        }
3056
-        // k now we need to ensure the template_pack and template_variation fields are set.
3057
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3058
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3059
-
3060
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3061
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3062
-            $message_template_group->set_template_pack_name($template_pack);
3063
-            $message_template_group->set_template_pack_variation($template_variation);
3064
-        }
3065
-        return true;
3066
-    }
3067
-
3068
-
3069
-    /**
3070
-     * recursively runs wp_kses() on message template content in a model safe manner
3071
-     *
3072
-     * @param array|string $content
3073
-     * @return array|string
3074
-     * @since   4.10.29.p
3075
-     */
3076
-    private function sanitizeMessageTemplateContent($content)
3077
-    {
3078
-        if (is_array($content)) {
3079
-            foreach ($content as $key => $value) {
3080
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3081
-            }
3082
-            return $content;
3083
-        }
3084
-        // remove slashes so wp_kses() works properly
3085
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3086
-        // so attributes using single quotes always appear invalid.
3087
-        $content = stripslashes($content);
3088
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3089
-        // But currently the models expect slashed data, so after wp_kses()
3090
-        // runs we need to re-slash the data. Sheesh.
3091
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3092
-        return addslashes($content);
3093
-    }
3094
-
3095
-
3096
-    /**
3097
-     * @param string $messenger
3098
-     * @param string $message_type
3099
-     * @param string $context
3100
-     * @return string
3101
-     * @since 4.10.29.p
3102
-     */
3103
-    private function generateUpdateDescription($messenger, $message_type, $context)
3104
-    {
3105
-        // need the message type and messenger objects to be able to use the labels for the notices
3106
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3107
-        $messenger_label  = $messenger_object instanceof EE_messenger
3108
-            ? ucwords($messenger_object->label['singular'])
3109
-            : '';
3110
-
3111
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3112
-        $message_type_label  = $message_type_object instanceof EE_message_type
3113
-            ? ucwords($message_type_object->label['singular'])
3114
-            : '';
3115
-
3116
-        $context   = ucwords(str_replace('_', ' ', $context));
3117
-        $item_desc = $messenger_label && $message_type_label
3118
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3119
-            : '';
3120
-        $item_desc .= 'Message Template';
3121
-        return $item_desc;
3122
-    }
3123
-
3124
-
3125
-    /**
3126
-     * @param string $messenger
3127
-     * @param string $message_type
3128
-     * @param string $context
3129
-     * @return bool
3130
-     * @throws EE_Error
3131
-     * @throws ReflectionException
3132
-     * @since 4.10.29.p
3133
-     */
3134
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3135
-    {
3136
-        // was a test send triggered?
3137
-        if ($this->request->requestParamIsSet('test_button')) {
3138
-            EE_Error::overwrite_success();
3139
-            $this->_do_test_send($context, $messenger, $message_type);
3140
-            return true;
3141
-        }
3142
-        return false;
3143
-    }
3144
-
3145
-
3146
-    /**
3147
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3148
-     *
3149
-     * @param string $context      what context being tested
3150
-     * @param string $messenger    messenger being tested
3151
-     * @param string $message_type message type being tested
3152
-     * @throws EE_Error
3153
-     * @throws InvalidArgumentException
3154
-     * @throws InvalidDataTypeException
3155
-     * @throws InvalidInterfaceException
3156
-     * @throws ReflectionException
3157
-     */
3158
-    protected function _do_test_send($context, $messenger, $message_type)
3159
-    {
3160
-        // set things up for preview
3161
-        $this->request->setRequestParam('messenger', $messenger);
3162
-        $this->request->setRequestParam('message_type', $message_type);
3163
-        $this->request->setRequestParam('context', $context);
3164
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3165
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3166
-
3167
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3168
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3169
-
3170
-        // let's save any existing fields that might be required by the messenger
3171
-        if (
3172
-            ! empty($test_settings_fld)
3173
-            && $active_messenger instanceof EE_messenger
3174
-            && apply_filters(
3175
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3176
-                true,
3177
-                $test_settings_fld,
3178
-                $active_messenger
3179
-            )
3180
-        ) {
3181
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3182
-        }
3183
-
3184
-        /**
3185
-         * Use filter to add additional controls on whether message can send or not
3186
-         */
3187
-        if (
3188
-            apply_filters(
3189
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3190
-                true,
3191
-                $context,
3192
-                $this->request->requestParams(),
3193
-                $messenger,
3194
-                $message_type
3195
-            )
3196
-        ) {
3197
-            if (EEM_Event::instance()->count() > 0) {
3198
-                $success = $this->_preview_message(true);
3199
-                if ($success) {
3200
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3201
-                } else {
3202
-                    EE_Error::add_error(
3203
-                        esc_html__('The test message was not sent', 'event_espresso'),
3204
-                        __FILE__,
3205
-                        __FUNCTION__,
3206
-                        __LINE__
3207
-                    );
3208
-                }
3209
-            } else {
3210
-                $this->noEventsErrorMessage(true);
3211
-            }
3212
-        }
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * _generate_new_templates
3218
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3219
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3220
-     * for the event.
3221
-     *
3222
-     *
3223
-     * @param string $messenger      the messenger we are generating templates for
3224
-     * @param array  $message_types  array of message types that the templates are generated for.
3225
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3226
-     *                               indicate the message_template_group being used as the base.
3227
-     *
3228
-     * @param bool   $global
3229
-     *
3230
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3231
-     *                               encountering problems.
3232
-     * @throws EE_Error
3233
-     * @throws ReflectionException
3234
-     */
3235
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3236
-    {
3237
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3238
-        // just don't generate any templates.
3239
-        if (empty($message_types)) {
3240
-            return [];
3241
-        }
3242
-
3243
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3244
-        return $templates[0];
3245
-    }
3246
-
3247
-
3248
-    /**
3249
-     * [_trash_or_restore_message_template]
3250
-     *
3251
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3252
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3253
-     *                        an individual context (FALSE).
3254
-     * @return void
3255
-     * @throws EE_Error
3256
-     * @throws InvalidArgumentException
3257
-     * @throws InvalidDataTypeException
3258
-     * @throws InvalidInterfaceException
3259
-     */
3260
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3261
-    {
3262
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3263
-
3264
-        $success = 1;
3265
-
3266
-        // incoming GRP_IDs
3267
-        if ($all) {
3268
-            // Checkboxes
3269
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
-            if (! empty($checkboxes)) {
3271
-                // if array has more than one element then success message should be plural.
3272
-                // todo: what about nonce?
3273
-                $success = count($checkboxes) > 1 ? 2 : 1;
3274
-
3275
-                // cycle through checkboxes
3276
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3277
-                    $trashed_or_restored = $trash
3278
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
-                    if (! $trashed_or_restored) {
3281
-                        $success = 0;
3282
-                    }
3283
-                }
3284
-            } else {
3285
-                // grab single GRP_ID and handle
3286
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
-                if (! empty($GRP_ID)) {
3288
-                    $trashed_or_restored = $trash
3289
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
-                    if (! $trashed_or_restored) {
3292
-                        $success = 0;
3293
-                    }
3294
-                } else {
3295
-                    $success = 0;
3296
-                }
3297
-            }
3298
-        }
3299
-
3300
-        $action_desc = $trash
3301
-            ? esc_html__('moved to the trash', 'event_espresso')
3302
-            : esc_html__('restored', 'event_espresso');
3303
-
3304
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3305
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3306
-
3307
-        $item_desc = $all ? _n(
3308
-            'Message Template Group',
3309
-            'Message Template Groups',
3310
-            $success,
3311
-            'event_espresso'
3312
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3313
-
3314
-        $item_desc = $template_switch
3315
-            ? _n('template', 'templates', $success, 'event_espresso')
3316
-            : $item_desc;
3317
-
3318
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3319
-    }
3320
-
3321
-
3322
-    /**
3323
-     * [_delete_message_template]
3324
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3325
-     *
3326
-     * @return void
3327
-     * @throws EE_Error
3328
-     * @throws InvalidArgumentException
3329
-     * @throws InvalidDataTypeException
3330
-     * @throws InvalidInterfaceException
3331
-     * @throws ReflectionException
3332
-     */
3333
-    protected function _delete_message_template()
3334
-    {
3335
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3336
-
3337
-        // checkboxes
3338
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
-        if (! empty($checkboxes)) {
3340
-            // if array has more than one element then success message should be plural
3341
-            $success = count($checkboxes) > 1 ? 2 : 1;
3342
-
3343
-            // cycle through bulk action checkboxes
3344
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3345
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3346
-            }
3347
-        } else {
3348
-            // grab single grp_id and delete
3349
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3350
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3351
-        }
3352
-
3353
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3354
-    }
3355
-
3356
-
3357
-    /**
3358
-     * helper for permanently deleting a mtP group and all related message_templates
3359
-     *
3360
-     * @param int  $GRP_ID        The group being deleted
3361
-     * @param bool $include_group whether to delete the Message Template Group as well.
3362
-     * @return bool boolean to indicate the success of the deletes or not.
3363
-     * @throws EE_Error
3364
-     * @throws InvalidArgumentException
3365
-     * @throws InvalidDataTypeException
3366
-     * @throws InvalidInterfaceException
3367
-     * @throws ReflectionException
3368
-     * @throws ReflectionException
3369
-     */
3370
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3371
-    {
3372
-        $success = true;
3373
-        // first let's GET this group
3374
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3375
-        // then delete permanently all the related Message Templates
3376
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3377
-
3378
-        if ($deleted === 0) {
3379
-            $success = false;
3380
-        }
3381
-
3382
-        // now delete permanently this particular group
3383
-
3384
-        if ($include_group && ! $MTG->delete_permanently()) {
3385
-            $success = false;
3386
-        }
3387
-
3388
-        return $success;
3389
-    }
3390
-
3391
-
3392
-    /**
3393
-     *    _learn_more_about_message_templates_link
3394
-     *
3395
-     * @access protected
3396
-     * @return string
3397
-     */
3398
-    protected function _learn_more_about_message_templates_link()
3399
-    {
3400
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3401
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3402
-               . '</a>';
3403
-    }
3404
-
3405
-
3406
-    /**
3407
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3408
-     * ajax and other routes.
3409
-     *
3410
-     * @return void
3411
-     * @throws DomainException
3412
-     * @throws EE_Error
3413
-     */
3414
-    protected function _settings()
3415
-    {
3416
-        $this->_set_m_mt_settings();
3417
-
3418
-        // let's setup the messenger tabs
3419
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3420
-            $this->_m_mt_settings['messenger_tabs'],
3421
-            'messenger_links',
3422
-            '|',
3423
-            $this->request->getRequestParam('selected_messenger', 'email')
3424
-        );
3425
-
3426
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3427
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3428
-
3429
-        $this->display_admin_page_with_sidebar();
3430
-    }
3431
-
3432
-
3433
-    /**
3434
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3435
-     *
3436
-     * @access protected
3437
-     * @return void
3438
-     * @throws DomainException
3439
-     */
3440
-    protected function _set_m_mt_settings()
3441
-    {
3442
-        // first if this is already set then lets get out no need to regenerate data.
3443
-        if (! empty($this->_m_mt_settings)) {
3444
-            return;
3445
-        }
3446
-
3447
-        // get all installed messengers and message_types
3448
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3449
-        $message_types = $this->_message_resource_manager->installed_message_types();
3450
-
3451
-
3452
-        // assemble the array for the _tab_text_links helper
3453
-
3454
-        foreach ($messengers as $messenger) {
3455
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3456
-                'label' => ucwords($messenger->label['singular']),
3457
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458
-                    ? 'messenger-active'
3459
-                    : '',
3460
-                'href'  => $messenger->name,
3461
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3462
-                'slug'  => $messenger->name,
3463
-                'obj'   => $messenger,
3464
-            ];
3465
-
3466
-
3467
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3468
-
3469
-            foreach ($message_types as $message_type) {
3470
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471
-                // it shouldn't show in either the inactive OR active metabox.
3472
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3473
-                    continue;
3474
-                }
3475
-
3476
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3477
-                    $messenger->name,
3478
-                    $message_type->name
3479
-                )
3480
-                    ? 'active'
3481
-                    : 'inactive';
3482
-
3483
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3484
-                    'label'    => ucwords($message_type->label['singular']),
3485
-                    'class'    => 'message-type-' . $a_or_i,
3486
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3489
-                    'title'    => $a_or_i === 'active'
3490
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3492
-                    'content'  => $a_or_i === 'active'
3493
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3494
-                        : $this->_message_type_settings_content($message_type, $messenger),
3495
-                    'slug'     => $message_type->name,
3496
-                    'active'   => $a_or_i === 'active',
3497
-                    'obj'      => $message_type,
3498
-                ];
3499
-            }
3500
-        }
3501
-    }
3502
-
3503
-
3504
-    /**
3505
-     * This just prepares the content for the message type settings
3506
-     *
3507
-     * @param EE_message_type $message_type The message type object
3508
-     * @param EE_messenger    $messenger    The messenger object
3509
-     * @param boolean         $active       Whether the message type is active or not
3510
-     * @return string html output for the content
3511
-     * @throws DomainException
3512
-     */
3513
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3514
-    {
3515
-        // get message type fields
3516
-        $fields                                         = $message_type->get_admin_settings_fields();
3517
-        $settings_template_args['template_form_fields'] = '';
3518
-
3519
-        if (! empty($fields) && $active) {
3520
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521
-            foreach ($fields as $fldname => $fldprops) {
3522
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
-                $template_form_field[ $field_id ] = [
3524
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3525
-                    'label'      => $fldprops['label'],
3526
-                    'input'      => $fldprops['field_type'],
3527
-                    'type'       => $fldprops['value_type'],
3528
-                    'required'   => $fldprops['required'],
3529
-                    'validation' => $fldprops['validation'],
3530
-                    'value'      => isset($existing_settings[ $fldname ])
3531
-                        ? $existing_settings[ $fldname ]
3532
-                        : $fldprops['default'],
3533
-                    'options'    => isset($fldprops['options'])
3534
-                        ? $fldprops['options']
3535
-                        : [],
3536
-                    'default'    => isset($existing_settings[ $fldname ])
3537
-                        ? $existing_settings[ $fldname ]
3538
-                        : $fldprops['default'],
3539
-                    'css_class'  => 'no-drag',
3540
-                    'format'     => $fldprops['format'],
3541
-                ];
3542
-            }
3543
-
3544
-
3545
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3546
-                ? $this->_generate_admin_form_fields(
3547
-                    $template_form_field,
3548
-                    'string',
3549
-                    'ee_mt_activate_form'
3550
-                )
3551
-                : '';
3552
-        }
3553
-
3554
-        $settings_template_args['description'] = $message_type->description;
3555
-        // we also need some hidden fields
3556
-        $hidden_fields = [
3557
-            'message_type_settings[messenger]' . $message_type->name    => [
3558
-                'type'  => 'hidden',
3559
-                'value' => $messenger->name,
3560
-            ],
3561
-            'message_type_settings[message_type]' . $message_type->name => [
3562
-                'type'  => 'hidden',
3563
-                'value' => $message_type->name,
3564
-            ],
3565
-            'type' . $message_type->name                                => [
3566
-                'type'  => 'hidden',
3567
-                'value' => 'message_type',
3568
-            ],
3569
-        ];
3570
-
3571
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3572
-            $hidden_fields,
3573
-            'array'
3574
-        );
3575
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3576
-            ? ' hidden'
3577
-            : '';
3578
-
3579
-
3580
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3581
-        return EEH_Template::display_template($template, $settings_template_args, true);
3582
-    }
3583
-
3584
-
3585
-    /**
3586
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3587
-     *
3588
-     * @access protected
3589
-     * @return void
3590
-     * @throws DomainException
3591
-     */
3592
-    protected function _messages_settings_metaboxes()
3593
-    {
3594
-        $this->_set_m_mt_settings();
3595
-        $m_boxes         = $mt_boxes = [];
3596
-        $m_template_args = $mt_template_args = [];
3597
-
3598
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3599
-
3600
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3601
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3602
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3603
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3604
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3605
-
3606
-                // messenger meta boxes
3607
-                $active         = $selected_messenger === $messenger;
3608
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
-                    : '';
3611
-
3612
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3613
-                    esc_html__('%s Settings', 'event_espresso'),
3614
-                    $tab_array['label']
3615
-                );
3616
-
3617
-                $m_template_args[ $messenger . '_a_box' ] = [
3618
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619
-                    'inactive_message_types' => isset(
3620
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3621
-                    )
3622
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3623
-                        : '',
3624
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625
-                    'hidden'                 => $active ? '' : ' hidden',
3626
-                    'hide_on_message'        => $hide_on_message,
3627
-                    'messenger'              => $messenger,
3628
-                    'active'                 => $active,
3629
-                ];
3630
-
3631
-                // message type meta boxes
3632
-                // (which is really just the inactive container for each messenger
3633
-                // showing inactive message types for that messenger)
3634
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
-                $mt_template_args[ $messenger . '_i_box' ] = [
3636
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637
-                    'inactive_message_types' => isset(
3638
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3639
-                    )
3640
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3641
-                        : '',
3642
-                    'hidden'                 => $active ? '' : ' hidden',
3643
-                    'hide_on_message'        => $hide_on_message,
3644
-                    'hide_off_message'       => $hide_off_message,
3645
-                    'messenger'              => $messenger,
3646
-                    'active'                 => $active,
3647
-                ];
3648
-            }
3649
-        }
3650
-
3651
-
3652
-        // register messenger metaboxes
3653
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3654
-        foreach ($m_boxes as $box => $label) {
3655
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3656
-            $msgr          = str_replace('_a_box', '', $box);
3657
-            add_meta_box(
3658
-                'espresso_' . $msgr . '_settings',
3659
-                $label,
3660
-                function ($post, $metabox) {
3661
-                    EEH_Template::display_template(
3662
-                        $metabox['args']['template_path'],
3663
-                        $metabox['args']['template_args']
3664
-                    );
3665
-                },
3666
-                $this->_current_screen->id,
3667
-                'normal',
3668
-                'high',
3669
-                $callback_args
3670
-            );
3671
-        }
3672
-
3673
-        // register message type metaboxes
3674
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3675
-        foreach ($mt_boxes as $box => $label) {
3676
-            $callback_args = [
3677
-                'template_path' => $mt_template_path,
3678
-                'template_args' => $mt_template_args[ $box ],
3679
-            ];
3680
-            $mt            = str_replace('_i_box', '', $box);
3681
-            add_meta_box(
3682
-                'espresso_' . $mt . '_inactive_mts',
3683
-                $label,
3684
-                function ($post, $metabox) {
3685
-                    EEH_Template::display_template(
3686
-                        $metabox['args']['template_path'],
3687
-                        $metabox['args']['template_args']
3688
-                    );
3689
-                },
3690
-                $this->_current_screen->id,
3691
-                'side',
3692
-                'high',
3693
-                $callback_args
3694
-            );
3695
-        }
3696
-
3697
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3698
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3699
-        if (is_main_site()) {
3700
-            add_meta_box(
3701
-                'espresso_global_message_settings',
3702
-                esc_html__('Global Message Settings', 'event_espresso'),
3703
-                [$this, 'global_messages_settings_metabox_content'],
3704
-                $this->_current_screen->id,
3705
-                'normal',
3706
-                'low',
3707
-                []
3708
-            );
3709
-        }
3710
-    }
3711
-
3712
-
3713
-    /**
3714
-     *  This generates the content for the global messages settings metabox.
3715
-     *
3716
-     * @return void
3717
-     * @throws EE_Error
3718
-     * @throws InvalidArgumentException
3719
-     * @throws ReflectionException
3720
-     * @throws InvalidDataTypeException
3721
-     * @throws InvalidInterfaceException
3722
-     */
3723
-    public function global_messages_settings_metabox_content()
3724
-    {
3725
-        $form = $this->_generate_global_settings_form();
3726
-        // already escaped
3727
-        echo $form->form_open(
3728
-            $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3729
-            'POST'
3730
-        );
3731
-        echo $form->get_html();
3732
-        echo $form->form_close();
3733
-    }
3734
-
3735
-
3736
-    /**
3737
-     * This generates and returns the form object for the global messages settings.
3738
-     *
3739
-     * @return EE_Form_Section_Proper
3740
-     * @throws EE_Error
3741
-     * @throws InvalidArgumentException
3742
-     * @throws ReflectionException
3743
-     * @throws InvalidDataTypeException
3744
-     * @throws InvalidInterfaceException
3745
-     */
3746
-    protected function _generate_global_settings_form()
3747
-    {
3748
-        /** @var EE_Network_Core_Config $network_config */
3749
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3750
-
3751
-        return new EE_Form_Section_Proper(
3752
-            [
3753
-                'name'            => 'global_messages_settings',
3754
-                'html_id'         => 'global_messages_settings',
3755
-                'html_class'      => 'form-table',
3756
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3757
-                'subsections'     => apply_filters(
3758
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3759
-                    [
3760
-                        'do_messages_on_same_request' => new EE_Select_Input(
3761
-                            [
3762
-                                true  => esc_html__('On the same request', 'event_espresso'),
3763
-                                false => esc_html__('On a separate request', 'event_espresso'),
3764
-                            ],
3765
-                            [
3766
-                                'default'         => $network_config->do_messages_on_same_request,
3767
-                                'html_label_text' => esc_html__(
3768
-                                    'Generate and send all messages:',
3769
-                                    'event_espresso'
3770
-                                ),
3771
-                                'html_help_text'  => esc_html__(
3772
-                                    '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.',
3773
-                                    'event_espresso'
3774
-                                ),
3775
-                            ]
3776
-                        ),
3777
-                        'delete_threshold'            => new EE_Select_Input(
3778
-                            [
3779
-                                0  => esc_html__('Forever', 'event_espresso'),
3780
-                                3  => esc_html__('3 Months', 'event_espresso'),
3781
-                                6  => esc_html__('6 Months', 'event_espresso'),
3782
-                                9  => esc_html__('9 Months', 'event_espresso'),
3783
-                                12 => esc_html__('12 Months', 'event_espresso'),
3784
-                                24 => esc_html__('24 Months', 'event_espresso'),
3785
-                                36 => esc_html__('36 Months', 'event_espresso'),
3786
-                            ],
3787
-                            [
3788
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3789
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3790
-                                'html_help_text'  => esc_html__(
3791
-                                    'You can control how long a record of processed messages is kept via this option.',
3792
-                                    'event_espresso'
3793
-                                ),
3794
-                            ]
3795
-                        ),
3796
-                        'update_settings'             => new EE_Submit_Input(
3797
-                            [
3798
-                                'default'         => esc_html__('Update', 'event_espresso'),
3799
-                                'html_label_text' => '&nbsp',
3800
-                            ]
3801
-                        ),
3802
-                    ]
3803
-                ),
3804
-            ]
3805
-        );
3806
-    }
3807
-
3808
-
3809
-    /**
3810
-     * This handles updating the global settings set on the admin page.
3811
-     *
3812
-     * @throws EE_Error
3813
-     * @throws InvalidDataTypeException
3814
-     * @throws InvalidInterfaceException
3815
-     * @throws InvalidArgumentException
3816
-     * @throws ReflectionException
3817
-     */
3818
-    protected function _update_global_settings()
3819
-    {
3820
-        /** @var EE_Network_Core_Config $network_config */
3821
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3822
-        $messages_config = EE_Registry::instance()->CFG->messages;
3823
-        $form            = $this->_generate_global_settings_form();
3824
-        if ($form->was_submitted()) {
3825
-            $form->receive_form_submission();
3826
-            if ($form->is_valid()) {
3827
-                $valid_data = $form->valid_data();
3828
-                foreach ($valid_data as $property => $value) {
3829
-                    $setter = 'set_' . $property;
3830
-                    if (method_exists($network_config, $setter)) {
3831
-                        $network_config->{$setter}($value);
3832
-                    } elseif (
3833
-                        property_exists($network_config, $property)
3834
-                        && $network_config->{$property} !== $value
3835
-                    ) {
3836
-                        $network_config->{$property} = $value;
3837
-                    } elseif (
3838
-                        property_exists($messages_config, $property)
3839
-                        && $messages_config->{$property} !== $value
3840
-                    ) {
3841
-                        $messages_config->{$property} = $value;
3842
-                    }
3843
-                }
3844
-                // only update if the form submission was valid!
3845
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3846
-                EE_Registry::instance()->CFG->update_espresso_config();
3847
-                EE_Error::overwrite_success();
3848
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3849
-            }
3850
-        }
3851
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3857
-     *
3858
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3859
-     * @return string html formatted tabs
3860
-     * @throws DomainException
3861
-     */
3862
-    protected function _get_mt_tabs($tab_array)
3863
-    {
3864
-        $tab_array = (array) $tab_array;
3865
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
-        $tabs      = '';
3867
-
3868
-        foreach ($tab_array as $tab) {
3869
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3870
-        }
3871
-
3872
-        return $tabs;
3873
-    }
3874
-
3875
-
3876
-    /**
3877
-     * This prepares the content of the messenger meta box admin settings
3878
-     *
3879
-     * @param EE_messenger $messenger The messenger we're setting up content for
3880
-     * @return string html formatted content
3881
-     * @throws DomainException
3882
-     */
3883
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3884
-    {
3885
-
3886
-        $fields                                         = $messenger->get_admin_settings_fields();
3887
-        $settings_template_args['template_form_fields'] = '';
3888
-
3889
-        // is $messenger active?
3890
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891
-
3892
-
3893
-        if (! empty($fields)) {
3894
-            $existing_settings = $messenger->get_existing_admin_settings();
3895
-
3896
-            foreach ($fields as $fldname => $fldprops) {
3897
-                $field_id                         = $messenger->name . '-' . $fldname;
3898
-                $template_form_field[ $field_id ] = [
3899
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3900
-                    'label'      => $fldprops['label'],
3901
-                    'input'      => $fldprops['field_type'],
3902
-                    'type'       => $fldprops['value_type'],
3903
-                    'required'   => $fldprops['required'],
3904
-                    'validation' => $fldprops['validation'],
3905
-                    'value'      => isset($existing_settings[ $field_id ])
3906
-                        ? $existing_settings[ $field_id ]
3907
-                        : $fldprops['default'],
3908
-                    'css_class'  => '',
3909
-                    'format'     => $fldprops['format'],
3910
-                ];
3911
-            }
3912
-
3913
-
3914
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3915
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3916
-                : '';
3917
-        }
3918
-
3919
-        // we also need some hidden fields
3920
-        $settings_template_args['hidden_fields'] = [
3921
-            'messenger_settings[messenger]' . $messenger->name => [
3922
-                'type'  => 'hidden',
3923
-                'value' => $messenger->name,
3924
-            ],
3925
-            'type' . $messenger->name                          => [
3926
-                'type'  => 'hidden',
3927
-                'value' => 'messenger',
3928
-            ],
3929
-        ];
3930
-
3931
-        // make sure any active message types that are existing are included in the hidden fields
3932
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3935
-                    'type'  => 'hidden',
3936
-                    'value' => $mt,
3937
-                ];
3938
-            }
3939
-        }
3940
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3941
-            $settings_template_args['hidden_fields'],
3942
-            'array'
3943
-        );
3944
-        $active                                  =
3945
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3946
-
3947
-        $settings_template_args['messenger']           = $messenger->name;
3948
-        $settings_template_args['description']         = $messenger->description;
3949
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3950
-
3951
-
3952
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3953
-            $messenger->name
3954
-        )
3955
-            ? $settings_template_args['show_hide_edit_form']
3956
-            : ' hidden';
3957
-
3958
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3959
-            ? ' hidden'
3960
-            : $settings_template_args['show_hide_edit_form'];
3961
-
3962
-
3963
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
-        $settings_template_args['on_off_status'] = $active;
3966
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
-        return EEH_Template::display_template(
3968
-            $template,
3969
-            $settings_template_args,
3970
-            true
3971
-        );
3972
-    }
3973
-
3974
-
3975
-    /**
3976
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3977
-     *
3978
-     * @throws DomainException
3979
-     * @throws EE_Error
3980
-     * @throws InvalidDataTypeException
3981
-     * @throws InvalidInterfaceException
3982
-     * @throws InvalidArgumentException
3983
-     * @throws ReflectionException
3984
-     */
3985
-    public function activate_messenger_toggle()
3986
-    {
3987
-        $success = true;
3988
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3989
-        // let's check that we have required data
3990
-
3991
-        if (! $this->_active_messenger_name) {
3992
-            EE_Error::add_error(
3993
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994
-                __FILE__,
3995
-                __FUNCTION__,
3996
-                __LINE__
3997
-            );
3998
-            $success = false;
3999
-        }
4000
-
4001
-        // do a nonce check here since we're not arriving via a normal route
4002
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4003
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4004
-
4005
-        $this->_verify_nonce($nonce, $nonce_ref);
4006
-
4007
-
4008
-        $status = $this->request->getRequestParam('status');
4009
-        if (! $status) {
4010
-            EE_Error::add_error(
4011
-                esc_html__(
4012
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4013
-                    'event_espresso'
4014
-                ),
4015
-                __FILE__,
4016
-                __FUNCTION__,
4017
-                __LINE__
4018
-            );
4019
-            $success = false;
4020
-        }
4021
-
4022
-        // do check to verify we have a valid status.
4023
-        if ($status !== 'off' && $status !== 'on') {
4024
-            EE_Error::add_error(
4025
-                sprintf(
4026
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4027
-                    $status
4028
-                ),
4029
-                __FILE__,
4030
-                __FUNCTION__,
4031
-                __LINE__
4032
-            );
4033
-            $success = false;
4034
-        }
4035
-
4036
-        if ($success) {
4037
-            // made it here?  Stop dawdling then!!
4038
-            $success = $status === 'off'
4039
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4040
-                : $this->_activate_messenger($this->_active_messenger_name);
4041
-        }
4042
-
4043
-        $this->_template_args['success'] = $success;
4044
-
4045
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4046
-        $this->_return_json();
4047
-    }
4048
-
4049
-
4050
-    /**
4051
-     * used by ajax from the messages settings page to activate|deactivate a message type
4052
-     *
4053
-     * @throws DomainException
4054
-     * @throws EE_Error
4055
-     * @throws ReflectionException
4056
-     * @throws InvalidDataTypeException
4057
-     * @throws InvalidInterfaceException
4058
-     * @throws InvalidArgumentException
4059
-     */
4060
-    public function activate_mt_toggle()
4061
-    {
4062
-        $success = true;
4063
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4064
-
4065
-        // let's make sure we have the necessary data
4066
-        if (! $this->_active_message_type_name) {
4067
-            EE_Error::add_error(
4068
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069
-                __FILE__,
4070
-                __FUNCTION__,
4071
-                __LINE__
4072
-            );
4073
-            $success = false;
4074
-        }
4075
-
4076
-        if (! $this->_active_messenger_name) {
4077
-            EE_Error::add_error(
4078
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079
-                __FILE__,
4080
-                __FUNCTION__,
4081
-                __LINE__
4082
-            );
4083
-            $success = false;
4084
-        }
4085
-
4086
-        $status = $this->request->getRequestParam('status');
4087
-        if (! $status) {
4088
-            EE_Error::add_error(
4089
-                esc_html__(
4090
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4091
-                    'event_espresso'
4092
-                ),
4093
-                __FILE__,
4094
-                __FUNCTION__,
4095
-                __LINE__
4096
-            );
4097
-            $success = false;
4098
-        }
4099
-
4100
-
4101
-        // do check to verify we have a valid status.
4102
-        if ($status !== 'activate' && $status !== 'deactivate') {
4103
-            EE_Error::add_error(
4104
-                sprintf(
4105
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4106
-                    $status
4107
-                ),
4108
-                __FILE__,
4109
-                __FUNCTION__,
4110
-                __LINE__
4111
-            );
4112
-            $success = false;
4113
-        }
4114
-
4115
-
4116
-        // do a nonce check here since we're not arriving via a normal route
4117
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4118
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4119
-
4120
-        if ($success) {
4121
-            // made it here? um, what are you waiting for then?
4122
-            $success = $status === 'deactivate'
4123
-                ? $this->_deactivate_message_type_for_messenger(
4124
-                    $this->_active_messenger_name,
4125
-                    $this->_active_message_type_name
4126
-                )
4127
-                : $this->_activate_message_type_for_messenger(
4128
-                    $this->_active_messenger_name,
4129
-                    $this->_active_message_type_name
4130
-                );
4131
-        }
4132
-
4133
-        $this->_template_args['success'] = $success;
4134
-        $this->_return_json();
4135
-    }
4136
-
4137
-
4138
-    /**
4139
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4140
-     *
4141
-     * @param string $messenger_name The name of the messenger being activated
4142
-     * @return bool
4143
-     * @throws DomainException
4144
-     * @throws EE_Error
4145
-     * @throws InvalidArgumentException
4146
-     * @throws ReflectionException
4147
-     * @throws InvalidDataTypeException
4148
-     * @throws InvalidInterfaceException
4149
-     */
4150
-    protected function _activate_messenger($messenger_name)
4151
-    {
4152
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4153
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4154
-            ? $active_messenger->get_default_message_types()
4155
-            : [];
4156
-
4157
-        // ensure is active
4158
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4159
-
4160
-        // set response_data for reload
4161
-        foreach ($message_types_to_activate as $message_type_name) {
4162
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4163
-            if (
4164
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4165
-                    $messenger_name,
4166
-                    $message_type_name
4167
-                )
4168
-                && $message_type instanceof EE_message_type
4169
-            ) {
4170
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4171
-                if ($message_type->get_admin_settings_fields()) {
4172
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4173
-                }
4174
-            }
4175
-        }
4176
-
4177
-        // add success message for activating messenger
4178
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4179
-    }
4180
-
4181
-
4182
-    /**
4183
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4184
-     *
4185
-     * @param string $messenger_name The name of the messenger being activated
4186
-     * @return bool
4187
-     * @throws DomainException
4188
-     * @throws EE_Error
4189
-     * @throws InvalidArgumentException
4190
-     * @throws ReflectionException
4191
-     * @throws InvalidDataTypeException
4192
-     * @throws InvalidInterfaceException
4193
-     */
4194
-    protected function _deactivate_messenger($messenger_name)
4195
-    {
4196
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4197
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4198
-
4199
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4200
-    }
4201
-
4202
-
4203
-    /**
4204
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4205
-     *
4206
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4207
-     * @param string $message_type_name The name of the message type being activated for the messenger
4208
-     * @return bool
4209
-     * @throws DomainException
4210
-     * @throws EE_Error
4211
-     * @throws InvalidArgumentException
4212
-     * @throws ReflectionException
4213
-     * @throws InvalidDataTypeException
4214
-     * @throws InvalidInterfaceException
4215
-     */
4216
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4217
-    {
4218
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4219
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4220
-
4221
-        // ensure is active
4222
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4223
-
4224
-        // set response for load
4225
-        if (
4226
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4227
-                $messenger_name,
4228
-                $message_type_name
4229
-            )
4230
-        ) {
4231
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4232
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4233
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4234
-            }
4235
-        }
4236
-
4237
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4238
-            $active_messenger,
4239
-            $message_type_to_activate
4240
-        );
4241
-    }
4242
-
4243
-
4244
-    /**
4245
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4246
-     *
4247
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4248
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4249
-     * @return bool
4250
-     * @throws DomainException
4251
-     * @throws EE_Error
4252
-     * @throws InvalidArgumentException
4253
-     * @throws ReflectionException
4254
-     * @throws InvalidDataTypeException
4255
-     * @throws InvalidInterfaceException
4256
-     */
4257
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4258
-    {
4259
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4260
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4261
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4262
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4263
-
4264
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4265
-            $active_messenger,
4266
-            $message_type_to_deactivate
4267
-        );
4268
-    }
4269
-
4270
-
4271
-    /**
4272
-     * This just initializes the defaults for activating messenger and message type responses.
4273
-     */
4274
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4275
-    {
4276
-        $this->_template_args['data']['active_mts'] = [];
4277
-        $this->_template_args['data']['mt_reload']  = [];
4278
-    }
4279
-
4280
-
4281
-    /**
4282
-     * Setup appropriate response for activating a messenger and/or message types
4283
-     *
4284
-     * @param EE_messenger         $messenger
4285
-     * @param EE_message_type|null $message_type
4286
-     * @return bool
4287
-     * @throws DomainException
4288
-     * @throws EE_Error
4289
-     * @throws InvalidArgumentException
4290
-     * @throws ReflectionException
4291
-     * @throws InvalidDataTypeException
4292
-     * @throws InvalidInterfaceException
4293
-     */
4294
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4295
-        $messenger,
4296
-        EE_Message_Type $message_type = null
4297
-    ) {
4298
-        // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4300
-            EE_Error::add_error(
4301
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302
-                __FILE__,
4303
-                __FUNCTION__,
4304
-                __LINE__
4305
-            );
4306
-            return false;
4307
-        }
4308
-        // activated
4309
-        if ($this->_template_args['data']['active_mts']) {
4310
-            EE_Error::overwrite_success();
4311
-            // activated a message type with the messenger
4312
-            if ($message_type instanceof EE_message_type) {
4313
-                EE_Error::add_success(
4314
-                    sprintf(
4315
-                        esc_html__(
4316
-                            '%s message type has been successfully activated with the %s messenger',
4317
-                            'event_espresso'
4318
-                        ),
4319
-                        ucwords($message_type->label['singular']),
4320
-                        ucwords($messenger->label['singular'])
4321
-                    )
4322
-                );
4323
-
4324
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4325
-                if ($message_type->name === 'invoice') {
4326
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4327
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4328
-                    if ($pm instanceof EE_Payment_Method) {
4329
-                        EE_Error::add_attention(
4330
-                            esc_html__(
4331
-                                '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.',
4332
-                                'event_espresso'
4333
-                            )
4334
-                        );
4335
-                    }
4336
-                }
4337
-                // just toggles the entire messenger
4338
-            } else {
4339
-                EE_Error::add_success(
4340
-                    sprintf(
4341
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4342
-                        ucwords($messenger->label['singular'])
4343
-                    )
4344
-                );
4345
-            }
4346
-
4347
-            return true;
4348
-
4349
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4350
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351
-            // in which case we just give a success message for the messenger being successfully activated.
4352
-        } else {
4353
-            if (! $messenger->get_default_message_types()) {
4354
-                // messenger doesn't have any default message types so still a success.
4355
-                EE_Error::add_success(
4356
-                    sprintf(
4357
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4358
-                        ucwords($messenger->label['singular'])
4359
-                    )
4360
-                );
4361
-
4362
-                return true;
4363
-            } else {
4364
-                EE_Error::add_error(
4365
-                    $message_type instanceof EE_message_type
4366
-                    ? sprintf(
4367
-                        esc_html__(
4368
-                            '%s message type was not successfully activated with the %s messenger',
4369
-                            'event_espresso'
4370
-                        ),
4371
-                        ucwords($message_type->label['singular']),
4372
-                        ucwords($messenger->label['singular'])
4373
-                    )
4374
-                    : sprintf(
4375
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4376
-                        ucwords($messenger->label['singular'])
4377
-                    ),
4378
-                    __FILE__,
4379
-                    __FUNCTION__,
4380
-                    __LINE__
4381
-                );
4382
-
4383
-                return false;
4384
-            }
4385
-        }
4386
-    }
4387
-
4388
-
4389
-    /**
4390
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4391
-     *
4392
-     * @param EE_messenger         $messenger
4393
-     * @param EE_message_type|null $message_type
4394
-     * @return bool
4395
-     * @throws DomainException
4396
-     * @throws EE_Error
4397
-     * @throws InvalidArgumentException
4398
-     * @throws ReflectionException
4399
-     * @throws InvalidDataTypeException
4400
-     * @throws InvalidInterfaceException
4401
-     */
4402
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4403
-        $messenger,
4404
-        EE_message_type $message_type = null
4405
-    ) {
4406
-        EE_Error::overwrite_success();
4407
-
4408
-        // if $messenger isn't a valid messenger object then get out.
4409
-        if (! $messenger instanceof EE_Messenger) {
4410
-            EE_Error::add_error(
4411
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412
-                __FILE__,
4413
-                __FUNCTION__,
4414
-                __LINE__
4415
-            );
4416
-
4417
-            return false;
4418
-        }
4419
-
4420
-        if ($message_type instanceof EE_message_type) {
4421
-            $message_type_name = $message_type->name;
4422
-            EE_Error::add_success(
4423
-                sprintf(
4424
-                    esc_html__(
4425
-                        '%s message type has been successfully deactivated for the %s messenger.',
4426
-                        'event_espresso'
4427
-                    ),
4428
-                    ucwords($message_type->label['singular']),
4429
-                    ucwords($messenger->label['singular'])
4430
-                )
4431
-            );
4432
-        } else {
4433
-            $message_type_name = '';
4434
-            EE_Error::add_success(
4435
-                sprintf(
4436
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4437
-                    ucwords($messenger->label['singular'])
4438
-                )
4439
-            );
4440
-        }
4441
-
4442
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4443
-        if (
4444
-            $messenger->name === 'html'
4445
-            && (
4446
-                is_null($message_type)
4447
-                || $message_type_name === 'invoice'
4448
-            )
4449
-        ) {
4450
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4451
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4452
-            if ($count_updated > 0) {
4453
-                $msg = $message_type_name === 'invoice'
4454
-                    ? esc_html__(
4455
-                        '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.',
4456
-                        'event_espresso'
4457
-                    )
4458
-                    : esc_html__(
4459
-                        '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.',
4460
-                        'event_espresso'
4461
-                    );
4462
-                EE_Error::add_attention($msg);
4463
-            }
4464
-        }
4465
-
4466
-        return true;
4467
-    }
4468
-
4469
-
4470
-    /**
4471
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4472
-     *
4473
-     * @throws DomainException
4474
-     * @throws EE_Error
4475
-     * @throws EE_Error
4476
-     */
4477
-    public function update_mt_form()
4478
-    {
4479
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
-            EE_Error::add_error(
4481
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482
-                __FILE__,
4483
-                __FUNCTION__,
4484
-                __LINE__
4485
-            );
4486
-            $this->_return_json();
4487
-        }
4488
-
4489
-        $message_types = $this->get_installed_message_types();
4490
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4491
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493
-
4494
-        $this->_template_args['success'] = true;
4495
-        $this->_template_args['content'] = $content;
4496
-        $this->_return_json();
4497
-    }
4498
-
4499
-
4500
-    /**
4501
-     * this handles saving the settings for a messenger or message type
4502
-     *
4503
-     * @throws EE_Error
4504
-     * @throws EE_Error
4505
-     */
4506
-    public function save_settings()
4507
-    {
4508
-        $type = $this->request->getRequestParam('type');
4509
-        if (! $type) {
4510
-            EE_Error::add_error(
4511
-                esc_html__(
4512
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4513
-                    'event_espresso'
4514
-                ),
4515
-                __FILE__,
4516
-                __FUNCTION__,
4517
-                __LINE__
4518
-            );
4519
-            $this->_template_args['error'] = true;
4520
-            $this->_return_json();
4521
-        }
4522
-
4523
-
4524
-        if ($type === 'messenger') {
4525
-            // this should be an array.
4526
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4527
-            $messenger = $settings['messenger'];
4528
-            // remove messenger and message_types from settings array
4529
-            unset($settings['messenger'], $settings['message_types']);
4530
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4531
-        } elseif ($type === 'message_type') {
4532
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4533
-            $messenger    = $settings['messenger'];
4534
-            $message_type = $settings['message_type'];
4535
-            // remove messenger and message_types from settings array
4536
-            unset($settings['messenger'], $settings['message_types']);
4537
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4538
-        }
4539
-
4540
-        // okay we should have the data all setup.  Now we just update!
4541
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4542
-
4543
-        if ($success) {
4544
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4545
-        } else {
4546
-            EE_Error::add_error(
4547
-                esc_html__('Settings did not get updated', 'event_espresso'),
4548
-                __FILE__,
4549
-                __FUNCTION__,
4550
-                __LINE__
4551
-            );
4552
-        }
4553
-
4554
-        $this->_template_args['success'] = $success;
4555
-        $this->_return_json();
4556
-    }
4557
-
4558
-
4559
-
4560
-
4561
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4562
-
4563
-
4564
-    /**
4565
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4566
-     * However, this does not send immediately, it just queues for sending.
4567
-     *
4568
-     * @throws EE_Error
4569
-     * @throws InvalidDataTypeException
4570
-     * @throws InvalidInterfaceException
4571
-     * @throws InvalidArgumentException
4572
-     * @throws ReflectionException
4573
-     * @since 4.9.0
4574
-     */
4575
-    protected function _generate_now()
4576
-    {
4577
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4578
-        $this->_redirect_after_action(false, '', '', [], true);
4579
-    }
4580
-
4581
-
4582
-    /**
4583
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4584
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4585
-     *
4586
-     * @throws EE_Error
4587
-     * @throws InvalidDataTypeException
4588
-     * @throws InvalidInterfaceException
4589
-     * @throws InvalidArgumentException
4590
-     * @throws ReflectionException
4591
-     * @since 4.9.0
4592
-     */
4593
-    protected function _generate_and_send_now()
4594
-    {
4595
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4596
-        $this->_redirect_after_action(false, '', '', [], true);
4597
-    }
4598
-
4599
-
4600
-    /**
4601
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4602
-     *
4603
-     * @throws EE_Error
4604
-     * @throws InvalidDataTypeException
4605
-     * @throws InvalidInterfaceException
4606
-     * @throws InvalidArgumentException
4607
-     * @throws ReflectionException
4608
-     * @since 4.9.0
4609
-     */
4610
-    protected function _queue_for_resending()
4611
-    {
4612
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4613
-        $this->_redirect_after_action(false, '', '', [], true);
4614
-    }
4615
-
4616
-
4617
-    /**
4618
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4619
-     *
4620
-     * @throws EE_Error
4621
-     * @throws InvalidDataTypeException
4622
-     * @throws InvalidInterfaceException
4623
-     * @throws InvalidArgumentException
4624
-     * @throws ReflectionException
4625
-     * @since 4.9.0
4626
-     */
4627
-    protected function _send_now()
4628
-    {
4629
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4630
-        $this->_redirect_after_action(false, '', '', [], true);
4631
-    }
4632
-
4633
-
4634
-    /**
4635
-     * Deletes EE_messages for IDs in the request.
4636
-     *
4637
-     * @throws EE_Error
4638
-     * @throws InvalidDataTypeException
4639
-     * @throws InvalidInterfaceException
4640
-     * @throws InvalidArgumentException
4641
-     * @since 4.9.0
4642
-     */
4643
-    protected function _delete_ee_messages()
4644
-    {
4645
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4646
-        $deleted_count = 0;
4647
-        foreach ($MSG_IDs as $MSG_ID) {
4648
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4649
-                $deleted_count++;
4650
-            }
4651
-        }
4652
-        if ($deleted_count) {
4653
-            EE_Error::add_success(
4654
-                esc_html(
4655
-                    _n(
4656
-                        'Message successfully deleted',
4657
-                        'Messages successfully deleted',
4658
-                        $deleted_count,
4659
-                        'event_espresso'
4660
-                    )
4661
-                )
4662
-            );
4663
-        } else {
4664
-            EE_Error::add_error(
4665
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4666
-                __FILE__,
4667
-                __FUNCTION__,
4668
-                __LINE__
4669
-            );
4670
-        }
4671
-        $this->_redirect_after_action(false, '', '', [], true);
4672
-    }
4673
-
4674
-
4675
-    /**
4676
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4677
-     *
4678
-     * @return array
4679
-     * @since 4.9.0
4680
-     */
4681
-    protected function _get_msg_ids_from_request()
4682
-    {
4683
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4684
-        if (empty($MSG_IDs)) {
4685
-            return [];
4686
-        }
4687
-        // if 'MSG_ID' was just a single ID (not an array)
4688
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4689
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4690
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4691
-            ? $MSG_IDs
4692
-            : array_keys($MSG_IDs);
4693
-    }
2706
+		$this->_context_switcher = ob_get_clean();
2707
+	}
2708
+
2709
+
2710
+	/**
2711
+	 * @param bool $new
2712
+	 * @throws EE_Error
2713
+	 * @throws ReflectionException
2714
+	 */
2715
+	protected function _insert_or_update_message_template($new = false)
2716
+	{
2717
+		$form_data    = $this->getMessageTemplateFormData();
2718
+		$GRP_ID       = $form_data['GRP_ID'];
2719
+		$messenger    = $form_data['MTP_messenger'];
2720
+		$message_type = $form_data['MTP_message_type'];
2721
+		$context      = $form_data['MTP_context'];
2722
+
2723
+		// if this is "new" then we need to generate the default contexts
2724
+		// for the selected messenger/message_type for user to edit.
2725
+		list($success, $query_args) = $new
2726
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2727
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2728
+
2729
+		$success     = $success ? 1 : 0;
2730
+		$action_desc = $new ? 'created' : 'updated';
2731
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2732
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2733
+
2734
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2735
+	}
2736
+
2737
+
2738
+	/**
2739
+	 * retrieve and sanitize form data
2740
+	 *
2741
+	 * @return array
2742
+	 * @since 4.10.29.p
2743
+	 */
2744
+	protected function getMessageTemplateFormData()
2745
+	{
2746
+		return [
2747
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2748
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2749
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2750
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2751
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2752
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2753
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2754
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2755
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2756
+		];
2757
+	}
2758
+
2759
+
2760
+	/**
2761
+	 * @param int    $GRP_ID
2762
+	 * @param string $messenger
2763
+	 * @param string $message_type
2764
+	 * @return array no return on AJAX requests
2765
+	 * @throws EE_Error
2766
+	 * @throws ReflectionException
2767
+	 * @since 4.10.29.p
2768
+	 */
2769
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2770
+	{
2771
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2772
+		$success       = ! empty($new_templates);
2773
+
2774
+		// we return things differently if doing ajax
2775
+		if ($this->request->isAjax()) {
2776
+			$this->_template_args['success'] = $success;
2777
+			$this->_template_args['error']   = ! $success;
2778
+			$this->_template_args['content'] = '';
2779
+			$this->_template_args['data']    = [
2780
+				'grpID'        => $new_templates['GRP_ID'],
2781
+				'templateName' => $new_templates['template_name'],
2782
+			];
2783
+			if ($success) {
2784
+				EE_Error::overwrite_success();
2785
+				EE_Error::add_success(
2786
+					esc_html__(
2787
+						'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.',
2788
+						'event_espresso'
2789
+					)
2790
+				);
2791
+			}
2792
+			$this->_return_json();
2793
+		}
2794
+		return [
2795
+			$success,
2796
+			// 'query_args'
2797
+			[
2798
+				'id'      => $new_templates['GRP_ID'],
2799
+				'context' => $new_templates['MTP_context'],
2800
+				'action'  => 'edit_message_template',
2801
+			],
2802
+		];
2803
+	}
2804
+
2805
+
2806
+	/**
2807
+	 * @param int    $GRP_ID
2808
+	 * @param string $messenger
2809
+	 * @param string $message_type
2810
+	 * @param string $context
2811
+	 * @param array  $form_data
2812
+	 * @return array
2813
+	 * @throws EE_Error
2814
+	 * @since 4.10.29.p
2815
+	 */
2816
+	private function updateExistingTemplates(
2817
+		$GRP_ID,
2818
+		$messenger,
2819
+		$message_type,
2820
+		$context,
2821
+		array $form_data
2822
+	) {
2823
+		$success         = false;
2824
+		$template_fields = $this->getTemplateFields();
2825
+		if ($template_fields) {
2826
+			// if field data is valid, then success will be true
2827
+			$success = $this->validateTemplateFields(
2828
+				$messenger,
2829
+				$message_type,
2830
+				$context,
2831
+				$template_fields
2832
+			);
2833
+			if ($success) {
2834
+				$field_data = [];
2835
+				foreach ($template_fields as $template_field => $content) {
2836
+					// combine top-level form data with content for this field
2837
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2838
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2839
+				}
2840
+				// we can use the last set_column_values for the MTPG update
2841
+				// (because its the same for all of these specific MTPs)
2842
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2843
+			}
2844
+		}
2845
+
2846
+		return [
2847
+			$success,
2848
+			// 'query_args'
2849
+			[
2850
+				'id'      => $GRP_ID,
2851
+				'context' => $context,
2852
+				'action'  => 'edit_message_template',
2853
+			],
2854
+		];
2855
+	}
2856
+
2857
+
2858
+	/**
2859
+	 * @return array
2860
+	 * @since 4.10.29.p
2861
+	 */
2862
+	private function getTemplateFields()
2863
+	{
2864
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2865
+		if (empty($template_fields)) {
2866
+			EE_Error::add_error(
2867
+				esc_html__(
2868
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2869
+					'event_espresso'
2870
+				),
2871
+				__FILE__,
2872
+				__FUNCTION__,
2873
+				__LINE__
2874
+			);
2875
+			return null;
2876
+		}
2877
+		// messages content is expected to be escaped
2878
+		return EEH_Array::addSlashesRecursively($template_fields);
2879
+	}
2880
+
2881
+
2882
+	/**
2883
+	 * @param string $messenger
2884
+	 * @param string $message_type
2885
+	 * @param string $context
2886
+	 * @param array  $template_fields
2887
+	 * @return bool
2888
+	 * @throws EE_Error
2889
+	 * @since   4.10.29.p
2890
+	 */
2891
+	private function validateTemplateFields(
2892
+		$messenger,
2893
+		$message_type,
2894
+		$context,
2895
+		array $template_fields
2896
+	) {
2897
+		// first validate all fields!
2898
+		// this filter allows client code to add its own validation to the template fields as well.
2899
+		// returning an empty array means everything passed validation.
2900
+		// errors in validation should be represented in an array with the following shape:
2901
+		// array(
2902
+		//   'fieldname' => array(
2903
+		//          'msg' => 'error message'
2904
+		//          'value' => 'value for field producing error'
2905
+		// )
2906
+		$custom_validation = (array) apply_filters(
2907
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2908
+			[],
2909
+			$template_fields,
2910
+			$context,
2911
+			$messenger,
2912
+			$message_type
2913
+		);
2914
+
2915
+		$system_validation = $this->getMtgModel()->validate(
2916
+			$template_fields,
2917
+			$context,
2918
+			$messenger,
2919
+			$message_type
2920
+		);
2921
+
2922
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2923
+		$validates         = array_merge($custom_validation, $system_validation);
2924
+
2925
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2926
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2927
+		//  WE need to make sure there is no actual error messages in validates.
2928
+		if (empty($validates)) {
2929
+			return true;
2930
+		}
2931
+
2932
+		// add the transient so when the form loads we know which fields to highlight
2933
+		$this->_add_transient('edit_message_template', $validates);
2934
+		// setup notices
2935
+		foreach ($validates as $error) {
2936
+			if (isset($error['msg'])) {
2937
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2938
+			}
2939
+		}
2940
+		return false;
2941
+	}
2942
+
2943
+
2944
+	/**
2945
+	 * @param array $field_data
2946
+	 * @param array $form_data
2947
+	 * @return array
2948
+	 * @since   4.10.29.p
2949
+	 */
2950
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2951
+	{
2952
+		return $form_data + [
2953
+				'MTP_ID'             => $field_data['MTP_ID'],
2954
+				'MTP_template_field' => $field_data['name'],
2955
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2956
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2957
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2958
+					: $field_data['content'],
2959
+			];
2960
+	}
2961
+
2962
+
2963
+	/**
2964
+	 * @param string $template_field
2965
+	 * @param array  $form_data
2966
+	 * @return bool
2967
+	 * @throws EE_Error
2968
+	 * @since 4.10.29.p
2969
+	 */
2970
+	private function updateMessageTemplates($template_field, array $form_data)
2971
+	{
2972
+		$MTP_ID                  = $form_data['MTP_ID'];
2973
+		$message_template_fields = [
2974
+			'GRP_ID'             => $form_data['GRP_ID'],
2975
+			'MTP_template_field' => $form_data['MTP_template_field'],
2976
+			'MTP_context'        => $form_data['MTP_context'],
2977
+			'MTP_content'        => $form_data['MTP_content'],
2978
+		];
2979
+
2980
+		$hasMtpID = ! empty($MTP_ID);
2981
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2982
+		// this has already been through the template field validator and sanitized, so it will be
2983
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2984
+		// message template field in a messenger/message type and existing users don't have the
2985
+		// default setup for it.
2986
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2987
+		$updated = $hasMtpID
2988
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2989
+			: $this->getMtpModel()->insert($message_template_fields);
2990
+
2991
+		$insert_failed = ! $hasMtpID && ! $updated;
2992
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2993
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2994
+		$update_failed = $hasMtpID && $updated === false;
2995
+
2996
+		if ($insert_failed || $update_failed) {
2997
+			EE_Error::add_error(
2998
+				sprintf(
2999
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3000
+					$template_field
3001
+				),
3002
+				__FILE__,
3003
+				__FUNCTION__,
3004
+				__LINE__
3005
+			);
3006
+			return false;
3007
+		}
3008
+		return true;
3009
+	}
3010
+
3011
+
3012
+	/**
3013
+	 * @param array $form_data
3014
+	 * @return bool
3015
+	 * @throws EE_Error
3016
+	 * @since 4.10.29.p
3017
+	 */
3018
+	private function updateMessageTemplateGroup(array $form_data)
3019
+	{
3020
+		$GRP_ID  = $form_data['GRP_ID'];
3021
+		$updated = $this->getMtgModel()->update(
3022
+		// fields and values
3023
+			[
3024
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3025
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3026
+				'MTP_message_type' => $form_data['MTP_message_type'],
3027
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3028
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3029
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3030
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3031
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3032
+				'MTP_description'  => $this->request->getRequestParam(
3033
+					'ee_msg_non_global_fields[MTP_description]',
3034
+					''
3035
+				),
3036
+			],
3037
+			// where
3038
+			[['GRP_ID' => $GRP_ID]]
3039
+		);
3040
+
3041
+		if ($updated === false) {
3042
+			EE_Error::add_error(
3043
+				sprintf(
3044
+					esc_html__(
3045
+						'The Message Template Group (%d) was NOT updated for some reason',
3046
+						'event_espresso'
3047
+					),
3048
+					$form_data['GRP_ID']
3049
+				),
3050
+				__FILE__,
3051
+				__FUNCTION__,
3052
+				__LINE__
3053
+			);
3054
+			return false;
3055
+		}
3056
+		// k now we need to ensure the template_pack and template_variation fields are set.
3057
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3058
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3059
+
3060
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3061
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3062
+			$message_template_group->set_template_pack_name($template_pack);
3063
+			$message_template_group->set_template_pack_variation($template_variation);
3064
+		}
3065
+		return true;
3066
+	}
3067
+
3068
+
3069
+	/**
3070
+	 * recursively runs wp_kses() on message template content in a model safe manner
3071
+	 *
3072
+	 * @param array|string $content
3073
+	 * @return array|string
3074
+	 * @since   4.10.29.p
3075
+	 */
3076
+	private function sanitizeMessageTemplateContent($content)
3077
+	{
3078
+		if (is_array($content)) {
3079
+			foreach ($content as $key => $value) {
3080
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3081
+			}
3082
+			return $content;
3083
+		}
3084
+		// remove slashes so wp_kses() works properly
3085
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3086
+		// so attributes using single quotes always appear invalid.
3087
+		$content = stripslashes($content);
3088
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3089
+		// But currently the models expect slashed data, so after wp_kses()
3090
+		// runs we need to re-slash the data. Sheesh.
3091
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3092
+		return addslashes($content);
3093
+	}
3094
+
3095
+
3096
+	/**
3097
+	 * @param string $messenger
3098
+	 * @param string $message_type
3099
+	 * @param string $context
3100
+	 * @return string
3101
+	 * @since 4.10.29.p
3102
+	 */
3103
+	private function generateUpdateDescription($messenger, $message_type, $context)
3104
+	{
3105
+		// need the message type and messenger objects to be able to use the labels for the notices
3106
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3107
+		$messenger_label  = $messenger_object instanceof EE_messenger
3108
+			? ucwords($messenger_object->label['singular'])
3109
+			: '';
3110
+
3111
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3112
+		$message_type_label  = $message_type_object instanceof EE_message_type
3113
+			? ucwords($message_type_object->label['singular'])
3114
+			: '';
3115
+
3116
+		$context   = ucwords(str_replace('_', ' ', $context));
3117
+		$item_desc = $messenger_label && $message_type_label
3118
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3119
+			: '';
3120
+		$item_desc .= 'Message Template';
3121
+		return $item_desc;
3122
+	}
3123
+
3124
+
3125
+	/**
3126
+	 * @param string $messenger
3127
+	 * @param string $message_type
3128
+	 * @param string $context
3129
+	 * @return bool
3130
+	 * @throws EE_Error
3131
+	 * @throws ReflectionException
3132
+	 * @since 4.10.29.p
3133
+	 */
3134
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3135
+	{
3136
+		// was a test send triggered?
3137
+		if ($this->request->requestParamIsSet('test_button')) {
3138
+			EE_Error::overwrite_success();
3139
+			$this->_do_test_send($context, $messenger, $message_type);
3140
+			return true;
3141
+		}
3142
+		return false;
3143
+	}
3144
+
3145
+
3146
+	/**
3147
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3148
+	 *
3149
+	 * @param string $context      what context being tested
3150
+	 * @param string $messenger    messenger being tested
3151
+	 * @param string $message_type message type being tested
3152
+	 * @throws EE_Error
3153
+	 * @throws InvalidArgumentException
3154
+	 * @throws InvalidDataTypeException
3155
+	 * @throws InvalidInterfaceException
3156
+	 * @throws ReflectionException
3157
+	 */
3158
+	protected function _do_test_send($context, $messenger, $message_type)
3159
+	{
3160
+		// set things up for preview
3161
+		$this->request->setRequestParam('messenger', $messenger);
3162
+		$this->request->setRequestParam('message_type', $message_type);
3163
+		$this->request->setRequestParam('context', $context);
3164
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3165
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3166
+
3167
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3168
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3169
+
3170
+		// let's save any existing fields that might be required by the messenger
3171
+		if (
3172
+			! empty($test_settings_fld)
3173
+			&& $active_messenger instanceof EE_messenger
3174
+			&& apply_filters(
3175
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3176
+				true,
3177
+				$test_settings_fld,
3178
+				$active_messenger
3179
+			)
3180
+		) {
3181
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3182
+		}
3183
+
3184
+		/**
3185
+		 * Use filter to add additional controls on whether message can send or not
3186
+		 */
3187
+		if (
3188
+			apply_filters(
3189
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3190
+				true,
3191
+				$context,
3192
+				$this->request->requestParams(),
3193
+				$messenger,
3194
+				$message_type
3195
+			)
3196
+		) {
3197
+			if (EEM_Event::instance()->count() > 0) {
3198
+				$success = $this->_preview_message(true);
3199
+				if ($success) {
3200
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3201
+				} else {
3202
+					EE_Error::add_error(
3203
+						esc_html__('The test message was not sent', 'event_espresso'),
3204
+						__FILE__,
3205
+						__FUNCTION__,
3206
+						__LINE__
3207
+					);
3208
+				}
3209
+			} else {
3210
+				$this->noEventsErrorMessage(true);
3211
+			}
3212
+		}
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * _generate_new_templates
3218
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3219
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3220
+	 * for the event.
3221
+	 *
3222
+	 *
3223
+	 * @param string $messenger      the messenger we are generating templates for
3224
+	 * @param array  $message_types  array of message types that the templates are generated for.
3225
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3226
+	 *                               indicate the message_template_group being used as the base.
3227
+	 *
3228
+	 * @param bool   $global
3229
+	 *
3230
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3231
+	 *                               encountering problems.
3232
+	 * @throws EE_Error
3233
+	 * @throws ReflectionException
3234
+	 */
3235
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3236
+	{
3237
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3238
+		// just don't generate any templates.
3239
+		if (empty($message_types)) {
3240
+			return [];
3241
+		}
3242
+
3243
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3244
+		return $templates[0];
3245
+	}
3246
+
3247
+
3248
+	/**
3249
+	 * [_trash_or_restore_message_template]
3250
+	 *
3251
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3252
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3253
+	 *                        an individual context (FALSE).
3254
+	 * @return void
3255
+	 * @throws EE_Error
3256
+	 * @throws InvalidArgumentException
3257
+	 * @throws InvalidDataTypeException
3258
+	 * @throws InvalidInterfaceException
3259
+	 */
3260
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3261
+	{
3262
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3263
+
3264
+		$success = 1;
3265
+
3266
+		// incoming GRP_IDs
3267
+		if ($all) {
3268
+			// Checkboxes
3269
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
+			if (! empty($checkboxes)) {
3271
+				// if array has more than one element then success message should be plural.
3272
+				// todo: what about nonce?
3273
+				$success = count($checkboxes) > 1 ? 2 : 1;
3274
+
3275
+				// cycle through checkboxes
3276
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3277
+					$trashed_or_restored = $trash
3278
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
+					if (! $trashed_or_restored) {
3281
+						$success = 0;
3282
+					}
3283
+				}
3284
+			} else {
3285
+				// grab single GRP_ID and handle
3286
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
+				if (! empty($GRP_ID)) {
3288
+					$trashed_or_restored = $trash
3289
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
+					if (! $trashed_or_restored) {
3292
+						$success = 0;
3293
+					}
3294
+				} else {
3295
+					$success = 0;
3296
+				}
3297
+			}
3298
+		}
3299
+
3300
+		$action_desc = $trash
3301
+			? esc_html__('moved to the trash', 'event_espresso')
3302
+			: esc_html__('restored', 'event_espresso');
3303
+
3304
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3305
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3306
+
3307
+		$item_desc = $all ? _n(
3308
+			'Message Template Group',
3309
+			'Message Template Groups',
3310
+			$success,
3311
+			'event_espresso'
3312
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3313
+
3314
+		$item_desc = $template_switch
3315
+			? _n('template', 'templates', $success, 'event_espresso')
3316
+			: $item_desc;
3317
+
3318
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3319
+	}
3320
+
3321
+
3322
+	/**
3323
+	 * [_delete_message_template]
3324
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3325
+	 *
3326
+	 * @return void
3327
+	 * @throws EE_Error
3328
+	 * @throws InvalidArgumentException
3329
+	 * @throws InvalidDataTypeException
3330
+	 * @throws InvalidInterfaceException
3331
+	 * @throws ReflectionException
3332
+	 */
3333
+	protected function _delete_message_template()
3334
+	{
3335
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3336
+
3337
+		// checkboxes
3338
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
+		if (! empty($checkboxes)) {
3340
+			// if array has more than one element then success message should be plural
3341
+			$success = count($checkboxes) > 1 ? 2 : 1;
3342
+
3343
+			// cycle through bulk action checkboxes
3344
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3345
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3346
+			}
3347
+		} else {
3348
+			// grab single grp_id and delete
3349
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3350
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3351
+		}
3352
+
3353
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3354
+	}
3355
+
3356
+
3357
+	/**
3358
+	 * helper for permanently deleting a mtP group and all related message_templates
3359
+	 *
3360
+	 * @param int  $GRP_ID        The group being deleted
3361
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3362
+	 * @return bool boolean to indicate the success of the deletes or not.
3363
+	 * @throws EE_Error
3364
+	 * @throws InvalidArgumentException
3365
+	 * @throws InvalidDataTypeException
3366
+	 * @throws InvalidInterfaceException
3367
+	 * @throws ReflectionException
3368
+	 * @throws ReflectionException
3369
+	 */
3370
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3371
+	{
3372
+		$success = true;
3373
+		// first let's GET this group
3374
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3375
+		// then delete permanently all the related Message Templates
3376
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3377
+
3378
+		if ($deleted === 0) {
3379
+			$success = false;
3380
+		}
3381
+
3382
+		// now delete permanently this particular group
3383
+
3384
+		if ($include_group && ! $MTG->delete_permanently()) {
3385
+			$success = false;
3386
+		}
3387
+
3388
+		return $success;
3389
+	}
3390
+
3391
+
3392
+	/**
3393
+	 *    _learn_more_about_message_templates_link
3394
+	 *
3395
+	 * @access protected
3396
+	 * @return string
3397
+	 */
3398
+	protected function _learn_more_about_message_templates_link()
3399
+	{
3400
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3401
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3402
+			   . '</a>';
3403
+	}
3404
+
3405
+
3406
+	/**
3407
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3408
+	 * ajax and other routes.
3409
+	 *
3410
+	 * @return void
3411
+	 * @throws DomainException
3412
+	 * @throws EE_Error
3413
+	 */
3414
+	protected function _settings()
3415
+	{
3416
+		$this->_set_m_mt_settings();
3417
+
3418
+		// let's setup the messenger tabs
3419
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3420
+			$this->_m_mt_settings['messenger_tabs'],
3421
+			'messenger_links',
3422
+			'|',
3423
+			$this->request->getRequestParam('selected_messenger', 'email')
3424
+		);
3425
+
3426
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3427
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3428
+
3429
+		$this->display_admin_page_with_sidebar();
3430
+	}
3431
+
3432
+
3433
+	/**
3434
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3435
+	 *
3436
+	 * @access protected
3437
+	 * @return void
3438
+	 * @throws DomainException
3439
+	 */
3440
+	protected function _set_m_mt_settings()
3441
+	{
3442
+		// first if this is already set then lets get out no need to regenerate data.
3443
+		if (! empty($this->_m_mt_settings)) {
3444
+			return;
3445
+		}
3446
+
3447
+		// get all installed messengers and message_types
3448
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3449
+		$message_types = $this->_message_resource_manager->installed_message_types();
3450
+
3451
+
3452
+		// assemble the array for the _tab_text_links helper
3453
+
3454
+		foreach ($messengers as $messenger) {
3455
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3456
+				'label' => ucwords($messenger->label['singular']),
3457
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458
+					? 'messenger-active'
3459
+					: '',
3460
+				'href'  => $messenger->name,
3461
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3462
+				'slug'  => $messenger->name,
3463
+				'obj'   => $messenger,
3464
+			];
3465
+
3466
+
3467
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3468
+
3469
+			foreach ($message_types as $message_type) {
3470
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471
+				// it shouldn't show in either the inactive OR active metabox.
3472
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3473
+					continue;
3474
+				}
3475
+
3476
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3477
+					$messenger->name,
3478
+					$message_type->name
3479
+				)
3480
+					? 'active'
3481
+					: 'inactive';
3482
+
3483
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3484
+					'label'    => ucwords($message_type->label['singular']),
3485
+					'class'    => 'message-type-' . $a_or_i,
3486
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3489
+					'title'    => $a_or_i === 'active'
3490
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3492
+					'content'  => $a_or_i === 'active'
3493
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3494
+						: $this->_message_type_settings_content($message_type, $messenger),
3495
+					'slug'     => $message_type->name,
3496
+					'active'   => $a_or_i === 'active',
3497
+					'obj'      => $message_type,
3498
+				];
3499
+			}
3500
+		}
3501
+	}
3502
+
3503
+
3504
+	/**
3505
+	 * This just prepares the content for the message type settings
3506
+	 *
3507
+	 * @param EE_message_type $message_type The message type object
3508
+	 * @param EE_messenger    $messenger    The messenger object
3509
+	 * @param boolean         $active       Whether the message type is active or not
3510
+	 * @return string html output for the content
3511
+	 * @throws DomainException
3512
+	 */
3513
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3514
+	{
3515
+		// get message type fields
3516
+		$fields                                         = $message_type->get_admin_settings_fields();
3517
+		$settings_template_args['template_form_fields'] = '';
3518
+
3519
+		if (! empty($fields) && $active) {
3520
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521
+			foreach ($fields as $fldname => $fldprops) {
3522
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
+				$template_form_field[ $field_id ] = [
3524
+					'name'       => 'message_type_settings[' . $fldname . ']',
3525
+					'label'      => $fldprops['label'],
3526
+					'input'      => $fldprops['field_type'],
3527
+					'type'       => $fldprops['value_type'],
3528
+					'required'   => $fldprops['required'],
3529
+					'validation' => $fldprops['validation'],
3530
+					'value'      => isset($existing_settings[ $fldname ])
3531
+						? $existing_settings[ $fldname ]
3532
+						: $fldprops['default'],
3533
+					'options'    => isset($fldprops['options'])
3534
+						? $fldprops['options']
3535
+						: [],
3536
+					'default'    => isset($existing_settings[ $fldname ])
3537
+						? $existing_settings[ $fldname ]
3538
+						: $fldprops['default'],
3539
+					'css_class'  => 'no-drag',
3540
+					'format'     => $fldprops['format'],
3541
+				];
3542
+			}
3543
+
3544
+
3545
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3546
+				? $this->_generate_admin_form_fields(
3547
+					$template_form_field,
3548
+					'string',
3549
+					'ee_mt_activate_form'
3550
+				)
3551
+				: '';
3552
+		}
3553
+
3554
+		$settings_template_args['description'] = $message_type->description;
3555
+		// we also need some hidden fields
3556
+		$hidden_fields = [
3557
+			'message_type_settings[messenger]' . $message_type->name    => [
3558
+				'type'  => 'hidden',
3559
+				'value' => $messenger->name,
3560
+			],
3561
+			'message_type_settings[message_type]' . $message_type->name => [
3562
+				'type'  => 'hidden',
3563
+				'value' => $message_type->name,
3564
+			],
3565
+			'type' . $message_type->name                                => [
3566
+				'type'  => 'hidden',
3567
+				'value' => 'message_type',
3568
+			],
3569
+		];
3570
+
3571
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3572
+			$hidden_fields,
3573
+			'array'
3574
+		);
3575
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3576
+			? ' hidden'
3577
+			: '';
3578
+
3579
+
3580
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3581
+		return EEH_Template::display_template($template, $settings_template_args, true);
3582
+	}
3583
+
3584
+
3585
+	/**
3586
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3587
+	 *
3588
+	 * @access protected
3589
+	 * @return void
3590
+	 * @throws DomainException
3591
+	 */
3592
+	protected function _messages_settings_metaboxes()
3593
+	{
3594
+		$this->_set_m_mt_settings();
3595
+		$m_boxes         = $mt_boxes = [];
3596
+		$m_template_args = $mt_template_args = [];
3597
+
3598
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3599
+
3600
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3601
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3602
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3603
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3604
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3605
+
3606
+				// messenger meta boxes
3607
+				$active         = $selected_messenger === $messenger;
3608
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
+					: '';
3611
+
3612
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3613
+					esc_html__('%s Settings', 'event_espresso'),
3614
+					$tab_array['label']
3615
+				);
3616
+
3617
+				$m_template_args[ $messenger . '_a_box' ] = [
3618
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619
+					'inactive_message_types' => isset(
3620
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3621
+					)
3622
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3623
+						: '',
3624
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625
+					'hidden'                 => $active ? '' : ' hidden',
3626
+					'hide_on_message'        => $hide_on_message,
3627
+					'messenger'              => $messenger,
3628
+					'active'                 => $active,
3629
+				];
3630
+
3631
+				// message type meta boxes
3632
+				// (which is really just the inactive container for each messenger
3633
+				// showing inactive message types for that messenger)
3634
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
+				$mt_template_args[ $messenger . '_i_box' ] = [
3636
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637
+					'inactive_message_types' => isset(
3638
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3639
+					)
3640
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3641
+						: '',
3642
+					'hidden'                 => $active ? '' : ' hidden',
3643
+					'hide_on_message'        => $hide_on_message,
3644
+					'hide_off_message'       => $hide_off_message,
3645
+					'messenger'              => $messenger,
3646
+					'active'                 => $active,
3647
+				];
3648
+			}
3649
+		}
3650
+
3651
+
3652
+		// register messenger metaboxes
3653
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3654
+		foreach ($m_boxes as $box => $label) {
3655
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3656
+			$msgr          = str_replace('_a_box', '', $box);
3657
+			add_meta_box(
3658
+				'espresso_' . $msgr . '_settings',
3659
+				$label,
3660
+				function ($post, $metabox) {
3661
+					EEH_Template::display_template(
3662
+						$metabox['args']['template_path'],
3663
+						$metabox['args']['template_args']
3664
+					);
3665
+				},
3666
+				$this->_current_screen->id,
3667
+				'normal',
3668
+				'high',
3669
+				$callback_args
3670
+			);
3671
+		}
3672
+
3673
+		// register message type metaboxes
3674
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3675
+		foreach ($mt_boxes as $box => $label) {
3676
+			$callback_args = [
3677
+				'template_path' => $mt_template_path,
3678
+				'template_args' => $mt_template_args[ $box ],
3679
+			];
3680
+			$mt            = str_replace('_i_box', '', $box);
3681
+			add_meta_box(
3682
+				'espresso_' . $mt . '_inactive_mts',
3683
+				$label,
3684
+				function ($post, $metabox) {
3685
+					EEH_Template::display_template(
3686
+						$metabox['args']['template_path'],
3687
+						$metabox['args']['template_args']
3688
+					);
3689
+				},
3690
+				$this->_current_screen->id,
3691
+				'side',
3692
+				'high',
3693
+				$callback_args
3694
+			);
3695
+		}
3696
+
3697
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3698
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3699
+		if (is_main_site()) {
3700
+			add_meta_box(
3701
+				'espresso_global_message_settings',
3702
+				esc_html__('Global Message Settings', 'event_espresso'),
3703
+				[$this, 'global_messages_settings_metabox_content'],
3704
+				$this->_current_screen->id,
3705
+				'normal',
3706
+				'low',
3707
+				[]
3708
+			);
3709
+		}
3710
+	}
3711
+
3712
+
3713
+	/**
3714
+	 *  This generates the content for the global messages settings metabox.
3715
+	 *
3716
+	 * @return void
3717
+	 * @throws EE_Error
3718
+	 * @throws InvalidArgumentException
3719
+	 * @throws ReflectionException
3720
+	 * @throws InvalidDataTypeException
3721
+	 * @throws InvalidInterfaceException
3722
+	 */
3723
+	public function global_messages_settings_metabox_content()
3724
+	{
3725
+		$form = $this->_generate_global_settings_form();
3726
+		// already escaped
3727
+		echo $form->form_open(
3728
+			$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3729
+			'POST'
3730
+		);
3731
+		echo $form->get_html();
3732
+		echo $form->form_close();
3733
+	}
3734
+
3735
+
3736
+	/**
3737
+	 * This generates and returns the form object for the global messages settings.
3738
+	 *
3739
+	 * @return EE_Form_Section_Proper
3740
+	 * @throws EE_Error
3741
+	 * @throws InvalidArgumentException
3742
+	 * @throws ReflectionException
3743
+	 * @throws InvalidDataTypeException
3744
+	 * @throws InvalidInterfaceException
3745
+	 */
3746
+	protected function _generate_global_settings_form()
3747
+	{
3748
+		/** @var EE_Network_Core_Config $network_config */
3749
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3750
+
3751
+		return new EE_Form_Section_Proper(
3752
+			[
3753
+				'name'            => 'global_messages_settings',
3754
+				'html_id'         => 'global_messages_settings',
3755
+				'html_class'      => 'form-table',
3756
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3757
+				'subsections'     => apply_filters(
3758
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3759
+					[
3760
+						'do_messages_on_same_request' => new EE_Select_Input(
3761
+							[
3762
+								true  => esc_html__('On the same request', 'event_espresso'),
3763
+								false => esc_html__('On a separate request', 'event_espresso'),
3764
+							],
3765
+							[
3766
+								'default'         => $network_config->do_messages_on_same_request,
3767
+								'html_label_text' => esc_html__(
3768
+									'Generate and send all messages:',
3769
+									'event_espresso'
3770
+								),
3771
+								'html_help_text'  => esc_html__(
3772
+									'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.',
3773
+									'event_espresso'
3774
+								),
3775
+							]
3776
+						),
3777
+						'delete_threshold'            => new EE_Select_Input(
3778
+							[
3779
+								0  => esc_html__('Forever', 'event_espresso'),
3780
+								3  => esc_html__('3 Months', 'event_espresso'),
3781
+								6  => esc_html__('6 Months', 'event_espresso'),
3782
+								9  => esc_html__('9 Months', 'event_espresso'),
3783
+								12 => esc_html__('12 Months', 'event_espresso'),
3784
+								24 => esc_html__('24 Months', 'event_espresso'),
3785
+								36 => esc_html__('36 Months', 'event_espresso'),
3786
+							],
3787
+							[
3788
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3789
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3790
+								'html_help_text'  => esc_html__(
3791
+									'You can control how long a record of processed messages is kept via this option.',
3792
+									'event_espresso'
3793
+								),
3794
+							]
3795
+						),
3796
+						'update_settings'             => new EE_Submit_Input(
3797
+							[
3798
+								'default'         => esc_html__('Update', 'event_espresso'),
3799
+								'html_label_text' => '&nbsp',
3800
+							]
3801
+						),
3802
+					]
3803
+				),
3804
+			]
3805
+		);
3806
+	}
3807
+
3808
+
3809
+	/**
3810
+	 * This handles updating the global settings set on the admin page.
3811
+	 *
3812
+	 * @throws EE_Error
3813
+	 * @throws InvalidDataTypeException
3814
+	 * @throws InvalidInterfaceException
3815
+	 * @throws InvalidArgumentException
3816
+	 * @throws ReflectionException
3817
+	 */
3818
+	protected function _update_global_settings()
3819
+	{
3820
+		/** @var EE_Network_Core_Config $network_config */
3821
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3822
+		$messages_config = EE_Registry::instance()->CFG->messages;
3823
+		$form            = $this->_generate_global_settings_form();
3824
+		if ($form->was_submitted()) {
3825
+			$form->receive_form_submission();
3826
+			if ($form->is_valid()) {
3827
+				$valid_data = $form->valid_data();
3828
+				foreach ($valid_data as $property => $value) {
3829
+					$setter = 'set_' . $property;
3830
+					if (method_exists($network_config, $setter)) {
3831
+						$network_config->{$setter}($value);
3832
+					} elseif (
3833
+						property_exists($network_config, $property)
3834
+						&& $network_config->{$property} !== $value
3835
+					) {
3836
+						$network_config->{$property} = $value;
3837
+					} elseif (
3838
+						property_exists($messages_config, $property)
3839
+						&& $messages_config->{$property} !== $value
3840
+					) {
3841
+						$messages_config->{$property} = $value;
3842
+					}
3843
+				}
3844
+				// only update if the form submission was valid!
3845
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3846
+				EE_Registry::instance()->CFG->update_espresso_config();
3847
+				EE_Error::overwrite_success();
3848
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3849
+			}
3850
+		}
3851
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3857
+	 *
3858
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3859
+	 * @return string html formatted tabs
3860
+	 * @throws DomainException
3861
+	 */
3862
+	protected function _get_mt_tabs($tab_array)
3863
+	{
3864
+		$tab_array = (array) $tab_array;
3865
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
+		$tabs      = '';
3867
+
3868
+		foreach ($tab_array as $tab) {
3869
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3870
+		}
3871
+
3872
+		return $tabs;
3873
+	}
3874
+
3875
+
3876
+	/**
3877
+	 * This prepares the content of the messenger meta box admin settings
3878
+	 *
3879
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3880
+	 * @return string html formatted content
3881
+	 * @throws DomainException
3882
+	 */
3883
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3884
+	{
3885
+
3886
+		$fields                                         = $messenger->get_admin_settings_fields();
3887
+		$settings_template_args['template_form_fields'] = '';
3888
+
3889
+		// is $messenger active?
3890
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891
+
3892
+
3893
+		if (! empty($fields)) {
3894
+			$existing_settings = $messenger->get_existing_admin_settings();
3895
+
3896
+			foreach ($fields as $fldname => $fldprops) {
3897
+				$field_id                         = $messenger->name . '-' . $fldname;
3898
+				$template_form_field[ $field_id ] = [
3899
+					'name'       => 'messenger_settings[' . $field_id . ']',
3900
+					'label'      => $fldprops['label'],
3901
+					'input'      => $fldprops['field_type'],
3902
+					'type'       => $fldprops['value_type'],
3903
+					'required'   => $fldprops['required'],
3904
+					'validation' => $fldprops['validation'],
3905
+					'value'      => isset($existing_settings[ $field_id ])
3906
+						? $existing_settings[ $field_id ]
3907
+						: $fldprops['default'],
3908
+					'css_class'  => '',
3909
+					'format'     => $fldprops['format'],
3910
+				];
3911
+			}
3912
+
3913
+
3914
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3915
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3916
+				: '';
3917
+		}
3918
+
3919
+		// we also need some hidden fields
3920
+		$settings_template_args['hidden_fields'] = [
3921
+			'messenger_settings[messenger]' . $messenger->name => [
3922
+				'type'  => 'hidden',
3923
+				'value' => $messenger->name,
3924
+			],
3925
+			'type' . $messenger->name                          => [
3926
+				'type'  => 'hidden',
3927
+				'value' => 'messenger',
3928
+			],
3929
+		];
3930
+
3931
+		// make sure any active message types that are existing are included in the hidden fields
3932
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3935
+					'type'  => 'hidden',
3936
+					'value' => $mt,
3937
+				];
3938
+			}
3939
+		}
3940
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3941
+			$settings_template_args['hidden_fields'],
3942
+			'array'
3943
+		);
3944
+		$active                                  =
3945
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3946
+
3947
+		$settings_template_args['messenger']           = $messenger->name;
3948
+		$settings_template_args['description']         = $messenger->description;
3949
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3950
+
3951
+
3952
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3953
+			$messenger->name
3954
+		)
3955
+			? $settings_template_args['show_hide_edit_form']
3956
+			: ' hidden';
3957
+
3958
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3959
+			? ' hidden'
3960
+			: $settings_template_args['show_hide_edit_form'];
3961
+
3962
+
3963
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
+		$settings_template_args['on_off_status'] = $active;
3966
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
+		return EEH_Template::display_template(
3968
+			$template,
3969
+			$settings_template_args,
3970
+			true
3971
+		);
3972
+	}
3973
+
3974
+
3975
+	/**
3976
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3977
+	 *
3978
+	 * @throws DomainException
3979
+	 * @throws EE_Error
3980
+	 * @throws InvalidDataTypeException
3981
+	 * @throws InvalidInterfaceException
3982
+	 * @throws InvalidArgumentException
3983
+	 * @throws ReflectionException
3984
+	 */
3985
+	public function activate_messenger_toggle()
3986
+	{
3987
+		$success = true;
3988
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3989
+		// let's check that we have required data
3990
+
3991
+		if (! $this->_active_messenger_name) {
3992
+			EE_Error::add_error(
3993
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994
+				__FILE__,
3995
+				__FUNCTION__,
3996
+				__LINE__
3997
+			);
3998
+			$success = false;
3999
+		}
4000
+
4001
+		// do a nonce check here since we're not arriving via a normal route
4002
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4003
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4004
+
4005
+		$this->_verify_nonce($nonce, $nonce_ref);
4006
+
4007
+
4008
+		$status = $this->request->getRequestParam('status');
4009
+		if (! $status) {
4010
+			EE_Error::add_error(
4011
+				esc_html__(
4012
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4013
+					'event_espresso'
4014
+				),
4015
+				__FILE__,
4016
+				__FUNCTION__,
4017
+				__LINE__
4018
+			);
4019
+			$success = false;
4020
+		}
4021
+
4022
+		// do check to verify we have a valid status.
4023
+		if ($status !== 'off' && $status !== 'on') {
4024
+			EE_Error::add_error(
4025
+				sprintf(
4026
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4027
+					$status
4028
+				),
4029
+				__FILE__,
4030
+				__FUNCTION__,
4031
+				__LINE__
4032
+			);
4033
+			$success = false;
4034
+		}
4035
+
4036
+		if ($success) {
4037
+			// made it here?  Stop dawdling then!!
4038
+			$success = $status === 'off'
4039
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4040
+				: $this->_activate_messenger($this->_active_messenger_name);
4041
+		}
4042
+
4043
+		$this->_template_args['success'] = $success;
4044
+
4045
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4046
+		$this->_return_json();
4047
+	}
4048
+
4049
+
4050
+	/**
4051
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4052
+	 *
4053
+	 * @throws DomainException
4054
+	 * @throws EE_Error
4055
+	 * @throws ReflectionException
4056
+	 * @throws InvalidDataTypeException
4057
+	 * @throws InvalidInterfaceException
4058
+	 * @throws InvalidArgumentException
4059
+	 */
4060
+	public function activate_mt_toggle()
4061
+	{
4062
+		$success = true;
4063
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4064
+
4065
+		// let's make sure we have the necessary data
4066
+		if (! $this->_active_message_type_name) {
4067
+			EE_Error::add_error(
4068
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069
+				__FILE__,
4070
+				__FUNCTION__,
4071
+				__LINE__
4072
+			);
4073
+			$success = false;
4074
+		}
4075
+
4076
+		if (! $this->_active_messenger_name) {
4077
+			EE_Error::add_error(
4078
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079
+				__FILE__,
4080
+				__FUNCTION__,
4081
+				__LINE__
4082
+			);
4083
+			$success = false;
4084
+		}
4085
+
4086
+		$status = $this->request->getRequestParam('status');
4087
+		if (! $status) {
4088
+			EE_Error::add_error(
4089
+				esc_html__(
4090
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4091
+					'event_espresso'
4092
+				),
4093
+				__FILE__,
4094
+				__FUNCTION__,
4095
+				__LINE__
4096
+			);
4097
+			$success = false;
4098
+		}
4099
+
4100
+
4101
+		// do check to verify we have a valid status.
4102
+		if ($status !== 'activate' && $status !== 'deactivate') {
4103
+			EE_Error::add_error(
4104
+				sprintf(
4105
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4106
+					$status
4107
+				),
4108
+				__FILE__,
4109
+				__FUNCTION__,
4110
+				__LINE__
4111
+			);
4112
+			$success = false;
4113
+		}
4114
+
4115
+
4116
+		// do a nonce check here since we're not arriving via a normal route
4117
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4118
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4119
+
4120
+		if ($success) {
4121
+			// made it here? um, what are you waiting for then?
4122
+			$success = $status === 'deactivate'
4123
+				? $this->_deactivate_message_type_for_messenger(
4124
+					$this->_active_messenger_name,
4125
+					$this->_active_message_type_name
4126
+				)
4127
+				: $this->_activate_message_type_for_messenger(
4128
+					$this->_active_messenger_name,
4129
+					$this->_active_message_type_name
4130
+				);
4131
+		}
4132
+
4133
+		$this->_template_args['success'] = $success;
4134
+		$this->_return_json();
4135
+	}
4136
+
4137
+
4138
+	/**
4139
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4140
+	 *
4141
+	 * @param string $messenger_name The name of the messenger being activated
4142
+	 * @return bool
4143
+	 * @throws DomainException
4144
+	 * @throws EE_Error
4145
+	 * @throws InvalidArgumentException
4146
+	 * @throws ReflectionException
4147
+	 * @throws InvalidDataTypeException
4148
+	 * @throws InvalidInterfaceException
4149
+	 */
4150
+	protected function _activate_messenger($messenger_name)
4151
+	{
4152
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4153
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4154
+			? $active_messenger->get_default_message_types()
4155
+			: [];
4156
+
4157
+		// ensure is active
4158
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4159
+
4160
+		// set response_data for reload
4161
+		foreach ($message_types_to_activate as $message_type_name) {
4162
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4163
+			if (
4164
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4165
+					$messenger_name,
4166
+					$message_type_name
4167
+				)
4168
+				&& $message_type instanceof EE_message_type
4169
+			) {
4170
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4171
+				if ($message_type->get_admin_settings_fields()) {
4172
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4173
+				}
4174
+			}
4175
+		}
4176
+
4177
+		// add success message for activating messenger
4178
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4179
+	}
4180
+
4181
+
4182
+	/**
4183
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4184
+	 *
4185
+	 * @param string $messenger_name The name of the messenger being activated
4186
+	 * @return bool
4187
+	 * @throws DomainException
4188
+	 * @throws EE_Error
4189
+	 * @throws InvalidArgumentException
4190
+	 * @throws ReflectionException
4191
+	 * @throws InvalidDataTypeException
4192
+	 * @throws InvalidInterfaceException
4193
+	 */
4194
+	protected function _deactivate_messenger($messenger_name)
4195
+	{
4196
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4197
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4198
+
4199
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4200
+	}
4201
+
4202
+
4203
+	/**
4204
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4205
+	 *
4206
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4207
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4208
+	 * @return bool
4209
+	 * @throws DomainException
4210
+	 * @throws EE_Error
4211
+	 * @throws InvalidArgumentException
4212
+	 * @throws ReflectionException
4213
+	 * @throws InvalidDataTypeException
4214
+	 * @throws InvalidInterfaceException
4215
+	 */
4216
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4217
+	{
4218
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4219
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4220
+
4221
+		// ensure is active
4222
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4223
+
4224
+		// set response for load
4225
+		if (
4226
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4227
+				$messenger_name,
4228
+				$message_type_name
4229
+			)
4230
+		) {
4231
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4232
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4233
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4234
+			}
4235
+		}
4236
+
4237
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4238
+			$active_messenger,
4239
+			$message_type_to_activate
4240
+		);
4241
+	}
4242
+
4243
+
4244
+	/**
4245
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4246
+	 *
4247
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4248
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4249
+	 * @return bool
4250
+	 * @throws DomainException
4251
+	 * @throws EE_Error
4252
+	 * @throws InvalidArgumentException
4253
+	 * @throws ReflectionException
4254
+	 * @throws InvalidDataTypeException
4255
+	 * @throws InvalidInterfaceException
4256
+	 */
4257
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4258
+	{
4259
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4260
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4261
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4262
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4263
+
4264
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4265
+			$active_messenger,
4266
+			$message_type_to_deactivate
4267
+		);
4268
+	}
4269
+
4270
+
4271
+	/**
4272
+	 * This just initializes the defaults for activating messenger and message type responses.
4273
+	 */
4274
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4275
+	{
4276
+		$this->_template_args['data']['active_mts'] = [];
4277
+		$this->_template_args['data']['mt_reload']  = [];
4278
+	}
4279
+
4280
+
4281
+	/**
4282
+	 * Setup appropriate response for activating a messenger and/or message types
4283
+	 *
4284
+	 * @param EE_messenger         $messenger
4285
+	 * @param EE_message_type|null $message_type
4286
+	 * @return bool
4287
+	 * @throws DomainException
4288
+	 * @throws EE_Error
4289
+	 * @throws InvalidArgumentException
4290
+	 * @throws ReflectionException
4291
+	 * @throws InvalidDataTypeException
4292
+	 * @throws InvalidInterfaceException
4293
+	 */
4294
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4295
+		$messenger,
4296
+		EE_Message_Type $message_type = null
4297
+	) {
4298
+		// if $messenger isn't a valid messenger object then get out.
4299
+		if (! $messenger instanceof EE_Messenger) {
4300
+			EE_Error::add_error(
4301
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302
+				__FILE__,
4303
+				__FUNCTION__,
4304
+				__LINE__
4305
+			);
4306
+			return false;
4307
+		}
4308
+		// activated
4309
+		if ($this->_template_args['data']['active_mts']) {
4310
+			EE_Error::overwrite_success();
4311
+			// activated a message type with the messenger
4312
+			if ($message_type instanceof EE_message_type) {
4313
+				EE_Error::add_success(
4314
+					sprintf(
4315
+						esc_html__(
4316
+							'%s message type has been successfully activated with the %s messenger',
4317
+							'event_espresso'
4318
+						),
4319
+						ucwords($message_type->label['singular']),
4320
+						ucwords($messenger->label['singular'])
4321
+					)
4322
+				);
4323
+
4324
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4325
+				if ($message_type->name === 'invoice') {
4326
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4327
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4328
+					if ($pm instanceof EE_Payment_Method) {
4329
+						EE_Error::add_attention(
4330
+							esc_html__(
4331
+								'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.',
4332
+								'event_espresso'
4333
+							)
4334
+						);
4335
+					}
4336
+				}
4337
+				// just toggles the entire messenger
4338
+			} else {
4339
+				EE_Error::add_success(
4340
+					sprintf(
4341
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4342
+						ucwords($messenger->label['singular'])
4343
+					)
4344
+				);
4345
+			}
4346
+
4347
+			return true;
4348
+
4349
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4350
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351
+			// in which case we just give a success message for the messenger being successfully activated.
4352
+		} else {
4353
+			if (! $messenger->get_default_message_types()) {
4354
+				// messenger doesn't have any default message types so still a success.
4355
+				EE_Error::add_success(
4356
+					sprintf(
4357
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4358
+						ucwords($messenger->label['singular'])
4359
+					)
4360
+				);
4361
+
4362
+				return true;
4363
+			} else {
4364
+				EE_Error::add_error(
4365
+					$message_type instanceof EE_message_type
4366
+					? sprintf(
4367
+						esc_html__(
4368
+							'%s message type was not successfully activated with the %s messenger',
4369
+							'event_espresso'
4370
+						),
4371
+						ucwords($message_type->label['singular']),
4372
+						ucwords($messenger->label['singular'])
4373
+					)
4374
+					: sprintf(
4375
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4376
+						ucwords($messenger->label['singular'])
4377
+					),
4378
+					__FILE__,
4379
+					__FUNCTION__,
4380
+					__LINE__
4381
+				);
4382
+
4383
+				return false;
4384
+			}
4385
+		}
4386
+	}
4387
+
4388
+
4389
+	/**
4390
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4391
+	 *
4392
+	 * @param EE_messenger         $messenger
4393
+	 * @param EE_message_type|null $message_type
4394
+	 * @return bool
4395
+	 * @throws DomainException
4396
+	 * @throws EE_Error
4397
+	 * @throws InvalidArgumentException
4398
+	 * @throws ReflectionException
4399
+	 * @throws InvalidDataTypeException
4400
+	 * @throws InvalidInterfaceException
4401
+	 */
4402
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4403
+		$messenger,
4404
+		EE_message_type $message_type = null
4405
+	) {
4406
+		EE_Error::overwrite_success();
4407
+
4408
+		// if $messenger isn't a valid messenger object then get out.
4409
+		if (! $messenger instanceof EE_Messenger) {
4410
+			EE_Error::add_error(
4411
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412
+				__FILE__,
4413
+				__FUNCTION__,
4414
+				__LINE__
4415
+			);
4416
+
4417
+			return false;
4418
+		}
4419
+
4420
+		if ($message_type instanceof EE_message_type) {
4421
+			$message_type_name = $message_type->name;
4422
+			EE_Error::add_success(
4423
+				sprintf(
4424
+					esc_html__(
4425
+						'%s message type has been successfully deactivated for the %s messenger.',
4426
+						'event_espresso'
4427
+					),
4428
+					ucwords($message_type->label['singular']),
4429
+					ucwords($messenger->label['singular'])
4430
+				)
4431
+			);
4432
+		} else {
4433
+			$message_type_name = '';
4434
+			EE_Error::add_success(
4435
+				sprintf(
4436
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4437
+					ucwords($messenger->label['singular'])
4438
+				)
4439
+			);
4440
+		}
4441
+
4442
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4443
+		if (
4444
+			$messenger->name === 'html'
4445
+			&& (
4446
+				is_null($message_type)
4447
+				|| $message_type_name === 'invoice'
4448
+			)
4449
+		) {
4450
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4451
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4452
+			if ($count_updated > 0) {
4453
+				$msg = $message_type_name === 'invoice'
4454
+					? esc_html__(
4455
+						'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.',
4456
+						'event_espresso'
4457
+					)
4458
+					: esc_html__(
4459
+						'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.',
4460
+						'event_espresso'
4461
+					);
4462
+				EE_Error::add_attention($msg);
4463
+			}
4464
+		}
4465
+
4466
+		return true;
4467
+	}
4468
+
4469
+
4470
+	/**
4471
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4472
+	 *
4473
+	 * @throws DomainException
4474
+	 * @throws EE_Error
4475
+	 * @throws EE_Error
4476
+	 */
4477
+	public function update_mt_form()
4478
+	{
4479
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
+			EE_Error::add_error(
4481
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482
+				__FILE__,
4483
+				__FUNCTION__,
4484
+				__LINE__
4485
+			);
4486
+			$this->_return_json();
4487
+		}
4488
+
4489
+		$message_types = $this->get_installed_message_types();
4490
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4491
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493
+
4494
+		$this->_template_args['success'] = true;
4495
+		$this->_template_args['content'] = $content;
4496
+		$this->_return_json();
4497
+	}
4498
+
4499
+
4500
+	/**
4501
+	 * this handles saving the settings for a messenger or message type
4502
+	 *
4503
+	 * @throws EE_Error
4504
+	 * @throws EE_Error
4505
+	 */
4506
+	public function save_settings()
4507
+	{
4508
+		$type = $this->request->getRequestParam('type');
4509
+		if (! $type) {
4510
+			EE_Error::add_error(
4511
+				esc_html__(
4512
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4513
+					'event_espresso'
4514
+				),
4515
+				__FILE__,
4516
+				__FUNCTION__,
4517
+				__LINE__
4518
+			);
4519
+			$this->_template_args['error'] = true;
4520
+			$this->_return_json();
4521
+		}
4522
+
4523
+
4524
+		if ($type === 'messenger') {
4525
+			// this should be an array.
4526
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4527
+			$messenger = $settings['messenger'];
4528
+			// remove messenger and message_types from settings array
4529
+			unset($settings['messenger'], $settings['message_types']);
4530
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4531
+		} elseif ($type === 'message_type') {
4532
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4533
+			$messenger    = $settings['messenger'];
4534
+			$message_type = $settings['message_type'];
4535
+			// remove messenger and message_types from settings array
4536
+			unset($settings['messenger'], $settings['message_types']);
4537
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4538
+		}
4539
+
4540
+		// okay we should have the data all setup.  Now we just update!
4541
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4542
+
4543
+		if ($success) {
4544
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4545
+		} else {
4546
+			EE_Error::add_error(
4547
+				esc_html__('Settings did not get updated', 'event_espresso'),
4548
+				__FILE__,
4549
+				__FUNCTION__,
4550
+				__LINE__
4551
+			);
4552
+		}
4553
+
4554
+		$this->_template_args['success'] = $success;
4555
+		$this->_return_json();
4556
+	}
4557
+
4558
+
4559
+
4560
+
4561
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4562
+
4563
+
4564
+	/**
4565
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4566
+	 * However, this does not send immediately, it just queues for sending.
4567
+	 *
4568
+	 * @throws EE_Error
4569
+	 * @throws InvalidDataTypeException
4570
+	 * @throws InvalidInterfaceException
4571
+	 * @throws InvalidArgumentException
4572
+	 * @throws ReflectionException
4573
+	 * @since 4.9.0
4574
+	 */
4575
+	protected function _generate_now()
4576
+	{
4577
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4578
+		$this->_redirect_after_action(false, '', '', [], true);
4579
+	}
4580
+
4581
+
4582
+	/**
4583
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4584
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4585
+	 *
4586
+	 * @throws EE_Error
4587
+	 * @throws InvalidDataTypeException
4588
+	 * @throws InvalidInterfaceException
4589
+	 * @throws InvalidArgumentException
4590
+	 * @throws ReflectionException
4591
+	 * @since 4.9.0
4592
+	 */
4593
+	protected function _generate_and_send_now()
4594
+	{
4595
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4596
+		$this->_redirect_after_action(false, '', '', [], true);
4597
+	}
4598
+
4599
+
4600
+	/**
4601
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4602
+	 *
4603
+	 * @throws EE_Error
4604
+	 * @throws InvalidDataTypeException
4605
+	 * @throws InvalidInterfaceException
4606
+	 * @throws InvalidArgumentException
4607
+	 * @throws ReflectionException
4608
+	 * @since 4.9.0
4609
+	 */
4610
+	protected function _queue_for_resending()
4611
+	{
4612
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4613
+		$this->_redirect_after_action(false, '', '', [], true);
4614
+	}
4615
+
4616
+
4617
+	/**
4618
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4619
+	 *
4620
+	 * @throws EE_Error
4621
+	 * @throws InvalidDataTypeException
4622
+	 * @throws InvalidInterfaceException
4623
+	 * @throws InvalidArgumentException
4624
+	 * @throws ReflectionException
4625
+	 * @since 4.9.0
4626
+	 */
4627
+	protected function _send_now()
4628
+	{
4629
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4630
+		$this->_redirect_after_action(false, '', '', [], true);
4631
+	}
4632
+
4633
+
4634
+	/**
4635
+	 * Deletes EE_messages for IDs in the request.
4636
+	 *
4637
+	 * @throws EE_Error
4638
+	 * @throws InvalidDataTypeException
4639
+	 * @throws InvalidInterfaceException
4640
+	 * @throws InvalidArgumentException
4641
+	 * @since 4.9.0
4642
+	 */
4643
+	protected function _delete_ee_messages()
4644
+	{
4645
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4646
+		$deleted_count = 0;
4647
+		foreach ($MSG_IDs as $MSG_ID) {
4648
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4649
+				$deleted_count++;
4650
+			}
4651
+		}
4652
+		if ($deleted_count) {
4653
+			EE_Error::add_success(
4654
+				esc_html(
4655
+					_n(
4656
+						'Message successfully deleted',
4657
+						'Messages successfully deleted',
4658
+						$deleted_count,
4659
+						'event_espresso'
4660
+					)
4661
+				)
4662
+			);
4663
+		} else {
4664
+			EE_Error::add_error(
4665
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4666
+				__FILE__,
4667
+				__FUNCTION__,
4668
+				__LINE__
4669
+			);
4670
+		}
4671
+		$this->_redirect_after_action(false, '', '', [], true);
4672
+	}
4673
+
4674
+
4675
+	/**
4676
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4677
+	 *
4678
+	 * @return array
4679
+	 * @since 4.9.0
4680
+	 */
4681
+	protected function _get_msg_ids_from_request()
4682
+	{
4683
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4684
+		if (empty($MSG_IDs)) {
4685
+			return [];
4686
+		}
4687
+		// if 'MSG_ID' was just a single ID (not an array)
4688
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4689
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4690
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4691
+			? $MSG_IDs
4692
+			: array_keys($MSG_IDs);
4693
+	}
4694 4694
 }
Please login to merge, or discard this patch.
admin_pages/venues/Venues_Admin_Page.core.php 1 patch
Indentation   +1556 added lines, -1556 removed lines patch added patch discarded remove patch
@@ -14,1566 +14,1566 @@
 block discarded – undo
14 14
 class Venues_Admin_Page extends EE_Admin_Page_CPT
15 15
 {
16 16
 
17
-    /**
18
-     * _venue
19
-     * This will hold the venue object for venue_details screen.
20
-     *
21
-     * @access protected
22
-     * @var object
23
-     */
24
-    protected $_venue;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var object
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This property will hold the venue model instance
37
-     *
38
-     * @var object
39
-     */
40
-    protected $_venue_model;
41
-
42
-
43
-    /**
44
-     * @throws EE_Error
45
-     */
46
-    protected function _init_page_props()
47
-    {
48
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
49
-        $this->page_slug        = EE_VENUES_PG_SLUG;
50
-        $this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
-        $this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
-        $this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
-        $this->_cpt_model_names = [
54
-            'create_new' => 'EEM_Venue',
55
-            'edit'       => 'EEM_Venue',
56
-        ];
57
-        $this->_cpt_edit_routes = [
58
-            'espresso_venues' => 'edit',
59
-        ];
60
-        $this->_venue_model     = EEM_Venue::instance();
61
-    }
62
-
63
-
64
-    protected function _ajax_hooks()
65
-    {
66
-        // todo: all hooks for ee_venues ajax goes in here.
67
-    }
68
-
69
-
70
-    protected function _define_page_props()
71
-    {
72
-        $this->_admin_page_title = $this->page_label;
73
-        $this->_labels           = [
74
-            'buttons'      => [
75
-                'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
-                'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
-                'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
-            ],
82
-            'editor_title' => [
83
-                'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
-            ],
85
-            'publishbox'   => [
86
-                'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
-                'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
-                'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
-                'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
-                'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
-            ],
92
-        ];
93
-    }
94
-
95
-
96
-    protected function _set_page_routes()
97
-    {
98
-
99
-        // load formatter helper
100
-        // load field generator helper
101
-
102
-        // is there a vnu_id in the request?
103
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
-
106
-        $this->_page_routes = [
107
-            'default'                    => [
108
-                'func'       => '_overview_list_table',
109
-                'capability' => 'ee_read_venues',
110
-            ],
111
-            'create_new'                 => [
112
-                'func'       => '_create_new_cpt_item',
113
-                'capability' => 'ee_edit_venues',
114
-            ],
115
-            'edit'                       => [
116
-                'func'       => '_edit_cpt_item',
117
-                'capability' => 'ee_edit_venue',
118
-                'obj_id'     => $VNU_ID,
119
-            ],
120
-            'trash_venue'                => [
121
-                'func'       => '_trash_or_restore_venue',
122
-                'args'       => ['venue_status' => 'trash'],
123
-                'noheader'   => true,
124
-                'capability' => 'ee_delete_venue',
125
-                'obj_id'     => $VNU_ID,
126
-            ],
127
-            'trash_venues'               => [
128
-                'func'       => '_trash_or_restore_venues',
129
-                'args'       => ['venue_status' => 'trash'],
130
-                'noheader'   => true,
131
-                'capability' => 'ee_delete_venues',
132
-            ],
133
-            'restore_venue'              => [
134
-                'func'       => '_trash_or_restore_venue',
135
-                'args'       => ['venue_status' => 'draft'],
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_venue',
138
-                'obj_id'     => $VNU_ID,
139
-            ],
140
-            'restore_venues'             => [
141
-                'func'       => '_trash_or_restore_venues',
142
-                'args'       => ['venue_status' => 'draft'],
143
-                'noheader'   => true,
144
-                'capability' => 'ee_delete_venues',
145
-            ],
146
-            'delete_venues'              => [
147
-                'func'       => '_delete_venues',
148
-                'noheader'   => true,
149
-                'capability' => 'ee_delete_venues',
150
-            ],
151
-            'delete_venue'               => [
152
-                'func'       => '_delete_venue',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_delete_venue',
155
-                'obj_id'     => $VNU_ID,
156
-            ],
157
-            // settings related
158
-            'google_map_settings'        => [
159
-                'func'       => '_google_map_settings',
160
-                'capability' => 'manage_options',
161
-            ],
162
-            'update_google_map_settings' => [
163
-                'func'       => '_update_google_map_settings',
164
-                'capability' => 'manage_options',
165
-                'noheader'   => true,
166
-            ],
167
-            // venue category tab related
168
-            'add_category'               => [
169
-                'func'       => '_category_details',
170
-                'args'       => ['add'],
171
-                'capability' => 'ee_edit_venue_category',
172
-            ],
173
-            'edit_category'              => [
174
-                'func'       => '_category_details',
175
-                'args'       => ['edit'],
176
-                'capability' => 'ee_edit_venue_category',
177
-            ],
178
-            'delete_categories'          => [
179
-                'func'       => '_delete_categories',
180
-                'noheader'   => true,
181
-                'capability' => 'ee_delete_venue_category',
182
-            ],
183
-
184
-            'delete_category' => [
185
-                'func'       => '_delete_categories',
186
-                'noheader'   => true,
187
-                'capability' => 'ee_delete_venue_category',
188
-            ],
189
-
190
-            'insert_category' => [
191
-                'func'       => '_insert_or_update_category',
192
-                'args'       => ['new_category' => true],
193
-                'noheader'   => true,
194
-                'capability' => 'ee_edit_venue_category',
195
-            ],
196
-
197
-            'update_category'   => [
198
-                'func'       => '_insert_or_update_category',
199
-                'args'       => ['new_category' => false],
200
-                'noheader'   => true,
201
-                'capability' => 'ee_edit_venue_category',
202
-            ],
203
-            'export_categories' => [
204
-                'func'       => '_categories_export',
205
-                'noheader'   => true,
206
-                'capability' => 'export',
207
-            ],
208
-            'import_categories' => [
209
-                'func'       => '_import_categories',
210
-                'capability' => 'import',
211
-            ],
212
-            'category_list'     => [
213
-                'func'       => '_category_list_table',
214
-                'capability' => 'ee_manage_venue_categories',
215
-            ],
216
-        ];
217
-    }
218
-
219
-
220
-    protected function _set_page_config()
221
-    {
222
-        $VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
-        $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
-
225
-        $this->_page_config = [
226
-            'default'             => [
227
-                'nav'           => [
228
-                    'label' => esc_html__('Overview', 'event_espresso'),
229
-                    'order' => 10,
230
-                ],
231
-                'list_table'    => 'Venues_Admin_List_Table',
232
-                'help_tabs'     => [
233
-                    'venues_overview_help_tab'                           => [
234
-                        'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
-                        'filename' => 'venues_overview',
236
-                    ],
237
-                    'venues_overview_table_column_headings_help_tab'     => [
238
-                        'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
-                        'filename' => 'venues_overview_table_column_headings',
240
-                    ],
241
-                    'venues_overview_views_bulk_actions_search_help_tab' => [
242
-                        'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
-                        'filename' => 'venues_overview_views_bulk_actions_search',
244
-                    ],
245
-                ],
246
-                'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
247
-                'require_nonce' => false,
248
-            ],
249
-            'create_new'          => [
250
-                'nav'           => [
251
-                    'label'      => esc_html__('Add Venue', 'event_espresso'),
252
-                    'order'      => 5,
253
-                    'persistent' => false,
254
-                ],
255
-                'help_tabs'     => [
256
-                    'venues_editor_help_tab'                                               => [
257
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
258
-                        'filename' => 'venues_editor',
259
-                    ],
260
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
261
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
262
-                        'filename' => 'venues_editor_title_richtexteditor',
263
-                    ],
264
-                    'venues_editor_tags_categories_help_tab'                               => [
265
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
266
-                        'filename' => 'venues_editor_tags_categories',
267
-                    ],
268
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
269
-                        'title'    => esc_html__(
270
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
271
-                            'event_espresso'
272
-                        ),
273
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
-                    ],
275
-                    'venues_editor_save_new_venue_help_tab'                                => [
276
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
277
-                        'filename' => 'venues_editor_save_new_venue',
278
-                    ],
279
-                    'venues_editor_other_help_tab'                                         => [
280
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
281
-                        'filename' => 'venues_editor_other',
282
-                    ],
283
-                ],
284
-                'metaboxes'     => ['_venue_editor_metaboxes'],
285
-                'require_nonce' => false,
286
-            ],
287
-            'edit'                => [
288
-                'nav'           => [
289
-                    'label'      => esc_html__('Edit Venue', 'event_espresso'),
290
-                    'order'      => 5,
291
-                    'persistent' => false,
292
-                    'url'        => $VNU_ID
293
-                        ? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
294
-                        : $this->_admin_base_url,
295
-                ],
296
-                'help_tabs'     => [
297
-                    'venues_editor_help_tab'                                               => [
298
-                        'title'    => esc_html__('Venue Editor', 'event_espresso'),
299
-                        'filename' => 'venues_editor',
300
-                    ],
301
-                    'venues_editor_title_richtexteditor_help_tab'                          => [
302
-                        'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
303
-                        'filename' => 'venues_editor_title_richtexteditor',
304
-                    ],
305
-                    'venues_editor_tags_categories_help_tab'                               => [
306
-                        'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
307
-                        'filename' => 'venues_editor_tags_categories',
308
-                    ],
309
-                    'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
310
-                        'title'    => esc_html__(
311
-                            'Venue Editor Physical Location & Google Map & Virtual Location',
312
-                            'event_espresso'
313
-                        ),
314
-                        'filename' => 'venues_editor_physical_location_google_map_virtual_location',
315
-                    ],
316
-                    'venues_editor_save_new_venue_help_tab'                                => [
317
-                        'title'    => esc_html__('Save New Venue', 'event_espresso'),
318
-                        'filename' => 'venues_editor_save_new_venue',
319
-                    ],
320
-                    'venues_editor_other_help_tab'                                         => [
321
-                        'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
322
-                        'filename' => 'venues_editor_other',
323
-                    ],
324
-                ],
325
-                'metaboxes'     => ['_venue_editor_metaboxes'],
326
-                'require_nonce' => false,
327
-            ],
328
-            'google_map_settings' => [
329
-                'nav'           => [
330
-                    'label' => esc_html__('Google Maps', 'event_espresso'),
331
-                    'order' => 40,
332
-                ],
333
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
334
-                'help_tabs'     => [
335
-                    'general_settings_google_maps_help_tab' => [
336
-                        'title'    => esc_html__('Google Maps', 'event_espresso'),
337
-                        'filename' => 'general_settings_google_maps',
338
-                    ],
339
-                ],
340
-                'require_nonce' => false,
341
-            ],
342
-            // venue category stuff
343
-            'add_category'        => [
344
-                'nav'           => [
345
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
346
-                    'order'      => 15,
347
-                    'persistent' => false,
348
-                ],
349
-                'metaboxes'     => ['_publish_post_box'],
350
-                'help_tabs'     => [
351
-                    'venues_add_category_help_tab' => [
352
-                        'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
353
-                        'filename' => 'venues_add_category',
354
-                    ],
355
-                ],
356
-                'require_nonce' => false,
357
-            ],
358
-            'edit_category'       => [
359
-                'nav'           => [
360
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
361
-                    'order'      => 15,
362
-                    'persistent' => false,
363
-                    'url'        => $EVT_CAT_ID
364
-                        ? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
365
-                        : $this->_admin_base_url,
366
-                ],
367
-                'metaboxes'     => ['_publish_post_box'],
368
-                'help_tabs'     => [
369
-                    'venues_edit_category_help_tab' => [
370
-                        'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
371
-                        'filename' => 'venues_edit_category',
372
-                    ],
373
-                ],
374
-                'require_nonce' => false,
375
-            ],
376
-            'category_list'       => [
377
-                'nav'           => [
378
-                    'label' => esc_html__('Categories', 'event_espresso'),
379
-                    'order' => 20,
380
-                ],
381
-                'list_table'    => 'Venue_Categories_Admin_List_Table',
382
-                'help_tabs'     => [
383
-                    'venues_categories_help_tab'                       => [
384
-                        'title'    => esc_html__('Venue Categories', 'event_espresso'),
385
-                        'filename' => 'venues_categories',
386
-                    ],
387
-                    'venues_categories_table_column_headings_help_tab' => [
388
-                        'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
389
-                        'filename' => 'venues_categories_table_column_headings',
390
-                    ],
391
-                    'venues_categories_views_help_tab'                 => [
392
-                        'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
393
-                        'filename' => 'venues_categories_views',
394
-                    ],
395
-                    'venues_categories_other_help_tab'                 => [
396
-                        'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
397
-                        'filename' => 'venues_categories_other',
398
-                    ],
399
-                ],
400
-                'metaboxes'     => $this->_default_espresso_metaboxes,
401
-                'require_nonce' => false,
402
-            ],
403
-        ];
404
-    }
405
-
406
-
407
-    protected function _add_screen_options()
408
-    {
409
-        // todo
410
-    }
411
-
412
-
413
-    protected function _add_screen_options_default()
414
-    {
415
-        $this->_per_page_screen_option();
416
-    }
417
-
418
-
419
-    protected function _add_screen_options_category_list()
420
-    {
421
-        $page_title              = $this->_admin_page_title;
422
-        $this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
423
-        $this->_per_page_screen_option();
424
-        $this->_admin_page_title = $page_title;
425
-    }
426
-
427
-
428
-    // none of the below group are currently used for Event Venues
429
-    protected function _add_feature_pointers()
430
-    {
431
-    }
432
-
433
-
434
-    public function admin_init()
435
-    {
436
-    }
437
-
438
-
439
-    public function admin_notices()
440
-    {
441
-    }
442
-
443
-
444
-    public function admin_footer_scripts()
445
-    {
446
-    }
447
-
448
-
449
-    public function load_scripts_styles_create_new()
450
-    {
451
-        $this->load_scripts_styles_edit();
452
-    }
453
-
454
-
455
-    public function load_scripts_styles()
456
-    {
457
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
458
-        wp_enqueue_style('ee-cat-admin');
459
-    }
460
-
461
-
462
-    public function load_scripts_styles_add_category()
463
-    {
464
-        $this->load_scripts_styles_edit_category();
465
-    }
466
-
467
-
468
-    public function load_scripts_styles_edit_category()
469
-    {
470
-    }
471
-
472
-
473
-    public function load_scripts_styles_edit()
474
-    {
475
-        // styles
476
-        wp_enqueue_style('espresso-ui-theme');
477
-        wp_register_style(
478
-            'espresso_venues',
479
-            EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
480
-            [],
481
-            EVENT_ESPRESSO_VERSION
482
-        );
483
-        wp_enqueue_style('espresso_venues');
484
-    }
485
-
486
-
487
-    protected function _set_list_table_views_default()
488
-    {
489
-        $this->_views = [
490
-            'all' => [
491
-                'slug'        => 'all',
492
-                'label'       => esc_html__('View All Venues', 'event_espresso'),
493
-                'count'       => 0,
494
-                'bulk_action' => [],
495
-            ],
496
-        ];
497
-
498
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
499
-            $this->_views['all']['bulk_action'] = [
500
-                'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
501
-            ];
502
-            $this->_views['trash']              = [
503
-                'slug'        => 'trash',
504
-                'label'       => esc_html__('Trash', 'event_espresso'),
505
-                'count'       => 0,
506
-                'bulk_action' => [
507
-                    'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
508
-                    'delete_venues'  => esc_html__('Delete', 'event_espresso'),
509
-                ],
510
-            ];
511
-        }
512
-    }
513
-
514
-
515
-    protected function _set_list_table_views_category_list()
516
-    {
517
-        $this->_views = [
518
-            'all' => [
519
-                'slug'        => 'all',
520
-                'label'       => esc_html__('All', 'event_espresso'),
521
-                'count'       => 0,
522
-                'bulk_action' => [
523
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
524
-                ],
525
-            ],
526
-        ];
527
-    }
528
-
529
-
530
-    /**
531
-     * @throws EE_Error
532
-     */
533
-    protected function _overview_list_table()
534
-    {
535
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
536
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
537
-            get_post_type_archive_link('espresso_venues'),
538
-            esc_html__("View Venue Archive Page", "event_espresso"),
539
-            'button'
540
-        );
541
-
542
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
543
-            'create_new',
544
-            'add',
545
-            [],
546
-            'add-new-h2'
547
-        );
548
-
549
-        $this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
550
-        $this->display_admin_list_table_page_with_sidebar();
551
-    }
552
-
553
-
554
-    /**
555
-     * @throws EE_Error
556
-     * @throws ReflectionException
557
-     */
558
-    public function extra_misc_actions_publish_box()
559
-    {
560
-        $extra_rows = [
561
-            'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
562
-            'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
563
-            'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
564
-        ];
565
-        $template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
566
-        EEH_Template::display_template($template, $extra_rows);
567
-    }
568
-
569
-
570
-    /*************        Google Maps        *************
17
+	/**
18
+	 * _venue
19
+	 * This will hold the venue object for venue_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var object
23
+	 */
24
+	protected $_venue;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var object
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This property will hold the venue model instance
37
+	 *
38
+	 * @var object
39
+	 */
40
+	protected $_venue_model;
41
+
42
+
43
+	/**
44
+	 * @throws EE_Error
45
+	 */
46
+	protected function _init_page_props()
47
+	{
48
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
49
+		$this->page_slug        = EE_VENUES_PG_SLUG;
50
+		$this->_admin_base_url  = EE_VENUES_ADMIN_URL;
51
+		$this->_admin_base_path = EE_ADMIN_PAGES . 'venues';
52
+		$this->page_label       = esc_html__('Event Venues', 'event_espresso');
53
+		$this->_cpt_model_names = [
54
+			'create_new' => 'EEM_Venue',
55
+			'edit'       => 'EEM_Venue',
56
+		];
57
+		$this->_cpt_edit_routes = [
58
+			'espresso_venues' => 'edit',
59
+		];
60
+		$this->_venue_model     = EEM_Venue::instance();
61
+	}
62
+
63
+
64
+	protected function _ajax_hooks()
65
+	{
66
+		// todo: all hooks for ee_venues ajax goes in here.
67
+	}
68
+
69
+
70
+	protected function _define_page_props()
71
+	{
72
+		$this->_admin_page_title = $this->page_label;
73
+		$this->_labels           = [
74
+			'buttons'      => [
75
+				'add'             => esc_html__('Add New Venue', 'event_espresso'),
76
+				'edit'            => esc_html__('Edit Venue', 'event_espresso'),
77
+				'delete'          => esc_html__('Delete Venue', 'event_espresso'),
78
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
79
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
80
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
81
+			],
82
+			'editor_title' => [
83
+				'espresso_venues' => esc_html__('Enter Venue name here', 'event_espresso'),
84
+			],
85
+			'publishbox'   => [
86
+				'create_new'          => esc_html__('Save New Venue', 'event_espresso'),
87
+				'edit'                => esc_html__('Update Venue', 'event_espresso'),
88
+				'add_category'        => esc_html__('Save New Category', 'event_espresso'),
89
+				'edit_category'       => esc_html__('Update Category', 'event_espresso'),
90
+				'google_map_settings' => esc_html__('Update Settings', 'event_espresso'),
91
+			],
92
+		];
93
+	}
94
+
95
+
96
+	protected function _set_page_routes()
97
+	{
98
+
99
+		// load formatter helper
100
+		// load field generator helper
101
+
102
+		// is there a vnu_id in the request?
103
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
104
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
105
+
106
+		$this->_page_routes = [
107
+			'default'                    => [
108
+				'func'       => '_overview_list_table',
109
+				'capability' => 'ee_read_venues',
110
+			],
111
+			'create_new'                 => [
112
+				'func'       => '_create_new_cpt_item',
113
+				'capability' => 'ee_edit_venues',
114
+			],
115
+			'edit'                       => [
116
+				'func'       => '_edit_cpt_item',
117
+				'capability' => 'ee_edit_venue',
118
+				'obj_id'     => $VNU_ID,
119
+			],
120
+			'trash_venue'                => [
121
+				'func'       => '_trash_or_restore_venue',
122
+				'args'       => ['venue_status' => 'trash'],
123
+				'noheader'   => true,
124
+				'capability' => 'ee_delete_venue',
125
+				'obj_id'     => $VNU_ID,
126
+			],
127
+			'trash_venues'               => [
128
+				'func'       => '_trash_or_restore_venues',
129
+				'args'       => ['venue_status' => 'trash'],
130
+				'noheader'   => true,
131
+				'capability' => 'ee_delete_venues',
132
+			],
133
+			'restore_venue'              => [
134
+				'func'       => '_trash_or_restore_venue',
135
+				'args'       => ['venue_status' => 'draft'],
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_venue',
138
+				'obj_id'     => $VNU_ID,
139
+			],
140
+			'restore_venues'             => [
141
+				'func'       => '_trash_or_restore_venues',
142
+				'args'       => ['venue_status' => 'draft'],
143
+				'noheader'   => true,
144
+				'capability' => 'ee_delete_venues',
145
+			],
146
+			'delete_venues'              => [
147
+				'func'       => '_delete_venues',
148
+				'noheader'   => true,
149
+				'capability' => 'ee_delete_venues',
150
+			],
151
+			'delete_venue'               => [
152
+				'func'       => '_delete_venue',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_delete_venue',
155
+				'obj_id'     => $VNU_ID,
156
+			],
157
+			// settings related
158
+			'google_map_settings'        => [
159
+				'func'       => '_google_map_settings',
160
+				'capability' => 'manage_options',
161
+			],
162
+			'update_google_map_settings' => [
163
+				'func'       => '_update_google_map_settings',
164
+				'capability' => 'manage_options',
165
+				'noheader'   => true,
166
+			],
167
+			// venue category tab related
168
+			'add_category'               => [
169
+				'func'       => '_category_details',
170
+				'args'       => ['add'],
171
+				'capability' => 'ee_edit_venue_category',
172
+			],
173
+			'edit_category'              => [
174
+				'func'       => '_category_details',
175
+				'args'       => ['edit'],
176
+				'capability' => 'ee_edit_venue_category',
177
+			],
178
+			'delete_categories'          => [
179
+				'func'       => '_delete_categories',
180
+				'noheader'   => true,
181
+				'capability' => 'ee_delete_venue_category',
182
+			],
183
+
184
+			'delete_category' => [
185
+				'func'       => '_delete_categories',
186
+				'noheader'   => true,
187
+				'capability' => 'ee_delete_venue_category',
188
+			],
189
+
190
+			'insert_category' => [
191
+				'func'       => '_insert_or_update_category',
192
+				'args'       => ['new_category' => true],
193
+				'noheader'   => true,
194
+				'capability' => 'ee_edit_venue_category',
195
+			],
196
+
197
+			'update_category'   => [
198
+				'func'       => '_insert_or_update_category',
199
+				'args'       => ['new_category' => false],
200
+				'noheader'   => true,
201
+				'capability' => 'ee_edit_venue_category',
202
+			],
203
+			'export_categories' => [
204
+				'func'       => '_categories_export',
205
+				'noheader'   => true,
206
+				'capability' => 'export',
207
+			],
208
+			'import_categories' => [
209
+				'func'       => '_import_categories',
210
+				'capability' => 'import',
211
+			],
212
+			'category_list'     => [
213
+				'func'       => '_category_list_table',
214
+				'capability' => 'ee_manage_venue_categories',
215
+			],
216
+		];
217
+	}
218
+
219
+
220
+	protected function _set_page_config()
221
+	{
222
+		$VNU_ID     = $this->request->getRequestParam('post', 0, 'int');
223
+		$EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
224
+
225
+		$this->_page_config = [
226
+			'default'             => [
227
+				'nav'           => [
228
+					'label' => esc_html__('Overview', 'event_espresso'),
229
+					'order' => 10,
230
+				],
231
+				'list_table'    => 'Venues_Admin_List_Table',
232
+				'help_tabs'     => [
233
+					'venues_overview_help_tab'                           => [
234
+						'title'    => esc_html__('Venues Overview', 'event_espresso'),
235
+						'filename' => 'venues_overview',
236
+					],
237
+					'venues_overview_table_column_headings_help_tab'     => [
238
+						'title'    => esc_html__('Venues Overview Table Column Headings', 'event_espresso'),
239
+						'filename' => 'venues_overview_table_column_headings',
240
+					],
241
+					'venues_overview_views_bulk_actions_search_help_tab' => [
242
+						'title'    => esc_html__('Venues Overview Views & Bulk Actions & Search', 'event_espresso'),
243
+						'filename' => 'venues_overview_views_bulk_actions_search',
244
+					],
245
+				],
246
+				'metaboxes'     => ['_espresso_news_post_box', '_espresso_links_post_box'],
247
+				'require_nonce' => false,
248
+			],
249
+			'create_new'          => [
250
+				'nav'           => [
251
+					'label'      => esc_html__('Add Venue', 'event_espresso'),
252
+					'order'      => 5,
253
+					'persistent' => false,
254
+				],
255
+				'help_tabs'     => [
256
+					'venues_editor_help_tab'                                               => [
257
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
258
+						'filename' => 'venues_editor',
259
+					],
260
+					'venues_editor_title_richtexteditor_help_tab'                          => [
261
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
262
+						'filename' => 'venues_editor_title_richtexteditor',
263
+					],
264
+					'venues_editor_tags_categories_help_tab'                               => [
265
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
266
+						'filename' => 'venues_editor_tags_categories',
267
+					],
268
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
269
+						'title'    => esc_html__(
270
+							'Venue Editor Physical Location & Google Map & Virtual Location',
271
+							'event_espresso'
272
+						),
273
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
274
+					],
275
+					'venues_editor_save_new_venue_help_tab'                                => [
276
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
277
+						'filename' => 'venues_editor_save_new_venue',
278
+					],
279
+					'venues_editor_other_help_tab'                                         => [
280
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
281
+						'filename' => 'venues_editor_other',
282
+					],
283
+				],
284
+				'metaboxes'     => ['_venue_editor_metaboxes'],
285
+				'require_nonce' => false,
286
+			],
287
+			'edit'                => [
288
+				'nav'           => [
289
+					'label'      => esc_html__('Edit Venue', 'event_espresso'),
290
+					'order'      => 5,
291
+					'persistent' => false,
292
+					'url'        => $VNU_ID
293
+						? add_query_arg(['post' => $VNU_ID], $this->_current_page_view_url)
294
+						: $this->_admin_base_url,
295
+				],
296
+				'help_tabs'     => [
297
+					'venues_editor_help_tab'                                               => [
298
+						'title'    => esc_html__('Venue Editor', 'event_espresso'),
299
+						'filename' => 'venues_editor',
300
+					],
301
+					'venues_editor_title_richtexteditor_help_tab'                          => [
302
+						'title'    => esc_html__('Venue Title & Rich Text Editor', 'event_espresso'),
303
+						'filename' => 'venues_editor_title_richtexteditor',
304
+					],
305
+					'venues_editor_tags_categories_help_tab'                               => [
306
+						'title'    => esc_html__('Venue Tags & Categories', 'event_espresso'),
307
+						'filename' => 'venues_editor_tags_categories',
308
+					],
309
+					'venues_editor_physical_location_google_map_virtual_location_help_tab' => [
310
+						'title'    => esc_html__(
311
+							'Venue Editor Physical Location & Google Map & Virtual Location',
312
+							'event_espresso'
313
+						),
314
+						'filename' => 'venues_editor_physical_location_google_map_virtual_location',
315
+					],
316
+					'venues_editor_save_new_venue_help_tab'                                => [
317
+						'title'    => esc_html__('Save New Venue', 'event_espresso'),
318
+						'filename' => 'venues_editor_save_new_venue',
319
+					],
320
+					'venues_editor_other_help_tab'                                         => [
321
+						'title'    => esc_html__('Venue Editor Other', 'event_espresso'),
322
+						'filename' => 'venues_editor_other',
323
+					],
324
+				],
325
+				'metaboxes'     => ['_venue_editor_metaboxes'],
326
+				'require_nonce' => false,
327
+			],
328
+			'google_map_settings' => [
329
+				'nav'           => [
330
+					'label' => esc_html__('Google Maps', 'event_espresso'),
331
+					'order' => 40,
332
+				],
333
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
334
+				'help_tabs'     => [
335
+					'general_settings_google_maps_help_tab' => [
336
+						'title'    => esc_html__('Google Maps', 'event_espresso'),
337
+						'filename' => 'general_settings_google_maps',
338
+					],
339
+				],
340
+				'require_nonce' => false,
341
+			],
342
+			// venue category stuff
343
+			'add_category'        => [
344
+				'nav'           => [
345
+					'label'      => esc_html__('Add Category', 'event_espresso'),
346
+					'order'      => 15,
347
+					'persistent' => false,
348
+				],
349
+				'metaboxes'     => ['_publish_post_box'],
350
+				'help_tabs'     => [
351
+					'venues_add_category_help_tab' => [
352
+						'title'    => esc_html__('Add New Venue Category', 'event_espresso'),
353
+						'filename' => 'venues_add_category',
354
+					],
355
+				],
356
+				'require_nonce' => false,
357
+			],
358
+			'edit_category'       => [
359
+				'nav'           => [
360
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
361
+					'order'      => 15,
362
+					'persistent' => false,
363
+					'url'        => $EVT_CAT_ID
364
+						? add_query_arg(['EVT_CAT_ID' => $EVT_CAT_ID], $this->_current_page_view_url)
365
+						: $this->_admin_base_url,
366
+				],
367
+				'metaboxes'     => ['_publish_post_box'],
368
+				'help_tabs'     => [
369
+					'venues_edit_category_help_tab' => [
370
+						'title'    => esc_html__('Edit Venue Category', 'event_espresso'),
371
+						'filename' => 'venues_edit_category',
372
+					],
373
+				],
374
+				'require_nonce' => false,
375
+			],
376
+			'category_list'       => [
377
+				'nav'           => [
378
+					'label' => esc_html__('Categories', 'event_espresso'),
379
+					'order' => 20,
380
+				],
381
+				'list_table'    => 'Venue_Categories_Admin_List_Table',
382
+				'help_tabs'     => [
383
+					'venues_categories_help_tab'                       => [
384
+						'title'    => esc_html__('Venue Categories', 'event_espresso'),
385
+						'filename' => 'venues_categories',
386
+					],
387
+					'venues_categories_table_column_headings_help_tab' => [
388
+						'title'    => esc_html__('Venue Categories Table Column Headings', 'event_espresso'),
389
+						'filename' => 'venues_categories_table_column_headings',
390
+					],
391
+					'venues_categories_views_help_tab'                 => [
392
+						'title'    => esc_html__('Venue Categories Views', 'event_espresso'),
393
+						'filename' => 'venues_categories_views',
394
+					],
395
+					'venues_categories_other_help_tab'                 => [
396
+						'title'    => esc_html__('Venue Categories Other', 'event_espresso'),
397
+						'filename' => 'venues_categories_other',
398
+					],
399
+				],
400
+				'metaboxes'     => $this->_default_espresso_metaboxes,
401
+				'require_nonce' => false,
402
+			],
403
+		];
404
+	}
405
+
406
+
407
+	protected function _add_screen_options()
408
+	{
409
+		// todo
410
+	}
411
+
412
+
413
+	protected function _add_screen_options_default()
414
+	{
415
+		$this->_per_page_screen_option();
416
+	}
417
+
418
+
419
+	protected function _add_screen_options_category_list()
420
+	{
421
+		$page_title              = $this->_admin_page_title;
422
+		$this->_admin_page_title = esc_html__('Venue Categories', 'event_espresso');
423
+		$this->_per_page_screen_option();
424
+		$this->_admin_page_title = $page_title;
425
+	}
426
+
427
+
428
+	// none of the below group are currently used for Event Venues
429
+	protected function _add_feature_pointers()
430
+	{
431
+	}
432
+
433
+
434
+	public function admin_init()
435
+	{
436
+	}
437
+
438
+
439
+	public function admin_notices()
440
+	{
441
+	}
442
+
443
+
444
+	public function admin_footer_scripts()
445
+	{
446
+	}
447
+
448
+
449
+	public function load_scripts_styles_create_new()
450
+	{
451
+		$this->load_scripts_styles_edit();
452
+	}
453
+
454
+
455
+	public function load_scripts_styles()
456
+	{
457
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
458
+		wp_enqueue_style('ee-cat-admin');
459
+	}
460
+
461
+
462
+	public function load_scripts_styles_add_category()
463
+	{
464
+		$this->load_scripts_styles_edit_category();
465
+	}
466
+
467
+
468
+	public function load_scripts_styles_edit_category()
469
+	{
470
+	}
471
+
472
+
473
+	public function load_scripts_styles_edit()
474
+	{
475
+		// styles
476
+		wp_enqueue_style('espresso-ui-theme');
477
+		wp_register_style(
478
+			'espresso_venues',
479
+			EE_VENUES_ASSETS_URL . 'ee-venues-admin.css',
480
+			[],
481
+			EVENT_ESPRESSO_VERSION
482
+		);
483
+		wp_enqueue_style('espresso_venues');
484
+	}
485
+
486
+
487
+	protected function _set_list_table_views_default()
488
+	{
489
+		$this->_views = [
490
+			'all' => [
491
+				'slug'        => 'all',
492
+				'label'       => esc_html__('View All Venues', 'event_espresso'),
493
+				'count'       => 0,
494
+				'bulk_action' => [],
495
+			],
496
+		];
497
+
498
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) {
499
+			$this->_views['all']['bulk_action'] = [
500
+				'trash_venues' => esc_html__('Move to Trash', 'event_espresso'),
501
+			];
502
+			$this->_views['trash']              = [
503
+				'slug'        => 'trash',
504
+				'label'       => esc_html__('Trash', 'event_espresso'),
505
+				'count'       => 0,
506
+				'bulk_action' => [
507
+					'restore_venues' => esc_html__('Restore from Trash', 'event_espresso'),
508
+					'delete_venues'  => esc_html__('Delete', 'event_espresso'),
509
+				],
510
+			];
511
+		}
512
+	}
513
+
514
+
515
+	protected function _set_list_table_views_category_list()
516
+	{
517
+		$this->_views = [
518
+			'all' => [
519
+				'slug'        => 'all',
520
+				'label'       => esc_html__('All', 'event_espresso'),
521
+				'count'       => 0,
522
+				'bulk_action' => [
523
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
524
+				],
525
+			],
526
+		];
527
+	}
528
+
529
+
530
+	/**
531
+	 * @throws EE_Error
532
+	 */
533
+	protected function _overview_list_table()
534
+	{
535
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
536
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
537
+			get_post_type_archive_link('espresso_venues'),
538
+			esc_html__("View Venue Archive Page", "event_espresso"),
539
+			'button'
540
+		);
541
+
542
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
543
+			'create_new',
544
+			'add',
545
+			[],
546
+			'add-new-h2'
547
+		);
548
+
549
+		$this->_search_btn_label  = esc_html__('Venues', 'event_espresso');
550
+		$this->display_admin_list_table_page_with_sidebar();
551
+	}
552
+
553
+
554
+	/**
555
+	 * @throws EE_Error
556
+	 * @throws ReflectionException
557
+	 */
558
+	public function extra_misc_actions_publish_box()
559
+	{
560
+		$extra_rows = [
561
+			'vnu_capacity' => $this->_cpt_model_obj->get_f('VNU_capacity'),
562
+			'vnu_url'      => $this->_cpt_model_obj->get_f('VNU_url'),
563
+			'vnu_phone'    => $this->_cpt_model_obj->get_f('VNU_phone'),
564
+		];
565
+		$template   = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php';
566
+		EEH_Template::display_template($template, $extra_rows);
567
+	}
568
+
569
+
570
+	/*************        Google Maps        *************
571 571
      *
572 572
      * @throws EE_Error
573 573
      * @throws EE_Error
574 574
      */
575 575
 
576 576
 
577
-    protected function _google_map_settings()
578
-    {
579
-
580
-
581
-        $this->_template_args['values']           = $this->_yes_no_values;
582
-        $default_map_settings                     = new stdClass();
583
-        $default_map_settings->use_google_maps    = true;
584
-        $default_map_settings->google_map_api_key = '';
585
-        // for event details pages (reg page)
586
-        $default_map_settings->event_details_map_width    = 585;
587
-        // ee_map_width_single
588
-        $default_map_settings->event_details_map_height   = 362;
589
-        // ee_map_height_single
590
-        $default_map_settings->event_details_map_zoom     = 14;
591
-        // ee_map_zoom_single
592
-        $default_map_settings->event_details_display_nav  = true;
593
-        // ee_map_nav_display_single
594
-        $default_map_settings->event_details_nav_size     = false;
595
-        // ee_map_nav_size_single
596
-        $default_map_settings->event_details_control_type = 'default';
597
-        // ee_map_type_control_single
598
-        $default_map_settings->event_details_map_align    = 'center';
599
-        // ee_map_align_single
600
-
601
-        // for event list pages
602
-        $default_map_settings->event_list_map_width    = 300;
603
-        // ee_map_width
604
-        $default_map_settings->event_list_map_height   = 185;
605
-        // ee_map_height
606
-        $default_map_settings->event_list_map_zoom     = 12;
607
-        // ee_map_zoom
608
-        $default_map_settings->event_list_display_nav  = false;
609
-        // ee_map_nav_display
610
-        $default_map_settings->event_list_nav_size     = true;
611
-        // ee_map_nav_size
612
-        $default_map_settings->event_list_control_type = 'dropdown';
613
-        // ee_map_type_control
614
-        $default_map_settings->event_list_map_align    = 'center';
615
-        // ee_map_align
616
-
617
-        $this->_template_args['map_settings'] =
618
-            isset(EE_Registry::instance()->CFG->map_settings)
619
-            && ! empty(EE_Registry::instance()->CFG->map_settings)
620
-                ? (object) array_merge(
621
-                    (array) $default_map_settings,
622
-                    (array) EE_Registry::instance()->CFG->map_settings
623
-                )
624
-                : $default_map_settings;
625
-
626
-        $this->_set_add_edit_form_tags('update_google_map_settings');
627
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
628
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
629
-            EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
630
-            $this->_template_args,
631
-            true
632
-        );
633
-        $this->display_admin_page_with_sidebar();
634
-    }
635
-
636
-
637
-    /**
638
-     * @throws EE_Error
639
-     */
640
-    protected function _update_google_map_settings()
641
-    {
642
-        $map_settings = EE_Registry::instance()->CFG->map_settings;
643
-
644
-        $settings = [
645
-            'use_google_maps'            => 'int',
646
-            'google_map_api_key'         => 'string',
647
-            'event_details_map_width'    => 'int',
648
-            'event_details_map_zoom'     => 'int',
649
-            'event_details_display_nav'  => 'int',
650
-            'event_details_nav_size'     => 'int',
651
-            'event_details_control_type' => 'string',
652
-            'event_details_map_align'    => 'string',
653
-            'event_list_map_width'       => 'int',
654
-            'event_list_map_height'      => 'int',
655
-            'event_list_map_zoom'        => 'int',
656
-            'event_list_display_nav'     => 'int',
657
-            'event_list_nav_size'        => 'int',
658
-            'event_list_control_type'    => 'string',
659
-            'event_list_map_align'       => 'string',
660
-        ];
661
-
662
-        foreach ($settings as $setting => $type) {
663
-            $map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
664
-        }
665
-
666
-        EE_Registry::instance()->CFG->map_settings = apply_filters(
667
-            'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
668
-            $map_settings
669
-        );
670
-
671
-        $what    = 'Google Map Settings';
672
-        $success = $this->_update_espresso_configuration(
673
-            $what,
674
-            EE_Registry::instance()->CFG->map_settings,
675
-            __FILE__,
676
-            __FUNCTION__,
677
-            __LINE__
678
-        );
679
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
680
-    }
681
-
682
-
683
-    /**
684
-     * @throws EE_Error
685
-     * @throws ReflectionException
686
-     */
687
-    protected function _venue_editor_metaboxes()
688
-    {
689
-        $this->verify_cpt_object();
690
-
691
-        add_meta_box(
692
-            'espresso_venue_address_options',
693
-            esc_html__('Physical Location', 'event_espresso'),
694
-            [$this, 'venue_address_metabox'],
695
-            $this->page_slug,
696
-            'side'
697
-        );
698
-        add_meta_box(
699
-            'espresso_venue_gmap_options',
700
-            esc_html__('Google Map', 'event_espresso'),
701
-            [$this, 'venue_gmap_metabox'],
702
-            $this->page_slug,
703
-            'side'
704
-        );
705
-        add_meta_box(
706
-            'espresso_venue_virtual_loc_options',
707
-            esc_html__('Virtual Location', 'event_espresso'),
708
-            [$this, 'venue_virtual_loc_metabox'],
709
-            $this->page_slug,
710
-            'side'
711
-        );
712
-    }
713
-
714
-
715
-    public function venue_gmap_metabox()
716
-    {
717
-        $template_args = [
718
-            'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
719
-                'vnu_enable_for_gmap',
720
-                $this->get_yes_no_values(),
721
-                $this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
722
-            ),
723
-            'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
724
-        ];
725
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
726
-        EEH_Template::display_template($template, $template_args);
727
-    }
728
-
729
-
730
-    /**
731
-     * @throws EE_Error
732
-     * @throws ReflectionException
733
-     */
734
-    public function venue_address_metabox()
735
-    {
736
-        $template_args['_venue'] = $this->_cpt_model_obj;
737
-
738
-        $template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
739
-            new EE_Question_Form_Input(
740
-                EE_Question::new_instance(
741
-                    ['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
742
-                ),
743
-                EE_Answer::new_instance(
744
-                    [
745
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
746
-                            ? $this->_cpt_model_obj->state_ID()
747
-                            : 0,
748
-                    ]
749
-                ),
750
-                [
751
-                    'input_name'     => 'sta_id',
752
-                    'input_id'       => 'sta_id',
753
-                    'input_class'    => '',
754
-                    'input_prefix'   => '',
755
-                    'append_qstn_id' => false,
756
-                ]
757
-            )
758
-        );
759
-        $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
760
-            new EE_Question_Form_Input(
761
-                EE_Question::new_instance(
762
-                    ['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
763
-                ),
764
-                EE_Answer::new_instance(
765
-                    [
766
-                        'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
767
-                            ? $this->_cpt_model_obj->country_ID()
768
-                            : 0,
769
-                    ]
770
-                ),
771
-                [
772
-                    'input_name'     => 'cnt_iso',
773
-                    'input_id'       => 'cnt_iso',
774
-                    'input_class'    => '',
775
-                    'input_prefix'   => '',
776
-                    'append_qstn_id' => false,
777
-                ]
778
-            )
779
-        );
780
-
781
-        $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
782
-        EEH_Template::display_template($template, $template_args);
783
-    }
784
-
785
-
786
-    public function venue_virtual_loc_metabox()
787
-    {
788
-        $template_args = [
789
-            '_venue' => $this->_cpt_model_obj,
790
-        ];
791
-        $template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
792
-        EEH_Template::display_template($template, $template_args);
793
-    }
794
-
795
-
796
-    protected function _restore_cpt_item($post_id, $revision_id)
797
-    {
798
-        $venue_obj = $this->_venue_model->get_one_by_ID($post_id);
799
-
800
-        // meta revision restore
801
-        $venue_obj->restore_revision($revision_id);
802
-    }
803
-
804
-
805
-    /**
806
-     * Handles updates for venue cpts
807
-     *
808
-     * @param int    $post_id ID of Venue CPT
809
-     * @param WP_Post $post    Post object (with "blessed" WP properties)
810
-     * @return void
811
-     */
812
-    protected function _insert_update_cpt_item($post_id, $post)
813
-    {
814
-
815
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
816
-            return;// get out we're not processing the saving of venues.
817
-        }
818
-
819
-        $wheres = [$this->_venue_model->primary_key_name() => $post_id];
820
-
821
-        $venue_values = [
822
-            'VNU_address'         => $this->request->getRequestParam('vnu_address'),
823
-            'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
824
-            'VNU_city'            => $this->request->getRequestParam('vnu_city'),
825
-            'STA_ID'              => $this->request->getRequestParam('sta_id'),
826
-            'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
827
-            'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
828
-            'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
829
-            'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
830
-                ? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
831
-                : EE_INF,
832
-            'VNU_url'             => $this->request->getRequestParam('vnu_url'),
833
-            'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
834
-            'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
835
-            'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
836
-            'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
837
-        ];
838
-
839
-        // update venue
840
-        $success = $this->_venue_model->update($venue_values, [$wheres]);
841
-
842
-        // get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
843
-        $get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
844
-        $venue         = $this->_venue_model->get_one([$get_one_where]);
845
-
846
-        // notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
847
-        $venue_update_callbacks = apply_filters(
848
-            'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
849
-            []
850
-        );
851
-        $att_success            = true;
852
-        foreach ($venue_update_callbacks as $v_callback) {
853
-            // if ANY of these updates fail then we want the appropriate global error message
854
-            $att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
855
-                ? $att_success
856
-                : false;
857
-        }
858
-
859
-        // any errors?
860
-        if ($success && ! $att_success) {
861
-            EE_Error::add_error(
862
-                esc_html__(
863
-                    'Venue Details saved successfully but something went wrong with saving attachments.',
864
-                    'event_espresso'
865
-                ),
866
-                __FILE__,
867
-                __FUNCTION__,
868
-                __LINE__
869
-            );
870
-        } elseif ($success === false) {
871
-            EE_Error::add_error(
872
-                esc_html__('Venue Details did not save successfully.', 'event_espresso'),
873
-                __FILE__,
874
-                __FUNCTION__,
875
-                __LINE__
876
-            );
877
-        }
878
-    }
879
-
880
-
881
-    /**
882
-     * @param int $post_id
883
-     * @throws EE_Error
884
-     * @throws ReflectionException
885
-     */
886
-    public function trash_cpt_item($post_id)
887
-    {
888
-        $this->request->setRequestParam('VNU_ID', $post_id);
889
-        $this->_trash_or_restore_venue('trash', false);
890
-    }
891
-
892
-
893
-    /**
894
-     * @param int $post_id
895
-     * @throws EE_Error
896
-     * @throws ReflectionException
897
-     */
898
-    public function restore_cpt_item($post_id)
899
-    {
900
-        $this->request->setRequestParam('VNU_ID', $post_id);
901
-        $this->_trash_or_restore_venue('draft', false);
902
-    }
903
-
904
-
905
-    /**
906
-     * @param int $post_id
907
-     * @throws EE_Error
908
-     * @throws ReflectionException
909
-     */
910
-    public function delete_cpt_item($post_id)
911
-    {
912
-        $this->request->setRequestParam('VNU_ID', $post_id);
913
-        $this->_delete_venue(false);
914
-    }
915
-
916
-
917
-    public function get_venue_object()
918
-    {
919
-        return $this->_cpt_model_obj;
920
-    }
921
-
922
-
923
-    /**
924
-     * @throws EE_Error
925
-     * @throws ReflectionException
926
-     */
927
-    protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
928
-    {
929
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
930
-
931
-        // loop thru venues
932
-        if ($VNU_ID) {
933
-            // clean status
934
-            $venue_status = sanitize_key($venue_status);
935
-            // grab status
936
-            if (! empty($venue_status)) {
937
-                $success = $this->_change_venue_status($VNU_ID, $venue_status);
938
-            } else {
939
-                $success = false;
940
-                $msg     = esc_html__(
941
-                    'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
942
-                    'event_espresso'
943
-                );
944
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
945
-            }
946
-        } else {
947
-            $success = false;
948
-            $msg     = esc_html__(
949
-                'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
950
-                'event_espresso'
951
-            );
952
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
953
-        }
954
-        $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
955
-
956
-        if ($redirect_after) {
957
-            $this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
958
-        }
959
-    }
960
-
961
-
962
-    /**
963
-     * @throws EE_Error
964
-     * @throws ReflectionException
965
-     */
966
-    protected function _trash_or_restore_venues($venue_status = 'trash')
967
-    {
968
-        // clean status
969
-        $venue_status = sanitize_key($venue_status);
970
-        // grab status
971
-        if (! empty($venue_status)) {
972
-            $success = true;
973
-            // determine the event id and set to array.
974
-            $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
975
-            // loop thru events
976
-            foreach ($VNU_IDs as $VNU_ID) {
977
-                if ($VNU_ID = absint($VNU_ID)) {
978
-                    $results = $this->_change_venue_status($VNU_ID, $venue_status);
979
-                    $success = $results !== false ? $success : false;
980
-                } else {
981
-                    $msg = sprintf(
982
-                        esc_html__(
983
-                            'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
984
-                            'event_espresso'
985
-                        ),
986
-                        $VNU_ID
987
-                    );
988
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
989
-                    $success = false;
990
-                }
991
-            }
992
-        } else {
993
-            $success = false;
994
-            $msg     = esc_html__(
995
-                'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
996
-                'event_espresso'
997
-            );
998
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
-        }
1000
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1001
-        $success = $success ? 2 : false;
1002
-        $action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1003
-        $this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * _trash_or_restore_venues
1009
-     *
1010
-     * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1011
-     * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1012
-     * accepting a certain number of params.
1013
-     *
1014
-     * @access  private
1015
-     * @param int    $VNU_ID
1016
-     * @param string $venue_status
1017
-     * @return bool
1018
-     * @throws EE_Error
1019
-     * @throws ReflectionException
1020
-     */
1021
-    private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1022
-    {
1023
-        // grab venue id
1024
-        if (! $VNU_ID) {
1025
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1026
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1027
-            return false;
1028
-        }
1029
-
1030
-        $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1031
-
1032
-        // clean status
1033
-        $venue_status = sanitize_key($venue_status);
1034
-        // grab status
1035
-        if (! $venue_status) {
1036
-            $msg = esc_html__(
1037
-                'An error occurred. No Venue Status or an invalid Venue Status was received.',
1038
-                'event_espresso'
1039
-            );
1040
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
-            return false;
1042
-        }
1043
-
1044
-        // was event trashed or restored ?
1045
-        switch ($venue_status) {
1046
-            case 'draft':
1047
-                $action = 'restored from the trash';
1048
-                $hook   = 'AHEE_venue_restored_from_trash';
1049
-                break;
1050
-            case 'trash':
1051
-                $action = 'moved to the trash';
1052
-                $hook   = 'AHEE_venue_moved_to_trash';
1053
-                break;
1054
-            default:
1055
-                $action = 'updated';
1056
-                $hook   = false;
1057
-        }
1058
-        // use class to change status
1059
-        $this->_cpt_model_obj->set_status($venue_status);
1060
-        $success = $this->_cpt_model_obj->save();
1061
-
1062
-        if ($success === false) {
1063
-            $msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1064
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1065
-            return false;
1066
-        }
1067
-        if ($hook) {
1068
-            do_action($hook);
1069
-        }
1070
-        return true;
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * @param bool $redirect_after
1076
-     * @return void
1077
-     * @throws EE_Error
1078
-     * @throws ReflectionException
1079
-     */
1080
-    protected function _delete_venue($redirect_after = true)
1081
-    {
1082
-        // determine the venue id and set to array.
1083
-        $VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1084
-        $VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1085
-
1086
-        // loop thru venues
1087
-        if ($VNU_ID) {
1088
-            $success = $this->_delete_or_trash_venue($VNU_ID);
1089
-        } else {
1090
-            $success = false;
1091
-            $msg     = esc_html__(
1092
-                'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1093
-                'event_espresso'
1094
-            );
1095
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1096
-        }
1097
-        if ($redirect_after) {
1098
-            $this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1099
-        }
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * @throws EE_Error
1105
-     * @throws ReflectionException
1106
-     */
1107
-    protected function _delete_venues()
1108
-    {
1109
-        $success = true;
1110
-        // determine the event id and set to array.
1111
-        $VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1112
-        // loop thru events
1113
-        foreach ($VNU_IDs as $VNU_ID) {
1114
-            if ($VNU_ID = absint($VNU_ID)) {
1115
-                $results = $this->_delete_or_trash_venue($VNU_ID);
1116
-                $success = $results !== false ? $success : false;
1117
-            } else {
1118
-                $success = false;
1119
-                $msg     = esc_html__(
1120
-                    'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1121
-                    'event_espresso'
1122
-                );
1123
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1124
-            }
1125
-        }
1126
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1127
-        $success = $success ? 2 : false;
1128
-        $this->_redirect_after_action(
1129
-            $success,
1130
-            esc_html__('Venues', 'event_espresso'),
1131
-            esc_html__('deleted', 'event_espresso'),
1132
-            ['action' => 'default']
1133
-        );
1134
-    }
1135
-
1136
-
1137
-    // todo: put in parent
1138
-
1139
-
1140
-    /**
1141
-     * @throws EE_Error
1142
-     * @throws ReflectionException
1143
-     */
1144
-    private function _delete_or_trash_venue($VNU_ID = false)
1145
-    {
1146
-        // grab event id
1147
-        if (! $VNU_ID = absint($VNU_ID)) {
1148
-            $msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1149
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1150
-            return false;
1151
-        }
1152
-
1153
-
1154
-        $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1155
-        // first need to remove all term relationships
1156
-        $venue->_remove_relations('Term_Taxonomy');
1157
-        $success = $venue->delete_permanently();
1158
-        // did it all go as planned ?
1159
-        if ($success) {
1160
-            $msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1161
-            EE_Error::add_success($msg);
1162
-        } else {
1163
-            $msg =
1164
-                sprintf(
1165
-                    esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1166
-                    $VNU_ID
1167
-                );
1168
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1169
-            return false;
1170
-        }
1171
-        do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1172
-        return true;
1173
-    }
1174
-
1175
-
1176
-
1177
-
1178
-    /***********/
1179
-    /* QUERIES */
1180
-
1181
-
1182
-    public function get_venues($per_page = 10, $count = false)
1183
-    {
1184
-
1185
-        $orderby = $this->request->getRequestParam('orderby', '');
1186
-
1187
-        switch ($orderby) {
1188
-            case 'id':
1189
-                $orderby = 'VNU_ID';
1190
-                break;
1191
-
1192
-            case 'capacity':
1193
-                $orderby = 'VNU_capacity';
1194
-                break;
1195
-
1196
-            case 'city':
1197
-                $orderby = 'VNU_city';
1198
-                break;
1199
-
1200
-            default:
1201
-                $orderby = 'VNU_name';
1202
-        }
1203
-
1204
-        $sort         = $this->request->getRequestParam('order', 'ASC');
1205
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1206
-        $per_page     = ! empty($per_page) ? $per_page : 10;
1207
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1208
-
1209
-        $offset = ($current_page - 1) * $per_page;
1210
-        $limit  = [$offset, $per_page];
1211
-
1212
-        $category = $this->request->getRequestParam('category');
1213
-        $category = $category > 0 ? $category : null;
1214
-
1215
-        $where = [];
1216
-
1217
-        // only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1218
-        $status = $this->request->getRequestParam('status');
1219
-        if ($status && $status !== 'all') {
1220
-            $where['status'] = $status;
1221
-        }
1222
-
1223
-        $venue_status = $this->request->getRequestParam('venue_status');
1224
-        if ($venue_status) {
1225
-            $where['status'] = $venue_status;
1226
-        }
1227
-
1228
-
1229
-        if ($category) {
1230
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1231
-            $where['Term_Taxonomy.term_id']  = $category;
1232
-        }
1233
-
1234
-
1235
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1236
-            $where['VNU_wp_user'] = get_current_user_id();
1237
-        } else {
1238
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1239
-                $where['OR'] = [
1240
-                    'status*restrict_private' => ['!=', 'private'],
1241
-                    'AND'                     => [
1242
-                        'status*inclusive' => ['=', 'private'],
1243
-                        'VNU_wp_user'      => get_current_user_id(),
1244
-                    ],
1245
-                ];
1246
-            }
1247
-        }
1248
-
1249
-        $search_term = $this->request->getRequestParam('s');
1250
-        if ($search_term) {
1251
-            $search_term = '%' . $search_term . '%';
1252
-            $where['OR'] = [
1253
-                'VNU_name'               => ['LIKE', $search_term],
1254
-                'VNU_desc'               => ['LIKE', $search_term],
1255
-                'VNU_short_desc'         => ['LIKE', $search_term],
1256
-                'VNU_address'            => ['LIKE', $search_term],
1257
-                'VNU_address2'           => ['LIKE', $search_term],
1258
-                'VNU_city'               => ['LIKE', $search_term],
1259
-                'VNU_zip'                => ['LIKE', $search_term],
1260
-                'VNU_phone'              => ['LIKE', $search_term],
1261
-                'VNU_url'                => ['LIKE', $search_term],
1262
-                'VNU_virtual_phone'      => ['LIKE', $search_term],
1263
-                'VNU_virtual_url'        => ['LIKE', $search_term],
1264
-                'VNU_google_map_link'    => ['LIKE', $search_term],
1265
-                'Event.EVT_name'         => ['LIKE', $search_term],
1266
-                'Event.EVT_desc'         => ['LIKE', $search_term],
1267
-                'Event.EVT_phone'        => ['LIKE', $search_term],
1268
-                'Event.EVT_external_URL' => ['LIKE', $search_term],
1269
-            ];
1270
-        }
1271
-
1272
-
1273
-        return $count
1274
-            ? $this->_venue_model->count([$where], 'VNU_ID')
1275
-            : $this->_venue_model->get_all(
1276
-                [$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1277
-            );
1278
-    }
1279
-
1280
-
1281
-
1282
-
1283
-    /** Venue Category Stuff **/
1284
-
1285
-    /**
1286
-     * set the _category property with the category object for the loaded page.
1287
-     *
1288
-     * @access private
1289
-     * @return void
1290
-     */
1291
-    private function _set_category_object()
1292
-    {
1293
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
1294
-            return;
1295
-        } // already have the category object so get out.
1296
-
1297
-        // set default category object
1298
-        $this->_set_empty_category_object();
1299
-
1300
-        // only set if we've got an id
1301
-        $category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1302
-        if (! $category_ID) {
1303
-            return;
1304
-        }
1305
-
1306
-        $term = get_term($category_ID, 'espresso_venue_categories');
1307
-
1308
-
1309
-        if (! empty($term)) {
1310
-            $this->_category->category_name       = $term->name;
1311
-            $this->_category->category_identifier = $term->slug;
1312
-            $this->_category->category_desc       = $term->description;
1313
-            $this->_category->id                  = $term->term_id;
1314
-            $this->_category->parent              = $term->parent;
1315
-        }
1316
-    }
1317
-
1318
-
1319
-    private function _set_empty_category_object()
1320
-    {
1321
-        $this->_category                = new stdClass();
1322
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1323
-        $this->_category->id            = $this->_category->parent = 0;
1324
-    }
1325
-
1326
-
1327
-    /**
1328
-     * @throws EE_Error
1329
-     */
1330
-    protected function _category_list_table()
1331
-    {
1332
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1334
-            'add_category',
1335
-            'add_category',
1336
-            [],
1337
-            'add-new-h2'
1338
-        );
1339
-        $this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1340
-        $this->display_admin_list_table_page_with_sidebar();
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * @throws EE_Error
1346
-     */
1347
-    protected function _category_details($view)
1348
-    {
1349
-
1350
-        // load formatter helper
1351
-        // load field generator helper
1352
-
1353
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
1354
-        $this->_set_add_edit_form_tags($route);
1355
-
1356
-        $this->_set_category_object();
1357
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
1358
-
1359
-        $delete_action = 'delete_category';
1360
-
1361
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1362
-
1363
-        $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1364
-
1365
-        // take care of contents
1366
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
1367
-        $this->display_admin_page_with_sidebar();
1368
-    }
1369
-
1370
-
1371
-    protected function _category_details_content()
1372
-    {
1373
-        $editor_args['category_desc'] = [
1374
-            'type'          => 'wp_editor',
1375
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1376
-            'class'         => 'my_editor_custom',
1377
-            'wpeditor_args' => ['media_buttons' => false],
1378
-        ];
1379
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1380
-
1381
-        $all_terms = get_terms(
1382
-            ['espresso_venue_categories'],
1383
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1384
-        );
1385
-
1386
-        // setup category select for term parents.
1387
-        $category_select_values[] = [
1388
-            'text' => esc_html__('No Parent', 'event_espresso'),
1389
-            'id'   => 0,
1390
-        ];
1391
-        foreach ($all_terms as $term) {
1392
-            $category_select_values[] = [
1393
-                'text' => $term->name,
1394
-                'id'   => $term->term_id,
1395
-            ];
1396
-        }
1397
-
1398
-        $category_select = EEH_Form_Fields::select_input(
1399
-            'category_parent',
1400
-            $category_select_values,
1401
-            $this->_category->parent
1402
-        );
1403
-        $template_args   = [
1404
-            'category'                 => $this->_category,
1405
-            'category_select'          => $category_select,
1406
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1407
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1408
-            'disable'                  => '',
1409
-            'disabled_message'         => false,
1410
-        ];
1411
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1412
-        return EEH_Template::display_template($template, $template_args, true);
1413
-    }
1414
-
1415
-
1416
-    /**
1417
-     * @throws EE_Error
1418
-     */
1419
-    protected function _delete_categories()
1420
-    {
1421
-        $category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1422
-        $category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1423
-
1424
-        foreach ($category_IDs as $cat_id) {
1425
-            $this->_delete_category($cat_id);
1426
-        }
1427
-
1428
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
1429
-        $query_args = [
1430
-            'action' => 'category_list',
1431
-        ];
1432
-        $this->_redirect_after_action(0, '', '', $query_args);
1433
-    }
1434
-
1435
-
1436
-    protected function _delete_category($cat_id)
1437
-    {
1438
-        $cat_id = absint($cat_id);
1439
-        wp_delete_term($cat_id, 'espresso_venue_categories');
1440
-    }
1441
-
1442
-
1443
-    /**
1444
-     * @throws EE_Error
1445
-     */
1446
-    protected function _insert_or_update_category($new_category)
1447
-    {
1448
-
1449
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1450
-        $success = 0; // we already have a success message so lets not send another.
1451
-        if ($cat_id) {
1452
-            $query_args = [
1453
-                'action'     => 'edit_category',
1454
-                'VEN_CAT_ID' => $cat_id,
1455
-            ];
1456
-        } else {
1457
-            $query_args = ['action' => 'add_category'];
1458
-        }
1459
-        $this->_redirect_after_action($success, '', '', $query_args, true);
1460
-    }
1461
-
1462
-
1463
-    private function _insert_category($update = false)
1464
-    {
1465
-        $category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1466
-        $category_name   = $this->request->getRequestParam('category_name', '');
1467
-        $category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1468
-        $category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1469
-
1470
-        if (empty($category_name)) {
1471
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
1472
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1473
-            return false;
1474
-        }
1475
-
1476
-
1477
-        $term_args = [
1478
-            'name'        => $category_name,
1479
-            'description' => $category_desc,
1480
-            'parent'      => $category_parent,
1481
-        ];
1482
-
1483
-        $insert_ids = $update
1484
-            ? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1485
-            : wp_insert_term(
1486
-                $category_name,
1487
-                'espresso_venue_categories',
1488
-                $term_args
1489
-            );
1490
-
1491
-        if (! is_array($insert_ids)) {
1492
-            EE_Error::add_error(
1493
-                esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1494
-                __FILE__,
1495
-                __FUNCTION__,
1496
-                __LINE__
1497
-            );
1498
-        } else {
1499
-            $category_ID = $insert_ids['term_id'];
1500
-            EE_Error::add_success(
1501
-                sprintf(
1502
-                    esc_html__('The category %s was successfully created', 'event_espresso'),
1503
-                    $category_name
1504
-                )
1505
-            );
1506
-        }
1507
-
1508
-        return $category_ID;
1509
-    }
1510
-
1511
-
1512
-    /**
1513
-     * TODO handle category exports()
1514
-     *
1515
-     * @return void
1516
-     */
1517
-    protected function _categories_export()
1518
-    {
1519
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
1520
-        $this->request->mergeRequestParams(
1521
-            [
1522
-                'export'       => 'report',
1523
-                'action'       => 'categories',
1524
-                'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1525
-            ]
1526
-        );
1527
-
1528
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1529
-            require_once(EE_CLASSES . 'EE_Export.class.php');
1530
-            $EE_Export = EE_Export::instance($this->request->requestParams());
1531
-            $EE_Export->export();
1532
-        }
1533
-    }
1534
-
1535
-
1536
-    protected function _import_categories()
1537
-    {
1538
-
1539
-        require_once(EE_CLASSES . 'EE_Import.class.php');
1540
-        EE_Import::instance()->import();
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * @throws EE_Error
1546
-     */
1547
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
1548
-    {
1549
-
1550
-        // testing term stuff
1551
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1552
-        $order       = $this->request->getRequestParam('order', 'DESC');
1553
-        $limit       = ($current_page - 1) * $per_page;
1554
-        $where       = ['taxonomy' => 'espresso_venue_categories'];
1555
-        $search_term = $this->request->getRequestParam('s');
1556
-        if ($search_term) {
1557
-            $search_term = '%' . $search_term . '%';
1558
-            $where['OR'] = [
1559
-                'Term.name'   => ['LIKE', $search_term],
1560
-                'description' => ['LIKE', $search_term],
1561
-            ];
1562
-        }
1563
-
1564
-        $query_params = [
1565
-            $where,
1566
-            'order_by'   => [$orderby => $order],
1567
-            'limit'      => $limit . ',' . $per_page,
1568
-            'force_join' => ['Term'],
1569
-        ];
1570
-
1571
-        return $count
1572
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1573
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
1574
-    }
1575
-
1576
-
1577
-    /* end category stuff */
1578
-    /**************/
577
+	protected function _google_map_settings()
578
+	{
579
+
580
+
581
+		$this->_template_args['values']           = $this->_yes_no_values;
582
+		$default_map_settings                     = new stdClass();
583
+		$default_map_settings->use_google_maps    = true;
584
+		$default_map_settings->google_map_api_key = '';
585
+		// for event details pages (reg page)
586
+		$default_map_settings->event_details_map_width    = 585;
587
+		// ee_map_width_single
588
+		$default_map_settings->event_details_map_height   = 362;
589
+		// ee_map_height_single
590
+		$default_map_settings->event_details_map_zoom     = 14;
591
+		// ee_map_zoom_single
592
+		$default_map_settings->event_details_display_nav  = true;
593
+		// ee_map_nav_display_single
594
+		$default_map_settings->event_details_nav_size     = false;
595
+		// ee_map_nav_size_single
596
+		$default_map_settings->event_details_control_type = 'default';
597
+		// ee_map_type_control_single
598
+		$default_map_settings->event_details_map_align    = 'center';
599
+		// ee_map_align_single
600
+
601
+		// for event list pages
602
+		$default_map_settings->event_list_map_width    = 300;
603
+		// ee_map_width
604
+		$default_map_settings->event_list_map_height   = 185;
605
+		// ee_map_height
606
+		$default_map_settings->event_list_map_zoom     = 12;
607
+		// ee_map_zoom
608
+		$default_map_settings->event_list_display_nav  = false;
609
+		// ee_map_nav_display
610
+		$default_map_settings->event_list_nav_size     = true;
611
+		// ee_map_nav_size
612
+		$default_map_settings->event_list_control_type = 'dropdown';
613
+		// ee_map_type_control
614
+		$default_map_settings->event_list_map_align    = 'center';
615
+		// ee_map_align
616
+
617
+		$this->_template_args['map_settings'] =
618
+			isset(EE_Registry::instance()->CFG->map_settings)
619
+			&& ! empty(EE_Registry::instance()->CFG->map_settings)
620
+				? (object) array_merge(
621
+					(array) $default_map_settings,
622
+					(array) EE_Registry::instance()->CFG->map_settings
623
+				)
624
+				: $default_map_settings;
625
+
626
+		$this->_set_add_edit_form_tags('update_google_map_settings');
627
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
628
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
629
+			EE_VENUES_TEMPLATE_PATH . 'google_map.template.php',
630
+			$this->_template_args,
631
+			true
632
+		);
633
+		$this->display_admin_page_with_sidebar();
634
+	}
635
+
636
+
637
+	/**
638
+	 * @throws EE_Error
639
+	 */
640
+	protected function _update_google_map_settings()
641
+	{
642
+		$map_settings = EE_Registry::instance()->CFG->map_settings;
643
+
644
+		$settings = [
645
+			'use_google_maps'            => 'int',
646
+			'google_map_api_key'         => 'string',
647
+			'event_details_map_width'    => 'int',
648
+			'event_details_map_zoom'     => 'int',
649
+			'event_details_display_nav'  => 'int',
650
+			'event_details_nav_size'     => 'int',
651
+			'event_details_control_type' => 'string',
652
+			'event_details_map_align'    => 'string',
653
+			'event_list_map_width'       => 'int',
654
+			'event_list_map_height'      => 'int',
655
+			'event_list_map_zoom'        => 'int',
656
+			'event_list_display_nav'     => 'int',
657
+			'event_list_nav_size'        => 'int',
658
+			'event_list_control_type'    => 'string',
659
+			'event_list_map_align'       => 'string',
660
+		];
661
+
662
+		foreach ($settings as $setting => $type) {
663
+			$map_settings->{$setting} = $this->request->getRequestParam($setting, $map_settings->{$setting}, $type);
664
+		}
665
+
666
+		EE_Registry::instance()->CFG->map_settings = apply_filters(
667
+			'FHEE__Extend_General_Settings_Admin_Page___update_google_map_settings__CFG_map_settings',
668
+			$map_settings
669
+		);
670
+
671
+		$what    = 'Google Map Settings';
672
+		$success = $this->_update_espresso_configuration(
673
+			$what,
674
+			EE_Registry::instance()->CFG->map_settings,
675
+			__FILE__,
676
+			__FUNCTION__,
677
+			__LINE__
678
+		);
679
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'google_map_settings']);
680
+	}
681
+
682
+
683
+	/**
684
+	 * @throws EE_Error
685
+	 * @throws ReflectionException
686
+	 */
687
+	protected function _venue_editor_metaboxes()
688
+	{
689
+		$this->verify_cpt_object();
690
+
691
+		add_meta_box(
692
+			'espresso_venue_address_options',
693
+			esc_html__('Physical Location', 'event_espresso'),
694
+			[$this, 'venue_address_metabox'],
695
+			$this->page_slug,
696
+			'side'
697
+		);
698
+		add_meta_box(
699
+			'espresso_venue_gmap_options',
700
+			esc_html__('Google Map', 'event_espresso'),
701
+			[$this, 'venue_gmap_metabox'],
702
+			$this->page_slug,
703
+			'side'
704
+		);
705
+		add_meta_box(
706
+			'espresso_venue_virtual_loc_options',
707
+			esc_html__('Virtual Location', 'event_espresso'),
708
+			[$this, 'venue_virtual_loc_metabox'],
709
+			$this->page_slug,
710
+			'side'
711
+		);
712
+	}
713
+
714
+
715
+	public function venue_gmap_metabox()
716
+	{
717
+		$template_args = [
718
+			'vnu_enable_for_gmap' => EEH_Form_Fields::select_input(
719
+				'vnu_enable_for_gmap',
720
+				$this->get_yes_no_values(),
721
+				$this->_cpt_model_obj instanceof EE_Venue ? $this->_cpt_model_obj->enable_for_gmap() : false
722
+			),
723
+			'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(),
724
+		];
725
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php';
726
+		EEH_Template::display_template($template, $template_args);
727
+	}
728
+
729
+
730
+	/**
731
+	 * @throws EE_Error
732
+	 * @throws ReflectionException
733
+	 */
734
+	public function venue_address_metabox()
735
+	{
736
+		$template_args['_venue'] = $this->_cpt_model_obj;
737
+
738
+		$template_args['states_dropdown']    = EEH_Form_Fields::generate_form_input(
739
+			new EE_Question_Form_Input(
740
+				EE_Question::new_instance(
741
+					['QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state']
742
+				),
743
+				EE_Answer::new_instance(
744
+					[
745
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
746
+							? $this->_cpt_model_obj->state_ID()
747
+							: 0,
748
+					]
749
+				),
750
+				[
751
+					'input_name'     => 'sta_id',
752
+					'input_id'       => 'sta_id',
753
+					'input_class'    => '',
754
+					'input_prefix'   => '',
755
+					'append_qstn_id' => false,
756
+				]
757
+			)
758
+		);
759
+		$template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input(
760
+			new EE_Question_Form_Input(
761
+				EE_Question::new_instance(
762
+					['QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country']
763
+				),
764
+				EE_Answer::new_instance(
765
+					[
766
+						'ANS_value' => $this->_cpt_model_obj instanceof EE_Venue
767
+							? $this->_cpt_model_obj->country_ID()
768
+							: 0,
769
+					]
770
+				),
771
+				[
772
+					'input_name'     => 'cnt_iso',
773
+					'input_id'       => 'cnt_iso',
774
+					'input_class'    => '',
775
+					'input_prefix'   => '',
776
+					'append_qstn_id' => false,
777
+				]
778
+			)
779
+		);
780
+
781
+		$template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php';
782
+		EEH_Template::display_template($template, $template_args);
783
+	}
784
+
785
+
786
+	public function venue_virtual_loc_metabox()
787
+	{
788
+		$template_args = [
789
+			'_venue' => $this->_cpt_model_obj,
790
+		];
791
+		$template      = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php';
792
+		EEH_Template::display_template($template, $template_args);
793
+	}
794
+
795
+
796
+	protected function _restore_cpt_item($post_id, $revision_id)
797
+	{
798
+		$venue_obj = $this->_venue_model->get_one_by_ID($post_id);
799
+
800
+		// meta revision restore
801
+		$venue_obj->restore_revision($revision_id);
802
+	}
803
+
804
+
805
+	/**
806
+	 * Handles updates for venue cpts
807
+	 *
808
+	 * @param int    $post_id ID of Venue CPT
809
+	 * @param WP_Post $post    Post object (with "blessed" WP properties)
810
+	 * @return void
811
+	 */
812
+	protected function _insert_update_cpt_item($post_id, $post)
813
+	{
814
+
815
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') {
816
+			return;// get out we're not processing the saving of venues.
817
+		}
818
+
819
+		$wheres = [$this->_venue_model->primary_key_name() => $post_id];
820
+
821
+		$venue_values = [
822
+			'VNU_address'         => $this->request->getRequestParam('vnu_address'),
823
+			'VNU_address2'        => $this->request->getRequestParam('vnu_address2'),
824
+			'VNU_city'            => $this->request->getRequestParam('vnu_city'),
825
+			'STA_ID'              => $this->request->getRequestParam('sta_id'),
826
+			'CNT_ISO'             => $this->request->getRequestParam('cnt_iso'),
827
+			'VNU_zip'             => $this->request->getRequestParam('vnu_zip'),
828
+			'VNU_phone'           => $this->request->getRequestParam('vnu_phone'),
829
+			'VNU_capacity'        => $this->request->requestParamIsSet('vnu_capacity')
830
+				? str_replace(',', '', $this->request->getRequestParam('vnu_capacity'))
831
+				: EE_INF,
832
+			'VNU_url'             => $this->request->getRequestParam('vnu_url'),
833
+			'VNU_virtual_phone'   => $this->request->getRequestParam('vnu_virtual_phone'),
834
+			'VNU_virtual_url'     => $this->request->getRequestParam('vnu_virtual_url'),
835
+			'VNU_enable_for_gmap' => $this->request->getRequestParam('vnu_enable_for_gmap', false, 'bool'),
836
+			'VNU_google_map_link' => $this->request->getRequestParam('vnu_google_map_link'),
837
+		];
838
+
839
+		// update venue
840
+		$success = $this->_venue_model->update($venue_values, [$wheres]);
841
+
842
+		// get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
843
+		$get_one_where = [$this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status];
844
+		$venue         = $this->_venue_model->get_one([$get_one_where]);
845
+
846
+		// notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use.  So this is just here for addons to more easily hook into venue saves.
847
+		$venue_update_callbacks = apply_filters(
848
+			'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks',
849
+			[]
850
+		);
851
+		$att_success            = true;
852
+		foreach ($venue_update_callbacks as $v_callback) {
853
+			// if ANY of these updates fail then we want the appropriate global error message
854
+			$att_success = call_user_func_array($v_callback, [$venue, $this->request->requestParams()])
855
+				? $att_success
856
+				: false;
857
+		}
858
+
859
+		// any errors?
860
+		if ($success && ! $att_success) {
861
+			EE_Error::add_error(
862
+				esc_html__(
863
+					'Venue Details saved successfully but something went wrong with saving attachments.',
864
+					'event_espresso'
865
+				),
866
+				__FILE__,
867
+				__FUNCTION__,
868
+				__LINE__
869
+			);
870
+		} elseif ($success === false) {
871
+			EE_Error::add_error(
872
+				esc_html__('Venue Details did not save successfully.', 'event_espresso'),
873
+				__FILE__,
874
+				__FUNCTION__,
875
+				__LINE__
876
+			);
877
+		}
878
+	}
879
+
880
+
881
+	/**
882
+	 * @param int $post_id
883
+	 * @throws EE_Error
884
+	 * @throws ReflectionException
885
+	 */
886
+	public function trash_cpt_item($post_id)
887
+	{
888
+		$this->request->setRequestParam('VNU_ID', $post_id);
889
+		$this->_trash_or_restore_venue('trash', false);
890
+	}
891
+
892
+
893
+	/**
894
+	 * @param int $post_id
895
+	 * @throws EE_Error
896
+	 * @throws ReflectionException
897
+	 */
898
+	public function restore_cpt_item($post_id)
899
+	{
900
+		$this->request->setRequestParam('VNU_ID', $post_id);
901
+		$this->_trash_or_restore_venue('draft', false);
902
+	}
903
+
904
+
905
+	/**
906
+	 * @param int $post_id
907
+	 * @throws EE_Error
908
+	 * @throws ReflectionException
909
+	 */
910
+	public function delete_cpt_item($post_id)
911
+	{
912
+		$this->request->setRequestParam('VNU_ID', $post_id);
913
+		$this->_delete_venue(false);
914
+	}
915
+
916
+
917
+	public function get_venue_object()
918
+	{
919
+		return $this->_cpt_model_obj;
920
+	}
921
+
922
+
923
+	/**
924
+	 * @throws EE_Error
925
+	 * @throws ReflectionException
926
+	 */
927
+	protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = true)
928
+	{
929
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
930
+
931
+		// loop thru venues
932
+		if ($VNU_ID) {
933
+			// clean status
934
+			$venue_status = sanitize_key($venue_status);
935
+			// grab status
936
+			if (! empty($venue_status)) {
937
+				$success = $this->_change_venue_status($VNU_ID, $venue_status);
938
+			} else {
939
+				$success = false;
940
+				$msg     = esc_html__(
941
+					'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
942
+					'event_espresso'
943
+				);
944
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
945
+			}
946
+		} else {
947
+			$success = false;
948
+			$msg     = esc_html__(
949
+				'An error occurred. The venue could not be moved to the trash because a valid venue ID was not not supplied.',
950
+				'event_espresso'
951
+			);
952
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
953
+		}
954
+		$action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
955
+
956
+		if ($redirect_after) {
957
+			$this->_redirect_after_action($success, 'Venue', $action, ['action' => 'default']);
958
+		}
959
+	}
960
+
961
+
962
+	/**
963
+	 * @throws EE_Error
964
+	 * @throws ReflectionException
965
+	 */
966
+	protected function _trash_or_restore_venues($venue_status = 'trash')
967
+	{
968
+		// clean status
969
+		$venue_status = sanitize_key($venue_status);
970
+		// grab status
971
+		if (! empty($venue_status)) {
972
+			$success = true;
973
+			// determine the event id and set to array.
974
+			$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
975
+			// loop thru events
976
+			foreach ($VNU_IDs as $VNU_ID) {
977
+				if ($VNU_ID = absint($VNU_ID)) {
978
+					$results = $this->_change_venue_status($VNU_ID, $venue_status);
979
+					$success = $results !== false ? $success : false;
980
+				} else {
981
+					$msg = sprintf(
982
+						esc_html__(
983
+							'An error occurred. Venue #%d could not be moved to the trash because a valid venue ID was not not supplied.',
984
+							'event_espresso'
985
+						),
986
+						$VNU_ID
987
+					);
988
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
989
+					$success = false;
990
+				}
991
+			}
992
+		} else {
993
+			$success = false;
994
+			$msg     = esc_html__(
995
+				'An error occurred. The venue could not be moved to the trash because a valid venue status was not not supplied.',
996
+				'event_espresso'
997
+			);
998
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
+		}
1000
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1001
+		$success = $success ? 2 : false;
1002
+		$action  = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1003
+		$this->_redirect_after_action($success, 'Venues', $action, ['action' => 'default']);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * _trash_or_restore_venues
1009
+	 *
1010
+	 * //todo this is pretty much the same as the corresponding change_event_status method in Events_Admin_Page.  We
1011
+	 * should probably abstract this up to the EE_Admin_Page_CPT (or even EE_Admin_Page) and make this a common method
1012
+	 * accepting a certain number of params.
1013
+	 *
1014
+	 * @access  private
1015
+	 * @param int    $VNU_ID
1016
+	 * @param string $venue_status
1017
+	 * @return bool
1018
+	 * @throws EE_Error
1019
+	 * @throws ReflectionException
1020
+	 */
1021
+	private function _change_venue_status($VNU_ID = 0, $venue_status = '')
1022
+	{
1023
+		// grab venue id
1024
+		if (! $VNU_ID) {
1025
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1026
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1027
+			return false;
1028
+		}
1029
+
1030
+		$this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1031
+
1032
+		// clean status
1033
+		$venue_status = sanitize_key($venue_status);
1034
+		// grab status
1035
+		if (! $venue_status) {
1036
+			$msg = esc_html__(
1037
+				'An error occurred. No Venue Status or an invalid Venue Status was received.',
1038
+				'event_espresso'
1039
+			);
1040
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1041
+			return false;
1042
+		}
1043
+
1044
+		// was event trashed or restored ?
1045
+		switch ($venue_status) {
1046
+			case 'draft':
1047
+				$action = 'restored from the trash';
1048
+				$hook   = 'AHEE_venue_restored_from_trash';
1049
+				break;
1050
+			case 'trash':
1051
+				$action = 'moved to the trash';
1052
+				$hook   = 'AHEE_venue_moved_to_trash';
1053
+				break;
1054
+			default:
1055
+				$action = 'updated';
1056
+				$hook   = false;
1057
+		}
1058
+		// use class to change status
1059
+		$this->_cpt_model_obj->set_status($venue_status);
1060
+		$success = $this->_cpt_model_obj->save();
1061
+
1062
+		if ($success === false) {
1063
+			$msg = sprintf(esc_html__('An error occurred. The venue could not be %s.', 'event_espresso'), $action);
1064
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1065
+			return false;
1066
+		}
1067
+		if ($hook) {
1068
+			do_action($hook);
1069
+		}
1070
+		return true;
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * @param bool $redirect_after
1076
+	 * @return void
1077
+	 * @throws EE_Error
1078
+	 * @throws ReflectionException
1079
+	 */
1080
+	protected function _delete_venue($redirect_after = true)
1081
+	{
1082
+		// determine the venue id and set to array.
1083
+		$VNU_ID = $this->request->getRequestParam('VNU_ID', 0, 'int');
1084
+		$VNU_ID = $this->request->getRequestParam('post', $VNU_ID, 'int');
1085
+
1086
+		// loop thru venues
1087
+		if ($VNU_ID) {
1088
+			$success = $this->_delete_or_trash_venue($VNU_ID);
1089
+		} else {
1090
+			$success = false;
1091
+			$msg     = esc_html__(
1092
+				'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1093
+				'event_espresso'
1094
+			);
1095
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1096
+		}
1097
+		if ($redirect_after) {
1098
+			$this->_redirect_after_action($success, 'Venue', 'deleted', ['action' => 'default']);
1099
+		}
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * @throws EE_Error
1105
+	 * @throws ReflectionException
1106
+	 */
1107
+	protected function _delete_venues()
1108
+	{
1109
+		$success = true;
1110
+		// determine the event id and set to array.
1111
+		$VNU_IDs = $this->request->getRequestParam('venue_id', [], 'int', true);
1112
+		// loop thru events
1113
+		foreach ($VNU_IDs as $VNU_ID) {
1114
+			if ($VNU_ID = absint($VNU_ID)) {
1115
+				$results = $this->_delete_or_trash_venue($VNU_ID);
1116
+				$success = $results !== false ? $success : false;
1117
+			} else {
1118
+				$success = false;
1119
+				$msg     = esc_html__(
1120
+					'An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.',
1121
+					'event_espresso'
1122
+				);
1123
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1124
+			}
1125
+		}
1126
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1127
+		$success = $success ? 2 : false;
1128
+		$this->_redirect_after_action(
1129
+			$success,
1130
+			esc_html__('Venues', 'event_espresso'),
1131
+			esc_html__('deleted', 'event_espresso'),
1132
+			['action' => 'default']
1133
+		);
1134
+	}
1135
+
1136
+
1137
+	// todo: put in parent
1138
+
1139
+
1140
+	/**
1141
+	 * @throws EE_Error
1142
+	 * @throws ReflectionException
1143
+	 */
1144
+	private function _delete_or_trash_venue($VNU_ID = false)
1145
+	{
1146
+		// grab event id
1147
+		if (! $VNU_ID = absint($VNU_ID)) {
1148
+			$msg = esc_html__('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso');
1149
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1150
+			return false;
1151
+		}
1152
+
1153
+
1154
+		$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
1155
+		// first need to remove all term relationships
1156
+		$venue->_remove_relations('Term_Taxonomy');
1157
+		$success = $venue->delete_permanently();
1158
+		// did it all go as planned ?
1159
+		if ($success) {
1160
+			$msg = sprintf(esc_html__('Venue ID # %d has been deleted.', 'event_espresso'), $VNU_ID);
1161
+			EE_Error::add_success($msg);
1162
+		} else {
1163
+			$msg =
1164
+				sprintf(
1165
+					esc_html__('An error occurred. Venue ID # %d could not be deleted.', 'event_espresso'),
1166
+					$VNU_ID
1167
+				);
1168
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1169
+			return false;
1170
+		}
1171
+		do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted');
1172
+		return true;
1173
+	}
1174
+
1175
+
1176
+
1177
+
1178
+	/***********/
1179
+	/* QUERIES */
1180
+
1181
+
1182
+	public function get_venues($per_page = 10, $count = false)
1183
+	{
1184
+
1185
+		$orderby = $this->request->getRequestParam('orderby', '');
1186
+
1187
+		switch ($orderby) {
1188
+			case 'id':
1189
+				$orderby = 'VNU_ID';
1190
+				break;
1191
+
1192
+			case 'capacity':
1193
+				$orderby = 'VNU_capacity';
1194
+				break;
1195
+
1196
+			case 'city':
1197
+				$orderby = 'VNU_city';
1198
+				break;
1199
+
1200
+			default:
1201
+				$orderby = 'VNU_name';
1202
+		}
1203
+
1204
+		$sort         = $this->request->getRequestParam('order', 'ASC');
1205
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1206
+		$per_page     = ! empty($per_page) ? $per_page : 10;
1207
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1208
+
1209
+		$offset = ($current_page - 1) * $per_page;
1210
+		$limit  = [$offset, $per_page];
1211
+
1212
+		$category = $this->request->getRequestParam('category');
1213
+		$category = $category > 0 ? $category : null;
1214
+
1215
+		$where = [];
1216
+
1217
+		// only set initial status if it is in the incoming request.  Otherwise the "all" view display's all statuses.
1218
+		$status = $this->request->getRequestParam('status');
1219
+		if ($status && $status !== 'all') {
1220
+			$where['status'] = $status;
1221
+		}
1222
+
1223
+		$venue_status = $this->request->getRequestParam('venue_status');
1224
+		if ($venue_status) {
1225
+			$where['status'] = $venue_status;
1226
+		}
1227
+
1228
+
1229
+		if ($category) {
1230
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories';
1231
+			$where['Term_Taxonomy.term_id']  = $category;
1232
+		}
1233
+
1234
+
1235
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) {
1236
+			$where['VNU_wp_user'] = get_current_user_id();
1237
+		} else {
1238
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) {
1239
+				$where['OR'] = [
1240
+					'status*restrict_private' => ['!=', 'private'],
1241
+					'AND'                     => [
1242
+						'status*inclusive' => ['=', 'private'],
1243
+						'VNU_wp_user'      => get_current_user_id(),
1244
+					],
1245
+				];
1246
+			}
1247
+		}
1248
+
1249
+		$search_term = $this->request->getRequestParam('s');
1250
+		if ($search_term) {
1251
+			$search_term = '%' . $search_term . '%';
1252
+			$where['OR'] = [
1253
+				'VNU_name'               => ['LIKE', $search_term],
1254
+				'VNU_desc'               => ['LIKE', $search_term],
1255
+				'VNU_short_desc'         => ['LIKE', $search_term],
1256
+				'VNU_address'            => ['LIKE', $search_term],
1257
+				'VNU_address2'           => ['LIKE', $search_term],
1258
+				'VNU_city'               => ['LIKE', $search_term],
1259
+				'VNU_zip'                => ['LIKE', $search_term],
1260
+				'VNU_phone'              => ['LIKE', $search_term],
1261
+				'VNU_url'                => ['LIKE', $search_term],
1262
+				'VNU_virtual_phone'      => ['LIKE', $search_term],
1263
+				'VNU_virtual_url'        => ['LIKE', $search_term],
1264
+				'VNU_google_map_link'    => ['LIKE', $search_term],
1265
+				'Event.EVT_name'         => ['LIKE', $search_term],
1266
+				'Event.EVT_desc'         => ['LIKE', $search_term],
1267
+				'Event.EVT_phone'        => ['LIKE', $search_term],
1268
+				'Event.EVT_external_URL' => ['LIKE', $search_term],
1269
+			];
1270
+		}
1271
+
1272
+
1273
+		return $count
1274
+			? $this->_venue_model->count([$where], 'VNU_ID')
1275
+			: $this->_venue_model->get_all(
1276
+				[$where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort]
1277
+			);
1278
+	}
1279
+
1280
+
1281
+
1282
+
1283
+	/** Venue Category Stuff **/
1284
+
1285
+	/**
1286
+	 * set the _category property with the category object for the loaded page.
1287
+	 *
1288
+	 * @access private
1289
+	 * @return void
1290
+	 */
1291
+	private function _set_category_object()
1292
+	{
1293
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
1294
+			return;
1295
+		} // already have the category object so get out.
1296
+
1297
+		// set default category object
1298
+		$this->_set_empty_category_object();
1299
+
1300
+		// only set if we've got an id
1301
+		$category_ID = $this->request->getRequestParam('VEN_CAT_ID', 0, 'int');
1302
+		if (! $category_ID) {
1303
+			return;
1304
+		}
1305
+
1306
+		$term = get_term($category_ID, 'espresso_venue_categories');
1307
+
1308
+
1309
+		if (! empty($term)) {
1310
+			$this->_category->category_name       = $term->name;
1311
+			$this->_category->category_identifier = $term->slug;
1312
+			$this->_category->category_desc       = $term->description;
1313
+			$this->_category->id                  = $term->term_id;
1314
+			$this->_category->parent              = $term->parent;
1315
+		}
1316
+	}
1317
+
1318
+
1319
+	private function _set_empty_category_object()
1320
+	{
1321
+		$this->_category                = new stdClass();
1322
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
1323
+		$this->_category->id            = $this->_category->parent = 0;
1324
+	}
1325
+
1326
+
1327
+	/**
1328
+	 * @throws EE_Error
1329
+	 */
1330
+	protected function _category_list_table()
1331
+	{
1332
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1333
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1334
+			'add_category',
1335
+			'add_category',
1336
+			[],
1337
+			'add-new-h2'
1338
+		);
1339
+		$this->_search_btn_label = esc_html__('Venue Categories', 'event_espresso');
1340
+		$this->display_admin_list_table_page_with_sidebar();
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * @throws EE_Error
1346
+	 */
1347
+	protected function _category_details($view)
1348
+	{
1349
+
1350
+		// load formatter helper
1351
+		// load field generator helper
1352
+
1353
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
1354
+		$this->_set_add_edit_form_tags($route);
1355
+
1356
+		$this->_set_category_object();
1357
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
1358
+
1359
+		$delete_action = 'delete_category';
1360
+
1361
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(['action' => 'category_list'], $this->_admin_base_url);
1362
+
1363
+		$this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect);
1364
+
1365
+		// take care of contents
1366
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
1367
+		$this->display_admin_page_with_sidebar();
1368
+	}
1369
+
1370
+
1371
+	protected function _category_details_content()
1372
+	{
1373
+		$editor_args['category_desc'] = [
1374
+			'type'          => 'wp_editor',
1375
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
1376
+			'class'         => 'my_editor_custom',
1377
+			'wpeditor_args' => ['media_buttons' => false],
1378
+		];
1379
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
1380
+
1381
+		$all_terms = get_terms(
1382
+			['espresso_venue_categories'],
1383
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
1384
+		);
1385
+
1386
+		// setup category select for term parents.
1387
+		$category_select_values[] = [
1388
+			'text' => esc_html__('No Parent', 'event_espresso'),
1389
+			'id'   => 0,
1390
+		];
1391
+		foreach ($all_terms as $term) {
1392
+			$category_select_values[] = [
1393
+				'text' => $term->name,
1394
+				'id'   => $term->term_id,
1395
+			];
1396
+		}
1397
+
1398
+		$category_select = EEH_Form_Fields::select_input(
1399
+			'category_parent',
1400
+			$category_select_values,
1401
+			$this->_category->parent
1402
+		);
1403
+		$template_args   = [
1404
+			'category'                 => $this->_category,
1405
+			'category_select'          => $category_select,
1406
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
1407
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
1408
+			'disable'                  => '',
1409
+			'disabled_message'         => false,
1410
+		];
1411
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
1412
+		return EEH_Template::display_template($template, $template_args, true);
1413
+	}
1414
+
1415
+
1416
+	/**
1417
+	 * @throws EE_Error
1418
+	 */
1419
+	protected function _delete_categories()
1420
+	{
1421
+		$category_ID  = $this->request->getRequestParam('category_id', 0, 'int');
1422
+		$category_IDs = $this->request->getRequestParam('VEN_CAT_ID', [$category_ID], 'int', true);
1423
+
1424
+		foreach ($category_IDs as $cat_id) {
1425
+			$this->_delete_category($cat_id);
1426
+		}
1427
+
1428
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
1429
+		$query_args = [
1430
+			'action' => 'category_list',
1431
+		];
1432
+		$this->_redirect_after_action(0, '', '', $query_args);
1433
+	}
1434
+
1435
+
1436
+	protected function _delete_category($cat_id)
1437
+	{
1438
+		$cat_id = absint($cat_id);
1439
+		wp_delete_term($cat_id, 'espresso_venue_categories');
1440
+	}
1441
+
1442
+
1443
+	/**
1444
+	 * @throws EE_Error
1445
+	 */
1446
+	protected function _insert_or_update_category($new_category)
1447
+	{
1448
+
1449
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
1450
+		$success = 0; // we already have a success message so lets not send another.
1451
+		if ($cat_id) {
1452
+			$query_args = [
1453
+				'action'     => 'edit_category',
1454
+				'VEN_CAT_ID' => $cat_id,
1455
+			];
1456
+		} else {
1457
+			$query_args = ['action' => 'add_category'];
1458
+		}
1459
+		$this->_redirect_after_action($success, '', '', $query_args, true);
1460
+	}
1461
+
1462
+
1463
+	private function _insert_category($update = false)
1464
+	{
1465
+		$category_ID     = $update ? $this->request->getRequestParam('VEN_CAT_ID', '', 'int') : '';
1466
+		$category_name   = $this->request->getRequestParam('category_name', '');
1467
+		$category_desc   = $this->request->getRequestParam('category_desc', '', 'html');
1468
+		$category_parent = $this->request->getRequestParam('category_parent', 0, 'int');
1469
+
1470
+		if (empty($category_name)) {
1471
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
1472
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1473
+			return false;
1474
+		}
1475
+
1476
+
1477
+		$term_args = [
1478
+			'name'        => $category_name,
1479
+			'description' => $category_desc,
1480
+			'parent'      => $category_parent,
1481
+		];
1482
+
1483
+		$insert_ids = $update
1484
+			? wp_update_term($category_ID, 'espresso_venue_categories', $term_args)
1485
+			: wp_insert_term(
1486
+				$category_name,
1487
+				'espresso_venue_categories',
1488
+				$term_args
1489
+			);
1490
+
1491
+		if (! is_array($insert_ids)) {
1492
+			EE_Error::add_error(
1493
+				esc_html__('An error occurred and the category has not been saved to the database.', 'event_espresso'),
1494
+				__FILE__,
1495
+				__FUNCTION__,
1496
+				__LINE__
1497
+			);
1498
+		} else {
1499
+			$category_ID = $insert_ids['term_id'];
1500
+			EE_Error::add_success(
1501
+				sprintf(
1502
+					esc_html__('The category %s was successfully created', 'event_espresso'),
1503
+					$category_name
1504
+				)
1505
+			);
1506
+		}
1507
+
1508
+		return $category_ID;
1509
+	}
1510
+
1511
+
1512
+	/**
1513
+	 * TODO handle category exports()
1514
+	 *
1515
+	 * @return void
1516
+	 */
1517
+	protected function _categories_export()
1518
+	{
1519
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
1520
+		$this->request->mergeRequestParams(
1521
+			[
1522
+				'export'       => 'report',
1523
+				'action'       => 'categories',
1524
+				'category_ids' => $this->request->getRequestParam('VEN_CAT_ID', 0, 'int'),
1525
+			]
1526
+		);
1527
+
1528
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
1529
+			require_once(EE_CLASSES . 'EE_Export.class.php');
1530
+			$EE_Export = EE_Export::instance($this->request->requestParams());
1531
+			$EE_Export->export();
1532
+		}
1533
+	}
1534
+
1535
+
1536
+	protected function _import_categories()
1537
+	{
1538
+
1539
+		require_once(EE_CLASSES . 'EE_Import.class.php');
1540
+		EE_Import::instance()->import();
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * @throws EE_Error
1546
+	 */
1547
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
1548
+	{
1549
+
1550
+		// testing term stuff
1551
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
1552
+		$order       = $this->request->getRequestParam('order', 'DESC');
1553
+		$limit       = ($current_page - 1) * $per_page;
1554
+		$where       = ['taxonomy' => 'espresso_venue_categories'];
1555
+		$search_term = $this->request->getRequestParam('s');
1556
+		if ($search_term) {
1557
+			$search_term = '%' . $search_term . '%';
1558
+			$where['OR'] = [
1559
+				'Term.name'   => ['LIKE', $search_term],
1560
+				'description' => ['LIKE', $search_term],
1561
+			];
1562
+		}
1563
+
1564
+		$query_params = [
1565
+			$where,
1566
+			'order_by'   => [$orderby => $order],
1567
+			'limit'      => $limit . ',' . $per_page,
1568
+			'force_join' => ['Term'],
1569
+		];
1570
+
1571
+		return $count
1572
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
1573
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
1574
+	}
1575
+
1576
+
1577
+	/* end category stuff */
1578
+	/**************/
1579 1579
 }
Please login to merge, or discard this patch.
admin_pages/events/templates/event_tickets_metabox_ticket_row.template.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,12 +84,15 @@  discard block
 block discarded – undo
84 84
                    name="edit_prices[<?php echo esc_attr($ticketrow); ?>][1][PRC_amount]"
85 85
                    value="<?php echo esc_attr($PRC_amount); ?>"
86 86
             />
87
-        <?php else : ?>
87
+        <?php else {
88
+	: ?>
88 89
             <input type="text"
89 90
                    size="1"
90 91
                    class="edit-price-PRC_amount ee-small-text-inp ee-inp-right"
91 92
                    name="disabled_price_amount"
92
-                   value="<?php echo esc_attr($PRC_amount); ?>"
93
+                   value="<?php echo esc_attr($PRC_amount);
94
+}
95
+?>"
93 96
                 <?php echo esc_attr($disabled); ?>
94 97
             />
95 98
             <input type="hidden"
@@ -123,11 +126,14 @@  discard block
 block discarded – undo
123 126
                    name="<?php echo esc_attr("{$edit_ticketrow_name}[{$ticketrow}][TKT_qty]"); ?>"
124 127
                    value="<?php echo absint($TKT_qty); ?>"
125 128
             />
126
-        <?php else : ?>
129
+        <?php else {
130
+	: ?>
127 131
             <input type="text"
128 132
                    class="edit-ticket-TKT_qty ee-small-text-inp ee-inp-right"
129 133
                    name="disabled_tkt_qty"
130
-                   value="<?php echo absint($TKT_qty); ?>"
134
+                   value="<?php echo absint($TKT_qty);
135
+}
136
+?>"
131 137
                 <?php echo esc_attr($disabled); ?>
132 138
             />
133 139
             <input type="hidden"
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 1 patch
Indentation   +1470 added lines, -1470 removed lines patch added patch discarded remove patch
@@ -28,481 +28,481 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * This gets set in _setup_cpt
33
-     * It will contain the object for the custom post type.
34
-     *
35
-     * @var EE_CPT_Base
36
-     */
37
-    protected $_cpt_object;
38
-
39
-
40
-    /**
41
-     * a boolean flag to set whether the current route is a cpt route or not.
42
-     *
43
-     * @var bool
44
-     */
45
-    protected $_cpt_route = false;
46
-
47
-
48
-    /**
49
-     * This property allows cpt classes to define multiple routes as cpt routes.
50
-     * //in this array we define what the custom post type for this route is.
51
-     * array(
52
-     * 'route_name' => 'custom_post_type_slug'
53
-     * )
54
-     *
55
-     * @var array
56
-     */
57
-    protected $_cpt_routes = [];
58
-
59
-
60
-    /**
61
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
-     * in this format:
63
-     * array(
64
-     * 'post_type_slug' => 'edit_route'
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    protected $_cpt_edit_routes = [];
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = [];
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-    /**
90
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
91
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
92
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
93
-     * Registration of containers should be done before load_page_dependencies() is run.
94
-     *
95
-     * @var array()
96
-     */
97
-    protected $_autosave_containers = [];
98
-
99
-    protected $_autosave_fields     = [];
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @abstract
119
-     * @param string      $post_id The ID of the cpt that was saved (so you can link relationally)
120
-     * @param WP_Post     $post    The post object of the cpt that was saved.
121
-     * @return void
122
-     */
123
-    abstract protected function _insert_update_cpt_item($post_id, $post);
124
-
125
-
126
-    /**
127
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
128
-     *
129
-     * @abstract
130
-     * @param string $post_id The ID of the cpt that was trashed
131
-     * @return void
132
-     */
133
-    abstract public function trash_cpt_item($post_id);
134
-
135
-
136
-    /**
137
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
138
-     *
139
-     * @param string $post_id theID of the cpt that was untrashed
140
-     * @return void
141
-     */
142
-    abstract public function restore_cpt_item($post_id);
143
-
144
-
145
-    /**
146
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
147
-     * from the db
148
-     *
149
-     * @param string $post_id the ID of the cpt that was deleted
150
-     * @return void
151
-     */
152
-    abstract public function delete_cpt_item($post_id);
153
-
154
-
155
-    /**
156
-     * @return LoaderInterface
157
-     * @throws InvalidArgumentException
158
-     * @throws InvalidDataTypeException
159
-     * @throws InvalidInterfaceException
160
-     */
161
-    protected function getLoader()
162
-    {
163
-        if (! $this->loader instanceof LoaderInterface) {
164
-            $this->loader = LoaderFactory::getLoader();
165
-        }
166
-        return $this->loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
172
-     *
173
-     * @return void
174
-     */
175
-    protected function _before_page_setup()
176
-    {
177
-        $this->raw_req_action = $this->request->getRequestParam('action');
178
-        $this->raw_req_page = $this->request->getRequestParam('page');
179
-        $this->_cpt_routes = array_merge(
180
-            [
181
-                'create_new' => $this->page_slug,
182
-                'edit'       => $this->page_slug,
183
-                'trash'      => $this->page_slug,
184
-            ],
185
-            $this->_cpt_routes
186
-        );
187
-        $cpt_route_action  = isset($this->_cpt_routes[ $this->raw_req_action ])
188
-            ? $this->_cpt_routes[ $this->raw_req_action ]
189
-            : null;
190
-        // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page
191
-        $page              = $this->raw_req_page ?: $this->page_slug;
192
-        $page              = $cpt_route_action ?: $page;
193
-        $this->_cpt_object = get_post_type_object($page);
194
-        // tweak pagenow for page loading.
195
-        if (! $this->_pagenow_map) {
196
-            $this->_pagenow_map = [
197
-                'create_new' => 'post-new.php',
198
-                'edit'       => 'post.php',
199
-                'trash'      => 'post.php',
200
-            ];
201
-        }
202
-        add_action('current_screen', [$this, 'modify_pagenow']);
203
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
204
-        // get current page from autosave
205
-        $current_page        = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]');
206
-        $this->_current_page = $this->request->getRequestParam('current_page', $current_page);
207
-    }
208
-
209
-
210
-    /**
211
-     * Simply ensure that we simulate the correct post route for cpt screens
212
-     *
213
-     * @param WP_Screen $current_screen
214
-     * @return void
215
-     */
216
-    public function modify_pagenow($current_screen)
217
-    {
218
-        // possibly reset pagenow.
219
-        if (
220
-            $this->page_slug === $this->raw_req_page
221
-            && isset($this->_pagenow_map[ $this->raw_req_action ])
222
-        ) {
223
-            global $pagenow, $hook_suffix;
224
-            $pagenow     = $this->_pagenow_map[ $this->raw_req_action ];
225
-            $hook_suffix = $pagenow;
226
-        }
227
-    }
228
-
229
-
230
-    /**
231
-     * This method is used to register additional autosave containers to the _autosave_containers property.
232
-     *
233
-     * @param array $ids  an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
234
-     *                    you would send along the id of a metabox container.
235
-     * @return void
236
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
237
-     *                    automatically register the id for the post metabox as a container.
238
-     */
239
-    protected function _register_autosave_containers($ids)
240
-    {
241
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
242
-    }
243
-
244
-
245
-    /**
246
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
247
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
248
-     */
249
-    protected function _set_autosave_containers()
250
-    {
251
-        global $wp_meta_boxes;
252
-        $containers = [];
253
-        if (empty($wp_meta_boxes)) {
254
-            return;
255
-        }
256
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : [];
257
-        foreach ($current_metaboxes as $box_context) {
258
-            foreach ($box_context as $box_details) {
259
-                foreach ($box_details as $box) {
260
-                    if (
261
-                        is_array($box) && is_array($box['callback'])
262
-                        && (
263
-                            $box['callback'][0] instanceof EE_Admin_Page
264
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
265
-                        )
266
-                    ) {
267
-                        $containers[] = $box['id'];
268
-                    }
269
-                }
270
-            }
271
-        }
272
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
273
-        // add hidden inputs container
274
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
275
-    }
276
-
277
-
278
-    protected function _load_autosave_scripts_styles()
279
-    {
280
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
31
+	/**
32
+	 * This gets set in _setup_cpt
33
+	 * It will contain the object for the custom post type.
34
+	 *
35
+	 * @var EE_CPT_Base
36
+	 */
37
+	protected $_cpt_object;
38
+
39
+
40
+	/**
41
+	 * a boolean flag to set whether the current route is a cpt route or not.
42
+	 *
43
+	 * @var bool
44
+	 */
45
+	protected $_cpt_route = false;
46
+
47
+
48
+	/**
49
+	 * This property allows cpt classes to define multiple routes as cpt routes.
50
+	 * //in this array we define what the custom post type for this route is.
51
+	 * array(
52
+	 * 'route_name' => 'custom_post_type_slug'
53
+	 * )
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected $_cpt_routes = [];
58
+
59
+
60
+	/**
61
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
62
+	 * in this format:
63
+	 * array(
64
+	 * 'post_type_slug' => 'edit_route'
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	protected $_cpt_edit_routes = [];
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = [];
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+	/**
90
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
91
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
92
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
93
+	 * Registration of containers should be done before load_page_dependencies() is run.
94
+	 *
95
+	 * @var array()
96
+	 */
97
+	protected $_autosave_containers = [];
98
+
99
+	protected $_autosave_fields     = [];
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @abstract
119
+	 * @param string      $post_id The ID of the cpt that was saved (so you can link relationally)
120
+	 * @param WP_Post     $post    The post object of the cpt that was saved.
121
+	 * @return void
122
+	 */
123
+	abstract protected function _insert_update_cpt_item($post_id, $post);
124
+
125
+
126
+	/**
127
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
128
+	 *
129
+	 * @abstract
130
+	 * @param string $post_id The ID of the cpt that was trashed
131
+	 * @return void
132
+	 */
133
+	abstract public function trash_cpt_item($post_id);
134
+
135
+
136
+	/**
137
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
138
+	 *
139
+	 * @param string $post_id theID of the cpt that was untrashed
140
+	 * @return void
141
+	 */
142
+	abstract public function restore_cpt_item($post_id);
143
+
144
+
145
+	/**
146
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
147
+	 * from the db
148
+	 *
149
+	 * @param string $post_id the ID of the cpt that was deleted
150
+	 * @return void
151
+	 */
152
+	abstract public function delete_cpt_item($post_id);
153
+
154
+
155
+	/**
156
+	 * @return LoaderInterface
157
+	 * @throws InvalidArgumentException
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws InvalidInterfaceException
160
+	 */
161
+	protected function getLoader()
162
+	{
163
+		if (! $this->loader instanceof LoaderInterface) {
164
+			$this->loader = LoaderFactory::getLoader();
165
+		}
166
+		return $this->loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
172
+	 *
173
+	 * @return void
174
+	 */
175
+	protected function _before_page_setup()
176
+	{
177
+		$this->raw_req_action = $this->request->getRequestParam('action');
178
+		$this->raw_req_page = $this->request->getRequestParam('page');
179
+		$this->_cpt_routes = array_merge(
180
+			[
181
+				'create_new' => $this->page_slug,
182
+				'edit'       => $this->page_slug,
183
+				'trash'      => $this->page_slug,
184
+			],
185
+			$this->_cpt_routes
186
+		);
187
+		$cpt_route_action  = isset($this->_cpt_routes[ $this->raw_req_action ])
188
+			? $this->_cpt_routes[ $this->raw_req_action ]
189
+			: null;
190
+		// let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page
191
+		$page              = $this->raw_req_page ?: $this->page_slug;
192
+		$page              = $cpt_route_action ?: $page;
193
+		$this->_cpt_object = get_post_type_object($page);
194
+		// tweak pagenow for page loading.
195
+		if (! $this->_pagenow_map) {
196
+			$this->_pagenow_map = [
197
+				'create_new' => 'post-new.php',
198
+				'edit'       => 'post.php',
199
+				'trash'      => 'post.php',
200
+			];
201
+		}
202
+		add_action('current_screen', [$this, 'modify_pagenow']);
203
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
204
+		// get current page from autosave
205
+		$current_page        = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]');
206
+		$this->_current_page = $this->request->getRequestParam('current_page', $current_page);
207
+	}
208
+
209
+
210
+	/**
211
+	 * Simply ensure that we simulate the correct post route for cpt screens
212
+	 *
213
+	 * @param WP_Screen $current_screen
214
+	 * @return void
215
+	 */
216
+	public function modify_pagenow($current_screen)
217
+	{
218
+		// possibly reset pagenow.
219
+		if (
220
+			$this->page_slug === $this->raw_req_page
221
+			&& isset($this->_pagenow_map[ $this->raw_req_action ])
222
+		) {
223
+			global $pagenow, $hook_suffix;
224
+			$pagenow     = $this->_pagenow_map[ $this->raw_req_action ];
225
+			$hook_suffix = $pagenow;
226
+		}
227
+	}
228
+
229
+
230
+	/**
231
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
232
+	 *
233
+	 * @param array $ids  an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
234
+	 *                    you would send along the id of a metabox container.
235
+	 * @return void
236
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
237
+	 *                    automatically register the id for the post metabox as a container.
238
+	 */
239
+	protected function _register_autosave_containers($ids)
240
+	{
241
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
242
+	}
243
+
244
+
245
+	/**
246
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
247
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
248
+	 */
249
+	protected function _set_autosave_containers()
250
+	{
251
+		global $wp_meta_boxes;
252
+		$containers = [];
253
+		if (empty($wp_meta_boxes)) {
254
+			return;
255
+		}
256
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : [];
257
+		foreach ($current_metaboxes as $box_context) {
258
+			foreach ($box_context as $box_details) {
259
+				foreach ($box_details as $box) {
260
+					if (
261
+						is_array($box) && is_array($box['callback'])
262
+						&& (
263
+							$box['callback'][0] instanceof EE_Admin_Page
264
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
265
+						)
266
+					) {
267
+						$containers[] = $box['id'];
268
+					}
269
+				}
270
+			}
271
+		}
272
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
273
+		// add hidden inputs container
274
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
275
+	}
276
+
277
+
278
+	protected function _load_autosave_scripts_styles()
279
+	{
280
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
281 281
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
282 282
 
283
-        // filter _autosave_containers
284
-        $containers = apply_filters(
285
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
286
-            $this->_autosave_containers,
287
-            $this
288
-        );
289
-        $containers = apply_filters(
290
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
291
-            $containers,
292
-            $this
293
-        );
294
-
295
-        wp_localize_script(
296
-            'event_editor_js',
297
-            'EE_AUTOSAVE_IDS',
298
-            $containers
299
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
300
-
301
-        $unsaved_data_msg = [
302
-            'eventmsg'     => sprintf(
303
-                wp_strip_all_tags(
304
-                    __(
305
-                        "The changes you made to this %s will be lost if you navigate away from this page.",
306
-                        'event_espresso'
307
-                    )
308
-                ),
309
-                $this->_cpt_object->labels->singular_name
310
-            ),
311
-            'inputChanged' => 0,
312
-        ];
313
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
314
-    }
315
-
316
-
317
-    /**
318
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
319
-     *
320
-     * @return void
321
-     * @throws EE_Error
322
-     * @throws ReflectionException
323
-     */
324
-    protected function _load_page_dependencies()
325
-    {
326
-        // we only add stuff if this is a cpt_route!
327
-        if (! $this->_cpt_route) {
328
-            parent::_load_page_dependencies();
329
-            return;
330
-        }
331
-        // now let's do some automatic filters into the wp_system
332
-        // and we'll check to make sure the CHILD class
333
-        // automatically has the required methods in place.
334
-        // the following filters are for setting all the redirects
335
-        // on DEFAULT WP custom post type actions
336
-        // let's add a hidden input to the post-edit form
337
-        // so we know when we have to trigger our custom redirects!
338
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
339
-        add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']);
340
-        // inject our Admin page nav tabs...
341
-        // let's make sure the nav tabs are set if they aren't already
342
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
343
-        add_action('post_edit_form_tag', [$this, 'inject_nav_tabs']);
344
-        // modify the post_updated messages array
345
-        add_action('post_updated_messages', [$this, 'post_update_messages'], 10);
346
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
347
-        // cpts use the same format for shortlinks as posts!
348
-        add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4);
349
-        // This basically allows us to change the title of the "publish" metabox area
350
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
351
-        if (! empty($this->_labels['publishbox'])) {
352
-            $box_label = is_array($this->_labels['publishbox'])
353
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
354
-                ? $this->_labels['publishbox'][ $this->_req_action ]
355
-                : $this->_labels['publishbox'];
356
-            add_meta_box(
357
-                'submitdiv',
358
-                $box_label,
359
-                'post_submit_meta_box',
360
-                $this->_cpt_routes[ $this->_req_action ],
361
-                'side',
362
-                'core'
363
-            );
364
-        }
365
-        // let's add page_templates metabox if this cpt added support for it.
366
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
367
-            add_meta_box(
368
-                'page_templates',
369
-                esc_html__('Page Template', 'event_espresso'),
370
-                [$this, 'page_template_meta_box'],
371
-                $this->_cpt_routes[ $this->_req_action ],
372
-                'side',
373
-                'default'
374
-            );
375
-        }
376
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
377
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
378
-            add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4);
379
-        }
380
-        // add preview button
381
-        add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4);
382
-        // insert our own post_stati dropdown
383
-        add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10);
384
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
385
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
386
-            add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10);
387
-        }
388
-        // This allows for adding additional stuff after the title field on the wp post edit form.
389
-        // This is also before the wp_editor for post description field.
390
-        if (method_exists($this, 'edit_form_after_title')) {
391
-            add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10);
392
-        }
393
-        /**
394
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
395
-         */
396
-        add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3);
397
-        parent::_load_page_dependencies();
398
-        // notice we are ALSO going to load the pagenow hook set for this route
399
-        // (see _before_page_setup for the reset of the pagenow global ).
400
-        // This is for any plugins that are doing things properly
401
-        // and hooking into the load page hook for core wp cpt routes.
402
-        global $pagenow;
403
-        add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20);
404
-        do_action('load-' . $pagenow);
405
-        add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30);
406
-        // we route REALLY early.
407
-        try {
408
-            $this->_route_admin_request();
409
-        } catch (EE_Error $e) {
410
-            $e->get_error();
411
-        }
412
-    }
413
-
414
-
415
-    /**
416
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
417
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
418
-     * route instead.
419
-     *
420
-     * @param string $good_protocol_url The escaped url.
421
-     * @param string $original_url      The original url.
422
-     * @param string $_context          The context sent to the esc_url method.
423
-     * @return string possibly a new url for our route.
424
-     */
425
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
426
-    {
427
-        $routes_to_match = [
428
-            0 => [
429
-                'edit.php?post_type=espresso_attendees',
430
-                'admin.php?page=espresso_registrations&action=contact_list',
431
-            ],
432
-            1 => [
433
-                'edit.php?post_type=' . $this->_cpt_object->name,
434
-                'admin.php?page=' . $this->_cpt_object->name,
435
-            ],
436
-        ];
437
-        foreach ($routes_to_match as $route_matches) {
438
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
439
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
440
-            }
441
-        }
442
-        return $good_protocol_url;
443
-    }
444
-
445
-
446
-    /**
447
-     * Determine whether the current cpt supports page templates or not.
448
-     *
449
-     * @param string $cpt_name The cpt slug we're checking on.
450
-     * @return bool True supported, false not.
451
-     * @throws InvalidArgumentException
452
-     * @throws InvalidDataTypeException
453
-     * @throws InvalidInterfaceException
454
-     * @since %VER%
455
-     */
456
-    private function _supports_page_templates($cpt_name)
457
-    {
458
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
459
-        $custom_post_types = $this->loader->getShared(
460
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
461
-        );
462
-        $cpt_args          = $custom_post_types->getDefinitions();
463
-        $cpt_args          = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : [];
464
-        $cpt_has_support   = ! empty($cpt_args['page_templates']);
465
-
466
-        // if the installed version of WP is > 4.7 we do some additional checks.
467
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
468
-            $post_templates = wp_get_theme()->get_post_templates();
469
-            // if there are $post_templates for this cpt, then we return false for this method because
470
-            // that means we aren't going to load our page template manager and leave that up to the native
471
-            // cpt template manager.
472
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
473
-        }
474
-
475
-        return $cpt_has_support;
476
-    }
477
-
478
-
479
-    /**
480
-     * Callback for the page_templates metabox selector.
481
-     *
482
-     * @return void
483
-     * @since %VER%
484
-     */
485
-    public function page_template_meta_box()
486
-    {
487
-        global $post;
488
-        $template = '';
489
-
490
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
491
-            $page_template_count = count(get_page_templates());
492
-        } else {
493
-            $page_template_count = count(get_page_templates($post));
494
-        }
495
-
496
-        if ($page_template_count) {
497
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
498
-            $template      = ! empty($page_template) ? $page_template : '';
499
-        }
500
-        ?>
283
+		// filter _autosave_containers
284
+		$containers = apply_filters(
285
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
286
+			$this->_autosave_containers,
287
+			$this
288
+		);
289
+		$containers = apply_filters(
290
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
291
+			$containers,
292
+			$this
293
+		);
294
+
295
+		wp_localize_script(
296
+			'event_editor_js',
297
+			'EE_AUTOSAVE_IDS',
298
+			$containers
299
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
300
+
301
+		$unsaved_data_msg = [
302
+			'eventmsg'     => sprintf(
303
+				wp_strip_all_tags(
304
+					__(
305
+						"The changes you made to this %s will be lost if you navigate away from this page.",
306
+						'event_espresso'
307
+					)
308
+				),
309
+				$this->_cpt_object->labels->singular_name
310
+			),
311
+			'inputChanged' => 0,
312
+		];
313
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
314
+	}
315
+
316
+
317
+	/**
318
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
319
+	 *
320
+	 * @return void
321
+	 * @throws EE_Error
322
+	 * @throws ReflectionException
323
+	 */
324
+	protected function _load_page_dependencies()
325
+	{
326
+		// we only add stuff if this is a cpt_route!
327
+		if (! $this->_cpt_route) {
328
+			parent::_load_page_dependencies();
329
+			return;
330
+		}
331
+		// now let's do some automatic filters into the wp_system
332
+		// and we'll check to make sure the CHILD class
333
+		// automatically has the required methods in place.
334
+		// the following filters are for setting all the redirects
335
+		// on DEFAULT WP custom post type actions
336
+		// let's add a hidden input to the post-edit form
337
+		// so we know when we have to trigger our custom redirects!
338
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
339
+		add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']);
340
+		// inject our Admin page nav tabs...
341
+		// let's make sure the nav tabs are set if they aren't already
342
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
343
+		add_action('post_edit_form_tag', [$this, 'inject_nav_tabs']);
344
+		// modify the post_updated messages array
345
+		add_action('post_updated_messages', [$this, 'post_update_messages'], 10);
346
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
347
+		// cpts use the same format for shortlinks as posts!
348
+		add_filter('pre_get_shortlink', [$this, 'add_shortlink_button_to_editor'], 10, 4);
349
+		// This basically allows us to change the title of the "publish" metabox area
350
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
351
+		if (! empty($this->_labels['publishbox'])) {
352
+			$box_label = is_array($this->_labels['publishbox'])
353
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
354
+				? $this->_labels['publishbox'][ $this->_req_action ]
355
+				: $this->_labels['publishbox'];
356
+			add_meta_box(
357
+				'submitdiv',
358
+				$box_label,
359
+				'post_submit_meta_box',
360
+				$this->_cpt_routes[ $this->_req_action ],
361
+				'side',
362
+				'core'
363
+			);
364
+		}
365
+		// let's add page_templates metabox if this cpt added support for it.
366
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
367
+			add_meta_box(
368
+				'page_templates',
369
+				esc_html__('Page Template', 'event_espresso'),
370
+				[$this, 'page_template_meta_box'],
371
+				$this->_cpt_routes[ $this->_req_action ],
372
+				'side',
373
+				'default'
374
+			);
375
+		}
376
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
377
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
378
+			add_filter('get_sample_permalink_html', [$this, 'extra_permalink_field_buttons'], 10, 4);
379
+		}
380
+		// add preview button
381
+		add_filter('get_sample_permalink_html', [$this, 'preview_button_html'], 5, 4);
382
+		// insert our own post_stati dropdown
383
+		add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10);
384
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
385
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
386
+			add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10);
387
+		}
388
+		// This allows for adding additional stuff after the title field on the wp post edit form.
389
+		// This is also before the wp_editor for post description field.
390
+		if (method_exists($this, 'edit_form_after_title')) {
391
+			add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10);
392
+		}
393
+		/**
394
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
395
+		 */
396
+		add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10, 3);
397
+		parent::_load_page_dependencies();
398
+		// notice we are ALSO going to load the pagenow hook set for this route
399
+		// (see _before_page_setup for the reset of the pagenow global ).
400
+		// This is for any plugins that are doing things properly
401
+		// and hooking into the load page hook for core wp cpt routes.
402
+		global $pagenow;
403
+		add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20);
404
+		do_action('load-' . $pagenow);
405
+		add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30);
406
+		// we route REALLY early.
407
+		try {
408
+			$this->_route_admin_request();
409
+		} catch (EE_Error $e) {
410
+			$e->get_error();
411
+		}
412
+	}
413
+
414
+
415
+	/**
416
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
417
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
418
+	 * route instead.
419
+	 *
420
+	 * @param string $good_protocol_url The escaped url.
421
+	 * @param string $original_url      The original url.
422
+	 * @param string $_context          The context sent to the esc_url method.
423
+	 * @return string possibly a new url for our route.
424
+	 */
425
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
426
+	{
427
+		$routes_to_match = [
428
+			0 => [
429
+				'edit.php?post_type=espresso_attendees',
430
+				'admin.php?page=espresso_registrations&action=contact_list',
431
+			],
432
+			1 => [
433
+				'edit.php?post_type=' . $this->_cpt_object->name,
434
+				'admin.php?page=' . $this->_cpt_object->name,
435
+			],
436
+		];
437
+		foreach ($routes_to_match as $route_matches) {
438
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
439
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
440
+			}
441
+		}
442
+		return $good_protocol_url;
443
+	}
444
+
445
+
446
+	/**
447
+	 * Determine whether the current cpt supports page templates or not.
448
+	 *
449
+	 * @param string $cpt_name The cpt slug we're checking on.
450
+	 * @return bool True supported, false not.
451
+	 * @throws InvalidArgumentException
452
+	 * @throws InvalidDataTypeException
453
+	 * @throws InvalidInterfaceException
454
+	 * @since %VER%
455
+	 */
456
+	private function _supports_page_templates($cpt_name)
457
+	{
458
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
459
+		$custom_post_types = $this->loader->getShared(
460
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
461
+		);
462
+		$cpt_args          = $custom_post_types->getDefinitions();
463
+		$cpt_args          = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : [];
464
+		$cpt_has_support   = ! empty($cpt_args['page_templates']);
465
+
466
+		// if the installed version of WP is > 4.7 we do some additional checks.
467
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
468
+			$post_templates = wp_get_theme()->get_post_templates();
469
+			// if there are $post_templates for this cpt, then we return false for this method because
470
+			// that means we aren't going to load our page template manager and leave that up to the native
471
+			// cpt template manager.
472
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
473
+		}
474
+
475
+		return $cpt_has_support;
476
+	}
477
+
478
+
479
+	/**
480
+	 * Callback for the page_templates metabox selector.
481
+	 *
482
+	 * @return void
483
+	 * @since %VER%
484
+	 */
485
+	public function page_template_meta_box()
486
+	{
487
+		global $post;
488
+		$template = '';
489
+
490
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
491
+			$page_template_count = count(get_page_templates());
492
+		} else {
493
+			$page_template_count = count(get_page_templates($post));
494
+		}
495
+
496
+		if ($page_template_count) {
497
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
498
+			$template      = ! empty($page_template) ? $page_template : '';
499
+		}
500
+		?>
501 501
         <p><strong><?php esc_html_e('Template', 'event_espresso') ?></strong></p>
502 502
         <label class="screen-reader-text" for="page_template"><?php esc_html_e(
503
-            'Page Template',
504
-            'event_espresso'
505
-        ) ?></label>
503
+			'Page Template',
504
+			'event_espresso'
505
+		) ?></label>
506 506
         <select
507 507
             name="page_template" id="page_template"
508 508
         >
@@ -510,474 +510,474 @@  discard block
 block discarded – undo
510 510
             <?php page_template_dropdown($template); ?>
511 511
         </select>
512 512
         <?php
513
-    }
514
-
515
-
516
-    /**
517
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
518
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
519
-     *
520
-     * @param string $return    the current html
521
-     * @param int    $id        the post id for the page
522
-     * @param string $new_title What the title is
523
-     * @param string $new_slug  what the slug is
524
-     * @return string            The new html string for the permalink area
525
-     */
526
-    public function preview_button_html($return, $id, $new_title, $new_slug)
527
-    {
528
-        $post = get_post($id);
529
-        if ('publish' !== get_post_status($post)) {
530
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
531
-                       . get_preview_post_link($id)
532
-                       . '" class="button button-small">'
533
-                       . esc_html__('Preview', 'event_espresso')
534
-                       . '</a></span>'
535
-                       . "\n";
536
-        }
537
-        return $return;
538
-    }
539
-
540
-
541
-    /**
542
-     * add our custom post stati dropdown on the wp post page for this cpt
543
-     *
544
-     * @return void
545
-     */
546
-    public function custom_post_stati_dropdown()
547
-    {
548
-
549
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
550
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
551
-            ? $statuses[ $this->_cpt_model_obj->status() ]
552
-            : '';
553
-        $template_args    = [
554
-            'cur_status'            => $this->_cpt_model_obj->status(),
555
-            'statuses'              => $statuses,
556
-            'cur_status_label'      => $cur_status_label,
557
-            'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label),
558
-        ];
559
-        // we'll add a trash post status (WP doesn't add one for some reason)
560
-        if ($this->_cpt_model_obj->status() === 'trash') {
561
-            $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso');
562
-            $statuses['trash']                 = esc_html__('Trashed', 'event_espresso');
563
-            $template_args['statuses']         = $statuses;
564
-        }
565
-
566
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
567
-        EEH_Template::display_template($template, $template_args);
568
-    }
569
-
570
-
571
-    public function setup_autosave_hooks()
572
-    {
573
-        $this->_set_autosave_containers();
574
-        $this->_load_autosave_scripts_styles();
575
-    }
576
-
577
-
578
-    /**
579
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available
580
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
581
-     * for the nonce in here, but then this method looks for two things:
582
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
583
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
584
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
585
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
586
-     * template args.
587
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
588
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
589
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
590
-     *    $this->_template_args['data']['items'] = array(
591
-     *        'event-datetime-ids' => '1,2,3';
592
-     *    );
593
-     *    Keep in mind the following things:
594
-     *    - "where" index is for the input with the id as that string.
595
-     *    - "what" index is what will be used for the value of that input.
596
-     *
597
-     * @return void
598
-     * @throws EE_Error
599
-     */
600
-    public function do_extra_autosave_stuff()
601
-    {
602
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
603
-        $nonce = $this->request->getRequestParam('autosavenonce');
604
-        $this->_verify_nonce($nonce, 'autosave');
605
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
606
-        if (! defined('DOING_AUTOSAVE')) {
607
-            define('DOING_AUTOSAVE', true);
608
-        }
609
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
610
-        $autosave = "_ee_autosave_{$this->_current_view}";
611
-        if (method_exists($this, $autosave)) {
612
-            $this->$autosave();
613
-        } else {
614
-            $this->_template_args['success'] = true;
615
-        }
616
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
617
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
618
-        // now let's return json
619
-        $this->_return_json();
620
-    }
621
-
622
-
623
-    /**
624
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
625
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
626
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
627
-     *
628
-     * @return void
629
-     * @throws EE_Error
630
-     * @throws ReflectionException
631
-     */
632
-    protected function _extend_page_config_for_cpt()
633
-    {
634
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
635
-        if ($this->raw_req_page !== $this->page_slug) {
636
-            return;
637
-        }
638
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
639
-        if (! empty($this->_cpt_object)) {
640
-            $this->_page_routes = array_merge(
641
-                [
642
-                    'create_new' => '_create_new_cpt_item',
643
-                    'edit'       => '_edit_cpt_item',
644
-                ],
645
-                $this->_page_routes
646
-            );
647
-            $this->_page_config = array_merge(
648
-                [
649
-                    'create_new' => [
650
-                        'nav'           => [
651
-                            'label' => $this->_cpt_object->labels->add_new_item,
652
-                            'order' => 5,
653
-                        ],
654
-                        'require_nonce' => false,
655
-                    ],
656
-                    'edit'       => [
657
-                        'nav'           => [
658
-                            'label'      => $this->_cpt_object->labels->edit_item,
659
-                            'order'      => 5,
660
-                            'persistent' => false,
661
-                            'url'        => '',
662
-                        ],
663
-                        'require_nonce' => false,
664
-                    ],
665
-                ],
666
-                $this->_page_config
667
-            );
668
-        }
669
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
670
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
671
-            return;
672
-        }
673
-        $this->_cpt_route = true;
674
-        // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]);
675
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
676
-        if (empty($this->_cpt_object)) {
677
-            $msg = sprintf(
678
-                esc_html__(
679
-                    'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
680
-                    'event_espresso'
681
-                ),
682
-                $this->page_slug,
683
-                $this->_req_action,
684
-                get_class($this)
685
-            );
686
-            throw new EE_Error($msg);
687
-        }
688
-        $this->_set_model_object($this->request->getRequestParam('post'));
689
-    }
690
-
691
-
692
-    /**
693
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
694
-     *
695
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
696
-     * @param bool   $ignore_route_check
697
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
698
-     * @throws EE_Error
699
-     * @throws InvalidArgumentException
700
-     * @throws InvalidDataTypeException
701
-     * @throws InvalidInterfaceException
702
-     * @throws ReflectionException
703
-     */
704
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
705
-    {
706
-        $model = null;
707
-        if (
708
-            empty($this->_cpt_model_names)
709
-            || (
710
-                ! $ignore_route_check
711
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
712
-            )
713
-            || (
714
-                $this->_cpt_model_obj instanceof EE_CPT_Base
715
-                && $this->_cpt_model_obj->ID() === $id
716
-            )
717
-        ) {
718
-            // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
719
-            return;
720
-        }
721
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
722
-        if ($ignore_route_check) {
723
-            $post_type = get_post_type($id);
724
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
725
-            $custom_post_types = $this->loader->getShared(
726
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
727
-            );
728
-            $model_names       = $custom_post_types->getCustomPostTypeModelNames($post_type);
729
-            if (isset($model_names[ $post_type ])) {
730
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
731
-            }
732
-        } else {
733
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
734
-        }
735
-        if ($model instanceof EEM_Base) {
736
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
737
-        }
738
-        do_action(
739
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
740
-            $this->_cpt_model_obj,
741
-            $req_type
742
-        );
743
-    }
744
-
745
-
746
-    /**
747
-     * admin_init_global
748
-     * This runs all the code that we want executed within the WP admin_init hook.
749
-     * This method executes for ALL EE Admin pages.
750
-     *
751
-     * @return void
752
-     */
753
-    public function admin_init_global()
754
-    {
755
-        $post = $this->request->getRequestParam('post');
756
-        // its possible this is a new save so let's catch that instead
757
-        $post           = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
758
-        $post_type      = $post instanceof WP_Post ? $post->post_type : false;
759
-        $current_route  = isset($this->_req_data['current_route'])
760
-            ? $this->_req_data['current_route']
761
-            : 'shouldneverwork';
762
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
763
-            ? $this->_cpt_routes[ $current_route ]
764
-            : '';
765
-        add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3);
766
-        add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3);
767
-        if ($post_type === $route_to_check) {
768
-            add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2);
769
-        }
770
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
771
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
772
-        if (! empty($revision)) {
773
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
774
-            // doing a restore?
775
-            if (! empty($action) && $action === 'restore') {
776
-                // get post for revision
777
-                $rev_post   = get_post($revision);
778
-                $rev_parent = get_post($rev_post->post_parent);
779
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
780
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
781
-                    add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2);
782
-                    // restores of revisions
783
-                    add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2);
784
-                }
785
-            }
786
-        }
787
-        // NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
788
-        if ($post_type && $post_type === $route_to_check) {
789
-            // $post_id, $post
790
-            add_action('save_post', [$this, 'insert_update'], 10, 3);
791
-            // $post_id
792
-            add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10);
793
-            add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10);
794
-            add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10);
795
-            add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10);
796
-        }
797
-    }
798
-
799
-
800
-    /**
801
-     * Callback for the WordPress trashed_post hook.
802
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
803
-     *
804
-     * @param int $post_id
805
-     * @throws EE_Error
806
-     * @throws ReflectionException
807
-     */
808
-    public function before_trash_cpt_item($post_id)
809
-    {
810
-        $this->_set_model_object($post_id, true, 'trash');
811
-        // if our cpt object isn't existent then get out immediately.
812
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
813
-            return;
814
-        }
815
-        $this->trash_cpt_item($post_id);
816
-    }
817
-
818
-
819
-    /**
820
-     * Callback for the WordPress untrashed_post hook.
821
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
822
-     *
823
-     * @param $post_id
824
-     * @throws EE_Error
825
-     * @throws ReflectionException
826
-     */
827
-    public function before_restore_cpt_item($post_id)
828
-    {
829
-        $this->_set_model_object($post_id, true, 'restore');
830
-        // if our cpt object isn't existent then get out immediately.
831
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
832
-            return;
833
-        }
834
-        $this->restore_cpt_item($post_id);
835
-    }
836
-
837
-
838
-    /**
839
-     * Callback for the WordPress after_delete_post hook.
840
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
841
-     *
842
-     * @param $post_id
843
-     * @throws EE_Error
844
-     * @throws ReflectionException
845
-     */
846
-    public function before_delete_cpt_item($post_id)
847
-    {
848
-        $this->_set_model_object($post_id, true, 'delete');
849
-        // if our cpt object isn't existent then get out immediately.
850
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
851
-            return;
852
-        }
853
-        $this->delete_cpt_item($post_id);
854
-    }
855
-
856
-
857
-    /**
858
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
859
-     * accordingly.
860
-     *
861
-     * @return void
862
-     * @throws EE_Error
863
-     * @throws ReflectionException
864
-     */
865
-    public function verify_cpt_object()
866
-    {
867
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
868
-        // verify event object
869
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
870
-            throw new EE_Error(
871
-                sprintf(
872
-                    esc_html__(
873
-                        'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
874
-                        'event_espresso'
875
-                    ),
876
-                    $label
877
-                )
878
-            );
879
-        }
880
-        // if auto-draft then throw an error
881
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
882
-            EE_Error::overwrite_errors();
883
-            EE_Error::add_error(
884
-                sprintf(
885
-                    esc_html__(
886
-                        'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
887
-                        'event_espresso'
888
-                    ),
889
-                    $label
890
-                ),
891
-                __FILE__,
892
-                __FUNCTION__,
893
-                __LINE__
894
-            );
895
-        }
896
-    }
897
-
898
-
899
-    /**
900
-     * admin_footer_scripts_global
901
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
902
-     * will apply on ALL EE_Admin pages.
903
-     *
904
-     * @return void
905
-     */
906
-    public function admin_footer_scripts_global()
907
-    {
908
-        $this->_add_admin_page_ajax_loading_img();
909
-        $this->_add_admin_page_overlay();
910
-    }
911
-
912
-
913
-    /**
914
-     * add in any global scripts for cpt routes
915
-     *
916
-     * @return void
917
-     * @throws EE_Error
918
-     */
919
-    public function load_global_scripts_styles()
920
-    {
921
-        parent::load_global_scripts_styles();
922
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
923
-            // setup custom post status object for localize script but only if we've got a cpt object
924
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
925
-            if (! empty($statuses)) {
926
-                // get ALL statuses!
927
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
928
-                // setup object
929
-                $ee_cpt_statuses = [];
930
-                foreach ($statuses as $status => $label) {
931
-                    $ee_cpt_statuses[ $status ] = [
932
-                        'label'      => $label,
933
-                        'save_label' => sprintf(
934
-                            wp_strip_all_tags(__('Save as %s', 'event_espresso')),
935
-                            $label
936
-                        ),
937
-                    ];
938
-                }
939
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
940
-            }
941
-        }
942
-    }
943
-
944
-
945
-    /**
946
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
947
-     * insert/updates
948
-     *
949
-     * @param int     $post_id ID of post being updated
950
-     * @param WP_Post $post    Post object from WP
951
-     * @param bool    $update  Whether this is an update or a new save.
952
-     * @return void
953
-     * @throws EE_Error
954
-     * @throws ReflectionException
955
-     */
956
-    public function insert_update($post_id, $post, $update)
957
-    {
958
-        // make sure that if this is a revision OR trash action that we don't do any updates!
959
-        if (
960
-            isset($this->_req_data['action'])
961
-            && (
962
-                $this->_req_data['action'] === 'restore'
963
-                || $this->_req_data['action'] === 'trash'
964
-            )
965
-        ) {
966
-            return;
967
-        }
968
-        $this->_set_model_object($post_id, true, 'insert_update');
969
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
970
-        if (
971
-            $update
972
-            && (
973
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
974
-                || $this->_cpt_model_obj->ID() !== $post_id
975
-            )
976
-        ) {
977
-            return;
978
-        }
979
-        // check for autosave and update our req_data property accordingly.
980
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
513
+	}
514
+
515
+
516
+	/**
517
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
518
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
519
+	 *
520
+	 * @param string $return    the current html
521
+	 * @param int    $id        the post id for the page
522
+	 * @param string $new_title What the title is
523
+	 * @param string $new_slug  what the slug is
524
+	 * @return string            The new html string for the permalink area
525
+	 */
526
+	public function preview_button_html($return, $id, $new_title, $new_slug)
527
+	{
528
+		$post = get_post($id);
529
+		if ('publish' !== get_post_status($post)) {
530
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
531
+					   . get_preview_post_link($id)
532
+					   . '" class="button button-small">'
533
+					   . esc_html__('Preview', 'event_espresso')
534
+					   . '</a></span>'
535
+					   . "\n";
536
+		}
537
+		return $return;
538
+	}
539
+
540
+
541
+	/**
542
+	 * add our custom post stati dropdown on the wp post page for this cpt
543
+	 *
544
+	 * @return void
545
+	 */
546
+	public function custom_post_stati_dropdown()
547
+	{
548
+
549
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
550
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
551
+			? $statuses[ $this->_cpt_model_obj->status() ]
552
+			: '';
553
+		$template_args    = [
554
+			'cur_status'            => $this->_cpt_model_obj->status(),
555
+			'statuses'              => $statuses,
556
+			'cur_status_label'      => $cur_status_label,
557
+			'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label),
558
+		];
559
+		// we'll add a trash post status (WP doesn't add one for some reason)
560
+		if ($this->_cpt_model_obj->status() === 'trash') {
561
+			$template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso');
562
+			$statuses['trash']                 = esc_html__('Trashed', 'event_espresso');
563
+			$template_args['statuses']         = $statuses;
564
+		}
565
+
566
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
567
+		EEH_Template::display_template($template, $template_args);
568
+	}
569
+
570
+
571
+	public function setup_autosave_hooks()
572
+	{
573
+		$this->_set_autosave_containers();
574
+		$this->_load_autosave_scripts_styles();
575
+	}
576
+
577
+
578
+	/**
579
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available
580
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
581
+	 * for the nonce in here, but then this method looks for two things:
582
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
583
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
584
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
585
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
586
+	 * template args.
587
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
588
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
589
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
590
+	 *    $this->_template_args['data']['items'] = array(
591
+	 *        'event-datetime-ids' => '1,2,3';
592
+	 *    );
593
+	 *    Keep in mind the following things:
594
+	 *    - "where" index is for the input with the id as that string.
595
+	 *    - "what" index is what will be used for the value of that input.
596
+	 *
597
+	 * @return void
598
+	 * @throws EE_Error
599
+	 */
600
+	public function do_extra_autosave_stuff()
601
+	{
602
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
603
+		$nonce = $this->request->getRequestParam('autosavenonce');
604
+		$this->_verify_nonce($nonce, 'autosave');
605
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
606
+		if (! defined('DOING_AUTOSAVE')) {
607
+			define('DOING_AUTOSAVE', true);
608
+		}
609
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
610
+		$autosave = "_ee_autosave_{$this->_current_view}";
611
+		if (method_exists($this, $autosave)) {
612
+			$this->$autosave();
613
+		} else {
614
+			$this->_template_args['success'] = true;
615
+		}
616
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
617
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
618
+		// now let's return json
619
+		$this->_return_json();
620
+	}
621
+
622
+
623
+	/**
624
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
625
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
626
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
627
+	 *
628
+	 * @return void
629
+	 * @throws EE_Error
630
+	 * @throws ReflectionException
631
+	 */
632
+	protected function _extend_page_config_for_cpt()
633
+	{
634
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
635
+		if ($this->raw_req_page !== $this->page_slug) {
636
+			return;
637
+		}
638
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
639
+		if (! empty($this->_cpt_object)) {
640
+			$this->_page_routes = array_merge(
641
+				[
642
+					'create_new' => '_create_new_cpt_item',
643
+					'edit'       => '_edit_cpt_item',
644
+				],
645
+				$this->_page_routes
646
+			);
647
+			$this->_page_config = array_merge(
648
+				[
649
+					'create_new' => [
650
+						'nav'           => [
651
+							'label' => $this->_cpt_object->labels->add_new_item,
652
+							'order' => 5,
653
+						],
654
+						'require_nonce' => false,
655
+					],
656
+					'edit'       => [
657
+						'nav'           => [
658
+							'label'      => $this->_cpt_object->labels->edit_item,
659
+							'order'      => 5,
660
+							'persistent' => false,
661
+							'url'        => '',
662
+						],
663
+						'require_nonce' => false,
664
+					],
665
+				],
666
+				$this->_page_config
667
+			);
668
+		}
669
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
670
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
671
+			return;
672
+		}
673
+		$this->_cpt_route = true;
674
+		// $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]);
675
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
676
+		if (empty($this->_cpt_object)) {
677
+			$msg = sprintf(
678
+				esc_html__(
679
+					'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
680
+					'event_espresso'
681
+				),
682
+				$this->page_slug,
683
+				$this->_req_action,
684
+				get_class($this)
685
+			);
686
+			throw new EE_Error($msg);
687
+		}
688
+		$this->_set_model_object($this->request->getRequestParam('post'));
689
+	}
690
+
691
+
692
+	/**
693
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
694
+	 *
695
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
696
+	 * @param bool   $ignore_route_check
697
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
698
+	 * @throws EE_Error
699
+	 * @throws InvalidArgumentException
700
+	 * @throws InvalidDataTypeException
701
+	 * @throws InvalidInterfaceException
702
+	 * @throws ReflectionException
703
+	 */
704
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
705
+	{
706
+		$model = null;
707
+		if (
708
+			empty($this->_cpt_model_names)
709
+			|| (
710
+				! $ignore_route_check
711
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
712
+			)
713
+			|| (
714
+				$this->_cpt_model_obj instanceof EE_CPT_Base
715
+				&& $this->_cpt_model_obj->ID() === $id
716
+			)
717
+		) {
718
+			// get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
719
+			return;
720
+		}
721
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
722
+		if ($ignore_route_check) {
723
+			$post_type = get_post_type($id);
724
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
725
+			$custom_post_types = $this->loader->getShared(
726
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
727
+			);
728
+			$model_names       = $custom_post_types->getCustomPostTypeModelNames($post_type);
729
+			if (isset($model_names[ $post_type ])) {
730
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
731
+			}
732
+		} else {
733
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
734
+		}
735
+		if ($model instanceof EEM_Base) {
736
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
737
+		}
738
+		do_action(
739
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
740
+			$this->_cpt_model_obj,
741
+			$req_type
742
+		);
743
+	}
744
+
745
+
746
+	/**
747
+	 * admin_init_global
748
+	 * This runs all the code that we want executed within the WP admin_init hook.
749
+	 * This method executes for ALL EE Admin pages.
750
+	 *
751
+	 * @return void
752
+	 */
753
+	public function admin_init_global()
754
+	{
755
+		$post = $this->request->getRequestParam('post');
756
+		// its possible this is a new save so let's catch that instead
757
+		$post           = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
758
+		$post_type      = $post instanceof WP_Post ? $post->post_type : false;
759
+		$current_route  = isset($this->_req_data['current_route'])
760
+			? $this->_req_data['current_route']
761
+			: 'shouldneverwork';
762
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
763
+			? $this->_cpt_routes[ $current_route ]
764
+			: '';
765
+		add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 3);
766
+		add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 3);
767
+		if ($post_type === $route_to_check) {
768
+			add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2);
769
+		}
770
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
771
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
772
+		if (! empty($revision)) {
773
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
774
+			// doing a restore?
775
+			if (! empty($action) && $action === 'restore') {
776
+				// get post for revision
777
+				$rev_post   = get_post($revision);
778
+				$rev_parent = get_post($rev_post->post_parent);
779
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
780
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
781
+					add_filter('wp_redirect', [$this, 'revision_redirect'], 10, 2);
782
+					// restores of revisions
783
+					add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2);
784
+				}
785
+			}
786
+		}
787
+		// NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
788
+		if ($post_type && $post_type === $route_to_check) {
789
+			// $post_id, $post
790
+			add_action('save_post', [$this, 'insert_update'], 10, 3);
791
+			// $post_id
792
+			add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10);
793
+			add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10);
794
+			add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10);
795
+			add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10);
796
+		}
797
+	}
798
+
799
+
800
+	/**
801
+	 * Callback for the WordPress trashed_post hook.
802
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
803
+	 *
804
+	 * @param int $post_id
805
+	 * @throws EE_Error
806
+	 * @throws ReflectionException
807
+	 */
808
+	public function before_trash_cpt_item($post_id)
809
+	{
810
+		$this->_set_model_object($post_id, true, 'trash');
811
+		// if our cpt object isn't existent then get out immediately.
812
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
813
+			return;
814
+		}
815
+		$this->trash_cpt_item($post_id);
816
+	}
817
+
818
+
819
+	/**
820
+	 * Callback for the WordPress untrashed_post hook.
821
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
822
+	 *
823
+	 * @param $post_id
824
+	 * @throws EE_Error
825
+	 * @throws ReflectionException
826
+	 */
827
+	public function before_restore_cpt_item($post_id)
828
+	{
829
+		$this->_set_model_object($post_id, true, 'restore');
830
+		// if our cpt object isn't existent then get out immediately.
831
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
832
+			return;
833
+		}
834
+		$this->restore_cpt_item($post_id);
835
+	}
836
+
837
+
838
+	/**
839
+	 * Callback for the WordPress after_delete_post hook.
840
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
841
+	 *
842
+	 * @param $post_id
843
+	 * @throws EE_Error
844
+	 * @throws ReflectionException
845
+	 */
846
+	public function before_delete_cpt_item($post_id)
847
+	{
848
+		$this->_set_model_object($post_id, true, 'delete');
849
+		// if our cpt object isn't existent then get out immediately.
850
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
851
+			return;
852
+		}
853
+		$this->delete_cpt_item($post_id);
854
+	}
855
+
856
+
857
+	/**
858
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
859
+	 * accordingly.
860
+	 *
861
+	 * @return void
862
+	 * @throws EE_Error
863
+	 * @throws ReflectionException
864
+	 */
865
+	public function verify_cpt_object()
866
+	{
867
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
868
+		// verify event object
869
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
870
+			throw new EE_Error(
871
+				sprintf(
872
+					esc_html__(
873
+						'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
874
+						'event_espresso'
875
+					),
876
+					$label
877
+				)
878
+			);
879
+		}
880
+		// if auto-draft then throw an error
881
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
882
+			EE_Error::overwrite_errors();
883
+			EE_Error::add_error(
884
+				sprintf(
885
+					esc_html__(
886
+						'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
887
+						'event_espresso'
888
+					),
889
+					$label
890
+				),
891
+				__FILE__,
892
+				__FUNCTION__,
893
+				__LINE__
894
+			);
895
+		}
896
+	}
897
+
898
+
899
+	/**
900
+	 * admin_footer_scripts_global
901
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
902
+	 * will apply on ALL EE_Admin pages.
903
+	 *
904
+	 * @return void
905
+	 */
906
+	public function admin_footer_scripts_global()
907
+	{
908
+		$this->_add_admin_page_ajax_loading_img();
909
+		$this->_add_admin_page_overlay();
910
+	}
911
+
912
+
913
+	/**
914
+	 * add in any global scripts for cpt routes
915
+	 *
916
+	 * @return void
917
+	 * @throws EE_Error
918
+	 */
919
+	public function load_global_scripts_styles()
920
+	{
921
+		parent::load_global_scripts_styles();
922
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
923
+			// setup custom post status object for localize script but only if we've got a cpt object
924
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
925
+			if (! empty($statuses)) {
926
+				// get ALL statuses!
927
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
928
+				// setup object
929
+				$ee_cpt_statuses = [];
930
+				foreach ($statuses as $status => $label) {
931
+					$ee_cpt_statuses[ $status ] = [
932
+						'label'      => $label,
933
+						'save_label' => sprintf(
934
+							wp_strip_all_tags(__('Save as %s', 'event_espresso')),
935
+							$label
936
+						),
937
+					];
938
+				}
939
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
940
+			}
941
+		}
942
+	}
943
+
944
+
945
+	/**
946
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
947
+	 * insert/updates
948
+	 *
949
+	 * @param int     $post_id ID of post being updated
950
+	 * @param WP_Post $post    Post object from WP
951
+	 * @param bool    $update  Whether this is an update or a new save.
952
+	 * @return void
953
+	 * @throws EE_Error
954
+	 * @throws ReflectionException
955
+	 */
956
+	public function insert_update($post_id, $post, $update)
957
+	{
958
+		// make sure that if this is a revision OR trash action that we don't do any updates!
959
+		if (
960
+			isset($this->_req_data['action'])
961
+			&& (
962
+				$this->_req_data['action'] === 'restore'
963
+				|| $this->_req_data['action'] === 'trash'
964
+			)
965
+		) {
966
+			return;
967
+		}
968
+		$this->_set_model_object($post_id, true, 'insert_update');
969
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
970
+		if (
971
+			$update
972
+			&& (
973
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
974
+				|| $this->_cpt_model_obj->ID() !== $post_id
975
+			)
976
+		) {
977
+			return;
978
+		}
979
+		// check for autosave and update our req_data property accordingly.
980
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
981 981
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
982 982
 
983 983
                 foreach ( (array) $values as $key => $value ) {
@@ -987,548 +987,548 @@  discard block
 block discarded – undo
987 987
 
988 988
         }/**/ // TODO reactivate after autosave is implemented in 4.2
989 989
 
990
-        // take care of updating any selected page_template IF this cpt supports it.
991
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
992
-            // wp version aware.
993
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
994
-                $page_templates = wp_get_theme()->get_page_templates();
995
-            } else {
996
-                $post->page_template = $this->_req_data['page_template'];
997
-                $page_templates      = wp_get_theme()->get_page_templates($post);
998
-            }
999
-            if (
1000
-                'default' != $this->_req_data['page_template']
1001
-                && ! isset($page_templates[ $this->_req_data['page_template'] ])
1002
-            ) {
1003
-                EE_Error::add_error(
1004
-                    esc_html__('Invalid Page Template.', 'event_espresso'),
1005
-                    __FILE__,
1006
-                    __FUNCTION__,
1007
-                    __LINE__
1008
-                );
1009
-            } else {
1010
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1011
-            }
1012
-        }
1013
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1014
-            return;
1015
-        } //TODO we'll remove this after reimplementing autosave in 4.2
1016
-        $this->_insert_update_cpt_item($post_id, $post);
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1022
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1023
-     * so we don't have to check for our CPT.
1024
-     *
1025
-     * @param int $post_id ID of the post
1026
-     * @return void
1027
-     */
1028
-    public function dont_permanently_delete_ee_cpts($post_id)
1029
-    {
1030
-        // only do this if we're actually processing one of our CPTs
1031
-        // if our cpt object isn't existent then get out immediately.
1032
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1033
-            return;
1034
-        }
1035
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1036
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1037
-        // our cpts may have comments so let's take care of that too
1038
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1044
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1045
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1046
-     *
1047
-     * @param int $post_id     ID of cpt item
1048
-     * @param int $revision_id ID of revision being restored
1049
-     * @return void
1050
-     */
1051
-    public function restore_revision($post_id, $revision_id)
1052
-    {
1053
-        $this->_restore_cpt_item($post_id, $revision_id);
1054
-        // global action
1055
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1056
-        // class specific action so you can limit hooking into a specific page.
1057
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     * @param int $post_id     ID of cpt item
1063
-     * @param int $revision_id ID of revision for item
1064
-     * @return void
1065
-     * @see restore_revision() for details
1066
-     */
1067
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1068
-
1069
-
1070
-    /**
1071
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1072
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1073
-     * To fix we have to reset the current_screen using the page_slug
1074
-     * (which is identical - or should be - to our registered_post_type id.)
1075
-     * Also, since the core WP file loads the admin_header.php for WP
1076
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1077
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1078
-     *
1079
-     * @return void
1080
-     * @throws EE_Error
1081
-     */
1082
-    public function modify_current_screen()
1083
-    {
1084
-        // ONLY do this if the current page_route IS a cpt route
1085
-        if (! $this->_cpt_route) {
1086
-            return;
1087
-        }
1088
-        // routing things REALLY early b/c this is a cpt admin page
1089
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1090
-        $this->_current_screen       = get_current_screen();
1091
-        $this->_current_screen->base = 'event-espresso';
1092
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1093
-        /*try {
990
+		// take care of updating any selected page_template IF this cpt supports it.
991
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
992
+			// wp version aware.
993
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
994
+				$page_templates = wp_get_theme()->get_page_templates();
995
+			} else {
996
+				$post->page_template = $this->_req_data['page_template'];
997
+				$page_templates      = wp_get_theme()->get_page_templates($post);
998
+			}
999
+			if (
1000
+				'default' != $this->_req_data['page_template']
1001
+				&& ! isset($page_templates[ $this->_req_data['page_template'] ])
1002
+			) {
1003
+				EE_Error::add_error(
1004
+					esc_html__('Invalid Page Template.', 'event_espresso'),
1005
+					__FILE__,
1006
+					__FUNCTION__,
1007
+					__LINE__
1008
+				);
1009
+			} else {
1010
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1011
+			}
1012
+		}
1013
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1014
+			return;
1015
+		} //TODO we'll remove this after reimplementing autosave in 4.2
1016
+		$this->_insert_update_cpt_item($post_id, $post);
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1022
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1023
+	 * so we don't have to check for our CPT.
1024
+	 *
1025
+	 * @param int $post_id ID of the post
1026
+	 * @return void
1027
+	 */
1028
+	public function dont_permanently_delete_ee_cpts($post_id)
1029
+	{
1030
+		// only do this if we're actually processing one of our CPTs
1031
+		// if our cpt object isn't existent then get out immediately.
1032
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1033
+			return;
1034
+		}
1035
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1036
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1037
+		// our cpts may have comments so let's take care of that too
1038
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1044
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1045
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1046
+	 *
1047
+	 * @param int $post_id     ID of cpt item
1048
+	 * @param int $revision_id ID of revision being restored
1049
+	 * @return void
1050
+	 */
1051
+	public function restore_revision($post_id, $revision_id)
1052
+	{
1053
+		$this->_restore_cpt_item($post_id, $revision_id);
1054
+		// global action
1055
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1056
+		// class specific action so you can limit hooking into a specific page.
1057
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 * @param int $post_id     ID of cpt item
1063
+	 * @param int $revision_id ID of revision for item
1064
+	 * @return void
1065
+	 * @see restore_revision() for details
1066
+	 */
1067
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1068
+
1069
+
1070
+	/**
1071
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1072
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1073
+	 * To fix we have to reset the current_screen using the page_slug
1074
+	 * (which is identical - or should be - to our registered_post_type id.)
1075
+	 * Also, since the core WP file loads the admin_header.php for WP
1076
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1077
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1078
+	 *
1079
+	 * @return void
1080
+	 * @throws EE_Error
1081
+	 */
1082
+	public function modify_current_screen()
1083
+	{
1084
+		// ONLY do this if the current page_route IS a cpt route
1085
+		if (! $this->_cpt_route) {
1086
+			return;
1087
+		}
1088
+		// routing things REALLY early b/c this is a cpt admin page
1089
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1090
+		$this->_current_screen       = get_current_screen();
1091
+		$this->_current_screen->base = 'event-espresso';
1092
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1093
+		/*try {
1094 1094
             $this->_route_admin_request();
1095 1095
         } catch ( EE_Error $e ) {
1096 1096
             $e->get_error();
1097 1097
         }/**/
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1103
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1104
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1105
-     * default to be.
1106
-     *
1107
-     * @param string $title The new title (or existing if there is no editor_title defined)
1108
-     * @return string
1109
-     */
1110
-    public function add_custom_editor_default_title($title)
1111
-    {
1112
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1113
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1114
-            : $title;
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1120
-     *
1121
-     * @param string $shortlink   The already generated shortlink
1122
-     * @param int    $id          Post ID for this item
1123
-     * @param string $context     The context for the link
1124
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1125
-     * @return string
1126
-     */
1127
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1128
-    {
1129
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1130
-            $post = get_post($id);
1131
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1132
-                $shortlink = home_url('?p=' . $post->ID);
1133
-            }
1134
-        }
1135
-        return $shortlink;
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1141
-     * already run in modify_current_screen())
1142
-     *
1143
-     * @return void
1144
-     * @throws EE_Error
1145
-     * @throws ReflectionException
1146
-     */
1147
-    public function route_admin_request()
1148
-    {
1149
-        if ($this->_cpt_route) {
1150
-            return;
1151
-        }
1152
-        try {
1153
-            $this->_route_admin_request();
1154
-        } catch (EE_Error $e) {
1155
-            $e->get_error();
1156
-        }
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1162
-     *
1163
-     * @return void
1164
-     */
1165
-    public function cpt_post_form_hidden_input()
1166
-    {
1167
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1168
-        echo '
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1103
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1104
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1105
+	 * default to be.
1106
+	 *
1107
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1108
+	 * @return string
1109
+	 */
1110
+	public function add_custom_editor_default_title($title)
1111
+	{
1112
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1113
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1114
+			: $title;
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1120
+	 *
1121
+	 * @param string $shortlink   The already generated shortlink
1122
+	 * @param int    $id          Post ID for this item
1123
+	 * @param string $context     The context for the link
1124
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1125
+	 * @return string
1126
+	 */
1127
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1128
+	{
1129
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1130
+			$post = get_post($id);
1131
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1132
+				$shortlink = home_url('?p=' . $post->ID);
1133
+			}
1134
+		}
1135
+		return $shortlink;
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1141
+	 * already run in modify_current_screen())
1142
+	 *
1143
+	 * @return void
1144
+	 * @throws EE_Error
1145
+	 * @throws ReflectionException
1146
+	 */
1147
+	public function route_admin_request()
1148
+	{
1149
+		if ($this->_cpt_route) {
1150
+			return;
1151
+		}
1152
+		try {
1153
+			$this->_route_admin_request();
1154
+		} catch (EE_Error $e) {
1155
+			$e->get_error();
1156
+		}
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1162
+	 *
1163
+	 * @return void
1164
+	 */
1165
+	public function cpt_post_form_hidden_input()
1166
+	{
1167
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1168
+		echo '
1169 1169
         <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/>
1170 1170
         <div id="ee-cpt-hidden-inputs">
1171 1171
             <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/>
1172 1172
             <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/>
1173 1173
         </div>';
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1179
-     *
1180
-     * @param string $location Original location url
1181
-     * @param int    $status   Status for http header
1182
-     * @return string           new (or original) url to redirect to.
1183
-     * @throws EE_Error
1184
-     */
1185
-    public function revision_redirect($location, $status)
1186
-    {
1187
-        // get revision
1188
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1189
-        // can't do anything without revision so let's get out if not present
1190
-        if (empty($rev_id)) {
1191
-            return $location;
1192
-        }
1193
-        // get rev_post_data
1194
-        $rev        = get_post($rev_id);
1195
-        $admin_url  = $this->_admin_base_url;
1196
-        $query_args = [
1197
-            'action'   => 'edit',
1198
-            'post'     => $rev->post_parent,
1199
-            'revision' => $rev_id,
1200
-            'message'  => 5,
1201
-        ];
1202
-        $this->_process_notices($query_args, true);
1203
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1209
-     *
1210
-     * @param string $link    the original generated link
1211
-     * @param int    $id      post id
1212
-     * @param string $context optional, defaults to display.  How to write the '&'
1213
-     * @return string          the link
1214
-     */
1215
-    public function modify_edit_post_link($link, $id, $context)
1216
-    {
1217
-        $post = get_post($id);
1218
-        if (
1219
-            ! isset($this->_req_data['action'])
1220
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1221
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1222
-        ) {
1223
-            return $link;
1224
-        }
1225
-        $query_args = [
1226
-            'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit',
1227
-            'post'   => $id,
1228
-        ];
1229
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1235
-     * our routes.
1236
-     *
1237
-     * @param string $delete_link  original delete link
1238
-     * @param int    $post_id      id of cpt object
1239
-     * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1240
-     * @return string new delete link
1241
-     * @throws EE_Error
1242
-     * @throws ReflectionException
1243
-     */
1244
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1245
-    {
1246
-        $post = get_post($post_id);
1247
-
1248
-        if (
1249
-            empty($this->_req_data['action'])
1250
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1251
-            || ! $post instanceof WP_Post
1252
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1253
-        ) {
1254
-            return $delete_link;
1255
-        }
1256
-        $this->_set_model_object($post->ID, true);
1257
-
1258
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1259
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1260
-
1261
-        return EE_Admin_Page::add_query_args_and_nonce(
1262
-            [
1263
-                'page'   => $this->_req_data['page'],
1264
-                'action' => $action,
1265
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1266
-                         => $post->ID,
1267
-            ],
1268
-            admin_url()
1269
-        );
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1275
-     * so that we can hijack the default redirect locations for wp custom post types
1276
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1277
-     *
1278
-     * @param string $location This is the incoming currently set redirect location
1279
-     * @param string $post_id  This is the 'ID' value of the wp_posts table
1280
-     * @return string           the new location to redirect to
1281
-     * @throws EE_Error
1282
-     */
1283
-    public function cpt_post_location_redirect($location, $post_id)
1284
-    {
1285
-        // we DO have a match so let's setup the url
1286
-        // we have to get the post to determine our route
1287
-        $post       = get_post($post_id);
1288
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1289
-        // shared query_args
1290
-        $query_args = ['action' => $edit_route, 'post' => $post_id];
1291
-        $admin_url  = $this->_admin_base_url;
1292
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1293
-            $status = get_post_status($post_id);
1294
-            if (isset($this->_req_data['publish'])) {
1295
-                switch ($status) {
1296
-                    case 'pending':
1297
-                        $message = 8;
1298
-                        break;
1299
-                    case 'future':
1300
-                        $message = 9;
1301
-                        break;
1302
-                    default:
1303
-                        $message = 6;
1304
-                }
1305
-            } else {
1306
-                $message = 'draft' === $status ? 10 : 1;
1307
-            }
1308
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1309
-            $message = 2;
1310
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1311
-            $message = 3;
1312
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1313
-            $message = 7;
1314
-        } else {
1315
-            $message = 4;
1316
-        }
1317
-        // change the message if the post type is not viewable on the frontend
1318
-        $this->_cpt_object = get_post_type_object($post->post_type);
1319
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1320
-        $query_args        = array_merge(['message' => $message], $query_args);
1321
-        $this->_process_notices($query_args, true);
1322
-        return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1323
-    }
1324
-
1325
-
1326
-    /**
1327
-     * This method is called to inject nav tabs on core WP cpt pages
1328
-     *
1329
-     * @return void
1330
-     * @throws EE_Error
1331
-     */
1332
-    public function inject_nav_tabs()
1333
-    {
1334
-        // can we hijack and insert the nav_tabs?
1335
-        $nav_tabs = $this->_get_main_nav_tabs();
1336
-        // first close off existing form tag
1337
-        $html = '>';
1338
-        $html .= $nav_tabs;
1339
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1340
-        $html .= '<span></span';
1341
-        echo $html;  // already escaped
1342
-    }
1343
-
1344
-
1345
-    /**
1346
-     * This just sets up the post update messages when an update form is loaded
1347
-     *
1348
-     * @param array $messages the original messages array
1349
-     * @return array           the new messages array
1350
-     */
1351
-    public function post_update_messages($messages)
1352
-    {
1353
-        global $post;
1354
-        $id       = $this->request->getRequestParam('post');
1355
-        $id       = empty($id) && is_object($post) ? $post->ID : null;
1356
-        $revision = $this->request->getRequestParam('revision', 0, 'int');
1357
-
1358
-        $messages[ $post->post_type ] = [
1359
-            0  => '', // Unused. Messages start at index 1.
1360
-            1  => sprintf(
1361
-                esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1362
-                $this->_cpt_object->labels->singular_name,
1363
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1364
-                '</a>'
1365
-            ),
1366
-            2  => esc_html__('Custom field updated', 'event_espresso'),
1367
-            3  => esc_html__('Custom field deleted.', 'event_espresso'),
1368
-            4  => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1369
-            5  => $revision
1370
-                ? sprintf(
1371
-                    esc_html__('%s restored to revision from %s', 'event_espresso'),
1372
-                    $this->_cpt_object->labels->singular_name,
1373
-                    wp_post_revision_title($revision, false)
1374
-                )
1375
-                : false,
1376
-            6  => sprintf(
1377
-                esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1378
-                $this->_cpt_object->labels->singular_name,
1379
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1380
-                '</a>'
1381
-            ),
1382
-            7  => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1383
-            8  => sprintf(
1384
-                esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1385
-                $this->_cpt_object->labels->singular_name,
1386
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1387
-                '</a>'
1388
-            ),
1389
-            9  => sprintf(
1390
-                esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1391
-                $this->_cpt_object->labels->singular_name,
1392
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1393
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1394
-                '</a>'
1395
-            ),
1396
-            10 => sprintf(
1397
-                esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1398
-                $this->_cpt_object->labels->singular_name,
1399
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1400
-                '</a>'
1401
-            ),
1402
-        ];
1403
-        return $messages;
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * default method for the 'create_new' route for cpt admin pages.
1409
-     * For reference what to include in here, see wp-admin/post-new.php
1410
-     *
1411
-     * @return void
1412
-     */
1413
-    protected function _create_new_cpt_item()
1414
-    {
1415
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1416
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1417
-        $post_type        = $this->_cpt_routes[ $this->_req_action ];
1418
-        $post_type_object = $this->_cpt_object;
1419
-        $title            = $post_type_object->labels->add_new_item;
1420
-        $post             = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1421
-        add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1422
-        // modify the default editor title field with default title.
1423
-        add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1424
-        $this->loadEditorTemplate(true);
1425
-    }
1426
-
1427
-
1428
-    /**
1429
-     * Enqueues auto-save and loads the editor template
1430
-     *
1431
-     * @param bool $creating
1432
-     */
1433
-    private function loadEditorTemplate($creating = true)
1434
-    {
1435
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1436
-        // these vars are used by the template
1437
-        $editing = true;
1438
-        $post_ID = $post->ID;
1439
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1440
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1441
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1442
-            if ($creating) {
1443
-                wp_enqueue_script('autosave');
1444
-            } elseif (
1445
-                isset($this->_cpt_routes[ $this->_req_data['action'] ])
1446
-                && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1447
-            ) {
1448
-                $create_new_action = apply_filters(
1449
-                    'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1450
-                    'create_new',
1451
-                    $this
1452
-                );
1453
-                $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1454
-                    array(
1455
-                        'action' => $create_new_action,
1456
-                        'page'   => $this->page_slug,
1457
-                    ),
1458
-                    'admin.php'
1459
-                );
1460
-            }
1461
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1462
-        }
1463
-    }
1464
-
1465
-
1466
-    public function add_new_admin_page_global()
1467
-    {
1468
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1469
-        ?>
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1179
+	 *
1180
+	 * @param string $location Original location url
1181
+	 * @param int    $status   Status for http header
1182
+	 * @return string           new (or original) url to redirect to.
1183
+	 * @throws EE_Error
1184
+	 */
1185
+	public function revision_redirect($location, $status)
1186
+	{
1187
+		// get revision
1188
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1189
+		// can't do anything without revision so let's get out if not present
1190
+		if (empty($rev_id)) {
1191
+			return $location;
1192
+		}
1193
+		// get rev_post_data
1194
+		$rev        = get_post($rev_id);
1195
+		$admin_url  = $this->_admin_base_url;
1196
+		$query_args = [
1197
+			'action'   => 'edit',
1198
+			'post'     => $rev->post_parent,
1199
+			'revision' => $rev_id,
1200
+			'message'  => 5,
1201
+		];
1202
+		$this->_process_notices($query_args, true);
1203
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1209
+	 *
1210
+	 * @param string $link    the original generated link
1211
+	 * @param int    $id      post id
1212
+	 * @param string $context optional, defaults to display.  How to write the '&'
1213
+	 * @return string          the link
1214
+	 */
1215
+	public function modify_edit_post_link($link, $id, $context)
1216
+	{
1217
+		$post = get_post($id);
1218
+		if (
1219
+			! isset($this->_req_data['action'])
1220
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1221
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1222
+		) {
1223
+			return $link;
1224
+		}
1225
+		$query_args = [
1226
+			'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit',
1227
+			'post'   => $id,
1228
+		];
1229
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1235
+	 * our routes.
1236
+	 *
1237
+	 * @param string $delete_link  original delete link
1238
+	 * @param int    $post_id      id of cpt object
1239
+	 * @param bool   $force_delete whether this is forcing a hard delete instead of trash
1240
+	 * @return string new delete link
1241
+	 * @throws EE_Error
1242
+	 * @throws ReflectionException
1243
+	 */
1244
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1245
+	{
1246
+		$post = get_post($post_id);
1247
+
1248
+		if (
1249
+			empty($this->_req_data['action'])
1250
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1251
+			|| ! $post instanceof WP_Post
1252
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1253
+		) {
1254
+			return $delete_link;
1255
+		}
1256
+		$this->_set_model_object($post->ID, true);
1257
+
1258
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1259
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1260
+
1261
+		return EE_Admin_Page::add_query_args_and_nonce(
1262
+			[
1263
+				'page'   => $this->_req_data['page'],
1264
+				'action' => $action,
1265
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1266
+						 => $post->ID,
1267
+			],
1268
+			admin_url()
1269
+		);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1275
+	 * so that we can hijack the default redirect locations for wp custom post types
1276
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1277
+	 *
1278
+	 * @param string $location This is the incoming currently set redirect location
1279
+	 * @param string $post_id  This is the 'ID' value of the wp_posts table
1280
+	 * @return string           the new location to redirect to
1281
+	 * @throws EE_Error
1282
+	 */
1283
+	public function cpt_post_location_redirect($location, $post_id)
1284
+	{
1285
+		// we DO have a match so let's setup the url
1286
+		// we have to get the post to determine our route
1287
+		$post       = get_post($post_id);
1288
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1289
+		// shared query_args
1290
+		$query_args = ['action' => $edit_route, 'post' => $post_id];
1291
+		$admin_url  = $this->_admin_base_url;
1292
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1293
+			$status = get_post_status($post_id);
1294
+			if (isset($this->_req_data['publish'])) {
1295
+				switch ($status) {
1296
+					case 'pending':
1297
+						$message = 8;
1298
+						break;
1299
+					case 'future':
1300
+						$message = 9;
1301
+						break;
1302
+					default:
1303
+						$message = 6;
1304
+				}
1305
+			} else {
1306
+				$message = 'draft' === $status ? 10 : 1;
1307
+			}
1308
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1309
+			$message = 2;
1310
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1311
+			$message = 3;
1312
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1313
+			$message = 7;
1314
+		} else {
1315
+			$message = 4;
1316
+		}
1317
+		// change the message if the post type is not viewable on the frontend
1318
+		$this->_cpt_object = get_post_type_object($post->post_type);
1319
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1320
+		$query_args        = array_merge(['message' => $message], $query_args);
1321
+		$this->_process_notices($query_args, true);
1322
+		return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url);
1323
+	}
1324
+
1325
+
1326
+	/**
1327
+	 * This method is called to inject nav tabs on core WP cpt pages
1328
+	 *
1329
+	 * @return void
1330
+	 * @throws EE_Error
1331
+	 */
1332
+	public function inject_nav_tabs()
1333
+	{
1334
+		// can we hijack and insert the nav_tabs?
1335
+		$nav_tabs = $this->_get_main_nav_tabs();
1336
+		// first close off existing form tag
1337
+		$html = '>';
1338
+		$html .= $nav_tabs;
1339
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1340
+		$html .= '<span></span';
1341
+		echo $html;  // already escaped
1342
+	}
1343
+
1344
+
1345
+	/**
1346
+	 * This just sets up the post update messages when an update form is loaded
1347
+	 *
1348
+	 * @param array $messages the original messages array
1349
+	 * @return array           the new messages array
1350
+	 */
1351
+	public function post_update_messages($messages)
1352
+	{
1353
+		global $post;
1354
+		$id       = $this->request->getRequestParam('post');
1355
+		$id       = empty($id) && is_object($post) ? $post->ID : null;
1356
+		$revision = $this->request->getRequestParam('revision', 0, 'int');
1357
+
1358
+		$messages[ $post->post_type ] = [
1359
+			0  => '', // Unused. Messages start at index 1.
1360
+			1  => sprintf(
1361
+				esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1362
+				$this->_cpt_object->labels->singular_name,
1363
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1364
+				'</a>'
1365
+			),
1366
+			2  => esc_html__('Custom field updated', 'event_espresso'),
1367
+			3  => esc_html__('Custom field deleted.', 'event_espresso'),
1368
+			4  => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1369
+			5  => $revision
1370
+				? sprintf(
1371
+					esc_html__('%s restored to revision from %s', 'event_espresso'),
1372
+					$this->_cpt_object->labels->singular_name,
1373
+					wp_post_revision_title($revision, false)
1374
+				)
1375
+				: false,
1376
+			6  => sprintf(
1377
+				esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1378
+				$this->_cpt_object->labels->singular_name,
1379
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1380
+				'</a>'
1381
+			),
1382
+			7  => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1383
+			8  => sprintf(
1384
+				esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1385
+				$this->_cpt_object->labels->singular_name,
1386
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1387
+				'</a>'
1388
+			),
1389
+			9  => sprintf(
1390
+				esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1391
+				$this->_cpt_object->labels->singular_name,
1392
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1393
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1394
+				'</a>'
1395
+			),
1396
+			10 => sprintf(
1397
+				esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1398
+				$this->_cpt_object->labels->singular_name,
1399
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1400
+				'</a>'
1401
+			),
1402
+		];
1403
+		return $messages;
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * default method for the 'create_new' route for cpt admin pages.
1409
+	 * For reference what to include in here, see wp-admin/post-new.php
1410
+	 *
1411
+	 * @return void
1412
+	 */
1413
+	protected function _create_new_cpt_item()
1414
+	{
1415
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1416
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1417
+		$post_type        = $this->_cpt_routes[ $this->_req_action ];
1418
+		$post_type_object = $this->_cpt_object;
1419
+		$title            = $post_type_object->labels->add_new_item;
1420
+		$post             = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1421
+		add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1422
+		// modify the default editor title field with default title.
1423
+		add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1424
+		$this->loadEditorTemplate(true);
1425
+	}
1426
+
1427
+
1428
+	/**
1429
+	 * Enqueues auto-save and loads the editor template
1430
+	 *
1431
+	 * @param bool $creating
1432
+	 */
1433
+	private function loadEditorTemplate($creating = true)
1434
+	{
1435
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1436
+		// these vars are used by the template
1437
+		$editing = true;
1438
+		$post_ID = $post->ID;
1439
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1440
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1441
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1442
+			if ($creating) {
1443
+				wp_enqueue_script('autosave');
1444
+			} elseif (
1445
+				isset($this->_cpt_routes[ $this->_req_data['action'] ])
1446
+				&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1447
+			) {
1448
+				$create_new_action = apply_filters(
1449
+					'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1450
+					'create_new',
1451
+					$this
1452
+				);
1453
+				$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1454
+					array(
1455
+						'action' => $create_new_action,
1456
+						'page'   => $this->page_slug,
1457
+					),
1458
+					'admin.php'
1459
+				);
1460
+			}
1461
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1462
+		}
1463
+	}
1464
+
1465
+
1466
+	public function add_new_admin_page_global()
1467
+	{
1468
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1469
+		?>
1470 1470
         <script type="text/javascript">
1471 1471
             adminpage = '<?php echo $admin_page; ?>';
1472 1472
         </script>
1473 1473
         <?php
1474
-    }
1475
-
1476
-
1477
-    /**
1478
-     * default method for the 'edit' route for cpt admin pages
1479
-     * For reference on what to put in here, refer to wp-admin/post.php
1480
-     *
1481
-     * @return string   template for edit cpt form
1482
-     */
1483
-    protected function _edit_cpt_item()
1484
-    {
1485
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1486
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1487
-        $post    = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1488
-        if (empty($post)) {
1489
-            wp_die(esc_html__(
1490
-                'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?',
1491
-                'event_espresso'
1492
-            ));
1493
-        }
1494
-
1495
-        $post_lock = $this->request->getRequestParam('get-post-lock');
1496
-        if ($post_lock) {
1497
-            wp_set_post_lock($post_id);
1498
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1499
-            exit();
1500
-        }
1501
-
1502
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1503
-        $post_type        = $this->_cpt_routes[ $this->_req_action ];
1504
-        $post_type_object = $this->_cpt_object;
1505
-
1506
-        if (! wp_check_post_lock($post->ID)) {
1507
-            wp_set_post_lock($post->ID);
1508
-        }
1509
-        add_action('admin_footer', '_admin_notice_post_locked');
1510
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1511
-            wp_enqueue_script('admin-comments');
1512
-            enqueue_comment_hotkeys_js();
1513
-        }
1514
-        add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1515
-        // modify the default editor title field with default title.
1516
-        add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1517
-        $this->loadEditorTemplate(false);
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * some getters
1524
-     */
1525
-    /**
1526
-     * This returns the protected _cpt_model_obj property
1527
-     *
1528
-     * @return EE_CPT_Base
1529
-     */
1530
-    public function get_cpt_model_obj()
1531
-    {
1532
-        return $this->_cpt_model_obj;
1533
-    }
1474
+	}
1475
+
1476
+
1477
+	/**
1478
+	 * default method for the 'edit' route for cpt admin pages
1479
+	 * For reference on what to put in here, refer to wp-admin/post.php
1480
+	 *
1481
+	 * @return string   template for edit cpt form
1482
+	 */
1483
+	protected function _edit_cpt_item()
1484
+	{
1485
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1486
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1487
+		$post    = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1488
+		if (empty($post)) {
1489
+			wp_die(esc_html__(
1490
+				'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?',
1491
+				'event_espresso'
1492
+			));
1493
+		}
1494
+
1495
+		$post_lock = $this->request->getRequestParam('get-post-lock');
1496
+		if ($post_lock) {
1497
+			wp_set_post_lock($post_id);
1498
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1499
+			exit();
1500
+		}
1501
+
1502
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1503
+		$post_type        = $this->_cpt_routes[ $this->_req_action ];
1504
+		$post_type_object = $this->_cpt_object;
1505
+
1506
+		if (! wp_check_post_lock($post->ID)) {
1507
+			wp_set_post_lock($post->ID);
1508
+		}
1509
+		add_action('admin_footer', '_admin_notice_post_locked');
1510
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1511
+			wp_enqueue_script('admin-comments');
1512
+			enqueue_comment_hotkeys_js();
1513
+		}
1514
+		add_action('admin_print_styles', [$this, 'add_new_admin_page_global']);
1515
+		// modify the default editor title field with default title.
1516
+		add_filter('enter_title_here', [$this, 'add_custom_editor_default_title'], 10);
1517
+		$this->loadEditorTemplate(false);
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * some getters
1524
+	 */
1525
+	/**
1526
+	 * This returns the protected _cpt_model_obj property
1527
+	 *
1528
+	 * @return EE_CPT_Base
1529
+	 */
1530
+	public function get_cpt_model_obj()
1531
+	{
1532
+		return $this->_cpt_model_obj;
1533
+	}
1534 1534
 }
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/templates/receipt_body.template.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
             <h3 class="section-title event-name">
62 62
                 <img class="icon" src="<?php echo EE_IMAGES_URL . 'calendar_year-24x24.png'; ?>">
63 63
                 <?php
64
-                esc_html_e(
65
-                    "Event Name:",
66
-                    "event_espresso"
67
-                ) ?>
64
+				esc_html_e(
65
+					"Event Name:",
66
+					"event_espresso"
67
+				) ?>
68 68
                 <span class="plain-text"><?php echo $event->name(); ?></span>
69 69
                 <span class="small-text link">
70 70
                 [ <a href='<?php echo esc_url_raw($event->get_permalink()) ?>'><?php esc_html_e(
71
-                    'view',
72
-                    'event_espresso'
73
-                ); ?></a> ]
71
+					'view',
72
+					'event_espresso'
73
+				); ?></a> ]
74 74
             </span>
75 75
             </h3>
76 76
             <?php if (strlen($event->description() > 1)) { ?>
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
             <?php } ?>
79 79
             <ul class="tickets-per-event">
80 80
                 <?php
81
-                foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
82
-                    $ticket       = $line_item->ticket();
83
-                    $taxable_html = $ticket->taxable()
84
-                        ? '*'
85
-                        : '';
86
-                    $subitems     = $line_item->children();
87
-                    $ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
88
-                    ?>
81
+				foreach ($ticket_line_items_per_event[ $event_id ] as $line_item_id => $line_item) {
82
+					$ticket       = $line_item->ticket();
83
+					$taxable_html = $ticket->taxable()
84
+						? '*'
85
+						: '';
86
+					$subitems     = $line_item->children();
87
+					$ticket_uses  = $ticket->get_pretty('TKT_uses', esc_html__("any", "event_espresso"));
88
+					?>
89 89
                     <li class="event-ticket">
90 90
                         <div class="ticket-details">
91 91
                             <table class="invoice-amount">
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                                         <th class="name-column"><?php esc_html_e("Ticket", "event_espresso"); ?></th>
95 95
                                         <th colspan="2" class="desc-column">
96 96
                                             <?php
97
-                                            esc_html_e("Description", 'event_espresso'); ?>
97
+											esc_html_e("Description", 'event_espresso'); ?>
98 98
                                         </th>
99 99
                                         <th class="number-column item_r">
100 100
                                             <?php esc_html_e("Quantity", "event_espresso"); ?>
@@ -109,20 +109,20 @@  discard block
 block discarded – undo
109 109
                                 </thead>
110 110
                                 <tbody>
111 111
                                     <?php
112
-                                    if (count($subitems) < 2) { ?>
112
+									if (count($subitems) < 2) { ?>
113 113
                                         <tr class="item">
114 114
                                             <td><?php echo esc_html($line_item->name() . $taxable_html); ?></td>
115 115
                                             <td colspan="2">
116 116
                                                 <?php echo esc_html($line_item->desc()); ?>
117 117
                                                 <p class="ticket-note">
118 118
                                                     <?php
119
-                                                    echo sprintf(
120
-                                                        esc_html__(
121
-                                                            'This ticket can be used once at %s of the dates/times below.',
122
-                                                            'event_espresso'
123
-                                                        ),
124
-                                                        $ticket_uses
125
-                                                    ); ?>
119
+													echo sprintf(
120
+														esc_html__(
121
+															'This ticket can be used once at %s of the dates/times below.',
122
+															'event_espresso'
123
+														),
124
+														$ticket_uses
125
+													); ?>
126 126
                                                 </p>
127 127
                                             </td>
128 128
                                             <td class="item_r">
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                                             </td>
137 137
                                         </tr>
138 138
                                         <?php
139
-                                    } else { ?>
139
+									} else { ?>
140 140
                                         <tr class="item">
141 141
                                             <td class="aln-left">
142 142
                                                 <?php echo esc_html($line_item->name() . $taxable_html); ?>
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
                                                 <?php echo esc_html($line_item->desc()); ?>
146 146
                                                 <p class="ticket-note">
147 147
                                                     <?php
148
-                                                    echo sprintf(
149
-                                                        esc_html__(
150
-                                                            'This ticket can be used once at %s of the dates/times below.',
151
-                                                            'event_espresso'
152
-                                                        ),
153
-                                                        $ticket_uses
154
-                                                    ); ?>
148
+													echo sprintf(
149
+														esc_html__(
150
+															'This ticket can be used once at %s of the dates/times below.',
151
+															'event_espresso'
152
+														),
153
+														$ticket_uses
154
+													); ?>
155 155
                                                 </p>
156 156
                                             </td>
157 157
                                             <td class="item_c">
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
                                             </td>
166 166
                                         </tr>
167 167
                                         <?php
168
-                                        foreach ($subitems as $sub_line_item) {
169
-                                            $is_percent = $sub_line_item->is_percent(); ?>
168
+										foreach ($subitems as $sub_line_item) {
169
+											$is_percent = $sub_line_item->is_percent(); ?>
170 170
                                             <tr class="subitem-row">
171 171
                                                 <td class="subitem">
172 172
                                                     <?php echo esc_html($sub_line_item->name()); ?>
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
                                                     <?php // echo $is_percent ? '' : $sub_line_item->quantity()?>
179 179
                                                 </td>
180 180
                                                 <td class="item_c"><?php
181
-                                                    echo $is_percent
182
-                                                        ? $sub_line_item->percent() . "%"
183
-                                                        : $sub_line_item->unit_price_no_code(); // already escaped ?>
181
+													echo $is_percent
182
+														? $sub_line_item->percent() . "%"
183
+														: $sub_line_item->unit_price_no_code(); // already escaped ?>
184 184
                                                 </td>
185 185
                                                 <td class="item_r"><?php echo $sub_line_item->total_no_code() ?></td>
186 186
                                             </tr>
187 187
                                             <?php
188
-                                        } ?>
188
+										} ?>
189 189
                                         <tr class="total_tr odd">
190 190
                                             <td colspan="4"></td>
191 191
                                             <td class="total" nowrap="nowrap">
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
                                             </td>
197 197
                                         </tr>
198 198
                                         <?php
199
-                                    } ?>
199
+									} ?>
200 200
                                 </tbody>
201 201
                             </table>
202 202
 
@@ -209,50 +209,50 @@  discard block
 block discarded – undo
209 209
                                              src="<?php echo esc_url_raw(EE_IMAGES_URL . 'clock-16x16.png'); ?>"
210 210
                                         >
211 211
                                         <?php
212
-                                        echo _n(
213
-                                            "Date/Time:",
214
-                                            "Dates/Times:",
215
-                                            count($ticket->datetimes()),
216
-                                            'event_espresso'
217
-                                        ); ?></h4>
212
+										echo _n(
213
+											"Date/Time:",
214
+											"Dates/Times:",
215
+											count($ticket->datetimes()),
216
+											'event_espresso'
217
+										); ?></h4>
218 218
                                     <ul class="event-dates">
219 219
                                         <?php
220
-                                        foreach ($ticket->datetimes_ordered() as $datetime) {
221
-                                            /* @var $datetime EE_Datetime */ ?>
220
+										foreach ($ticket->datetimes_ordered() as $datetime) {
221
+											/* @var $datetime EE_Datetime */ ?>
222 222
                                             <li><?php
223
-                                                echo $datetime->name()
224
-                                                    ? '<b>' . esc_html($datetime->name()) . ' </b>'
225
-                                                    : '';
226
-                                                echo sprintf(
227
-                                                    esc_html__("%s - %s (%s)", "event_espresso"),
228
-                                                    $datetime->start_date_and_time(),
229
-                                                    $datetime->end_date_and_time(),
230
-                                                    $datetime->get_timezone()
231
-                                                );
232
-                                                echo $datetime->description()
233
-                                                    ? '<p class="ticket-note">' . $datetime->description() . '</p>'
234
-                                                    : '' ?></li>
223
+												echo $datetime->name()
224
+													? '<b>' . esc_html($datetime->name()) . ' </b>'
225
+													: '';
226
+												echo sprintf(
227
+													esc_html__("%s - %s (%s)", "event_espresso"),
228
+													$datetime->start_date_and_time(),
229
+													$datetime->end_date_and_time(),
230
+													$datetime->get_timezone()
231
+												);
232
+												echo $datetime->description()
233
+													? '<p class="ticket-note">' . $datetime->description() . '</p>'
234
+													: '' ?></li>
235 235
                                             <?php
236
-                                        } ?>
236
+										} ?>
237 237
                                     </ul>
238 238
                                 </div>
239 239
                                 <?php
240
-                                if ($event->venues()) { ?>
240
+								if ($event->venues()) { ?>
241 241
                                     <div class="ticket-place-details">
242 242
                                         <h4 class="sub-section-title no-bottom-margin">
243 243
                                             <img class="icon" src="<?php
244
-                                            echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>"
244
+											echo esc_url_raw(EE_IMAGES_URL . 'location-pin-16x16.png'); ?>"
245 245
                                             >
246 246
                                             <?php
247
-                                            echo _n(
248
-                                                "Venue:",
249
-                                                "Venues:",
250
-                                                count($event->venues()),
251
-                                                'event_espresso'
252
-                                            ); ?></h4>
247
+											echo _n(
248
+												"Venue:",
249
+												"Venues:",
250
+												count($event->venues()),
251
+												'event_espresso'
252
+											); ?></h4>
253 253
                                         <ul class="event-venues">
254 254
                                             <?php
255
-                                            foreach ($event->venues() as $venue) { ?>
255
+											foreach ($event->venues() as $venue) { ?>
256 256
                                                 <li>
257 257
                                                     <?php echo esc_html($venue->name()) ?>
258 258
                                                     <span class="small-text">
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
                                         </ul>
268 268
                                     </div>
269 269
                                     <?php
270
-                                } ?>
270
+								} ?>
271 271
                             </div>
272 272
                             <div class="ticket-registrations-area">
273 273
                                 <h4 class="sub-section-title">
274 274
                                     <img class="icon" src="<?php
275
-                                    echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>"
275
+									echo esc_url_raw(EE_IMAGES_URL . 'users-16x16.png'); ?>"
276 276
                                     >
277 277
                                     <?php
278
-                                    echo esc_html__("Registration Details", "event_espresso"); ?>
278
+									echo esc_html__("Registration Details", "event_espresso"); ?>
279 279
                                     <span class="small-text link">[
280 280
                                 <a class="print_button noPrint" href="<?php echo esc_url_raw($edit_reg_info_url); ?>">
281 281
                                     <?php esc_html_e('edit', 'event_espresso'); ?>
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
                                 </h4>
286 286
                                 <ul class="ticket-registrations-list">
287 287
                                     <?php
288
-                                    foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
289
-                                        /* @var $registration EE_Registration */
290
-                                        $attendee = $registration->attendee();
291
-                                        $answers  = $registration->answers(
292
-                                            ['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
293
-                                        ); ?>
288
+									foreach ($registrations_per_line_item[ $line_item_id ] as $registration) {
289
+										/* @var $registration EE_Registration */
290
+										$attendee = $registration->attendee();
291
+										$answers  = $registration->answers(
292
+											['order_by' => ['Question.Question_Group_Question.QGQ_order' => 'ASC']]
293
+										); ?>
294 294
                                         <li class="ticket-registration">
295 295
                                             <table class="registration-details">
296 296
                                                 <tr class="odd">
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
                                                     </td>
306 306
                                                 </tr>
307 307
                                                 <?php
308
-                                                foreach ($event->question_groups() as $question_group) { ?>
308
+												foreach ($event->question_groups() as $question_group) { ?>
309 309
                                                     <tr>
310 310
                                                         <th>
311 311
                                                             <?php $question_group->e('QSG_name'); ?>
@@ -313,44 +313,44 @@  discard block
 block discarded – undo
313 313
                                                         <td></td>
314 314
                                                     </tr>
315 315
                                                     <?php $has_personal_info = false;
316
-                                                    foreach ($question_group->questions() as $question) {
317
-                                                        if (in_array($question->system_ID(), $questions_to_skip)) {
318
-                                                            $has_personal_info = true;
319
-                                                            continue;
320
-                                                        }
321
-                                                        ?>
316
+													foreach ($question_group->questions() as $question) {
317
+														if (in_array($question->system_ID(), $questions_to_skip)) {
318
+															$has_personal_info = true;
319
+															continue;
320
+														}
321
+														?>
322 322
                                                         <tr>
323 323
                                                             <th>
324 324
                                                                 <?php echo $question->display_text(
325
-                                                                ); // already escaped ?>
325
+																); // already escaped ?>
326 326
                                                             </th>
327 327
                                                             <td>
328 328
                                                                 <?php echo $registration->answer_value_to_question(
329
-                                                                    $question
330
-                                                                ); // already escaped?>
329
+																	$question
330
+																); // already escaped?>
331 331
                                                             </td>
332 332
                                                         </tr>
333 333
                                                     <?php }
334
-                                                    if ($has_personal_info) { ?>
334
+													if ($has_personal_info) { ?>
335 335
                                                         <tr>
336 336
                                                             <th><?php esc_html_e('Attendee', 'event_espresso'); ?></th>
337 337
                                                             <td>
338 338
                                                                 <?php
339
-                                                                echo sprintf(
340
-                                                                    esc_html__('%s (%s)', "event_espresso"),
341
-                                                                    esc_html($attendee->full_name()),
342
-                                                                    sanitize_email($attendee->email())
343
-                                                                ) ?>
339
+																echo sprintf(
340
+																	esc_html__('%s (%s)', "event_espresso"),
341
+																	esc_html($attendee->full_name()),
342
+																	sanitize_email($attendee->email())
343
+																) ?>
344 344
                                                             </td>
345 345
                                                         </tr>
346 346
                                                         <?php
347
-                                                    }
348
-                                                }
349
-                                                ?>
347
+													}
348
+												}
349
+												?>
350 350
                                             </table>
351 351
                                         </li>
352 352
                                         <?php
353
-                                    } ?>
353
+									} ?>
354 354
                                 </ul>
355 355
                             </div>
356 356
                         </div>
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
     <div class="grand-total-dv">
395 395
         <h2 class="grand-total">
396 396
             <?php
397
-            printf(
398
-                esc_html__("Grand Total: %s", "event_espresso"),
399
-                EEH_Template::format_currency($total_cost)
400
-            ); ?>
397
+			printf(
398
+				esc_html__("Grand Total: %s", "event_espresso"),
399
+				EEH_Template::format_currency($total_cost)
400
+			); ?>
401 401
         </h2>
402 402
     </div>
403 403
     <div class="payment-dv">
@@ -416,13 +416,13 @@  discard block
 block discarded – undo
416 416
             </thead>
417 417
             <tbody>
418 418
                 <?php
419
-                $c = false;
420
-                if (! empty($payments)) {
421
-                    foreach ($payments as $payment) {
422
-                        /* @var $payment EE_Payment */ ?>
419
+				$c = false;
420
+				if (! empty($payments)) {
421
+					foreach ($payments as $payment) {
422
+						/* @var $payment EE_Payment */ ?>
423 423
                         <tr class='item <?php echo(($c = ! $c)
424
-                            ? ' odd'
425
-                            : '') ?>'
424
+							? ' odd'
425
+							: '') ?>'
426 426
                         >
427 427
                             <td><?php $payment->e('PAY_gateway') ?></td>
428 428
                             <td><?php echo esc_html($payment->timestamp()); ?></td>
@@ -432,14 +432,14 @@  discard block
 block discarded – undo
432 432
                             <td class='item_r'><?php echo $payment->amount_no_code(); // already escaped ?></td>
433 433
                         </tr>
434 434
                     <?php }
435
-                } else { ?>
435
+				} else { ?>
436 436
                     <tr class='item'>
437 437
                         <td class='aln-cntr' colspan="6">
438 438
                             <?php
439
-                            esc_html_e(
440
-                                "No approved payments have been received.",
441
-                                'event_espresso'
442
-                            ) ?>
439
+							esc_html_e(
440
+								"No approved payments have been received.",
441
+								'event_espresso'
442
+							) ?>
443 443
                         </td>
444 444
                     </tr>
445 445
                 <?php } ?>
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
             <?php if ($venues_for_events) { ?>
477 477
                 <h2>
478 478
                     <?php
479
-                    echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
479
+					echo _n("Venue Details:", "Venues Details:", count($venues_for_events), "event_espresso"); ?>
480 480
                 </h2>
481 481
                 <table class="venue-list">
482 482
                     <?php foreach ($venues_for_events as $venue) { ?>
Please login to merge, or discard this patch.
admin/new/pricing/templates/event_tickets_metabox_main.template.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             </thead>
74 74
             <tbody class="datetime-editing-dtts-tbody">
75 75
             <?php
76
-            echo $datetime_rows; ?>
76
+			echo $datetime_rows; ?>
77 77
             </tbody>
78 78
         </table>
79 79
         <div style="clear:both"></div>
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
     <div style="clear:both"></div>
140 140
 
141 141
     <?php
142
-    if (isset($status_change_notice)) {
143
-        echo $status_change_notice;
144
-    }
145
-    ?>
142
+	if (isset($status_change_notice)) {
143
+		echo $status_change_notice;
144
+	}
145
+	?>
146 146
 
147 147
     <div class="available-tickets-container">
148 148
         <h3 class="event-tickets-datetimes-title">
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
                 </thead>
195 195
                 <tbody>
196 196
                 <?php
197
-                echo $ticket_rows; ?>
197
+				echo $ticket_rows; ?>
198 198
                 </tbody>
199 199
             </table> <!-- end .ticket-table -->
200 200
 
Please login to merge, or discard this patch.