Completed
Branch dev (1e1f5b)
by
unknown
10:49 queued 08:28
created
templates/txn_admin_details_main_meta_box_txn_details.template.php 1 patch
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -80,25 +80,25 @@  discard block
 block discarded – undo
80 80
     </div>
81 81
     <br class="clear" />
82 82
     <?php
83
-    $no_payments = $grand_raw_total > 0
84
-                   || $TXN_status !== EEM_Transaction::complete_status_code
85
-                   || ! empty($payments);
86
-    ?>
83
+	$no_payments = $grand_raw_total > 0
84
+				   || $TXN_status !== EEM_Transaction::complete_status_code
85
+				   || ! empty($payments);
86
+	?>
87 87
     <?php if ($attendee instanceof EE_Attendee && $no_payments) : ?>
88 88
         <?php $no_payment_text = $can_edit_payments
89
-            ? esc_html__(
90
-                'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
91
-                'event_espresso'
92
-            )
93
-            : esc_html__(
94
-                'No payments have been applied to this transaction yet.',
95
-                'event_espresso'
96
-            );
97
-        ?>
89
+			? esc_html__(
90
+				'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
91
+				'event_espresso'
92
+			)
93
+			: esc_html__(
94
+				'No payments have been applied to this transaction yet.',
95
+				'event_espresso'
96
+			);
97
+		?>
98 98
 
99 99
         <h3 class="admin-primary-mbox-h4 hdr-has-icon">
100 100
             <span class="ee-icon ee-icon-cash"></span><?php
101
-            esc_html_e('Payment Details', 'event_espresso'); ?>
101
+			esc_html_e('Payment Details', 'event_espresso'); ?>
102 102
         </h3>
103 103
 
104 104
         <div class="admin-primary-mbox-tbl-wrap">
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
                         <th class="jst-left"><?php esc_html_e('TXN&nbsp;ID / CHQ&nbsp;#', 'event_espresso'); ?></th>
115 115
                         <th class="jst-left"><?php esc_html_e('P.O. / S.O.&nbsp;#', 'event_espresso'); ?></th>
116 116
                         <th class="jst-left"><?php esc_html_e(
117
-                            'Notes / Extra&nbsp;Accounting',
118
-                            'event_espresso'
119
-                        ); ?></th>
117
+							'Notes / Extra&nbsp;Accounting',
118
+							'event_espresso'
119
+						); ?></th>
120 120
                         <!--<th class="jst-left"><?php esc_html_e('Details', 'event_espresso'); ?></th>-->
121 121
                         <th class="jst-cntr"><?php esc_html_e('Amount', 'event_espresso'); ?></th>
122 122
                     </tr>
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
                     <?php if ($payments) : ?>
126 126
                         <?php $payment_total = 0; ?>
127 127
                         <?php foreach ($payments as $PAY_ID => $payment) :
128
-                            if (! $payment instanceof EE_Payment) {
129
-                                continue;
130
-                            }
131
-                            $PAY_ID = absint($PAY_ID);
132
-                            $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ])
133
-                                ? wp_json_encode($existing_reg_payments[ $PAY_ID ])
134
-                                : '{}';
135
-                            $escaped_pay_id = esc_attr($PAY_ID);
136
-                            ?>
128
+							if (! $payment instanceof EE_Payment) {
129
+								continue;
130
+							}
131
+							$PAY_ID = absint($PAY_ID);
132
+							$existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ])
133
+								? wp_json_encode($existing_reg_payments[ $PAY_ID ])
134
+								: '{}';
135
+							$escaped_pay_id = esc_attr($PAY_ID);
136
+							?>
137 137
                             <tr id="txn-admin-payment-tr-<?php echo $escaped_pay_id; ?>">
138 138
                                 <td>
139 139
                 <span id="payment-status-<?php echo $escaped_pay_id; ?>"
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                                 <td class=" jst-rght">
175 175
                                     <div id="payment-id-<?php echo $escaped_pay_id; ?>">
176 176
                                         <?php echo $PAY_ID; // sanitized
177
-                                        ?>
177
+										?>
178 178
                                     </div>
179 179
                                 </td>
180 180
                                 <td class=" jst-left">
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
                                     </div>
189 189
                                     <div id="payment-gateway-<?php echo $escaped_pay_id; ?>">
190 190
                                         <?php echo $payment->payment_method() instanceof EE_Payment_Method
191
-                                            ? esc_html($payment->payment_method()->admin_name())
192
-                                            : esc_html__("Unknown", 'event_espresso'); ?>
191
+											? esc_html($payment->payment_method()->admin_name())
192
+											: esc_html__("Unknown", 'event_espresso'); ?>
193 193
                                     </div>
194 194
                                     <div id="payment-gateway-id-<?php echo $escaped_pay_id; ?>"
195 195
                                          class="hidden"
196 196
                                     >
197 197
                                         <?php echo $payment->payment_method() instanceof EE_Payment_Method
198
-                                            ? esc_html($payment->payment_method()->ID())
199
-                                            : 0; ?>
198
+											? esc_html($payment->payment_method()->ID())
199
+											: 0; ?>
200 200
                                     </div>
201 201
                                 </td>
202 202
                                 <td class=" jst-left">
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
                                 </td>
222 222
                                 <td class=" jst-rght">
223 223
                                     <?php
224
-                                    $payment_class = $payment->amount() > 0
225
-                                        ? 'txn-admin-payment-status-' . $payment->STS_ID()
226
-                                        : 'txn-admin-payment-status-PDC';
227
-                                    ?>
224
+									$payment_class = $payment->amount() > 0
225
+										? 'txn-admin-payment-status-' . $payment->STS_ID()
226
+										: 'txn-admin-payment-status-PDC';
227
+									?>
228 228
                                     <span class="<?php echo esc_attr($payment_class); ?>">
229 229
                                         <span id="payment-amount-<?php echo $escaped_pay_id; ?>" style="display:inline;">
230 230
                                         <?php echo EEH_Template::format_currency(
231
-                                            $payment->amount(),
232
-                                            false,
233
-                                            false
234
-                                        ); // already escaped
235
-                                        ?>
231
+											$payment->amount(),
232
+											false,
233
+											false
234
+										); // already escaped
235
+										?>
236 236
                                         </span>
237 237
                                     </span>
238 238
                                 </td>
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
                             <?php $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; ?>
241 241
                         <?php endforeach; ?>
242 242
                         <?php $pay_totals_class = $payment_total > $grand_raw_total
243
-                            ? ' important-notice'
244
-                            : '';
245
-                        ?>
243
+							? ' important-notice'
244
+							: '';
245
+						?>
246 246
                         <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
247 247
                             <td class=" jst-rght" colspan="10">
248 248
                                 <span class="important-notice"><?php echo $no_payment_text; // already escaped ?></span>
@@ -254,28 +254,28 @@  discard block
 block discarded – undo
254 254
                             <th class=" jst-rght" colspan="9">
255 255
                         <span id="payments-total-spn">
256 256
                         <?php
257
-                        $overpaid = $payment_total > $grand_raw_total
258
-                            ? '<span id="overpaid">'
259
-                              . __('This transaction has been overpaid ! ', 'event_espresso')
260
-                              . '</span>'
261
-                            : '';
262
-                        echo esc_html(
263
-                            $overpaid
264
-                            . sprintf(
265
-                                __('Payments Total %s', 'event_espresso'),
266
-                                '(' . EE_Registry::instance()->CFG->currency->code . ')'
267
-                            )
268
-                        ); ?>
257
+						$overpaid = $payment_total > $grand_raw_total
258
+							? '<span id="overpaid">'
259
+							  . __('This transaction has been overpaid ! ', 'event_espresso')
260
+							  . '</span>'
261
+							: '';
262
+						echo esc_html(
263
+							$overpaid
264
+							. sprintf(
265
+								__('Payments Total %s', 'event_espresso'),
266
+								'(' . EE_Registry::instance()->CFG->currency->code . ')'
267
+							)
268
+						); ?>
269 269
                         </span>
270 270
                             </th>
271 271
                             <th class=" jst-rght">
272 272
                         <span id="txn-admin-payment-total">
273 273
                         <?php
274
-                        echo EEH_Template::format_currency(
275
-                            $payment_total,
276
-                            false,
277
-                            false
278
-                        ); // already escaped ?>
274
+						echo EEH_Template::format_currency(
275
+							$payment_total,
276
+							false,
277
+							false
278
+						); // already escaped ?>
279 279
                         </span>
280 280
                             </th>
281 281
                         </tr>
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
         <ul id="txn-admin-payment-options-ul">
360 360
             <?php if ($can_edit_payments) :
361
-                ?>
361
+				?>
362 362
                 <li>
363 363
                     <a id="display-txn-admin-apply-payment"
364 364
                        class="button-primary no-icon no-hide"
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
                 </li>
384 384
             <?php endif; ?>
385 385
             <?php
386
-            // Allows extend the fields at actions area.
387
-            do_action(
388
-                'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons',
389
-                $can_edit_payments
390
-            );
391
-            ?>
386
+			// Allows extend the fields at actions area.
387
+			do_action(
388
+				'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons',
389
+				$can_edit_payments
390
+			);
391
+			?>
392 392
         </ul>
393 393
         <br class="clear" />
394 394
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             >
400 400
                 <div class="ee-icon ee-icon-cash-add float-left"></div>
401 401
                 <?php
402
-                echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?>
402
+				echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?>
403 403
             </h2>
404 404
 
405 405
             <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -407,23 +407,23 @@  discard block
 block discarded – undo
407 407
             >
408 408
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
409 409
                 <?php
410
-                printf(
411
-                    esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
412
-                    '<span></span>',
413
-                    $txn_nmbr['value']
414
-                );
415
-                ?>
410
+				printf(
411
+					esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
412
+					'<span></span>',
413
+					$txn_nmbr['value']
414
+				);
415
+				?>
416 416
             </h2>
417 417
 
418 418
             <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;">
419 419
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
420 420
                 <?php
421
-                printf(
422
-                    esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
423
-                    '<span></span>',
424
-                    $txn_nmbr['value']
425
-                );
426
-                ?>
421
+				printf(
422
+					esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
423
+					'<span></span>',
424
+					$txn_nmbr['value']
425
+				);
426
+				?>
427 427
             </h2>
428 428
 
429 429
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
             >
432 432
                 <div class="ee-icon ee-icon-cash-remove float-left"></div>
433 433
                 <?php
434
-                echo esc_html__('Apply a Refund to Transaction #', 'event_espresso');
435
-                echo esc_html($txn_nmbr['value']);
436
-                ?>
434
+				echo esc_html__('Apply a Refund to Transaction #', 'event_espresso');
435
+				echo esc_html($txn_nmbr['value']);
436
+				?>
437 437
             </h2>
438 438
 
439 439
             <form name="txn-admin-apply-payment-frm"
@@ -532,29 +532,29 @@  discard block
 block discarded – undo
532 532
                             >
533 533
                                 <?php foreach ($payment_methods as $method) : ?>
534 534
                                     <?php
535
-                                    $selected = $method->slug() == 'cash'
536
-                                        ? ' selected="selected"'
537
-                                        : '';
538
-                                    ?>
535
+									$selected = $method->slug() == 'cash'
536
+										? ' selected="selected"'
537
+										: '';
538
+									?>
539 539
                                     <option id="payment-method-opt-<?php echo esc_attr($method->slug()); ?>"
540 540
                                             value="<?php echo esc_attr($method->ID()); ?>"
541 541
                                         <?php echo $selected; ?>
542 542
                                     >
543 543
                                         <?php
544
-                                        echo esc_html(
545
-                                            sanitize_key($method->admin_desc())
546
-                                                ? substr($method->admin_desc(), 0, 128)
547
-                                                : $method->admin_name()
548
-                                        );
549
-                                        ?>&nbsp;&nbsp;
544
+										echo esc_html(
545
+											sanitize_key($method->admin_desc())
546
+												? substr($method->admin_desc(), 0, 128)
547
+												: $method->admin_name()
548
+										);
549
+										?>&nbsp;&nbsp;
550 550
                                     </option>
551 551
                                 <?php endforeach; ?>
552 552
                             </select>
553 553
                             <p class="description">
554 554
                                 <?php esc_html_e(
555
-                                    'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
556
-                                    'event_espresso'
557
-                                ); ?>
555
+									'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
556
+									'event_espresso'
557
+								); ?>
558 558
                             </p>
559 559
                         </div>
560 560
 
@@ -562,9 +562,9 @@  discard block
 block discarded – undo
562 562
                             <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row">
563 563
                                 <label for="txn-admin-payment-txn-id-chq-nmbr-inp" class="">
564 564
                                     <?php esc_html_e(
565
-                                        'TXN ID / CHQ #',
566
-                                        'event_espresso'
567
-                                    ); ?>
565
+										'TXN ID / CHQ #',
566
+										'event_espresso'
567
+									); ?>
568 568
                                 </label>
569 569
                                 <input name="txn_admin_payment[txn_id_chq_nmbr]"
570 570
                                        id="txn-admin-payment-txn-id-chq-nmbr-inp"
@@ -573,9 +573,9 @@  discard block
 block discarded – undo
573 573
                                 />
574 574
                                 <p class="description">
575 575
                                     <?php esc_html_e(
576
-                                        'The Transaction ID sent back from the payment gateway, or the Cheque #',
577
-                                        'event_espresso'
578
-                                    ); ?>
576
+										'The Transaction ID sent back from the payment gateway, or the Cheque #',
577
+										'event_espresso'
578
+									); ?>
579 579
                                 </p>
580 580
                             </div>
581 581
                         </div>
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
                                 />
593 593
                                 <p class="description">
594 594
                                     <?php esc_html_e(
595
-                                        'The gateway response string (optional)',
596
-                                        'event_espresso'
597
-                                    ); ?>
595
+										'The gateway response string (optional)',
596
+										'event_espresso'
597
+									); ?>
598 598
                                 </p>
599 599
                             </div>
600 600
                         </div>
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
                             <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row">
604 604
                                 <label for="txn-admin-payment-status-slct" class="">
605 605
                                     <?php esc_html_e(
606
-                                        'Payment Status',
607
-                                        'event_espresso'
608
-                                    ); ?>
606
+										'Payment Status',
607
+										'event_espresso'
608
+									); ?>
609 609
                                 </label>
610 610
                                 <select name="txn_admin_payment[status]"
611 611
                                         id="txn-admin-payment-status-slct"
@@ -614,10 +614,10 @@  discard block
 block discarded – undo
614 614
                                 >
615 615
                                     <?php foreach ($payment_status as $STS_ID => $STS_code) : ?>
616 616
                                         <?php
617
-                                        $selected = $STS_ID == 'PAP'
618
-                                            ? ' selected="selected"'
619
-                                            : '';
620
-                                        ?>
617
+										$selected = $STS_ID == 'PAP'
618
+											? ' selected="selected"'
619
+											: '';
620
+										?>
621 621
                                         <option id="payment-status-opt-<?php echo esc_attr($STS_ID); ?>"
622 622
                                                 value="<?php echo esc_attr($STS_ID); ?>"
623 623
                                             <?php echo $selected; ?>
@@ -628,10 +628,10 @@  discard block
 block discarded – undo
628 628
                                 </select>
629 629
                                 <p class="description">
630 630
                                     <?php
631
-                                    esc_html_e(
632
-                                        'Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
633
-                                        'event_espresso'
634
-                                    ); ?>
631
+									esc_html_e(
632
+										'Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
633
+										'event_espresso'
634
+									); ?>
635 635
                                 </p>
636 636
                             </div>
637 637
                         </div>
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
                             />
649 649
                             <p class="description">
650 650
                                 <?php esc_html_e(
651
-                                    'The Purchase or Sales Order Number if any (optional)',
652
-                                    'event_espresso'
653
-                                ); ?>
651
+									'The Purchase or Sales Order Number if any (optional)',
652
+									'event_espresso'
653
+								); ?>
654 654
                             </p>
655 655
                         </div>
656 656
 
@@ -671,9 +671,9 @@  discard block
 block discarded – undo
671 671
                             />
672 672
                             <p class="description">
673 673
                                 <?php esc_html_e(
674
-                                    'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
675
-                                    'event_espresso'
676
-                                ); ?>
674
+									'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
675
+									'event_espresso'
676
+								); ?>
677 677
                             </p>
678 678
                         </div>
679 679
 
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
                                 <?php esc_html_e('Change Registration Status?', 'event_espresso'); ?>
707 707
                             </label>
708 708
                             <?php
709
-                            echo $status_change_select; // already escaped ?>
709
+							echo $status_change_select; // already escaped ?>
710 710
                             <p class="description">
711 711
                                 <?php esc_html_e(
712
-                                    'If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
713
-                                    'event_espresso'
714
-                                ); ?>
712
+									'If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
713
+									'event_espresso'
714
+								); ?>
715 715
                             </p>
716 716
                             <br />
717 717
                         </div>
@@ -742,14 +742,14 @@  discard block
 block discarded – undo
742 742
                             <br class="clear-float" />
743 743
                             <p class="description">
744 744
                                 <?php printf(
745
-                                    esc_html__(
746
-                                        'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
747
-                                        'event_espresso'
748
-                                    ),
749
-                                    '<strong>',
750
-                                    '</strong>',
751
-                                    '<br />'
752
-                                ); ?>
745
+									esc_html__(
746
+										'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
747
+										'event_espresso'
748
+									),
749
+									'<strong>',
750
+									'</strong>',
751
+									'<br />'
752
+								); ?>
753 753
                             </p>
754 754
                         </div>
755 755
                         <div class="clear"></div>
@@ -814,10 +814,10 @@  discard block
 block discarded – undo
814 814
             >
815 815
                 <span class="ee-icon ee-icon-cash-add"></span>
816 816
                 <?php printf(
817
-                    esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'),
818
-                    $txn_nmbr['value']
819
-                );
820
-                ?>
817
+					esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'),
818
+					$txn_nmbr['value']
819
+				);
820
+				?>
821 821
             </h2>
822 822
 
823 823
             <form name="txn-admin-delete-payment-frm"
@@ -853,13 +853,13 @@  discard block
 block discarded – undo
853 853
                             <?php echo $delete_status_change_select; // already escaped ?>
854 854
                             <p class="description">
855 855
                                 <?php printf(
856
-                                    esc_html__(
857
-                                        'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
858
-                                        'event_espresso'
859
-                                    ),
860
-                                    '<strong>',
861
-                                    '</strong>'
862
-                                ); ?>
856
+									esc_html__(
857
+										'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
858
+										'event_espresso'
859
+									),
860
+									'<strong>',
861
+									'</strong>'
862
+								); ?>
863 863
                             </p>
864 864
                         </div>
865 865
 
@@ -874,10 +874,10 @@  discard block
 block discarded – undo
874 874
                             />
875 875
                             <p class="description">
876 876
                                 <?php
877
-                                esc_html_e(
878
-                                    'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
879
-                                    'event_espresso'
880
-                                ); ?>
877
+								esc_html_e(
878
+									'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
879
+									'event_espresso'
880
+								); ?>
881 881
                             </p>
882 882
                         </div>
883 883
                         <div class="clear"></div>
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
     <?php endif; // $grand_raw_total > 0?>
911 911
 
912 912
     <?php if (WP_DEBUG) {
913
-        $delivered_messages = get_option('EED_Messages__payment', []);
914
-        if (isset($delivered_messages[ $TXN_ID ])) { ?>
913
+		$delivered_messages = get_option('EED_Messages__payment', []);
914
+		if (isset($delivered_messages[ $TXN_ID ])) { ?>
915 915
             <h4 class="admin-primary-mbox-h4 hdr-has-icon">
916 916
                 <span class="dashicons dashicons-email-alt"></span>
917 917
                 <?php esc_html_e('Messages Sent to Primary Registrant', 'event_espresso'); ?>
@@ -923,39 +923,39 @@  discard block
 block discarded – undo
923 923
                             <th class="jst-left"><?php esc_html_e('Date & Time', 'event_espresso'); ?></th>
924 924
                             <th class="jst-left"><?php esc_html_e('Message Type', 'event_espresso'); ?></th>
925 925
                             <th class="jst-left"><?php esc_html_e(
926
-                                'Payment Status Upon Sending',
927
-                                'event_espresso'
928
-                            ); ?></th>
926
+								'Payment Status Upon Sending',
927
+								'event_espresso'
928
+							); ?></th>
929 929
                             <th class="jst-left"><?php esc_html_e('TXN Status Upon Sending', 'event_espresso'); ?></th>
930 930
                         </tr>
931 931
                     </thead>
932 932
                     <tbody>
933 933
                         <?php
934
-                        foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) :
935
-                            ?>
934
+						foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) :
935
+							?>
936 936
                             <tr>
937 937
                                 <td class="jst-left">
938 938
                                     <?php echo esc_html(
939
-                                        date(
940
-                                            get_option('date_format') . ' ' . get_option('time_format'),
941
-                                            ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))
942
-                                        )
943
-                                    ); ?>
939
+										date(
940
+											get_option('date_format') . ' ' . get_option('time_format'),
941
+											($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))
942
+										)
943
+									); ?>
944 944
                                 </td>
945 945
                                 <td class="jst-left"><?php
946
-                                    echo isset($delivered_message['message_type'])
947
-                                        ? esc_html($delivered_message['message_type'])
948
-                                        : ''; ?>
946
+									echo isset($delivered_message['message_type'])
947
+										? esc_html($delivered_message['message_type'])
948
+										: ''; ?>
949 949
                                 </td>
950 950
                                 <td class="jst-left"><?php
951
-                                    echo isset($delivered_message['pay_status'])
952
-                                        ? esc_html($delivered_message['pay_status'])
953
-                                        : ''; ?>
951
+									echo isset($delivered_message['pay_status'])
952
+										? esc_html($delivered_message['pay_status'])
953
+										: ''; ?>
954 954
                                 </td>
955 955
                                 <td class="jst-left"><?php
956
-                                    echo isset($delivered_message['txn_status'])
957
-                                        ? esc_html($delivered_message['txn_status'])
958
-                                        : ''; ?>
956
+									echo isset($delivered_message['txn_status'])
957
+										? esc_html($delivered_message['txn_status'])
958
+										: ''; ?>
959 959
                                 </td>
960 960
                             </tr>
961 961
                         <?php endforeach; // $delivered_messages?>
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
                 </table>
964 964
             </div>
965 965
             <?php
966
-        }
967
-    }
968
-    ?>
966
+		}
967
+	}
968
+	?>
969 969
 </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -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 $VID:$
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 $VID:$
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 esc_attr($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 esc_attr($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="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="selected"' : '';
2684
+							?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo $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 $VID:$
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 $VID:$
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 $VID:$
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 $VID:$
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   $VID:$
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   $VID:$
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 $VID:$
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 $VID:$
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   $VID:$
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 $VID:$
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 $VID:$
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 $VID:$
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 $VID:$
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 $VID:$
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 $VID:$
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   $VID:$
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   $VID:$
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 $VID:$
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 $VID:$
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   $VID:$
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 $VID:$
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 $VID:$
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.
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 esc_attr($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="selected"' : '';
2684 2684
                             ?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo $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.
core/EE_Config.core.php 1 patch
Indentation   +3215 added lines, -3215 removed lines patch added patch discarded remove patch
@@ -19,2546 +19,2546 @@  discard block
 block discarded – undo
19 19
 final class EE_Config implements ResettableInterface
20 20
 {
21 21
 
22
-    const OPTION_NAME = 'ee_config';
23
-
24
-    const LOG_NAME = 'ee_config_log';
25
-
26
-    const LOG_LENGTH = 100;
27
-
28
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
29
-
30
-    /**
31
-     *    instance of the EE_Config object
32
-     *
33
-     * @var    EE_Config $_instance
34
-     * @access    private
35
-     */
36
-    private static $_instance;
37
-
38
-    /**
39
-     * @var boolean $_logging_enabled
40
-     */
41
-    private static $_logging_enabled = false;
42
-
43
-    /**
44
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
45
-     */
46
-    private $legacy_shortcodes_manager;
47
-
48
-    /**
49
-     * An StdClass whose property names are addon slugs,
50
-     * and values are their config classes
51
-     *
52
-     * @var StdClass
53
-     */
54
-    public $addons;
55
-
56
-    /**
57
-     * @var EE_Admin_Config
58
-     */
59
-    public $admin;
60
-
61
-    /**
62
-     * @var EE_Core_Config
63
-     */
64
-    public $core;
65
-
66
-    /**
67
-     * @var EE_Currency_Config
68
-     */
69
-    public $currency;
70
-
71
-    /**
72
-     * @var EE_Organization_Config
73
-     */
74
-    public $organization;
75
-
76
-    /**
77
-     * @var EE_Registration_Config
78
-     */
79
-    public $registration;
80
-
81
-    /**
82
-     * @var EE_Template_Config
83
-     */
84
-    public $template_settings;
85
-
86
-    /**
87
-     * Holds EE environment values.
88
-     *
89
-     * @var EE_Environment_Config
90
-     */
91
-    public $environment;
92
-
93
-    /**
94
-     * settings pertaining to Google maps
95
-     *
96
-     * @var EE_Map_Config
97
-     */
98
-    public $map_settings;
99
-
100
-    /**
101
-     * settings pertaining to Taxes
102
-     *
103
-     * @var EE_Tax_Config
104
-     */
105
-    public $tax_settings;
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-    /**
146
-     * @singleton method used to instantiate class object
147
-     * @access    public
148
-     * @return EE_Config instance
149
-     */
150
-    public static function instance()
151
-    {
152
-        // check if class object is instantiated, and instantiated properly
153
-        if (! self::$_instance instanceof EE_Config) {
154
-            self::$_instance = new self();
155
-        }
156
-        return self::$_instance;
157
-    }
158
-
159
-
160
-    /**
161
-     * Resets the config
162
-     *
163
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
164
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
165
-     *                               reflect its state in the database
166
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
167
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
168
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
169
-     *                               site was put into maintenance mode)
170
-     * @return EE_Config
171
-     */
172
-    public static function reset($hard_reset = false, $reinstantiate = true)
173
-    {
174
-        if (self::$_instance instanceof EE_Config) {
175
-            if ($hard_reset) {
176
-                self::$_instance->legacy_shortcodes_manager = null;
177
-                self::$_instance->_addon_option_names = array();
178
-                self::$_instance->_initialize_config();
179
-                self::$_instance->update_espresso_config();
180
-            }
181
-            self::$_instance->update_addon_option_names();
182
-        }
183
-        self::$_instance = null;
184
-        // we don't need to reset the static properties imo because those should
185
-        // only change when a module is added or removed. Currently we don't
186
-        // support removing a module during a request when it previously existed
187
-        if ($reinstantiate) {
188
-            return self::instance();
189
-        } else {
190
-            return null;
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     *    class constructor
197
-     *
198
-     * @access    private
199
-     */
200
-    private function __construct()
201
-    {
202
-        do_action('AHEE__EE_Config__construct__begin', $this);
203
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
204
-        // setup empty config classes
205
-        $this->_initialize_config();
206
-        // load existing EE site settings
207
-        $this->_load_core_config();
208
-        // confirm everything loaded correctly and set filtered defaults if not
209
-        $this->_verify_config();
210
-        //  register shortcodes and modules
211
-        add_action(
212
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
213
-            array($this, 'register_shortcodes_and_modules'),
214
-            999
215
-        );
216
-        //  initialize shortcodes and modules
217
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
218
-        // register widgets
219
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
220
-        // shutdown
221
-        add_action('shutdown', array($this, 'shutdown'), 10);
222
-        // construct__end hook
223
-        do_action('AHEE__EE_Config__construct__end', $this);
224
-        // hardcoded hack
225
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
226
-    }
227
-
228
-
229
-    /**
230
-     * @return boolean
231
-     */
232
-    public static function logging_enabled()
233
-    {
234
-        return self::$_logging_enabled;
235
-    }
236
-
237
-
238
-    /**
239
-     * use to get the current theme if needed from static context
240
-     *
241
-     * @return string current theme set.
242
-     */
243
-    public static function get_current_theme()
244
-    {
245
-        return isset(self::$_instance->template_settings->current_espresso_theme)
246
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
247
-    }
248
-
249
-
250
-    /**
251
-     *        _initialize_config
252
-     *
253
-     * @access private
254
-     * @return void
255
-     */
256
-    private function _initialize_config()
257
-    {
258
-        EE_Config::trim_log();
259
-        // set defaults
260
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
261
-        $this->addons = new stdClass();
262
-        // set _module_route_map
263
-        EE_Config::$_module_route_map = array();
264
-        // set _module_forward_map
265
-        EE_Config::$_module_forward_map = array();
266
-        // set _module_view_map
267
-        EE_Config::$_module_view_map = array();
268
-    }
269
-
270
-
271
-    /**
272
-     *        load core plugin configuration
273
-     *
274
-     * @access private
275
-     * @return void
276
-     */
277
-    private function _load_core_config()
278
-    {
279
-        // load_core_config__start hook
280
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
281
-        $espresso_config = $this->get_espresso_config();
282
-        foreach ($espresso_config as $config => $settings) {
283
-            // load_core_config__start hook
284
-            $settings = apply_filters(
285
-                'FHEE__EE_Config___load_core_config__config_settings',
286
-                $settings,
287
-                $config,
288
-                $this
289
-            );
290
-            if (is_object($settings) && property_exists($this, $config)) {
291
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
292
-                // call configs populate method to ensure any defaults are set for empty values.
293
-                if (method_exists($settings, 'populate')) {
294
-                    $this->{$config}->populate();
295
-                }
296
-                if (method_exists($settings, 'do_hooks')) {
297
-                    $this->{$config}->do_hooks();
298
-                }
299
-            }
300
-        }
301
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
302
-            $this->update_espresso_config();
303
-        }
304
-        // load_core_config__end hook
305
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
306
-    }
307
-
308
-
309
-    /**
310
-     *    _verify_config
311
-     *
312
-     * @access    protected
313
-     * @return    void
314
-     */
315
-    protected function _verify_config()
316
-    {
317
-        $this->core = $this->core instanceof EE_Core_Config
318
-            ? $this->core
319
-            : new EE_Core_Config();
320
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
321
-        $this->organization = $this->organization instanceof EE_Organization_Config
322
-            ? $this->organization
323
-            : new EE_Organization_Config();
324
-        $this->organization = apply_filters(
325
-            'FHEE__EE_Config___initialize_config__organization',
326
-            $this->organization
327
-        );
328
-        $this->currency = $this->currency instanceof EE_Currency_Config
329
-            ? $this->currency
330
-            : new EE_Currency_Config();
331
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
332
-        $this->registration = $this->registration instanceof EE_Registration_Config
333
-            ? $this->registration
334
-            : new EE_Registration_Config();
335
-        $this->registration = apply_filters(
336
-            'FHEE__EE_Config___initialize_config__registration',
337
-            $this->registration
338
-        );
339
-        $this->admin = $this->admin instanceof EE_Admin_Config
340
-            ? $this->admin
341
-            : new EE_Admin_Config();
342
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
343
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
344
-            ? $this->template_settings
345
-            : new EE_Template_Config();
346
-        $this->template_settings = apply_filters(
347
-            'FHEE__EE_Config___initialize_config__template_settings',
348
-            $this->template_settings
349
-        );
350
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
351
-            ? $this->map_settings
352
-            : new EE_Map_Config();
353
-        $this->map_settings = apply_filters(
354
-            'FHEE__EE_Config___initialize_config__map_settings',
355
-            $this->map_settings
356
-        );
357
-        $this->environment = $this->environment instanceof EE_Environment_Config
358
-            ? $this->environment
359
-            : new EE_Environment_Config();
360
-        $this->environment = apply_filters(
361
-            'FHEE__EE_Config___initialize_config__environment',
362
-            $this->environment
363
-        );
364
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
365
-            ? $this->tax_settings
366
-            : new EE_Tax_Config();
367
-        $this->tax_settings = apply_filters(
368
-            'FHEE__EE_Config___initialize_config__tax_settings',
369
-            $this->tax_settings
370
-        );
371
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
372
-        $this->messages = $this->messages instanceof EE_Messages_Config
373
-            ? $this->messages
374
-            : new EE_Messages_Config();
375
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
376
-            ? $this->gateway
377
-            : new EE_Gateway_Config();
378
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
379
-        $this->legacy_shortcodes_manager = null;
380
-    }
381
-
382
-
383
-    /**
384
-     *    get_espresso_config
385
-     *
386
-     * @access    public
387
-     * @return    array of espresso config stuff
388
-     */
389
-    public function get_espresso_config()
390
-    {
391
-        // grab espresso configuration
392
-        return apply_filters(
393
-            'FHEE__EE_Config__get_espresso_config__CFG',
394
-            get_option(EE_Config::OPTION_NAME, array())
395
-        );
396
-    }
397
-
398
-
399
-    /**
400
-     *    double_check_config_comparison
401
-     *
402
-     * @access    public
403
-     * @param string $option
404
-     * @param        $old_value
405
-     * @param        $value
406
-     */
407
-    public function double_check_config_comparison($option = '', $old_value, $value)
408
-    {
409
-        // make sure we're checking the ee config
410
-        if ($option === EE_Config::OPTION_NAME) {
411
-            // run a loose comparison of the old value against the new value for type and properties,
412
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
413
-            if ($value != $old_value) {
414
-                // if they are NOT the same, then remove the hook,
415
-                // which means the subsequent update results will be based solely on the update query results
416
-                // the reason we do this is because, as stated above,
417
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
418
-                // this happens PRIOR to serialization and any subsequent update.
419
-                // If values are found to match their previous old value,
420
-                // then WP bails before performing any update.
421
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
422
-                // it just pulled from the db, with the one being passed to it (which will not match).
423
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
424
-                // MySQL MAY ALSO NOT perform the update because
425
-                // the string it sees in the db looks the same as the new one it has been passed!!!
426
-                // This results in the query returning an "affected rows" value of ZERO,
427
-                // which gets returned immediately by WP update_option and looks like an error.
428
-                remove_action('update_option', array($this, 'check_config_updated'));
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-    /**
435
-     *    update_espresso_config
436
-     *
437
-     * @access   public
438
-     */
439
-    protected function _reset_espresso_addon_config()
440
-    {
441
-        $this->_addon_option_names = array();
442
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
443
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
444
-            if ($addon_config_obj instanceof EE_Config_Base) {
445
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
446
-            }
447
-            $this->addons->{$addon_name} = null;
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     *    update_espresso_config
454
-     *
455
-     * @access   public
456
-     * @param   bool $add_success
457
-     * @param   bool $add_error
458
-     * @return   bool
459
-     */
460
-    public function update_espresso_config($add_success = false, $add_error = true)
461
-    {
462
-        // don't allow config updates during WP heartbeats
463
-        /** @var RequestInterface $request */
464
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
465
-        if ($request->isWordPressHeartbeat()) {
466
-            return false;
467
-        }
468
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
469
-        // $clone = clone( self::$_instance );
470
-        // self::$_instance = NULL;
471
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
472
-        $this->_reset_espresso_addon_config();
473
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
474
-        // but BEFORE the actual update occurs
475
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
476
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
477
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
478
-        $this->legacy_shortcodes_manager = null;
479
-        // now update "ee_config"
480
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
481
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
482
-        EE_Config::log(EE_Config::OPTION_NAME);
483
-        // if not saved... check if the hook we just added still exists;
484
-        // if it does, it means one of two things:
485
-        // that update_option bailed at the($value === $old_value) conditional,
486
-        // or...
487
-        // the db update query returned 0 rows affected
488
-        // (probably because the data  value was the same from it's perspective)
489
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
490
-        // but just means no update occurred, so don't display an error to the user.
491
-        // BUT... if update_option returns FALSE, AND the hook is missing,
492
-        // then it means that something truly went wrong
493
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
494
-        // remove our action since we don't want it in the system anymore
495
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
496
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
497
-        // self::$_instance = $clone;
498
-        // unset( $clone );
499
-        // if config remains the same or was updated successfully
500
-        if ($saved) {
501
-            if ($add_success) {
502
-                EE_Error::add_success(
503
-                    esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
504
-                    __FILE__,
505
-                    __FUNCTION__,
506
-                    __LINE__
507
-                );
508
-            }
509
-            return true;
510
-        } else {
511
-            if ($add_error) {
512
-                EE_Error::add_error(
513
-                    esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
514
-                    __FILE__,
515
-                    __FUNCTION__,
516
-                    __LINE__
517
-                );
518
-            }
519
-            return false;
520
-        }
521
-    }
522
-
523
-
524
-    /**
525
-     *    _verify_config_params
526
-     *
527
-     * @access    private
528
-     * @param    string         $section
529
-     * @param    string         $name
530
-     * @param    string         $config_class
531
-     * @param    EE_Config_Base $config_obj
532
-     * @param    array          $tests_to_run
533
-     * @param    bool           $display_errors
534
-     * @return    bool    TRUE on success, FALSE on fail
535
-     */
536
-    private function _verify_config_params(
537
-        $section = '',
538
-        $name = '',
539
-        $config_class = '',
540
-        $config_obj = null,
541
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
542
-        $display_errors = true
543
-    ) {
544
-        try {
545
-            foreach ($tests_to_run as $test) {
546
-                switch ($test) {
547
-                    // TEST #1 : check that section was set
548
-                    case 1:
549
-                        if (empty($section)) {
550
-                            if ($display_errors) {
551
-                                throw new EE_Error(
552
-                                    sprintf(
553
-                                        esc_html__(
554
-                                            'No configuration section has been provided while attempting to save "%s".',
555
-                                            'event_espresso'
556
-                                        ),
557
-                                        $config_class
558
-                                    )
559
-                                );
560
-                            }
561
-                            return false;
562
-                        }
563
-                        break;
564
-                    // TEST #2 : check that settings section exists
565
-                    case 2:
566
-                        if (! isset($this->{$section})) {
567
-                            if ($display_errors) {
568
-                                throw new EE_Error(
569
-                                    sprintf(
570
-                                        esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
571
-                                        $section
572
-                                    )
573
-                                );
574
-                            }
575
-                            return false;
576
-                        }
577
-                        break;
578
-                    // TEST #3 : check that section is the proper format
579
-                    case 3:
580
-                        if (
581
-                            ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
582
-                        ) {
583
-                            if ($display_errors) {
584
-                                throw new EE_Error(
585
-                                    sprintf(
586
-                                        esc_html__(
587
-                                            'The "%s" configuration settings have not been formatted correctly.',
588
-                                            'event_espresso'
589
-                                        ),
590
-                                        $section
591
-                                    )
592
-                                );
593
-                            }
594
-                            return false;
595
-                        }
596
-                        break;
597
-                    // TEST #4 : check that config section name has been set
598
-                    case 4:
599
-                        if (empty($name)) {
600
-                            if ($display_errors) {
601
-                                throw new EE_Error(
602
-                                    esc_html__(
603
-                                        'No name has been provided for the specific configuration section.',
604
-                                        'event_espresso'
605
-                                    )
606
-                                );
607
-                            }
608
-                            return false;
609
-                        }
610
-                        break;
611
-                    // TEST #5 : check that a config class name has been set
612
-                    case 5:
613
-                        if (empty($config_class)) {
614
-                            if ($display_errors) {
615
-                                throw new EE_Error(
616
-                                    esc_html__(
617
-                                        'No class name has been provided for the specific configuration section.',
618
-                                        'event_espresso'
619
-                                    )
620
-                                );
621
-                            }
622
-                            return false;
623
-                        }
624
-                        break;
625
-                    // TEST #6 : verify config class is accessible
626
-                    case 6:
627
-                        if (! class_exists($config_class)) {
628
-                            if ($display_errors) {
629
-                                throw new EE_Error(
630
-                                    sprintf(
631
-                                        esc_html__(
632
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
633
-                                            'event_espresso'
634
-                                        ),
635
-                                        $config_class
636
-                                    )
637
-                                );
638
-                            }
639
-                            return false;
640
-                        }
641
-                        break;
642
-                    // TEST #7 : check that config has even been set
643
-                    case 7:
644
-                        if (! isset($this->{$section}->{$name})) {
645
-                            if ($display_errors) {
646
-                                throw new EE_Error(
647
-                                    sprintf(
648
-                                        esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
649
-                                        $section,
650
-                                        $name
651
-                                    )
652
-                                );
653
-                            }
654
-                            return false;
655
-                        } else {
656
-                            // and make sure it's not serialized
657
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
658
-                        }
659
-                        break;
660
-                    // TEST #8 : check that config is the requested type
661
-                    case 8:
662
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
663
-                            if ($display_errors) {
664
-                                throw new EE_Error(
665
-                                    sprintf(
666
-                                        esc_html__(
667
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
668
-                                            'event_espresso'
669
-                                        ),
670
-                                        $section,
671
-                                        $name,
672
-                                        $config_class
673
-                                    )
674
-                                );
675
-                            }
676
-                            return false;
677
-                        }
678
-                        break;
679
-                    // TEST #9 : verify config object
680
-                    case 9:
681
-                        if (! $config_obj instanceof EE_Config_Base) {
682
-                            if ($display_errors) {
683
-                                throw new EE_Error(
684
-                                    sprintf(
685
-                                        esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
686
-                                        print_r($config_obj, true)
687
-                                    )
688
-                                );
689
-                            }
690
-                            return false;
691
-                        }
692
-                        break;
693
-                }
694
-            }
695
-        } catch (EE_Error $e) {
696
-            $e->get_error();
697
-        }
698
-        // you have successfully run the gauntlet
699
-        return true;
700
-    }
701
-
702
-
703
-    /**
704
-     *    _generate_config_option_name
705
-     *
706
-     * @access        protected
707
-     * @param        string $section
708
-     * @param        string $name
709
-     * @return        string
710
-     */
711
-    private function _generate_config_option_name($section = '', $name = '')
712
-    {
713
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
714
-    }
715
-
716
-
717
-    /**
718
-     *    _set_config_class
719
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
720
-     *
721
-     * @access    private
722
-     * @param    string $config_class
723
-     * @param    string $name
724
-     * @return    string
725
-     */
726
-    private function _set_config_class($config_class = '', $name = '')
727
-    {
728
-        return ! empty($config_class)
729
-            ? $config_class
730
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
731
-    }
732
-
733
-
734
-    /**
735
-     *    set_config
736
-     *
737
-     * @access    protected
738
-     * @param    string         $section
739
-     * @param    string         $name
740
-     * @param    string         $config_class
741
-     * @param    EE_Config_Base $config_obj
742
-     * @return    EE_Config_Base
743
-     */
744
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
745
-    {
746
-        // ensure config class is set to something
747
-        $config_class = $this->_set_config_class($config_class, $name);
748
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
749
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
750
-            return null;
751
-        }
752
-        $config_option_name = $this->_generate_config_option_name($section, $name);
753
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
754
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
755
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
756
-            $this->update_addon_option_names();
757
-        }
758
-        // verify the incoming config object but suppress errors
759
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
760
-            $config_obj = new $config_class();
761
-        }
762
-        if (get_option($config_option_name)) {
763
-            EE_Config::log($config_option_name);
764
-            update_option($config_option_name, $config_obj);
765
-            $this->{$section}->{$name} = $config_obj;
766
-            return $this->{$section}->{$name};
767
-        } else {
768
-            // create a wp-option for this config
769
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
770
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
771
-                return $this->{$section}->{$name};
772
-            } else {
773
-                EE_Error::add_error(
774
-                    sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
775
-                    __FILE__,
776
-                    __FUNCTION__,
777
-                    __LINE__
778
-                );
779
-                return null;
780
-            }
781
-        }
782
-    }
783
-
784
-
785
-    /**
786
-     *    update_config
787
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
788
-     *
789
-     * @access    public
790
-     * @param    string                $section
791
-     * @param    string                $name
792
-     * @param    EE_Config_Base|string $config_obj
793
-     * @param    bool                  $throw_errors
794
-     * @return    bool
795
-     */
796
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
797
-    {
798
-        // don't allow config updates during WP heartbeats
799
-        /** @var RequestInterface $request */
800
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
801
-        if ($request->isWordPressHeartbeat()) {
802
-            return false;
803
-        }
804
-        $config_obj = maybe_unserialize($config_obj);
805
-        // get class name of the incoming object
806
-        $config_class = get_class($config_obj);
807
-        // run tests 1-5 and 9 to verify config
808
-        if (
809
-            ! $this->_verify_config_params(
810
-                $section,
811
-                $name,
812
-                $config_class,
813
-                $config_obj,
814
-                array(1, 2, 3, 4, 7, 9)
815
-            )
816
-        ) {
817
-            return false;
818
-        }
819
-        $config_option_name = $this->_generate_config_option_name($section, $name);
820
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
821
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
822
-            // save new config to db
823
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
824
-                return true;
825
-            }
826
-        } else {
827
-            // first check if the record already exists
828
-            $existing_config = get_option($config_option_name);
829
-            $config_obj = serialize($config_obj);
830
-            // just return if db record is already up to date (NOT type safe comparison)
831
-            if ($existing_config == $config_obj) {
832
-                $this->{$section}->{$name} = $config_obj;
833
-                return true;
834
-            } elseif (update_option($config_option_name, $config_obj)) {
835
-                EE_Config::log($config_option_name);
836
-                // update wp-option for this config class
837
-                $this->{$section}->{$name} = $config_obj;
838
-                return true;
839
-            } elseif ($throw_errors) {
840
-                EE_Error::add_error(
841
-                    sprintf(
842
-                        esc_html__(
843
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
844
-                            'event_espresso'
845
-                        ),
846
-                        $config_class,
847
-                        'EE_Config->' . $section . '->' . $name
848
-                    ),
849
-                    __FILE__,
850
-                    __FUNCTION__,
851
-                    __LINE__
852
-                );
853
-            }
854
-        }
855
-        return false;
856
-    }
857
-
858
-
859
-    /**
860
-     *    get_config
861
-     *
862
-     * @access    public
863
-     * @param    string $section
864
-     * @param    string $name
865
-     * @param    string $config_class
866
-     * @return    mixed EE_Config_Base | NULL
867
-     */
868
-    public function get_config($section = '', $name = '', $config_class = '')
869
-    {
870
-        // ensure config class is set to something
871
-        $config_class = $this->_set_config_class($config_class, $name);
872
-        // run tests 1-4, 6 and 7 to verify that all params have been set
873
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
874
-            return null;
875
-        }
876
-        // now test if the requested config object exists, but suppress errors
877
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
878
-            // config already exists, so pass it back
879
-            return $this->{$section}->{$name};
880
-        }
881
-        // load config option from db if it exists
882
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
883
-        // verify the newly retrieved config object, but suppress errors
884
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
885
-            // config is good, so set it and pass it back
886
-            $this->{$section}->{$name} = $config_obj;
887
-            return $this->{$section}->{$name};
888
-        }
889
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
890
-        $config_obj = $this->set_config($section, $name, $config_class);
891
-        // verify the newly created config object
892
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
893
-            return $this->{$section}->{$name};
894
-        } else {
895
-            EE_Error::add_error(
896
-                sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
897
-                __FILE__,
898
-                __FUNCTION__,
899
-                __LINE__
900
-            );
901
-        }
902
-        return null;
903
-    }
904
-
905
-
906
-    /**
907
-     *    get_config_option
908
-     *
909
-     * @access    public
910
-     * @param    string $config_option_name
911
-     * @return    mixed EE_Config_Base | FALSE
912
-     */
913
-    public function get_config_option($config_option_name = '')
914
-    {
915
-        // retrieve the wp-option for this config class.
916
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
917
-        if (empty($config_option)) {
918
-            EE_Config::log($config_option_name . '-NOT-FOUND');
919
-        }
920
-        return $config_option;
921
-    }
922
-
923
-
924
-    /**
925
-     * log
926
-     *
927
-     * @param string $config_option_name
928
-     */
929
-    public static function log($config_option_name = '')
930
-    {
931
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
932
-            $config_log = get_option(EE_Config::LOG_NAME, array());
933
-            /** @var RequestParams $request */
934
-            $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
935
-            $config_log[ (string) microtime(true) ] = array(
936
-                'config_name' => $config_option_name,
937
-                'request'     => $request->requestParams(),
938
-            );
939
-            update_option(EE_Config::LOG_NAME, $config_log);
940
-        }
941
-    }
942
-
943
-
944
-    /**
945
-     * trim_log
946
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
947
-     */
948
-    public static function trim_log()
949
-    {
950
-        if (! EE_Config::logging_enabled()) {
951
-            return;
952
-        }
953
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
954
-        $log_length = count($config_log);
955
-        if ($log_length > EE_Config::LOG_LENGTH) {
956
-            ksort($config_log);
957
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
958
-            update_option(EE_Config::LOG_NAME, $config_log);
959
-        }
960
-    }
961
-
962
-
963
-    /**
964
-     *    get_page_for_posts
965
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
966
-     *    wp-option "page_for_posts", or "posts" if no page is selected
967
-     *
968
-     * @access    public
969
-     * @return    string
970
-     */
971
-    public static function get_page_for_posts()
972
-    {
973
-        $page_for_posts = get_option('page_for_posts');
974
-        if (! $page_for_posts) {
975
-            return 'posts';
976
-        }
977
-        global $wpdb;
978
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
979
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
980
-    }
981
-
982
-
983
-    /**
984
-     *    register_shortcodes_and_modules.
985
-     *    At this point, it's too early to tell if we're maintenance mode or not.
986
-     *    In fact, this is where we give modules a chance to let core know they exist
987
-     *    so they can help trigger maintenance mode if it's needed
988
-     *
989
-     * @access    public
990
-     * @return    void
991
-     */
992
-    public function register_shortcodes_and_modules()
993
-    {
994
-        // allow modules to set hooks for the rest of the system
995
-        EE_Registry::instance()->modules = $this->_register_modules();
996
-    }
997
-
998
-
999
-    /**
1000
-     *    initialize_shortcodes_and_modules
1001
-     *    meaning they can start adding their hooks to get stuff done
1002
-     *
1003
-     * @access    public
1004
-     * @return    void
1005
-     */
1006
-    public function initialize_shortcodes_and_modules()
1007
-    {
1008
-        // allow modules to set hooks for the rest of the system
1009
-        $this->_initialize_modules();
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     *    widgets_init
1015
-     *
1016
-     * @access private
1017
-     * @return void
1018
-     */
1019
-    public function widgets_init()
1020
-    {
1021
-        // only init widgets on admin pages when not in complete maintenance, and
1022
-        // on frontend when not in any maintenance mode
1023
-        if (
1024
-            ! EE_Maintenance_Mode::instance()->level()
1025
-            || (
1026
-                is_admin()
1027
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1028
-            )
1029
-        ) {
1030
-            // grab list of installed widgets
1031
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1032
-            // filter list of modules to register
1033
-            $widgets_to_register = apply_filters(
1034
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1035
-                $widgets_to_register
1036
-            );
1037
-            if (! empty($widgets_to_register)) {
1038
-                // cycle thru widget folders
1039
-                foreach ($widgets_to_register as $widget_path) {
1040
-                    // add to list of installed widget modules
1041
-                    EE_Config::register_ee_widget($widget_path);
1042
-                }
1043
-            }
1044
-            // filter list of installed modules
1045
-            EE_Registry::instance()->widgets = apply_filters(
1046
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1047
-                EE_Registry::instance()->widgets
1048
-            );
1049
-        }
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     *    register_ee_widget - makes core aware of this widget
1055
-     *
1056
-     * @access    public
1057
-     * @param    string $widget_path - full path up to and including widget folder
1058
-     * @return    void
1059
-     */
1060
-    public static function register_ee_widget($widget_path = null)
1061
-    {
1062
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1063
-        $widget_ext = '.widget.php';
1064
-        // make all separators match
1065
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1066
-        // does the file path INCLUDE the actual file name as part of the path ?
1067
-        if (strpos($widget_path, $widget_ext) !== false) {
1068
-            // grab and shortcode file name from directory name and break apart at dots
1069
-            $file_name = explode('.', basename($widget_path));
1070
-            // take first segment from file name pieces and remove class prefix if it exists
1071
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1072
-            // sanitize shortcode directory name
1073
-            $widget = sanitize_key($widget);
1074
-            // now we need to rebuild the shortcode path
1075
-            $widget_path = explode('/', $widget_path);
1076
-            // remove last segment
1077
-            array_pop($widget_path);
1078
-            // glue it back together
1079
-            $widget_path = implode(DS, $widget_path);
1080
-        } else {
1081
-            // grab and sanitize widget directory name
1082
-            $widget = sanitize_key(basename($widget_path));
1083
-        }
1084
-        // create classname from widget directory name
1085
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1086
-        // add class prefix
1087
-        $widget_class = 'EEW_' . $widget;
1088
-        // does the widget exist ?
1089
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1090
-            $msg = sprintf(
1091
-                esc_html__(
1092
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1093
-                    'event_espresso'
1094
-                ),
1095
-                $widget_class,
1096
-                $widget_path . '/' . $widget_class . $widget_ext
1097
-            );
1098
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1099
-            return;
1100
-        }
1101
-        // load the widget class file
1102
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1103
-        // verify that class exists
1104
-        if (! class_exists($widget_class)) {
1105
-            $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1106
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1107
-            return;
1108
-        }
1109
-        register_widget($widget_class);
1110
-        // add to array of registered widgets
1111
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     *        _register_modules
1117
-     *
1118
-     * @access private
1119
-     * @return array
1120
-     */
1121
-    private function _register_modules()
1122
-    {
1123
-        // grab list of installed modules
1124
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1125
-        // filter list of modules to register
1126
-        $modules_to_register = apply_filters(
1127
-            'FHEE__EE_Config__register_modules__modules_to_register',
1128
-            $modules_to_register
1129
-        );
1130
-        if (! empty($modules_to_register)) {
1131
-            // loop through folders
1132
-            foreach ($modules_to_register as $module_path) {
1133
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1134
-                if (
1135
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1136
-                    && $module_path !== EE_MODULES . 'gateways'
1137
-                ) {
1138
-                    // add to list of installed modules
1139
-                    EE_Config::register_module($module_path);
1140
-                }
1141
-            }
1142
-        }
1143
-        // filter list of installed modules
1144
-        return apply_filters(
1145
-            'FHEE__EE_Config___register_modules__installed_modules',
1146
-            EE_Registry::instance()->modules
1147
-        );
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     *    register_module - makes core aware of this module
1153
-     *
1154
-     * @access    public
1155
-     * @param    string $module_path - full path up to and including module folder
1156
-     * @return    bool
1157
-     */
1158
-    public static function register_module($module_path = null)
1159
-    {
1160
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1161
-        $module_ext = '.module.php';
1162
-        // make all separators match
1163
-        $module_path = str_replace(array('\\', '/'), '/', $module_path);
1164
-        // does the file path INCLUDE the actual file name as part of the path ?
1165
-        if (strpos($module_path, $module_ext) !== false) {
1166
-            // grab and shortcode file name from directory name and break apart at dots
1167
-            $module_file = explode('.', basename($module_path));
1168
-            // now we need to rebuild the shortcode path
1169
-            $module_path = explode('/', $module_path);
1170
-            // remove last segment
1171
-            array_pop($module_path);
1172
-            // glue it back together
1173
-            $module_path = implode('/', $module_path) . '/';
1174
-            // take first segment from file name pieces and sanitize it
1175
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1176
-            // ensure class prefix is added
1177
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1178
-        } else {
1179
-            // we need to generate the filename based off of the folder name
1180
-            // grab and sanitize module name
1181
-            $module = strtolower(basename($module_path));
1182
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1183
-            // like trailingslashit()
1184
-            $module_path = rtrim($module_path, '/') . '/';
1185
-            // create classname from module directory name
1186
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1187
-            // add class prefix
1188
-            $module_class = 'EED_' . $module;
1189
-        }
1190
-        // does the module exist ?
1191
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1192
-            $msg = sprintf(
1193
-                esc_html__(
1194
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1195
-                    'event_espresso'
1196
-                ),
1197
-                $module
1198
-            );
1199
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
-            return false;
1201
-        }
1202
-        // load the module class file
1203
-        require_once($module_path . $module_class . $module_ext);
1204
-        // verify that class exists
1205
-        if (! class_exists($module_class)) {
1206
-            $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1207
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1208
-            return false;
1209
-        }
1210
-        // add to array of registered modules
1211
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1212
-        do_action(
1213
-            'AHEE__EE_Config__register_module__complete',
1214
-            $module_class,
1215
-            EE_Registry::instance()->modules->{$module_class}
1216
-        );
1217
-        return true;
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     *    _initialize_modules
1223
-     *    allow modules to set hooks for the rest of the system
1224
-     *
1225
-     * @access private
1226
-     * @return void
1227
-     */
1228
-    private function _initialize_modules()
1229
-    {
1230
-        // cycle thru shortcode folders
1231
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1232
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1233
-            // which set hooks ?
1234
-            if (is_admin()) {
1235
-                // fire immediately
1236
-                call_user_func(array($module_class, 'set_hooks_admin'));
1237
-            } else {
1238
-                // delay until other systems are online
1239
-                add_action(
1240
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1241
-                    array($module_class, 'set_hooks')
1242
-                );
1243
-            }
1244
-        }
1245
-    }
1246
-
1247
-
1248
-    /**
1249
-     *    register_route - adds module method routes to route_map
1250
-     *
1251
-     * @access    public
1252
-     * @param    string $route       - "pretty" public alias for module method
1253
-     * @param    string $module      - module name (classname without EED_ prefix)
1254
-     * @param    string $method_name - the actual module method to be routed to
1255
-     * @param    string $key         - url param key indicating a route is being called
1256
-     * @return    bool
1257
-     */
1258
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1259
-    {
1260
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1261
-        $module = str_replace('EED_', '', $module);
1262
-        $module_class = 'EED_' . $module;
1263
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1264
-            $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1265
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1266
-            return false;
1267
-        }
1268
-        if (empty($route)) {
1269
-            $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1270
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1271
-            return false;
1272
-        }
1273
-        if (! method_exists('EED_' . $module, $method_name)) {
1274
-            $msg = sprintf(
1275
-                esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1276
-                $route
1277
-            );
1278
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1279
-            return false;
1280
-        }
1281
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1282
-        return true;
1283
-    }
1284
-
1285
-
1286
-    /**
1287
-     *    get_route - get module method route
1288
-     *
1289
-     * @access    public
1290
-     * @param    string $route - "pretty" public alias for module method
1291
-     * @param    string $key   - url param key indicating a route is being called
1292
-     * @return    string
1293
-     */
1294
-    public static function get_route($route = null, $key = 'ee')
1295
-    {
1296
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1297
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1298
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1299
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1300
-        }
1301
-        return null;
1302
-    }
1303
-
1304
-
1305
-    /**
1306
-     *    get_routes - get ALL module method routes
1307
-     *
1308
-     * @access    public
1309
-     * @return    array
1310
-     */
1311
-    public static function get_routes()
1312
-    {
1313
-        return EE_Config::$_module_route_map;
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     *    register_forward - allows modules to forward request to another module for further processing
1319
-     *
1320
-     * @access    public
1321
-     * @param    string       $route   - "pretty" public alias for module method
1322
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1323
-     *                                 class, allows different forwards to be served based on status
1324
-     * @param    array|string $forward - function name or array( class, method )
1325
-     * @param    string       $key     - url param key indicating a route is being called
1326
-     * @return    bool
1327
-     */
1328
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1329
-    {
1330
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1331
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1332
-            $msg = sprintf(
1333
-                esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1334
-                $route
1335
-            );
1336
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1337
-            return false;
1338
-        }
1339
-        if (empty($forward)) {
1340
-            $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1341
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1342
-            return false;
1343
-        }
1344
-        if (is_array($forward)) {
1345
-            if (! isset($forward[1])) {
1346
-                $msg = sprintf(
1347
-                    esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1348
-                    $route
1349
-                );
1350
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1351
-                return false;
1352
-            }
1353
-            if (! method_exists($forward[0], $forward[1])) {
1354
-                $msg = sprintf(
1355
-                    esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1356
-                    $forward[1],
1357
-                    $route
1358
-                );
1359
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
-                return false;
1361
-            }
1362
-        } elseif (! function_exists($forward)) {
1363
-            $msg = sprintf(
1364
-                esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1365
-                $forward,
1366
-                $route
1367
-            );
1368
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1369
-            return false;
1370
-        }
1371
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1372
-        return true;
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     *    get_forward - get forwarding route
1378
-     *
1379
-     * @access    public
1380
-     * @param    string  $route  - "pretty" public alias for module method
1381
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1382
-     *                           allows different forwards to be served based on status
1383
-     * @param    string  $key    - url param key indicating a route is being called
1384
-     * @return    string
1385
-     */
1386
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1387
-    {
1388
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1389
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1390
-            return apply_filters(
1391
-                'FHEE__EE_Config__get_forward',
1392
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1393
-                $route,
1394
-                $status
1395
-            );
1396
-        }
1397
-        return null;
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1403
-     *    results
1404
-     *
1405
-     * @access    public
1406
-     * @param    string  $route  - "pretty" public alias for module method
1407
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1408
-     *                           allows different views to be served based on status
1409
-     * @param    string  $view
1410
-     * @param    string  $key    - url param key indicating a route is being called
1411
-     * @return    bool
1412
-     */
1413
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1414
-    {
1415
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1416
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1417
-            $msg = sprintf(
1418
-                esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1419
-                $route
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        if (! is_readable($view)) {
1425
-            $msg = sprintf(
1426
-                esc_html__(
1427
-                    'The %s view file could not be found or is not readable due to file permissions.',
1428
-                    'event_espresso'
1429
-                ),
1430
-                $view
1431
-            );
1432
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1433
-            return false;
1434
-        }
1435
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1436
-        return true;
1437
-    }
1438
-
1439
-
1440
-    /**
1441
-     *    get_view - get view for route and status
1442
-     *
1443
-     * @access    public
1444
-     * @param    string  $route  - "pretty" public alias for module method
1445
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1446
-     *                           allows different views to be served based on status
1447
-     * @param    string  $key    - url param key indicating a route is being called
1448
-     * @return    string
1449
-     */
1450
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1451
-    {
1452
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1453
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1454
-            return apply_filters(
1455
-                'FHEE__EE_Config__get_view',
1456
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1457
-                $route,
1458
-                $status
1459
-            );
1460
-        }
1461
-        return null;
1462
-    }
1463
-
1464
-
1465
-    public function update_addon_option_names()
1466
-    {
1467
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1468
-    }
1469
-
1470
-
1471
-    public function shutdown()
1472
-    {
1473
-        $this->update_addon_option_names();
1474
-    }
1475
-
1476
-
1477
-    /**
1478
-     * @return LegacyShortcodesManager
1479
-     */
1480
-    public static function getLegacyShortcodesManager()
1481
-    {
1482
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1483
-            EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1484
-                LegacyShortcodesManager::class
1485
-            );
1486
-        }
1487
-        return EE_Config::instance()->legacy_shortcodes_manager;
1488
-    }
1489
-
1490
-
1491
-    /**
1492
-     * register_shortcode - makes core aware of this shortcode
1493
-     *
1494
-     * @deprecated 4.9.26
1495
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1496
-     * @return    bool
1497
-     */
1498
-    public static function register_shortcode($shortcode_path = null)
1499
-    {
1500
-        EE_Error::doing_it_wrong(
1501
-            __METHOD__,
1502
-            esc_html__(
1503
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1504
-                'event_espresso'
1505
-            ),
1506
-            '4.9.26'
1507
-        );
1508
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1509
-    }
1510
-}
1511
-
1512
-/**
1513
- * Base class used for config classes. These classes should generally not have
1514
- * magic functions in use, except we'll allow them to magically set and get stuff...
1515
- * basically, they should just be well-defined stdClasses
1516
- */
1517
-class EE_Config_Base
1518
-{
1519
-
1520
-    /**
1521
-     * Utility function for escaping the value of a property and returning.
1522
-     *
1523
-     * @param string $property property name (checks to see if exists).
1524
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1525
-     * @throws EE_Error
1526
-     */
1527
-    public function get_pretty($property)
1528
-    {
1529
-        if (! property_exists($this, $property)) {
1530
-            throw new EE_Error(
1531
-                sprintf(
1532
-                    esc_html__(
1533
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1534
-                        'event_espresso'
1535
-                    ),
1536
-                    get_class($this),
1537
-                    $property
1538
-                )
1539
-            );
1540
-        }
1541
-        // just handling escaping of strings for now.
1542
-        if (is_string($this->{$property})) {
1543
-            return stripslashes($this->{$property});
1544
-        }
1545
-        return $this->{$property};
1546
-    }
1547
-
1548
-
1549
-    public function populate()
1550
-    {
1551
-        // grab defaults via a new instance of this class.
1552
-        $class_name = get_class($this);
1553
-        $defaults = new $class_name();
1554
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1555
-        // default from our $defaults object.
1556
-        foreach (get_object_vars($defaults) as $property => $value) {
1557
-            if ($this->{$property} === null) {
1558
-                $this->{$property} = $value;
1559
-            }
1560
-        }
1561
-        // cleanup
1562
-        unset($defaults);
1563
-    }
1564
-
1565
-
1566
-    /**
1567
-     *        __isset
1568
-     *
1569
-     * @param $a
1570
-     * @return bool
1571
-     */
1572
-    public function __isset($a)
1573
-    {
1574
-        return false;
1575
-    }
1576
-
1577
-
1578
-    /**
1579
-     *        __unset
1580
-     *
1581
-     * @param $a
1582
-     * @return bool
1583
-     */
1584
-    public function __unset($a)
1585
-    {
1586
-        return false;
1587
-    }
1588
-
1589
-
1590
-    /**
1591
-     *        __clone
1592
-     */
1593
-    public function __clone()
1594
-    {
1595
-    }
1596
-
1597
-
1598
-    /**
1599
-     *        __wakeup
1600
-     */
1601
-    public function __wakeup()
1602
-    {
1603
-    }
1604
-
1605
-
1606
-    /**
1607
-     *        __destruct
1608
-     */
1609
-    public function __destruct()
1610
-    {
1611
-    }
1612
-}
1613
-
1614
-/**
1615
- * Class for defining what's in the EE_Config relating to registration settings
1616
- */
1617
-class EE_Core_Config extends EE_Config_Base
1618
-{
1619
-
1620
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1621
-
1622
-
1623
-    public $current_blog_id;
1624
-
1625
-    public $ee_ueip_optin;
1626
-
1627
-    public $ee_ueip_has_notified;
1628
-
1629
-    /**
1630
-     * Not to be confused with the 4 critical page variables (See
1631
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1632
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1633
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1634
-     *
1635
-     * @var array
1636
-     */
1637
-    public $post_shortcodes;
1638
-
1639
-    public $module_route_map;
1640
-
1641
-    public $module_forward_map;
1642
-
1643
-    public $module_view_map;
1644
-
1645
-    /**
1646
-     * The next 4 vars are the IDs of critical EE pages.
1647
-     *
1648
-     * @var int
1649
-     */
1650
-    public $reg_page_id;
1651
-
1652
-    public $txn_page_id;
1653
-
1654
-    public $thank_you_page_id;
1655
-
1656
-    public $cancel_page_id;
1657
-
1658
-    /**
1659
-     * The next 4 vars are the URLs of critical EE pages.
1660
-     *
1661
-     * @var int
1662
-     */
1663
-    public $reg_page_url;
1664
-
1665
-    public $txn_page_url;
1666
-
1667
-    public $thank_you_page_url;
1668
-
1669
-    public $cancel_page_url;
1670
-
1671
-    /**
1672
-     * The next vars relate to the custom slugs for EE CPT routes
1673
-     */
1674
-    public $event_cpt_slug;
1675
-
1676
-    /**
1677
-     * This caches the _ee_ueip_option in case this config is reset in the same
1678
-     * request across blog switches in a multisite context.
1679
-     * Avoids extra queries to the db for this option.
1680
-     *
1681
-     * @var bool
1682
-     */
1683
-    public static $ee_ueip_option;
1684
-
1685
-
1686
-    /**
1687
-     *    class constructor
1688
-     *
1689
-     * @access    public
1690
-     */
1691
-    public function __construct()
1692
-    {
1693
-        // set default organization settings
1694
-        $this->current_blog_id = get_current_blog_id();
1695
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1696
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1697
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1698
-        $this->post_shortcodes = array();
1699
-        $this->module_route_map = array();
1700
-        $this->module_forward_map = array();
1701
-        $this->module_view_map = array();
1702
-        // critical EE page IDs
1703
-        $this->reg_page_id = 0;
1704
-        $this->txn_page_id = 0;
1705
-        $this->thank_you_page_id = 0;
1706
-        $this->cancel_page_id = 0;
1707
-        // critical EE page URLs
1708
-        $this->reg_page_url = '';
1709
-        $this->txn_page_url = '';
1710
-        $this->thank_you_page_url = '';
1711
-        $this->cancel_page_url = '';
1712
-        // cpt slugs
1713
-        $this->event_cpt_slug = esc_html__('events', 'event_espresso');
1714
-        // ueip constant check
1715
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1716
-            $this->ee_ueip_optin = false;
1717
-            $this->ee_ueip_has_notified = true;
1718
-        }
1719
-    }
1720
-
1721
-
1722
-    /**
1723
-     * @return array
1724
-     */
1725
-    public function get_critical_pages_array()
1726
-    {
1727
-        return array(
1728
-            $this->reg_page_id,
1729
-            $this->txn_page_id,
1730
-            $this->thank_you_page_id,
1731
-            $this->cancel_page_id,
1732
-        );
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     * @return array
1738
-     */
1739
-    public function get_critical_pages_shortcodes_array()
1740
-    {
1741
-        return array(
1742
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1743
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1744
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1745
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1746
-        );
1747
-    }
1748
-
1749
-
1750
-    /**
1751
-     *  gets/returns URL for EE reg_page
1752
-     *
1753
-     * @access    public
1754
-     * @return    string
1755
-     */
1756
-    public function reg_page_url()
1757
-    {
1758
-        if (! $this->reg_page_url) {
1759
-            $this->reg_page_url = add_query_arg(
1760
-                array('uts' => time()),
1761
-                get_permalink($this->reg_page_id)
1762
-            ) . '#checkout';
1763
-        }
1764
-        return $this->reg_page_url;
1765
-    }
1766
-
1767
-
1768
-    /**
1769
-     *  gets/returns URL for EE txn_page
1770
-     *
1771
-     * @param array $query_args like what gets passed to
1772
-     *                          add_query_arg() as the first argument
1773
-     * @access    public
1774
-     * @return    string
1775
-     */
1776
-    public function txn_page_url($query_args = array())
1777
-    {
1778
-        if (! $this->txn_page_url) {
1779
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1780
-        }
1781
-        if ($query_args) {
1782
-            return add_query_arg($query_args, $this->txn_page_url);
1783
-        } else {
1784
-            return $this->txn_page_url;
1785
-        }
1786
-    }
1787
-
1788
-
1789
-    /**
1790
-     *  gets/returns URL for EE thank_you_page
1791
-     *
1792
-     * @param array $query_args like what gets passed to
1793
-     *                          add_query_arg() as the first argument
1794
-     * @access    public
1795
-     * @return    string
1796
-     */
1797
-    public function thank_you_page_url($query_args = array())
1798
-    {
1799
-        if (! $this->thank_you_page_url) {
1800
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1801
-        }
1802
-        if ($query_args) {
1803
-            return add_query_arg($query_args, $this->thank_you_page_url);
1804
-        } else {
1805
-            return $this->thank_you_page_url;
1806
-        }
1807
-    }
1808
-
1809
-
1810
-    /**
1811
-     *  gets/returns URL for EE cancel_page
1812
-     *
1813
-     * @access    public
1814
-     * @return    string
1815
-     */
1816
-    public function cancel_page_url()
1817
-    {
1818
-        if (! $this->cancel_page_url) {
1819
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1820
-        }
1821
-        return $this->cancel_page_url;
1822
-    }
1823
-
1824
-
1825
-    /**
1826
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1827
-     *
1828
-     * @since 4.7.5
1829
-     */
1830
-    protected function _reset_urls()
1831
-    {
1832
-        $this->reg_page_url = '';
1833
-        $this->txn_page_url = '';
1834
-        $this->cancel_page_url = '';
1835
-        $this->thank_you_page_url = '';
1836
-    }
1837
-
1838
-
1839
-    /**
1840
-     * Used to return what the optin value is set for the EE User Experience Program.
1841
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1842
-     * on the main site only.
1843
-     *
1844
-     * @return bool
1845
-     */
1846
-    protected function _get_main_ee_ueip_optin()
1847
-    {
1848
-        // if this is the main site then we can just bypass our direct query.
1849
-        if (is_main_site()) {
1850
-            return get_option(self::OPTION_NAME_UXIP, false);
1851
-        }
1852
-        // is this already cached for this request?  If so use it.
1853
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1854
-            return EE_Core_Config::$ee_ueip_option;
1855
-        }
1856
-        global $wpdb;
1857
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1858
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1859
-        $option = self::OPTION_NAME_UXIP;
1860
-        // set correct table for query
1861
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1862
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1863
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1864
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1865
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1866
-        // for the purpose of caching.
1867
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1868
-        if (false !== $pre) {
1869
-            EE_Core_Config::$ee_ueip_option = $pre;
1870
-            return EE_Core_Config::$ee_ueip_option;
1871
-        }
1872
-        $row = $wpdb->get_row(
1873
-            $wpdb->prepare(
1874
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1875
-                $option
1876
-            )
1877
-        );
1878
-        if (is_object($row)) {
1879
-            $value = $row->option_value;
1880
-        } else { // option does not exist so use default.
1881
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1882
-            return EE_Core_Config::$ee_ueip_option;
1883
-        }
1884
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1885
-        return EE_Core_Config::$ee_ueip_option;
1886
-    }
1887
-
1888
-
1889
-    /**
1890
-     * Utility function for escaping the value of a property and returning.
1891
-     *
1892
-     * @param string $property property name (checks to see if exists).
1893
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1894
-     * @throws EE_Error
1895
-     */
1896
-    public function get_pretty($property)
1897
-    {
1898
-        if ($property === self::OPTION_NAME_UXIP) {
1899
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1900
-        }
1901
-        return parent::get_pretty($property);
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1907
-     * on the object.
1908
-     *
1909
-     * @return array
1910
-     */
1911
-    public function __sleep()
1912
-    {
1913
-        // reset all url properties
1914
-        $this->_reset_urls();
1915
-        // return what to save to db
1916
-        return array_keys(get_object_vars($this));
1917
-    }
1918
-}
1919
-
1920
-/**
1921
- * Config class for storing info on the Organization
1922
- */
1923
-class EE_Organization_Config extends EE_Config_Base
1924
-{
1925
-
1926
-    /**
1927
-     * @var string $name
1928
-     * eg EE4.1
1929
-     */
1930
-    public $name;
1931
-
1932
-    /**
1933
-     * @var string $address_1
1934
-     * eg 123 Onna Road
1935
-     */
1936
-    public $address_1 = '';
1937
-
1938
-    /**
1939
-     * @var string $address_2
1940
-     * eg PO Box 123
1941
-     */
1942
-    public $address_2 = '';
1943
-
1944
-    /**
1945
-     * @var string $city
1946
-     * eg Inna City
1947
-     */
1948
-    public $city = '';
1949
-
1950
-    /**
1951
-     * @var int $STA_ID
1952
-     * eg 4
1953
-     */
1954
-    public $STA_ID = 0;
1955
-
1956
-    /**
1957
-     * @var string $CNT_ISO
1958
-     * eg US
1959
-     */
1960
-    public $CNT_ISO = '';
1961
-
1962
-    /**
1963
-     * @var string $zip
1964
-     * eg 12345  or V1A 2B3
1965
-     */
1966
-    public $zip = '';
1967
-
1968
-    /**
1969
-     * @var string $email
1970
-     * eg [email protected]
1971
-     */
1972
-    public $email;
1973
-
1974
-    /**
1975
-     * @var string $phone
1976
-     * eg. 111-111-1111
1977
-     */
1978
-    public $phone = '';
1979
-
1980
-    /**
1981
-     * @var string $vat
1982
-     * VAT/Tax Number
1983
-     */
1984
-    public $vat = '';
1985
-
1986
-    /**
1987
-     * @var string $logo_url
1988
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1989
-     */
1990
-    public $logo_url = '';
1991
-
1992
-    /**
1993
-     * The below are all various properties for holding links to organization social network profiles
1994
-     *
1995
-     * @var string
1996
-     */
1997
-    /**
1998
-     * facebook (facebook.com/profile.name)
1999
-     *
2000
-     * @var string
2001
-     */
2002
-    public $facebook = '';
2003
-
2004
-    /**
2005
-     * twitter (twitter.com/twitter_handle)
2006
-     *
2007
-     * @var string
2008
-     */
2009
-    public $twitter = '';
2010
-
2011
-    /**
2012
-     * linkedin (linkedin.com/in/profile_name)
2013
-     *
2014
-     * @var string
2015
-     */
2016
-    public $linkedin = '';
2017
-
2018
-    /**
2019
-     * pinterest (www.pinterest.com/profile_name)
2020
-     *
2021
-     * @var string
2022
-     */
2023
-    public $pinterest = '';
2024
-
2025
-    /**
2026
-     * google+ (google.com/+profileName)
2027
-     *
2028
-     * @var string
2029
-     */
2030
-    public $google = '';
2031
-
2032
-    /**
2033
-     * instagram (instagram.com/handle)
2034
-     *
2035
-     * @var string
2036
-     */
2037
-    public $instagram = '';
2038
-
2039
-
2040
-    /**
2041
-     *    class constructor
2042
-     *
2043
-     * @access    public
2044
-     */
2045
-    public function __construct()
2046
-    {
2047
-        // set default organization settings
2048
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2049
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2050
-        $this->email = get_bloginfo('admin_email');
2051
-    }
2052
-}
2053
-
2054
-/**
2055
- * Class for defining what's in the EE_Config relating to currency
2056
- */
2057
-class EE_Currency_Config extends EE_Config_Base
2058
-{
2059
-
2060
-    /**
2061
-     * @var string $code
2062
-     * eg 'US'
2063
-     */
2064
-    public $code;
2065
-
2066
-    /**
2067
-     * @var string $name
2068
-     * eg 'Dollar'
2069
-     */
2070
-    public $name;
2071
-
2072
-    /**
2073
-     * plural name
2074
-     *
2075
-     * @var string $plural
2076
-     * eg 'Dollars'
2077
-     */
2078
-    public $plural;
2079
-
2080
-    /**
2081
-     * currency sign
2082
-     *
2083
-     * @var string $sign
2084
-     * eg '$'
2085
-     */
2086
-    public $sign;
2087
-
2088
-    /**
2089
-     * Whether the currency sign should come before the number or not
2090
-     *
2091
-     * @var boolean $sign_b4
2092
-     */
2093
-    public $sign_b4;
2094
-
2095
-    /**
2096
-     * How many digits should come after the decimal place
2097
-     *
2098
-     * @var int $dec_plc
2099
-     */
2100
-    public $dec_plc;
2101
-
2102
-    /**
2103
-     * Symbol to use for decimal mark
2104
-     *
2105
-     * @var string $dec_mrk
2106
-     * eg '.'
2107
-     */
2108
-    public $dec_mrk;
2109
-
2110
-    /**
2111
-     * Symbol to use for thousands
2112
-     *
2113
-     * @var string $thsnds
2114
-     * eg ','
2115
-     */
2116
-    public $thsnds;
2117
-
2118
-
2119
-    /**
2120
-     *    class constructor
2121
-     *
2122
-     * @access    public
2123
-     * @param string $CNT_ISO
2124
-     * @throws EE_Error
2125
-     * @throws ReflectionException
2126
-     */
2127
-    public function __construct($CNT_ISO = '')
2128
-    {
2129
-        /** @var TableAnalysis $table_analysis */
2130
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2131
-        // get country code from organization settings or use default
2132
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2133
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2134
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2135
-            : '';
2136
-        // but override if requested
2137
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2138
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2139
-        if (
2140
-            ! empty($CNT_ISO)
2141
-            && EE_Maintenance_Mode::instance()->models_can_query()
2142
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2143
-        ) {
2144
-            // retrieve the country settings from the db, just in case they have been customized
2145
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2146
-            if ($country instanceof EE_Country) {
2147
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2148
-                $this->name = $country->currency_name_single();    // Dollar
2149
-                $this->plural = $country->currency_name_plural();    // Dollars
2150
-                $this->sign = $country->currency_sign();            // currency sign: $
2151
-                $this->sign_b4 = $country->currency_sign_before(
2152
-                );        // currency sign before or after: $TRUE  or  FALSE$
2153
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2154
-                $this->dec_mrk = $country->currency_decimal_mark(
2155
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2156
-                $this->thsnds = $country->currency_thousands_separator(
2157
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2158
-            }
2159
-        }
2160
-        // fallback to hardcoded defaults, in case the above failed
2161
-        if (empty($this->code)) {
2162
-            // set default currency settings
2163
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2164
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2165
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2166
-            $this->sign = '$';    // currency sign: $
2167
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2168
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2169
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2170
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2171
-        }
2172
-    }
2173
-}
2174
-
2175
-/**
2176
- * Class for defining what's in the EE_Config relating to registration settings
2177
- */
2178
-class EE_Registration_Config extends EE_Config_Base
2179
-{
2180
-
2181
-    /**
2182
-     * Default registration status
2183
-     *
2184
-     * @var string $default_STS_ID
2185
-     * eg 'RPP'
2186
-     */
2187
-    public $default_STS_ID;
2188
-
2189
-    /**
2190
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2191
-     * registrations)
2192
-     *
2193
-     * @var int
2194
-     */
2195
-    public $default_maximum_number_of_tickets;
2196
-
2197
-    /**
2198
-     * level of validation to apply to email addresses
2199
-     *
2200
-     * @var string $email_validation_level
2201
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2202
-     */
2203
-    public $email_validation_level;
2204
-
2205
-    /**
2206
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2207
-     *
2208
-     * @var boolean $show_pending_payment_options
2209
-     */
2210
-    public $show_pending_payment_options;
2211
-
2212
-    /**
2213
-     * Whether to skip the registration confirmation page
2214
-     *
2215
-     * @var boolean $skip_reg_confirmation
2216
-     */
2217
-    public $skip_reg_confirmation;
2218
-
2219
-    /**
2220
-     * an array of SPCO reg steps where:
2221
-     *        the keys denotes the reg step order
2222
-     *        each element consists of an array with the following elements:
2223
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2224
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2225
-     *            "slug" => the URL param used to trigger the reg step
2226
-     *
2227
-     * @var array $reg_steps
2228
-     */
2229
-    public $reg_steps;
2230
-
2231
-    /**
2232
-     * Whether registration confirmation should be the last page of SPCO
2233
-     *
2234
-     * @var boolean $reg_confirmation_last
2235
-     */
2236
-    public $reg_confirmation_last;
2237
-
2238
-    /**
2239
-     * Whether or not to enable the EE Bot Trap
2240
-     *
2241
-     * @var boolean $use_bot_trap
2242
-     */
2243
-    public $use_bot_trap;
2244
-
2245
-    /**
2246
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2247
-     *
2248
-     * @var boolean $use_encryption
2249
-     */
2250
-    public $use_encryption;
2251
-
2252
-    /**
2253
-     * Whether or not to use ReCaptcha
2254
-     *
2255
-     * @var boolean $use_captcha
2256
-     */
2257
-    public $use_captcha;
2258
-
2259
-    /**
2260
-     * ReCaptcha Theme
2261
-     *
2262
-     * @var string $recaptcha_theme
2263
-     *    options: 'dark', 'light', 'invisible'
2264
-     */
2265
-    public $recaptcha_theme;
2266
-
2267
-    /**
2268
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2269
-     *
2270
-     * @var string $recaptcha_badge
2271
-     *    options: 'bottomright', 'bottomleft', 'inline'
2272
-     */
2273
-    public $recaptcha_badge;
22
+	const OPTION_NAME = 'ee_config';
23
+
24
+	const LOG_NAME = 'ee_config_log';
25
+
26
+	const LOG_LENGTH = 100;
27
+
28
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
29
+
30
+	/**
31
+	 *    instance of the EE_Config object
32
+	 *
33
+	 * @var    EE_Config $_instance
34
+	 * @access    private
35
+	 */
36
+	private static $_instance;
37
+
38
+	/**
39
+	 * @var boolean $_logging_enabled
40
+	 */
41
+	private static $_logging_enabled = false;
42
+
43
+	/**
44
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
45
+	 */
46
+	private $legacy_shortcodes_manager;
47
+
48
+	/**
49
+	 * An StdClass whose property names are addon slugs,
50
+	 * and values are their config classes
51
+	 *
52
+	 * @var StdClass
53
+	 */
54
+	public $addons;
55
+
56
+	/**
57
+	 * @var EE_Admin_Config
58
+	 */
59
+	public $admin;
60
+
61
+	/**
62
+	 * @var EE_Core_Config
63
+	 */
64
+	public $core;
65
+
66
+	/**
67
+	 * @var EE_Currency_Config
68
+	 */
69
+	public $currency;
70
+
71
+	/**
72
+	 * @var EE_Organization_Config
73
+	 */
74
+	public $organization;
75
+
76
+	/**
77
+	 * @var EE_Registration_Config
78
+	 */
79
+	public $registration;
80
+
81
+	/**
82
+	 * @var EE_Template_Config
83
+	 */
84
+	public $template_settings;
85
+
86
+	/**
87
+	 * Holds EE environment values.
88
+	 *
89
+	 * @var EE_Environment_Config
90
+	 */
91
+	public $environment;
92
+
93
+	/**
94
+	 * settings pertaining to Google maps
95
+	 *
96
+	 * @var EE_Map_Config
97
+	 */
98
+	public $map_settings;
99
+
100
+	/**
101
+	 * settings pertaining to Taxes
102
+	 *
103
+	 * @var EE_Tax_Config
104
+	 */
105
+	public $tax_settings;
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+	/**
146
+	 * @singleton method used to instantiate class object
147
+	 * @access    public
148
+	 * @return EE_Config instance
149
+	 */
150
+	public static function instance()
151
+	{
152
+		// check if class object is instantiated, and instantiated properly
153
+		if (! self::$_instance instanceof EE_Config) {
154
+			self::$_instance = new self();
155
+		}
156
+		return self::$_instance;
157
+	}
158
+
159
+
160
+	/**
161
+	 * Resets the config
162
+	 *
163
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
164
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
165
+	 *                               reflect its state in the database
166
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
167
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
168
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
169
+	 *                               site was put into maintenance mode)
170
+	 * @return EE_Config
171
+	 */
172
+	public static function reset($hard_reset = false, $reinstantiate = true)
173
+	{
174
+		if (self::$_instance instanceof EE_Config) {
175
+			if ($hard_reset) {
176
+				self::$_instance->legacy_shortcodes_manager = null;
177
+				self::$_instance->_addon_option_names = array();
178
+				self::$_instance->_initialize_config();
179
+				self::$_instance->update_espresso_config();
180
+			}
181
+			self::$_instance->update_addon_option_names();
182
+		}
183
+		self::$_instance = null;
184
+		// we don't need to reset the static properties imo because those should
185
+		// only change when a module is added or removed. Currently we don't
186
+		// support removing a module during a request when it previously existed
187
+		if ($reinstantiate) {
188
+			return self::instance();
189
+		} else {
190
+			return null;
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 *    class constructor
197
+	 *
198
+	 * @access    private
199
+	 */
200
+	private function __construct()
201
+	{
202
+		do_action('AHEE__EE_Config__construct__begin', $this);
203
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
204
+		// setup empty config classes
205
+		$this->_initialize_config();
206
+		// load existing EE site settings
207
+		$this->_load_core_config();
208
+		// confirm everything loaded correctly and set filtered defaults if not
209
+		$this->_verify_config();
210
+		//  register shortcodes and modules
211
+		add_action(
212
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
213
+			array($this, 'register_shortcodes_and_modules'),
214
+			999
215
+		);
216
+		//  initialize shortcodes and modules
217
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
218
+		// register widgets
219
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
220
+		// shutdown
221
+		add_action('shutdown', array($this, 'shutdown'), 10);
222
+		// construct__end hook
223
+		do_action('AHEE__EE_Config__construct__end', $this);
224
+		// hardcoded hack
225
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
226
+	}
227
+
228
+
229
+	/**
230
+	 * @return boolean
231
+	 */
232
+	public static function logging_enabled()
233
+	{
234
+		return self::$_logging_enabled;
235
+	}
236
+
237
+
238
+	/**
239
+	 * use to get the current theme if needed from static context
240
+	 *
241
+	 * @return string current theme set.
242
+	 */
243
+	public static function get_current_theme()
244
+	{
245
+		return isset(self::$_instance->template_settings->current_espresso_theme)
246
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
247
+	}
248
+
249
+
250
+	/**
251
+	 *        _initialize_config
252
+	 *
253
+	 * @access private
254
+	 * @return void
255
+	 */
256
+	private function _initialize_config()
257
+	{
258
+		EE_Config::trim_log();
259
+		// set defaults
260
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
261
+		$this->addons = new stdClass();
262
+		// set _module_route_map
263
+		EE_Config::$_module_route_map = array();
264
+		// set _module_forward_map
265
+		EE_Config::$_module_forward_map = array();
266
+		// set _module_view_map
267
+		EE_Config::$_module_view_map = array();
268
+	}
269
+
270
+
271
+	/**
272
+	 *        load core plugin configuration
273
+	 *
274
+	 * @access private
275
+	 * @return void
276
+	 */
277
+	private function _load_core_config()
278
+	{
279
+		// load_core_config__start hook
280
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
281
+		$espresso_config = $this->get_espresso_config();
282
+		foreach ($espresso_config as $config => $settings) {
283
+			// load_core_config__start hook
284
+			$settings = apply_filters(
285
+				'FHEE__EE_Config___load_core_config__config_settings',
286
+				$settings,
287
+				$config,
288
+				$this
289
+			);
290
+			if (is_object($settings) && property_exists($this, $config)) {
291
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
292
+				// call configs populate method to ensure any defaults are set for empty values.
293
+				if (method_exists($settings, 'populate')) {
294
+					$this->{$config}->populate();
295
+				}
296
+				if (method_exists($settings, 'do_hooks')) {
297
+					$this->{$config}->do_hooks();
298
+				}
299
+			}
300
+		}
301
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
302
+			$this->update_espresso_config();
303
+		}
304
+		// load_core_config__end hook
305
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
306
+	}
307
+
308
+
309
+	/**
310
+	 *    _verify_config
311
+	 *
312
+	 * @access    protected
313
+	 * @return    void
314
+	 */
315
+	protected function _verify_config()
316
+	{
317
+		$this->core = $this->core instanceof EE_Core_Config
318
+			? $this->core
319
+			: new EE_Core_Config();
320
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
321
+		$this->organization = $this->organization instanceof EE_Organization_Config
322
+			? $this->organization
323
+			: new EE_Organization_Config();
324
+		$this->organization = apply_filters(
325
+			'FHEE__EE_Config___initialize_config__organization',
326
+			$this->organization
327
+		);
328
+		$this->currency = $this->currency instanceof EE_Currency_Config
329
+			? $this->currency
330
+			: new EE_Currency_Config();
331
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
332
+		$this->registration = $this->registration instanceof EE_Registration_Config
333
+			? $this->registration
334
+			: new EE_Registration_Config();
335
+		$this->registration = apply_filters(
336
+			'FHEE__EE_Config___initialize_config__registration',
337
+			$this->registration
338
+		);
339
+		$this->admin = $this->admin instanceof EE_Admin_Config
340
+			? $this->admin
341
+			: new EE_Admin_Config();
342
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
343
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
344
+			? $this->template_settings
345
+			: new EE_Template_Config();
346
+		$this->template_settings = apply_filters(
347
+			'FHEE__EE_Config___initialize_config__template_settings',
348
+			$this->template_settings
349
+		);
350
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
351
+			? $this->map_settings
352
+			: new EE_Map_Config();
353
+		$this->map_settings = apply_filters(
354
+			'FHEE__EE_Config___initialize_config__map_settings',
355
+			$this->map_settings
356
+		);
357
+		$this->environment = $this->environment instanceof EE_Environment_Config
358
+			? $this->environment
359
+			: new EE_Environment_Config();
360
+		$this->environment = apply_filters(
361
+			'FHEE__EE_Config___initialize_config__environment',
362
+			$this->environment
363
+		);
364
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
365
+			? $this->tax_settings
366
+			: new EE_Tax_Config();
367
+		$this->tax_settings = apply_filters(
368
+			'FHEE__EE_Config___initialize_config__tax_settings',
369
+			$this->tax_settings
370
+		);
371
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
372
+		$this->messages = $this->messages instanceof EE_Messages_Config
373
+			? $this->messages
374
+			: new EE_Messages_Config();
375
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
376
+			? $this->gateway
377
+			: new EE_Gateway_Config();
378
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
379
+		$this->legacy_shortcodes_manager = null;
380
+	}
381
+
382
+
383
+	/**
384
+	 *    get_espresso_config
385
+	 *
386
+	 * @access    public
387
+	 * @return    array of espresso config stuff
388
+	 */
389
+	public function get_espresso_config()
390
+	{
391
+		// grab espresso configuration
392
+		return apply_filters(
393
+			'FHEE__EE_Config__get_espresso_config__CFG',
394
+			get_option(EE_Config::OPTION_NAME, array())
395
+		);
396
+	}
397
+
398
+
399
+	/**
400
+	 *    double_check_config_comparison
401
+	 *
402
+	 * @access    public
403
+	 * @param string $option
404
+	 * @param        $old_value
405
+	 * @param        $value
406
+	 */
407
+	public function double_check_config_comparison($option = '', $old_value, $value)
408
+	{
409
+		// make sure we're checking the ee config
410
+		if ($option === EE_Config::OPTION_NAME) {
411
+			// run a loose comparison of the old value against the new value for type and properties,
412
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
413
+			if ($value != $old_value) {
414
+				// if they are NOT the same, then remove the hook,
415
+				// which means the subsequent update results will be based solely on the update query results
416
+				// the reason we do this is because, as stated above,
417
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
418
+				// this happens PRIOR to serialization and any subsequent update.
419
+				// If values are found to match their previous old value,
420
+				// then WP bails before performing any update.
421
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
422
+				// it just pulled from the db, with the one being passed to it (which will not match).
423
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
424
+				// MySQL MAY ALSO NOT perform the update because
425
+				// the string it sees in the db looks the same as the new one it has been passed!!!
426
+				// This results in the query returning an "affected rows" value of ZERO,
427
+				// which gets returned immediately by WP update_option and looks like an error.
428
+				remove_action('update_option', array($this, 'check_config_updated'));
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+	/**
435
+	 *    update_espresso_config
436
+	 *
437
+	 * @access   public
438
+	 */
439
+	protected function _reset_espresso_addon_config()
440
+	{
441
+		$this->_addon_option_names = array();
442
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
443
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
444
+			if ($addon_config_obj instanceof EE_Config_Base) {
445
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
446
+			}
447
+			$this->addons->{$addon_name} = null;
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 *    update_espresso_config
454
+	 *
455
+	 * @access   public
456
+	 * @param   bool $add_success
457
+	 * @param   bool $add_error
458
+	 * @return   bool
459
+	 */
460
+	public function update_espresso_config($add_success = false, $add_error = true)
461
+	{
462
+		// don't allow config updates during WP heartbeats
463
+		/** @var RequestInterface $request */
464
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
465
+		if ($request->isWordPressHeartbeat()) {
466
+			return false;
467
+		}
468
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
469
+		// $clone = clone( self::$_instance );
470
+		// self::$_instance = NULL;
471
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
472
+		$this->_reset_espresso_addon_config();
473
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
474
+		// but BEFORE the actual update occurs
475
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
476
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
477
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
478
+		$this->legacy_shortcodes_manager = null;
479
+		// now update "ee_config"
480
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
481
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
482
+		EE_Config::log(EE_Config::OPTION_NAME);
483
+		// if not saved... check if the hook we just added still exists;
484
+		// if it does, it means one of two things:
485
+		// that update_option bailed at the($value === $old_value) conditional,
486
+		// or...
487
+		// the db update query returned 0 rows affected
488
+		// (probably because the data  value was the same from it's perspective)
489
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
490
+		// but just means no update occurred, so don't display an error to the user.
491
+		// BUT... if update_option returns FALSE, AND the hook is missing,
492
+		// then it means that something truly went wrong
493
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
494
+		// remove our action since we don't want it in the system anymore
495
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
496
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
497
+		// self::$_instance = $clone;
498
+		// unset( $clone );
499
+		// if config remains the same or was updated successfully
500
+		if ($saved) {
501
+			if ($add_success) {
502
+				EE_Error::add_success(
503
+					esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
504
+					__FILE__,
505
+					__FUNCTION__,
506
+					__LINE__
507
+				);
508
+			}
509
+			return true;
510
+		} else {
511
+			if ($add_error) {
512
+				EE_Error::add_error(
513
+					esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
514
+					__FILE__,
515
+					__FUNCTION__,
516
+					__LINE__
517
+				);
518
+			}
519
+			return false;
520
+		}
521
+	}
522
+
523
+
524
+	/**
525
+	 *    _verify_config_params
526
+	 *
527
+	 * @access    private
528
+	 * @param    string         $section
529
+	 * @param    string         $name
530
+	 * @param    string         $config_class
531
+	 * @param    EE_Config_Base $config_obj
532
+	 * @param    array          $tests_to_run
533
+	 * @param    bool           $display_errors
534
+	 * @return    bool    TRUE on success, FALSE on fail
535
+	 */
536
+	private function _verify_config_params(
537
+		$section = '',
538
+		$name = '',
539
+		$config_class = '',
540
+		$config_obj = null,
541
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
542
+		$display_errors = true
543
+	) {
544
+		try {
545
+			foreach ($tests_to_run as $test) {
546
+				switch ($test) {
547
+					// TEST #1 : check that section was set
548
+					case 1:
549
+						if (empty($section)) {
550
+							if ($display_errors) {
551
+								throw new EE_Error(
552
+									sprintf(
553
+										esc_html__(
554
+											'No configuration section has been provided while attempting to save "%s".',
555
+											'event_espresso'
556
+										),
557
+										$config_class
558
+									)
559
+								);
560
+							}
561
+							return false;
562
+						}
563
+						break;
564
+					// TEST #2 : check that settings section exists
565
+					case 2:
566
+						if (! isset($this->{$section})) {
567
+							if ($display_errors) {
568
+								throw new EE_Error(
569
+									sprintf(
570
+										esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
571
+										$section
572
+									)
573
+								);
574
+							}
575
+							return false;
576
+						}
577
+						break;
578
+					// TEST #3 : check that section is the proper format
579
+					case 3:
580
+						if (
581
+							! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
582
+						) {
583
+							if ($display_errors) {
584
+								throw new EE_Error(
585
+									sprintf(
586
+										esc_html__(
587
+											'The "%s" configuration settings have not been formatted correctly.',
588
+											'event_espresso'
589
+										),
590
+										$section
591
+									)
592
+								);
593
+							}
594
+							return false;
595
+						}
596
+						break;
597
+					// TEST #4 : check that config section name has been set
598
+					case 4:
599
+						if (empty($name)) {
600
+							if ($display_errors) {
601
+								throw new EE_Error(
602
+									esc_html__(
603
+										'No name has been provided for the specific configuration section.',
604
+										'event_espresso'
605
+									)
606
+								);
607
+							}
608
+							return false;
609
+						}
610
+						break;
611
+					// TEST #5 : check that a config class name has been set
612
+					case 5:
613
+						if (empty($config_class)) {
614
+							if ($display_errors) {
615
+								throw new EE_Error(
616
+									esc_html__(
617
+										'No class name has been provided for the specific configuration section.',
618
+										'event_espresso'
619
+									)
620
+								);
621
+							}
622
+							return false;
623
+						}
624
+						break;
625
+					// TEST #6 : verify config class is accessible
626
+					case 6:
627
+						if (! class_exists($config_class)) {
628
+							if ($display_errors) {
629
+								throw new EE_Error(
630
+									sprintf(
631
+										esc_html__(
632
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
633
+											'event_espresso'
634
+										),
635
+										$config_class
636
+									)
637
+								);
638
+							}
639
+							return false;
640
+						}
641
+						break;
642
+					// TEST #7 : check that config has even been set
643
+					case 7:
644
+						if (! isset($this->{$section}->{$name})) {
645
+							if ($display_errors) {
646
+								throw new EE_Error(
647
+									sprintf(
648
+										esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
649
+										$section,
650
+										$name
651
+									)
652
+								);
653
+							}
654
+							return false;
655
+						} else {
656
+							// and make sure it's not serialized
657
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
658
+						}
659
+						break;
660
+					// TEST #8 : check that config is the requested type
661
+					case 8:
662
+						if (! $this->{$section}->{$name} instanceof $config_class) {
663
+							if ($display_errors) {
664
+								throw new EE_Error(
665
+									sprintf(
666
+										esc_html__(
667
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
668
+											'event_espresso'
669
+										),
670
+										$section,
671
+										$name,
672
+										$config_class
673
+									)
674
+								);
675
+							}
676
+							return false;
677
+						}
678
+						break;
679
+					// TEST #9 : verify config object
680
+					case 9:
681
+						if (! $config_obj instanceof EE_Config_Base) {
682
+							if ($display_errors) {
683
+								throw new EE_Error(
684
+									sprintf(
685
+										esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
686
+										print_r($config_obj, true)
687
+									)
688
+								);
689
+							}
690
+							return false;
691
+						}
692
+						break;
693
+				}
694
+			}
695
+		} catch (EE_Error $e) {
696
+			$e->get_error();
697
+		}
698
+		// you have successfully run the gauntlet
699
+		return true;
700
+	}
701
+
702
+
703
+	/**
704
+	 *    _generate_config_option_name
705
+	 *
706
+	 * @access        protected
707
+	 * @param        string $section
708
+	 * @param        string $name
709
+	 * @return        string
710
+	 */
711
+	private function _generate_config_option_name($section = '', $name = '')
712
+	{
713
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
714
+	}
715
+
716
+
717
+	/**
718
+	 *    _set_config_class
719
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
720
+	 *
721
+	 * @access    private
722
+	 * @param    string $config_class
723
+	 * @param    string $name
724
+	 * @return    string
725
+	 */
726
+	private function _set_config_class($config_class = '', $name = '')
727
+	{
728
+		return ! empty($config_class)
729
+			? $config_class
730
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
731
+	}
732
+
733
+
734
+	/**
735
+	 *    set_config
736
+	 *
737
+	 * @access    protected
738
+	 * @param    string         $section
739
+	 * @param    string         $name
740
+	 * @param    string         $config_class
741
+	 * @param    EE_Config_Base $config_obj
742
+	 * @return    EE_Config_Base
743
+	 */
744
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
745
+	{
746
+		// ensure config class is set to something
747
+		$config_class = $this->_set_config_class($config_class, $name);
748
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
749
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
750
+			return null;
751
+		}
752
+		$config_option_name = $this->_generate_config_option_name($section, $name);
753
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
754
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
755
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
756
+			$this->update_addon_option_names();
757
+		}
758
+		// verify the incoming config object but suppress errors
759
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
760
+			$config_obj = new $config_class();
761
+		}
762
+		if (get_option($config_option_name)) {
763
+			EE_Config::log($config_option_name);
764
+			update_option($config_option_name, $config_obj);
765
+			$this->{$section}->{$name} = $config_obj;
766
+			return $this->{$section}->{$name};
767
+		} else {
768
+			// create a wp-option for this config
769
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
770
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
771
+				return $this->{$section}->{$name};
772
+			} else {
773
+				EE_Error::add_error(
774
+					sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
775
+					__FILE__,
776
+					__FUNCTION__,
777
+					__LINE__
778
+				);
779
+				return null;
780
+			}
781
+		}
782
+	}
783
+
784
+
785
+	/**
786
+	 *    update_config
787
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
788
+	 *
789
+	 * @access    public
790
+	 * @param    string                $section
791
+	 * @param    string                $name
792
+	 * @param    EE_Config_Base|string $config_obj
793
+	 * @param    bool                  $throw_errors
794
+	 * @return    bool
795
+	 */
796
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
797
+	{
798
+		// don't allow config updates during WP heartbeats
799
+		/** @var RequestInterface $request */
800
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
801
+		if ($request->isWordPressHeartbeat()) {
802
+			return false;
803
+		}
804
+		$config_obj = maybe_unserialize($config_obj);
805
+		// get class name of the incoming object
806
+		$config_class = get_class($config_obj);
807
+		// run tests 1-5 and 9 to verify config
808
+		if (
809
+			! $this->_verify_config_params(
810
+				$section,
811
+				$name,
812
+				$config_class,
813
+				$config_obj,
814
+				array(1, 2, 3, 4, 7, 9)
815
+			)
816
+		) {
817
+			return false;
818
+		}
819
+		$config_option_name = $this->_generate_config_option_name($section, $name);
820
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
821
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
822
+			// save new config to db
823
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
824
+				return true;
825
+			}
826
+		} else {
827
+			// first check if the record already exists
828
+			$existing_config = get_option($config_option_name);
829
+			$config_obj = serialize($config_obj);
830
+			// just return if db record is already up to date (NOT type safe comparison)
831
+			if ($existing_config == $config_obj) {
832
+				$this->{$section}->{$name} = $config_obj;
833
+				return true;
834
+			} elseif (update_option($config_option_name, $config_obj)) {
835
+				EE_Config::log($config_option_name);
836
+				// update wp-option for this config class
837
+				$this->{$section}->{$name} = $config_obj;
838
+				return true;
839
+			} elseif ($throw_errors) {
840
+				EE_Error::add_error(
841
+					sprintf(
842
+						esc_html__(
843
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
844
+							'event_espresso'
845
+						),
846
+						$config_class,
847
+						'EE_Config->' . $section . '->' . $name
848
+					),
849
+					__FILE__,
850
+					__FUNCTION__,
851
+					__LINE__
852
+				);
853
+			}
854
+		}
855
+		return false;
856
+	}
857
+
858
+
859
+	/**
860
+	 *    get_config
861
+	 *
862
+	 * @access    public
863
+	 * @param    string $section
864
+	 * @param    string $name
865
+	 * @param    string $config_class
866
+	 * @return    mixed EE_Config_Base | NULL
867
+	 */
868
+	public function get_config($section = '', $name = '', $config_class = '')
869
+	{
870
+		// ensure config class is set to something
871
+		$config_class = $this->_set_config_class($config_class, $name);
872
+		// run tests 1-4, 6 and 7 to verify that all params have been set
873
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
874
+			return null;
875
+		}
876
+		// now test if the requested config object exists, but suppress errors
877
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
878
+			// config already exists, so pass it back
879
+			return $this->{$section}->{$name};
880
+		}
881
+		// load config option from db if it exists
882
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
883
+		// verify the newly retrieved config object, but suppress errors
884
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
885
+			// config is good, so set it and pass it back
886
+			$this->{$section}->{$name} = $config_obj;
887
+			return $this->{$section}->{$name};
888
+		}
889
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
890
+		$config_obj = $this->set_config($section, $name, $config_class);
891
+		// verify the newly created config object
892
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
893
+			return $this->{$section}->{$name};
894
+		} else {
895
+			EE_Error::add_error(
896
+				sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
897
+				__FILE__,
898
+				__FUNCTION__,
899
+				__LINE__
900
+			);
901
+		}
902
+		return null;
903
+	}
904
+
905
+
906
+	/**
907
+	 *    get_config_option
908
+	 *
909
+	 * @access    public
910
+	 * @param    string $config_option_name
911
+	 * @return    mixed EE_Config_Base | FALSE
912
+	 */
913
+	public function get_config_option($config_option_name = '')
914
+	{
915
+		// retrieve the wp-option for this config class.
916
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
917
+		if (empty($config_option)) {
918
+			EE_Config::log($config_option_name . '-NOT-FOUND');
919
+		}
920
+		return $config_option;
921
+	}
922
+
923
+
924
+	/**
925
+	 * log
926
+	 *
927
+	 * @param string $config_option_name
928
+	 */
929
+	public static function log($config_option_name = '')
930
+	{
931
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
932
+			$config_log = get_option(EE_Config::LOG_NAME, array());
933
+			/** @var RequestParams $request */
934
+			$request = LoaderFactory::getLoader()->getShared(RequestParams::class);
935
+			$config_log[ (string) microtime(true) ] = array(
936
+				'config_name' => $config_option_name,
937
+				'request'     => $request->requestParams(),
938
+			);
939
+			update_option(EE_Config::LOG_NAME, $config_log);
940
+		}
941
+	}
942
+
943
+
944
+	/**
945
+	 * trim_log
946
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
947
+	 */
948
+	public static function trim_log()
949
+	{
950
+		if (! EE_Config::logging_enabled()) {
951
+			return;
952
+		}
953
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
954
+		$log_length = count($config_log);
955
+		if ($log_length > EE_Config::LOG_LENGTH) {
956
+			ksort($config_log);
957
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
958
+			update_option(EE_Config::LOG_NAME, $config_log);
959
+		}
960
+	}
961
+
962
+
963
+	/**
964
+	 *    get_page_for_posts
965
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
966
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
967
+	 *
968
+	 * @access    public
969
+	 * @return    string
970
+	 */
971
+	public static function get_page_for_posts()
972
+	{
973
+		$page_for_posts = get_option('page_for_posts');
974
+		if (! $page_for_posts) {
975
+			return 'posts';
976
+		}
977
+		global $wpdb;
978
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
979
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
980
+	}
981
+
982
+
983
+	/**
984
+	 *    register_shortcodes_and_modules.
985
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
986
+	 *    In fact, this is where we give modules a chance to let core know they exist
987
+	 *    so they can help trigger maintenance mode if it's needed
988
+	 *
989
+	 * @access    public
990
+	 * @return    void
991
+	 */
992
+	public function register_shortcodes_and_modules()
993
+	{
994
+		// allow modules to set hooks for the rest of the system
995
+		EE_Registry::instance()->modules = $this->_register_modules();
996
+	}
997
+
998
+
999
+	/**
1000
+	 *    initialize_shortcodes_and_modules
1001
+	 *    meaning they can start adding their hooks to get stuff done
1002
+	 *
1003
+	 * @access    public
1004
+	 * @return    void
1005
+	 */
1006
+	public function initialize_shortcodes_and_modules()
1007
+	{
1008
+		// allow modules to set hooks for the rest of the system
1009
+		$this->_initialize_modules();
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 *    widgets_init
1015
+	 *
1016
+	 * @access private
1017
+	 * @return void
1018
+	 */
1019
+	public function widgets_init()
1020
+	{
1021
+		// only init widgets on admin pages when not in complete maintenance, and
1022
+		// on frontend when not in any maintenance mode
1023
+		if (
1024
+			! EE_Maintenance_Mode::instance()->level()
1025
+			|| (
1026
+				is_admin()
1027
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1028
+			)
1029
+		) {
1030
+			// grab list of installed widgets
1031
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1032
+			// filter list of modules to register
1033
+			$widgets_to_register = apply_filters(
1034
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1035
+				$widgets_to_register
1036
+			);
1037
+			if (! empty($widgets_to_register)) {
1038
+				// cycle thru widget folders
1039
+				foreach ($widgets_to_register as $widget_path) {
1040
+					// add to list of installed widget modules
1041
+					EE_Config::register_ee_widget($widget_path);
1042
+				}
1043
+			}
1044
+			// filter list of installed modules
1045
+			EE_Registry::instance()->widgets = apply_filters(
1046
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1047
+				EE_Registry::instance()->widgets
1048
+			);
1049
+		}
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 *    register_ee_widget - makes core aware of this widget
1055
+	 *
1056
+	 * @access    public
1057
+	 * @param    string $widget_path - full path up to and including widget folder
1058
+	 * @return    void
1059
+	 */
1060
+	public static function register_ee_widget($widget_path = null)
1061
+	{
1062
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1063
+		$widget_ext = '.widget.php';
1064
+		// make all separators match
1065
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1066
+		// does the file path INCLUDE the actual file name as part of the path ?
1067
+		if (strpos($widget_path, $widget_ext) !== false) {
1068
+			// grab and shortcode file name from directory name and break apart at dots
1069
+			$file_name = explode('.', basename($widget_path));
1070
+			// take first segment from file name pieces and remove class prefix if it exists
1071
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1072
+			// sanitize shortcode directory name
1073
+			$widget = sanitize_key($widget);
1074
+			// now we need to rebuild the shortcode path
1075
+			$widget_path = explode('/', $widget_path);
1076
+			// remove last segment
1077
+			array_pop($widget_path);
1078
+			// glue it back together
1079
+			$widget_path = implode(DS, $widget_path);
1080
+		} else {
1081
+			// grab and sanitize widget directory name
1082
+			$widget = sanitize_key(basename($widget_path));
1083
+		}
1084
+		// create classname from widget directory name
1085
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1086
+		// add class prefix
1087
+		$widget_class = 'EEW_' . $widget;
1088
+		// does the widget exist ?
1089
+		if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1090
+			$msg = sprintf(
1091
+				esc_html__(
1092
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1093
+					'event_espresso'
1094
+				),
1095
+				$widget_class,
1096
+				$widget_path . '/' . $widget_class . $widget_ext
1097
+			);
1098
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1099
+			return;
1100
+		}
1101
+		// load the widget class file
1102
+		require_once($widget_path . '/' . $widget_class . $widget_ext);
1103
+		// verify that class exists
1104
+		if (! class_exists($widget_class)) {
1105
+			$msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1106
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1107
+			return;
1108
+		}
1109
+		register_widget($widget_class);
1110
+		// add to array of registered widgets
1111
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 *        _register_modules
1117
+	 *
1118
+	 * @access private
1119
+	 * @return array
1120
+	 */
1121
+	private function _register_modules()
1122
+	{
1123
+		// grab list of installed modules
1124
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1125
+		// filter list of modules to register
1126
+		$modules_to_register = apply_filters(
1127
+			'FHEE__EE_Config__register_modules__modules_to_register',
1128
+			$modules_to_register
1129
+		);
1130
+		if (! empty($modules_to_register)) {
1131
+			// loop through folders
1132
+			foreach ($modules_to_register as $module_path) {
1133
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1134
+				if (
1135
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1136
+					&& $module_path !== EE_MODULES . 'gateways'
1137
+				) {
1138
+					// add to list of installed modules
1139
+					EE_Config::register_module($module_path);
1140
+				}
1141
+			}
1142
+		}
1143
+		// filter list of installed modules
1144
+		return apply_filters(
1145
+			'FHEE__EE_Config___register_modules__installed_modules',
1146
+			EE_Registry::instance()->modules
1147
+		);
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 *    register_module - makes core aware of this module
1153
+	 *
1154
+	 * @access    public
1155
+	 * @param    string $module_path - full path up to and including module folder
1156
+	 * @return    bool
1157
+	 */
1158
+	public static function register_module($module_path = null)
1159
+	{
1160
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1161
+		$module_ext = '.module.php';
1162
+		// make all separators match
1163
+		$module_path = str_replace(array('\\', '/'), '/', $module_path);
1164
+		// does the file path INCLUDE the actual file name as part of the path ?
1165
+		if (strpos($module_path, $module_ext) !== false) {
1166
+			// grab and shortcode file name from directory name and break apart at dots
1167
+			$module_file = explode('.', basename($module_path));
1168
+			// now we need to rebuild the shortcode path
1169
+			$module_path = explode('/', $module_path);
1170
+			// remove last segment
1171
+			array_pop($module_path);
1172
+			// glue it back together
1173
+			$module_path = implode('/', $module_path) . '/';
1174
+			// take first segment from file name pieces and sanitize it
1175
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1176
+			// ensure class prefix is added
1177
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1178
+		} else {
1179
+			// we need to generate the filename based off of the folder name
1180
+			// grab and sanitize module name
1181
+			$module = strtolower(basename($module_path));
1182
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1183
+			// like trailingslashit()
1184
+			$module_path = rtrim($module_path, '/') . '/';
1185
+			// create classname from module directory name
1186
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1187
+			// add class prefix
1188
+			$module_class = 'EED_' . $module;
1189
+		}
1190
+		// does the module exist ?
1191
+		if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1192
+			$msg = sprintf(
1193
+				esc_html__(
1194
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1195
+					'event_espresso'
1196
+				),
1197
+				$module
1198
+			);
1199
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
+			return false;
1201
+		}
1202
+		// load the module class file
1203
+		require_once($module_path . $module_class . $module_ext);
1204
+		// verify that class exists
1205
+		if (! class_exists($module_class)) {
1206
+			$msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1207
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1208
+			return false;
1209
+		}
1210
+		// add to array of registered modules
1211
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1212
+		do_action(
1213
+			'AHEE__EE_Config__register_module__complete',
1214
+			$module_class,
1215
+			EE_Registry::instance()->modules->{$module_class}
1216
+		);
1217
+		return true;
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 *    _initialize_modules
1223
+	 *    allow modules to set hooks for the rest of the system
1224
+	 *
1225
+	 * @access private
1226
+	 * @return void
1227
+	 */
1228
+	private function _initialize_modules()
1229
+	{
1230
+		// cycle thru shortcode folders
1231
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1232
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1233
+			// which set hooks ?
1234
+			if (is_admin()) {
1235
+				// fire immediately
1236
+				call_user_func(array($module_class, 'set_hooks_admin'));
1237
+			} else {
1238
+				// delay until other systems are online
1239
+				add_action(
1240
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1241
+					array($module_class, 'set_hooks')
1242
+				);
1243
+			}
1244
+		}
1245
+	}
1246
+
1247
+
1248
+	/**
1249
+	 *    register_route - adds module method routes to route_map
1250
+	 *
1251
+	 * @access    public
1252
+	 * @param    string $route       - "pretty" public alias for module method
1253
+	 * @param    string $module      - module name (classname without EED_ prefix)
1254
+	 * @param    string $method_name - the actual module method to be routed to
1255
+	 * @param    string $key         - url param key indicating a route is being called
1256
+	 * @return    bool
1257
+	 */
1258
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1259
+	{
1260
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1261
+		$module = str_replace('EED_', '', $module);
1262
+		$module_class = 'EED_' . $module;
1263
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1264
+			$msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1265
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1266
+			return false;
1267
+		}
1268
+		if (empty($route)) {
1269
+			$msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1270
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1271
+			return false;
1272
+		}
1273
+		if (! method_exists('EED_' . $module, $method_name)) {
1274
+			$msg = sprintf(
1275
+				esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1276
+				$route
1277
+			);
1278
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1279
+			return false;
1280
+		}
1281
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1282
+		return true;
1283
+	}
1284
+
1285
+
1286
+	/**
1287
+	 *    get_route - get module method route
1288
+	 *
1289
+	 * @access    public
1290
+	 * @param    string $route - "pretty" public alias for module method
1291
+	 * @param    string $key   - url param key indicating a route is being called
1292
+	 * @return    string
1293
+	 */
1294
+	public static function get_route($route = null, $key = 'ee')
1295
+	{
1296
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1297
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1298
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1299
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1300
+		}
1301
+		return null;
1302
+	}
1303
+
1304
+
1305
+	/**
1306
+	 *    get_routes - get ALL module method routes
1307
+	 *
1308
+	 * @access    public
1309
+	 * @return    array
1310
+	 */
1311
+	public static function get_routes()
1312
+	{
1313
+		return EE_Config::$_module_route_map;
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 *    register_forward - allows modules to forward request to another module for further processing
1319
+	 *
1320
+	 * @access    public
1321
+	 * @param    string       $route   - "pretty" public alias for module method
1322
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1323
+	 *                                 class, allows different forwards to be served based on status
1324
+	 * @param    array|string $forward - function name or array( class, method )
1325
+	 * @param    string       $key     - url param key indicating a route is being called
1326
+	 * @return    bool
1327
+	 */
1328
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1329
+	{
1330
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1331
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1332
+			$msg = sprintf(
1333
+				esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1334
+				$route
1335
+			);
1336
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1337
+			return false;
1338
+		}
1339
+		if (empty($forward)) {
1340
+			$msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1341
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1342
+			return false;
1343
+		}
1344
+		if (is_array($forward)) {
1345
+			if (! isset($forward[1])) {
1346
+				$msg = sprintf(
1347
+					esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1348
+					$route
1349
+				);
1350
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1351
+				return false;
1352
+			}
1353
+			if (! method_exists($forward[0], $forward[1])) {
1354
+				$msg = sprintf(
1355
+					esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1356
+					$forward[1],
1357
+					$route
1358
+				);
1359
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
+				return false;
1361
+			}
1362
+		} elseif (! function_exists($forward)) {
1363
+			$msg = sprintf(
1364
+				esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1365
+				$forward,
1366
+				$route
1367
+			);
1368
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1369
+			return false;
1370
+		}
1371
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1372
+		return true;
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 *    get_forward - get forwarding route
1378
+	 *
1379
+	 * @access    public
1380
+	 * @param    string  $route  - "pretty" public alias for module method
1381
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1382
+	 *                           allows different forwards to be served based on status
1383
+	 * @param    string  $key    - url param key indicating a route is being called
1384
+	 * @return    string
1385
+	 */
1386
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1387
+	{
1388
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1389
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1390
+			return apply_filters(
1391
+				'FHEE__EE_Config__get_forward',
1392
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1393
+				$route,
1394
+				$status
1395
+			);
1396
+		}
1397
+		return null;
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1403
+	 *    results
1404
+	 *
1405
+	 * @access    public
1406
+	 * @param    string  $route  - "pretty" public alias for module method
1407
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1408
+	 *                           allows different views to be served based on status
1409
+	 * @param    string  $view
1410
+	 * @param    string  $key    - url param key indicating a route is being called
1411
+	 * @return    bool
1412
+	 */
1413
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1414
+	{
1415
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1416
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1417
+			$msg = sprintf(
1418
+				esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1419
+				$route
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		if (! is_readable($view)) {
1425
+			$msg = sprintf(
1426
+				esc_html__(
1427
+					'The %s view file could not be found or is not readable due to file permissions.',
1428
+					'event_espresso'
1429
+				),
1430
+				$view
1431
+			);
1432
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1433
+			return false;
1434
+		}
1435
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1436
+		return true;
1437
+	}
1438
+
1439
+
1440
+	/**
1441
+	 *    get_view - get view for route and status
1442
+	 *
1443
+	 * @access    public
1444
+	 * @param    string  $route  - "pretty" public alias for module method
1445
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1446
+	 *                           allows different views to be served based on status
1447
+	 * @param    string  $key    - url param key indicating a route is being called
1448
+	 * @return    string
1449
+	 */
1450
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1451
+	{
1452
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1453
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1454
+			return apply_filters(
1455
+				'FHEE__EE_Config__get_view',
1456
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1457
+				$route,
1458
+				$status
1459
+			);
1460
+		}
1461
+		return null;
1462
+	}
1463
+
1464
+
1465
+	public function update_addon_option_names()
1466
+	{
1467
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1468
+	}
1469
+
1470
+
1471
+	public function shutdown()
1472
+	{
1473
+		$this->update_addon_option_names();
1474
+	}
1475
+
1476
+
1477
+	/**
1478
+	 * @return LegacyShortcodesManager
1479
+	 */
1480
+	public static function getLegacyShortcodesManager()
1481
+	{
1482
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1483
+			EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1484
+				LegacyShortcodesManager::class
1485
+			);
1486
+		}
1487
+		return EE_Config::instance()->legacy_shortcodes_manager;
1488
+	}
1489
+
1490
+
1491
+	/**
1492
+	 * register_shortcode - makes core aware of this shortcode
1493
+	 *
1494
+	 * @deprecated 4.9.26
1495
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1496
+	 * @return    bool
1497
+	 */
1498
+	public static function register_shortcode($shortcode_path = null)
1499
+	{
1500
+		EE_Error::doing_it_wrong(
1501
+			__METHOD__,
1502
+			esc_html__(
1503
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1504
+				'event_espresso'
1505
+			),
1506
+			'4.9.26'
1507
+		);
1508
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1509
+	}
1510
+}
2274 1511
 
2275
-    /**
2276
-     * ReCaptcha Type
2277
-     *
2278
-     * @var string $recaptcha_type
2279
-     *    options: 'audio', 'image'
2280
-     */
2281
-    public $recaptcha_type;
1512
+/**
1513
+ * Base class used for config classes. These classes should generally not have
1514
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1515
+ * basically, they should just be well-defined stdClasses
1516
+ */
1517
+class EE_Config_Base
1518
+{
2282 1519
 
2283
-    /**
2284
-     * ReCaptcha language
2285
-     *
2286
-     * @var string $recaptcha_language
2287
-     * eg 'en'
2288
-     */
2289
-    public $recaptcha_language;
1520
+	/**
1521
+	 * Utility function for escaping the value of a property and returning.
1522
+	 *
1523
+	 * @param string $property property name (checks to see if exists).
1524
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1525
+	 * @throws EE_Error
1526
+	 */
1527
+	public function get_pretty($property)
1528
+	{
1529
+		if (! property_exists($this, $property)) {
1530
+			throw new EE_Error(
1531
+				sprintf(
1532
+					esc_html__(
1533
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1534
+						'event_espresso'
1535
+					),
1536
+					get_class($this),
1537
+					$property
1538
+				)
1539
+			);
1540
+		}
1541
+		// just handling escaping of strings for now.
1542
+		if (is_string($this->{$property})) {
1543
+			return stripslashes($this->{$property});
1544
+		}
1545
+		return $this->{$property};
1546
+	}
1547
+
1548
+
1549
+	public function populate()
1550
+	{
1551
+		// grab defaults via a new instance of this class.
1552
+		$class_name = get_class($this);
1553
+		$defaults = new $class_name();
1554
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1555
+		// default from our $defaults object.
1556
+		foreach (get_object_vars($defaults) as $property => $value) {
1557
+			if ($this->{$property} === null) {
1558
+				$this->{$property} = $value;
1559
+			}
1560
+		}
1561
+		// cleanup
1562
+		unset($defaults);
1563
+	}
1564
+
1565
+
1566
+	/**
1567
+	 *        __isset
1568
+	 *
1569
+	 * @param $a
1570
+	 * @return bool
1571
+	 */
1572
+	public function __isset($a)
1573
+	{
1574
+		return false;
1575
+	}
1576
+
1577
+
1578
+	/**
1579
+	 *        __unset
1580
+	 *
1581
+	 * @param $a
1582
+	 * @return bool
1583
+	 */
1584
+	public function __unset($a)
1585
+	{
1586
+		return false;
1587
+	}
1588
+
1589
+
1590
+	/**
1591
+	 *        __clone
1592
+	 */
1593
+	public function __clone()
1594
+	{
1595
+	}
1596
+
1597
+
1598
+	/**
1599
+	 *        __wakeup
1600
+	 */
1601
+	public function __wakeup()
1602
+	{
1603
+	}
1604
+
1605
+
1606
+	/**
1607
+	 *        __destruct
1608
+	 */
1609
+	public function __destruct()
1610
+	{
1611
+	}
1612
+}
2290 1613
 
2291
-    /**
2292
-     * ReCaptcha public key
2293
-     *
2294
-     * @var string $recaptcha_publickey
2295
-     */
2296
-    public $recaptcha_publickey;
1614
+/**
1615
+ * Class for defining what's in the EE_Config relating to registration settings
1616
+ */
1617
+class EE_Core_Config extends EE_Config_Base
1618
+{
2297 1619
 
2298
-    /**
2299
-     * ReCaptcha private key
2300
-     *
2301
-     * @var string $recaptcha_privatekey
2302
-     */
2303
-    public $recaptcha_privatekey;
1620
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1621
+
1622
+
1623
+	public $current_blog_id;
1624
+
1625
+	public $ee_ueip_optin;
1626
+
1627
+	public $ee_ueip_has_notified;
1628
+
1629
+	/**
1630
+	 * Not to be confused with the 4 critical page variables (See
1631
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1632
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1633
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1634
+	 *
1635
+	 * @var array
1636
+	 */
1637
+	public $post_shortcodes;
1638
+
1639
+	public $module_route_map;
1640
+
1641
+	public $module_forward_map;
1642
+
1643
+	public $module_view_map;
1644
+
1645
+	/**
1646
+	 * The next 4 vars are the IDs of critical EE pages.
1647
+	 *
1648
+	 * @var int
1649
+	 */
1650
+	public $reg_page_id;
1651
+
1652
+	public $txn_page_id;
1653
+
1654
+	public $thank_you_page_id;
1655
+
1656
+	public $cancel_page_id;
1657
+
1658
+	/**
1659
+	 * The next 4 vars are the URLs of critical EE pages.
1660
+	 *
1661
+	 * @var int
1662
+	 */
1663
+	public $reg_page_url;
1664
+
1665
+	public $txn_page_url;
1666
+
1667
+	public $thank_you_page_url;
1668
+
1669
+	public $cancel_page_url;
1670
+
1671
+	/**
1672
+	 * The next vars relate to the custom slugs for EE CPT routes
1673
+	 */
1674
+	public $event_cpt_slug;
1675
+
1676
+	/**
1677
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1678
+	 * request across blog switches in a multisite context.
1679
+	 * Avoids extra queries to the db for this option.
1680
+	 *
1681
+	 * @var bool
1682
+	 */
1683
+	public static $ee_ueip_option;
1684
+
1685
+
1686
+	/**
1687
+	 *    class constructor
1688
+	 *
1689
+	 * @access    public
1690
+	 */
1691
+	public function __construct()
1692
+	{
1693
+		// set default organization settings
1694
+		$this->current_blog_id = get_current_blog_id();
1695
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1696
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1697
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1698
+		$this->post_shortcodes = array();
1699
+		$this->module_route_map = array();
1700
+		$this->module_forward_map = array();
1701
+		$this->module_view_map = array();
1702
+		// critical EE page IDs
1703
+		$this->reg_page_id = 0;
1704
+		$this->txn_page_id = 0;
1705
+		$this->thank_you_page_id = 0;
1706
+		$this->cancel_page_id = 0;
1707
+		// critical EE page URLs
1708
+		$this->reg_page_url = '';
1709
+		$this->txn_page_url = '';
1710
+		$this->thank_you_page_url = '';
1711
+		$this->cancel_page_url = '';
1712
+		// cpt slugs
1713
+		$this->event_cpt_slug = esc_html__('events', 'event_espresso');
1714
+		// ueip constant check
1715
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1716
+			$this->ee_ueip_optin = false;
1717
+			$this->ee_ueip_has_notified = true;
1718
+		}
1719
+	}
1720
+
1721
+
1722
+	/**
1723
+	 * @return array
1724
+	 */
1725
+	public function get_critical_pages_array()
1726
+	{
1727
+		return array(
1728
+			$this->reg_page_id,
1729
+			$this->txn_page_id,
1730
+			$this->thank_you_page_id,
1731
+			$this->cancel_page_id,
1732
+		);
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 * @return array
1738
+	 */
1739
+	public function get_critical_pages_shortcodes_array()
1740
+	{
1741
+		return array(
1742
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1743
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1744
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1745
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1746
+		);
1747
+	}
1748
+
1749
+
1750
+	/**
1751
+	 *  gets/returns URL for EE reg_page
1752
+	 *
1753
+	 * @access    public
1754
+	 * @return    string
1755
+	 */
1756
+	public function reg_page_url()
1757
+	{
1758
+		if (! $this->reg_page_url) {
1759
+			$this->reg_page_url = add_query_arg(
1760
+				array('uts' => time()),
1761
+				get_permalink($this->reg_page_id)
1762
+			) . '#checkout';
1763
+		}
1764
+		return $this->reg_page_url;
1765
+	}
1766
+
1767
+
1768
+	/**
1769
+	 *  gets/returns URL for EE txn_page
1770
+	 *
1771
+	 * @param array $query_args like what gets passed to
1772
+	 *                          add_query_arg() as the first argument
1773
+	 * @access    public
1774
+	 * @return    string
1775
+	 */
1776
+	public function txn_page_url($query_args = array())
1777
+	{
1778
+		if (! $this->txn_page_url) {
1779
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1780
+		}
1781
+		if ($query_args) {
1782
+			return add_query_arg($query_args, $this->txn_page_url);
1783
+		} else {
1784
+			return $this->txn_page_url;
1785
+		}
1786
+	}
1787
+
1788
+
1789
+	/**
1790
+	 *  gets/returns URL for EE thank_you_page
1791
+	 *
1792
+	 * @param array $query_args like what gets passed to
1793
+	 *                          add_query_arg() as the first argument
1794
+	 * @access    public
1795
+	 * @return    string
1796
+	 */
1797
+	public function thank_you_page_url($query_args = array())
1798
+	{
1799
+		if (! $this->thank_you_page_url) {
1800
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1801
+		}
1802
+		if ($query_args) {
1803
+			return add_query_arg($query_args, $this->thank_you_page_url);
1804
+		} else {
1805
+			return $this->thank_you_page_url;
1806
+		}
1807
+	}
1808
+
1809
+
1810
+	/**
1811
+	 *  gets/returns URL for EE cancel_page
1812
+	 *
1813
+	 * @access    public
1814
+	 * @return    string
1815
+	 */
1816
+	public function cancel_page_url()
1817
+	{
1818
+		if (! $this->cancel_page_url) {
1819
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1820
+		}
1821
+		return $this->cancel_page_url;
1822
+	}
1823
+
1824
+
1825
+	/**
1826
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1827
+	 *
1828
+	 * @since 4.7.5
1829
+	 */
1830
+	protected function _reset_urls()
1831
+	{
1832
+		$this->reg_page_url = '';
1833
+		$this->txn_page_url = '';
1834
+		$this->cancel_page_url = '';
1835
+		$this->thank_you_page_url = '';
1836
+	}
1837
+
1838
+
1839
+	/**
1840
+	 * Used to return what the optin value is set for the EE User Experience Program.
1841
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1842
+	 * on the main site only.
1843
+	 *
1844
+	 * @return bool
1845
+	 */
1846
+	protected function _get_main_ee_ueip_optin()
1847
+	{
1848
+		// if this is the main site then we can just bypass our direct query.
1849
+		if (is_main_site()) {
1850
+			return get_option(self::OPTION_NAME_UXIP, false);
1851
+		}
1852
+		// is this already cached for this request?  If so use it.
1853
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1854
+			return EE_Core_Config::$ee_ueip_option;
1855
+		}
1856
+		global $wpdb;
1857
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1858
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1859
+		$option = self::OPTION_NAME_UXIP;
1860
+		// set correct table for query
1861
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1862
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1863
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1864
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1865
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1866
+		// for the purpose of caching.
1867
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1868
+		if (false !== $pre) {
1869
+			EE_Core_Config::$ee_ueip_option = $pre;
1870
+			return EE_Core_Config::$ee_ueip_option;
1871
+		}
1872
+		$row = $wpdb->get_row(
1873
+			$wpdb->prepare(
1874
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1875
+				$option
1876
+			)
1877
+		);
1878
+		if (is_object($row)) {
1879
+			$value = $row->option_value;
1880
+		} else { // option does not exist so use default.
1881
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1882
+			return EE_Core_Config::$ee_ueip_option;
1883
+		}
1884
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1885
+		return EE_Core_Config::$ee_ueip_option;
1886
+	}
1887
+
1888
+
1889
+	/**
1890
+	 * Utility function for escaping the value of a property and returning.
1891
+	 *
1892
+	 * @param string $property property name (checks to see if exists).
1893
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1894
+	 * @throws EE_Error
1895
+	 */
1896
+	public function get_pretty($property)
1897
+	{
1898
+		if ($property === self::OPTION_NAME_UXIP) {
1899
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1900
+		}
1901
+		return parent::get_pretty($property);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1907
+	 * on the object.
1908
+	 *
1909
+	 * @return array
1910
+	 */
1911
+	public function __sleep()
1912
+	{
1913
+		// reset all url properties
1914
+		$this->_reset_urls();
1915
+		// return what to save to db
1916
+		return array_keys(get_object_vars($this));
1917
+	}
1918
+}
2304 1919
 
2305
-    /**
2306
-     * array of form names protected by ReCaptcha
2307
-     *
2308
-     * @var array $recaptcha_protected_forms
2309
-     */
2310
-    public $recaptcha_protected_forms;
1920
+/**
1921
+ * Config class for storing info on the Organization
1922
+ */
1923
+class EE_Organization_Config extends EE_Config_Base
1924
+{
2311 1925
 
2312
-    /**
2313
-     * ReCaptcha width
2314
-     *
2315
-     * @var int $recaptcha_width
2316
-     * @deprecated
2317
-     */
2318
-    public $recaptcha_width;
1926
+	/**
1927
+	 * @var string $name
1928
+	 * eg EE4.1
1929
+	 */
1930
+	public $name;
1931
+
1932
+	/**
1933
+	 * @var string $address_1
1934
+	 * eg 123 Onna Road
1935
+	 */
1936
+	public $address_1 = '';
1937
+
1938
+	/**
1939
+	 * @var string $address_2
1940
+	 * eg PO Box 123
1941
+	 */
1942
+	public $address_2 = '';
1943
+
1944
+	/**
1945
+	 * @var string $city
1946
+	 * eg Inna City
1947
+	 */
1948
+	public $city = '';
1949
+
1950
+	/**
1951
+	 * @var int $STA_ID
1952
+	 * eg 4
1953
+	 */
1954
+	public $STA_ID = 0;
1955
+
1956
+	/**
1957
+	 * @var string $CNT_ISO
1958
+	 * eg US
1959
+	 */
1960
+	public $CNT_ISO = '';
1961
+
1962
+	/**
1963
+	 * @var string $zip
1964
+	 * eg 12345  or V1A 2B3
1965
+	 */
1966
+	public $zip = '';
1967
+
1968
+	/**
1969
+	 * @var string $email
1970
+	 * eg [email protected]
1971
+	 */
1972
+	public $email;
1973
+
1974
+	/**
1975
+	 * @var string $phone
1976
+	 * eg. 111-111-1111
1977
+	 */
1978
+	public $phone = '';
1979
+
1980
+	/**
1981
+	 * @var string $vat
1982
+	 * VAT/Tax Number
1983
+	 */
1984
+	public $vat = '';
1985
+
1986
+	/**
1987
+	 * @var string $logo_url
1988
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1989
+	 */
1990
+	public $logo_url = '';
1991
+
1992
+	/**
1993
+	 * The below are all various properties for holding links to organization social network profiles
1994
+	 *
1995
+	 * @var string
1996
+	 */
1997
+	/**
1998
+	 * facebook (facebook.com/profile.name)
1999
+	 *
2000
+	 * @var string
2001
+	 */
2002
+	public $facebook = '';
2003
+
2004
+	/**
2005
+	 * twitter (twitter.com/twitter_handle)
2006
+	 *
2007
+	 * @var string
2008
+	 */
2009
+	public $twitter = '';
2010
+
2011
+	/**
2012
+	 * linkedin (linkedin.com/in/profile_name)
2013
+	 *
2014
+	 * @var string
2015
+	 */
2016
+	public $linkedin = '';
2017
+
2018
+	/**
2019
+	 * pinterest (www.pinterest.com/profile_name)
2020
+	 *
2021
+	 * @var string
2022
+	 */
2023
+	public $pinterest = '';
2024
+
2025
+	/**
2026
+	 * google+ (google.com/+profileName)
2027
+	 *
2028
+	 * @var string
2029
+	 */
2030
+	public $google = '';
2031
+
2032
+	/**
2033
+	 * instagram (instagram.com/handle)
2034
+	 *
2035
+	 * @var string
2036
+	 */
2037
+	public $instagram = '';
2038
+
2039
+
2040
+	/**
2041
+	 *    class constructor
2042
+	 *
2043
+	 * @access    public
2044
+	 */
2045
+	public function __construct()
2046
+	{
2047
+		// set default organization settings
2048
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2049
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2050
+		$this->email = get_bloginfo('admin_email');
2051
+	}
2052
+}
2319 2053
 
2320
-    /**
2321
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2322
-     *
2323
-     * @var boolean $track_invalid_checkout_access
2324
-     */
2325
-    protected $track_invalid_checkout_access = true;
2054
+/**
2055
+ * Class for defining what's in the EE_Config relating to currency
2056
+ */
2057
+class EE_Currency_Config extends EE_Config_Base
2058
+{
2326 2059
 
2327
-    /**
2328
-     * Whether or not to show the privacy policy consent checkbox
2329
-     *
2330
-     * @var bool
2331
-     */
2332
-    public $consent_checkbox_enabled;
2060
+	/**
2061
+	 * @var string $code
2062
+	 * eg 'US'
2063
+	 */
2064
+	public $code;
2065
+
2066
+	/**
2067
+	 * @var string $name
2068
+	 * eg 'Dollar'
2069
+	 */
2070
+	public $name;
2071
+
2072
+	/**
2073
+	 * plural name
2074
+	 *
2075
+	 * @var string $plural
2076
+	 * eg 'Dollars'
2077
+	 */
2078
+	public $plural;
2079
+
2080
+	/**
2081
+	 * currency sign
2082
+	 *
2083
+	 * @var string $sign
2084
+	 * eg '$'
2085
+	 */
2086
+	public $sign;
2087
+
2088
+	/**
2089
+	 * Whether the currency sign should come before the number or not
2090
+	 *
2091
+	 * @var boolean $sign_b4
2092
+	 */
2093
+	public $sign_b4;
2094
+
2095
+	/**
2096
+	 * How many digits should come after the decimal place
2097
+	 *
2098
+	 * @var int $dec_plc
2099
+	 */
2100
+	public $dec_plc;
2101
+
2102
+	/**
2103
+	 * Symbol to use for decimal mark
2104
+	 *
2105
+	 * @var string $dec_mrk
2106
+	 * eg '.'
2107
+	 */
2108
+	public $dec_mrk;
2109
+
2110
+	/**
2111
+	 * Symbol to use for thousands
2112
+	 *
2113
+	 * @var string $thsnds
2114
+	 * eg ','
2115
+	 */
2116
+	public $thsnds;
2117
+
2118
+
2119
+	/**
2120
+	 *    class constructor
2121
+	 *
2122
+	 * @access    public
2123
+	 * @param string $CNT_ISO
2124
+	 * @throws EE_Error
2125
+	 * @throws ReflectionException
2126
+	 */
2127
+	public function __construct($CNT_ISO = '')
2128
+	{
2129
+		/** @var TableAnalysis $table_analysis */
2130
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2131
+		// get country code from organization settings or use default
2132
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2133
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2134
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2135
+			: '';
2136
+		// but override if requested
2137
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2138
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2139
+		if (
2140
+			! empty($CNT_ISO)
2141
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2142
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2143
+		) {
2144
+			// retrieve the country settings from the db, just in case they have been customized
2145
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2146
+			if ($country instanceof EE_Country) {
2147
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2148
+				$this->name = $country->currency_name_single();    // Dollar
2149
+				$this->plural = $country->currency_name_plural();    // Dollars
2150
+				$this->sign = $country->currency_sign();            // currency sign: $
2151
+				$this->sign_b4 = $country->currency_sign_before(
2152
+				);        // currency sign before or after: $TRUE  or  FALSE$
2153
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2154
+				$this->dec_mrk = $country->currency_decimal_mark(
2155
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2156
+				$this->thsnds = $country->currency_thousands_separator(
2157
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2158
+			}
2159
+		}
2160
+		// fallback to hardcoded defaults, in case the above failed
2161
+		if (empty($this->code)) {
2162
+			// set default currency settings
2163
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2164
+			$this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2165
+			$this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2166
+			$this->sign = '$';    // currency sign: $
2167
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2168
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2169
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2170
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2171
+		}
2172
+	}
2173
+}
2333 2174
 
2334
-    /**
2335
-     * Label text to show on the checkbox
2336
-     *
2337
-     * @var string
2338
-     */
2339
-    public $consent_checkbox_label_text;
2175
+/**
2176
+ * Class for defining what's in the EE_Config relating to registration settings
2177
+ */
2178
+class EE_Registration_Config extends EE_Config_Base
2179
+{
2340 2180
 
2341
-    /*
2181
+	/**
2182
+	 * Default registration status
2183
+	 *
2184
+	 * @var string $default_STS_ID
2185
+	 * eg 'RPP'
2186
+	 */
2187
+	public $default_STS_ID;
2188
+
2189
+	/**
2190
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2191
+	 * registrations)
2192
+	 *
2193
+	 * @var int
2194
+	 */
2195
+	public $default_maximum_number_of_tickets;
2196
+
2197
+	/**
2198
+	 * level of validation to apply to email addresses
2199
+	 *
2200
+	 * @var string $email_validation_level
2201
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2202
+	 */
2203
+	public $email_validation_level;
2204
+
2205
+	/**
2206
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2207
+	 *
2208
+	 * @var boolean $show_pending_payment_options
2209
+	 */
2210
+	public $show_pending_payment_options;
2211
+
2212
+	/**
2213
+	 * Whether to skip the registration confirmation page
2214
+	 *
2215
+	 * @var boolean $skip_reg_confirmation
2216
+	 */
2217
+	public $skip_reg_confirmation;
2218
+
2219
+	/**
2220
+	 * an array of SPCO reg steps where:
2221
+	 *        the keys denotes the reg step order
2222
+	 *        each element consists of an array with the following elements:
2223
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2224
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2225
+	 *            "slug" => the URL param used to trigger the reg step
2226
+	 *
2227
+	 * @var array $reg_steps
2228
+	 */
2229
+	public $reg_steps;
2230
+
2231
+	/**
2232
+	 * Whether registration confirmation should be the last page of SPCO
2233
+	 *
2234
+	 * @var boolean $reg_confirmation_last
2235
+	 */
2236
+	public $reg_confirmation_last;
2237
+
2238
+	/**
2239
+	 * Whether or not to enable the EE Bot Trap
2240
+	 *
2241
+	 * @var boolean $use_bot_trap
2242
+	 */
2243
+	public $use_bot_trap;
2244
+
2245
+	/**
2246
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2247
+	 *
2248
+	 * @var boolean $use_encryption
2249
+	 */
2250
+	public $use_encryption;
2251
+
2252
+	/**
2253
+	 * Whether or not to use ReCaptcha
2254
+	 *
2255
+	 * @var boolean $use_captcha
2256
+	 */
2257
+	public $use_captcha;
2258
+
2259
+	/**
2260
+	 * ReCaptcha Theme
2261
+	 *
2262
+	 * @var string $recaptcha_theme
2263
+	 *    options: 'dark', 'light', 'invisible'
2264
+	 */
2265
+	public $recaptcha_theme;
2266
+
2267
+	/**
2268
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2269
+	 *
2270
+	 * @var string $recaptcha_badge
2271
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2272
+	 */
2273
+	public $recaptcha_badge;
2274
+
2275
+	/**
2276
+	 * ReCaptcha Type
2277
+	 *
2278
+	 * @var string $recaptcha_type
2279
+	 *    options: 'audio', 'image'
2280
+	 */
2281
+	public $recaptcha_type;
2282
+
2283
+	/**
2284
+	 * ReCaptcha language
2285
+	 *
2286
+	 * @var string $recaptcha_language
2287
+	 * eg 'en'
2288
+	 */
2289
+	public $recaptcha_language;
2290
+
2291
+	/**
2292
+	 * ReCaptcha public key
2293
+	 *
2294
+	 * @var string $recaptcha_publickey
2295
+	 */
2296
+	public $recaptcha_publickey;
2297
+
2298
+	/**
2299
+	 * ReCaptcha private key
2300
+	 *
2301
+	 * @var string $recaptcha_privatekey
2302
+	 */
2303
+	public $recaptcha_privatekey;
2304
+
2305
+	/**
2306
+	 * array of form names protected by ReCaptcha
2307
+	 *
2308
+	 * @var array $recaptcha_protected_forms
2309
+	 */
2310
+	public $recaptcha_protected_forms;
2311
+
2312
+	/**
2313
+	 * ReCaptcha width
2314
+	 *
2315
+	 * @var int $recaptcha_width
2316
+	 * @deprecated
2317
+	 */
2318
+	public $recaptcha_width;
2319
+
2320
+	/**
2321
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2322
+	 *
2323
+	 * @var boolean $track_invalid_checkout_access
2324
+	 */
2325
+	protected $track_invalid_checkout_access = true;
2326
+
2327
+	/**
2328
+	 * Whether or not to show the privacy policy consent checkbox
2329
+	 *
2330
+	 * @var bool
2331
+	 */
2332
+	public $consent_checkbox_enabled;
2333
+
2334
+	/**
2335
+	 * Label text to show on the checkbox
2336
+	 *
2337
+	 * @var string
2338
+	 */
2339
+	public $consent_checkbox_label_text;
2340
+
2341
+	/*
2342 2342
      * String describing how long to keep payment logs. Passed into DateTime constructor
2343 2343
      * @var string
2344 2344
      */
2345
-    public $gateway_log_lifespan = '1 week';
2346
-
2347
-    /**
2348
-     * Enable copy attendee info at form
2349
-     *
2350
-     * @var boolean $enable_copy_attendee
2351
-     */
2352
-    protected $copy_attendee_info = true;
2353
-
2354
-
2355
-    /**
2356
-     *    class constructor
2357
-     *
2358
-     * @access    public
2359
-     */
2360
-    public function __construct()
2361
-    {
2362
-        // set default registration settings
2363
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2364
-        $this->email_validation_level = 'wp_default';
2365
-        $this->show_pending_payment_options = true;
2366
-        $this->skip_reg_confirmation = true;
2367
-        $this->reg_steps = array();
2368
-        $this->reg_confirmation_last = false;
2369
-        $this->use_bot_trap = true;
2370
-        $this->use_encryption = true;
2371
-        $this->use_captcha = false;
2372
-        $this->recaptcha_theme = 'light';
2373
-        $this->recaptcha_badge = 'bottomleft';
2374
-        $this->recaptcha_type = 'image';
2375
-        $this->recaptcha_language = 'en';
2376
-        $this->recaptcha_publickey = null;
2377
-        $this->recaptcha_privatekey = null;
2378
-        $this->recaptcha_protected_forms = array();
2379
-        $this->recaptcha_width = 500;
2380
-        $this->default_maximum_number_of_tickets = 10;
2381
-        $this->consent_checkbox_enabled = false;
2382
-        $this->consent_checkbox_label_text = '';
2383
-        $this->gateway_log_lifespan = '7 days';
2384
-        $this->copy_attendee_info = true;
2385
-    }
2386
-
2387
-
2388
-    /**
2389
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2390
-     *
2391
-     * @since 4.8.8.rc.019
2392
-     */
2393
-    public function do_hooks()
2394
-    {
2395
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2396
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2397
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2403
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2404
-     */
2405
-    public function set_default_reg_status_on_EEM_Event()
2406
-    {
2407
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2408
-    }
2409
-
2410
-
2411
-    /**
2412
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2413
-     * for Events matches the config setting for default_maximum_number_of_tickets
2414
-     */
2415
-    public function set_default_max_ticket_on_EEM_Event()
2416
-    {
2417
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2418
-    }
2419
-
2420
-
2421
-    /**
2422
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2423
-     * constructed because that happens before we can get the privacy policy page's permalink.
2424
-     *
2425
-     * @throws InvalidArgumentException
2426
-     * @throws InvalidDataTypeException
2427
-     * @throws InvalidInterfaceException
2428
-     */
2429
-    public function setDefaultCheckboxLabelText()
2430
-    {
2431
-        if (
2432
-            $this->getConsentCheckboxLabelText() === null
2433
-            || $this->getConsentCheckboxLabelText() === ''
2434
-        ) {
2435
-            $opening_a_tag = '';
2436
-            $closing_a_tag = '';
2437
-            if (function_exists('get_privacy_policy_url')) {
2438
-                $privacy_page_url = get_privacy_policy_url();
2439
-                if (! empty($privacy_page_url)) {
2440
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2441
-                    $closing_a_tag = '</a>';
2442
-                }
2443
-            }
2444
-            $loader = LoaderFactory::getLoader();
2445
-            $org_config = $loader->getShared('EE_Organization_Config');
2446
-            /**
2447
-             * @var $org_config EE_Organization_Config
2448
-             */
2449
-
2450
-            $this->setConsentCheckboxLabelText(
2451
-                sprintf(
2452
-                    esc_html__(
2453
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2454
-                        'event_espresso'
2455
-                    ),
2456
-                    $org_config->name,
2457
-                    $opening_a_tag,
2458
-                    $closing_a_tag
2459
-                )
2460
-            );
2461
-        }
2462
-    }
2463
-
2464
-
2465
-    /**
2466
-     * @return boolean
2467
-     */
2468
-    public function track_invalid_checkout_access()
2469
-    {
2470
-        return $this->track_invalid_checkout_access;
2471
-    }
2472
-
2473
-
2474
-    /**
2475
-     * @param boolean $track_invalid_checkout_access
2476
-     */
2477
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2478
-    {
2479
-        $this->track_invalid_checkout_access = filter_var(
2480
-            $track_invalid_checkout_access,
2481
-            FILTER_VALIDATE_BOOLEAN
2482
-        );
2483
-    }
2484
-
2485
-    /**
2486
-     * @return boolean
2487
-     */
2488
-    public function copyAttendeeInfo()
2489
-    {
2490
-        return $this->copy_attendee_info;
2491
-    }
2492
-
2493
-
2494
-    /**
2495
-     * @param boolean $copy_attendee_info
2496
-     */
2497
-    public function setCopyAttendeeInfo($copy_attendee_info)
2498
-    {
2499
-        $this->copy_attendee_info = filter_var(
2500
-            $copy_attendee_info,
2501
-            FILTER_VALIDATE_BOOLEAN
2502
-        );
2503
-    }
2504
-
2505
-
2506
-    /**
2507
-     * Gets the options to make availalbe for the gateway log lifespan
2508
-     * @return array
2509
-     */
2510
-    public function gatewayLogLifespanOptions()
2511
-    {
2512
-        return (array) apply_filters(
2513
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2514
-            array(
2515
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2516
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2517
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2518
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2519
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2520
-            )
2521
-        );
2522
-    }
2523
-
2524
-
2525
-    /**
2526
-     * @return bool
2527
-     */
2528
-    public function isConsentCheckboxEnabled()
2529
-    {
2530
-        return $this->consent_checkbox_enabled;
2531
-    }
2532
-
2533
-
2534
-    /**
2535
-     * @param bool $consent_checkbox_enabled
2536
-     */
2537
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2538
-    {
2539
-        $this->consent_checkbox_enabled = filter_var(
2540
-            $consent_checkbox_enabled,
2541
-            FILTER_VALIDATE_BOOLEAN
2542
-        );
2543
-    }
2544
-
2545
-
2546
-    /**
2547
-     * @return string
2548
-     */
2549
-    public function getConsentCheckboxLabelText()
2550
-    {
2551
-        return $this->consent_checkbox_label_text;
2552
-    }
2553
-
2554
-
2555
-    /**
2556
-     * @param string $consent_checkbox_label_text
2557
-     */
2558
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2559
-    {
2560
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2561
-    }
2345
+	public $gateway_log_lifespan = '1 week';
2346
+
2347
+	/**
2348
+	 * Enable copy attendee info at form
2349
+	 *
2350
+	 * @var boolean $enable_copy_attendee
2351
+	 */
2352
+	protected $copy_attendee_info = true;
2353
+
2354
+
2355
+	/**
2356
+	 *    class constructor
2357
+	 *
2358
+	 * @access    public
2359
+	 */
2360
+	public function __construct()
2361
+	{
2362
+		// set default registration settings
2363
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2364
+		$this->email_validation_level = 'wp_default';
2365
+		$this->show_pending_payment_options = true;
2366
+		$this->skip_reg_confirmation = true;
2367
+		$this->reg_steps = array();
2368
+		$this->reg_confirmation_last = false;
2369
+		$this->use_bot_trap = true;
2370
+		$this->use_encryption = true;
2371
+		$this->use_captcha = false;
2372
+		$this->recaptcha_theme = 'light';
2373
+		$this->recaptcha_badge = 'bottomleft';
2374
+		$this->recaptcha_type = 'image';
2375
+		$this->recaptcha_language = 'en';
2376
+		$this->recaptcha_publickey = null;
2377
+		$this->recaptcha_privatekey = null;
2378
+		$this->recaptcha_protected_forms = array();
2379
+		$this->recaptcha_width = 500;
2380
+		$this->default_maximum_number_of_tickets = 10;
2381
+		$this->consent_checkbox_enabled = false;
2382
+		$this->consent_checkbox_label_text = '';
2383
+		$this->gateway_log_lifespan = '7 days';
2384
+		$this->copy_attendee_info = true;
2385
+	}
2386
+
2387
+
2388
+	/**
2389
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2390
+	 *
2391
+	 * @since 4.8.8.rc.019
2392
+	 */
2393
+	public function do_hooks()
2394
+	{
2395
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2396
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2397
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2403
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2404
+	 */
2405
+	public function set_default_reg_status_on_EEM_Event()
2406
+	{
2407
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2408
+	}
2409
+
2410
+
2411
+	/**
2412
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2413
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2414
+	 */
2415
+	public function set_default_max_ticket_on_EEM_Event()
2416
+	{
2417
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2418
+	}
2419
+
2420
+
2421
+	/**
2422
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2423
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2424
+	 *
2425
+	 * @throws InvalidArgumentException
2426
+	 * @throws InvalidDataTypeException
2427
+	 * @throws InvalidInterfaceException
2428
+	 */
2429
+	public function setDefaultCheckboxLabelText()
2430
+	{
2431
+		if (
2432
+			$this->getConsentCheckboxLabelText() === null
2433
+			|| $this->getConsentCheckboxLabelText() === ''
2434
+		) {
2435
+			$opening_a_tag = '';
2436
+			$closing_a_tag = '';
2437
+			if (function_exists('get_privacy_policy_url')) {
2438
+				$privacy_page_url = get_privacy_policy_url();
2439
+				if (! empty($privacy_page_url)) {
2440
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2441
+					$closing_a_tag = '</a>';
2442
+				}
2443
+			}
2444
+			$loader = LoaderFactory::getLoader();
2445
+			$org_config = $loader->getShared('EE_Organization_Config');
2446
+			/**
2447
+			 * @var $org_config EE_Organization_Config
2448
+			 */
2449
+
2450
+			$this->setConsentCheckboxLabelText(
2451
+				sprintf(
2452
+					esc_html__(
2453
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2454
+						'event_espresso'
2455
+					),
2456
+					$org_config->name,
2457
+					$opening_a_tag,
2458
+					$closing_a_tag
2459
+				)
2460
+			);
2461
+		}
2462
+	}
2463
+
2464
+
2465
+	/**
2466
+	 * @return boolean
2467
+	 */
2468
+	public function track_invalid_checkout_access()
2469
+	{
2470
+		return $this->track_invalid_checkout_access;
2471
+	}
2472
+
2473
+
2474
+	/**
2475
+	 * @param boolean $track_invalid_checkout_access
2476
+	 */
2477
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2478
+	{
2479
+		$this->track_invalid_checkout_access = filter_var(
2480
+			$track_invalid_checkout_access,
2481
+			FILTER_VALIDATE_BOOLEAN
2482
+		);
2483
+	}
2484
+
2485
+	/**
2486
+	 * @return boolean
2487
+	 */
2488
+	public function copyAttendeeInfo()
2489
+	{
2490
+		return $this->copy_attendee_info;
2491
+	}
2492
+
2493
+
2494
+	/**
2495
+	 * @param boolean $copy_attendee_info
2496
+	 */
2497
+	public function setCopyAttendeeInfo($copy_attendee_info)
2498
+	{
2499
+		$this->copy_attendee_info = filter_var(
2500
+			$copy_attendee_info,
2501
+			FILTER_VALIDATE_BOOLEAN
2502
+		);
2503
+	}
2504
+
2505
+
2506
+	/**
2507
+	 * Gets the options to make availalbe for the gateway log lifespan
2508
+	 * @return array
2509
+	 */
2510
+	public function gatewayLogLifespanOptions()
2511
+	{
2512
+		return (array) apply_filters(
2513
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2514
+			array(
2515
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2516
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2517
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2518
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2519
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2520
+			)
2521
+		);
2522
+	}
2523
+
2524
+
2525
+	/**
2526
+	 * @return bool
2527
+	 */
2528
+	public function isConsentCheckboxEnabled()
2529
+	{
2530
+		return $this->consent_checkbox_enabled;
2531
+	}
2532
+
2533
+
2534
+	/**
2535
+	 * @param bool $consent_checkbox_enabled
2536
+	 */
2537
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2538
+	{
2539
+		$this->consent_checkbox_enabled = filter_var(
2540
+			$consent_checkbox_enabled,
2541
+			FILTER_VALIDATE_BOOLEAN
2542
+		);
2543
+	}
2544
+
2545
+
2546
+	/**
2547
+	 * @return string
2548
+	 */
2549
+	public function getConsentCheckboxLabelText()
2550
+	{
2551
+		return $this->consent_checkbox_label_text;
2552
+	}
2553
+
2554
+
2555
+	/**
2556
+	 * @param string $consent_checkbox_label_text
2557
+	 */
2558
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2559
+	{
2560
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2561
+	}
2562 2562
 }
2563 2563
 
2564 2564
 /**
@@ -2567,180 +2567,180 @@  discard block
 block discarded – undo
2567 2567
 class EE_Admin_Config extends EE_Config_Base
2568 2568
 {
2569 2569
 
2570
-    /**
2571
-     * @var boolean $useAdvancedEditor
2572
-     */
2573
-    private $useAdvancedEditor;
2574
-
2575
-    /**
2576
-     * @var boolean $use_personnel_manager
2577
-     */
2578
-    public $use_personnel_manager;
2579
-
2580
-    /**
2581
-     * @var boolean $use_dashboard_widget
2582
-     */
2583
-    public $use_dashboard_widget;
2584
-
2585
-    /**
2586
-     * @var int $events_in_dashboard
2587
-     */
2588
-    public $events_in_dashboard;
2589
-
2590
-    /**
2591
-     * @var boolean $use_event_timezones
2592
-     */
2593
-    public $use_event_timezones;
2594
-
2595
-    /**
2596
-     * @var string $log_file_name
2597
-     */
2598
-    public $log_file_name;
2599
-
2600
-    /**
2601
-     * @var string $debug_file_name
2602
-     */
2603
-    public $debug_file_name;
2604
-
2605
-    /**
2606
-     * @var boolean $use_remote_logging
2607
-     */
2608
-    public $use_remote_logging;
2609
-
2610
-    /**
2611
-     * @var string $remote_logging_url
2612
-     */
2613
-    public $remote_logging_url;
2614
-
2615
-    /**
2616
-     * @var boolean $show_reg_footer
2617
-     */
2618
-    public $show_reg_footer;
2619
-
2620
-    /**
2621
-     * @var string $affiliate_id
2622
-     */
2623
-    public $affiliate_id;
2624
-
2625
-    /**
2626
-     * adds extra layer of encoding to session data to prevent serialization errors
2627
-     * but is incompatible with some server configuration errors
2628
-     * if you get "500 internal server errors" during registration, try turning this on
2629
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2630
-     *
2631
-     * @var boolean $encode_session_data
2632
-     */
2633
-    private $encode_session_data = false;
2634
-
2635
-    /**
2636
-     * @var boolean
2637
-     */
2638
-    private $is_caffeinated;
2639
-
2640
-
2641
-    /**
2642
-     *    class constructor
2643
-     *
2644
-     * @access    public
2645
-     */
2646
-    public function __construct()
2647
-    {
2648
-        // set default general admin settings
2649
-        $this->useAdvancedEditor = true;
2650
-        $this->use_personnel_manager = true;
2651
-        $this->use_dashboard_widget = true;
2652
-        $this->events_in_dashboard = 30;
2653
-        $this->use_event_timezones = false;
2654
-        $this->use_remote_logging = false;
2655
-        $this->remote_logging_url = null;
2656
-        $this->show_reg_footer = apply_filters(
2657
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2658
-            false
2659
-        );
2660
-        $this->affiliate_id = 'default';
2661
-        $this->encode_session_data = false;
2662
-    }
2663
-
2664
-
2665
-    /**
2666
-     * @param bool $reset
2667
-     * @return string
2668
-     */
2669
-    public function log_file_name($reset = false)
2670
-    {
2671
-        if (empty($this->log_file_name) || $reset) {
2672
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2673
-            EE_Config::instance()->update_espresso_config(false, false);
2674
-        }
2675
-        return $this->log_file_name;
2676
-    }
2677
-
2678
-
2679
-    /**
2680
-     * @param bool $reset
2681
-     * @return string
2682
-     */
2683
-    public function debug_file_name($reset = false)
2684
-    {
2685
-        if (empty($this->debug_file_name) || $reset) {
2686
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2687
-            EE_Config::instance()->update_espresso_config(false, false);
2688
-        }
2689
-        return $this->debug_file_name;
2690
-    }
2691
-
2692
-
2693
-    /**
2694
-     * @return string
2695
-     */
2696
-    public function affiliate_id()
2697
-    {
2698
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * @return boolean
2704
-     */
2705
-    public function encode_session_data()
2706
-    {
2707
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2708
-    }
2709
-
2710
-
2711
-    /**
2712
-     * @param boolean $encode_session_data
2713
-     */
2714
-    public function set_encode_session_data($encode_session_data)
2715
-    {
2716
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2717
-    }
2718
-
2719
-    /**
2720
-     * @return boolean
2721
-     */
2722
-    public function useAdvancedEditor()
2723
-    {
2724
-        if ($this->is_caffeinated === null) {
2725
-            $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain');
2726
-            $this->is_caffeinated = $domain->isCaffeinated();
2727
-        }
2728
-        return $this->useAdvancedEditor && $this->is_caffeinated;
2729
-    }
2730
-
2731
-    /**
2732
-     * @param boolean $use_advanced_editor
2733
-     */
2734
-    public function setUseAdvancedEditor($use_advanced_editor = true)
2735
-    {
2736
-        $this->useAdvancedEditor = filter_var(
2737
-            apply_filters(
2738
-                'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2739
-                $use_advanced_editor
2740
-            ),
2741
-            FILTER_VALIDATE_BOOLEAN
2742
-        );
2743
-    }
2570
+	/**
2571
+	 * @var boolean $useAdvancedEditor
2572
+	 */
2573
+	private $useAdvancedEditor;
2574
+
2575
+	/**
2576
+	 * @var boolean $use_personnel_manager
2577
+	 */
2578
+	public $use_personnel_manager;
2579
+
2580
+	/**
2581
+	 * @var boolean $use_dashboard_widget
2582
+	 */
2583
+	public $use_dashboard_widget;
2584
+
2585
+	/**
2586
+	 * @var int $events_in_dashboard
2587
+	 */
2588
+	public $events_in_dashboard;
2589
+
2590
+	/**
2591
+	 * @var boolean $use_event_timezones
2592
+	 */
2593
+	public $use_event_timezones;
2594
+
2595
+	/**
2596
+	 * @var string $log_file_name
2597
+	 */
2598
+	public $log_file_name;
2599
+
2600
+	/**
2601
+	 * @var string $debug_file_name
2602
+	 */
2603
+	public $debug_file_name;
2604
+
2605
+	/**
2606
+	 * @var boolean $use_remote_logging
2607
+	 */
2608
+	public $use_remote_logging;
2609
+
2610
+	/**
2611
+	 * @var string $remote_logging_url
2612
+	 */
2613
+	public $remote_logging_url;
2614
+
2615
+	/**
2616
+	 * @var boolean $show_reg_footer
2617
+	 */
2618
+	public $show_reg_footer;
2619
+
2620
+	/**
2621
+	 * @var string $affiliate_id
2622
+	 */
2623
+	public $affiliate_id;
2624
+
2625
+	/**
2626
+	 * adds extra layer of encoding to session data to prevent serialization errors
2627
+	 * but is incompatible with some server configuration errors
2628
+	 * if you get "500 internal server errors" during registration, try turning this on
2629
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2630
+	 *
2631
+	 * @var boolean $encode_session_data
2632
+	 */
2633
+	private $encode_session_data = false;
2634
+
2635
+	/**
2636
+	 * @var boolean
2637
+	 */
2638
+	private $is_caffeinated;
2639
+
2640
+
2641
+	/**
2642
+	 *    class constructor
2643
+	 *
2644
+	 * @access    public
2645
+	 */
2646
+	public function __construct()
2647
+	{
2648
+		// set default general admin settings
2649
+		$this->useAdvancedEditor = true;
2650
+		$this->use_personnel_manager = true;
2651
+		$this->use_dashboard_widget = true;
2652
+		$this->events_in_dashboard = 30;
2653
+		$this->use_event_timezones = false;
2654
+		$this->use_remote_logging = false;
2655
+		$this->remote_logging_url = null;
2656
+		$this->show_reg_footer = apply_filters(
2657
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2658
+			false
2659
+		);
2660
+		$this->affiliate_id = 'default';
2661
+		$this->encode_session_data = false;
2662
+	}
2663
+
2664
+
2665
+	/**
2666
+	 * @param bool $reset
2667
+	 * @return string
2668
+	 */
2669
+	public function log_file_name($reset = false)
2670
+	{
2671
+		if (empty($this->log_file_name) || $reset) {
2672
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2673
+			EE_Config::instance()->update_espresso_config(false, false);
2674
+		}
2675
+		return $this->log_file_name;
2676
+	}
2677
+
2678
+
2679
+	/**
2680
+	 * @param bool $reset
2681
+	 * @return string
2682
+	 */
2683
+	public function debug_file_name($reset = false)
2684
+	{
2685
+		if (empty($this->debug_file_name) || $reset) {
2686
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2687
+			EE_Config::instance()->update_espresso_config(false, false);
2688
+		}
2689
+		return $this->debug_file_name;
2690
+	}
2691
+
2692
+
2693
+	/**
2694
+	 * @return string
2695
+	 */
2696
+	public function affiliate_id()
2697
+	{
2698
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * @return boolean
2704
+	 */
2705
+	public function encode_session_data()
2706
+	{
2707
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2708
+	}
2709
+
2710
+
2711
+	/**
2712
+	 * @param boolean $encode_session_data
2713
+	 */
2714
+	public function set_encode_session_data($encode_session_data)
2715
+	{
2716
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2717
+	}
2718
+
2719
+	/**
2720
+	 * @return boolean
2721
+	 */
2722
+	public function useAdvancedEditor()
2723
+	{
2724
+		if ($this->is_caffeinated === null) {
2725
+			$domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain');
2726
+			$this->is_caffeinated = $domain->isCaffeinated();
2727
+		}
2728
+		return $this->useAdvancedEditor && $this->is_caffeinated;
2729
+	}
2730
+
2731
+	/**
2732
+	 * @param boolean $use_advanced_editor
2733
+	 */
2734
+	public function setUseAdvancedEditor($use_advanced_editor = true)
2735
+	{
2736
+		$this->useAdvancedEditor = filter_var(
2737
+			apply_filters(
2738
+				'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor',
2739
+				$use_advanced_editor
2740
+			),
2741
+			FILTER_VALIDATE_BOOLEAN
2742
+		);
2743
+	}
2744 2744
 }
2745 2745
 
2746 2746
 /**
@@ -2749,70 +2749,70 @@  discard block
 block discarded – undo
2749 2749
 class EE_Template_Config extends EE_Config_Base
2750 2750
 {
2751 2751
 
2752
-    /**
2753
-     * @var boolean $enable_default_style
2754
-     */
2755
-    public $enable_default_style;
2756
-
2757
-    /**
2758
-     * @var string $custom_style_sheet
2759
-     */
2760
-    public $custom_style_sheet;
2761
-
2762
-    /**
2763
-     * @var boolean $display_address_in_regform
2764
-     */
2765
-    public $display_address_in_regform;
2766
-
2767
-    /**
2768
-     * @var int $display_description_on_multi_reg_page
2769
-     */
2770
-    public $display_description_on_multi_reg_page;
2771
-
2772
-    /**
2773
-     * @var boolean $use_custom_templates
2774
-     */
2775
-    public $use_custom_templates;
2776
-
2777
-    /**
2778
-     * @var string $current_espresso_theme
2779
-     */
2780
-    public $current_espresso_theme;
2781
-
2782
-    /**
2783
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2784
-     */
2785
-    public $EED_Ticket_Selector;
2786
-
2787
-    /**
2788
-     * @var EE_Event_Single_Config $EED_Event_Single
2789
-     */
2790
-    public $EED_Event_Single;
2791
-
2792
-    /**
2793
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2794
-     */
2795
-    public $EED_Events_Archive;
2796
-
2797
-
2798
-    /**
2799
-     *    class constructor
2800
-     *
2801
-     * @access    public
2802
-     */
2803
-    public function __construct()
2804
-    {
2805
-        // set default template settings
2806
-        $this->enable_default_style = true;
2807
-        $this->custom_style_sheet = null;
2808
-        $this->display_address_in_regform = true;
2809
-        $this->display_description_on_multi_reg_page = false;
2810
-        $this->use_custom_templates = false;
2811
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2812
-        $this->EED_Event_Single = null;
2813
-        $this->EED_Events_Archive = null;
2814
-        $this->EED_Ticket_Selector = null;
2815
-    }
2752
+	/**
2753
+	 * @var boolean $enable_default_style
2754
+	 */
2755
+	public $enable_default_style;
2756
+
2757
+	/**
2758
+	 * @var string $custom_style_sheet
2759
+	 */
2760
+	public $custom_style_sheet;
2761
+
2762
+	/**
2763
+	 * @var boolean $display_address_in_regform
2764
+	 */
2765
+	public $display_address_in_regform;
2766
+
2767
+	/**
2768
+	 * @var int $display_description_on_multi_reg_page
2769
+	 */
2770
+	public $display_description_on_multi_reg_page;
2771
+
2772
+	/**
2773
+	 * @var boolean $use_custom_templates
2774
+	 */
2775
+	public $use_custom_templates;
2776
+
2777
+	/**
2778
+	 * @var string $current_espresso_theme
2779
+	 */
2780
+	public $current_espresso_theme;
2781
+
2782
+	/**
2783
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2784
+	 */
2785
+	public $EED_Ticket_Selector;
2786
+
2787
+	/**
2788
+	 * @var EE_Event_Single_Config $EED_Event_Single
2789
+	 */
2790
+	public $EED_Event_Single;
2791
+
2792
+	/**
2793
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2794
+	 */
2795
+	public $EED_Events_Archive;
2796
+
2797
+
2798
+	/**
2799
+	 *    class constructor
2800
+	 *
2801
+	 * @access    public
2802
+	 */
2803
+	public function __construct()
2804
+	{
2805
+		// set default template settings
2806
+		$this->enable_default_style = true;
2807
+		$this->custom_style_sheet = null;
2808
+		$this->display_address_in_regform = true;
2809
+		$this->display_description_on_multi_reg_page = false;
2810
+		$this->use_custom_templates = false;
2811
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2812
+		$this->EED_Event_Single = null;
2813
+		$this->EED_Events_Archive = null;
2814
+		$this->EED_Ticket_Selector = null;
2815
+	}
2816 2816
 }
2817 2817
 
2818 2818
 /**
@@ -2821,114 +2821,114 @@  discard block
 block discarded – undo
2821 2821
 class EE_Map_Config extends EE_Config_Base
2822 2822
 {
2823 2823
 
2824
-    /**
2825
-     * @var boolean $use_google_maps
2826
-     */
2827
-    public $use_google_maps;
2828
-
2829
-    /**
2830
-     * @var string $api_key
2831
-     */
2832
-    public $google_map_api_key;
2833
-
2834
-    /**
2835
-     * @var int $event_details_map_width
2836
-     */
2837
-    public $event_details_map_width;
2838
-
2839
-    /**
2840
-     * @var int $event_details_map_height
2841
-     */
2842
-    public $event_details_map_height;
2843
-
2844
-    /**
2845
-     * @var int $event_details_map_zoom
2846
-     */
2847
-    public $event_details_map_zoom;
2848
-
2849
-    /**
2850
-     * @var boolean $event_details_display_nav
2851
-     */
2852
-    public $event_details_display_nav;
2853
-
2854
-    /**
2855
-     * @var boolean $event_details_nav_size
2856
-     */
2857
-    public $event_details_nav_size;
2858
-
2859
-    /**
2860
-     * @var string $event_details_control_type
2861
-     */
2862
-    public $event_details_control_type;
2863
-
2864
-    /**
2865
-     * @var string $event_details_map_align
2866
-     */
2867
-    public $event_details_map_align;
2868
-
2869
-    /**
2870
-     * @var int $event_list_map_width
2871
-     */
2872
-    public $event_list_map_width;
2873
-
2874
-    /**
2875
-     * @var int $event_list_map_height
2876
-     */
2877
-    public $event_list_map_height;
2878
-
2879
-    /**
2880
-     * @var int $event_list_map_zoom
2881
-     */
2882
-    public $event_list_map_zoom;
2883
-
2884
-    /**
2885
-     * @var boolean $event_list_display_nav
2886
-     */
2887
-    public $event_list_display_nav;
2888
-
2889
-    /**
2890
-     * @var boolean $event_list_nav_size
2891
-     */
2892
-    public $event_list_nav_size;
2893
-
2894
-    /**
2895
-     * @var string $event_list_control_type
2896
-     */
2897
-    public $event_list_control_type;
2898
-
2899
-    /**
2900
-     * @var string $event_list_map_align
2901
-     */
2902
-    public $event_list_map_align;
2903
-
2904
-
2905
-    /**
2906
-     *    class constructor
2907
-     *
2908
-     * @access    public
2909
-     */
2910
-    public function __construct()
2911
-    {
2912
-        // set default map settings
2913
-        $this->use_google_maps = true;
2914
-        $this->google_map_api_key = '';
2915
-        // for event details pages (reg page)
2916
-        $this->event_details_map_width = 585;            // ee_map_width_single
2917
-        $this->event_details_map_height = 362;            // ee_map_height_single
2918
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2919
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2920
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2921
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2922
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2923
-        // for event list pages
2924
-        $this->event_list_map_width = 300;            // ee_map_width
2925
-        $this->event_list_map_height = 185;        // ee_map_height
2926
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2927
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2928
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2929
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2930
-        $this->event_list_map_align = 'center';            // ee_map_align
2931
-    }
2824
+	/**
2825
+	 * @var boolean $use_google_maps
2826
+	 */
2827
+	public $use_google_maps;
2828
+
2829
+	/**
2830
+	 * @var string $api_key
2831
+	 */
2832
+	public $google_map_api_key;
2833
+
2834
+	/**
2835
+	 * @var int $event_details_map_width
2836
+	 */
2837
+	public $event_details_map_width;
2838
+
2839
+	/**
2840
+	 * @var int $event_details_map_height
2841
+	 */
2842
+	public $event_details_map_height;
2843
+
2844
+	/**
2845
+	 * @var int $event_details_map_zoom
2846
+	 */
2847
+	public $event_details_map_zoom;
2848
+
2849
+	/**
2850
+	 * @var boolean $event_details_display_nav
2851
+	 */
2852
+	public $event_details_display_nav;
2853
+
2854
+	/**
2855
+	 * @var boolean $event_details_nav_size
2856
+	 */
2857
+	public $event_details_nav_size;
2858
+
2859
+	/**
2860
+	 * @var string $event_details_control_type
2861
+	 */
2862
+	public $event_details_control_type;
2863
+
2864
+	/**
2865
+	 * @var string $event_details_map_align
2866
+	 */
2867
+	public $event_details_map_align;
2868
+
2869
+	/**
2870
+	 * @var int $event_list_map_width
2871
+	 */
2872
+	public $event_list_map_width;
2873
+
2874
+	/**
2875
+	 * @var int $event_list_map_height
2876
+	 */
2877
+	public $event_list_map_height;
2878
+
2879
+	/**
2880
+	 * @var int $event_list_map_zoom
2881
+	 */
2882
+	public $event_list_map_zoom;
2883
+
2884
+	/**
2885
+	 * @var boolean $event_list_display_nav
2886
+	 */
2887
+	public $event_list_display_nav;
2888
+
2889
+	/**
2890
+	 * @var boolean $event_list_nav_size
2891
+	 */
2892
+	public $event_list_nav_size;
2893
+
2894
+	/**
2895
+	 * @var string $event_list_control_type
2896
+	 */
2897
+	public $event_list_control_type;
2898
+
2899
+	/**
2900
+	 * @var string $event_list_map_align
2901
+	 */
2902
+	public $event_list_map_align;
2903
+
2904
+
2905
+	/**
2906
+	 *    class constructor
2907
+	 *
2908
+	 * @access    public
2909
+	 */
2910
+	public function __construct()
2911
+	{
2912
+		// set default map settings
2913
+		$this->use_google_maps = true;
2914
+		$this->google_map_api_key = '';
2915
+		// for event details pages (reg page)
2916
+		$this->event_details_map_width = 585;            // ee_map_width_single
2917
+		$this->event_details_map_height = 362;            // ee_map_height_single
2918
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2919
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2920
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2921
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2922
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2923
+		// for event list pages
2924
+		$this->event_list_map_width = 300;            // ee_map_width
2925
+		$this->event_list_map_height = 185;        // ee_map_height
2926
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2927
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2928
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2929
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2930
+		$this->event_list_map_align = 'center';            // ee_map_align
2931
+	}
2932 2932
 }
2933 2933
 
2934 2934
 /**
@@ -2937,46 +2937,46 @@  discard block
 block discarded – undo
2937 2937
 class EE_Events_Archive_Config extends EE_Config_Base
2938 2938
 {
2939 2939
 
2940
-    public $display_status_banner;
2940
+	public $display_status_banner;
2941 2941
 
2942
-    public $display_description;
2942
+	public $display_description;
2943 2943
 
2944
-    public $display_ticket_selector;
2944
+	public $display_ticket_selector;
2945 2945
 
2946
-    public $display_datetimes;
2946
+	public $display_datetimes;
2947 2947
 
2948
-    public $display_venue;
2948
+	public $display_venue;
2949 2949
 
2950
-    public $display_expired_events;
2950
+	public $display_expired_events;
2951 2951
 
2952
-    public $use_sortable_display_order;
2952
+	public $use_sortable_display_order;
2953 2953
 
2954
-    public $display_order_tickets;
2954
+	public $display_order_tickets;
2955 2955
 
2956
-    public $display_order_datetimes;
2956
+	public $display_order_datetimes;
2957 2957
 
2958
-    public $display_order_event;
2958
+	public $display_order_event;
2959 2959
 
2960
-    public $display_order_venue;
2960
+	public $display_order_venue;
2961 2961
 
2962 2962
 
2963
-    /**
2964
-     *    class constructor
2965
-     */
2966
-    public function __construct()
2967
-    {
2968
-        $this->display_status_banner = 0;
2969
-        $this->display_description = 1;
2970
-        $this->display_ticket_selector = 0;
2971
-        $this->display_datetimes = 1;
2972
-        $this->display_venue = 0;
2973
-        $this->display_expired_events = 0;
2974
-        $this->use_sortable_display_order = false;
2975
-        $this->display_order_tickets = 100;
2976
-        $this->display_order_datetimes = 110;
2977
-        $this->display_order_event = 120;
2978
-        $this->display_order_venue = 130;
2979
-    }
2963
+	/**
2964
+	 *    class constructor
2965
+	 */
2966
+	public function __construct()
2967
+	{
2968
+		$this->display_status_banner = 0;
2969
+		$this->display_description = 1;
2970
+		$this->display_ticket_selector = 0;
2971
+		$this->display_datetimes = 1;
2972
+		$this->display_venue = 0;
2973
+		$this->display_expired_events = 0;
2974
+		$this->use_sortable_display_order = false;
2975
+		$this->display_order_tickets = 100;
2976
+		$this->display_order_datetimes = 110;
2977
+		$this->display_order_event = 120;
2978
+		$this->display_order_venue = 130;
2979
+	}
2980 2980
 }
2981 2981
 
2982 2982
 /**
@@ -2985,34 +2985,34 @@  discard block
 block discarded – undo
2985 2985
 class EE_Event_Single_Config extends EE_Config_Base
2986 2986
 {
2987 2987
 
2988
-    public $display_status_banner_single;
2988
+	public $display_status_banner_single;
2989 2989
 
2990
-    public $display_venue;
2990
+	public $display_venue;
2991 2991
 
2992
-    public $use_sortable_display_order;
2992
+	public $use_sortable_display_order;
2993 2993
 
2994
-    public $display_order_tickets;
2994
+	public $display_order_tickets;
2995 2995
 
2996
-    public $display_order_datetimes;
2996
+	public $display_order_datetimes;
2997 2997
 
2998
-    public $display_order_event;
2998
+	public $display_order_event;
2999 2999
 
3000
-    public $display_order_venue;
3000
+	public $display_order_venue;
3001 3001
 
3002 3002
 
3003
-    /**
3004
-     *    class constructor
3005
-     */
3006
-    public function __construct()
3007
-    {
3008
-        $this->display_status_banner_single = 0;
3009
-        $this->display_venue = 1;
3010
-        $this->use_sortable_display_order = false;
3011
-        $this->display_order_tickets = 100;
3012
-        $this->display_order_datetimes = 110;
3013
-        $this->display_order_event = 120;
3014
-        $this->display_order_venue = 130;
3015
-    }
3003
+	/**
3004
+	 *    class constructor
3005
+	 */
3006
+	public function __construct()
3007
+	{
3008
+		$this->display_status_banner_single = 0;
3009
+		$this->display_venue = 1;
3010
+		$this->use_sortable_display_order = false;
3011
+		$this->display_order_tickets = 100;
3012
+		$this->display_order_datetimes = 110;
3013
+		$this->display_order_event = 120;
3014
+		$this->display_order_venue = 130;
3015
+	}
3016 3016
 }
3017 3017
 
3018 3018
 /**
@@ -3021,172 +3021,172 @@  discard block
 block discarded – undo
3021 3021
 class EE_Ticket_Selector_Config extends EE_Config_Base
3022 3022
 {
3023 3023
 
3024
-    /**
3025
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3026
-     */
3027
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3028
-
3029
-    /**
3030
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
3031
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3032
-     */
3033
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3034
-
3035
-    /**
3036
-     * @var boolean $show_ticket_sale_columns
3037
-     */
3038
-    public $show_ticket_sale_columns;
3039
-
3040
-    /**
3041
-     * @var boolean $show_ticket_details
3042
-     */
3043
-    public $show_ticket_details;
3044
-
3045
-    /**
3046
-     * @var boolean $show_expired_tickets
3047
-     */
3048
-    public $show_expired_tickets;
3049
-
3050
-    /**
3051
-     * whether or not to display a dropdown box populated with event datetimes
3052
-     * that toggles which tickets are displayed for a ticket selector.
3053
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3054
-     *
3055
-     * @var string $show_datetime_selector
3056
-     */
3057
-    private $show_datetime_selector = 'no_datetime_selector';
3058
-
3059
-    /**
3060
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3061
-     *
3062
-     * @var int $datetime_selector_threshold
3063
-     */
3064
-    private $datetime_selector_threshold = 3;
3065
-
3066
-    /**
3067
-     * determines the maximum number of "checked" dates in the date and time filter
3068
-     *
3069
-     * @var int $datetime_selector_checked
3070
-     */
3071
-    private $datetime_selector_max_checked = 10;
3072
-
3073
-
3074
-    /**
3075
-     *    class constructor
3076
-     */
3077
-    public function __construct()
3078
-    {
3079
-        $this->show_ticket_sale_columns = true;
3080
-        $this->show_ticket_details = true;
3081
-        $this->show_expired_tickets = true;
3082
-        $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3083
-        $this->datetime_selector_threshold = 3;
3084
-        $this->datetime_selector_max_checked = 10;
3085
-    }
3086
-
3087
-
3088
-    /**
3089
-     * returns true if a datetime selector should be displayed
3090
-     *
3091
-     * @param array $datetimes
3092
-     * @return bool
3093
-     */
3094
-    public function showDatetimeSelector(array $datetimes)
3095
-    {
3096
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3097
-        return ! (
3098
-            $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3099
-            || (
3100
-                $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3101
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3102
-            )
3103
-        );
3104
-    }
3105
-
3106
-
3107
-    /**
3108
-     * @return string
3109
-     */
3110
-    public function getShowDatetimeSelector()
3111
-    {
3112
-        return $this->show_datetime_selector;
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     * @param bool $keys_only
3118
-     * @return array
3119
-     */
3120
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3121
-    {
3122
-        return $keys_only
3123
-            ? array(
3124
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3125
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3126
-            )
3127
-            : array(
3128
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3129
-                    'Do not show date & time filter',
3130
-                    'event_espresso'
3131
-                ),
3132
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3133
-                    'Maybe show date & time filter',
3134
-                    'event_espresso'
3135
-                ),
3136
-            );
3137
-    }
3138
-
3139
-
3140
-    /**
3141
-     * @param string $show_datetime_selector
3142
-     */
3143
-    public function setShowDatetimeSelector($show_datetime_selector)
3144
-    {
3145
-        $this->show_datetime_selector = in_array(
3146
-            $show_datetime_selector,
3147
-            $this->getShowDatetimeSelectorOptions(),
3148
-            true
3149
-        )
3150
-            ? $show_datetime_selector
3151
-            : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3152
-    }
3153
-
3154
-
3155
-    /**
3156
-     * @return int
3157
-     */
3158
-    public function getDatetimeSelectorThreshold()
3159
-    {
3160
-        return $this->datetime_selector_threshold;
3161
-    }
3162
-
3163
-
3164
-    /**
3165
-     * @param int $datetime_selector_threshold
3166
-     */
3167
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3168
-    {
3169
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3170
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3171
-    }
3172
-
3173
-
3174
-    /**
3175
-     * @return int
3176
-     */
3177
-    public function getDatetimeSelectorMaxChecked()
3178
-    {
3179
-        return $this->datetime_selector_max_checked;
3180
-    }
3181
-
3182
-
3183
-    /**
3184
-     * @param int $datetime_selector_max_checked
3185
-     */
3186
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3187
-    {
3188
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3189
-    }
3024
+	/**
3025
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
3026
+	 */
3027
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
3028
+
3029
+	/**
3030
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
3031
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
3032
+	 */
3033
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
3034
+
3035
+	/**
3036
+	 * @var boolean $show_ticket_sale_columns
3037
+	 */
3038
+	public $show_ticket_sale_columns;
3039
+
3040
+	/**
3041
+	 * @var boolean $show_ticket_details
3042
+	 */
3043
+	public $show_ticket_details;
3044
+
3045
+	/**
3046
+	 * @var boolean $show_expired_tickets
3047
+	 */
3048
+	public $show_expired_tickets;
3049
+
3050
+	/**
3051
+	 * whether or not to display a dropdown box populated with event datetimes
3052
+	 * that toggles which tickets are displayed for a ticket selector.
3053
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3054
+	 *
3055
+	 * @var string $show_datetime_selector
3056
+	 */
3057
+	private $show_datetime_selector = 'no_datetime_selector';
3058
+
3059
+	/**
3060
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3061
+	 *
3062
+	 * @var int $datetime_selector_threshold
3063
+	 */
3064
+	private $datetime_selector_threshold = 3;
3065
+
3066
+	/**
3067
+	 * determines the maximum number of "checked" dates in the date and time filter
3068
+	 *
3069
+	 * @var int $datetime_selector_checked
3070
+	 */
3071
+	private $datetime_selector_max_checked = 10;
3072
+
3073
+
3074
+	/**
3075
+	 *    class constructor
3076
+	 */
3077
+	public function __construct()
3078
+	{
3079
+		$this->show_ticket_sale_columns = true;
3080
+		$this->show_ticket_details = true;
3081
+		$this->show_expired_tickets = true;
3082
+		$this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3083
+		$this->datetime_selector_threshold = 3;
3084
+		$this->datetime_selector_max_checked = 10;
3085
+	}
3086
+
3087
+
3088
+	/**
3089
+	 * returns true if a datetime selector should be displayed
3090
+	 *
3091
+	 * @param array $datetimes
3092
+	 * @return bool
3093
+	 */
3094
+	public function showDatetimeSelector(array $datetimes)
3095
+	{
3096
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3097
+		return ! (
3098
+			$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3099
+			|| (
3100
+				$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3101
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3102
+			)
3103
+		);
3104
+	}
3105
+
3106
+
3107
+	/**
3108
+	 * @return string
3109
+	 */
3110
+	public function getShowDatetimeSelector()
3111
+	{
3112
+		return $this->show_datetime_selector;
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 * @param bool $keys_only
3118
+	 * @return array
3119
+	 */
3120
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3121
+	{
3122
+		return $keys_only
3123
+			? array(
3124
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3125
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3126
+			)
3127
+			: array(
3128
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3129
+					'Do not show date & time filter',
3130
+					'event_espresso'
3131
+				),
3132
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3133
+					'Maybe show date & time filter',
3134
+					'event_espresso'
3135
+				),
3136
+			);
3137
+	}
3138
+
3139
+
3140
+	/**
3141
+	 * @param string $show_datetime_selector
3142
+	 */
3143
+	public function setShowDatetimeSelector($show_datetime_selector)
3144
+	{
3145
+		$this->show_datetime_selector = in_array(
3146
+			$show_datetime_selector,
3147
+			$this->getShowDatetimeSelectorOptions(),
3148
+			true
3149
+		)
3150
+			? $show_datetime_selector
3151
+			: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3152
+	}
3153
+
3154
+
3155
+	/**
3156
+	 * @return int
3157
+	 */
3158
+	public function getDatetimeSelectorThreshold()
3159
+	{
3160
+		return $this->datetime_selector_threshold;
3161
+	}
3162
+
3163
+
3164
+	/**
3165
+	 * @param int $datetime_selector_threshold
3166
+	 */
3167
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3168
+	{
3169
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3170
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3171
+	}
3172
+
3173
+
3174
+	/**
3175
+	 * @return int
3176
+	 */
3177
+	public function getDatetimeSelectorMaxChecked()
3178
+	{
3179
+		return $this->datetime_selector_max_checked;
3180
+	}
3181
+
3182
+
3183
+	/**
3184
+	 * @param int $datetime_selector_max_checked
3185
+	 */
3186
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3187
+	{
3188
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3189
+	}
3190 3190
 }
3191 3191
 
3192 3192
 /**
@@ -3199,87 +3199,87 @@  discard block
 block discarded – undo
3199 3199
 class EE_Environment_Config extends EE_Config_Base
3200 3200
 {
3201 3201
 
3202
-    /**
3203
-     * Hold any php environment variables that we want to track.
3204
-     *
3205
-     * @var stdClass;
3206
-     */
3207
-    public $php;
3208
-
3209
-
3210
-    /**
3211
-     *    constructor
3212
-     */
3213
-    public function __construct()
3214
-    {
3215
-        $this->php = new stdClass();
3216
-        $this->_set_php_values();
3217
-    }
3218
-
3219
-
3220
-    /**
3221
-     * This sets the php environment variables.
3222
-     *
3223
-     * @since 4.4.0
3224
-     * @return void
3225
-     */
3226
-    protected function _set_php_values()
3227
-    {
3228
-        $this->php->max_input_vars = ini_get('max_input_vars');
3229
-        $this->php->version = phpversion();
3230
-    }
3231
-
3232
-
3233
-    /**
3234
-     * helper method for determining whether input_count is
3235
-     * reaching the potential maximum the server can handle
3236
-     * according to max_input_vars
3237
-     *
3238
-     * @param int   $input_count the count of input vars.
3239
-     * @return array {
3240
-     *                           An array that represents whether available space and if no available space the error
3241
-     *                           message.
3242
-     * @type bool   $has_space   whether more inputs can be added.
3243
-     * @type string $msg         Any message to be displayed.
3244
-     *                           }
3245
-     */
3246
-    public function max_input_vars_limit_check($input_count = 0)
3247
-    {
3248
-        if (
3249
-            ! empty($this->php->max_input_vars)
3250
-            && ($input_count >= $this->php->max_input_vars)
3251
-        ) {
3252
-            // check the server setting because the config value could be stale
3253
-            $max_input_vars = ini_get('max_input_vars');
3254
-            if ($input_count >= $max_input_vars) {
3255
-                return sprintf(
3256
-                    esc_html__(
3257
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3258
-                        'event_espresso'
3259
-                    ),
3260
-                    '<br>',
3261
-                    $input_count,
3262
-                    $max_input_vars
3263
-                );
3264
-            } else {
3265
-                return '';
3266
-            }
3267
-        } else {
3268
-            return '';
3269
-        }
3270
-    }
3271
-
3272
-
3273
-    /**
3274
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3275
-     *
3276
-     * @since 4.4.1
3277
-     * @return void
3278
-     */
3279
-    public function recheck_values()
3280
-    {
3281
-        $this->_set_php_values();
3282
-    }
3202
+	/**
3203
+	 * Hold any php environment variables that we want to track.
3204
+	 *
3205
+	 * @var stdClass;
3206
+	 */
3207
+	public $php;
3208
+
3209
+
3210
+	/**
3211
+	 *    constructor
3212
+	 */
3213
+	public function __construct()
3214
+	{
3215
+		$this->php = new stdClass();
3216
+		$this->_set_php_values();
3217
+	}
3218
+
3219
+
3220
+	/**
3221
+	 * This sets the php environment variables.
3222
+	 *
3223
+	 * @since 4.4.0
3224
+	 * @return void
3225
+	 */
3226
+	protected function _set_php_values()
3227
+	{
3228
+		$this->php->max_input_vars = ini_get('max_input_vars');
3229
+		$this->php->version = phpversion();
3230
+	}
3231
+
3232
+
3233
+	/**
3234
+	 * helper method for determining whether input_count is
3235
+	 * reaching the potential maximum the server can handle
3236
+	 * according to max_input_vars
3237
+	 *
3238
+	 * @param int   $input_count the count of input vars.
3239
+	 * @return array {
3240
+	 *                           An array that represents whether available space and if no available space the error
3241
+	 *                           message.
3242
+	 * @type bool   $has_space   whether more inputs can be added.
3243
+	 * @type string $msg         Any message to be displayed.
3244
+	 *                           }
3245
+	 */
3246
+	public function max_input_vars_limit_check($input_count = 0)
3247
+	{
3248
+		if (
3249
+			! empty($this->php->max_input_vars)
3250
+			&& ($input_count >= $this->php->max_input_vars)
3251
+		) {
3252
+			// check the server setting because the config value could be stale
3253
+			$max_input_vars = ini_get('max_input_vars');
3254
+			if ($input_count >= $max_input_vars) {
3255
+				return sprintf(
3256
+					esc_html__(
3257
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3258
+						'event_espresso'
3259
+					),
3260
+					'<br>',
3261
+					$input_count,
3262
+					$max_input_vars
3263
+				);
3264
+			} else {
3265
+				return '';
3266
+			}
3267
+		} else {
3268
+			return '';
3269
+		}
3270
+	}
3271
+
3272
+
3273
+	/**
3274
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3275
+	 *
3276
+	 * @since 4.4.1
3277
+	 * @return void
3278
+	 */
3279
+	public function recheck_values()
3280
+	{
3281
+		$this->_set_php_values();
3282
+	}
3283 3283
 }
3284 3284
 
3285 3285
 /**
@@ -3292,21 +3292,21 @@  discard block
 block discarded – undo
3292 3292
 class EE_Tax_Config extends EE_Config_Base
3293 3293
 {
3294 3294
 
3295
-    /*
3295
+	/*
3296 3296
      * flag to indicate whether or not to display ticket prices with the taxes included
3297 3297
      *
3298 3298
      * @var boolean $prices_displayed_including_taxes
3299 3299
      */
3300
-    public $prices_displayed_including_taxes;
3300
+	public $prices_displayed_including_taxes;
3301 3301
 
3302 3302
 
3303
-    /**
3304
-     *    class constructor
3305
-     */
3306
-    public function __construct()
3307
-    {
3308
-        $this->prices_displayed_including_taxes = true;
3309
-    }
3303
+	/**
3304
+	 *    class constructor
3305
+	 */
3306
+	public function __construct()
3307
+	{
3308
+		$this->prices_displayed_including_taxes = true;
3309
+	}
3310 3310
 }
3311 3311
 
3312 3312
 /**
@@ -3320,19 +3320,19 @@  discard block
 block discarded – undo
3320 3320
 class EE_Messages_Config extends EE_Config_Base
3321 3321
 {
3322 3322
 
3323
-    /**
3324
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3325
-     * A value of 0 represents never deleting.  Default is 0.
3326
-     *
3327
-     * @var integer
3328
-     */
3329
-    public $delete_threshold;
3323
+	/**
3324
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3325
+	 * A value of 0 represents never deleting.  Default is 0.
3326
+	 *
3327
+	 * @var integer
3328
+	 */
3329
+	public $delete_threshold;
3330 3330
 
3331 3331
 
3332
-    public function __construct()
3333
-    {
3334
-        $this->delete_threshold = 0;
3335
-    }
3332
+	public function __construct()
3333
+	{
3334
+		$this->delete_threshold = 0;
3335
+	}
3336 3336
 }
3337 3337
 
3338 3338
 /**
@@ -3343,31 +3343,31 @@  discard block
 block discarded – undo
3343 3343
 class EE_Gateway_Config extends EE_Config_Base
3344 3344
 {
3345 3345
 
3346
-    /**
3347
-     * Array with keys that are payment gateways slugs, and values are arrays
3348
-     * with any config info the gateway wants to store
3349
-     *
3350
-     * @var array
3351
-     */
3352
-    public $payment_settings;
3353
-
3354
-    /**
3355
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3356
-     * the gateway is stored in the uploads directory
3357
-     *
3358
-     * @var array
3359
-     */
3360
-    public $active_gateways;
3361
-
3362
-
3363
-    /**
3364
-     *    class constructor
3365
-     *
3366
-     * @deprecated
3367
-     */
3368
-    public function __construct()
3369
-    {
3370
-        $this->payment_settings = array();
3371
-        $this->active_gateways = array('Invoice' => false);
3372
-    }
3346
+	/**
3347
+	 * Array with keys that are payment gateways slugs, and values are arrays
3348
+	 * with any config info the gateway wants to store
3349
+	 *
3350
+	 * @var array
3351
+	 */
3352
+	public $payment_settings;
3353
+
3354
+	/**
3355
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3356
+	 * the gateway is stored in the uploads directory
3357
+	 *
3358
+	 * @var array
3359
+	 */
3360
+	public $active_gateways;
3361
+
3362
+
3363
+	/**
3364
+	 *    class constructor
3365
+	 *
3366
+	 * @deprecated
3367
+	 */
3368
+	public function __construct()
3369
+	{
3370
+		$this->payment_settings = array();
3371
+		$this->active_gateways = array('Invoice' => false);
3372
+	}
3373 3373
 }
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks.class.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -15,102 +15,102 @@  discard block
 block discarded – undo
15 15
 class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Event|null
20
-     */
21
-    protected $_event;
22
-
23
-
24
-    protected function _set_hooks_properties()
25
-    {
26
-        $this->_name = 'registration_form';
27
-        if (
28
-            $this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
-            && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
-        ) {
31
-            $this->_metaboxes      = [];
32
-            $this->_scripts_styles = [];
33
-            return;
34
-        }
35
-        $this->_metaboxes = [
36
-            0 => [
37
-                'page_route' => ['edit', 'create_new'],
38
-                'func'       => 'primary_questions',
39
-                'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
40
-                'priority'   => 'default',
41
-                'context'    => 'side',
42
-            ],
43
-        ];
44
-
45
-        // hook into the handler for saving question groups
46
-        add_filter(
47
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
48
-            [$this, 'modify_callbacks'],
49
-            10
50
-        );
51
-
52
-        // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
53
-        // restricted by page)
54
-        add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
55
-    }
56
-
57
-
58
-    /**
59
-     * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
60
-     *
61
-     * @param $callbacks
62
-     * @return array
63
-     */
64
-    public function modify_callbacks($callbacks)
65
-    {
66
-        // now let's add the question group callback
67
-        $callbacks['primary_question_group_update'] = [$this, 'primary_question_group_update'];
68
-        return $callbacks;
69
-    }
70
-
71
-
72
-    /**
73
-     * Hooked into revision restores.
74
-     *
75
-     * @param $post_id
76
-     * @param $revision_id
77
-     * @return EE_Base_Class
78
-     * @throws EE_Error
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    public function restore_revision($post_id, $revision_id)
84
-    {
85
-        $post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
86
-        // restore revision for primary questions
87
-        if ($post_evt instanceof EE_Event) {
88
-            $post_evt->restore_revision(
89
-                $revision_id,
90
-                ['Question_Group'],
91
-                ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
92
-            );
93
-        }
94
-        return $post_evt;
95
-    }
96
-
97
-
98
-    /**
99
-     * Content of metabox.
100
-     *
101
-     * @param $post_id
102
-     * @param $post
103
-     * @throws EE_Error
104
-     * @throws InvalidArgumentException
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @throws ReflectionException
108
-     */
109
-    public function primary_questions($post_id, $post)
110
-    {
111
-        $this->_event = $this->_adminpage_obj->get_event_object();
112
-        $event_id     = $this->_event->ID();
113
-        ?>
18
+	/**
19
+	 * @var EE_Event|null
20
+	 */
21
+	protected $_event;
22
+
23
+
24
+	protected function _set_hooks_properties()
25
+	{
26
+		$this->_name = 'registration_form';
27
+		if (
28
+			$this->_adminpage_obj->adminConfig()->useAdvancedEditor()
29
+			&& $this->_adminpage_obj->feature()->allowed('use_reg_form_builder')
30
+		) {
31
+			$this->_metaboxes      = [];
32
+			$this->_scripts_styles = [];
33
+			return;
34
+		}
35
+		$this->_metaboxes = [
36
+			0 => [
37
+				'page_route' => ['edit', 'create_new'],
38
+				'func'       => 'primary_questions',
39
+				'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
40
+				'priority'   => 'default',
41
+				'context'    => 'side',
42
+			],
43
+		];
44
+
45
+		// hook into the handler for saving question groups
46
+		add_filter(
47
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
48
+			[$this, 'modify_callbacks'],
49
+			10
50
+		);
51
+
52
+		// hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
53
+		// restricted by page)
54
+		add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
55
+	}
56
+
57
+
58
+	/**
59
+	 * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
60
+	 *
61
+	 * @param $callbacks
62
+	 * @return array
63
+	 */
64
+	public function modify_callbacks($callbacks)
65
+	{
66
+		// now let's add the question group callback
67
+		$callbacks['primary_question_group_update'] = [$this, 'primary_question_group_update'];
68
+		return $callbacks;
69
+	}
70
+
71
+
72
+	/**
73
+	 * Hooked into revision restores.
74
+	 *
75
+	 * @param $post_id
76
+	 * @param $revision_id
77
+	 * @return EE_Base_Class
78
+	 * @throws EE_Error
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	public function restore_revision($post_id, $revision_id)
84
+	{
85
+		$post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
86
+		// restore revision for primary questions
87
+		if ($post_evt instanceof EE_Event) {
88
+			$post_evt->restore_revision(
89
+				$revision_id,
90
+				['Question_Group'],
91
+				['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
92
+			);
93
+		}
94
+		return $post_evt;
95
+	}
96
+
97
+
98
+	/**
99
+	 * Content of metabox.
100
+	 *
101
+	 * @param $post_id
102
+	 * @param $post
103
+	 * @throws EE_Error
104
+	 * @throws InvalidArgumentException
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @throws ReflectionException
108
+	 */
109
+	public function primary_questions($post_id, $post)
110
+	{
111
+		$this->_event = $this->_adminpage_obj->get_event_object();
112
+		$event_id     = $this->_event->ID();
113
+		?>
114 114
         <div class="inside">
115 115
             <p>
116 116
                 <strong>
@@ -118,64 +118,64 @@  discard block
 block discarded – undo
118 118
                 </strong>
119 119
                 <br />
120 120
                 <?php
121
-                printf(
122
-                    esc_html__(
123
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
124
-                        'event_espresso'
125
-                    ),
126
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
127
-                    '</a>'
128
-                )
129
-                ?>
121
+				printf(
122
+					esc_html__(
123
+						'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
124
+						'event_espresso'
125
+					),
126
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
127
+					'</a>'
128
+				)
129
+				?>
130 130
             </p>
131 131
             <?php
132 132
 
133
-            $qsg_where['QSG_deleted'] = false;
134
-            $query_params             = apply_filters(
135
-                'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
136
-                [$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
137
-            );
138
-            $QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
139
-            $EQGs                     = ! empty($event_id)
140
-                ? $this->_event->get_many_related(
141
-                    'Question_Group',
142
-                    [['Event_Question_Group.EQG_primary' => true]]
143
-                )
144
-                : [];
145
-            $EQGids                   = array_keys($EQGs);
146
-
147
-            if (! empty($QSGs)) {
148
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
149
-                foreach ($QSGs as $QSG) {
150
-                    $QSG_ID          = absint($QSG->ID());
151
-                    $checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
152
-                        ? ' checked="checked"'
153
-                        : '';
154
-                    $visibility      = $QSG->get('QSG_system') === 1
155
-                        ? ' style="visibility:hidden"'
156
-                        : '';
157
-                    $edit_query_args = $this->_adminpage_obj->is_caf()
158
-                        ? [
159
-                            'action' => 'edit_question_group',
160
-                            'QSG_ID' => $QSG_ID,
161
-                        ]
162
-                        : ['action' => 'question_groups'];
163
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
164
-                        $edit_query_args,
165
-                        EE_FORMS_ADMIN_URL
166
-                    );
167
-                    $edit_link_title = sprintf(
168
-                        esc_attr__('Edit %s Group', 'event_espresso'),
169
-                        $QSG->get('QSG_name')
170
-                    );
171
-
172
-                    $html .= '
133
+			$qsg_where['QSG_deleted'] = false;
134
+			$query_params             = apply_filters(
135
+				'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
136
+				[$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
137
+			);
138
+			$QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
139
+			$EQGs                     = ! empty($event_id)
140
+				? $this->_event->get_many_related(
141
+					'Question_Group',
142
+					[['Event_Question_Group.EQG_primary' => true]]
143
+				)
144
+				: [];
145
+			$EQGids                   = array_keys($EQGs);
146
+
147
+			if (! empty($QSGs)) {
148
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
149
+				foreach ($QSGs as $QSG) {
150
+					$QSG_ID          = absint($QSG->ID());
151
+					$checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
152
+						? ' checked="checked"'
153
+						: '';
154
+					$visibility      = $QSG->get('QSG_system') === 1
155
+						? ' style="visibility:hidden"'
156
+						: '';
157
+					$edit_query_args = $this->_adminpage_obj->is_caf()
158
+						? [
159
+							'action' => 'edit_question_group',
160
+							'QSG_ID' => $QSG_ID,
161
+						]
162
+						: ['action' => 'question_groups'];
163
+					$edit_link       = EE_Admin_Page::add_query_args_and_nonce(
164
+						$edit_query_args,
165
+						EE_FORMS_ADMIN_URL
166
+					);
167
+					$edit_link_title = sprintf(
168
+						esc_attr__('Edit %s Group', 'event_espresso'),
169
+						$QSG->get('QSG_name')
170
+					);
171
+
172
+					$html .= '
173 173
 					<p id="event-question-group-' . $QSG_ID . '">
174 174
 						<input value="' . $QSG_ID . '"
175 175
 						    type="checkbox"
176 176
 						    name="question_groups[' . $QSG_ID . ']" '
177
-                            . $visibility
178
-                            . $checked . '
177
+							. $visibility
178
+							. $checked . '
179 179
                         />
180 180
 						<a href="' . esc_url_raw($edit_link) . '"
181 181
 						    title="' . esc_attr($edit_link_title) . '"
@@ -184,63 +184,63 @@  discard block
 block discarded – undo
184 184
 						    ' . $QSG->get('QSG_name') . '
185 185
                         </a>
186 186
 					</p>';
187
-                }
188
-                $html .= count($QSGs) > 10 ? '</div>' : '';
189
-
190
-                echo $html; // already escaped
191
-            } else {
192
-                esc_html_e(
193
-                    'There seems to be a problem with your questions. Please contact [email protected]',
194
-                    'event_espresso'
195
-                );
196
-            }
197
-            do_action('AHEE_event_editor_questions_notice');
198
-            ?>
187
+				}
188
+				$html .= count($QSGs) > 10 ? '</div>' : '';
189
+
190
+				echo $html; // already escaped
191
+			} else {
192
+				esc_html_e(
193
+					'There seems to be a problem with your questions. Please contact [email protected]',
194
+					'event_espresso'
195
+				);
196
+			}
197
+			do_action('AHEE_event_editor_questions_notice');
198
+			?>
199 199
         </div>
200 200
         <?php
201
-    }
202
-
203
-
204
-    /**
205
-     * @param EE_Event $event
206
-     * @param array    $data
207
-     * @return bool
208
-     * @throws EE_Error
209
-     * @throws ReflectionException
210
-     */
211
-    public function primary_question_group_update($event, $data)
212
-    {
213
-        $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
214
-        $added_qgs       = array_keys($question_groups);
215
-        $success         = true;
216
-
217
-        // let's get all current question groups associated with this event.
218
-        $current_qgs = $event->get_many_related(
219
-            'Question_Group',
220
-            [['Event_Question_Group.EQG_primary' => true]]
221
-        );
222
-        $current_qgs = array_keys($current_qgs); // we just want the ids
223
-
224
-        // now let's get the groups selected in the editor and update (IF we have data)
225
-        if (! empty($question_groups)) {
226
-            foreach ($question_groups as $QSG_ID => $val) {
227
-                // add to event
228
-                if ($val) {
229
-                    $qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
230
-                }
231
-                // trip success to false if result is empty
232
-                $success = ! empty($qg) ? $success : false;
233
-            }
234
-        }
235
-
236
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
237
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
238
-
239
-        foreach ($removed_qgs as $QSG_ID) {
240
-            $qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
241
-            // trip success to false if result is empty
242
-            $success = ! empty($qg) ? $success : false;
243
-        }
244
-        return $success;
245
-    }
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param EE_Event $event
206
+	 * @param array    $data
207
+	 * @return bool
208
+	 * @throws EE_Error
209
+	 * @throws ReflectionException
210
+	 */
211
+	public function primary_question_group_update($event, $data)
212
+	{
213
+		$question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
214
+		$added_qgs       = array_keys($question_groups);
215
+		$success         = true;
216
+
217
+		// let's get all current question groups associated with this event.
218
+		$current_qgs = $event->get_many_related(
219
+			'Question_Group',
220
+			[['Event_Question_Group.EQG_primary' => true]]
221
+		);
222
+		$current_qgs = array_keys($current_qgs); // we just want the ids
223
+
224
+		// now let's get the groups selected in the editor and update (IF we have data)
225
+		if (! empty($question_groups)) {
226
+			foreach ($question_groups as $QSG_ID => $val) {
227
+				// add to event
228
+				if ($val) {
229
+					$qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
230
+				}
231
+				// trip success to false if result is empty
232
+				$success = ! empty($qg) ? $success : false;
233
+			}
234
+		}
235
+
236
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
237
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
238
+
239
+		foreach ($removed_qgs as $QSG_ID) {
240
+			$qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
241
+			// trip success to false if result is empty
242
+			$success = ! empty($qg) ? $success : false;
243
+		}
244
+		return $success;
245
+	}
246 246
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
                     [['Event_Question_Group.EQG_primary' => true]]
143 143
                 )
144 144
                 : [];
145
-            $EQGids                   = array_keys($EQGs);
145
+            $EQGids = array_keys($EQGs);
146 146
 
147
-            if (! empty($QSGs)) {
147
+            if ( ! empty($QSGs)) {
148 148
                 $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
149 149
                 foreach ($QSGs as $QSG) {
150 150
                     $QSG_ID          = absint($QSG->ID());
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                             'QSG_ID' => $QSG_ID,
161 161
                         ]
162 162
                         : ['action' => 'question_groups'];
163
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
163
+                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
164 164
                         $edit_query_args,
165 165
                         EE_FORMS_ADMIN_URL
166 166
                     );
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
                     );
171 171
 
172 172
                     $html .= '
173
-					<p id="event-question-group-' . $QSG_ID . '">
174
-						<input value="' . $QSG_ID . '"
173
+					<p id="event-question-group-' . $QSG_ID.'">
174
+						<input value="' . $QSG_ID.'"
175 175
 						    type="checkbox"
176
-						    name="question_groups[' . $QSG_ID . ']" '
176
+						    name="question_groups[' . $QSG_ID.']" '
177 177
                             . $visibility
178
-                            . $checked . '
178
+                            . $checked.'
179 179
                         />
180
-						<a href="' . esc_url_raw($edit_link) . '"
181
-						    title="' . esc_attr($edit_link_title) . '"
180
+						<a href="' . esc_url_raw($edit_link).'"
181
+						    title="' . esc_attr($edit_link_title).'"
182 182
 						    target="_blank"
183 183
 						    >
184
-						    ' . $QSG->get('QSG_name') . '
184
+						    ' . $QSG->get('QSG_name').'
185 185
                         </a>
186 186
 					</p>';
187 187
                 }
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         $current_qgs = array_keys($current_qgs); // we just want the ids
223 223
 
224 224
         // now let's get the groups selected in the editor and update (IF we have data)
225
-        if (! empty($question_groups)) {
225
+        if ( ! empty($question_groups)) {
226 226
             foreach ($question_groups as $QSG_ID => $val) {
227 227
                 // add to event
228 228
                 if ($val) {
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +3944 added lines, -3944 removed lines patch added patch discarded remove patch
@@ -19,4022 +19,4022 @@
 block discarded – undo
19 19
  */
20 20
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
21 21
 {
22
-    /**
23
-     * @var EE_Admin_Config
24
-     */
25
-    protected $admin_config;
22
+	/**
23
+	 * @var EE_Admin_Config
24
+	 */
25
+	protected $admin_config;
26 26
 
27
-    /**
28
-     * @var LoaderInterface
29
-     */
30
-    protected $loader;
27
+	/**
28
+	 * @var LoaderInterface
29
+	 */
30
+	protected $loader;
31 31
 
32
-    /**
33
-     * @var RequestInterface
34
-     */
35
-    protected $request;
32
+	/**
33
+	 * @var RequestInterface
34
+	 */
35
+	protected $request;
36 36
 
37
-    // set in _init_page_props()
38
-    public $page_slug;
37
+	// set in _init_page_props()
38
+	public $page_slug;
39 39
 
40
-    public $page_label;
40
+	public $page_label;
41 41
 
42
-    public $page_folder;
42
+	public $page_folder;
43 43
 
44
-    // set in define_page_props()
45
-    protected $_admin_base_url;
44
+	// set in define_page_props()
45
+	protected $_admin_base_url;
46 46
 
47
-    protected $_admin_base_path;
47
+	protected $_admin_base_path;
48 48
 
49
-    protected $_admin_page_title;
49
+	protected $_admin_page_title;
50 50
 
51
-    protected $_labels;
51
+	protected $_labels;
52 52
 
53 53
 
54
-    // set early within EE_Admin_Init
55
-    protected $_wp_page_slug;
54
+	// set early within EE_Admin_Init
55
+	protected $_wp_page_slug;
56 56
 
57
-    // nav tabs
58
-    protected $_nav_tabs;
57
+	// nav tabs
58
+	protected $_nav_tabs;
59 59
 
60
-    protected $_default_nav_tab_name;
60
+	protected $_default_nav_tab_name;
61 61
 
62 62
 
63
-    // template variables (used by templates)
64
-    protected $_template_path;
63
+	// template variables (used by templates)
64
+	protected $_template_path;
65 65
 
66
-    protected $_column_template_path;
66
+	protected $_column_template_path;
67 67
 
68
-    /**
69
-     * @var array $_template_args
70
-     */
71
-    protected $_template_args = [];
68
+	/**
69
+	 * @var array $_template_args
70
+	 */
71
+	protected $_template_args = [];
72 72
 
73
-    /**
74
-     * this will hold the list table object for a given view.
75
-     *
76
-     * @var EE_Admin_List_Table $_list_table_object
77
-     */
78
-    protected $_list_table_object;
73
+	/**
74
+	 * this will hold the list table object for a given view.
75
+	 *
76
+	 * @var EE_Admin_List_Table $_list_table_object
77
+	 */
78
+	protected $_list_table_object;
79 79
 
80
-    // boolean
81
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
80
+	// boolean
81
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
82 82
 
83
-    protected $_routing;
83
+	protected $_routing;
84 84
 
85
-    // list table args
86
-    protected $_view;
85
+	// list table args
86
+	protected $_view;
87 87
 
88
-    protected $_views;
88
+	protected $_views;
89 89
 
90 90
 
91
-    // action => method pairs used for routing incoming requests
92
-    protected $_page_routes;
91
+	// action => method pairs used for routing incoming requests
92
+	protected $_page_routes;
93 93
 
94
-    /**
95
-     * @var array $_page_config
96
-     */
97
-    protected $_page_config;
94
+	/**
95
+	 * @var array $_page_config
96
+	 */
97
+	protected $_page_config;
98 98
 
99
-    /**
100
-     * the current page route and route config
101
-     *
102
-     * @var string $_route
103
-     */
104
-    protected $_route;
99
+	/**
100
+	 * the current page route and route config
101
+	 *
102
+	 * @var string $_route
103
+	 */
104
+	protected $_route;
105 105
 
106
-    /**
107
-     * @var string $_cpt_route
108
-     */
109
-    protected $_cpt_route;
106
+	/**
107
+	 * @var string $_cpt_route
108
+	 */
109
+	protected $_cpt_route;
110 110
 
111
-    /**
112
-     * @var array $_route_config
113
-     */
114
-    protected $_route_config;
111
+	/**
112
+	 * @var array $_route_config
113
+	 */
114
+	protected $_route_config;
115 115
 
116
-    /**
117
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
118
-     * actions.
119
-     *
120
-     * @since 4.6.x
121
-     * @var array.
122
-     */
123
-    protected $_default_route_query_args;
116
+	/**
117
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
118
+	 * actions.
119
+	 *
120
+	 * @since 4.6.x
121
+	 * @var array.
122
+	 */
123
+	protected $_default_route_query_args;
124 124
 
125
-    // set via request page and action args.
126
-    protected $_current_page;
127
-
128
-    protected $_current_view;
125
+	// set via request page and action args.
126
+	protected $_current_page;
127
+
128
+	protected $_current_view;
129 129
 
130
-    protected $_current_page_view_url;
130
+	protected $_current_page_view_url;
131 131
 
132
-    /**
133
-     * unprocessed value for the 'action' request param (default '')
134
-     *
135
-     * @var string
136
-     */
137
-    protected $raw_req_action = '';
138
-
139
-    /**
140
-     * unprocessed value for the 'page' request param (default '')
141
-     *
142
-     * @var string
143
-     */
144
-    protected $raw_req_page = '';
145
-
146
-    /**
147
-     * sanitized request action (and nonce)
148
-     *
149
-     * @var string
150
-     */
151
-    protected $_req_action = '';
152
-
153
-    /**
154
-     * sanitized request action nonce
155
-     *
156
-     * @var string
157
-     */
158
-    protected $_req_nonce = '';
159
-
160
-    /**
161
-     * @var string
162
-     */
163
-    protected $_search_btn_label = '';
164
-
165
-    /**
166
-     * @var string
167
-     */
168
-    protected $_search_box_callback = '';
169
-
170
-    /**
171
-     * @var WP_Screen
172
-     */
173
-    protected $_current_screen;
174
-
175
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
176
-    protected $_hook_obj;
177
-
178
-    // for holding incoming request data
179
-    protected $_req_data = [];
180
-
181
-    // yes / no array for admin form fields
182
-    protected $_yes_no_values = [];
183
-
184
-    // some default things shared by all child classes
185
-    protected $_default_espresso_metaboxes;
186
-
187
-    /**
188
-     * @var EE_Registry
189
-     */
190
-    protected $EE;
191
-
192
-
193
-    /**
194
-     * This is just a property that flags whether the given route is a caffeinated route or not.
195
-     *
196
-     * @var boolean
197
-     */
198
-    protected $_is_caf = false;
199
-
200
-    /**
201
-     * whether or not initializePage() has run
202
-     *
203
-     * @var boolean
204
-     */
205
-    protected $initialized = false;
206
-
207
-    /**
208
-     * @var FeatureFlags
209
-     */
210
-    protected $feature;
211
-
212
-
213
-    /**
214
-     * @Constructor
215
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
216
-     * @throws InvalidArgumentException
217
-     * @throws InvalidDataTypeException
218
-     * @throws InvalidInterfaceException
219
-     * @throws ReflectionException
220
-     */
221
-    public function __construct($routing = true)
222
-    {
223
-        $this->loader = LoaderFactory::getLoader();
224
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
225
-        $this->feature = $this->loader->getShared(FeatureFlags::class);
226
-        $this->request = $this->loader->getShared(RequestInterface::class);
227
-        // routing enabled?
228
-        $this->_routing = $routing;
229
-
230
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
231
-            $this->_is_caf = true;
232
-        }
233
-        $this->_yes_no_values = [
234
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
235
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
236
-        ];
237
-        // set the _req_data property.
238
-        $this->_req_data = $this->request->requestParams();
239
-    }
240
-
241
-
242
-    /**
243
-     * @return EE_Admin_Config
244
-     */
245
-    public function adminConfig(): EE_Admin_Config
246
-    {
247
-        return $this->admin_config;
248
-    }
249
-
250
-
251
-    /**
252
-     * @return FeatureFlags
253
-     */
254
-    public function feature(): FeatureFlags
255
-    {
256
-        return $this->feature;
257
-    }
258
-
259
-
260
-    /**
261
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
262
-     * for child classes that needed to set properties prior to these methods getting called,
263
-     * but also needed the parent class to have its construction completed as well.
264
-     * Bottom line is that constructors should ONLY be used for setting initial properties
265
-     * and any complex initialization logic should only run after instantiation is complete.
266
-     *
267
-     * This method gets called immediately after construction from within
268
-     *      EE_Admin_Page_Init::_initialize_admin_page()
269
-     *
270
-     * @throws EE_Error
271
-     * @throws InvalidArgumentException
272
-     * @throws InvalidDataTypeException
273
-     * @throws InvalidInterfaceException
274
-     * @throws ReflectionException
275
-     * @since $VID:$
276
-     */
277
-    public function initializePage()
278
-    {
279
-        if ($this->initialized) {
280
-            return;
281
-        }
282
-        // set initial page props (child method)
283
-        $this->_init_page_props();
284
-        // set global defaults
285
-        $this->_set_defaults();
286
-        // set early because incoming requests could be ajax related and we need to register those hooks.
287
-        $this->_global_ajax_hooks();
288
-        $this->_ajax_hooks();
289
-        // other_page_hooks have to be early too.
290
-        $this->_do_other_page_hooks();
291
-        // set up page dependencies
292
-        $this->_before_page_setup();
293
-        $this->_page_setup();
294
-        $this->initialized = true;
295
-    }
296
-
297
-
298
-    /**
299
-     * _init_page_props
300
-     * Child classes use to set at least the following properties:
301
-     * $page_slug.
302
-     * $page_label.
303
-     *
304
-     * @abstract
305
-     * @return void
306
-     */
307
-    abstract protected function _init_page_props();
308
-
309
-
310
-    /**
311
-     * _ajax_hooks
312
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
313
-     * Note: within the ajax callback methods.
314
-     *
315
-     * @abstract
316
-     * @return void
317
-     */
318
-    abstract protected function _ajax_hooks();
319
-
320
-
321
-    /**
322
-     * _define_page_props
323
-     * child classes define page properties in here.  Must include at least:
324
-     * $_admin_base_url = base_url for all admin pages
325
-     * $_admin_page_title = default admin_page_title for admin pages
326
-     * $_labels = array of default labels for various automatically generated elements:
327
-     *    array(
328
-     *        'buttons' => array(
329
-     *            'add' => esc_html__('label for add new button'),
330
-     *            'edit' => esc_html__('label for edit button'),
331
-     *            'delete' => esc_html__('label for delete button')
332
-     *            )
333
-     *        )
334
-     *
335
-     * @abstract
336
-     * @return void
337
-     */
338
-    abstract protected function _define_page_props();
339
-
340
-
341
-    /**
342
-     * _set_page_routes
343
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
344
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
345
-     * have a 'default' route. Here's the format
346
-     * $this->_page_routes = array(
347
-     *        'default' => array(
348
-     *            'func' => '_default_method_handling_route',
349
-     *            'args' => array('array','of','args'),
350
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
351
-     *            ajax request, backend processing)
352
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
353
-     *            headers route after.  The string you enter here should match the defined route reference for a
354
-     *            headers sent route.
355
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
356
-     *            this route.
357
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
358
-     *            checks).
359
-     *        ),
360
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
361
-     *        handling method.
362
-     *        )
363
-     * )
364
-     *
365
-     * @abstract
366
-     * @return void
367
-     */
368
-    abstract protected function _set_page_routes();
369
-
370
-
371
-    /**
372
-     * _set_page_config
373
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
374
-     * array corresponds to the page_route for the loaded page. Format:
375
-     * $this->_page_config = array(
376
-     *        'default' => array(
377
-     *            'labels' => array(
378
-     *                'buttons' => array(
379
-     *                    'add' => esc_html__('label for adding item'),
380
-     *                    'edit' => esc_html__('label for editing item'),
381
-     *                    'delete' => esc_html__('label for deleting item')
382
-     *                ),
383
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
384
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
385
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
386
-     *            _define_page_props() method
387
-     *            'nav' => array(
388
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
389
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
390
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
391
-     *                'order' => 10, //required to indicate tab position.
392
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
393
-     *                displayed then add this parameter.
394
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
395
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
396
-     *            metaboxes set for eventespresso admin pages.
397
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
398
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
399
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
400
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
401
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
402
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
403
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
404
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
405
-     *            want to display.
406
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
407
-     *                'tab_id' => array(
408
-     *                    'title' => 'tab_title',
409
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
410
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
411
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
412
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
413
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
414
-     *                    attempt to use the callback which should match the name of a method in the class
415
-     *                    ),
416
-     *                'tab2_id' => array(
417
-     *                    'title' => 'tab2 title',
418
-     *                    'filename' => 'file_name_2'
419
-     *                    'callback' => 'callback_method_for_content',
420
-     *                 ),
421
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
422
-     *            help tab area on an admin page. @return void
423
-     *
424
-     * @abstract
425
-     */
426
-    abstract protected function _set_page_config();
427
-
428
-
429
-    /**
430
-     * _add_screen_options
431
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
432
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
433
-     * to a particular view.
434
-     *
435
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
436
-     *         see also WP_Screen object documents...
437
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
438
-     * @abstract
439
-     * @return void
440
-     */
441
-    abstract protected function _add_screen_options();
442
-
443
-
444
-    /**
445
-     * _add_feature_pointers
446
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
447
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
448
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
449
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
450
-     * extended) also see:
451
-     *
452
-     * @link   http://eamann.com/tech/wordpress-portland/
453
-     * @abstract
454
-     * @return void
455
-     */
456
-    abstract protected function _add_feature_pointers();
457
-
458
-
459
-    /**
460
-     * load_scripts_styles
461
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
462
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
463
-     * scripts/styles per view by putting them in a dynamic function in this format
464
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
465
-     *
466
-     * @abstract
467
-     * @return void
468
-     */
469
-    abstract public function load_scripts_styles();
470
-
471
-
472
-    /**
473
-     * admin_init
474
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
475
-     * all pages/views loaded by child class.
476
-     *
477
-     * @abstract
478
-     * @return void
479
-     */
480
-    abstract public function admin_init();
481
-
482
-
483
-    /**
484
-     * admin_notices
485
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
486
-     * all pages/views loaded by child class.
487
-     *
488
-     * @abstract
489
-     * @return void
490
-     */
491
-    abstract public function admin_notices();
492
-
493
-
494
-    /**
495
-     * admin_footer_scripts
496
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
497
-     * will apply to all pages/views loaded by child class.
498
-     *
499
-     * @return void
500
-     */
501
-    abstract public function admin_footer_scripts();
502
-
503
-
504
-    /**
505
-     * admin_footer
506
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
507
-     * apply to all pages/views loaded by child class.
508
-     *
509
-     * @return void
510
-     */
511
-    public function admin_footer()
512
-    {
513
-    }
514
-
515
-
516
-    /**
517
-     * _global_ajax_hooks
518
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
519
-     * Note: within the ajax callback methods.
520
-     *
521
-     * @abstract
522
-     * @return void
523
-     */
524
-    protected function _global_ajax_hooks()
525
-    {
526
-        // for lazy loading of metabox content
527
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
528
-
529
-        add_action(
530
-            'wp_ajax_espresso_hide_status_change_notice',
531
-            [$this, 'hideStatusChangeNotice']
532
-        );
533
-        add_action(
534
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
535
-            [$this, 'hideStatusChangeNotice']
536
-        );
537
-    }
538
-
539
-
540
-    public function ajax_metabox_content()
541
-    {
542
-        $content_id  = $this->request->getRequestParam('contentid', '');
543
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
544
-        EE_Admin_Page::cached_rss_display($content_id, $content_url);
545
-        wp_die();
546
-    }
547
-
548
-
549
-    public function hideStatusChangeNotice()
550
-    {
551
-        $response = [];
552
-        try {
553
-            /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
554
-            $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
555
-            $response['success'] = $status_change_notice->dismiss() > -1;
556
-        } catch (Exception $exception) {
557
-            $response['errors'] = $exception->getMessage();
558
-        }
559
-        echo wp_json_encode($response);
560
-        exit();
561
-    }
562
-
563
-
564
-    /**
565
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
566
-     *
567
-     * @return void
568
-     */
569
-    protected function _before_page_setup()
570
-    {
571
-        // default is to do nothing
572
-    }
573
-
574
-
575
-    /**
576
-     * Makes sure any things that need to be loaded early get handled.
577
-     * We also escape early here if the page requested doesn't match the object.
578
-     *
579
-     * @final
580
-     * @return void
581
-     * @throws EE_Error
582
-     * @throws InvalidArgumentException
583
-     * @throws ReflectionException
584
-     * @throws InvalidDataTypeException
585
-     * @throws InvalidInterfaceException
586
-     */
587
-    final protected function _page_setup()
588
-    {
589
-        // requires?
590
-        // admin_init stuff - global - we're setting this REALLY early
591
-        // so if EE_Admin pages have to hook into other WP pages they can.
592
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
593
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
594
-        // next verify if we need to load anything...
595
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
596
-        $this->page_folder   = strtolower(
597
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
598
-        );
599
-        global $ee_menu_slugs;
600
-        $ee_menu_slugs = (array) $ee_menu_slugs;
601
-        if (
602
-            ! $this->request->isAjax()
603
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
604
-        ) {
605
-            return;
606
-        }
607
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
608
-        // we need to copy the action from the second to the first
609
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
610
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
611
-        $action     = $action !== '-1' ? $action : $action2;
612
-        $req_action = $action !== '-1' ? $action : 'default';
613
-
614
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
615
-        // then let's use the route as the action.
616
-        // This covers cases where we're coming in from a list table that isn't on the default route.
617
-        $route = $this->request->getRequestParam('route');
618
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
619
-            ? $route
620
-            : $req_action;
621
-
622
-        $this->_current_view = $this->_req_action;
623
-        $this->_req_nonce    = $this->_req_action . '_nonce';
624
-        $this->_define_page_props();
625
-        $this->_current_page_view_url = add_query_arg(
626
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
627
-            $this->_admin_base_url
628
-        );
629
-        // default things
630
-        $this->_default_espresso_metaboxes = [
631
-            '_espresso_news_post_box',
632
-            '_espresso_links_post_box',
633
-            '_espresso_ratings_request',
634
-            '_espresso_sponsors_post_box',
635
-        ];
636
-        // set page configs
637
-        $this->_set_page_routes();
638
-        $this->_set_page_config();
639
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
640
-        if ($this->request->requestParamIsSet('wp_referer')) {
641
-            $wp_referer = $this->request->getRequestParam('wp_referer');
642
-            if ($wp_referer) {
643
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
644
-            }
645
-        }
646
-        // for caffeinated and other extended functionality.
647
-        //  If there is a _extend_page_config method
648
-        // then let's run that to modify the all the various page configuration arrays
649
-        if (method_exists($this, '_extend_page_config')) {
650
-            $this->_extend_page_config();
651
-        }
652
-        // for CPT and other extended functionality.
653
-        // If there is an _extend_page_config_for_cpt
654
-        // then let's run that to modify all the various page configuration arrays.
655
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
656
-            $this->_extend_page_config_for_cpt();
657
-        }
658
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
659
-        $this->_page_routes = apply_filters(
660
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
661
-            $this->_page_routes,
662
-            $this
663
-        );
664
-        $this->_page_config = apply_filters(
665
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
666
-            $this->_page_config,
667
-            $this
668
-        );
669
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
670
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
671
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
672
-            add_action(
673
-                'AHEE__EE_Admin_Page__route_admin_request',
674
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
675
-                10,
676
-                2
677
-            );
678
-        }
679
-        // next route only if routing enabled
680
-        if ($this->_routing && ! $this->request->isAjax()) {
681
-            $this->_verify_routes();
682
-            // next let's just check user_access and kill if no access
683
-            $this->check_user_access();
684
-            if ($this->_is_UI_request) {
685
-                // admin_init stuff - global, all views for this page class, specific view
686
-                add_action('admin_init', [$this, 'admin_init'], 10);
687
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
688
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
689
-                }
690
-            } else {
691
-                // hijack regular WP loading and route admin request immediately
692
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
693
-                $this->route_admin_request();
694
-            }
695
-        }
696
-    }
697
-
698
-
699
-    /**
700
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
701
-     *
702
-     * @return void
703
-     * @throws EE_Error
704
-     */
705
-    private function _do_other_page_hooks()
706
-    {
707
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
708
-        foreach ($registered_pages as $page) {
709
-            // now let's setup the file name and class that should be present
710
-            $classname = str_replace('.class.php', '', $page);
711
-            // autoloaders should take care of loading file
712
-            if (! class_exists($classname)) {
713
-                $error_msg[] = sprintf(
714
-                    esc_html__(
715
-                        'Something went wrong with loading the %s admin hooks page.',
716
-                        'event_espresso'
717
-                    ),
718
-                    $page
719
-                );
720
-                $error_msg[] = $error_msg[0]
721
-                               . "\r\n"
722
-                               . sprintf(
723
-                                   esc_html__(
724
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
725
-                                       'event_espresso'
726
-                                   ),
727
-                                   $page,
728
-                                   '<br />',
729
-                                   '<strong>' . $classname . '</strong>'
730
-                               );
731
-                throw new EE_Error(implode('||', $error_msg));
732
-            }
733
-            // notice we are passing the instance of this class to the hook object.
734
-            $this->loader->getShared($classname, [$this]);
735
-        }
736
-    }
737
-
738
-
739
-    /**
740
-     * @throws ReflectionException
741
-     * @throws EE_Error
742
-     */
743
-    public function load_page_dependencies()
744
-    {
745
-        try {
746
-            $this->_load_page_dependencies();
747
-        } catch (EE_Error $e) {
748
-            $e->get_error();
749
-        }
750
-    }
751
-
752
-
753
-    /**
754
-     * load_page_dependencies
755
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
756
-     *
757
-     * @return void
758
-     * @throws DomainException
759
-     * @throws EE_Error
760
-     * @throws InvalidArgumentException
761
-     * @throws InvalidDataTypeException
762
-     * @throws InvalidInterfaceException
763
-     */
764
-    protected function _load_page_dependencies()
765
-    {
766
-        // let's set the current_screen and screen options to override what WP set
767
-        $this->_current_screen = get_current_screen();
768
-        // load admin_notices - global, page class, and view specific
769
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
770
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
771
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
772
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
773
-        }
774
-        // load network admin_notices - global, page class, and view specific
775
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
776
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
777
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
778
-        }
779
-        // this will save any per_page screen options if they are present
780
-        $this->_set_per_page_screen_options();
781
-        // setup list table properties
782
-        $this->_set_list_table();
783
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
784
-        // However in some cases the metaboxes will need to be added within a route handling callback.
785
-        $this->_add_registered_meta_boxes();
786
-        $this->_add_screen_columns();
787
-        // add screen options - global, page child class, and view specific
788
-        $this->_add_global_screen_options();
789
-        $this->_add_screen_options();
790
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
791
-        if (method_exists($this, $add_screen_options)) {
792
-            $this->{$add_screen_options}();
793
-        }
794
-        // add help tab(s) - set via page_config and qtips.
795
-        $this->_add_help_tabs();
796
-        $this->_add_qtips();
797
-        // add feature_pointers - global, page child class, and view specific
798
-        $this->_add_feature_pointers();
799
-        $this->_add_global_feature_pointers();
800
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
801
-        if (method_exists($this, $add_feature_pointer)) {
802
-            $this->{$add_feature_pointer}();
803
-        }
804
-        // enqueue scripts/styles - global, page class, and view specific
805
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
806
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
807
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
808
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
809
-        }
810
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
811
-        // admin_print_footer_scripts - global, page child class, and view specific.
812
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
813
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
814
-        // is a good use case. Notice the late priority we're giving these
815
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
816
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
817
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
818
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
819
-        }
820
-        // admin footer scripts
821
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
822
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
823
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
824
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
825
-        }
826
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
827
-        // targeted hook
828
-        do_action(
829
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
830
-        );
831
-    }
832
-
833
-
834
-    /**
835
-     * _set_defaults
836
-     * This sets some global defaults for class properties.
837
-     */
838
-    private function _set_defaults()
839
-    {
840
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
841
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
842
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
843
-        $this->_page_config          = $this->_default_route_query_args = [];
844
-        $this->_default_nav_tab_name = 'overview';
845
-        // init template args
846
-        $this->_template_args = [
847
-            'admin_page_header'  => '',
848
-            'admin_page_content' => '',
849
-            'post_body_content'  => '',
850
-            'before_list_table'  => '',
851
-            'after_list_table'   => '',
852
-        ];
853
-    }
854
-
855
-
856
-    /**
857
-     * route_admin_request
858
-     *
859
-     * @return void
860
-     * @throws InvalidArgumentException
861
-     * @throws InvalidInterfaceException
862
-     * @throws InvalidDataTypeException
863
-     * @throws EE_Error
864
-     * @throws ReflectionException
865
-     * @see    _route_admin_request()
866
-     */
867
-    public function route_admin_request()
868
-    {
869
-        try {
870
-            $this->_route_admin_request();
871
-        } catch (EE_Error $e) {
872
-            $e->get_error();
873
-        }
874
-    }
875
-
876
-
877
-    public function set_wp_page_slug($wp_page_slug)
878
-    {
879
-        $this->_wp_page_slug = $wp_page_slug;
880
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
881
-        if (is_network_admin()) {
882
-            $this->_wp_page_slug .= '-network';
883
-        }
884
-    }
885
-
886
-
887
-    /**
888
-     * _verify_routes
889
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
890
-     * we know if we need to drop out.
891
-     *
892
-     * @return bool
893
-     * @throws EE_Error
894
-     */
895
-    protected function _verify_routes()
896
-    {
897
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
898
-        if (! $this->_current_page && ! $this->request->isAjax()) {
899
-            return false;
900
-        }
901
-        $this->_route = false;
902
-        // check that the page_routes array is not empty
903
-        if (empty($this->_page_routes)) {
904
-            // user error msg
905
-            $error_msg = sprintf(
906
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
907
-                $this->_admin_page_title
908
-            );
909
-            // developer error msg
910
-            $error_msg .= '||' . $error_msg
911
-                          . esc_html__(
912
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
913
-                              'event_espresso'
914
-                          );
915
-            throw new EE_Error($error_msg);
916
-        }
917
-        // and that the requested page route exists
918
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
919
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
920
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
921
-        } else {
922
-            // user error msg
923
-            $error_msg = sprintf(
924
-                esc_html__(
925
-                    'The requested page route does not exist for the %s admin page.',
926
-                    'event_espresso'
927
-                ),
928
-                $this->_admin_page_title
929
-            );
930
-            // developer error msg
931
-            $error_msg .= '||' . $error_msg
932
-                          . sprintf(
933
-                              esc_html__(
934
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
935
-                                  'event_espresso'
936
-                              ),
937
-                              $this->_req_action
938
-                          );
939
-            throw new EE_Error($error_msg);
940
-        }
941
-        // and that a default route exists
942
-        if (! array_key_exists('default', $this->_page_routes)) {
943
-            // user error msg
944
-            $error_msg = sprintf(
945
-                esc_html__(
946
-                    'A default page route has not been set for the % admin page.',
947
-                    'event_espresso'
948
-                ),
949
-                $this->_admin_page_title
950
-            );
951
-            // developer error msg
952
-            $error_msg .= '||' . $error_msg
953
-                          . esc_html__(
954
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
955
-                              'event_espresso'
956
-                          );
957
-            throw new EE_Error($error_msg);
958
-        }
959
-
960
-        // first lets' catch if the UI request has EVER been set.
961
-        if ($this->_is_UI_request === null) {
962
-            // lets set if this is a UI request or not.
963
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
964
-            // wait a minute... we might have a noheader in the route array
965
-            $this->_is_UI_request = ! (
966
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
967
-            )
968
-                ? $this->_is_UI_request
969
-                : false;
970
-        }
971
-        $this->_set_current_labels();
972
-        return true;
973
-    }
974
-
975
-
976
-    /**
977
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
978
-     *
979
-     * @param string $route the route name we're verifying
980
-     * @return bool we'll throw an exception if this isn't a valid route.
981
-     * @throws EE_Error
982
-     */
983
-    protected function _verify_route($route)
984
-    {
985
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
986
-            return true;
987
-        }
988
-        // user error msg
989
-        $error_msg = sprintf(
990
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
991
-            $this->_admin_page_title
992
-        );
993
-        // developer error msg
994
-        $error_msg .= '||' . $error_msg
995
-                      . sprintf(
996
-                          esc_html__(
997
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
998
-                              'event_espresso'
999
-                          ),
1000
-                          $route
1001
-                      );
1002
-        throw new EE_Error($error_msg);
1003
-    }
1004
-
1005
-
1006
-    /**
1007
-     * perform nonce verification
1008
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1009
-     * using this method (and save retyping!)
1010
-     *
1011
-     * @param string $nonce     The nonce sent
1012
-     * @param string $nonce_ref The nonce reference string (name0)
1013
-     * @return void
1014
-     * @throws EE_Error
1015
-     * @throws InvalidArgumentException
1016
-     * @throws InvalidDataTypeException
1017
-     * @throws InvalidInterfaceException
1018
-     */
1019
-    protected function _verify_nonce($nonce, $nonce_ref)
1020
-    {
1021
-        // verify nonce against expected value
1022
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1023
-            // these are not the droids you are looking for !!!
1024
-            $msg = sprintf(
1025
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1026
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1027
-                '</a>'
1028
-            );
1029
-            if (WP_DEBUG) {
1030
-                $msg .= "\n  ";
1031
-                $msg .= sprintf(
1032
-                    esc_html__(
1033
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1034
-                        'event_espresso'
1035
-                    ),
1036
-                    __CLASS__
1037
-                );
1038
-            }
1039
-            if (! $this->request->isAjax()) {
1040
-                wp_die($msg);
1041
-            }
1042
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1043
-            $this->_return_json();
1044
-        }
1045
-    }
1046
-
1047
-
1048
-    /**
1049
-     * _route_admin_request()
1050
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1051
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1052
-     * in the page routes and then will try to load the corresponding method.
1053
-     *
1054
-     * @return void
1055
-     * @throws EE_Error
1056
-     * @throws InvalidArgumentException
1057
-     * @throws InvalidDataTypeException
1058
-     * @throws InvalidInterfaceException
1059
-     * @throws ReflectionException
1060
-     */
1061
-    protected function _route_admin_request()
1062
-    {
1063
-        if (! $this->_is_UI_request) {
1064
-            $this->_verify_routes();
1065
-        }
1066
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1067
-        if ($this->_req_action !== 'default' && $nonce_check) {
1068
-            // set nonce from post data
1069
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1070
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1071
-        }
1072
-        // set the nav_tabs array but ONLY if this is  UI_request
1073
-        if ($this->_is_UI_request) {
1074
-            $this->_set_nav_tabs();
1075
-        }
1076
-        // grab callback function
1077
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1078
-        // check if callback has args
1079
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1080
-        $error_msg = '';
1081
-        // action right before calling route
1082
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1083
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1084
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1085
-        }
1086
-        // right before calling the route, let's clean the _wp_http_referer
1087
-        $this->request->setServerParam(
1088
-            'REQUEST_URI',
1089
-            remove_query_arg(
1090
-                '_wp_http_referer',
1091
-                wp_unslash($this->request->getServerParam('REQUEST_URI'))
1092
-            )
1093
-        );
1094
-        if (! empty($func)) {
1095
-            if (is_array($func)) {
1096
-                [$class, $method] = $func;
1097
-            } elseif (strpos($func, '::') !== false) {
1098
-                [$class, $method] = explode('::', $func);
1099
-            } else {
1100
-                $class  = $this;
1101
-                $method = $func;
1102
-            }
1103
-            if (! (is_object($class) && $class === $this)) {
1104
-                // send along this admin page object for access by addons.
1105
-                $args['admin_page_object'] = $this;
1106
-            }
1107
-            if (
1108
-                // is it a method on a class that doesn't work?
1109
-                (
1110
-                    (
1111
-                        method_exists($class, $method)
1112
-                        && call_user_func_array([$class, $method], $args) === false
1113
-                    )
1114
-                    && (
1115
-                        // is it a standalone function that doesn't work?
1116
-                        function_exists($method)
1117
-                        && call_user_func_array(
1118
-                            $func,
1119
-                            array_merge(['admin_page_object' => $this], $args)
1120
-                        ) === false
1121
-                    )
1122
-                )
1123
-                || (
1124
-                    // is it neither a class method NOR a standalone function?
1125
-                    ! method_exists($class, $method)
1126
-                    && ! function_exists($method)
1127
-                )
1128
-            ) {
1129
-                // user error msg
1130
-                $error_msg = esc_html__(
1131
-                    'An error occurred. The  requested page route could not be found.',
1132
-                    'event_espresso'
1133
-                );
1134
-                // developer error msg
1135
-                $error_msg .= '||';
1136
-                $error_msg .= sprintf(
1137
-                    esc_html__(
1138
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1139
-                        'event_espresso'
1140
-                    ),
1141
-                    $method
1142
-                );
1143
-            }
1144
-            if (! empty($error_msg)) {
1145
-                throw new EE_Error($error_msg);
1146
-            }
1147
-        }
1148
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1149
-        // then we need to reset the routing properties to the new route.
1150
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1151
-        if (
1152
-            $this->_is_UI_request === false
1153
-            && is_array($this->_route)
1154
-            && ! empty($this->_route['headers_sent_route'])
1155
-        ) {
1156
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1157
-        }
1158
-    }
1159
-
1160
-
1161
-    /**
1162
-     * This method just allows the resetting of page properties in the case where a no headers
1163
-     * route redirects to a headers route in its route config.
1164
-     *
1165
-     * @param string $new_route New (non header) route to redirect to.
1166
-     * @return   void
1167
-     * @throws ReflectionException
1168
-     * @throws InvalidArgumentException
1169
-     * @throws InvalidInterfaceException
1170
-     * @throws InvalidDataTypeException
1171
-     * @throws EE_Error
1172
-     * @since   4.3.0
1173
-     */
1174
-    protected function _reset_routing_properties($new_route)
1175
-    {
1176
-        $this->_is_UI_request = true;
1177
-        // now we set the current route to whatever the headers_sent_route is set at
1178
-        $this->request->setRequestParam('action', $new_route);
1179
-        // rerun page setup
1180
-        $this->_page_setup();
1181
-    }
1182
-
1183
-
1184
-    /**
1185
-     * _add_query_arg
1186
-     * adds nonce to array of arguments then calls WP add_query_arg function
1187
-     *(internally just uses EEH_URL's function with the same name)
1188
-     *
1189
-     * @param array  $args
1190
-     * @param string $url
1191
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1192
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1193
-     *                                        Example usage: If the current page is:
1194
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1195
-     *                                        &action=default&event_id=20&month_range=March%202015
1196
-     *                                        &_wpnonce=5467821
1197
-     *                                        and you call:
1198
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1199
-     *                                        array(
1200
-     *                                        'action' => 'resend_something',
1201
-     *                                        'page=>espresso_registrations'
1202
-     *                                        ),
1203
-     *                                        $some_url,
1204
-     *                                        true
1205
-     *                                        );
1206
-     *                                        It will produce a url in this structure:
1207
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1208
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1209
-     *                                        month_range]=March%202015
1210
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1211
-     * @return string
1212
-     */
1213
-    public static function add_query_args_and_nonce(
1214
-        $args = [],
1215
-        $url = '',
1216
-        $sticky = false,
1217
-        $exclude_nonce = false
1218
-    ) {
1219
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1220
-        if ($sticky) {
1221
-            /** @var RequestInterface $request */
1222
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1223
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1224
-            foreach ($request->requestParams() as $key => $value) {
1225
-                // do not add nonces
1226
-                if (strpos($key, 'nonce') !== false) {
1227
-                    continue;
1228
-                }
1229
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1230
-            }
1231
-        }
1232
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * This returns a generated link that will load the related help tab.
1238
-     *
1239
-     * @param string $help_tab_id the id for the connected help tab
1240
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1241
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1242
-     * @return string              generated link
1243
-     * @uses EEH_Template::get_help_tab_link()
1244
-     */
1245
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1246
-    {
1247
-        return EEH_Template::get_help_tab_link(
1248
-            $help_tab_id,
1249
-            $this->page_slug,
1250
-            $this->_req_action,
1251
-            $icon_style,
1252
-            $help_text
1253
-        );
1254
-    }
1255
-
1256
-
1257
-    /**
1258
-     * _add_help_tabs
1259
-     * Note child classes define their help tabs within the page_config array.
1260
-     *
1261
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1262
-     * @return void
1263
-     * @throws DomainException
1264
-     * @throws EE_Error
1265
-     * @throws ReflectionException
1266
-     */
1267
-    protected function _add_help_tabs()
1268
-    {
1269
-        if (isset($this->_page_config[ $this->_req_action ])) {
1270
-            $config = $this->_page_config[ $this->_req_action ];
1271
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1272
-            if (is_array($config) && isset($config['help_sidebar'])) {
1273
-                // check that the callback given is valid
1274
-                if (! method_exists($this, $config['help_sidebar'])) {
1275
-                    throw new EE_Error(
1276
-                        sprintf(
1277
-                            esc_html__(
1278
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1279
-                                'event_espresso'
1280
-                            ),
1281
-                            $config['help_sidebar'],
1282
-                            get_class($this)
1283
-                        )
1284
-                    );
1285
-                }
1286
-                $content = apply_filters(
1287
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1288
-                    $this->{$config['help_sidebar']}()
1289
-                );
1290
-                $this->_current_screen->set_help_sidebar($content);
1291
-            }
1292
-            if (! isset($config['help_tabs'])) {
1293
-                return;
1294
-            } //no help tabs for this route
1295
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1296
-                // we're here so there ARE help tabs!
1297
-                // make sure we've got what we need
1298
-                if (! isset($cfg['title'])) {
1299
-                    throw new EE_Error(
1300
-                        esc_html__(
1301
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1302
-                            'event_espresso'
1303
-                        )
1304
-                    );
1305
-                }
1306
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1307
-                    throw new EE_Error(
1308
-                        esc_html__(
1309
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1310
-                            'event_espresso'
1311
-                        )
1312
-                    );
1313
-                }
1314
-                // first priority goes to content.
1315
-                if (! empty($cfg['content'])) {
1316
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1317
-                    // second priority goes to filename
1318
-                } elseif (! empty($cfg['filename'])) {
1319
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1320
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1321
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1322
-                                                             . basename($this->_get_dir())
1323
-                                                             . '/help_tabs/'
1324
-                                                             . $cfg['filename']
1325
-                                                             . '.help_tab.php' : $file_path;
1326
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1327
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1328
-                        EE_Error::add_error(
1329
-                            sprintf(
1330
-                                esc_html__(
1331
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1332
-                                    'event_espresso'
1333
-                                ),
1334
-                                $tab_id,
1335
-                                key($config),
1336
-                                $file_path
1337
-                            ),
1338
-                            __FILE__,
1339
-                            __FUNCTION__,
1340
-                            __LINE__
1341
-                        );
1342
-                        return;
1343
-                    }
1344
-                    $template_args['admin_page_obj'] = $this;
1345
-                    $content                         = EEH_Template::display_template(
1346
-                        $file_path,
1347
-                        $template_args,
1348
-                        true
1349
-                    );
1350
-                } else {
1351
-                    $content = '';
1352
-                }
1353
-                // check if callback is valid
1354
-                if (
1355
-                    empty($content)
1356
-                    && (
1357
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1358
-                    )
1359
-                ) {
1360
-                    EE_Error::add_error(
1361
-                        sprintf(
1362
-                            esc_html__(
1363
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1364
-                                'event_espresso'
1365
-                            ),
1366
-                            $cfg['title']
1367
-                        ),
1368
-                        __FILE__,
1369
-                        __FUNCTION__,
1370
-                        __LINE__
1371
-                    );
1372
-                    return;
1373
-                }
1374
-                // setup config array for help tab method
1375
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1376
-                $_ht = [
1377
-                    'id'       => $id,
1378
-                    'title'    => $cfg['title'],
1379
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1380
-                    'content'  => $content,
1381
-                ];
1382
-                $this->_current_screen->add_help_tab($_ht);
1383
-            }
1384
-        }
1385
-    }
1386
-
1387
-
1388
-    /**
1389
-     * This simply sets up any qtips that have been defined in the page config
1390
-     *
1391
-     * @return void
1392
-     * @throws ReflectionException
1393
-     * @throws EE_Error
1394
-     */
1395
-    protected function _add_qtips()
1396
-    {
1397
-        if (isset($this->_route_config['qtips'])) {
1398
-            $qtips = (array) $this->_route_config['qtips'];
1399
-            // load qtip loader
1400
-            $path = [
1401
-                $this->_get_dir() . '/qtips/',
1402
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1403
-            ];
1404
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1405
-        }
1406
-    }
1407
-
1408
-
1409
-    /**
1410
-     * _set_nav_tabs
1411
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1412
-     * wish to add additional tabs or modify accordingly.
1413
-     *
1414
-     * @return void
1415
-     * @throws InvalidArgumentException
1416
-     * @throws InvalidInterfaceException
1417
-     * @throws InvalidDataTypeException
1418
-     */
1419
-    protected function _set_nav_tabs()
1420
-    {
1421
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1422
-        $i = 0;
1423
-        foreach ($this->_page_config as $slug => $config) {
1424
-            if (! is_array($config) || empty($config['nav'])) {
1425
-                continue;
1426
-            }
1427
-            // no nav tab for this config
1428
-            // check for persistent flag
1429
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1430
-                // nav tab is only to appear when route requested.
1431
-                continue;
1432
-            }
1433
-            if (! $this->check_user_access($slug, true)) {
1434
-                // no nav tab because current user does not have access.
1435
-                continue;
1436
-            }
1437
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1438
-            $this->_nav_tabs[ $slug ] = [
1439
-                'url'       => isset($config['nav']['url'])
1440
-                    ? $config['nav']['url']
1441
-                    : EE_Admin_Page::add_query_args_and_nonce(
1442
-                        ['action' => $slug],
1443
-                        $this->_admin_base_url
1444
-                    ),
1445
-                'link_text' => isset($config['nav']['label'])
1446
-                    ? $config['nav']['label']
1447
-                    : ucwords(
1448
-                        str_replace('_', ' ', $slug)
1449
-                    ),
1450
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1451
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1452
-            ];
1453
-            $i++;
1454
-        }
1455
-        // if $this->_nav_tabs is empty then lets set the default
1456
-        if (empty($this->_nav_tabs)) {
1457
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1458
-                'url'       => $this->_admin_base_url,
1459
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1460
-                'css_class' => 'nav-tab-active',
1461
-                'order'     => 10,
1462
-            ];
1463
-        }
1464
-        // now let's sort the tabs according to order
1465
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * _set_current_labels
1471
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1472
-     * property array
1473
-     *
1474
-     * @return void
1475
-     */
1476
-    private function _set_current_labels()
1477
-    {
1478
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1479
-            foreach ($this->_route_config['labels'] as $label => $text) {
1480
-                if (is_array($text)) {
1481
-                    foreach ($text as $sublabel => $subtext) {
1482
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1483
-                    }
1484
-                } else {
1485
-                    $this->_labels[ $label ] = $text;
1486
-                }
1487
-            }
1488
-        }
1489
-    }
1490
-
1491
-
1492
-    /**
1493
-     *        verifies user access for this admin page
1494
-     *
1495
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1496
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1497
-     *                               return false if verify fail.
1498
-     * @return bool
1499
-     * @throws InvalidArgumentException
1500
-     * @throws InvalidDataTypeException
1501
-     * @throws InvalidInterfaceException
1502
-     */
1503
-    public function check_user_access($route_to_check = '', $verify_only = false)
1504
-    {
1505
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1506
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1507
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1508
-                          && is_array(
1509
-                              $this->_page_routes[ $route_to_check ]
1510
-                          )
1511
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1512
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1513
-        if (empty($capability) && empty($route_to_check)) {
1514
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1515
-                : $this->_route['capability'];
1516
-        } else {
1517
-            $capability = empty($capability) ? 'manage_options' : $capability;
1518
-        }
1519
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1520
-        if (
1521
-            ! $this->request->isAjax()
1522
-            && (
1523
-                ! function_exists('is_admin')
1524
-                || ! EE_Registry::instance()->CAP->current_user_can(
1525
-                    $capability,
1526
-                    $this->page_slug
1527
-                    . '_'
1528
-                    . $route_to_check,
1529
-                    $id
1530
-                )
1531
-            )
1532
-        ) {
1533
-            if ($verify_only) {
1534
-                return false;
1535
-            }
1536
-            if (is_user_logged_in()) {
1537
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1538
-            } else {
1539
-                return false;
1540
-            }
1541
-        }
1542
-        return true;
1543
-    }
1544
-
1545
-
1546
-    /**
1547
-     * admin_init_global
1548
-     * This runs all the code that we want executed within the WP admin_init hook.
1549
-     * This method executes for ALL EE Admin pages.
1550
-     *
1551
-     * @return void
1552
-     */
1553
-    public function admin_init_global()
1554
-    {
1555
-    }
1556
-
1557
-
1558
-    /**
1559
-     * wp_loaded_global
1560
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1561
-     * EE_Admin page and will execute on every EE Admin Page load
1562
-     *
1563
-     * @return void
1564
-     */
1565
-    public function wp_loaded()
1566
-    {
1567
-    }
1568
-
1569
-
1570
-    /**
1571
-     * admin_notices
1572
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1573
-     * ALL EE_Admin pages.
1574
-     *
1575
-     * @return void
1576
-     */
1577
-    public function admin_notices_global()
1578
-    {
1579
-        $this->_display_no_javascript_warning();
1580
-        $this->_display_espresso_notices();
1581
-    }
1582
-
1583
-
1584
-    public function network_admin_notices_global()
1585
-    {
1586
-        $this->_display_no_javascript_warning();
1587
-        $this->_display_espresso_notices();
1588
-    }
1589
-
1590
-
1591
-    /**
1592
-     * admin_footer_scripts_global
1593
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1594
-     * will apply on ALL EE_Admin pages.
1595
-     *
1596
-     * @return void
1597
-     */
1598
-    public function admin_footer_scripts_global()
1599
-    {
1600
-        $this->_add_admin_page_ajax_loading_img();
1601
-        $this->_add_admin_page_overlay();
1602
-        // if metaboxes are present we need to add the nonce field
1603
-        if (
1604
-            isset($this->_route_config['metaboxes'])
1605
-            || isset($this->_route_config['list_table'])
1606
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1607
-        ) {
1608
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1609
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1610
-        }
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     * admin_footer_global
1616
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1617
-     * This particular method will apply on ALL EE_Admin Pages.
1618
-     *
1619
-     * @return void
1620
-     */
1621
-    public function admin_footer_global()
1622
-    {
1623
-        // dialog container for dialog helper
1624
-        echo '
132
+	/**
133
+	 * unprocessed value for the 'action' request param (default '')
134
+	 *
135
+	 * @var string
136
+	 */
137
+	protected $raw_req_action = '';
138
+
139
+	/**
140
+	 * unprocessed value for the 'page' request param (default '')
141
+	 *
142
+	 * @var string
143
+	 */
144
+	protected $raw_req_page = '';
145
+
146
+	/**
147
+	 * sanitized request action (and nonce)
148
+	 *
149
+	 * @var string
150
+	 */
151
+	protected $_req_action = '';
152
+
153
+	/**
154
+	 * sanitized request action nonce
155
+	 *
156
+	 * @var string
157
+	 */
158
+	protected $_req_nonce = '';
159
+
160
+	/**
161
+	 * @var string
162
+	 */
163
+	protected $_search_btn_label = '';
164
+
165
+	/**
166
+	 * @var string
167
+	 */
168
+	protected $_search_box_callback = '';
169
+
170
+	/**
171
+	 * @var WP_Screen
172
+	 */
173
+	protected $_current_screen;
174
+
175
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
176
+	protected $_hook_obj;
177
+
178
+	// for holding incoming request data
179
+	protected $_req_data = [];
180
+
181
+	// yes / no array for admin form fields
182
+	protected $_yes_no_values = [];
183
+
184
+	// some default things shared by all child classes
185
+	protected $_default_espresso_metaboxes;
186
+
187
+	/**
188
+	 * @var EE_Registry
189
+	 */
190
+	protected $EE;
191
+
192
+
193
+	/**
194
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
195
+	 *
196
+	 * @var boolean
197
+	 */
198
+	protected $_is_caf = false;
199
+
200
+	/**
201
+	 * whether or not initializePage() has run
202
+	 *
203
+	 * @var boolean
204
+	 */
205
+	protected $initialized = false;
206
+
207
+	/**
208
+	 * @var FeatureFlags
209
+	 */
210
+	protected $feature;
211
+
212
+
213
+	/**
214
+	 * @Constructor
215
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
216
+	 * @throws InvalidArgumentException
217
+	 * @throws InvalidDataTypeException
218
+	 * @throws InvalidInterfaceException
219
+	 * @throws ReflectionException
220
+	 */
221
+	public function __construct($routing = true)
222
+	{
223
+		$this->loader = LoaderFactory::getLoader();
224
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
225
+		$this->feature = $this->loader->getShared(FeatureFlags::class);
226
+		$this->request = $this->loader->getShared(RequestInterface::class);
227
+		// routing enabled?
228
+		$this->_routing = $routing;
229
+
230
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
231
+			$this->_is_caf = true;
232
+		}
233
+		$this->_yes_no_values = [
234
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
235
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
236
+		];
237
+		// set the _req_data property.
238
+		$this->_req_data = $this->request->requestParams();
239
+	}
240
+
241
+
242
+	/**
243
+	 * @return EE_Admin_Config
244
+	 */
245
+	public function adminConfig(): EE_Admin_Config
246
+	{
247
+		return $this->admin_config;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return FeatureFlags
253
+	 */
254
+	public function feature(): FeatureFlags
255
+	{
256
+		return $this->feature;
257
+	}
258
+
259
+
260
+	/**
261
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
262
+	 * for child classes that needed to set properties prior to these methods getting called,
263
+	 * but also needed the parent class to have its construction completed as well.
264
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
265
+	 * and any complex initialization logic should only run after instantiation is complete.
266
+	 *
267
+	 * This method gets called immediately after construction from within
268
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
269
+	 *
270
+	 * @throws EE_Error
271
+	 * @throws InvalidArgumentException
272
+	 * @throws InvalidDataTypeException
273
+	 * @throws InvalidInterfaceException
274
+	 * @throws ReflectionException
275
+	 * @since $VID:$
276
+	 */
277
+	public function initializePage()
278
+	{
279
+		if ($this->initialized) {
280
+			return;
281
+		}
282
+		// set initial page props (child method)
283
+		$this->_init_page_props();
284
+		// set global defaults
285
+		$this->_set_defaults();
286
+		// set early because incoming requests could be ajax related and we need to register those hooks.
287
+		$this->_global_ajax_hooks();
288
+		$this->_ajax_hooks();
289
+		// other_page_hooks have to be early too.
290
+		$this->_do_other_page_hooks();
291
+		// set up page dependencies
292
+		$this->_before_page_setup();
293
+		$this->_page_setup();
294
+		$this->initialized = true;
295
+	}
296
+
297
+
298
+	/**
299
+	 * _init_page_props
300
+	 * Child classes use to set at least the following properties:
301
+	 * $page_slug.
302
+	 * $page_label.
303
+	 *
304
+	 * @abstract
305
+	 * @return void
306
+	 */
307
+	abstract protected function _init_page_props();
308
+
309
+
310
+	/**
311
+	 * _ajax_hooks
312
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
313
+	 * Note: within the ajax callback methods.
314
+	 *
315
+	 * @abstract
316
+	 * @return void
317
+	 */
318
+	abstract protected function _ajax_hooks();
319
+
320
+
321
+	/**
322
+	 * _define_page_props
323
+	 * child classes define page properties in here.  Must include at least:
324
+	 * $_admin_base_url = base_url for all admin pages
325
+	 * $_admin_page_title = default admin_page_title for admin pages
326
+	 * $_labels = array of default labels for various automatically generated elements:
327
+	 *    array(
328
+	 *        'buttons' => array(
329
+	 *            'add' => esc_html__('label for add new button'),
330
+	 *            'edit' => esc_html__('label for edit button'),
331
+	 *            'delete' => esc_html__('label for delete button')
332
+	 *            )
333
+	 *        )
334
+	 *
335
+	 * @abstract
336
+	 * @return void
337
+	 */
338
+	abstract protected function _define_page_props();
339
+
340
+
341
+	/**
342
+	 * _set_page_routes
343
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
344
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
345
+	 * have a 'default' route. Here's the format
346
+	 * $this->_page_routes = array(
347
+	 *        'default' => array(
348
+	 *            'func' => '_default_method_handling_route',
349
+	 *            'args' => array('array','of','args'),
350
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
351
+	 *            ajax request, backend processing)
352
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
353
+	 *            headers route after.  The string you enter here should match the defined route reference for a
354
+	 *            headers sent route.
355
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
356
+	 *            this route.
357
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
358
+	 *            checks).
359
+	 *        ),
360
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
361
+	 *        handling method.
362
+	 *        )
363
+	 * )
364
+	 *
365
+	 * @abstract
366
+	 * @return void
367
+	 */
368
+	abstract protected function _set_page_routes();
369
+
370
+
371
+	/**
372
+	 * _set_page_config
373
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
374
+	 * array corresponds to the page_route for the loaded page. Format:
375
+	 * $this->_page_config = array(
376
+	 *        'default' => array(
377
+	 *            'labels' => array(
378
+	 *                'buttons' => array(
379
+	 *                    'add' => esc_html__('label for adding item'),
380
+	 *                    'edit' => esc_html__('label for editing item'),
381
+	 *                    'delete' => esc_html__('label for deleting item')
382
+	 *                ),
383
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
384
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
385
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
386
+	 *            _define_page_props() method
387
+	 *            'nav' => array(
388
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
389
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
390
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
391
+	 *                'order' => 10, //required to indicate tab position.
392
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
393
+	 *                displayed then add this parameter.
394
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
395
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
396
+	 *            metaboxes set for eventespresso admin pages.
397
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
398
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
399
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
400
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
401
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
402
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
403
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
404
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
405
+	 *            want to display.
406
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
407
+	 *                'tab_id' => array(
408
+	 *                    'title' => 'tab_title',
409
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
410
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
411
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
412
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
413
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
414
+	 *                    attempt to use the callback which should match the name of a method in the class
415
+	 *                    ),
416
+	 *                'tab2_id' => array(
417
+	 *                    'title' => 'tab2 title',
418
+	 *                    'filename' => 'file_name_2'
419
+	 *                    'callback' => 'callback_method_for_content',
420
+	 *                 ),
421
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
422
+	 *            help tab area on an admin page. @return void
423
+	 *
424
+	 * @abstract
425
+	 */
426
+	abstract protected function _set_page_config();
427
+
428
+
429
+	/**
430
+	 * _add_screen_options
431
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
432
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
433
+	 * to a particular view.
434
+	 *
435
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
436
+	 *         see also WP_Screen object documents...
437
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
438
+	 * @abstract
439
+	 * @return void
440
+	 */
441
+	abstract protected function _add_screen_options();
442
+
443
+
444
+	/**
445
+	 * _add_feature_pointers
446
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
447
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
448
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
449
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
450
+	 * extended) also see:
451
+	 *
452
+	 * @link   http://eamann.com/tech/wordpress-portland/
453
+	 * @abstract
454
+	 * @return void
455
+	 */
456
+	abstract protected function _add_feature_pointers();
457
+
458
+
459
+	/**
460
+	 * load_scripts_styles
461
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
462
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
463
+	 * scripts/styles per view by putting them in a dynamic function in this format
464
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
465
+	 *
466
+	 * @abstract
467
+	 * @return void
468
+	 */
469
+	abstract public function load_scripts_styles();
470
+
471
+
472
+	/**
473
+	 * admin_init
474
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
475
+	 * all pages/views loaded by child class.
476
+	 *
477
+	 * @abstract
478
+	 * @return void
479
+	 */
480
+	abstract public function admin_init();
481
+
482
+
483
+	/**
484
+	 * admin_notices
485
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
486
+	 * all pages/views loaded by child class.
487
+	 *
488
+	 * @abstract
489
+	 * @return void
490
+	 */
491
+	abstract public function admin_notices();
492
+
493
+
494
+	/**
495
+	 * admin_footer_scripts
496
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
497
+	 * will apply to all pages/views loaded by child class.
498
+	 *
499
+	 * @return void
500
+	 */
501
+	abstract public function admin_footer_scripts();
502
+
503
+
504
+	/**
505
+	 * admin_footer
506
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
507
+	 * apply to all pages/views loaded by child class.
508
+	 *
509
+	 * @return void
510
+	 */
511
+	public function admin_footer()
512
+	{
513
+	}
514
+
515
+
516
+	/**
517
+	 * _global_ajax_hooks
518
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
519
+	 * Note: within the ajax callback methods.
520
+	 *
521
+	 * @abstract
522
+	 * @return void
523
+	 */
524
+	protected function _global_ajax_hooks()
525
+	{
526
+		// for lazy loading of metabox content
527
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
528
+
529
+		add_action(
530
+			'wp_ajax_espresso_hide_status_change_notice',
531
+			[$this, 'hideStatusChangeNotice']
532
+		);
533
+		add_action(
534
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
535
+			[$this, 'hideStatusChangeNotice']
536
+		);
537
+	}
538
+
539
+
540
+	public function ajax_metabox_content()
541
+	{
542
+		$content_id  = $this->request->getRequestParam('contentid', '');
543
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
544
+		EE_Admin_Page::cached_rss_display($content_id, $content_url);
545
+		wp_die();
546
+	}
547
+
548
+
549
+	public function hideStatusChangeNotice()
550
+	{
551
+		$response = [];
552
+		try {
553
+			/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
554
+			$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
555
+			$response['success'] = $status_change_notice->dismiss() > -1;
556
+		} catch (Exception $exception) {
557
+			$response['errors'] = $exception->getMessage();
558
+		}
559
+		echo wp_json_encode($response);
560
+		exit();
561
+	}
562
+
563
+
564
+	/**
565
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
566
+	 *
567
+	 * @return void
568
+	 */
569
+	protected function _before_page_setup()
570
+	{
571
+		// default is to do nothing
572
+	}
573
+
574
+
575
+	/**
576
+	 * Makes sure any things that need to be loaded early get handled.
577
+	 * We also escape early here if the page requested doesn't match the object.
578
+	 *
579
+	 * @final
580
+	 * @return void
581
+	 * @throws EE_Error
582
+	 * @throws InvalidArgumentException
583
+	 * @throws ReflectionException
584
+	 * @throws InvalidDataTypeException
585
+	 * @throws InvalidInterfaceException
586
+	 */
587
+	final protected function _page_setup()
588
+	{
589
+		// requires?
590
+		// admin_init stuff - global - we're setting this REALLY early
591
+		// so if EE_Admin pages have to hook into other WP pages they can.
592
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
593
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
594
+		// next verify if we need to load anything...
595
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
596
+		$this->page_folder   = strtolower(
597
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
598
+		);
599
+		global $ee_menu_slugs;
600
+		$ee_menu_slugs = (array) $ee_menu_slugs;
601
+		if (
602
+			! $this->request->isAjax()
603
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
604
+		) {
605
+			return;
606
+		}
607
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
608
+		// we need to copy the action from the second to the first
609
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
610
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
611
+		$action     = $action !== '-1' ? $action : $action2;
612
+		$req_action = $action !== '-1' ? $action : 'default';
613
+
614
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
615
+		// then let's use the route as the action.
616
+		// This covers cases where we're coming in from a list table that isn't on the default route.
617
+		$route = $this->request->getRequestParam('route');
618
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
619
+			? $route
620
+			: $req_action;
621
+
622
+		$this->_current_view = $this->_req_action;
623
+		$this->_req_nonce    = $this->_req_action . '_nonce';
624
+		$this->_define_page_props();
625
+		$this->_current_page_view_url = add_query_arg(
626
+			['page' => $this->_current_page, 'action' => $this->_current_view],
627
+			$this->_admin_base_url
628
+		);
629
+		// default things
630
+		$this->_default_espresso_metaboxes = [
631
+			'_espresso_news_post_box',
632
+			'_espresso_links_post_box',
633
+			'_espresso_ratings_request',
634
+			'_espresso_sponsors_post_box',
635
+		];
636
+		// set page configs
637
+		$this->_set_page_routes();
638
+		$this->_set_page_config();
639
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
640
+		if ($this->request->requestParamIsSet('wp_referer')) {
641
+			$wp_referer = $this->request->getRequestParam('wp_referer');
642
+			if ($wp_referer) {
643
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
644
+			}
645
+		}
646
+		// for caffeinated and other extended functionality.
647
+		//  If there is a _extend_page_config method
648
+		// then let's run that to modify the all the various page configuration arrays
649
+		if (method_exists($this, '_extend_page_config')) {
650
+			$this->_extend_page_config();
651
+		}
652
+		// for CPT and other extended functionality.
653
+		// If there is an _extend_page_config_for_cpt
654
+		// then let's run that to modify all the various page configuration arrays.
655
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
656
+			$this->_extend_page_config_for_cpt();
657
+		}
658
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
659
+		$this->_page_routes = apply_filters(
660
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
661
+			$this->_page_routes,
662
+			$this
663
+		);
664
+		$this->_page_config = apply_filters(
665
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
666
+			$this->_page_config,
667
+			$this
668
+		);
669
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
670
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
671
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
672
+			add_action(
673
+				'AHEE__EE_Admin_Page__route_admin_request',
674
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
675
+				10,
676
+				2
677
+			);
678
+		}
679
+		// next route only if routing enabled
680
+		if ($this->_routing && ! $this->request->isAjax()) {
681
+			$this->_verify_routes();
682
+			// next let's just check user_access and kill if no access
683
+			$this->check_user_access();
684
+			if ($this->_is_UI_request) {
685
+				// admin_init stuff - global, all views for this page class, specific view
686
+				add_action('admin_init', [$this, 'admin_init'], 10);
687
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
688
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
689
+				}
690
+			} else {
691
+				// hijack regular WP loading and route admin request immediately
692
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
693
+				$this->route_admin_request();
694
+			}
695
+		}
696
+	}
697
+
698
+
699
+	/**
700
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
701
+	 *
702
+	 * @return void
703
+	 * @throws EE_Error
704
+	 */
705
+	private function _do_other_page_hooks()
706
+	{
707
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
708
+		foreach ($registered_pages as $page) {
709
+			// now let's setup the file name and class that should be present
710
+			$classname = str_replace('.class.php', '', $page);
711
+			// autoloaders should take care of loading file
712
+			if (! class_exists($classname)) {
713
+				$error_msg[] = sprintf(
714
+					esc_html__(
715
+						'Something went wrong with loading the %s admin hooks page.',
716
+						'event_espresso'
717
+					),
718
+					$page
719
+				);
720
+				$error_msg[] = $error_msg[0]
721
+							   . "\r\n"
722
+							   . sprintf(
723
+								   esc_html__(
724
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
725
+									   'event_espresso'
726
+								   ),
727
+								   $page,
728
+								   '<br />',
729
+								   '<strong>' . $classname . '</strong>'
730
+							   );
731
+				throw new EE_Error(implode('||', $error_msg));
732
+			}
733
+			// notice we are passing the instance of this class to the hook object.
734
+			$this->loader->getShared($classname, [$this]);
735
+		}
736
+	}
737
+
738
+
739
+	/**
740
+	 * @throws ReflectionException
741
+	 * @throws EE_Error
742
+	 */
743
+	public function load_page_dependencies()
744
+	{
745
+		try {
746
+			$this->_load_page_dependencies();
747
+		} catch (EE_Error $e) {
748
+			$e->get_error();
749
+		}
750
+	}
751
+
752
+
753
+	/**
754
+	 * load_page_dependencies
755
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
756
+	 *
757
+	 * @return void
758
+	 * @throws DomainException
759
+	 * @throws EE_Error
760
+	 * @throws InvalidArgumentException
761
+	 * @throws InvalidDataTypeException
762
+	 * @throws InvalidInterfaceException
763
+	 */
764
+	protected function _load_page_dependencies()
765
+	{
766
+		// let's set the current_screen and screen options to override what WP set
767
+		$this->_current_screen = get_current_screen();
768
+		// load admin_notices - global, page class, and view specific
769
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
770
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
771
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
772
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
773
+		}
774
+		// load network admin_notices - global, page class, and view specific
775
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
776
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
777
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
778
+		}
779
+		// this will save any per_page screen options if they are present
780
+		$this->_set_per_page_screen_options();
781
+		// setup list table properties
782
+		$this->_set_list_table();
783
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
784
+		// However in some cases the metaboxes will need to be added within a route handling callback.
785
+		$this->_add_registered_meta_boxes();
786
+		$this->_add_screen_columns();
787
+		// add screen options - global, page child class, and view specific
788
+		$this->_add_global_screen_options();
789
+		$this->_add_screen_options();
790
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
791
+		if (method_exists($this, $add_screen_options)) {
792
+			$this->{$add_screen_options}();
793
+		}
794
+		// add help tab(s) - set via page_config and qtips.
795
+		$this->_add_help_tabs();
796
+		$this->_add_qtips();
797
+		// add feature_pointers - global, page child class, and view specific
798
+		$this->_add_feature_pointers();
799
+		$this->_add_global_feature_pointers();
800
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
801
+		if (method_exists($this, $add_feature_pointer)) {
802
+			$this->{$add_feature_pointer}();
803
+		}
804
+		// enqueue scripts/styles - global, page class, and view specific
805
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
806
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
807
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
808
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
809
+		}
810
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
811
+		// admin_print_footer_scripts - global, page child class, and view specific.
812
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
813
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
814
+		// is a good use case. Notice the late priority we're giving these
815
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
816
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
817
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
818
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
819
+		}
820
+		// admin footer scripts
821
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
822
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
823
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
824
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
825
+		}
826
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
827
+		// targeted hook
828
+		do_action(
829
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
830
+		);
831
+	}
832
+
833
+
834
+	/**
835
+	 * _set_defaults
836
+	 * This sets some global defaults for class properties.
837
+	 */
838
+	private function _set_defaults()
839
+	{
840
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
841
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
842
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
843
+		$this->_page_config          = $this->_default_route_query_args = [];
844
+		$this->_default_nav_tab_name = 'overview';
845
+		// init template args
846
+		$this->_template_args = [
847
+			'admin_page_header'  => '',
848
+			'admin_page_content' => '',
849
+			'post_body_content'  => '',
850
+			'before_list_table'  => '',
851
+			'after_list_table'   => '',
852
+		];
853
+	}
854
+
855
+
856
+	/**
857
+	 * route_admin_request
858
+	 *
859
+	 * @return void
860
+	 * @throws InvalidArgumentException
861
+	 * @throws InvalidInterfaceException
862
+	 * @throws InvalidDataTypeException
863
+	 * @throws EE_Error
864
+	 * @throws ReflectionException
865
+	 * @see    _route_admin_request()
866
+	 */
867
+	public function route_admin_request()
868
+	{
869
+		try {
870
+			$this->_route_admin_request();
871
+		} catch (EE_Error $e) {
872
+			$e->get_error();
873
+		}
874
+	}
875
+
876
+
877
+	public function set_wp_page_slug($wp_page_slug)
878
+	{
879
+		$this->_wp_page_slug = $wp_page_slug;
880
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
881
+		if (is_network_admin()) {
882
+			$this->_wp_page_slug .= '-network';
883
+		}
884
+	}
885
+
886
+
887
+	/**
888
+	 * _verify_routes
889
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
890
+	 * we know if we need to drop out.
891
+	 *
892
+	 * @return bool
893
+	 * @throws EE_Error
894
+	 */
895
+	protected function _verify_routes()
896
+	{
897
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
898
+		if (! $this->_current_page && ! $this->request->isAjax()) {
899
+			return false;
900
+		}
901
+		$this->_route = false;
902
+		// check that the page_routes array is not empty
903
+		if (empty($this->_page_routes)) {
904
+			// user error msg
905
+			$error_msg = sprintf(
906
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
907
+				$this->_admin_page_title
908
+			);
909
+			// developer error msg
910
+			$error_msg .= '||' . $error_msg
911
+						  . esc_html__(
912
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
913
+							  'event_espresso'
914
+						  );
915
+			throw new EE_Error($error_msg);
916
+		}
917
+		// and that the requested page route exists
918
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
919
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
920
+			$this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
921
+		} else {
922
+			// user error msg
923
+			$error_msg = sprintf(
924
+				esc_html__(
925
+					'The requested page route does not exist for the %s admin page.',
926
+					'event_espresso'
927
+				),
928
+				$this->_admin_page_title
929
+			);
930
+			// developer error msg
931
+			$error_msg .= '||' . $error_msg
932
+						  . sprintf(
933
+							  esc_html__(
934
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
935
+								  'event_espresso'
936
+							  ),
937
+							  $this->_req_action
938
+						  );
939
+			throw new EE_Error($error_msg);
940
+		}
941
+		// and that a default route exists
942
+		if (! array_key_exists('default', $this->_page_routes)) {
943
+			// user error msg
944
+			$error_msg = sprintf(
945
+				esc_html__(
946
+					'A default page route has not been set for the % admin page.',
947
+					'event_espresso'
948
+				),
949
+				$this->_admin_page_title
950
+			);
951
+			// developer error msg
952
+			$error_msg .= '||' . $error_msg
953
+						  . esc_html__(
954
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
955
+							  'event_espresso'
956
+						  );
957
+			throw new EE_Error($error_msg);
958
+		}
959
+
960
+		// first lets' catch if the UI request has EVER been set.
961
+		if ($this->_is_UI_request === null) {
962
+			// lets set if this is a UI request or not.
963
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
964
+			// wait a minute... we might have a noheader in the route array
965
+			$this->_is_UI_request = ! (
966
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
967
+			)
968
+				? $this->_is_UI_request
969
+				: false;
970
+		}
971
+		$this->_set_current_labels();
972
+		return true;
973
+	}
974
+
975
+
976
+	/**
977
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
978
+	 *
979
+	 * @param string $route the route name we're verifying
980
+	 * @return bool we'll throw an exception if this isn't a valid route.
981
+	 * @throws EE_Error
982
+	 */
983
+	protected function _verify_route($route)
984
+	{
985
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
986
+			return true;
987
+		}
988
+		// user error msg
989
+		$error_msg = sprintf(
990
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
991
+			$this->_admin_page_title
992
+		);
993
+		// developer error msg
994
+		$error_msg .= '||' . $error_msg
995
+					  . sprintf(
996
+						  esc_html__(
997
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
998
+							  'event_espresso'
999
+						  ),
1000
+						  $route
1001
+					  );
1002
+		throw new EE_Error($error_msg);
1003
+	}
1004
+
1005
+
1006
+	/**
1007
+	 * perform nonce verification
1008
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1009
+	 * using this method (and save retyping!)
1010
+	 *
1011
+	 * @param string $nonce     The nonce sent
1012
+	 * @param string $nonce_ref The nonce reference string (name0)
1013
+	 * @return void
1014
+	 * @throws EE_Error
1015
+	 * @throws InvalidArgumentException
1016
+	 * @throws InvalidDataTypeException
1017
+	 * @throws InvalidInterfaceException
1018
+	 */
1019
+	protected function _verify_nonce($nonce, $nonce_ref)
1020
+	{
1021
+		// verify nonce against expected value
1022
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1023
+			// these are not the droids you are looking for !!!
1024
+			$msg = sprintf(
1025
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1026
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1027
+				'</a>'
1028
+			);
1029
+			if (WP_DEBUG) {
1030
+				$msg .= "\n  ";
1031
+				$msg .= sprintf(
1032
+					esc_html__(
1033
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1034
+						'event_espresso'
1035
+					),
1036
+					__CLASS__
1037
+				);
1038
+			}
1039
+			if (! $this->request->isAjax()) {
1040
+				wp_die($msg);
1041
+			}
1042
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1043
+			$this->_return_json();
1044
+		}
1045
+	}
1046
+
1047
+
1048
+	/**
1049
+	 * _route_admin_request()
1050
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1051
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1052
+	 * in the page routes and then will try to load the corresponding method.
1053
+	 *
1054
+	 * @return void
1055
+	 * @throws EE_Error
1056
+	 * @throws InvalidArgumentException
1057
+	 * @throws InvalidDataTypeException
1058
+	 * @throws InvalidInterfaceException
1059
+	 * @throws ReflectionException
1060
+	 */
1061
+	protected function _route_admin_request()
1062
+	{
1063
+		if (! $this->_is_UI_request) {
1064
+			$this->_verify_routes();
1065
+		}
1066
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1067
+		if ($this->_req_action !== 'default' && $nonce_check) {
1068
+			// set nonce from post data
1069
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1070
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1071
+		}
1072
+		// set the nav_tabs array but ONLY if this is  UI_request
1073
+		if ($this->_is_UI_request) {
1074
+			$this->_set_nav_tabs();
1075
+		}
1076
+		// grab callback function
1077
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1078
+		// check if callback has args
1079
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1080
+		$error_msg = '';
1081
+		// action right before calling route
1082
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1083
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1084
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1085
+		}
1086
+		// right before calling the route, let's clean the _wp_http_referer
1087
+		$this->request->setServerParam(
1088
+			'REQUEST_URI',
1089
+			remove_query_arg(
1090
+				'_wp_http_referer',
1091
+				wp_unslash($this->request->getServerParam('REQUEST_URI'))
1092
+			)
1093
+		);
1094
+		if (! empty($func)) {
1095
+			if (is_array($func)) {
1096
+				[$class, $method] = $func;
1097
+			} elseif (strpos($func, '::') !== false) {
1098
+				[$class, $method] = explode('::', $func);
1099
+			} else {
1100
+				$class  = $this;
1101
+				$method = $func;
1102
+			}
1103
+			if (! (is_object($class) && $class === $this)) {
1104
+				// send along this admin page object for access by addons.
1105
+				$args['admin_page_object'] = $this;
1106
+			}
1107
+			if (
1108
+				// is it a method on a class that doesn't work?
1109
+				(
1110
+					(
1111
+						method_exists($class, $method)
1112
+						&& call_user_func_array([$class, $method], $args) === false
1113
+					)
1114
+					&& (
1115
+						// is it a standalone function that doesn't work?
1116
+						function_exists($method)
1117
+						&& call_user_func_array(
1118
+							$func,
1119
+							array_merge(['admin_page_object' => $this], $args)
1120
+						) === false
1121
+					)
1122
+				)
1123
+				|| (
1124
+					// is it neither a class method NOR a standalone function?
1125
+					! method_exists($class, $method)
1126
+					&& ! function_exists($method)
1127
+				)
1128
+			) {
1129
+				// user error msg
1130
+				$error_msg = esc_html__(
1131
+					'An error occurred. The  requested page route could not be found.',
1132
+					'event_espresso'
1133
+				);
1134
+				// developer error msg
1135
+				$error_msg .= '||';
1136
+				$error_msg .= sprintf(
1137
+					esc_html__(
1138
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1139
+						'event_espresso'
1140
+					),
1141
+					$method
1142
+				);
1143
+			}
1144
+			if (! empty($error_msg)) {
1145
+				throw new EE_Error($error_msg);
1146
+			}
1147
+		}
1148
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1149
+		// then we need to reset the routing properties to the new route.
1150
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1151
+		if (
1152
+			$this->_is_UI_request === false
1153
+			&& is_array($this->_route)
1154
+			&& ! empty($this->_route['headers_sent_route'])
1155
+		) {
1156
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1157
+		}
1158
+	}
1159
+
1160
+
1161
+	/**
1162
+	 * This method just allows the resetting of page properties in the case where a no headers
1163
+	 * route redirects to a headers route in its route config.
1164
+	 *
1165
+	 * @param string $new_route New (non header) route to redirect to.
1166
+	 * @return   void
1167
+	 * @throws ReflectionException
1168
+	 * @throws InvalidArgumentException
1169
+	 * @throws InvalidInterfaceException
1170
+	 * @throws InvalidDataTypeException
1171
+	 * @throws EE_Error
1172
+	 * @since   4.3.0
1173
+	 */
1174
+	protected function _reset_routing_properties($new_route)
1175
+	{
1176
+		$this->_is_UI_request = true;
1177
+		// now we set the current route to whatever the headers_sent_route is set at
1178
+		$this->request->setRequestParam('action', $new_route);
1179
+		// rerun page setup
1180
+		$this->_page_setup();
1181
+	}
1182
+
1183
+
1184
+	/**
1185
+	 * _add_query_arg
1186
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1187
+	 *(internally just uses EEH_URL's function with the same name)
1188
+	 *
1189
+	 * @param array  $args
1190
+	 * @param string $url
1191
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1192
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1193
+	 *                                        Example usage: If the current page is:
1194
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1195
+	 *                                        &action=default&event_id=20&month_range=March%202015
1196
+	 *                                        &_wpnonce=5467821
1197
+	 *                                        and you call:
1198
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1199
+	 *                                        array(
1200
+	 *                                        'action' => 'resend_something',
1201
+	 *                                        'page=>espresso_registrations'
1202
+	 *                                        ),
1203
+	 *                                        $some_url,
1204
+	 *                                        true
1205
+	 *                                        );
1206
+	 *                                        It will produce a url in this structure:
1207
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1208
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1209
+	 *                                        month_range]=March%202015
1210
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1211
+	 * @return string
1212
+	 */
1213
+	public static function add_query_args_and_nonce(
1214
+		$args = [],
1215
+		$url = '',
1216
+		$sticky = false,
1217
+		$exclude_nonce = false
1218
+	) {
1219
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1220
+		if ($sticky) {
1221
+			/** @var RequestInterface $request */
1222
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1223
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1224
+			foreach ($request->requestParams() as $key => $value) {
1225
+				// do not add nonces
1226
+				if (strpos($key, 'nonce') !== false) {
1227
+					continue;
1228
+				}
1229
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1230
+			}
1231
+		}
1232
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * This returns a generated link that will load the related help tab.
1238
+	 *
1239
+	 * @param string $help_tab_id the id for the connected help tab
1240
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1241
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1242
+	 * @return string              generated link
1243
+	 * @uses EEH_Template::get_help_tab_link()
1244
+	 */
1245
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1246
+	{
1247
+		return EEH_Template::get_help_tab_link(
1248
+			$help_tab_id,
1249
+			$this->page_slug,
1250
+			$this->_req_action,
1251
+			$icon_style,
1252
+			$help_text
1253
+		);
1254
+	}
1255
+
1256
+
1257
+	/**
1258
+	 * _add_help_tabs
1259
+	 * Note child classes define their help tabs within the page_config array.
1260
+	 *
1261
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1262
+	 * @return void
1263
+	 * @throws DomainException
1264
+	 * @throws EE_Error
1265
+	 * @throws ReflectionException
1266
+	 */
1267
+	protected function _add_help_tabs()
1268
+	{
1269
+		if (isset($this->_page_config[ $this->_req_action ])) {
1270
+			$config = $this->_page_config[ $this->_req_action ];
1271
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1272
+			if (is_array($config) && isset($config['help_sidebar'])) {
1273
+				// check that the callback given is valid
1274
+				if (! method_exists($this, $config['help_sidebar'])) {
1275
+					throw new EE_Error(
1276
+						sprintf(
1277
+							esc_html__(
1278
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1279
+								'event_espresso'
1280
+							),
1281
+							$config['help_sidebar'],
1282
+							get_class($this)
1283
+						)
1284
+					);
1285
+				}
1286
+				$content = apply_filters(
1287
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1288
+					$this->{$config['help_sidebar']}()
1289
+				);
1290
+				$this->_current_screen->set_help_sidebar($content);
1291
+			}
1292
+			if (! isset($config['help_tabs'])) {
1293
+				return;
1294
+			} //no help tabs for this route
1295
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1296
+				// we're here so there ARE help tabs!
1297
+				// make sure we've got what we need
1298
+				if (! isset($cfg['title'])) {
1299
+					throw new EE_Error(
1300
+						esc_html__(
1301
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1302
+							'event_espresso'
1303
+						)
1304
+					);
1305
+				}
1306
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1307
+					throw new EE_Error(
1308
+						esc_html__(
1309
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1310
+							'event_espresso'
1311
+						)
1312
+					);
1313
+				}
1314
+				// first priority goes to content.
1315
+				if (! empty($cfg['content'])) {
1316
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1317
+					// second priority goes to filename
1318
+				} elseif (! empty($cfg['filename'])) {
1319
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1320
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1321
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1322
+															 . basename($this->_get_dir())
1323
+															 . '/help_tabs/'
1324
+															 . $cfg['filename']
1325
+															 . '.help_tab.php' : $file_path;
1326
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1327
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1328
+						EE_Error::add_error(
1329
+							sprintf(
1330
+								esc_html__(
1331
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1332
+									'event_espresso'
1333
+								),
1334
+								$tab_id,
1335
+								key($config),
1336
+								$file_path
1337
+							),
1338
+							__FILE__,
1339
+							__FUNCTION__,
1340
+							__LINE__
1341
+						);
1342
+						return;
1343
+					}
1344
+					$template_args['admin_page_obj'] = $this;
1345
+					$content                         = EEH_Template::display_template(
1346
+						$file_path,
1347
+						$template_args,
1348
+						true
1349
+					);
1350
+				} else {
1351
+					$content = '';
1352
+				}
1353
+				// check if callback is valid
1354
+				if (
1355
+					empty($content)
1356
+					&& (
1357
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1358
+					)
1359
+				) {
1360
+					EE_Error::add_error(
1361
+						sprintf(
1362
+							esc_html__(
1363
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1364
+								'event_espresso'
1365
+							),
1366
+							$cfg['title']
1367
+						),
1368
+						__FILE__,
1369
+						__FUNCTION__,
1370
+						__LINE__
1371
+					);
1372
+					return;
1373
+				}
1374
+				// setup config array for help tab method
1375
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1376
+				$_ht = [
1377
+					'id'       => $id,
1378
+					'title'    => $cfg['title'],
1379
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1380
+					'content'  => $content,
1381
+				];
1382
+				$this->_current_screen->add_help_tab($_ht);
1383
+			}
1384
+		}
1385
+	}
1386
+
1387
+
1388
+	/**
1389
+	 * This simply sets up any qtips that have been defined in the page config
1390
+	 *
1391
+	 * @return void
1392
+	 * @throws ReflectionException
1393
+	 * @throws EE_Error
1394
+	 */
1395
+	protected function _add_qtips()
1396
+	{
1397
+		if (isset($this->_route_config['qtips'])) {
1398
+			$qtips = (array) $this->_route_config['qtips'];
1399
+			// load qtip loader
1400
+			$path = [
1401
+				$this->_get_dir() . '/qtips/',
1402
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1403
+			];
1404
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1405
+		}
1406
+	}
1407
+
1408
+
1409
+	/**
1410
+	 * _set_nav_tabs
1411
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1412
+	 * wish to add additional tabs or modify accordingly.
1413
+	 *
1414
+	 * @return void
1415
+	 * @throws InvalidArgumentException
1416
+	 * @throws InvalidInterfaceException
1417
+	 * @throws InvalidDataTypeException
1418
+	 */
1419
+	protected function _set_nav_tabs()
1420
+	{
1421
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1422
+		$i = 0;
1423
+		foreach ($this->_page_config as $slug => $config) {
1424
+			if (! is_array($config) || empty($config['nav'])) {
1425
+				continue;
1426
+			}
1427
+			// no nav tab for this config
1428
+			// check for persistent flag
1429
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1430
+				// nav tab is only to appear when route requested.
1431
+				continue;
1432
+			}
1433
+			if (! $this->check_user_access($slug, true)) {
1434
+				// no nav tab because current user does not have access.
1435
+				continue;
1436
+			}
1437
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1438
+			$this->_nav_tabs[ $slug ] = [
1439
+				'url'       => isset($config['nav']['url'])
1440
+					? $config['nav']['url']
1441
+					: EE_Admin_Page::add_query_args_and_nonce(
1442
+						['action' => $slug],
1443
+						$this->_admin_base_url
1444
+					),
1445
+				'link_text' => isset($config['nav']['label'])
1446
+					? $config['nav']['label']
1447
+					: ucwords(
1448
+						str_replace('_', ' ', $slug)
1449
+					),
1450
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1451
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1452
+			];
1453
+			$i++;
1454
+		}
1455
+		// if $this->_nav_tabs is empty then lets set the default
1456
+		if (empty($this->_nav_tabs)) {
1457
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1458
+				'url'       => $this->_admin_base_url,
1459
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1460
+				'css_class' => 'nav-tab-active',
1461
+				'order'     => 10,
1462
+			];
1463
+		}
1464
+		// now let's sort the tabs according to order
1465
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * _set_current_labels
1471
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1472
+	 * property array
1473
+	 *
1474
+	 * @return void
1475
+	 */
1476
+	private function _set_current_labels()
1477
+	{
1478
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1479
+			foreach ($this->_route_config['labels'] as $label => $text) {
1480
+				if (is_array($text)) {
1481
+					foreach ($text as $sublabel => $subtext) {
1482
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1483
+					}
1484
+				} else {
1485
+					$this->_labels[ $label ] = $text;
1486
+				}
1487
+			}
1488
+		}
1489
+	}
1490
+
1491
+
1492
+	/**
1493
+	 *        verifies user access for this admin page
1494
+	 *
1495
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1496
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1497
+	 *                               return false if verify fail.
1498
+	 * @return bool
1499
+	 * @throws InvalidArgumentException
1500
+	 * @throws InvalidDataTypeException
1501
+	 * @throws InvalidInterfaceException
1502
+	 */
1503
+	public function check_user_access($route_to_check = '', $verify_only = false)
1504
+	{
1505
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1506
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1507
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1508
+						  && is_array(
1509
+							  $this->_page_routes[ $route_to_check ]
1510
+						  )
1511
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1512
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1513
+		if (empty($capability) && empty($route_to_check)) {
1514
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1515
+				: $this->_route['capability'];
1516
+		} else {
1517
+			$capability = empty($capability) ? 'manage_options' : $capability;
1518
+		}
1519
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1520
+		if (
1521
+			! $this->request->isAjax()
1522
+			&& (
1523
+				! function_exists('is_admin')
1524
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1525
+					$capability,
1526
+					$this->page_slug
1527
+					. '_'
1528
+					. $route_to_check,
1529
+					$id
1530
+				)
1531
+			)
1532
+		) {
1533
+			if ($verify_only) {
1534
+				return false;
1535
+			}
1536
+			if (is_user_logged_in()) {
1537
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1538
+			} else {
1539
+				return false;
1540
+			}
1541
+		}
1542
+		return true;
1543
+	}
1544
+
1545
+
1546
+	/**
1547
+	 * admin_init_global
1548
+	 * This runs all the code that we want executed within the WP admin_init hook.
1549
+	 * This method executes for ALL EE Admin pages.
1550
+	 *
1551
+	 * @return void
1552
+	 */
1553
+	public function admin_init_global()
1554
+	{
1555
+	}
1556
+
1557
+
1558
+	/**
1559
+	 * wp_loaded_global
1560
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1561
+	 * EE_Admin page and will execute on every EE Admin Page load
1562
+	 *
1563
+	 * @return void
1564
+	 */
1565
+	public function wp_loaded()
1566
+	{
1567
+	}
1568
+
1569
+
1570
+	/**
1571
+	 * admin_notices
1572
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1573
+	 * ALL EE_Admin pages.
1574
+	 *
1575
+	 * @return void
1576
+	 */
1577
+	public function admin_notices_global()
1578
+	{
1579
+		$this->_display_no_javascript_warning();
1580
+		$this->_display_espresso_notices();
1581
+	}
1582
+
1583
+
1584
+	public function network_admin_notices_global()
1585
+	{
1586
+		$this->_display_no_javascript_warning();
1587
+		$this->_display_espresso_notices();
1588
+	}
1589
+
1590
+
1591
+	/**
1592
+	 * admin_footer_scripts_global
1593
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1594
+	 * will apply on ALL EE_Admin pages.
1595
+	 *
1596
+	 * @return void
1597
+	 */
1598
+	public function admin_footer_scripts_global()
1599
+	{
1600
+		$this->_add_admin_page_ajax_loading_img();
1601
+		$this->_add_admin_page_overlay();
1602
+		// if metaboxes are present we need to add the nonce field
1603
+		if (
1604
+			isset($this->_route_config['metaboxes'])
1605
+			|| isset($this->_route_config['list_table'])
1606
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1607
+		) {
1608
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1609
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1610
+		}
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 * admin_footer_global
1616
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1617
+	 * This particular method will apply on ALL EE_Admin Pages.
1618
+	 *
1619
+	 * @return void
1620
+	 */
1621
+	public function admin_footer_global()
1622
+	{
1623
+		// dialog container for dialog helper
1624
+		echo '
1625 1625
         <div class="ee-admin-dialog-container auto-hide hidden">
1626 1626
             <div class="ee-notices"></div>
1627 1627
             <div class="ee-admin-dialog-container-inner-content"></div>
1628 1628
         </div>
1629 1629
         ';
1630 1630
 
1631
-        // current set timezone for timezone js
1632
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1633
-    }
1634
-
1635
-
1636
-    /**
1637
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1638
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1639
-     * help popups then in your templates or your content you set "triggers" for the content using the
1640
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1641
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1642
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1643
-     * for the
1644
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1645
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1646
-     *    'help_trigger_id' => array(
1647
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1648
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1649
-     *    )
1650
-     * );
1651
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1652
-     *
1653
-     * @param array $help_array
1654
-     * @param bool  $display
1655
-     * @return string content
1656
-     * @throws DomainException
1657
-     * @throws EE_Error
1658
-     */
1659
-    protected function _set_help_popup_content($help_array = [], $display = false)
1660
-    {
1661
-        $content    = '';
1662
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1663
-        // loop through the array and setup content
1664
-        foreach ($help_array as $trigger => $help) {
1665
-            // make sure the array is setup properly
1666
-            if (! isset($help['title'], $help['content'])) {
1667
-                throw new EE_Error(
1668
-                    esc_html__(
1669
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1670
-                        'event_espresso'
1671
-                    )
1672
-                );
1673
-            }
1674
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1675
-            $template_args = [
1676
-                'help_popup_id'      => $trigger,
1677
-                'help_popup_title'   => $help['title'],
1678
-                'help_popup_content' => $help['content'],
1679
-            ];
1680
-            $content       .= EEH_Template::display_template(
1681
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1682
-                $template_args,
1683
-                true
1684
-            );
1685
-        }
1686
-        if ($display) {
1687
-            echo $content; // already escaped
1688
-            return '';
1689
-        }
1690
-        return $content;
1691
-    }
1692
-
1693
-
1694
-    /**
1695
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1696
-     *
1697
-     * @return array properly formatted array for help popup content
1698
-     * @throws EE_Error
1699
-     */
1700
-    private function _get_help_content()
1701
-    {
1702
-        // what is the method we're looking for?
1703
-        $method_name = '_help_popup_content_' . $this->_req_action;
1704
-        // if method doesn't exist let's get out.
1705
-        if (! method_exists($this, $method_name)) {
1706
-            return [];
1707
-        }
1708
-        // k we're good to go let's retrieve the help array
1709
-        $help_array = $this->{$method_name}();
1710
-        // make sure we've got an array!
1711
-        if (! is_array($help_array)) {
1712
-            throw new EE_Error(
1713
-                esc_html__(
1714
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1715
-                    'event_espresso'
1716
-                )
1717
-            );
1718
-        }
1719
-        return $help_array;
1720
-    }
1721
-
1722
-
1723
-    /**
1724
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1725
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1726
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1727
-     *
1728
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1729
-     * @param boolean $display    if false then we return the trigger string
1730
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1731
-     * @return string
1732
-     * @throws DomainException
1733
-     * @throws EE_Error
1734
-     */
1735
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1736
-    {
1737
-        if ($this->request->isAjax()) {
1738
-            return '';
1739
-        }
1740
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1741
-        $help_array   = $this->_get_help_content();
1742
-        $help_content = '';
1743
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1744
-            $help_array[ $trigger_id ] = [
1745
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1746
-                'content' => esc_html__(
1747
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1748
-                    'event_espresso'
1749
-                ),
1750
-            ];
1751
-            $help_content = $this->_set_help_popup_content($help_array);
1752
-        }
1753
-        // let's setup the trigger
1754
-        $content = '<a class="ee-dialog" href="?height='
1755
-                   . esc_attr($dimensions[0])
1756
-                   . '&width='
1757
-                   . esc_attr($dimensions[1])
1758
-                   . '&inlineId='
1759
-                   . esc_attr($trigger_id)
1760
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1761
-        $content .= $help_content;
1762
-        if ($display) {
1763
-            echo $content; // already escaped
1764
-            return '';
1765
-        }
1766
-        return $content;
1767
-    }
1768
-
1769
-
1770
-    /**
1771
-     * _add_global_screen_options
1772
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1773
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1774
-     *
1775
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1776
-     *         see also WP_Screen object documents...
1777
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1778
-     * @abstract
1779
-     * @return void
1780
-     */
1781
-    private function _add_global_screen_options()
1782
-    {
1783
-    }
1784
-
1785
-
1786
-    /**
1787
-     * _add_global_feature_pointers
1788
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1789
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1790
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1791
-     *
1792
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1793
-     *         extended) also see:
1794
-     * @link   http://eamann.com/tech/wordpress-portland/
1795
-     * @abstract
1796
-     * @return void
1797
-     */
1798
-    private function _add_global_feature_pointers()
1799
-    {
1800
-    }
1801
-
1802
-
1803
-    /**
1804
-     * load_global_scripts_styles
1805
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1806
-     *
1807
-     * @return void
1808
-     */
1809
-    public function load_global_scripts_styles()
1810
-    {
1811
-        // add debugging styles
1812
-        if (WP_DEBUG) {
1813
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1814
-        }
1815
-        // taking care of metaboxes
1816
-        if (
1817
-            empty($this->_cpt_route)
1818
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1819
-        ) {
1820
-            wp_enqueue_script('dashboard');
1821
-        }
1822
-
1823
-        // LOCALIZED DATA
1824
-        // localize script for ajax lazy loading
1825
-        wp_localize_script(
1826
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1827
-            'eeLazyLoadingContainers',
1828
-            apply_filters(
1829
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1830
-                ['espresso_news_post_box_content']
1831
-            )
1832
-        );
1833
-        add_filter(
1834
-            'admin_body_class',
1835
-            function ($classes) {
1836
-                if (strpos($classes, 'espresso-admin') === false) {
1837
-                    $classes .= ' espresso-admin';
1838
-                }
1839
-                return $classes;
1840
-            }
1841
-        );
1842
-    }
1843
-
1844
-
1845
-    /**
1846
-     *        admin_footer_scripts_eei18n_js_strings
1847
-     *
1848
-     * @return        void
1849
-     */
1850
-    public function admin_footer_scripts_eei18n_js_strings()
1851
-    {
1852
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1853
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1854
-            __(
1855
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1856
-                'event_espresso'
1857
-            )
1858
-        );
1859
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1860
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1861
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1862
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1863
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1864
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1865
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1866
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1867
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1868
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1869
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1870
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1871
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1872
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1873
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1874
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1875
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1876
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1877
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1878
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1879
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1880
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1881
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1882
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1883
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1884
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1885
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1886
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1887
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1888
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1889
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1890
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1891
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1892
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1893
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1894
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1895
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1896
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     *        load enhanced xdebug styles for ppl with failing eyesight
1902
-     *
1903
-     * @return        void
1904
-     */
1905
-    public function add_xdebug_style()
1906
-    {
1907
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1908
-    }
1909
-
1910
-
1911
-    /************************/
1912
-    /** LIST TABLE METHODS **/
1913
-    /************************/
1914
-    /**
1915
-     * this sets up the list table if the current view requires it.
1916
-     *
1917
-     * @return void
1918
-     * @throws EE_Error
1919
-     * @throws InvalidArgumentException
1920
-     * @throws InvalidDataTypeException
1921
-     * @throws InvalidInterfaceException
1922
-     */
1923
-    protected function _set_list_table()
1924
-    {
1925
-        // first is this a list_table view?
1926
-        if (! isset($this->_route_config['list_table'])) {
1927
-            return;
1928
-        } //not a list_table view so get out.
1929
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
1930
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1931
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1932
-            // user error msg
1933
-            $error_msg = esc_html__(
1934
-                'An error occurred. The requested list table views could not be found.',
1935
-                'event_espresso'
1936
-            );
1937
-            // developer error msg
1938
-            $error_msg .= '||'
1939
-                          . sprintf(
1940
-                              esc_html__(
1941
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1942
-                                  'event_espresso'
1943
-                              ),
1944
-                              $this->_req_action,
1945
-                              $list_table_view
1946
-                          );
1947
-            throw new EE_Error($error_msg);
1948
-        }
1949
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1950
-        $this->_views = apply_filters(
1951
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1952
-            $this->_views
1953
-        );
1954
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1955
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1956
-        $this->_set_list_table_view();
1957
-        $this->_set_list_table_object();
1958
-    }
1959
-
1960
-
1961
-    /**
1962
-     * set current view for List Table
1963
-     *
1964
-     * @return void
1965
-     */
1966
-    protected function _set_list_table_view()
1967
-    {
1968
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1969
-        $status = $this->request->getRequestParam('status', null, 'key');
1970
-        $this->_view = $status && array_key_exists($status, $this->_views)
1971
-            ? $status
1972
-            : $this->_view;
1973
-    }
1974
-
1975
-
1976
-    /**
1977
-     * _set_list_table_object
1978
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1979
-     *
1980
-     * @throws InvalidInterfaceException
1981
-     * @throws InvalidArgumentException
1982
-     * @throws InvalidDataTypeException
1983
-     * @throws EE_Error
1984
-     * @throws InvalidInterfaceException
1985
-     */
1986
-    protected function _set_list_table_object()
1987
-    {
1988
-        if (isset($this->_route_config['list_table'])) {
1989
-            if (! class_exists($this->_route_config['list_table'])) {
1990
-                throw new EE_Error(
1991
-                    sprintf(
1992
-                        esc_html__(
1993
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1994
-                            'event_espresso'
1995
-                        ),
1996
-                        $this->_route_config['list_table'],
1997
-                        get_class($this)
1998
-                    )
1999
-                );
2000
-            }
2001
-            $this->_list_table_object = $this->loader->getShared(
2002
-                $this->_route_config['list_table'],
2003
-                [$this]
2004
-            );
2005
-        }
2006
-    }
2007
-
2008
-
2009
-    /**
2010
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2011
-     *
2012
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2013
-     *                                                    urls.  The array should be indexed by the view it is being
2014
-     *                                                    added to.
2015
-     * @return array
2016
-     */
2017
-    public function get_list_table_view_RLs($extra_query_args = [])
2018
-    {
2019
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2020
-        if (empty($this->_views)) {
2021
-            $this->_views = [];
2022
-        }
2023
-        // cycle thru views
2024
-        foreach ($this->_views as $key => $view) {
2025
-            $query_args = [];
2026
-            // check for current view
2027
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2028
-            $query_args['action']                        = $this->_req_action;
2029
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2030
-            $query_args['status']                        = $view['slug'];
2031
-            // merge any other arguments sent in.
2032
-            if (isset($extra_query_args[ $view['slug'] ])) {
2033
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2034
-                    $query_args[] = $extra_query_arg;
2035
-                }
2036
-            }
2037
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2038
-        }
2039
-        return $this->_views;
2040
-    }
2041
-
2042
-
2043
-    /**
2044
-     * _entries_per_page_dropdown
2045
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2046
-     *
2047
-     * @param int $max_entries total number of rows in the table
2048
-     * @return string
2049
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2050
-     *         WP does it.
2051
-     */
2052
-    protected function _entries_per_page_dropdown($max_entries = 0)
2053
-    {
2054
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2055
-        $values   = [10, 25, 50, 100];
2056
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2057
-        if ($max_entries) {
2058
-            $values[] = $max_entries;
2059
-            sort($values);
2060
-        }
2061
-        $entries_per_page_dropdown = '
1631
+		// current set timezone for timezone js
1632
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1633
+	}
1634
+
1635
+
1636
+	/**
1637
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1638
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1639
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1640
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1641
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1642
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1643
+	 * for the
1644
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1645
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1646
+	 *    'help_trigger_id' => array(
1647
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1648
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1649
+	 *    )
1650
+	 * );
1651
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1652
+	 *
1653
+	 * @param array $help_array
1654
+	 * @param bool  $display
1655
+	 * @return string content
1656
+	 * @throws DomainException
1657
+	 * @throws EE_Error
1658
+	 */
1659
+	protected function _set_help_popup_content($help_array = [], $display = false)
1660
+	{
1661
+		$content    = '';
1662
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1663
+		// loop through the array and setup content
1664
+		foreach ($help_array as $trigger => $help) {
1665
+			// make sure the array is setup properly
1666
+			if (! isset($help['title'], $help['content'])) {
1667
+				throw new EE_Error(
1668
+					esc_html__(
1669
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1670
+						'event_espresso'
1671
+					)
1672
+				);
1673
+			}
1674
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1675
+			$template_args = [
1676
+				'help_popup_id'      => $trigger,
1677
+				'help_popup_title'   => $help['title'],
1678
+				'help_popup_content' => $help['content'],
1679
+			];
1680
+			$content       .= EEH_Template::display_template(
1681
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1682
+				$template_args,
1683
+				true
1684
+			);
1685
+		}
1686
+		if ($display) {
1687
+			echo $content; // already escaped
1688
+			return '';
1689
+		}
1690
+		return $content;
1691
+	}
1692
+
1693
+
1694
+	/**
1695
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1696
+	 *
1697
+	 * @return array properly formatted array for help popup content
1698
+	 * @throws EE_Error
1699
+	 */
1700
+	private function _get_help_content()
1701
+	{
1702
+		// what is the method we're looking for?
1703
+		$method_name = '_help_popup_content_' . $this->_req_action;
1704
+		// if method doesn't exist let's get out.
1705
+		if (! method_exists($this, $method_name)) {
1706
+			return [];
1707
+		}
1708
+		// k we're good to go let's retrieve the help array
1709
+		$help_array = $this->{$method_name}();
1710
+		// make sure we've got an array!
1711
+		if (! is_array($help_array)) {
1712
+			throw new EE_Error(
1713
+				esc_html__(
1714
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1715
+					'event_espresso'
1716
+				)
1717
+			);
1718
+		}
1719
+		return $help_array;
1720
+	}
1721
+
1722
+
1723
+	/**
1724
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1725
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1726
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1727
+	 *
1728
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1729
+	 * @param boolean $display    if false then we return the trigger string
1730
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1731
+	 * @return string
1732
+	 * @throws DomainException
1733
+	 * @throws EE_Error
1734
+	 */
1735
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1736
+	{
1737
+		if ($this->request->isAjax()) {
1738
+			return '';
1739
+		}
1740
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1741
+		$help_array   = $this->_get_help_content();
1742
+		$help_content = '';
1743
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1744
+			$help_array[ $trigger_id ] = [
1745
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1746
+				'content' => esc_html__(
1747
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1748
+					'event_espresso'
1749
+				),
1750
+			];
1751
+			$help_content = $this->_set_help_popup_content($help_array);
1752
+		}
1753
+		// let's setup the trigger
1754
+		$content = '<a class="ee-dialog" href="?height='
1755
+				   . esc_attr($dimensions[0])
1756
+				   . '&width='
1757
+				   . esc_attr($dimensions[1])
1758
+				   . '&inlineId='
1759
+				   . esc_attr($trigger_id)
1760
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1761
+		$content .= $help_content;
1762
+		if ($display) {
1763
+			echo $content; // already escaped
1764
+			return '';
1765
+		}
1766
+		return $content;
1767
+	}
1768
+
1769
+
1770
+	/**
1771
+	 * _add_global_screen_options
1772
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1773
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1774
+	 *
1775
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1776
+	 *         see also WP_Screen object documents...
1777
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1778
+	 * @abstract
1779
+	 * @return void
1780
+	 */
1781
+	private function _add_global_screen_options()
1782
+	{
1783
+	}
1784
+
1785
+
1786
+	/**
1787
+	 * _add_global_feature_pointers
1788
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1789
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1790
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1791
+	 *
1792
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1793
+	 *         extended) also see:
1794
+	 * @link   http://eamann.com/tech/wordpress-portland/
1795
+	 * @abstract
1796
+	 * @return void
1797
+	 */
1798
+	private function _add_global_feature_pointers()
1799
+	{
1800
+	}
1801
+
1802
+
1803
+	/**
1804
+	 * load_global_scripts_styles
1805
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1806
+	 *
1807
+	 * @return void
1808
+	 */
1809
+	public function load_global_scripts_styles()
1810
+	{
1811
+		// add debugging styles
1812
+		if (WP_DEBUG) {
1813
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1814
+		}
1815
+		// taking care of metaboxes
1816
+		if (
1817
+			empty($this->_cpt_route)
1818
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1819
+		) {
1820
+			wp_enqueue_script('dashboard');
1821
+		}
1822
+
1823
+		// LOCALIZED DATA
1824
+		// localize script for ajax lazy loading
1825
+		wp_localize_script(
1826
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1827
+			'eeLazyLoadingContainers',
1828
+			apply_filters(
1829
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1830
+				['espresso_news_post_box_content']
1831
+			)
1832
+		);
1833
+		add_filter(
1834
+			'admin_body_class',
1835
+			function ($classes) {
1836
+				if (strpos($classes, 'espresso-admin') === false) {
1837
+					$classes .= ' espresso-admin';
1838
+				}
1839
+				return $classes;
1840
+			}
1841
+		);
1842
+	}
1843
+
1844
+
1845
+	/**
1846
+	 *        admin_footer_scripts_eei18n_js_strings
1847
+	 *
1848
+	 * @return        void
1849
+	 */
1850
+	public function admin_footer_scripts_eei18n_js_strings()
1851
+	{
1852
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1853
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1854
+			__(
1855
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1856
+				'event_espresso'
1857
+			)
1858
+		);
1859
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1860
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1861
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1862
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1863
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1864
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1865
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1866
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1867
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1868
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1869
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1870
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1871
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1872
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1873
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1874
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1875
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1876
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1877
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1878
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1879
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1880
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1881
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1882
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1883
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1884
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1885
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1886
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1887
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1888
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1889
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1890
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1891
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1892
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1893
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1894
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1895
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1896
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1902
+	 *
1903
+	 * @return        void
1904
+	 */
1905
+	public function add_xdebug_style()
1906
+	{
1907
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1908
+	}
1909
+
1910
+
1911
+	/************************/
1912
+	/** LIST TABLE METHODS **/
1913
+	/************************/
1914
+	/**
1915
+	 * this sets up the list table if the current view requires it.
1916
+	 *
1917
+	 * @return void
1918
+	 * @throws EE_Error
1919
+	 * @throws InvalidArgumentException
1920
+	 * @throws InvalidDataTypeException
1921
+	 * @throws InvalidInterfaceException
1922
+	 */
1923
+	protected function _set_list_table()
1924
+	{
1925
+		// first is this a list_table view?
1926
+		if (! isset($this->_route_config['list_table'])) {
1927
+			return;
1928
+		} //not a list_table view so get out.
1929
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
1930
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
1931
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1932
+			// user error msg
1933
+			$error_msg = esc_html__(
1934
+				'An error occurred. The requested list table views could not be found.',
1935
+				'event_espresso'
1936
+			);
1937
+			// developer error msg
1938
+			$error_msg .= '||'
1939
+						  . sprintf(
1940
+							  esc_html__(
1941
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1942
+								  'event_espresso'
1943
+							  ),
1944
+							  $this->_req_action,
1945
+							  $list_table_view
1946
+						  );
1947
+			throw new EE_Error($error_msg);
1948
+		}
1949
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1950
+		$this->_views = apply_filters(
1951
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1952
+			$this->_views
1953
+		);
1954
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1955
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1956
+		$this->_set_list_table_view();
1957
+		$this->_set_list_table_object();
1958
+	}
1959
+
1960
+
1961
+	/**
1962
+	 * set current view for List Table
1963
+	 *
1964
+	 * @return void
1965
+	 */
1966
+	protected function _set_list_table_view()
1967
+	{
1968
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1969
+		$status = $this->request->getRequestParam('status', null, 'key');
1970
+		$this->_view = $status && array_key_exists($status, $this->_views)
1971
+			? $status
1972
+			: $this->_view;
1973
+	}
1974
+
1975
+
1976
+	/**
1977
+	 * _set_list_table_object
1978
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1979
+	 *
1980
+	 * @throws InvalidInterfaceException
1981
+	 * @throws InvalidArgumentException
1982
+	 * @throws InvalidDataTypeException
1983
+	 * @throws EE_Error
1984
+	 * @throws InvalidInterfaceException
1985
+	 */
1986
+	protected function _set_list_table_object()
1987
+	{
1988
+		if (isset($this->_route_config['list_table'])) {
1989
+			if (! class_exists($this->_route_config['list_table'])) {
1990
+				throw new EE_Error(
1991
+					sprintf(
1992
+						esc_html__(
1993
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1994
+							'event_espresso'
1995
+						),
1996
+						$this->_route_config['list_table'],
1997
+						get_class($this)
1998
+					)
1999
+				);
2000
+			}
2001
+			$this->_list_table_object = $this->loader->getShared(
2002
+				$this->_route_config['list_table'],
2003
+				[$this]
2004
+			);
2005
+		}
2006
+	}
2007
+
2008
+
2009
+	/**
2010
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2011
+	 *
2012
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2013
+	 *                                                    urls.  The array should be indexed by the view it is being
2014
+	 *                                                    added to.
2015
+	 * @return array
2016
+	 */
2017
+	public function get_list_table_view_RLs($extra_query_args = [])
2018
+	{
2019
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2020
+		if (empty($this->_views)) {
2021
+			$this->_views = [];
2022
+		}
2023
+		// cycle thru views
2024
+		foreach ($this->_views as $key => $view) {
2025
+			$query_args = [];
2026
+			// check for current view
2027
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2028
+			$query_args['action']                        = $this->_req_action;
2029
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2030
+			$query_args['status']                        = $view['slug'];
2031
+			// merge any other arguments sent in.
2032
+			if (isset($extra_query_args[ $view['slug'] ])) {
2033
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2034
+					$query_args[] = $extra_query_arg;
2035
+				}
2036
+			}
2037
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2038
+		}
2039
+		return $this->_views;
2040
+	}
2041
+
2042
+
2043
+	/**
2044
+	 * _entries_per_page_dropdown
2045
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2046
+	 *
2047
+	 * @param int $max_entries total number of rows in the table
2048
+	 * @return string
2049
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2050
+	 *         WP does it.
2051
+	 */
2052
+	protected function _entries_per_page_dropdown($max_entries = 0)
2053
+	{
2054
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2055
+		$values   = [10, 25, 50, 100];
2056
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2057
+		if ($max_entries) {
2058
+			$values[] = $max_entries;
2059
+			sort($values);
2060
+		}
2061
+		$entries_per_page_dropdown = '
2062 2062
 			<div id="entries-per-page-dv" class="alignleft actions">
2063 2063
 				<label class="hide-if-no-js">
2064 2064
 					Show
2065 2065
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2066
-        foreach ($values as $value) {
2067
-            if ($value < $max_entries) {
2068
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2069
-                $entries_per_page_dropdown .= '
2066
+		foreach ($values as $value) {
2067
+			if ($value < $max_entries) {
2068
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2069
+				$entries_per_page_dropdown .= '
2070 2070
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2071
-            }
2072
-        }
2073
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2074
-        $entries_per_page_dropdown .= '
2071
+			}
2072
+		}
2073
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2074
+		$entries_per_page_dropdown .= '
2075 2075
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2076
-        $entries_per_page_dropdown .= '
2076
+		$entries_per_page_dropdown .= '
2077 2077
 					</select>
2078 2078
 					entries
2079 2079
 				</label>
2080 2080
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2081 2081
 			</div>
2082 2082
 		';
2083
-        return $entries_per_page_dropdown;
2084
-    }
2085
-
2086
-
2087
-    /**
2088
-     *        _set_search_attributes
2089
-     *
2090
-     * @return        void
2091
-     */
2092
-    public function _set_search_attributes()
2093
-    {
2094
-        $this->_template_args['search']['btn_label'] = sprintf(
2095
-            esc_html__('Search %s', 'event_espresso'),
2096
-            empty($this->_search_btn_label) ? $this->page_label
2097
-                : $this->_search_btn_label
2098
-        );
2099
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2100
-    }
2101
-
2102
-
2103
-
2104
-    /*** END LIST TABLE METHODS **/
2105
-
2106
-
2107
-    /**
2108
-     * _add_registered_metaboxes
2109
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2110
-     *
2111
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2112
-     * @return void
2113
-     * @throws EE_Error
2114
-     */
2115
-    private function _add_registered_meta_boxes()
2116
-    {
2117
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2118
-        // we only add meta boxes if the page_route calls for it
2119
-        if (
2120
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2121
-            && is_array(
2122
-                $this->_route_config['metaboxes']
2123
-            )
2124
-        ) {
2125
-            // this simply loops through the callbacks provided
2126
-            // and checks if there is a corresponding callback registered by the child
2127
-            // if there is then we go ahead and process the metabox loader.
2128
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2129
-                // first check for Closures
2130
-                if ($metabox_callback instanceof Closure) {
2131
-                    $result = $metabox_callback();
2132
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2133
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2134
-                } else {
2135
-                    $result = $this->{$metabox_callback}();
2136
-                }
2137
-                if ($result === false) {
2138
-                    // user error msg
2139
-                    $error_msg = esc_html__(
2140
-                        'An error occurred. The  requested metabox could not be found.',
2141
-                        'event_espresso'
2142
-                    );
2143
-                    // developer error msg
2144
-                    $error_msg .= '||'
2145
-                                  . sprintf(
2146
-                                      esc_html__(
2147
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2148
-                                          'event_espresso'
2149
-                                      ),
2150
-                                      $metabox_callback
2151
-                                  );
2152
-                    throw new EE_Error($error_msg);
2153
-                }
2154
-            }
2155
-        }
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     * _add_screen_columns
2161
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2162
-     * the dynamic column template and we'll setup the column options for the page.
2163
-     *
2164
-     * @return void
2165
-     */
2166
-    private function _add_screen_columns()
2167
-    {
2168
-        if (
2169
-            is_array($this->_route_config)
2170
-            && isset($this->_route_config['columns'])
2171
-            && is_array($this->_route_config['columns'])
2172
-            && count($this->_route_config['columns']) === 2
2173
-        ) {
2174
-            add_screen_option(
2175
-                'layout_columns',
2176
-                [
2177
-                    'max'     => (int) $this->_route_config['columns'][0],
2178
-                    'default' => (int) $this->_route_config['columns'][1],
2179
-                ]
2180
-            );
2181
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2182
-            $screen_id                                           = $this->_current_screen->id;
2183
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2184
-            $total_columns                                       = ! empty($screen_columns)
2185
-                ? $screen_columns
2186
-                : $this->_route_config['columns'][1];
2187
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2188
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2189
-            $this->_template_args['screen']                      = $this->_current_screen;
2190
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2191
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2192
-            // finally if we don't have has_metaboxes set in the route config
2193
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2194
-            $this->_route_config['has_metaboxes'] = true;
2195
-        }
2196
-    }
2197
-
2198
-
2199
-
2200
-    /** GLOBALLY AVAILABLE METABOXES **/
2201
-
2202
-
2203
-    /**
2204
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2205
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2206
-     * these get loaded on.
2207
-     */
2208
-    private function _espresso_news_post_box()
2209
-    {
2210
-        $news_box_title = apply_filters(
2211
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2212
-            esc_html__('New @ Event Espresso', 'event_espresso')
2213
-        );
2214
-        add_meta_box(
2215
-            'espresso_news_post_box',
2216
-            $news_box_title,
2217
-            [
2218
-                $this,
2219
-                'espresso_news_post_box',
2220
-            ],
2221
-            $this->_wp_page_slug,
2222
-            'side'
2223
-        );
2224
-    }
2225
-
2226
-
2227
-    /**
2228
-     * Code for setting up espresso ratings request metabox.
2229
-     */
2230
-    protected function _espresso_ratings_request()
2231
-    {
2232
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2233
-            return;
2234
-        }
2235
-        $ratings_box_title = apply_filters(
2236
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2237
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2238
-        );
2239
-        add_meta_box(
2240
-            'espresso_ratings_request',
2241
-            $ratings_box_title,
2242
-            [
2243
-                $this,
2244
-                'espresso_ratings_request',
2245
-            ],
2246
-            $this->_wp_page_slug,
2247
-            'side'
2248
-        );
2249
-    }
2250
-
2251
-
2252
-    /**
2253
-     * Code for setting up espresso ratings request metabox content.
2254
-     *
2255
-     * @throws DomainException
2256
-     */
2257
-    public function espresso_ratings_request()
2258
-    {
2259
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2260
-    }
2261
-
2262
-
2263
-    public static function cached_rss_display($rss_id, $url)
2264
-    {
2265
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2266
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2267
-                     . '</p><p class="hide-if-js">'
2268
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2269
-                     . '</p>';
2270
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2271
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2272
-        $post      = '</div>' . "\n";
2273
-        $cache_key = 'ee_rss_' . md5($rss_id);
2274
-        $output    = get_transient($cache_key);
2275
-        if ($output !== false) {
2276
-            echo $pre . $output . $post; // already escaped
2277
-            return true;
2278
-        }
2279
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2280
-            echo $pre . $loading . $post; // already escaped
2281
-            return false;
2282
-        }
2283
-        ob_start();
2284
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2285
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2286
-        return true;
2287
-    }
2288
-
2289
-
2290
-    public function espresso_news_post_box()
2291
-    {
2292
-        ?>
2083
+		return $entries_per_page_dropdown;
2084
+	}
2085
+
2086
+
2087
+	/**
2088
+	 *        _set_search_attributes
2089
+	 *
2090
+	 * @return        void
2091
+	 */
2092
+	public function _set_search_attributes()
2093
+	{
2094
+		$this->_template_args['search']['btn_label'] = sprintf(
2095
+			esc_html__('Search %s', 'event_espresso'),
2096
+			empty($this->_search_btn_label) ? $this->page_label
2097
+				: $this->_search_btn_label
2098
+		);
2099
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2100
+	}
2101
+
2102
+
2103
+
2104
+	/*** END LIST TABLE METHODS **/
2105
+
2106
+
2107
+	/**
2108
+	 * _add_registered_metaboxes
2109
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2110
+	 *
2111
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2112
+	 * @return void
2113
+	 * @throws EE_Error
2114
+	 */
2115
+	private function _add_registered_meta_boxes()
2116
+	{
2117
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2118
+		// we only add meta boxes if the page_route calls for it
2119
+		if (
2120
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2121
+			&& is_array(
2122
+				$this->_route_config['metaboxes']
2123
+			)
2124
+		) {
2125
+			// this simply loops through the callbacks provided
2126
+			// and checks if there is a corresponding callback registered by the child
2127
+			// if there is then we go ahead and process the metabox loader.
2128
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2129
+				// first check for Closures
2130
+				if ($metabox_callback instanceof Closure) {
2131
+					$result = $metabox_callback();
2132
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2133
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2134
+				} else {
2135
+					$result = $this->{$metabox_callback}();
2136
+				}
2137
+				if ($result === false) {
2138
+					// user error msg
2139
+					$error_msg = esc_html__(
2140
+						'An error occurred. The  requested metabox could not be found.',
2141
+						'event_espresso'
2142
+					);
2143
+					// developer error msg
2144
+					$error_msg .= '||'
2145
+								  . sprintf(
2146
+									  esc_html__(
2147
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2148
+										  'event_espresso'
2149
+									  ),
2150
+									  $metabox_callback
2151
+								  );
2152
+					throw new EE_Error($error_msg);
2153
+				}
2154
+			}
2155
+		}
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 * _add_screen_columns
2161
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2162
+	 * the dynamic column template and we'll setup the column options for the page.
2163
+	 *
2164
+	 * @return void
2165
+	 */
2166
+	private function _add_screen_columns()
2167
+	{
2168
+		if (
2169
+			is_array($this->_route_config)
2170
+			&& isset($this->_route_config['columns'])
2171
+			&& is_array($this->_route_config['columns'])
2172
+			&& count($this->_route_config['columns']) === 2
2173
+		) {
2174
+			add_screen_option(
2175
+				'layout_columns',
2176
+				[
2177
+					'max'     => (int) $this->_route_config['columns'][0],
2178
+					'default' => (int) $this->_route_config['columns'][1],
2179
+				]
2180
+			);
2181
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2182
+			$screen_id                                           = $this->_current_screen->id;
2183
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2184
+			$total_columns                                       = ! empty($screen_columns)
2185
+				? $screen_columns
2186
+				: $this->_route_config['columns'][1];
2187
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2188
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2189
+			$this->_template_args['screen']                      = $this->_current_screen;
2190
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2191
+																   . 'admin_details_metabox_column_wrapper.template.php';
2192
+			// finally if we don't have has_metaboxes set in the route config
2193
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2194
+			$this->_route_config['has_metaboxes'] = true;
2195
+		}
2196
+	}
2197
+
2198
+
2199
+
2200
+	/** GLOBALLY AVAILABLE METABOXES **/
2201
+
2202
+
2203
+	/**
2204
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2205
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2206
+	 * these get loaded on.
2207
+	 */
2208
+	private function _espresso_news_post_box()
2209
+	{
2210
+		$news_box_title = apply_filters(
2211
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2212
+			esc_html__('New @ Event Espresso', 'event_espresso')
2213
+		);
2214
+		add_meta_box(
2215
+			'espresso_news_post_box',
2216
+			$news_box_title,
2217
+			[
2218
+				$this,
2219
+				'espresso_news_post_box',
2220
+			],
2221
+			$this->_wp_page_slug,
2222
+			'side'
2223
+		);
2224
+	}
2225
+
2226
+
2227
+	/**
2228
+	 * Code for setting up espresso ratings request metabox.
2229
+	 */
2230
+	protected function _espresso_ratings_request()
2231
+	{
2232
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2233
+			return;
2234
+		}
2235
+		$ratings_box_title = apply_filters(
2236
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2237
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2238
+		);
2239
+		add_meta_box(
2240
+			'espresso_ratings_request',
2241
+			$ratings_box_title,
2242
+			[
2243
+				$this,
2244
+				'espresso_ratings_request',
2245
+			],
2246
+			$this->_wp_page_slug,
2247
+			'side'
2248
+		);
2249
+	}
2250
+
2251
+
2252
+	/**
2253
+	 * Code for setting up espresso ratings request metabox content.
2254
+	 *
2255
+	 * @throws DomainException
2256
+	 */
2257
+	public function espresso_ratings_request()
2258
+	{
2259
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2260
+	}
2261
+
2262
+
2263
+	public static function cached_rss_display($rss_id, $url)
2264
+	{
2265
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2266
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2267
+					 . '</p><p class="hide-if-js">'
2268
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2269
+					 . '</p>';
2270
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2271
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2272
+		$post      = '</div>' . "\n";
2273
+		$cache_key = 'ee_rss_' . md5($rss_id);
2274
+		$output    = get_transient($cache_key);
2275
+		if ($output !== false) {
2276
+			echo $pre . $output . $post; // already escaped
2277
+			return true;
2278
+		}
2279
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2280
+			echo $pre . $loading . $post; // already escaped
2281
+			return false;
2282
+		}
2283
+		ob_start();
2284
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2285
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2286
+		return true;
2287
+	}
2288
+
2289
+
2290
+	public function espresso_news_post_box()
2291
+	{
2292
+		?>
2293 2293
         <div class="padding">
2294 2294
             <div id="espresso_news_post_box_content" class="infolinks">
2295 2295
                 <?php
2296
-                // Get RSS Feed(s)
2297
-                EE_Admin_Page::cached_rss_display(
2298
-                    'espresso_news_post_box_content',
2299
-                    esc_url_raw(
2300
-                        apply_filters(
2301
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2302
-                            'https://eventespresso.com/feed/'
2303
-                        )
2304
-                    )
2305
-                );
2306
-                ?>
2296
+				// Get RSS Feed(s)
2297
+				EE_Admin_Page::cached_rss_display(
2298
+					'espresso_news_post_box_content',
2299
+					esc_url_raw(
2300
+						apply_filters(
2301
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2302
+							'https://eventespresso.com/feed/'
2303
+						)
2304
+					)
2305
+				);
2306
+				?>
2307 2307
             </div>
2308 2308
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2309 2309
         </div>
2310 2310
         <?php
2311
-    }
2312
-
2313
-
2314
-    private function _espresso_links_post_box()
2315
-    {
2316
-        // Hiding until we actually have content to put in here...
2317
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2318
-    }
2319
-
2320
-
2321
-    public function espresso_links_post_box()
2322
-    {
2323
-        // Hiding until we actually have content to put in here...
2324
-        // EEH_Template::display_template(
2325
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2326
-        // );
2327
-    }
2328
-
2329
-
2330
-    protected function _espresso_sponsors_post_box()
2331
-    {
2332
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2333
-            add_meta_box(
2334
-                'espresso_sponsors_post_box',
2335
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2336
-                [$this, 'espresso_sponsors_post_box'],
2337
-                $this->_wp_page_slug,
2338
-                'side'
2339
-            );
2340
-        }
2341
-    }
2342
-
2343
-
2344
-    public function espresso_sponsors_post_box()
2345
-    {
2346
-        EEH_Template::display_template(
2347
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2348
-        );
2349
-    }
2350
-
2351
-
2352
-    private function _publish_post_box()
2353
-    {
2354
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2355
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2356
-        // then we'll use that for the metabox label.
2357
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2358
-        if (! empty($this->_labels['publishbox'])) {
2359
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2360
-                : $this->_labels['publishbox'];
2361
-        } else {
2362
-            $box_label = esc_html__('Publish', 'event_espresso');
2363
-        }
2364
-        $box_label = apply_filters(
2365
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2366
-            $box_label,
2367
-            $this->_req_action,
2368
-            $this
2369
-        );
2370
-        add_meta_box(
2371
-            $meta_box_ref,
2372
-            $box_label,
2373
-            [$this, 'editor_overview'],
2374
-            $this->_current_screen->id,
2375
-            'side',
2376
-            'high'
2377
-        );
2378
-    }
2379
-
2380
-
2381
-    public function editor_overview()
2382
-    {
2383
-        // if we have extra content set let's add it in if not make sure its empty
2384
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2385
-            ? $this->_template_args['publish_box_extra_content']
2386
-            : '';
2387
-        echo EEH_Template::display_template(
2388
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2389
-            $this->_template_args,
2390
-            true
2391
-        );
2392
-    }
2393
-
2394
-
2395
-    /** end of globally available metaboxes section **/
2396
-
2397
-
2398
-    /**
2399
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2400
-     * protected method.
2401
-     *
2402
-     * @param string $name
2403
-     * @param int    $id
2404
-     * @param bool   $delete
2405
-     * @param string $save_close_redirect_URL
2406
-     * @param bool   $both_btns
2407
-     * @throws EE_Error
2408
-     * @throws InvalidArgumentException
2409
-     * @throws InvalidDataTypeException
2410
-     * @throws InvalidInterfaceException
2411
-     * @see   $this->_set_publish_post_box_vars for param details
2412
-     * @since 4.6.0
2413
-     */
2414
-    public function set_publish_post_box_vars(
2415
-        $name = '',
2416
-        $id = 0,
2417
-        $delete = false,
2418
-        $save_close_redirect_URL = '',
2419
-        $both_btns = true
2420
-    ) {
2421
-        $this->_set_publish_post_box_vars(
2422
-            $name,
2423
-            $id,
2424
-            $delete,
2425
-            $save_close_redirect_URL,
2426
-            $both_btns
2427
-        );
2428
-    }
2429
-
2430
-
2431
-    /**
2432
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2433
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2434
-     * save, and save and close buttons to work properly, then you will want to include a
2435
-     * values for the name and id arguments.
2436
-     *
2437
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2438
-     * @param int     $id                         id attached to the item published
2439
-     * @param string  $delete                     page route callback for the delete action
2440
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2441
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2442
-     *                                            the Save button
2443
-     * @throws EE_Error
2444
-     * @throws InvalidArgumentException
2445
-     * @throws InvalidDataTypeException
2446
-     * @throws InvalidInterfaceException
2447
-     * @todo  Add in validation for name/id arguments.
2448
-     */
2449
-    protected function _set_publish_post_box_vars(
2450
-        $name = '',
2451
-        $id = 0,
2452
-        $delete = '',
2453
-        $save_close_redirect_URL = '',
2454
-        $both_btns = true
2455
-    ) {
2456
-        // if Save & Close, use a custom redirect URL or default to the main page?
2457
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2458
-            ? $save_close_redirect_URL
2459
-            : $this->_admin_base_url;
2460
-        // create the Save & Close and Save buttons
2461
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2462
-        // if we have extra content set let's add it in if not make sure its empty
2463
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2464
-            ? $this->_template_args['publish_box_extra_content']
2465
-            : '';
2466
-        if ($delete && ! empty($id)) {
2467
-            // make sure we have a default if just true is sent.
2468
-            $delete           = ! empty($delete) ? $delete : 'delete';
2469
-            $delete_link_args = [$name => $id];
2470
-            $delete           = $this->get_action_link_or_button(
2471
-                $delete,
2472
-                $delete,
2473
-                $delete_link_args,
2474
-                'submitdelete deletion'
2475
-            );
2476
-        }
2477
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2478
-        if (! empty($name) && ! empty($id)) {
2479
-            $hidden_field_arr[ $name ] = [
2480
-                'type'  => 'hidden',
2481
-                'value' => $id,
2482
-            ];
2483
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2484
-        } else {
2485
-            $hf = '';
2486
-        }
2487
-        // add hidden field
2488
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2489
-            ? $hf[ $name ]['field']
2490
-            : $hf;
2491
-    }
2492
-
2493
-
2494
-    /**
2495
-     * displays an error message to ppl who have javascript disabled
2496
-     *
2497
-     * @return void
2498
-     */
2499
-    private function _display_no_javascript_warning()
2500
-    {
2501
-        ?>
2311
+	}
2312
+
2313
+
2314
+	private function _espresso_links_post_box()
2315
+	{
2316
+		// Hiding until we actually have content to put in here...
2317
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2318
+	}
2319
+
2320
+
2321
+	public function espresso_links_post_box()
2322
+	{
2323
+		// Hiding until we actually have content to put in here...
2324
+		// EEH_Template::display_template(
2325
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2326
+		// );
2327
+	}
2328
+
2329
+
2330
+	protected function _espresso_sponsors_post_box()
2331
+	{
2332
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2333
+			add_meta_box(
2334
+				'espresso_sponsors_post_box',
2335
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2336
+				[$this, 'espresso_sponsors_post_box'],
2337
+				$this->_wp_page_slug,
2338
+				'side'
2339
+			);
2340
+		}
2341
+	}
2342
+
2343
+
2344
+	public function espresso_sponsors_post_box()
2345
+	{
2346
+		EEH_Template::display_template(
2347
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2348
+		);
2349
+	}
2350
+
2351
+
2352
+	private function _publish_post_box()
2353
+	{
2354
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2355
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2356
+		// then we'll use that for the metabox label.
2357
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2358
+		if (! empty($this->_labels['publishbox'])) {
2359
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2360
+				: $this->_labels['publishbox'];
2361
+		} else {
2362
+			$box_label = esc_html__('Publish', 'event_espresso');
2363
+		}
2364
+		$box_label = apply_filters(
2365
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2366
+			$box_label,
2367
+			$this->_req_action,
2368
+			$this
2369
+		);
2370
+		add_meta_box(
2371
+			$meta_box_ref,
2372
+			$box_label,
2373
+			[$this, 'editor_overview'],
2374
+			$this->_current_screen->id,
2375
+			'side',
2376
+			'high'
2377
+		);
2378
+	}
2379
+
2380
+
2381
+	public function editor_overview()
2382
+	{
2383
+		// if we have extra content set let's add it in if not make sure its empty
2384
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2385
+			? $this->_template_args['publish_box_extra_content']
2386
+			: '';
2387
+		echo EEH_Template::display_template(
2388
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2389
+			$this->_template_args,
2390
+			true
2391
+		);
2392
+	}
2393
+
2394
+
2395
+	/** end of globally available metaboxes section **/
2396
+
2397
+
2398
+	/**
2399
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2400
+	 * protected method.
2401
+	 *
2402
+	 * @param string $name
2403
+	 * @param int    $id
2404
+	 * @param bool   $delete
2405
+	 * @param string $save_close_redirect_URL
2406
+	 * @param bool   $both_btns
2407
+	 * @throws EE_Error
2408
+	 * @throws InvalidArgumentException
2409
+	 * @throws InvalidDataTypeException
2410
+	 * @throws InvalidInterfaceException
2411
+	 * @see   $this->_set_publish_post_box_vars for param details
2412
+	 * @since 4.6.0
2413
+	 */
2414
+	public function set_publish_post_box_vars(
2415
+		$name = '',
2416
+		$id = 0,
2417
+		$delete = false,
2418
+		$save_close_redirect_URL = '',
2419
+		$both_btns = true
2420
+	) {
2421
+		$this->_set_publish_post_box_vars(
2422
+			$name,
2423
+			$id,
2424
+			$delete,
2425
+			$save_close_redirect_URL,
2426
+			$both_btns
2427
+		);
2428
+	}
2429
+
2430
+
2431
+	/**
2432
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2433
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2434
+	 * save, and save and close buttons to work properly, then you will want to include a
2435
+	 * values for the name and id arguments.
2436
+	 *
2437
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2438
+	 * @param int     $id                         id attached to the item published
2439
+	 * @param string  $delete                     page route callback for the delete action
2440
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2441
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2442
+	 *                                            the Save button
2443
+	 * @throws EE_Error
2444
+	 * @throws InvalidArgumentException
2445
+	 * @throws InvalidDataTypeException
2446
+	 * @throws InvalidInterfaceException
2447
+	 * @todo  Add in validation for name/id arguments.
2448
+	 */
2449
+	protected function _set_publish_post_box_vars(
2450
+		$name = '',
2451
+		$id = 0,
2452
+		$delete = '',
2453
+		$save_close_redirect_URL = '',
2454
+		$both_btns = true
2455
+	) {
2456
+		// if Save & Close, use a custom redirect URL or default to the main page?
2457
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2458
+			? $save_close_redirect_URL
2459
+			: $this->_admin_base_url;
2460
+		// create the Save & Close and Save buttons
2461
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2462
+		// if we have extra content set let's add it in if not make sure its empty
2463
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2464
+			? $this->_template_args['publish_box_extra_content']
2465
+			: '';
2466
+		if ($delete && ! empty($id)) {
2467
+			// make sure we have a default if just true is sent.
2468
+			$delete           = ! empty($delete) ? $delete : 'delete';
2469
+			$delete_link_args = [$name => $id];
2470
+			$delete           = $this->get_action_link_or_button(
2471
+				$delete,
2472
+				$delete,
2473
+				$delete_link_args,
2474
+				'submitdelete deletion'
2475
+			);
2476
+		}
2477
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2478
+		if (! empty($name) && ! empty($id)) {
2479
+			$hidden_field_arr[ $name ] = [
2480
+				'type'  => 'hidden',
2481
+				'value' => $id,
2482
+			];
2483
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2484
+		} else {
2485
+			$hf = '';
2486
+		}
2487
+		// add hidden field
2488
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2489
+			? $hf[ $name ]['field']
2490
+			: $hf;
2491
+	}
2492
+
2493
+
2494
+	/**
2495
+	 * displays an error message to ppl who have javascript disabled
2496
+	 *
2497
+	 * @return void
2498
+	 */
2499
+	private function _display_no_javascript_warning()
2500
+	{
2501
+		?>
2502 2502
         <noscript>
2503 2503
             <div id="no-js-message" class="error">
2504 2504
                 <p style="font-size:1.3em;">
2505 2505
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2506 2506
                     <?php esc_html_e(
2507
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2508
-                        'event_espresso'
2509
-                    ); ?>
2507
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2508
+						'event_espresso'
2509
+					); ?>
2510 2510
                 </p>
2511 2511
             </div>
2512 2512
         </noscript>
2513 2513
         <?php
2514
-    }
2515
-
2516
-
2517
-    /**
2518
-     * displays espresso success and/or error notices
2519
-     *
2520
-     * @return void
2521
-     */
2522
-    protected function _display_espresso_notices()
2523
-    {
2524
-        $notices = $this->_get_transient(true);
2525
-        echo stripslashes($notices);
2526
-    }
2527
-
2528
-
2529
-    /**
2530
-     * spinny things pacify the masses
2531
-     *
2532
-     * @return void
2533
-     */
2534
-    protected function _add_admin_page_ajax_loading_img()
2535
-    {
2536
-        ?>
2514
+	}
2515
+
2516
+
2517
+	/**
2518
+	 * displays espresso success and/or error notices
2519
+	 *
2520
+	 * @return void
2521
+	 */
2522
+	protected function _display_espresso_notices()
2523
+	{
2524
+		$notices = $this->_get_transient(true);
2525
+		echo stripslashes($notices);
2526
+	}
2527
+
2528
+
2529
+	/**
2530
+	 * spinny things pacify the masses
2531
+	 *
2532
+	 * @return void
2533
+	 */
2534
+	protected function _add_admin_page_ajax_loading_img()
2535
+	{
2536
+		?>
2537 2537
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2538 2538
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2539
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2539
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2540 2540
         </div>
2541 2541
         <?php
2542
-    }
2542
+	}
2543 2543
 
2544 2544
 
2545
-    /**
2546
-     * add admin page overlay for modal boxes
2547
-     *
2548
-     * @return void
2549
-     */
2550
-    protected function _add_admin_page_overlay()
2551
-    {
2552
-        ?>
2545
+	/**
2546
+	 * add admin page overlay for modal boxes
2547
+	 *
2548
+	 * @return void
2549
+	 */
2550
+	protected function _add_admin_page_overlay()
2551
+	{
2552
+		?>
2553 2553
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2554 2554
         <?php
2555
-    }
2556
-
2557
-
2558
-    /**
2559
-     * facade for add_meta_box
2560
-     *
2561
-     * @param string  $action        where the metabox gets displayed
2562
-     * @param string  $title         Title of Metabox (output in metabox header)
2563
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2564
-     *                               instead of the one created in here.
2565
-     * @param array   $callback_args an array of args supplied for the metabox
2566
-     * @param string  $column        what metabox column
2567
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2568
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2569
-     *                               created but just set our own callback for wp's add_meta_box.
2570
-     * @throws DomainException
2571
-     */
2572
-    public function _add_admin_page_meta_box(
2573
-        $action,
2574
-        $title,
2575
-        $callback,
2576
-        $callback_args,
2577
-        $column = 'normal',
2578
-        $priority = 'high',
2579
-        $create_func = true
2580
-    ) {
2581
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2582
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2583
-        if (empty($callback_args) && $create_func) {
2584
-            $callback_args = [
2585
-                'template_path' => $this->_template_path,
2586
-                'template_args' => $this->_template_args,
2587
-            ];
2588
-        }
2589
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2590
-        $call_back_func = $create_func
2591
-            ? static function ($post, $metabox) {
2592
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2593
-                echo EEH_Template::display_template(
2594
-                    $metabox['args']['template_path'],
2595
-                    $metabox['args']['template_args'],
2596
-                    true
2597
-                );
2598
-            }
2599
-            : $callback;
2600
-        add_meta_box(
2601
-            str_replace('_', '-', $action) . '-mbox',
2602
-            $title,
2603
-            $call_back_func,
2604
-            $this->_wp_page_slug,
2605
-            $column,
2606
-            $priority,
2607
-            $callback_args
2608
-        );
2609
-    }
2610
-
2611
-
2612
-    /**
2613
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2614
-     *
2615
-     * @throws DomainException
2616
-     * @throws EE_Error
2617
-     * @throws InvalidArgumentException
2618
-     * @throws InvalidDataTypeException
2619
-     * @throws InvalidInterfaceException
2620
-     */
2621
-    public function display_admin_page_with_metabox_columns()
2622
-    {
2623
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2624
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2625
-            $this->_column_template_path,
2626
-            $this->_template_args,
2627
-            true
2628
-        );
2629
-        // the final wrapper
2630
-        $this->admin_page_wrapper();
2631
-    }
2632
-
2633
-
2634
-    /**
2635
-     * generates  HTML wrapper for an admin details page
2636
-     *
2637
-     * @return void
2638
-     * @throws DomainException
2639
-     * @throws EE_Error
2640
-     * @throws InvalidArgumentException
2641
-     * @throws InvalidDataTypeException
2642
-     * @throws InvalidInterfaceException
2643
-     */
2644
-    public function display_admin_page_with_sidebar()
2645
-    {
2646
-        $this->_display_admin_page(true);
2647
-    }
2648
-
2649
-
2650
-    /**
2651
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2652
-     *
2653
-     * @return void
2654
-     * @throws DomainException
2655
-     * @throws EE_Error
2656
-     * @throws InvalidArgumentException
2657
-     * @throws InvalidDataTypeException
2658
-     * @throws InvalidInterfaceException
2659
-     */
2660
-    public function display_admin_page_with_no_sidebar()
2661
-    {
2662
-        $this->_display_admin_page();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2668
-     *
2669
-     * @return void
2670
-     * @throws DomainException
2671
-     * @throws EE_Error
2672
-     * @throws InvalidArgumentException
2673
-     * @throws InvalidDataTypeException
2674
-     * @throws InvalidInterfaceException
2675
-     */
2676
-    public function display_about_admin_page()
2677
-    {
2678
-        $this->_display_admin_page(false, true);
2679
-    }
2680
-
2681
-
2682
-    /**
2683
-     * display_admin_page
2684
-     * contains the code for actually displaying an admin page
2685
-     *
2686
-     * @param boolean $sidebar true with sidebar, false without
2687
-     * @param boolean $about   use the about admin wrapper instead of the default.
2688
-     * @return void
2689
-     * @throws DomainException
2690
-     * @throws EE_Error
2691
-     * @throws InvalidArgumentException
2692
-     * @throws InvalidDataTypeException
2693
-     * @throws InvalidInterfaceException
2694
-     */
2695
-    private function _display_admin_page($sidebar = false, $about = false)
2696
-    {
2697
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2698
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2699
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2700
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2701
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2702
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2703
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2704
-            ? 'poststuff'
2705
-            : 'espresso-default-admin';
2706
-        $template_path                                     = $sidebar
2707
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2708
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2709
-        if ($this->request->isAjax()) {
2710
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2711
-        }
2712
-        $template_path                                     = ! empty($this->_column_template_path)
2713
-            ? $this->_column_template_path : $template_path;
2714
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2715
-            ? $this->_template_args['admin_page_content']
2716
-            : '';
2717
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2718
-            ? $this->_template_args['before_admin_page_content']
2719
-            : '';
2720
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2721
-            ? $this->_template_args['after_admin_page_content']
2722
-            : '';
2723
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2724
-            $template_path,
2725
-            $this->_template_args,
2726
-            true
2727
-        );
2728
-        // the final template wrapper
2729
-        $this->admin_page_wrapper($about);
2730
-    }
2731
-
2732
-
2733
-    /**
2734
-     * This is used to display caf preview pages.
2735
-     *
2736
-     * @param string $utm_campaign_source what is the key used for google analytics link
2737
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2738
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2739
-     * @return void
2740
-     * @throws DomainException
2741
-     * @throws EE_Error
2742
-     * @throws InvalidArgumentException
2743
-     * @throws InvalidDataTypeException
2744
-     * @throws InvalidInterfaceException
2745
-     * @since 4.3.2
2746
-     */
2747
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2748
-    {
2749
-        // let's generate a default preview action button if there isn't one already present.
2750
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2751
-            'Upgrade to Event Espresso 4 Right Now',
2752
-            'event_espresso'
2753
-        );
2754
-        $buy_now_url                                   = add_query_arg(
2755
-            [
2756
-                'ee_ver'       => 'ee4',
2757
-                'utm_source'   => 'ee4_plugin_admin',
2758
-                'utm_medium'   => 'link',
2759
-                'utm_campaign' => $utm_campaign_source,
2760
-                'utm_content'  => 'buy_now_button',
2761
-            ],
2762
-            'https://eventespresso.com/pricing/'
2763
-        );
2764
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2765
-            ? $this->get_action_link_or_button(
2766
-                '',
2767
-                'buy_now',
2768
-                [],
2769
-                'button-primary button-large',
2770
-                esc_url_raw($buy_now_url),
2771
-                true
2772
-            )
2773
-            : $this->_template_args['preview_action_button'];
2774
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2775
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2776
-            $this->_template_args,
2777
-            true
2778
-        );
2779
-        $this->_display_admin_page($display_sidebar);
2780
-    }
2781
-
2782
-
2783
-    /**
2784
-     * display_admin_list_table_page_with_sidebar
2785
-     * generates HTML wrapper for an admin_page with list_table
2786
-     *
2787
-     * @return void
2788
-     * @throws DomainException
2789
-     * @throws EE_Error
2790
-     * @throws InvalidArgumentException
2791
-     * @throws InvalidDataTypeException
2792
-     * @throws InvalidInterfaceException
2793
-     */
2794
-    public function display_admin_list_table_page_with_sidebar()
2795
-    {
2796
-        $this->_display_admin_list_table_page(true);
2797
-    }
2798
-
2799
-
2800
-    /**
2801
-     * display_admin_list_table_page_with_no_sidebar
2802
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2803
-     *
2804
-     * @return void
2805
-     * @throws DomainException
2806
-     * @throws EE_Error
2807
-     * @throws InvalidArgumentException
2808
-     * @throws InvalidDataTypeException
2809
-     * @throws InvalidInterfaceException
2810
-     */
2811
-    public function display_admin_list_table_page_with_no_sidebar()
2812
-    {
2813
-        $this->_display_admin_list_table_page();
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * generates html wrapper for an admin_list_table page
2819
-     *
2820
-     * @param boolean $sidebar whether to display with sidebar or not.
2821
-     * @return void
2822
-     * @throws DomainException
2823
-     * @throws EE_Error
2824
-     * @throws InvalidArgumentException
2825
-     * @throws InvalidDataTypeException
2826
-     * @throws InvalidInterfaceException
2827
-     */
2828
-    private function _display_admin_list_table_page($sidebar = false)
2829
-    {
2830
-        // setup search attributes
2831
-        $this->_set_search_attributes();
2832
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2833
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2834
-        $this->_template_args['table_url']        = $this->request->isAjax()
2835
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2836
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2837
-        $this->_template_args['list_table']       = $this->_list_table_object;
2838
-        $this->_template_args['current_route']    = $this->_req_action;
2839
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2840
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2841
-        if (! empty($ajax_sorting_callback)) {
2842
-            $sortable_list_table_form_fields = wp_nonce_field(
2843
-                $ajax_sorting_callback . '_nonce',
2844
-                $ajax_sorting_callback . '_nonce',
2845
-                false,
2846
-                false
2847
-            );
2848
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2849
-                                                . $this->page_slug
2850
-                                                . '" />';
2851
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2852
-                                                . $ajax_sorting_callback
2853
-                                                . '" />';
2854
-        } else {
2855
-            $sortable_list_table_form_fields = '';
2856
-        }
2857
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2858
-        $hidden_form_fields                                      =
2859
-            isset($this->_template_args['list_table_hidden_fields'])
2860
-                ? $this->_template_args['list_table_hidden_fields']
2861
-                : '';
2862
-        $nonce_ref                                               = $this->_req_action . '_nonce';
2863
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
2864
-                                                                    . $nonce_ref
2865
-                                                                    . '" value="'
2866
-                                                                    . wp_create_nonce($nonce_ref)
2867
-                                                                    . '">';
2868
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2869
-        // display message about search results?
2870
-        $search = $this->request->getRequestParam('s');
2871
-        $this->_template_args['before_list_table'] .= ! empty($search)
2872
-            ? '<p class="ee-search-results">' . sprintf(
2873
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2874
-                trim($search, '%')
2875
-            ) . '</p>'
2876
-            : '';
2877
-        // filter before_list_table template arg
2878
-        $this->_template_args['before_list_table'] = apply_filters(
2879
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2880
-            $this->_template_args['before_list_table'],
2881
-            $this->page_slug,
2882
-            $this->request->requestParams(),
2883
-            $this->_req_action
2884
-        );
2885
-        // convert to array and filter again
2886
-        // arrays are easier to inject new items in a specific location,
2887
-        // but would not be backwards compatible, so we have to add a new filter
2888
-        $this->_template_args['before_list_table'] = implode(
2889
-            " \n",
2890
-            (array) apply_filters(
2891
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2892
-                (array) $this->_template_args['before_list_table'],
2893
-                $this->page_slug,
2894
-                $this->request->requestParams(),
2895
-                $this->_req_action
2896
-            )
2897
-        );
2898
-        // filter after_list_table template arg
2899
-        $this->_template_args['after_list_table'] = apply_filters(
2900
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2901
-            $this->_template_args['after_list_table'],
2902
-            $this->page_slug,
2903
-            $this->request->requestParams(),
2904
-            $this->_req_action
2905
-        );
2906
-        // convert to array and filter again
2907
-        // arrays are easier to inject new items in a specific location,
2908
-        // but would not be backwards compatible, so we have to add a new filter
2909
-        $this->_template_args['after_list_table']   = implode(
2910
-            " \n",
2911
-            (array) apply_filters(
2912
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2913
-                (array) $this->_template_args['after_list_table'],
2914
-                $this->page_slug,
2915
-                $this->request->requestParams(),
2916
-                $this->_req_action
2917
-            )
2918
-        );
2919
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2920
-            $template_path,
2921
-            $this->_template_args,
2922
-            true
2923
-        );
2924
-        // the final template wrapper
2925
-        if ($sidebar) {
2926
-            $this->display_admin_page_with_sidebar();
2927
-        } else {
2928
-            $this->display_admin_page_with_no_sidebar();
2929
-        }
2930
-    }
2931
-
2932
-
2933
-    /**
2934
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2935
-     * html string for the legend.
2936
-     * $items are expected in an array in the following format:
2937
-     * $legend_items = array(
2938
-     *        'item_id' => array(
2939
-     *            'icon' => 'http://url_to_icon_being_described.png',
2940
-     *            'desc' => esc_html__('localized description of item');
2941
-     *        )
2942
-     * );
2943
-     *
2944
-     * @param array $items see above for format of array
2945
-     * @return string html string of legend
2946
-     * @throws DomainException
2947
-     */
2948
-    protected function _display_legend($items)
2949
-    {
2950
-        $this->_template_args['items'] = apply_filters(
2951
-            'FHEE__EE_Admin_Page___display_legend__items',
2952
-            (array) $items,
2953
-            $this
2954
-        );
2955
-        /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
2956
-        $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
2957
-        if (! $status_change_notice->isDismissed()) {
2958
-            $this->_template_args['status_change_notice'] = EEH_Template::display_template(
2959
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
2960
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
2961
-                true
2962
-            );
2963
-        }
2964
-        return EEH_Template::display_template(
2965
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2966
-            $this->_template_args,
2967
-            true
2968
-        );
2969
-    }
2970
-
2971
-
2972
-    /**
2973
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2974
-     * The returned json object is created from an array in the following format:
2975
-     * array(
2976
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2977
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2978
-     *  'notices' => '', // - contains any EE_Error formatted notices
2979
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2980
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2981
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
2982
-     *  that might be included in here)
2983
-     * )
2984
-     * The json object is populated by whatever is set in the $_template_args property.
2985
-     *
2986
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2987
-     *                                 instead of displayed.
2988
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2989
-     * @return void
2990
-     * @throws EE_Error
2991
-     * @throws InvalidArgumentException
2992
-     * @throws InvalidDataTypeException
2993
-     * @throws InvalidInterfaceException
2994
-     */
2995
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
2996
-    {
2997
-        // make sure any EE_Error notices have been handled.
2998
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2999
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3000
-        unset($this->_template_args['data']);
3001
-        $json = [
3002
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3003
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3004
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3005
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3006
-            'notices'   => EE_Error::get_notices(),
3007
-            'content'   => isset($this->_template_args['admin_page_content'])
3008
-                ? $this->_template_args['admin_page_content'] : '',
3009
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3010
-            'isEEajax'  => true
3011
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3012
-        ];
3013
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3014
-        if (null === error_get_last() || ! headers_sent()) {
3015
-            header('Content-Type: application/json; charset=UTF-8');
3016
-        }
3017
-        echo wp_json_encode($json);
3018
-        exit();
3019
-    }
3020
-
3021
-
3022
-    /**
3023
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3024
-     *
3025
-     * @return void
3026
-     * @throws EE_Error
3027
-     * @throws InvalidArgumentException
3028
-     * @throws InvalidDataTypeException
3029
-     * @throws InvalidInterfaceException
3030
-     */
3031
-    public function return_json()
3032
-    {
3033
-        if ($this->request->isAjax()) {
3034
-            $this->_return_json();
3035
-        } else {
3036
-            throw new EE_Error(
3037
-                sprintf(
3038
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3039
-                    __FUNCTION__
3040
-                )
3041
-            );
3042
-        }
3043
-    }
3044
-
3045
-
3046
-    /**
3047
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3048
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3049
-     *
3050
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3051
-     */
3052
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3053
-    {
3054
-        $this->_hook_obj = $hook_obj;
3055
-    }
3056
-
3057
-
3058
-    /**
3059
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3060
-     *
3061
-     * @param boolean $about whether to use the special about page wrapper or default.
3062
-     * @return void
3063
-     * @throws DomainException
3064
-     * @throws EE_Error
3065
-     * @throws InvalidArgumentException
3066
-     * @throws InvalidDataTypeException
3067
-     * @throws InvalidInterfaceException
3068
-     */
3069
-    public function admin_page_wrapper($about = false)
3070
-    {
3071
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3072
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3073
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3074
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3075
-
3076
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3077
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3078
-            isset($this->_template_args['before_admin_page_content'])
3079
-                ? $this->_template_args['before_admin_page_content']
3080
-                : ''
3081
-        );
3082
-
3083
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3084
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3085
-            isset($this->_template_args['after_admin_page_content'])
3086
-                ? $this->_template_args['after_admin_page_content']
3087
-                : ''
3088
-        );
3089
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3090
-
3091
-        if ($this->request->isAjax()) {
3092
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3093
-                // $template_path,
3094
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3095
-                $this->_template_args,
3096
-                true
3097
-            );
3098
-            $this->_return_json();
3099
-        }
3100
-        // load settings page wrapper template
3101
-        $template_path = $about
3102
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3103
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3104
-
3105
-        EEH_Template::display_template($template_path, $this->_template_args);
3106
-    }
3107
-
3108
-
3109
-    /**
3110
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3111
-     *
3112
-     * @return string html
3113
-     * @throws EE_Error
3114
-     */
3115
-    protected function _get_main_nav_tabs()
3116
-    {
3117
-        // let's generate the html using the EEH_Tabbed_Content helper.
3118
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3119
-        // (rather than setting in the page_routes array)
3120
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3121
-    }
3122
-
3123
-
3124
-    /**
3125
-     *        sort nav tabs
3126
-     *
3127
-     * @param $a
3128
-     * @param $b
3129
-     * @return int
3130
-     */
3131
-    private function _sort_nav_tabs($a, $b)
3132
-    {
3133
-        if ($a['order'] === $b['order']) {
3134
-            return 0;
3135
-        }
3136
-        return ($a['order'] < $b['order']) ? -1 : 1;
3137
-    }
3138
-
3139
-
3140
-    /**
3141
-     * generates HTML for the forms used on admin pages
3142
-     *
3143
-     * @param array  $input_vars - array of input field details
3144
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3145
-     * @param bool   $id
3146
-     * @return array|string
3147
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3148
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3149
-     */
3150
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3151
-    {
3152
-        return $generator === 'string'
3153
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3154
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3155
-    }
3156
-
3157
-
3158
-    /**
3159
-     * generates the "Save" and "Save & Close" buttons for edit forms
3160
-     *
3161
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3162
-     *                                   Close" button.
3163
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3164
-     *                                   'Save', [1] => 'save & close')
3165
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3166
-     *                                   via the "name" value in the button).  We can also use this to just dump
3167
-     *                                   default actions by submitting some other value.
3168
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3169
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3170
-     *                                   close (normal form handling).
3171
-     */
3172
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3173
-    {
3174
-        // make sure $text and $actions are in an array
3175
-        $text          = (array) $text;
3176
-        $actions       = (array) $actions;
3177
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3178
-        $button_text   = ! empty($text)
3179
-            ? $text
3180
-            : [
3181
-                esc_html__('Save', 'event_espresso'),
3182
-                esc_html__('Save and Close', 'event_espresso'),
3183
-            ];
3184
-        $default_names = ['save', 'save_and_close'];
3185
-        $buttons = '';
3186
-        foreach ($button_text as $key => $button) {
3187
-            $ref     = $default_names[ $key ];
3188
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3189
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3190
-                        . 'value="' . $button . '" name="' . $name . '" '
3191
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3192
-            if (! $both) {
3193
-                break;
3194
-            }
3195
-        }
3196
-        // add in a hidden index for the current page (so save and close redirects properly)
3197
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3198
-                   . $referrer_url
3199
-                   . '" />';
3200
-        $this->_template_args['save_buttons'] = $buttons;
3201
-    }
3202
-
3203
-
3204
-    /**
3205
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3206
-     *
3207
-     * @param string $route
3208
-     * @param array  $additional_hidden_fields
3209
-     * @see   $this->_set_add_edit_form_tags() for details on params
3210
-     * @since 4.6.0
3211
-     */
3212
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3213
-    {
3214
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3215
-    }
3216
-
3217
-
3218
-    /**
3219
-     * set form open and close tags on add/edit pages.
3220
-     *
3221
-     * @param string $route                    the route you want the form to direct to
3222
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3223
-     * @return void
3224
-     */
3225
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3226
-    {
3227
-        if (empty($route)) {
3228
-            $user_msg = esc_html__(
3229
-                'An error occurred. No action was set for this page\'s form.',
3230
-                'event_espresso'
3231
-            );
3232
-            $dev_msg  = $user_msg . "\n"
3233
-                        . sprintf(
3234
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3235
-                            __FUNCTION__,
3236
-                            __CLASS__
3237
-                        );
3238
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3239
-        }
3240
-        // open form
3241
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3242
-                                                             . $this->_admin_base_url
3243
-                                                             . '" id="'
3244
-                                                             . $route
3245
-                                                             . '_event_form" >';
3246
-        // add nonce
3247
-        $nonce                                             =
3248
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3249
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3250
-        // add REQUIRED form action
3251
-        $hidden_fields = [
3252
-            'action' => ['type' => 'hidden', 'value' => $route],
3253
-        ];
3254
-        // merge arrays
3255
-        $hidden_fields = is_array($additional_hidden_fields)
3256
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3257
-            : $hidden_fields;
3258
-        // generate form fields
3259
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3260
-        // add fields to form
3261
-        foreach ((array) $form_fields as $form_field) {
3262
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3263
-        }
3264
-        // close form
3265
-        $this->_template_args['after_admin_page_content'] = '</form>';
3266
-    }
3267
-
3268
-
3269
-    /**
3270
-     * Public Wrapper for _redirect_after_action() method since its
3271
-     * discovered it would be useful for external code to have access.
3272
-     *
3273
-     * @param bool   $success
3274
-     * @param string $what
3275
-     * @param string $action_desc
3276
-     * @param array  $query_args
3277
-     * @param bool   $override_overwrite
3278
-     * @throws EE_Error
3279
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3280
-     * @since 4.5.0
3281
-     */
3282
-    public function redirect_after_action(
3283
-        $success = false,
3284
-        $what = 'item',
3285
-        $action_desc = 'processed',
3286
-        $query_args = [],
3287
-        $override_overwrite = false
3288
-    ) {
3289
-        $this->_redirect_after_action(
3290
-            $success,
3291
-            $what,
3292
-            $action_desc,
3293
-            $query_args,
3294
-            $override_overwrite
3295
-        );
3296
-    }
3297
-
3298
-
3299
-    /**
3300
-     * Helper method for merging existing request data with the returned redirect url.
3301
-     *
3302
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3303
-     * filters are still applied.
3304
-     *
3305
-     * @param array $new_route_data
3306
-     * @return array
3307
-     */
3308
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3309
-    {
3310
-        foreach ($this->request->requestParams() as $ref => $value) {
3311
-            // unset nonces
3312
-            if (strpos($ref, 'nonce') !== false) {
3313
-                $this->request->unSetRequestParam($ref);
3314
-                continue;
3315
-            }
3316
-            // urlencode values.
3317
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3318
-            $this->request->setRequestParam($ref, $value);
3319
-        }
3320
-        return array_merge($this->request->requestParams(), $new_route_data);
3321
-    }
3322
-
3323
-
3324
-    /**
3325
-     *    _redirect_after_action
3326
-     *
3327
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3328
-     * @param string $what               - what the action was performed on
3329
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3330
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3331
-     *                                   action is completed
3332
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3333
-     *                                   override this so that they show.
3334
-     * @return void
3335
-     * @throws EE_Error
3336
-     * @throws InvalidArgumentException
3337
-     * @throws InvalidDataTypeException
3338
-     * @throws InvalidInterfaceException
3339
-     */
3340
-    protected function _redirect_after_action(
3341
-        $success = 0,
3342
-        $what = 'item',
3343
-        $action_desc = 'processed',
3344
-        $query_args = [],
3345
-        $override_overwrite = false
3346
-    ) {
3347
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3348
-        // class name for actions/filters.
3349
-        $classname = get_class($this);
3350
-        // set redirect url.
3351
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3352
-        // otherwise we go with whatever is set as the _admin_base_url
3353
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3354
-        $notices      = EE_Error::get_notices(false);
3355
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3356
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3357
-            EE_Error::overwrite_success();
3358
-        }
3359
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3360
-            // how many records affected ? more than one record ? or just one ?
3361
-            if ($success > 1) {
3362
-                // set plural msg
3363
-                EE_Error::add_success(
3364
-                    sprintf(
3365
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3366
-                        $what,
3367
-                        $action_desc
3368
-                    ),
3369
-                    __FILE__,
3370
-                    __FUNCTION__,
3371
-                    __LINE__
3372
-                );
3373
-            } elseif ($success === 1) {
3374
-                // set singular msg
3375
-                EE_Error::add_success(
3376
-                    sprintf(
3377
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3378
-                        $what,
3379
-                        $action_desc
3380
-                    ),
3381
-                    __FILE__,
3382
-                    __FUNCTION__,
3383
-                    __LINE__
3384
-                );
3385
-            }
3386
-        }
3387
-        // check that $query_args isn't something crazy
3388
-        if (! is_array($query_args)) {
3389
-            $query_args = [];
3390
-        }
3391
-        /**
3392
-         * Allow injecting actions before the query_args are modified for possible different
3393
-         * redirections on save and close actions
3394
-         *
3395
-         * @param array $query_args       The original query_args array coming into the
3396
-         *                                method.
3397
-         * @since 4.2.0
3398
-         */
3399
-        do_action(
3400
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3401
-            $query_args
3402
-        );
3403
-        // calculate where we're going (if we have a "save and close" button pushed)
3404
-
3405
-        if (
3406
-            $this->request->requestParamIsSet('save_and_close')
3407
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3408
-        ) {
3409
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3410
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3411
-            // regenerate query args array from referrer URL
3412
-            parse_str($parsed_url['query'], $query_args);
3413
-            // correct page and action will be in the query args now
3414
-            $redirect_url = admin_url('admin.php');
3415
-        }
3416
-        // merge any default query_args set in _default_route_query_args property
3417
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3418
-            $args_to_merge = [];
3419
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3420
-                // is there a wp_referer array in our _default_route_query_args property?
3421
-                if ($query_param === 'wp_referer') {
3422
-                    $query_value = (array) $query_value;
3423
-                    foreach ($query_value as $reference => $value) {
3424
-                        if (strpos($reference, 'nonce') !== false) {
3425
-                            continue;
3426
-                        }
3427
-                        // finally we will override any arguments in the referer with
3428
-                        // what might be set on the _default_route_query_args array.
3429
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3430
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3431
-                        } else {
3432
-                            $args_to_merge[ $reference ] = urlencode($value);
3433
-                        }
3434
-                    }
3435
-                    continue;
3436
-                }
3437
-                $args_to_merge[ $query_param ] = $query_value;
3438
-            }
3439
-            // now let's merge these arguments but override with what was specifically sent in to the
3440
-            // redirect.
3441
-            $query_args = array_merge($args_to_merge, $query_args);
3442
-        }
3443
-        $this->_process_notices($query_args);
3444
-        // generate redirect url
3445
-        // if redirecting to anything other than the main page, add a nonce
3446
-        if (isset($query_args['action'])) {
3447
-            // manually generate wp_nonce and merge that with the query vars
3448
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3449
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3450
-        }
3451
-        // we're adding some hooks and filters in here for processing any things just before redirects
3452
-        // (example: an admin page has done an insert or update and we want to run something after that).
3453
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3454
-        $redirect_url = apply_filters(
3455
-            'FHEE_redirect_' . $classname . $this->_req_action,
3456
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3457
-            $query_args
3458
-        );
3459
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3460
-        if ($this->request->isAjax()) {
3461
-            $default_data                    = [
3462
-                'close'        => true,
3463
-                'redirect_url' => $redirect_url,
3464
-                'where'        => 'main',
3465
-                'what'         => 'append',
3466
-            ];
3467
-            $this->_template_args['success'] = $success;
3468
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3469
-                $default_data,
3470
-                $this->_template_args['data']
3471
-            ) : $default_data;
3472
-            $this->_return_json();
3473
-        }
3474
-        wp_safe_redirect($redirect_url);
3475
-        exit();
3476
-    }
3477
-
3478
-
3479
-    /**
3480
-     * process any notices before redirecting (or returning ajax request)
3481
-     * This method sets the $this->_template_args['notices'] attribute;
3482
-     *
3483
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3484
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3485
-     *                                  page_routes haven't been defined yet.
3486
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3487
-     *                                  still save a transient for the notice.
3488
-     * @return void
3489
-     * @throws EE_Error
3490
-     * @throws InvalidArgumentException
3491
-     * @throws InvalidDataTypeException
3492
-     * @throws InvalidInterfaceException
3493
-     */
3494
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3495
-    {
3496
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3497
-        if ($this->request->isAjax()) {
3498
-            $notices = EE_Error::get_notices(false);
3499
-            if (empty($this->_template_args['success'])) {
3500
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3501
-            }
3502
-            if (empty($this->_template_args['errors'])) {
3503
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3504
-            }
3505
-            if (empty($this->_template_args['attention'])) {
3506
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3507
-            }
3508
-        }
3509
-        $this->_template_args['notices'] = EE_Error::get_notices();
3510
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3511
-        if (! $this->request->isAjax() || $sticky_notices) {
3512
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3513
-            $this->_add_transient(
3514
-                $route,
3515
-                $this->_template_args['notices'],
3516
-                true,
3517
-                $skip_route_verify
3518
-            );
3519
-        }
3520
-    }
3521
-
3522
-
3523
-    /**
3524
-     * get_action_link_or_button
3525
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3526
-     *
3527
-     * @param string $action        use this to indicate which action the url is generated with.
3528
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3529
-     *                              property.
3530
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3531
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3532
-     * @param string $base_url      If this is not provided
3533
-     *                              the _admin_base_url will be used as the default for the button base_url.
3534
-     *                              Otherwise this value will be used.
3535
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3536
-     * @return string
3537
-     * @throws InvalidArgumentException
3538
-     * @throws InvalidInterfaceException
3539
-     * @throws InvalidDataTypeException
3540
-     * @throws EE_Error
3541
-     */
3542
-    public function get_action_link_or_button(
3543
-        $action,
3544
-        $type = 'add',
3545
-        $extra_request = [],
3546
-        $class = 'button-primary',
3547
-        $base_url = '',
3548
-        $exclude_nonce = false
3549
-    ) {
3550
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3551
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3552
-            throw new EE_Error(
3553
-                sprintf(
3554
-                    esc_html__(
3555
-                        'There is no page route for given action for the button.  This action was given: %s',
3556
-                        'event_espresso'
3557
-                    ),
3558
-                    $action
3559
-                )
3560
-            );
3561
-        }
3562
-        if (! isset($this->_labels['buttons'][ $type ])) {
3563
-            throw new EE_Error(
3564
-                sprintf(
3565
-                    esc_html__(
3566
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3567
-                        'event_espresso'
3568
-                    ),
3569
-                    $type
3570
-                )
3571
-            );
3572
-        }
3573
-        // finally check user access for this button.
3574
-        $has_access = $this->check_user_access($action, true);
3575
-        if (! $has_access) {
3576
-            return '';
3577
-        }
3578
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3579
-        $query_args = [
3580
-            'action' => $action,
3581
-        ];
3582
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3583
-        if (! empty($extra_request)) {
3584
-            $query_args = array_merge($extra_request, $query_args);
3585
-        }
3586
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3587
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3588
-    }
3589
-
3590
-
3591
-    /**
3592
-     * _per_page_screen_option
3593
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3594
-     *
3595
-     * @return void
3596
-     * @throws InvalidArgumentException
3597
-     * @throws InvalidInterfaceException
3598
-     * @throws InvalidDataTypeException
3599
-     */
3600
-    protected function _per_page_screen_option()
3601
-    {
3602
-        $option = 'per_page';
3603
-        $args   = [
3604
-            'label'   => apply_filters(
3605
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3606
-                $this->_admin_page_title,
3607
-                $this
3608
-            ),
3609
-            'default' => (int) apply_filters(
3610
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3611
-                20
3612
-            ),
3613
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3614
-        ];
3615
-        // ONLY add the screen option if the user has access to it.
3616
-        if ($this->check_user_access($this->_current_view, true)) {
3617
-            add_screen_option($option, $args);
3618
-        }
3619
-    }
3620
-
3621
-
3622
-    /**
3623
-     * set_per_page_screen_option
3624
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3625
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3626
-     * admin_menu.
3627
-     *
3628
-     * @return void
3629
-     */
3630
-    private function _set_per_page_screen_options()
3631
-    {
3632
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3633
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3634
-            if (! $user = wp_get_current_user()) {
3635
-                return;
3636
-            }
3637
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3638
-            if (! $option) {
3639
-                return;
3640
-            }
3641
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3642
-            $map_option = $option;
3643
-            $option     = str_replace('-', '_', $option);
3644
-            switch ($map_option) {
3645
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3646
-                    $max_value = apply_filters(
3647
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3648
-                        999,
3649
-                        $this->_current_page,
3650
-                        $this->_current_view
3651
-                    );
3652
-                    if ($value < 1) {
3653
-                        return;
3654
-                    }
3655
-                    $value = min($value, $max_value);
3656
-                    break;
3657
-                default:
3658
-                    $value = apply_filters(
3659
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3660
-                        false,
3661
-                        $option,
3662
-                        $value
3663
-                    );
3664
-                    if (false === $value) {
3665
-                        return;
3666
-                    }
3667
-                    break;
3668
-            }
3669
-            update_user_meta($user->ID, $option, $value);
3670
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3671
-            exit;
3672
-        }
3673
-    }
3674
-
3675
-
3676
-    /**
3677
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3678
-     *
3679
-     * @param array $data array that will be assigned to template args.
3680
-     */
3681
-    public function set_template_args($data)
3682
-    {
3683
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3684
-    }
3685
-
3686
-
3687
-    /**
3688
-     * This makes available the WP transient system for temporarily moving data between routes
3689
-     *
3690
-     * @param string $route             the route that should receive the transient
3691
-     * @param array  $data              the data that gets sent
3692
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3693
-     *                                  normal route transient.
3694
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3695
-     *                                  when we are adding a transient before page_routes have been defined.
3696
-     * @return void
3697
-     * @throws EE_Error
3698
-     */
3699
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3700
-    {
3701
-        $user_id = get_current_user_id();
3702
-        if (! $skip_route_verify) {
3703
-            $this->_verify_route($route);
3704
-        }
3705
-        // now let's set the string for what kind of transient we're setting
3706
-        $transient = $notices
3707
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3708
-            : 'rte_tx_' . $route . '_' . $user_id;
3709
-        $data      = $notices ? ['notices' => $data] : $data;
3710
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3711
-        $existing = is_multisite() && is_network_admin()
3712
-            ? get_site_transient($transient)
3713
-            : get_transient($transient);
3714
-        if ($existing) {
3715
-            $data = array_merge((array) $data, (array) $existing);
3716
-        }
3717
-        if (is_multisite() && is_network_admin()) {
3718
-            set_site_transient($transient, $data, 8);
3719
-        } else {
3720
-            set_transient($transient, $data, 8);
3721
-        }
3722
-    }
3723
-
3724
-
3725
-    /**
3726
-     * this retrieves the temporary transient that has been set for moving data between routes.
3727
-     *
3728
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3729
-     * @param string $route
3730
-     * @return mixed data
3731
-     */
3732
-    protected function _get_transient($notices = false, $route = '')
3733
-    {
3734
-        $user_id   = get_current_user_id();
3735
-        $route     = ! $route ? $this->_req_action : $route;
3736
-        $transient = $notices
3737
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3738
-            : 'rte_tx_' . $route . '_' . $user_id;
3739
-        $data      = is_multisite() && is_network_admin()
3740
-            ? get_site_transient($transient)
3741
-            : get_transient($transient);
3742
-        // delete transient after retrieval (just in case it hasn't expired);
3743
-        if (is_multisite() && is_network_admin()) {
3744
-            delete_site_transient($transient);
3745
-        } else {
3746
-            delete_transient($transient);
3747
-        }
3748
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3749
-    }
3750
-
3751
-
3752
-    /**
3753
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3754
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3755
-     * default route callback on the EE_Admin page you want it run.)
3756
-     *
3757
-     * @return void
3758
-     */
3759
-    protected function _transient_garbage_collection()
3760
-    {
3761
-        global $wpdb;
3762
-        // retrieve all existing transients
3763
-        $query =
3764
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3765
-        if ($results = $wpdb->get_results($query)) {
3766
-            foreach ($results as $result) {
3767
-                $transient = str_replace('_transient_', '', $result->option_name);
3768
-                get_transient($transient);
3769
-                if (is_multisite() && is_network_admin()) {
3770
-                    get_site_transient($transient);
3771
-                }
3772
-            }
3773
-        }
3774
-    }
3775
-
3776
-
3777
-    /**
3778
-     * get_view
3779
-     *
3780
-     * @return string content of _view property
3781
-     */
3782
-    public function get_view()
3783
-    {
3784
-        return $this->_view;
3785
-    }
3786
-
3787
-
3788
-    /**
3789
-     * getter for the protected $_views property
3790
-     *
3791
-     * @return array
3792
-     */
3793
-    public function get_views()
3794
-    {
3795
-        return $this->_views;
3796
-    }
3797
-
3798
-
3799
-    /**
3800
-     * get_current_page
3801
-     *
3802
-     * @return string _current_page property value
3803
-     */
3804
-    public function get_current_page()
3805
-    {
3806
-        return $this->_current_page;
3807
-    }
3808
-
3809
-
3810
-    /**
3811
-     * get_current_view
3812
-     *
3813
-     * @return string _current_view property value
3814
-     */
3815
-    public function get_current_view()
3816
-    {
3817
-        return $this->_current_view;
3818
-    }
3819
-
3820
-
3821
-    /**
3822
-     * get_current_screen
3823
-     *
3824
-     * @return object The current WP_Screen object
3825
-     */
3826
-    public function get_current_screen()
3827
-    {
3828
-        return $this->_current_screen;
3829
-    }
3830
-
3831
-
3832
-    /**
3833
-     * get_current_page_view_url
3834
-     *
3835
-     * @return string This returns the url for the current_page_view.
3836
-     */
3837
-    public function get_current_page_view_url()
3838
-    {
3839
-        return $this->_current_page_view_url;
3840
-    }
3841
-
3842
-
3843
-    /**
3844
-     * just returns the Request
3845
-     *
3846
-     * @return RequestInterface
3847
-     */
3848
-    public function get_request()
3849
-    {
3850
-        return $this->request;
3851
-    }
3852
-
3853
-
3854
-    /**
3855
-     * just returns the _req_data property
3856
-     *
3857
-     * @return array
3858
-     */
3859
-    public function get_request_data()
3860
-    {
3861
-        return $this->request->requestParams();
3862
-    }
3863
-
3864
-
3865
-    /**
3866
-     * returns the _req_data protected property
3867
-     *
3868
-     * @return string
3869
-     */
3870
-    public function get_req_action()
3871
-    {
3872
-        return $this->_req_action;
3873
-    }
3874
-
3875
-
3876
-    /**
3877
-     * @return bool  value of $_is_caf property
3878
-     */
3879
-    public function is_caf()
3880
-    {
3881
-        return $this->_is_caf;
3882
-    }
3883
-
3884
-
3885
-    /**
3886
-     * @return mixed
3887
-     */
3888
-    public function default_espresso_metaboxes()
3889
-    {
3890
-        return $this->_default_espresso_metaboxes;
3891
-    }
3892
-
3893
-
3894
-    /**
3895
-     * @return mixed
3896
-     */
3897
-    public function admin_base_url()
3898
-    {
3899
-        return $this->_admin_base_url;
3900
-    }
3901
-
3902
-
3903
-    /**
3904
-     * @return mixed
3905
-     */
3906
-    public function wp_page_slug()
3907
-    {
3908
-        return $this->_wp_page_slug;
3909
-    }
3910
-
3911
-
3912
-    /**
3913
-     * updates  espresso configuration settings
3914
-     *
3915
-     * @param string                   $tab
3916
-     * @param EE_Config_Base|EE_Config $config
3917
-     * @param string                   $file file where error occurred
3918
-     * @param string                   $func function  where error occurred
3919
-     * @param string                   $line line no where error occurred
3920
-     * @return boolean
3921
-     */
3922
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3923
-    {
3924
-        // remove any options that are NOT going to be saved with the config settings.
3925
-        if (isset($config->core->ee_ueip_optin)) {
3926
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3927
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3928
-            update_option('ee_ueip_has_notified', true);
3929
-        }
3930
-        // and save it (note we're also doing the network save here)
3931
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3932
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3933
-        if ($config_saved && $net_saved) {
3934
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3935
-            return true;
3936
-        }
3937
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3938
-        return false;
3939
-    }
3940
-
3941
-
3942
-    /**
3943
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3944
-     *
3945
-     * @return array
3946
-     */
3947
-    public function get_yes_no_values()
3948
-    {
3949
-        return $this->_yes_no_values;
3950
-    }
3951
-
3952
-
3953
-    /**
3954
-     * @return string
3955
-     * @throws ReflectionException
3956
-     * @since $VID:$
3957
-     */
3958
-    protected function _get_dir()
3959
-    {
3960
-        $reflector = new ReflectionClass(get_class($this));
3961
-        return dirname($reflector->getFileName());
3962
-    }
3963
-
3964
-
3965
-    /**
3966
-     * A helper for getting a "next link".
3967
-     *
3968
-     * @param string $url   The url to link to
3969
-     * @param string $class The class to use.
3970
-     * @return string
3971
-     */
3972
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3973
-    {
3974
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3975
-    }
3976
-
3977
-
3978
-    /**
3979
-     * A helper for getting a "previous link".
3980
-     *
3981
-     * @param string $url   The url to link to
3982
-     * @param string $class The class to use.
3983
-     * @return string
3984
-     */
3985
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3986
-    {
3987
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3988
-    }
3989
-
3990
-
3991
-
3992
-
3993
-
3994
-
3995
-
3996
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3997
-
3998
-
3999
-    /**
4000
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4001
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4002
-     * _req_data array.
4003
-     *
4004
-     * @return bool success/fail
4005
-     * @throws EE_Error
4006
-     * @throws InvalidArgumentException
4007
-     * @throws ReflectionException
4008
-     * @throws InvalidDataTypeException
4009
-     * @throws InvalidInterfaceException
4010
-     */
4011
-    protected function _process_resend_registration()
4012
-    {
4013
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4014
-        do_action(
4015
-            'AHEE__EE_Admin_Page___process_resend_registration',
4016
-            $this->_template_args['success'],
4017
-            $this->request->requestParams()
4018
-        );
4019
-        return $this->_template_args['success'];
4020
-    }
4021
-
4022
-
4023
-    /**
4024
-     * This automatically processes any payment message notifications when manual payment has been applied.
4025
-     *
4026
-     * @param EE_Payment $payment
4027
-     * @return bool success/fail
4028
-     */
4029
-    protected function _process_payment_notification(EE_Payment $payment)
4030
-    {
4031
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4032
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4033
-        $this->_template_args['success'] = apply_filters(
4034
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4035
-            false,
4036
-            $payment
4037
-        );
4038
-        return $this->_template_args['success'];
4039
-    }
2555
+	}
2556
+
2557
+
2558
+	/**
2559
+	 * facade for add_meta_box
2560
+	 *
2561
+	 * @param string  $action        where the metabox gets displayed
2562
+	 * @param string  $title         Title of Metabox (output in metabox header)
2563
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2564
+	 *                               instead of the one created in here.
2565
+	 * @param array   $callback_args an array of args supplied for the metabox
2566
+	 * @param string  $column        what metabox column
2567
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2568
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2569
+	 *                               created but just set our own callback for wp's add_meta_box.
2570
+	 * @throws DomainException
2571
+	 */
2572
+	public function _add_admin_page_meta_box(
2573
+		$action,
2574
+		$title,
2575
+		$callback,
2576
+		$callback_args,
2577
+		$column = 'normal',
2578
+		$priority = 'high',
2579
+		$create_func = true
2580
+	) {
2581
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2582
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2583
+		if (empty($callback_args) && $create_func) {
2584
+			$callback_args = [
2585
+				'template_path' => $this->_template_path,
2586
+				'template_args' => $this->_template_args,
2587
+			];
2588
+		}
2589
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2590
+		$call_back_func = $create_func
2591
+			? static function ($post, $metabox) {
2592
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2593
+				echo EEH_Template::display_template(
2594
+					$metabox['args']['template_path'],
2595
+					$metabox['args']['template_args'],
2596
+					true
2597
+				);
2598
+			}
2599
+			: $callback;
2600
+		add_meta_box(
2601
+			str_replace('_', '-', $action) . '-mbox',
2602
+			$title,
2603
+			$call_back_func,
2604
+			$this->_wp_page_slug,
2605
+			$column,
2606
+			$priority,
2607
+			$callback_args
2608
+		);
2609
+	}
2610
+
2611
+
2612
+	/**
2613
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2614
+	 *
2615
+	 * @throws DomainException
2616
+	 * @throws EE_Error
2617
+	 * @throws InvalidArgumentException
2618
+	 * @throws InvalidDataTypeException
2619
+	 * @throws InvalidInterfaceException
2620
+	 */
2621
+	public function display_admin_page_with_metabox_columns()
2622
+	{
2623
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2624
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2625
+			$this->_column_template_path,
2626
+			$this->_template_args,
2627
+			true
2628
+		);
2629
+		// the final wrapper
2630
+		$this->admin_page_wrapper();
2631
+	}
2632
+
2633
+
2634
+	/**
2635
+	 * generates  HTML wrapper for an admin details page
2636
+	 *
2637
+	 * @return void
2638
+	 * @throws DomainException
2639
+	 * @throws EE_Error
2640
+	 * @throws InvalidArgumentException
2641
+	 * @throws InvalidDataTypeException
2642
+	 * @throws InvalidInterfaceException
2643
+	 */
2644
+	public function display_admin_page_with_sidebar()
2645
+	{
2646
+		$this->_display_admin_page(true);
2647
+	}
2648
+
2649
+
2650
+	/**
2651
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2652
+	 *
2653
+	 * @return void
2654
+	 * @throws DomainException
2655
+	 * @throws EE_Error
2656
+	 * @throws InvalidArgumentException
2657
+	 * @throws InvalidDataTypeException
2658
+	 * @throws InvalidInterfaceException
2659
+	 */
2660
+	public function display_admin_page_with_no_sidebar()
2661
+	{
2662
+		$this->_display_admin_page();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2668
+	 *
2669
+	 * @return void
2670
+	 * @throws DomainException
2671
+	 * @throws EE_Error
2672
+	 * @throws InvalidArgumentException
2673
+	 * @throws InvalidDataTypeException
2674
+	 * @throws InvalidInterfaceException
2675
+	 */
2676
+	public function display_about_admin_page()
2677
+	{
2678
+		$this->_display_admin_page(false, true);
2679
+	}
2680
+
2681
+
2682
+	/**
2683
+	 * display_admin_page
2684
+	 * contains the code for actually displaying an admin page
2685
+	 *
2686
+	 * @param boolean $sidebar true with sidebar, false without
2687
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2688
+	 * @return void
2689
+	 * @throws DomainException
2690
+	 * @throws EE_Error
2691
+	 * @throws InvalidArgumentException
2692
+	 * @throws InvalidDataTypeException
2693
+	 * @throws InvalidInterfaceException
2694
+	 */
2695
+	private function _display_admin_page($sidebar = false, $about = false)
2696
+	{
2697
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2698
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2699
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2700
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2701
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2702
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2703
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2704
+			? 'poststuff'
2705
+			: 'espresso-default-admin';
2706
+		$template_path                                     = $sidebar
2707
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2708
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2709
+		if ($this->request->isAjax()) {
2710
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2711
+		}
2712
+		$template_path                                     = ! empty($this->_column_template_path)
2713
+			? $this->_column_template_path : $template_path;
2714
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2715
+			? $this->_template_args['admin_page_content']
2716
+			: '';
2717
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2718
+			? $this->_template_args['before_admin_page_content']
2719
+			: '';
2720
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2721
+			? $this->_template_args['after_admin_page_content']
2722
+			: '';
2723
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2724
+			$template_path,
2725
+			$this->_template_args,
2726
+			true
2727
+		);
2728
+		// the final template wrapper
2729
+		$this->admin_page_wrapper($about);
2730
+	}
2731
+
2732
+
2733
+	/**
2734
+	 * This is used to display caf preview pages.
2735
+	 *
2736
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2737
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2738
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2739
+	 * @return void
2740
+	 * @throws DomainException
2741
+	 * @throws EE_Error
2742
+	 * @throws InvalidArgumentException
2743
+	 * @throws InvalidDataTypeException
2744
+	 * @throws InvalidInterfaceException
2745
+	 * @since 4.3.2
2746
+	 */
2747
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2748
+	{
2749
+		// let's generate a default preview action button if there isn't one already present.
2750
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2751
+			'Upgrade to Event Espresso 4 Right Now',
2752
+			'event_espresso'
2753
+		);
2754
+		$buy_now_url                                   = add_query_arg(
2755
+			[
2756
+				'ee_ver'       => 'ee4',
2757
+				'utm_source'   => 'ee4_plugin_admin',
2758
+				'utm_medium'   => 'link',
2759
+				'utm_campaign' => $utm_campaign_source,
2760
+				'utm_content'  => 'buy_now_button',
2761
+			],
2762
+			'https://eventespresso.com/pricing/'
2763
+		);
2764
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2765
+			? $this->get_action_link_or_button(
2766
+				'',
2767
+				'buy_now',
2768
+				[],
2769
+				'button-primary button-large',
2770
+				esc_url_raw($buy_now_url),
2771
+				true
2772
+			)
2773
+			: $this->_template_args['preview_action_button'];
2774
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2775
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2776
+			$this->_template_args,
2777
+			true
2778
+		);
2779
+		$this->_display_admin_page($display_sidebar);
2780
+	}
2781
+
2782
+
2783
+	/**
2784
+	 * display_admin_list_table_page_with_sidebar
2785
+	 * generates HTML wrapper for an admin_page with list_table
2786
+	 *
2787
+	 * @return void
2788
+	 * @throws DomainException
2789
+	 * @throws EE_Error
2790
+	 * @throws InvalidArgumentException
2791
+	 * @throws InvalidDataTypeException
2792
+	 * @throws InvalidInterfaceException
2793
+	 */
2794
+	public function display_admin_list_table_page_with_sidebar()
2795
+	{
2796
+		$this->_display_admin_list_table_page(true);
2797
+	}
2798
+
2799
+
2800
+	/**
2801
+	 * display_admin_list_table_page_with_no_sidebar
2802
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2803
+	 *
2804
+	 * @return void
2805
+	 * @throws DomainException
2806
+	 * @throws EE_Error
2807
+	 * @throws InvalidArgumentException
2808
+	 * @throws InvalidDataTypeException
2809
+	 * @throws InvalidInterfaceException
2810
+	 */
2811
+	public function display_admin_list_table_page_with_no_sidebar()
2812
+	{
2813
+		$this->_display_admin_list_table_page();
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * generates html wrapper for an admin_list_table page
2819
+	 *
2820
+	 * @param boolean $sidebar whether to display with sidebar or not.
2821
+	 * @return void
2822
+	 * @throws DomainException
2823
+	 * @throws EE_Error
2824
+	 * @throws InvalidArgumentException
2825
+	 * @throws InvalidDataTypeException
2826
+	 * @throws InvalidInterfaceException
2827
+	 */
2828
+	private function _display_admin_list_table_page($sidebar = false)
2829
+	{
2830
+		// setup search attributes
2831
+		$this->_set_search_attributes();
2832
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2833
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2834
+		$this->_template_args['table_url']        = $this->request->isAjax()
2835
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2836
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2837
+		$this->_template_args['list_table']       = $this->_list_table_object;
2838
+		$this->_template_args['current_route']    = $this->_req_action;
2839
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2840
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2841
+		if (! empty($ajax_sorting_callback)) {
2842
+			$sortable_list_table_form_fields = wp_nonce_field(
2843
+				$ajax_sorting_callback . '_nonce',
2844
+				$ajax_sorting_callback . '_nonce',
2845
+				false,
2846
+				false
2847
+			);
2848
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2849
+												. $this->page_slug
2850
+												. '" />';
2851
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2852
+												. $ajax_sorting_callback
2853
+												. '" />';
2854
+		} else {
2855
+			$sortable_list_table_form_fields = '';
2856
+		}
2857
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2858
+		$hidden_form_fields                                      =
2859
+			isset($this->_template_args['list_table_hidden_fields'])
2860
+				? $this->_template_args['list_table_hidden_fields']
2861
+				: '';
2862
+		$nonce_ref                                               = $this->_req_action . '_nonce';
2863
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
2864
+																	. $nonce_ref
2865
+																	. '" value="'
2866
+																	. wp_create_nonce($nonce_ref)
2867
+																	. '">';
2868
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2869
+		// display message about search results?
2870
+		$search = $this->request->getRequestParam('s');
2871
+		$this->_template_args['before_list_table'] .= ! empty($search)
2872
+			? '<p class="ee-search-results">' . sprintf(
2873
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2874
+				trim($search, '%')
2875
+			) . '</p>'
2876
+			: '';
2877
+		// filter before_list_table template arg
2878
+		$this->_template_args['before_list_table'] = apply_filters(
2879
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2880
+			$this->_template_args['before_list_table'],
2881
+			$this->page_slug,
2882
+			$this->request->requestParams(),
2883
+			$this->_req_action
2884
+		);
2885
+		// convert to array and filter again
2886
+		// arrays are easier to inject new items in a specific location,
2887
+		// but would not be backwards compatible, so we have to add a new filter
2888
+		$this->_template_args['before_list_table'] = implode(
2889
+			" \n",
2890
+			(array) apply_filters(
2891
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2892
+				(array) $this->_template_args['before_list_table'],
2893
+				$this->page_slug,
2894
+				$this->request->requestParams(),
2895
+				$this->_req_action
2896
+			)
2897
+		);
2898
+		// filter after_list_table template arg
2899
+		$this->_template_args['after_list_table'] = apply_filters(
2900
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2901
+			$this->_template_args['after_list_table'],
2902
+			$this->page_slug,
2903
+			$this->request->requestParams(),
2904
+			$this->_req_action
2905
+		);
2906
+		// convert to array and filter again
2907
+		// arrays are easier to inject new items in a specific location,
2908
+		// but would not be backwards compatible, so we have to add a new filter
2909
+		$this->_template_args['after_list_table']   = implode(
2910
+			" \n",
2911
+			(array) apply_filters(
2912
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2913
+				(array) $this->_template_args['after_list_table'],
2914
+				$this->page_slug,
2915
+				$this->request->requestParams(),
2916
+				$this->_req_action
2917
+			)
2918
+		);
2919
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2920
+			$template_path,
2921
+			$this->_template_args,
2922
+			true
2923
+		);
2924
+		// the final template wrapper
2925
+		if ($sidebar) {
2926
+			$this->display_admin_page_with_sidebar();
2927
+		} else {
2928
+			$this->display_admin_page_with_no_sidebar();
2929
+		}
2930
+	}
2931
+
2932
+
2933
+	/**
2934
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2935
+	 * html string for the legend.
2936
+	 * $items are expected in an array in the following format:
2937
+	 * $legend_items = array(
2938
+	 *        'item_id' => array(
2939
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2940
+	 *            'desc' => esc_html__('localized description of item');
2941
+	 *        )
2942
+	 * );
2943
+	 *
2944
+	 * @param array $items see above for format of array
2945
+	 * @return string html string of legend
2946
+	 * @throws DomainException
2947
+	 */
2948
+	protected function _display_legend($items)
2949
+	{
2950
+		$this->_template_args['items'] = apply_filters(
2951
+			'FHEE__EE_Admin_Page___display_legend__items',
2952
+			(array) $items,
2953
+			$this
2954
+		);
2955
+		/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
2956
+		$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
2957
+		if (! $status_change_notice->isDismissed()) {
2958
+			$this->_template_args['status_change_notice'] = EEH_Template::display_template(
2959
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
2960
+				[ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
2961
+				true
2962
+			);
2963
+		}
2964
+		return EEH_Template::display_template(
2965
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2966
+			$this->_template_args,
2967
+			true
2968
+		);
2969
+	}
2970
+
2971
+
2972
+	/**
2973
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2974
+	 * The returned json object is created from an array in the following format:
2975
+	 * array(
2976
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2977
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2978
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2979
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2980
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2981
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
2982
+	 *  that might be included in here)
2983
+	 * )
2984
+	 * The json object is populated by whatever is set in the $_template_args property.
2985
+	 *
2986
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2987
+	 *                                 instead of displayed.
2988
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2989
+	 * @return void
2990
+	 * @throws EE_Error
2991
+	 * @throws InvalidArgumentException
2992
+	 * @throws InvalidDataTypeException
2993
+	 * @throws InvalidInterfaceException
2994
+	 */
2995
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
2996
+	{
2997
+		// make sure any EE_Error notices have been handled.
2998
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2999
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3000
+		unset($this->_template_args['data']);
3001
+		$json = [
3002
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3003
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3004
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3005
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3006
+			'notices'   => EE_Error::get_notices(),
3007
+			'content'   => isset($this->_template_args['admin_page_content'])
3008
+				? $this->_template_args['admin_page_content'] : '',
3009
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3010
+			'isEEajax'  => true
3011
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3012
+		];
3013
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3014
+		if (null === error_get_last() || ! headers_sent()) {
3015
+			header('Content-Type: application/json; charset=UTF-8');
3016
+		}
3017
+		echo wp_json_encode($json);
3018
+		exit();
3019
+	}
3020
+
3021
+
3022
+	/**
3023
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3024
+	 *
3025
+	 * @return void
3026
+	 * @throws EE_Error
3027
+	 * @throws InvalidArgumentException
3028
+	 * @throws InvalidDataTypeException
3029
+	 * @throws InvalidInterfaceException
3030
+	 */
3031
+	public function return_json()
3032
+	{
3033
+		if ($this->request->isAjax()) {
3034
+			$this->_return_json();
3035
+		} else {
3036
+			throw new EE_Error(
3037
+				sprintf(
3038
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3039
+					__FUNCTION__
3040
+				)
3041
+			);
3042
+		}
3043
+	}
3044
+
3045
+
3046
+	/**
3047
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3048
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3049
+	 *
3050
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3051
+	 */
3052
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3053
+	{
3054
+		$this->_hook_obj = $hook_obj;
3055
+	}
3056
+
3057
+
3058
+	/**
3059
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3060
+	 *
3061
+	 * @param boolean $about whether to use the special about page wrapper or default.
3062
+	 * @return void
3063
+	 * @throws DomainException
3064
+	 * @throws EE_Error
3065
+	 * @throws InvalidArgumentException
3066
+	 * @throws InvalidDataTypeException
3067
+	 * @throws InvalidInterfaceException
3068
+	 */
3069
+	public function admin_page_wrapper($about = false)
3070
+	{
3071
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3072
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3073
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3074
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3075
+
3076
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3077
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3078
+			isset($this->_template_args['before_admin_page_content'])
3079
+				? $this->_template_args['before_admin_page_content']
3080
+				: ''
3081
+		);
3082
+
3083
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3084
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3085
+			isset($this->_template_args['after_admin_page_content'])
3086
+				? $this->_template_args['after_admin_page_content']
3087
+				: ''
3088
+		);
3089
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3090
+
3091
+		if ($this->request->isAjax()) {
3092
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3093
+				// $template_path,
3094
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3095
+				$this->_template_args,
3096
+				true
3097
+			);
3098
+			$this->_return_json();
3099
+		}
3100
+		// load settings page wrapper template
3101
+		$template_path = $about
3102
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3103
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3104
+
3105
+		EEH_Template::display_template($template_path, $this->_template_args);
3106
+	}
3107
+
3108
+
3109
+	/**
3110
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3111
+	 *
3112
+	 * @return string html
3113
+	 * @throws EE_Error
3114
+	 */
3115
+	protected function _get_main_nav_tabs()
3116
+	{
3117
+		// let's generate the html using the EEH_Tabbed_Content helper.
3118
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3119
+		// (rather than setting in the page_routes array)
3120
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3121
+	}
3122
+
3123
+
3124
+	/**
3125
+	 *        sort nav tabs
3126
+	 *
3127
+	 * @param $a
3128
+	 * @param $b
3129
+	 * @return int
3130
+	 */
3131
+	private function _sort_nav_tabs($a, $b)
3132
+	{
3133
+		if ($a['order'] === $b['order']) {
3134
+			return 0;
3135
+		}
3136
+		return ($a['order'] < $b['order']) ? -1 : 1;
3137
+	}
3138
+
3139
+
3140
+	/**
3141
+	 * generates HTML for the forms used on admin pages
3142
+	 *
3143
+	 * @param array  $input_vars - array of input field details
3144
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3145
+	 * @param bool   $id
3146
+	 * @return array|string
3147
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3148
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3149
+	 */
3150
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3151
+	{
3152
+		return $generator === 'string'
3153
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3154
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3155
+	}
3156
+
3157
+
3158
+	/**
3159
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3160
+	 *
3161
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3162
+	 *                                   Close" button.
3163
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3164
+	 *                                   'Save', [1] => 'save & close')
3165
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3166
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3167
+	 *                                   default actions by submitting some other value.
3168
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3169
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3170
+	 *                                   close (normal form handling).
3171
+	 */
3172
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3173
+	{
3174
+		// make sure $text and $actions are in an array
3175
+		$text          = (array) $text;
3176
+		$actions       = (array) $actions;
3177
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3178
+		$button_text   = ! empty($text)
3179
+			? $text
3180
+			: [
3181
+				esc_html__('Save', 'event_espresso'),
3182
+				esc_html__('Save and Close', 'event_espresso'),
3183
+			];
3184
+		$default_names = ['save', 'save_and_close'];
3185
+		$buttons = '';
3186
+		foreach ($button_text as $key => $button) {
3187
+			$ref     = $default_names[ $key ];
3188
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3189
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3190
+						. 'value="' . $button . '" name="' . $name . '" '
3191
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3192
+			if (! $both) {
3193
+				break;
3194
+			}
3195
+		}
3196
+		// add in a hidden index for the current page (so save and close redirects properly)
3197
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3198
+				   . $referrer_url
3199
+				   . '" />';
3200
+		$this->_template_args['save_buttons'] = $buttons;
3201
+	}
3202
+
3203
+
3204
+	/**
3205
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3206
+	 *
3207
+	 * @param string $route
3208
+	 * @param array  $additional_hidden_fields
3209
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3210
+	 * @since 4.6.0
3211
+	 */
3212
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3213
+	{
3214
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3215
+	}
3216
+
3217
+
3218
+	/**
3219
+	 * set form open and close tags on add/edit pages.
3220
+	 *
3221
+	 * @param string $route                    the route you want the form to direct to
3222
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3223
+	 * @return void
3224
+	 */
3225
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3226
+	{
3227
+		if (empty($route)) {
3228
+			$user_msg = esc_html__(
3229
+				'An error occurred. No action was set for this page\'s form.',
3230
+				'event_espresso'
3231
+			);
3232
+			$dev_msg  = $user_msg . "\n"
3233
+						. sprintf(
3234
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3235
+							__FUNCTION__,
3236
+							__CLASS__
3237
+						);
3238
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3239
+		}
3240
+		// open form
3241
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3242
+															 . $this->_admin_base_url
3243
+															 . '" id="'
3244
+															 . $route
3245
+															 . '_event_form" >';
3246
+		// add nonce
3247
+		$nonce                                             =
3248
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3249
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3250
+		// add REQUIRED form action
3251
+		$hidden_fields = [
3252
+			'action' => ['type' => 'hidden', 'value' => $route],
3253
+		];
3254
+		// merge arrays
3255
+		$hidden_fields = is_array($additional_hidden_fields)
3256
+			? array_merge($hidden_fields, $additional_hidden_fields)
3257
+			: $hidden_fields;
3258
+		// generate form fields
3259
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3260
+		// add fields to form
3261
+		foreach ((array) $form_fields as $form_field) {
3262
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3263
+		}
3264
+		// close form
3265
+		$this->_template_args['after_admin_page_content'] = '</form>';
3266
+	}
3267
+
3268
+
3269
+	/**
3270
+	 * Public Wrapper for _redirect_after_action() method since its
3271
+	 * discovered it would be useful for external code to have access.
3272
+	 *
3273
+	 * @param bool   $success
3274
+	 * @param string $what
3275
+	 * @param string $action_desc
3276
+	 * @param array  $query_args
3277
+	 * @param bool   $override_overwrite
3278
+	 * @throws EE_Error
3279
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3280
+	 * @since 4.5.0
3281
+	 */
3282
+	public function redirect_after_action(
3283
+		$success = false,
3284
+		$what = 'item',
3285
+		$action_desc = 'processed',
3286
+		$query_args = [],
3287
+		$override_overwrite = false
3288
+	) {
3289
+		$this->_redirect_after_action(
3290
+			$success,
3291
+			$what,
3292
+			$action_desc,
3293
+			$query_args,
3294
+			$override_overwrite
3295
+		);
3296
+	}
3297
+
3298
+
3299
+	/**
3300
+	 * Helper method for merging existing request data with the returned redirect url.
3301
+	 *
3302
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3303
+	 * filters are still applied.
3304
+	 *
3305
+	 * @param array $new_route_data
3306
+	 * @return array
3307
+	 */
3308
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3309
+	{
3310
+		foreach ($this->request->requestParams() as $ref => $value) {
3311
+			// unset nonces
3312
+			if (strpos($ref, 'nonce') !== false) {
3313
+				$this->request->unSetRequestParam($ref);
3314
+				continue;
3315
+			}
3316
+			// urlencode values.
3317
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3318
+			$this->request->setRequestParam($ref, $value);
3319
+		}
3320
+		return array_merge($this->request->requestParams(), $new_route_data);
3321
+	}
3322
+
3323
+
3324
+	/**
3325
+	 *    _redirect_after_action
3326
+	 *
3327
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3328
+	 * @param string $what               - what the action was performed on
3329
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3330
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3331
+	 *                                   action is completed
3332
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3333
+	 *                                   override this so that they show.
3334
+	 * @return void
3335
+	 * @throws EE_Error
3336
+	 * @throws InvalidArgumentException
3337
+	 * @throws InvalidDataTypeException
3338
+	 * @throws InvalidInterfaceException
3339
+	 */
3340
+	protected function _redirect_after_action(
3341
+		$success = 0,
3342
+		$what = 'item',
3343
+		$action_desc = 'processed',
3344
+		$query_args = [],
3345
+		$override_overwrite = false
3346
+	) {
3347
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3348
+		// class name for actions/filters.
3349
+		$classname = get_class($this);
3350
+		// set redirect url.
3351
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3352
+		// otherwise we go with whatever is set as the _admin_base_url
3353
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3354
+		$notices      = EE_Error::get_notices(false);
3355
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3356
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3357
+			EE_Error::overwrite_success();
3358
+		}
3359
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3360
+			// how many records affected ? more than one record ? or just one ?
3361
+			if ($success > 1) {
3362
+				// set plural msg
3363
+				EE_Error::add_success(
3364
+					sprintf(
3365
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3366
+						$what,
3367
+						$action_desc
3368
+					),
3369
+					__FILE__,
3370
+					__FUNCTION__,
3371
+					__LINE__
3372
+				);
3373
+			} elseif ($success === 1) {
3374
+				// set singular msg
3375
+				EE_Error::add_success(
3376
+					sprintf(
3377
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3378
+						$what,
3379
+						$action_desc
3380
+					),
3381
+					__FILE__,
3382
+					__FUNCTION__,
3383
+					__LINE__
3384
+				);
3385
+			}
3386
+		}
3387
+		// check that $query_args isn't something crazy
3388
+		if (! is_array($query_args)) {
3389
+			$query_args = [];
3390
+		}
3391
+		/**
3392
+		 * Allow injecting actions before the query_args are modified for possible different
3393
+		 * redirections on save and close actions
3394
+		 *
3395
+		 * @param array $query_args       The original query_args array coming into the
3396
+		 *                                method.
3397
+		 * @since 4.2.0
3398
+		 */
3399
+		do_action(
3400
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3401
+			$query_args
3402
+		);
3403
+		// calculate where we're going (if we have a "save and close" button pushed)
3404
+
3405
+		if (
3406
+			$this->request->requestParamIsSet('save_and_close')
3407
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3408
+		) {
3409
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3410
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3411
+			// regenerate query args array from referrer URL
3412
+			parse_str($parsed_url['query'], $query_args);
3413
+			// correct page and action will be in the query args now
3414
+			$redirect_url = admin_url('admin.php');
3415
+		}
3416
+		// merge any default query_args set in _default_route_query_args property
3417
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3418
+			$args_to_merge = [];
3419
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3420
+				// is there a wp_referer array in our _default_route_query_args property?
3421
+				if ($query_param === 'wp_referer') {
3422
+					$query_value = (array) $query_value;
3423
+					foreach ($query_value as $reference => $value) {
3424
+						if (strpos($reference, 'nonce') !== false) {
3425
+							continue;
3426
+						}
3427
+						// finally we will override any arguments in the referer with
3428
+						// what might be set on the _default_route_query_args array.
3429
+						if (isset($this->_default_route_query_args[ $reference ])) {
3430
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3431
+						} else {
3432
+							$args_to_merge[ $reference ] = urlencode($value);
3433
+						}
3434
+					}
3435
+					continue;
3436
+				}
3437
+				$args_to_merge[ $query_param ] = $query_value;
3438
+			}
3439
+			// now let's merge these arguments but override with what was specifically sent in to the
3440
+			// redirect.
3441
+			$query_args = array_merge($args_to_merge, $query_args);
3442
+		}
3443
+		$this->_process_notices($query_args);
3444
+		// generate redirect url
3445
+		// if redirecting to anything other than the main page, add a nonce
3446
+		if (isset($query_args['action'])) {
3447
+			// manually generate wp_nonce and merge that with the query vars
3448
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3449
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3450
+		}
3451
+		// we're adding some hooks and filters in here for processing any things just before redirects
3452
+		// (example: an admin page has done an insert or update and we want to run something after that).
3453
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3454
+		$redirect_url = apply_filters(
3455
+			'FHEE_redirect_' . $classname . $this->_req_action,
3456
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3457
+			$query_args
3458
+		);
3459
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3460
+		if ($this->request->isAjax()) {
3461
+			$default_data                    = [
3462
+				'close'        => true,
3463
+				'redirect_url' => $redirect_url,
3464
+				'where'        => 'main',
3465
+				'what'         => 'append',
3466
+			];
3467
+			$this->_template_args['success'] = $success;
3468
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3469
+				$default_data,
3470
+				$this->_template_args['data']
3471
+			) : $default_data;
3472
+			$this->_return_json();
3473
+		}
3474
+		wp_safe_redirect($redirect_url);
3475
+		exit();
3476
+	}
3477
+
3478
+
3479
+	/**
3480
+	 * process any notices before redirecting (or returning ajax request)
3481
+	 * This method sets the $this->_template_args['notices'] attribute;
3482
+	 *
3483
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3484
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3485
+	 *                                  page_routes haven't been defined yet.
3486
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3487
+	 *                                  still save a transient for the notice.
3488
+	 * @return void
3489
+	 * @throws EE_Error
3490
+	 * @throws InvalidArgumentException
3491
+	 * @throws InvalidDataTypeException
3492
+	 * @throws InvalidInterfaceException
3493
+	 */
3494
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3495
+	{
3496
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3497
+		if ($this->request->isAjax()) {
3498
+			$notices = EE_Error::get_notices(false);
3499
+			if (empty($this->_template_args['success'])) {
3500
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3501
+			}
3502
+			if (empty($this->_template_args['errors'])) {
3503
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3504
+			}
3505
+			if (empty($this->_template_args['attention'])) {
3506
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3507
+			}
3508
+		}
3509
+		$this->_template_args['notices'] = EE_Error::get_notices();
3510
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3511
+		if (! $this->request->isAjax() || $sticky_notices) {
3512
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3513
+			$this->_add_transient(
3514
+				$route,
3515
+				$this->_template_args['notices'],
3516
+				true,
3517
+				$skip_route_verify
3518
+			);
3519
+		}
3520
+	}
3521
+
3522
+
3523
+	/**
3524
+	 * get_action_link_or_button
3525
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3526
+	 *
3527
+	 * @param string $action        use this to indicate which action the url is generated with.
3528
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3529
+	 *                              property.
3530
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3531
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3532
+	 * @param string $base_url      If this is not provided
3533
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3534
+	 *                              Otherwise this value will be used.
3535
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3536
+	 * @return string
3537
+	 * @throws InvalidArgumentException
3538
+	 * @throws InvalidInterfaceException
3539
+	 * @throws InvalidDataTypeException
3540
+	 * @throws EE_Error
3541
+	 */
3542
+	public function get_action_link_or_button(
3543
+		$action,
3544
+		$type = 'add',
3545
+		$extra_request = [],
3546
+		$class = 'button-primary',
3547
+		$base_url = '',
3548
+		$exclude_nonce = false
3549
+	) {
3550
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3551
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3552
+			throw new EE_Error(
3553
+				sprintf(
3554
+					esc_html__(
3555
+						'There is no page route for given action for the button.  This action was given: %s',
3556
+						'event_espresso'
3557
+					),
3558
+					$action
3559
+				)
3560
+			);
3561
+		}
3562
+		if (! isset($this->_labels['buttons'][ $type ])) {
3563
+			throw new EE_Error(
3564
+				sprintf(
3565
+					esc_html__(
3566
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3567
+						'event_espresso'
3568
+					),
3569
+					$type
3570
+				)
3571
+			);
3572
+		}
3573
+		// finally check user access for this button.
3574
+		$has_access = $this->check_user_access($action, true);
3575
+		if (! $has_access) {
3576
+			return '';
3577
+		}
3578
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3579
+		$query_args = [
3580
+			'action' => $action,
3581
+		];
3582
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3583
+		if (! empty($extra_request)) {
3584
+			$query_args = array_merge($extra_request, $query_args);
3585
+		}
3586
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3587
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3588
+	}
3589
+
3590
+
3591
+	/**
3592
+	 * _per_page_screen_option
3593
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3594
+	 *
3595
+	 * @return void
3596
+	 * @throws InvalidArgumentException
3597
+	 * @throws InvalidInterfaceException
3598
+	 * @throws InvalidDataTypeException
3599
+	 */
3600
+	protected function _per_page_screen_option()
3601
+	{
3602
+		$option = 'per_page';
3603
+		$args   = [
3604
+			'label'   => apply_filters(
3605
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3606
+				$this->_admin_page_title,
3607
+				$this
3608
+			),
3609
+			'default' => (int) apply_filters(
3610
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3611
+				20
3612
+			),
3613
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3614
+		];
3615
+		// ONLY add the screen option if the user has access to it.
3616
+		if ($this->check_user_access($this->_current_view, true)) {
3617
+			add_screen_option($option, $args);
3618
+		}
3619
+	}
3620
+
3621
+
3622
+	/**
3623
+	 * set_per_page_screen_option
3624
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3625
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3626
+	 * admin_menu.
3627
+	 *
3628
+	 * @return void
3629
+	 */
3630
+	private function _set_per_page_screen_options()
3631
+	{
3632
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3633
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3634
+			if (! $user = wp_get_current_user()) {
3635
+				return;
3636
+			}
3637
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3638
+			if (! $option) {
3639
+				return;
3640
+			}
3641
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3642
+			$map_option = $option;
3643
+			$option     = str_replace('-', '_', $option);
3644
+			switch ($map_option) {
3645
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3646
+					$max_value = apply_filters(
3647
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3648
+						999,
3649
+						$this->_current_page,
3650
+						$this->_current_view
3651
+					);
3652
+					if ($value < 1) {
3653
+						return;
3654
+					}
3655
+					$value = min($value, $max_value);
3656
+					break;
3657
+				default:
3658
+					$value = apply_filters(
3659
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3660
+						false,
3661
+						$option,
3662
+						$value
3663
+					);
3664
+					if (false === $value) {
3665
+						return;
3666
+					}
3667
+					break;
3668
+			}
3669
+			update_user_meta($user->ID, $option, $value);
3670
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3671
+			exit;
3672
+		}
3673
+	}
3674
+
3675
+
3676
+	/**
3677
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3678
+	 *
3679
+	 * @param array $data array that will be assigned to template args.
3680
+	 */
3681
+	public function set_template_args($data)
3682
+	{
3683
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3684
+	}
3685
+
3686
+
3687
+	/**
3688
+	 * This makes available the WP transient system for temporarily moving data between routes
3689
+	 *
3690
+	 * @param string $route             the route that should receive the transient
3691
+	 * @param array  $data              the data that gets sent
3692
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3693
+	 *                                  normal route transient.
3694
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3695
+	 *                                  when we are adding a transient before page_routes have been defined.
3696
+	 * @return void
3697
+	 * @throws EE_Error
3698
+	 */
3699
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3700
+	{
3701
+		$user_id = get_current_user_id();
3702
+		if (! $skip_route_verify) {
3703
+			$this->_verify_route($route);
3704
+		}
3705
+		// now let's set the string for what kind of transient we're setting
3706
+		$transient = $notices
3707
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3708
+			: 'rte_tx_' . $route . '_' . $user_id;
3709
+		$data      = $notices ? ['notices' => $data] : $data;
3710
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3711
+		$existing = is_multisite() && is_network_admin()
3712
+			? get_site_transient($transient)
3713
+			: get_transient($transient);
3714
+		if ($existing) {
3715
+			$data = array_merge((array) $data, (array) $existing);
3716
+		}
3717
+		if (is_multisite() && is_network_admin()) {
3718
+			set_site_transient($transient, $data, 8);
3719
+		} else {
3720
+			set_transient($transient, $data, 8);
3721
+		}
3722
+	}
3723
+
3724
+
3725
+	/**
3726
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3727
+	 *
3728
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3729
+	 * @param string $route
3730
+	 * @return mixed data
3731
+	 */
3732
+	protected function _get_transient($notices = false, $route = '')
3733
+	{
3734
+		$user_id   = get_current_user_id();
3735
+		$route     = ! $route ? $this->_req_action : $route;
3736
+		$transient = $notices
3737
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3738
+			: 'rte_tx_' . $route . '_' . $user_id;
3739
+		$data      = is_multisite() && is_network_admin()
3740
+			? get_site_transient($transient)
3741
+			: get_transient($transient);
3742
+		// delete transient after retrieval (just in case it hasn't expired);
3743
+		if (is_multisite() && is_network_admin()) {
3744
+			delete_site_transient($transient);
3745
+		} else {
3746
+			delete_transient($transient);
3747
+		}
3748
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3749
+	}
3750
+
3751
+
3752
+	/**
3753
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3754
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3755
+	 * default route callback on the EE_Admin page you want it run.)
3756
+	 *
3757
+	 * @return void
3758
+	 */
3759
+	protected function _transient_garbage_collection()
3760
+	{
3761
+		global $wpdb;
3762
+		// retrieve all existing transients
3763
+		$query =
3764
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3765
+		if ($results = $wpdb->get_results($query)) {
3766
+			foreach ($results as $result) {
3767
+				$transient = str_replace('_transient_', '', $result->option_name);
3768
+				get_transient($transient);
3769
+				if (is_multisite() && is_network_admin()) {
3770
+					get_site_transient($transient);
3771
+				}
3772
+			}
3773
+		}
3774
+	}
3775
+
3776
+
3777
+	/**
3778
+	 * get_view
3779
+	 *
3780
+	 * @return string content of _view property
3781
+	 */
3782
+	public function get_view()
3783
+	{
3784
+		return $this->_view;
3785
+	}
3786
+
3787
+
3788
+	/**
3789
+	 * getter for the protected $_views property
3790
+	 *
3791
+	 * @return array
3792
+	 */
3793
+	public function get_views()
3794
+	{
3795
+		return $this->_views;
3796
+	}
3797
+
3798
+
3799
+	/**
3800
+	 * get_current_page
3801
+	 *
3802
+	 * @return string _current_page property value
3803
+	 */
3804
+	public function get_current_page()
3805
+	{
3806
+		return $this->_current_page;
3807
+	}
3808
+
3809
+
3810
+	/**
3811
+	 * get_current_view
3812
+	 *
3813
+	 * @return string _current_view property value
3814
+	 */
3815
+	public function get_current_view()
3816
+	{
3817
+		return $this->_current_view;
3818
+	}
3819
+
3820
+
3821
+	/**
3822
+	 * get_current_screen
3823
+	 *
3824
+	 * @return object The current WP_Screen object
3825
+	 */
3826
+	public function get_current_screen()
3827
+	{
3828
+		return $this->_current_screen;
3829
+	}
3830
+
3831
+
3832
+	/**
3833
+	 * get_current_page_view_url
3834
+	 *
3835
+	 * @return string This returns the url for the current_page_view.
3836
+	 */
3837
+	public function get_current_page_view_url()
3838
+	{
3839
+		return $this->_current_page_view_url;
3840
+	}
3841
+
3842
+
3843
+	/**
3844
+	 * just returns the Request
3845
+	 *
3846
+	 * @return RequestInterface
3847
+	 */
3848
+	public function get_request()
3849
+	{
3850
+		return $this->request;
3851
+	}
3852
+
3853
+
3854
+	/**
3855
+	 * just returns the _req_data property
3856
+	 *
3857
+	 * @return array
3858
+	 */
3859
+	public function get_request_data()
3860
+	{
3861
+		return $this->request->requestParams();
3862
+	}
3863
+
3864
+
3865
+	/**
3866
+	 * returns the _req_data protected property
3867
+	 *
3868
+	 * @return string
3869
+	 */
3870
+	public function get_req_action()
3871
+	{
3872
+		return $this->_req_action;
3873
+	}
3874
+
3875
+
3876
+	/**
3877
+	 * @return bool  value of $_is_caf property
3878
+	 */
3879
+	public function is_caf()
3880
+	{
3881
+		return $this->_is_caf;
3882
+	}
3883
+
3884
+
3885
+	/**
3886
+	 * @return mixed
3887
+	 */
3888
+	public function default_espresso_metaboxes()
3889
+	{
3890
+		return $this->_default_espresso_metaboxes;
3891
+	}
3892
+
3893
+
3894
+	/**
3895
+	 * @return mixed
3896
+	 */
3897
+	public function admin_base_url()
3898
+	{
3899
+		return $this->_admin_base_url;
3900
+	}
3901
+
3902
+
3903
+	/**
3904
+	 * @return mixed
3905
+	 */
3906
+	public function wp_page_slug()
3907
+	{
3908
+		return $this->_wp_page_slug;
3909
+	}
3910
+
3911
+
3912
+	/**
3913
+	 * updates  espresso configuration settings
3914
+	 *
3915
+	 * @param string                   $tab
3916
+	 * @param EE_Config_Base|EE_Config $config
3917
+	 * @param string                   $file file where error occurred
3918
+	 * @param string                   $func function  where error occurred
3919
+	 * @param string                   $line line no where error occurred
3920
+	 * @return boolean
3921
+	 */
3922
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3923
+	{
3924
+		// remove any options that are NOT going to be saved with the config settings.
3925
+		if (isset($config->core->ee_ueip_optin)) {
3926
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3927
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3928
+			update_option('ee_ueip_has_notified', true);
3929
+		}
3930
+		// and save it (note we're also doing the network save here)
3931
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3932
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3933
+		if ($config_saved && $net_saved) {
3934
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3935
+			return true;
3936
+		}
3937
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3938
+		return false;
3939
+	}
3940
+
3941
+
3942
+	/**
3943
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3944
+	 *
3945
+	 * @return array
3946
+	 */
3947
+	public function get_yes_no_values()
3948
+	{
3949
+		return $this->_yes_no_values;
3950
+	}
3951
+
3952
+
3953
+	/**
3954
+	 * @return string
3955
+	 * @throws ReflectionException
3956
+	 * @since $VID:$
3957
+	 */
3958
+	protected function _get_dir()
3959
+	{
3960
+		$reflector = new ReflectionClass(get_class($this));
3961
+		return dirname($reflector->getFileName());
3962
+	}
3963
+
3964
+
3965
+	/**
3966
+	 * A helper for getting a "next link".
3967
+	 *
3968
+	 * @param string $url   The url to link to
3969
+	 * @param string $class The class to use.
3970
+	 * @return string
3971
+	 */
3972
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3973
+	{
3974
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3975
+	}
3976
+
3977
+
3978
+	/**
3979
+	 * A helper for getting a "previous link".
3980
+	 *
3981
+	 * @param string $url   The url to link to
3982
+	 * @param string $class The class to use.
3983
+	 * @return string
3984
+	 */
3985
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3986
+	{
3987
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3988
+	}
3989
+
3990
+
3991
+
3992
+
3993
+
3994
+
3995
+
3996
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3997
+
3998
+
3999
+	/**
4000
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4001
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4002
+	 * _req_data array.
4003
+	 *
4004
+	 * @return bool success/fail
4005
+	 * @throws EE_Error
4006
+	 * @throws InvalidArgumentException
4007
+	 * @throws ReflectionException
4008
+	 * @throws InvalidDataTypeException
4009
+	 * @throws InvalidInterfaceException
4010
+	 */
4011
+	protected function _process_resend_registration()
4012
+	{
4013
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4014
+		do_action(
4015
+			'AHEE__EE_Admin_Page___process_resend_registration',
4016
+			$this->_template_args['success'],
4017
+			$this->request->requestParams()
4018
+		);
4019
+		return $this->_template_args['success'];
4020
+	}
4021
+
4022
+
4023
+	/**
4024
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4025
+	 *
4026
+	 * @param EE_Payment $payment
4027
+	 * @return bool success/fail
4028
+	 */
4029
+	protected function _process_payment_notification(EE_Payment $payment)
4030
+	{
4031
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4032
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4033
+		$this->_template_args['success'] = apply_filters(
4034
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4035
+			false,
4036
+			$payment
4037
+		);
4038
+		return $this->_template_args['success'];
4039
+	}
4040 4040
 }
Please login to merge, or discard this patch.
Spacing   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
         $ee_menu_slugs = (array) $ee_menu_slugs;
601 601
         if (
602 602
             ! $this->request->isAjax()
603
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
603
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
604 604
         ) {
605 605
             return;
606 606
         }
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
             : $req_action;
621 621
 
622 622
         $this->_current_view = $this->_req_action;
623
-        $this->_req_nonce    = $this->_req_action . '_nonce';
623
+        $this->_req_nonce    = $this->_req_action.'_nonce';
624 624
         $this->_define_page_props();
625 625
         $this->_current_page_view_url = add_query_arg(
626 626
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -657,21 +657,21 @@  discard block
 block discarded – undo
657 657
         }
658 658
         // filter routes and page_config so addons can add their stuff. Filtering done per class
659 659
         $this->_page_routes = apply_filters(
660
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
660
+            'FHEE__'.get_class($this).'__page_setup__page_routes',
661 661
             $this->_page_routes,
662 662
             $this
663 663
         );
664 664
         $this->_page_config = apply_filters(
665
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
665
+            'FHEE__'.get_class($this).'__page_setup__page_config',
666 666
             $this->_page_config,
667 667
             $this
668 668
         );
669 669
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
670 670
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
671
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
671
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
672 672
             add_action(
673 673
                 'AHEE__EE_Admin_Page__route_admin_request',
674
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
674
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
675 675
                 10,
676 676
                 2
677 677
             );
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
             if ($this->_is_UI_request) {
685 685
                 // admin_init stuff - global, all views for this page class, specific view
686 686
                 add_action('admin_init', [$this, 'admin_init'], 10);
687
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
688
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
687
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
688
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
689 689
                 }
690 690
             } else {
691 691
                 // hijack regular WP loading and route admin request immediately
@@ -704,12 +704,12 @@  discard block
 block discarded – undo
704 704
      */
705 705
     private function _do_other_page_hooks()
706 706
     {
707
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
707
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
708 708
         foreach ($registered_pages as $page) {
709 709
             // now let's setup the file name and class that should be present
710 710
             $classname = str_replace('.class.php', '', $page);
711 711
             // autoloaders should take care of loading file
712
-            if (! class_exists($classname)) {
712
+            if ( ! class_exists($classname)) {
713 713
                 $error_msg[] = sprintf(
714 714
                     esc_html__(
715 715
                         'Something went wrong with loading the %s admin hooks page.',
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
                                    ),
727 727
                                    $page,
728 728
                                    '<br />',
729
-                                   '<strong>' . $classname . '</strong>'
729
+                                   '<strong>'.$classname.'</strong>'
730 730
                                );
731 731
                 throw new EE_Error(implode('||', $error_msg));
732 732
             }
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
         // load admin_notices - global, page class, and view specific
769 769
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
770 770
         add_action('admin_notices', [$this, 'admin_notices'], 10);
771
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
772
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
771
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
772
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
773 773
         }
774 774
         // load network admin_notices - global, page class, and view specific
775 775
         add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
776
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
777
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
776
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
777
+            add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]);
778 778
         }
779 779
         // this will save any per_page screen options if they are present
780 780
         $this->_set_per_page_screen_options();
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
     protected function _verify_routes()
896 896
     {
897 897
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
898
-        if (! $this->_current_page && ! $this->request->isAjax()) {
898
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
899 899
             return false;
900 900
         }
901 901
         $this->_route = false;
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
                 $this->_admin_page_title
908 908
             );
909 909
             // developer error msg
910
-            $error_msg .= '||' . $error_msg
910
+            $error_msg .= '||'.$error_msg
911 911
                           . esc_html__(
912 912
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
913 913
                               'event_espresso'
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
         }
917 917
         // and that the requested page route exists
918 918
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
919
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
920
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
919
+            $this->_route        = $this->_page_routes[$this->_req_action];
920
+            $this->_route_config = $this->_page_config[$this->_req_action] ?? [];
921 921
         } else {
922 922
             // user error msg
923 923
             $error_msg = sprintf(
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
                 $this->_admin_page_title
929 929
             );
930 930
             // developer error msg
931
-            $error_msg .= '||' . $error_msg
931
+            $error_msg .= '||'.$error_msg
932 932
                           . sprintf(
933 933
                               esc_html__(
934 934
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
             throw new EE_Error($error_msg);
940 940
         }
941 941
         // and that a default route exists
942
-        if (! array_key_exists('default', $this->_page_routes)) {
942
+        if ( ! array_key_exists('default', $this->_page_routes)) {
943 943
             // user error msg
944 944
             $error_msg = sprintf(
945 945
                 esc_html__(
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
                 $this->_admin_page_title
950 950
             );
951 951
             // developer error msg
952
-            $error_msg .= '||' . $error_msg
952
+            $error_msg .= '||'.$error_msg
953 953
                           . esc_html__(
954 954
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
955 955
                               'event_espresso'
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
             $this->_admin_page_title
992 992
         );
993 993
         // developer error msg
994
-        $error_msg .= '||' . $error_msg
994
+        $error_msg .= '||'.$error_msg
995 995
                       . sprintf(
996 996
                           esc_html__(
997 997
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
     protected function _verify_nonce($nonce, $nonce_ref)
1020 1020
     {
1021 1021
         // verify nonce against expected value
1022
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1022
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
1023 1023
             // these are not the droids you are looking for !!!
1024 1024
             $msg = sprintf(
1025 1025
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                     __CLASS__
1037 1037
                 );
1038 1038
             }
1039
-            if (! $this->request->isAjax()) {
1039
+            if ( ! $this->request->isAjax()) {
1040 1040
                 wp_die($msg);
1041 1041
             }
1042 1042
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -1060,7 +1060,7 @@  discard block
 block discarded – undo
1060 1060
      */
1061 1061
     protected function _route_admin_request()
1062 1062
     {
1063
-        if (! $this->_is_UI_request) {
1063
+        if ( ! $this->_is_UI_request) {
1064 1064
             $this->_verify_routes();
1065 1065
         }
1066 1066
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
         $error_msg = '';
1081 1081
         // action right before calling route
1082 1082
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1083
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1083
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1084 1084
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1085 1085
         }
1086 1086
         // right before calling the route, let's clean the _wp_http_referer
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
                 wp_unslash($this->request->getServerParam('REQUEST_URI'))
1092 1092
             )
1093 1093
         );
1094
-        if (! empty($func)) {
1094
+        if ( ! empty($func)) {
1095 1095
             if (is_array($func)) {
1096 1096
                 [$class, $method] = $func;
1097 1097
             } elseif (strpos($func, '::') !== false) {
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
                 $class  = $this;
1101 1101
                 $method = $func;
1102 1102
             }
1103
-            if (! (is_object($class) && $class === $this)) {
1103
+            if ( ! (is_object($class) && $class === $this)) {
1104 1104
                 // send along this admin page object for access by addons.
1105 1105
                 $args['admin_page_object'] = $this;
1106 1106
             }
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
                     $method
1142 1142
                 );
1143 1143
             }
1144
-            if (! empty($error_msg)) {
1144
+            if ( ! empty($error_msg)) {
1145 1145
                 throw new EE_Error($error_msg);
1146 1146
             }
1147 1147
         }
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
                 if (strpos($key, 'nonce') !== false) {
1227 1227
                     continue;
1228 1228
                 }
1229
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1229
+                $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value;
1230 1230
             }
1231 1231
         }
1232 1232
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1266,12 +1266,12 @@  discard block
 block discarded – undo
1266 1266
      */
1267 1267
     protected function _add_help_tabs()
1268 1268
     {
1269
-        if (isset($this->_page_config[ $this->_req_action ])) {
1270
-            $config = $this->_page_config[ $this->_req_action ];
1269
+        if (isset($this->_page_config[$this->_req_action])) {
1270
+            $config = $this->_page_config[$this->_req_action];
1271 1271
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1272 1272
             if (is_array($config) && isset($config['help_sidebar'])) {
1273 1273
                 // check that the callback given is valid
1274
-                if (! method_exists($this, $config['help_sidebar'])) {
1274
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1275 1275
                     throw new EE_Error(
1276 1276
                         sprintf(
1277 1277
                             esc_html__(
@@ -1284,18 +1284,18 @@  discard block
 block discarded – undo
1284 1284
                     );
1285 1285
                 }
1286 1286
                 $content = apply_filters(
1287
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1287
+                    'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar',
1288 1288
                     $this->{$config['help_sidebar']}()
1289 1289
                 );
1290 1290
                 $this->_current_screen->set_help_sidebar($content);
1291 1291
             }
1292
-            if (! isset($config['help_tabs'])) {
1292
+            if ( ! isset($config['help_tabs'])) {
1293 1293
                 return;
1294 1294
             } //no help tabs for this route
1295 1295
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1296 1296
                 // we're here so there ARE help tabs!
1297 1297
                 // make sure we've got what we need
1298
-                if (! isset($cfg['title'])) {
1298
+                if ( ! isset($cfg['title'])) {
1299 1299
                     throw new EE_Error(
1300 1300
                         esc_html__(
1301 1301
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
                         )
1304 1304
                     );
1305 1305
                 }
1306
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1306
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1307 1307
                     throw new EE_Error(
1308 1308
                         esc_html__(
1309 1309
                             'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
@@ -1312,11 +1312,11 @@  discard block
 block discarded – undo
1312 1312
                     );
1313 1313
                 }
1314 1314
                 // first priority goes to content.
1315
-                if (! empty($cfg['content'])) {
1315
+                if ( ! empty($cfg['content'])) {
1316 1316
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1317 1317
                     // second priority goes to filename
1318
-                } elseif (! empty($cfg['filename'])) {
1319
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1318
+                } elseif ( ! empty($cfg['filename'])) {
1319
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1320 1320
                     // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1321 1321
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1322 1322
                                                              . basename($this->_get_dir())
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
                                                              . $cfg['filename']
1325 1325
                                                              . '.help_tab.php' : $file_path;
1326 1326
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1327
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1327
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1328 1328
                         EE_Error::add_error(
1329 1329
                             sprintf(
1330 1330
                                 esc_html__(
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
                     return;
1373 1373
                 }
1374 1374
                 // setup config array for help tab method
1375
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1375
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1376 1376
                 $_ht = [
1377 1377
                     'id'       => $id,
1378 1378
                     'title'    => $cfg['title'],
@@ -1398,8 +1398,8 @@  discard block
 block discarded – undo
1398 1398
             $qtips = (array) $this->_route_config['qtips'];
1399 1399
             // load qtip loader
1400 1400
             $path = [
1401
-                $this->_get_dir() . '/qtips/',
1402
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1401
+                $this->_get_dir().'/qtips/',
1402
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1403 1403
             ];
1404 1404
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1405 1405
         }
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1422 1422
         $i = 0;
1423 1423
         foreach ($this->_page_config as $slug => $config) {
1424
-            if (! is_array($config) || empty($config['nav'])) {
1424
+            if ( ! is_array($config) || empty($config['nav'])) {
1425 1425
                 continue;
1426 1426
             }
1427 1427
             // no nav tab for this config
@@ -1430,12 +1430,12 @@  discard block
 block discarded – undo
1430 1430
                 // nav tab is only to appear when route requested.
1431 1431
                 continue;
1432 1432
             }
1433
-            if (! $this->check_user_access($slug, true)) {
1433
+            if ( ! $this->check_user_access($slug, true)) {
1434 1434
                 // no nav tab because current user does not have access.
1435 1435
                 continue;
1436 1436
             }
1437
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1438
-            $this->_nav_tabs[ $slug ] = [
1437
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1438
+            $this->_nav_tabs[$slug] = [
1439 1439
                 'url'       => isset($config['nav']['url'])
1440 1440
                     ? $config['nav']['url']
1441 1441
                     : EE_Admin_Page::add_query_args_and_nonce(
@@ -1447,14 +1447,14 @@  discard block
 block discarded – undo
1447 1447
                     : ucwords(
1448 1448
                         str_replace('_', ' ', $slug)
1449 1449
                     ),
1450
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1450
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1451 1451
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1452 1452
             ];
1453 1453
             $i++;
1454 1454
         }
1455 1455
         // if $this->_nav_tabs is empty then lets set the default
1456 1456
         if (empty($this->_nav_tabs)) {
1457
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1457
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1458 1458
                 'url'       => $this->_admin_base_url,
1459 1459
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1460 1460
                 'css_class' => 'nav-tab-active',
@@ -1479,10 +1479,10 @@  discard block
 block discarded – undo
1479 1479
             foreach ($this->_route_config['labels'] as $label => $text) {
1480 1480
                 if (is_array($text)) {
1481 1481
                     foreach ($text as $sublabel => $subtext) {
1482
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1482
+                        $this->_labels[$label][$sublabel] = $subtext;
1483 1483
                     }
1484 1484
                 } else {
1485
-                    $this->_labels[ $label ] = $text;
1485
+                    $this->_labels[$label] = $text;
1486 1486
                 }
1487 1487
             }
1488 1488
         }
@@ -1504,12 +1504,12 @@  discard block
 block discarded – undo
1504 1504
     {
1505 1505
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1506 1506
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1507
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1507
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1508 1508
                           && is_array(
1509
-                              $this->_page_routes[ $route_to_check ]
1509
+                              $this->_page_routes[$route_to_check]
1510 1510
                           )
1511
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1512
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1511
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1512
+            ? $this->_page_routes[$route_to_check]['capability'] : null;
1513 1513
         if (empty($capability) && empty($route_to_check)) {
1514 1514
             $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1515 1515
                 : $this->_route['capability'];
@@ -1629,7 +1629,7 @@  discard block
 block discarded – undo
1629 1629
         ';
1630 1630
 
1631 1631
         // current set timezone for timezone js
1632
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1632
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1633 1633
     }
1634 1634
 
1635 1635
 
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
         // loop through the array and setup content
1664 1664
         foreach ($help_array as $trigger => $help) {
1665 1665
             // make sure the array is setup properly
1666
-            if (! isset($help['title'], $help['content'])) {
1666
+            if ( ! isset($help['title'], $help['content'])) {
1667 1667
                 throw new EE_Error(
1668 1668
                     esc_html__(
1669 1669
                         'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
@@ -1677,8 +1677,8 @@  discard block
 block discarded – undo
1677 1677
                 'help_popup_title'   => $help['title'],
1678 1678
                 'help_popup_content' => $help['content'],
1679 1679
             ];
1680
-            $content       .= EEH_Template::display_template(
1681
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1680
+            $content .= EEH_Template::display_template(
1681
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1682 1682
                 $template_args,
1683 1683
                 true
1684 1684
             );
@@ -1700,15 +1700,15 @@  discard block
 block discarded – undo
1700 1700
     private function _get_help_content()
1701 1701
     {
1702 1702
         // what is the method we're looking for?
1703
-        $method_name = '_help_popup_content_' . $this->_req_action;
1703
+        $method_name = '_help_popup_content_'.$this->_req_action;
1704 1704
         // if method doesn't exist let's get out.
1705
-        if (! method_exists($this, $method_name)) {
1705
+        if ( ! method_exists($this, $method_name)) {
1706 1706
             return [];
1707 1707
         }
1708 1708
         // k we're good to go let's retrieve the help array
1709 1709
         $help_array = $this->{$method_name}();
1710 1710
         // make sure we've got an array!
1711
-        if (! is_array($help_array)) {
1711
+        if ( ! is_array($help_array)) {
1712 1712
             throw new EE_Error(
1713 1713
                 esc_html__(
1714 1714
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1740,8 +1740,8 @@  discard block
 block discarded – undo
1740 1740
         // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1741 1741
         $help_array   = $this->_get_help_content();
1742 1742
         $help_content = '';
1743
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1744
-            $help_array[ $trigger_id ] = [
1743
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1744
+            $help_array[$trigger_id] = [
1745 1745
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1746 1746
                 'content' => esc_html__(
1747 1747
                     'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
@@ -1832,7 +1832,7 @@  discard block
 block discarded – undo
1832 1832
         );
1833 1833
         add_filter(
1834 1834
             'admin_body_class',
1835
-            function ($classes) {
1835
+            function($classes) {
1836 1836
                 if (strpos($classes, 'espresso-admin') === false) {
1837 1837
                     $classes .= ' espresso-admin';
1838 1838
                 }
@@ -1923,12 +1923,12 @@  discard block
 block discarded – undo
1923 1923
     protected function _set_list_table()
1924 1924
     {
1925 1925
         // first is this a list_table view?
1926
-        if (! isset($this->_route_config['list_table'])) {
1926
+        if ( ! isset($this->_route_config['list_table'])) {
1927 1927
             return;
1928 1928
         } //not a list_table view so get out.
1929 1929
         // list table functions are per view specific (because some admin pages might have more than one list table!)
1930
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1931
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1930
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
1931
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1932 1932
             // user error msg
1933 1933
             $error_msg = esc_html__(
1934 1934
                 'An error occurred. The requested list table views could not be found.',
@@ -1948,10 +1948,10 @@  discard block
 block discarded – undo
1948 1948
         }
1949 1949
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1950 1950
         $this->_views = apply_filters(
1951
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1951
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
1952 1952
             $this->_views
1953 1953
         );
1954
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1954
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1955 1955
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1956 1956
         $this->_set_list_table_view();
1957 1957
         $this->_set_list_table_object();
@@ -1986,7 +1986,7 @@  discard block
 block discarded – undo
1986 1986
     protected function _set_list_table_object()
1987 1987
     {
1988 1988
         if (isset($this->_route_config['list_table'])) {
1989
-            if (! class_exists($this->_route_config['list_table'])) {
1989
+            if ( ! class_exists($this->_route_config['list_table'])) {
1990 1990
                 throw new EE_Error(
1991 1991
                     sprintf(
1992 1992
                         esc_html__(
@@ -2024,17 +2024,17 @@  discard block
 block discarded – undo
2024 2024
         foreach ($this->_views as $key => $view) {
2025 2025
             $query_args = [];
2026 2026
             // check for current view
2027
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2027
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2028 2028
             $query_args['action']                        = $this->_req_action;
2029
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2029
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2030 2030
             $query_args['status']                        = $view['slug'];
2031 2031
             // merge any other arguments sent in.
2032
-            if (isset($extra_query_args[ $view['slug'] ])) {
2033
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2032
+            if (isset($extra_query_args[$view['slug']])) {
2033
+                foreach ($extra_query_args[$view['slug']] as $extra_query_arg) {
2034 2034
                     $query_args[] = $extra_query_arg;
2035 2035
                 }
2036 2036
             }
2037
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2037
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2038 2038
         }
2039 2039
         return $this->_views;
2040 2040
     }
@@ -2065,14 +2065,14 @@  discard block
 block discarded – undo
2065 2065
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2066 2066
         foreach ($values as $value) {
2067 2067
             if ($value < $max_entries) {
2068
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2068
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2069 2069
                 $entries_per_page_dropdown .= '
2070
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2070
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2071 2071
             }
2072 2072
         }
2073
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2073
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2074 2074
         $entries_per_page_dropdown .= '
2075
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2075
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2076 2076
         $entries_per_page_dropdown .= '
2077 2077
 					</select>
2078 2078
 					entries
@@ -2096,7 +2096,7 @@  discard block
 block discarded – undo
2096 2096
             empty($this->_search_btn_label) ? $this->page_label
2097 2097
                 : $this->_search_btn_label
2098 2098
         );
2099
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2099
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2100 2100
     }
2101 2101
 
2102 2102
 
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
             $total_columns                                       = ! empty($screen_columns)
2185 2185
                 ? $screen_columns
2186 2186
                 : $this->_route_config['columns'][1];
2187
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2187
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2188 2188
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2189 2189
             $this->_template_args['screen']                      = $this->_current_screen;
2190 2190
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2229,7 +2229,7 @@  discard block
 block discarded – undo
2229 2229
      */
2230 2230
     protected function _espresso_ratings_request()
2231 2231
     {
2232
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2232
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2233 2233
             return;
2234 2234
         }
2235 2235
         $ratings_box_title = apply_filters(
@@ -2256,28 +2256,28 @@  discard block
 block discarded – undo
2256 2256
      */
2257 2257
     public function espresso_ratings_request()
2258 2258
     {
2259
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2259
+        EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php');
2260 2260
     }
2261 2261
 
2262 2262
 
2263 2263
     public static function cached_rss_display($rss_id, $url)
2264 2264
     {
2265
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2265
+        $loading = '<p class="widget-loading hide-if-no-js">'
2266 2266
                      . esc_html__('Loading&#8230;', 'event_espresso')
2267 2267
                      . '</p><p class="hide-if-js">'
2268 2268
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2269 2269
                      . '</p>';
2270
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2271
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2272
-        $post      = '</div>' . "\n";
2273
-        $cache_key = 'ee_rss_' . md5($rss_id);
2270
+        $pre       = '<div class="espresso-rss-display">'."\n\t";
2271
+        $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>';
2272
+        $post      = '</div>'."\n";
2273
+        $cache_key = 'ee_rss_'.md5($rss_id);
2274 2274
         $output    = get_transient($cache_key);
2275 2275
         if ($output !== false) {
2276
-            echo $pre . $output . $post; // already escaped
2276
+            echo $pre.$output.$post; // already escaped
2277 2277
             return true;
2278 2278
         }
2279
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2280
-            echo $pre . $loading . $post; // already escaped
2279
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2280
+            echo $pre.$loading.$post; // already escaped
2281 2281
             return false;
2282 2282
         }
2283 2283
         ob_start();
@@ -2344,19 +2344,19 @@  discard block
 block discarded – undo
2344 2344
     public function espresso_sponsors_post_box()
2345 2345
     {
2346 2346
         EEH_Template::display_template(
2347
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2347
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2348 2348
         );
2349 2349
     }
2350 2350
 
2351 2351
 
2352 2352
     private function _publish_post_box()
2353 2353
     {
2354
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2354
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2355 2355
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2356 2356
         // then we'll use that for the metabox label.
2357 2357
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2358
-        if (! empty($this->_labels['publishbox'])) {
2359
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2358
+        if ( ! empty($this->_labels['publishbox'])) {
2359
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2360 2360
                 : $this->_labels['publishbox'];
2361 2361
         } else {
2362 2362
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2385,7 +2385,7 @@  discard block
 block discarded – undo
2385 2385
             ? $this->_template_args['publish_box_extra_content']
2386 2386
             : '';
2387 2387
         echo EEH_Template::display_template(
2388
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2388
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2389 2389
             $this->_template_args,
2390 2390
             true
2391 2391
         );
@@ -2475,18 +2475,18 @@  discard block
 block discarded – undo
2475 2475
             );
2476 2476
         }
2477 2477
         $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2478
-        if (! empty($name) && ! empty($id)) {
2479
-            $hidden_field_arr[ $name ] = [
2478
+        if ( ! empty($name) && ! empty($id)) {
2479
+            $hidden_field_arr[$name] = [
2480 2480
                 'type'  => 'hidden',
2481 2481
                 'value' => $id,
2482 2482
             ];
2483
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2483
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2484 2484
         } else {
2485 2485
             $hf = '';
2486 2486
         }
2487 2487
         // add hidden field
2488 2488
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2489
-            ? $hf[ $name ]['field']
2489
+            ? $hf[$name]['field']
2490 2490
             : $hf;
2491 2491
     }
2492 2492
 
@@ -2588,7 +2588,7 @@  discard block
 block discarded – undo
2588 2588
         }
2589 2589
         // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2590 2590
         $call_back_func = $create_func
2591
-            ? static function ($post, $metabox) {
2591
+            ? static function($post, $metabox) {
2592 2592
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2593 2593
                 echo EEH_Template::display_template(
2594 2594
                     $metabox['args']['template_path'],
@@ -2598,7 +2598,7 @@  discard block
 block discarded – undo
2598 2598
             }
2599 2599
             : $callback;
2600 2600
         add_meta_box(
2601
-            str_replace('_', '-', $action) . '-mbox',
2601
+            str_replace('_', '-', $action).'-mbox',
2602 2602
             $title,
2603 2603
             $call_back_func,
2604 2604
             $this->_wp_page_slug,
@@ -2705,9 +2705,9 @@  discard block
 block discarded – undo
2705 2705
             : 'espresso-default-admin';
2706 2706
         $template_path                                     = $sidebar
2707 2707
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2708
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2708
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2709 2709
         if ($this->request->isAjax()) {
2710
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2710
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2711 2711
         }
2712 2712
         $template_path                                     = ! empty($this->_column_template_path)
2713 2713
             ? $this->_column_template_path : $template_path;
@@ -2747,11 +2747,11 @@  discard block
 block discarded – undo
2747 2747
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2748 2748
     {
2749 2749
         // let's generate a default preview action button if there isn't one already present.
2750
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2750
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2751 2751
             'Upgrade to Event Espresso 4 Right Now',
2752 2752
             'event_espresso'
2753 2753
         );
2754
-        $buy_now_url                                   = add_query_arg(
2754
+        $buy_now_url = add_query_arg(
2755 2755
             [
2756 2756
                 'ee_ver'       => 'ee4',
2757 2757
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2771,8 +2771,8 @@  discard block
 block discarded – undo
2771 2771
                 true
2772 2772
             )
2773 2773
             : $this->_template_args['preview_action_button'];
2774
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2775
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2774
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2775
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2776 2776
             $this->_template_args,
2777 2777
             true
2778 2778
         );
@@ -2830,7 +2830,7 @@  discard block
 block discarded – undo
2830 2830
         // setup search attributes
2831 2831
         $this->_set_search_attributes();
2832 2832
         $this->_template_args['current_page']     = $this->_wp_page_slug;
2833
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2833
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2834 2834
         $this->_template_args['table_url']        = $this->request->isAjax()
2835 2835
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2836 2836
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -2838,10 +2838,10 @@  discard block
 block discarded – undo
2838 2838
         $this->_template_args['current_route']    = $this->_req_action;
2839 2839
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2840 2840
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2841
-        if (! empty($ajax_sorting_callback)) {
2841
+        if ( ! empty($ajax_sorting_callback)) {
2842 2842
             $sortable_list_table_form_fields = wp_nonce_field(
2843
-                $ajax_sorting_callback . '_nonce',
2844
-                $ajax_sorting_callback . '_nonce',
2843
+                $ajax_sorting_callback.'_nonce',
2844
+                $ajax_sorting_callback.'_nonce',
2845 2845
                 false,
2846 2846
                 false
2847 2847
             );
@@ -2859,20 +2859,20 @@  discard block
 block discarded – undo
2859 2859
             isset($this->_template_args['list_table_hidden_fields'])
2860 2860
                 ? $this->_template_args['list_table_hidden_fields']
2861 2861
                 : '';
2862
-        $nonce_ref                                               = $this->_req_action . '_nonce';
2863
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
2862
+        $nonce_ref = $this->_req_action.'_nonce';
2863
+        $hidden_form_fields .= '<input type="hidden" name="'
2864 2864
                                                                     . $nonce_ref
2865 2865
                                                                     . '" value="'
2866 2866
                                                                     . wp_create_nonce($nonce_ref)
2867 2867
                                                                     . '">';
2868
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2868
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2869 2869
         // display message about search results?
2870 2870
         $search = $this->request->getRequestParam('s');
2871 2871
         $this->_template_args['before_list_table'] .= ! empty($search)
2872
-            ? '<p class="ee-search-results">' . sprintf(
2872
+            ? '<p class="ee-search-results">'.sprintf(
2873 2873
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2874 2874
                 trim($search, '%')
2875
-            ) . '</p>'
2875
+            ).'</p>'
2876 2876
             : '';
2877 2877
         // filter before_list_table template arg
2878 2878
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2906,7 +2906,7 @@  discard block
 block discarded – undo
2906 2906
         // convert to array and filter again
2907 2907
         // arrays are easier to inject new items in a specific location,
2908 2908
         // but would not be backwards compatible, so we have to add a new filter
2909
-        $this->_template_args['after_list_table']   = implode(
2909
+        $this->_template_args['after_list_table'] = implode(
2910 2910
             " \n",
2911 2911
             (array) apply_filters(
2912 2912
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -2954,15 +2954,15 @@  discard block
 block discarded – undo
2954 2954
         );
2955 2955
         /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
2956 2956
         $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
2957
-        if (! $status_change_notice->isDismissed()) {
2957
+        if ( ! $status_change_notice->isDismissed()) {
2958 2958
             $this->_template_args['status_change_notice'] = EEH_Template::display_template(
2959
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
2960
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
2959
+                EE_ADMIN_TEMPLATE.'status_change_notice.template.php',
2960
+                ['context' => '__admin-legend', 'page_slug' => $this->page_slug],
2961 2961
                 true
2962 2962
             );
2963 2963
         }
2964 2964
         return EEH_Template::display_template(
2965
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2965
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
2966 2966
             $this->_template_args,
2967 2967
             true
2968 2968
         );
@@ -3080,18 +3080,18 @@  discard block
 block discarded – undo
3080 3080
                 : ''
3081 3081
         );
3082 3082
 
3083
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3083
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3084 3084
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3085 3085
             isset($this->_template_args['after_admin_page_content'])
3086 3086
                 ? $this->_template_args['after_admin_page_content']
3087 3087
                 : ''
3088 3088
         );
3089
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3089
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3090 3090
 
3091 3091
         if ($this->request->isAjax()) {
3092 3092
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3093 3093
                 // $template_path,
3094
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3094
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3095 3095
                 $this->_template_args,
3096 3096
                 true
3097 3097
             );
@@ -3100,7 +3100,7 @@  discard block
 block discarded – undo
3100 3100
         // load settings page wrapper template
3101 3101
         $template_path = $about
3102 3102
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3103
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3103
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3104 3104
 
3105 3105
         EEH_Template::display_template($template_path, $this->_template_args);
3106 3106
     }
@@ -3184,12 +3184,12 @@  discard block
 block discarded – undo
3184 3184
         $default_names = ['save', 'save_and_close'];
3185 3185
         $buttons = '';
3186 3186
         foreach ($button_text as $key => $button) {
3187
-            $ref     = $default_names[ $key ];
3188
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3189
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3190
-                        . 'value="' . $button . '" name="' . $name . '" '
3191
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3192
-            if (! $both) {
3187
+            $ref     = $default_names[$key];
3188
+            $name    = ! empty($actions) ? $actions[$key] : $ref;
3189
+            $buttons .= '<input type="submit" class="button-primary '.$ref.'" '
3190
+                        . 'value="'.$button.'" name="'.$name.'" '
3191
+                        . 'id="'.$this->_current_view.'_'.$ref.'" />';
3192
+            if ( ! $both) {
3193 3193
                 break;
3194 3194
             }
3195 3195
         }
@@ -3229,13 +3229,13 @@  discard block
 block discarded – undo
3229 3229
                 'An error occurred. No action was set for this page\'s form.',
3230 3230
                 'event_espresso'
3231 3231
             );
3232
-            $dev_msg  = $user_msg . "\n"
3232
+            $dev_msg = $user_msg."\n"
3233 3233
                         . sprintf(
3234 3234
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3235 3235
                             __FUNCTION__,
3236 3236
                             __CLASS__
3237 3237
                         );
3238
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3238
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3239 3239
         }
3240 3240
         // open form
3241 3241
         $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
@@ -3244,9 +3244,9 @@  discard block
 block discarded – undo
3244 3244
                                                              . $route
3245 3245
                                                              . '_event_form" >';
3246 3246
         // add nonce
3247
-        $nonce                                             =
3248
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3249
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3247
+        $nonce =
3248
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3249
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3250 3250
         // add REQUIRED form action
3251 3251
         $hidden_fields = [
3252 3252
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3259,7 +3259,7 @@  discard block
 block discarded – undo
3259 3259
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3260 3260
         // add fields to form
3261 3261
         foreach ((array) $form_fields as $form_field) {
3262
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3262
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3263 3263
         }
3264 3264
         // close form
3265 3265
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3353,10 +3353,10 @@  discard block
 block discarded – undo
3353 3353
         $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3354 3354
         $notices      = EE_Error::get_notices(false);
3355 3355
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3356
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3356
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3357 3357
             EE_Error::overwrite_success();
3358 3358
         }
3359
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3359
+        if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3360 3360
             // how many records affected ? more than one record ? or just one ?
3361 3361
             if ($success > 1) {
3362 3362
                 // set plural msg
@@ -3385,7 +3385,7 @@  discard block
 block discarded – undo
3385 3385
             }
3386 3386
         }
3387 3387
         // check that $query_args isn't something crazy
3388
-        if (! is_array($query_args)) {
3388
+        if ( ! is_array($query_args)) {
3389 3389
             $query_args = [];
3390 3390
         }
3391 3391
         /**
@@ -3414,7 +3414,7 @@  discard block
 block discarded – undo
3414 3414
             $redirect_url = admin_url('admin.php');
3415 3415
         }
3416 3416
         // merge any default query_args set in _default_route_query_args property
3417
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3417
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3418 3418
             $args_to_merge = [];
3419 3419
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3420 3420
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3426,15 +3426,15 @@  discard block
 block discarded – undo
3426 3426
                         }
3427 3427
                         // finally we will override any arguments in the referer with
3428 3428
                         // what might be set on the _default_route_query_args array.
3429
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3430
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3429
+                        if (isset($this->_default_route_query_args[$reference])) {
3430
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3431 3431
                         } else {
3432
-                            $args_to_merge[ $reference ] = urlencode($value);
3432
+                            $args_to_merge[$reference] = urlencode($value);
3433 3433
                         }
3434 3434
                     }
3435 3435
                     continue;
3436 3436
                 }
3437
-                $args_to_merge[ $query_param ] = $query_value;
3437
+                $args_to_merge[$query_param] = $query_value;
3438 3438
             }
3439 3439
             // now let's merge these arguments but override with what was specifically sent in to the
3440 3440
             // redirect.
@@ -3446,19 +3446,19 @@  discard block
 block discarded – undo
3446 3446
         if (isset($query_args['action'])) {
3447 3447
             // manually generate wp_nonce and merge that with the query vars
3448 3448
             // becuz the wp_nonce_url function wrecks havoc on some vars
3449
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3449
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3450 3450
         }
3451 3451
         // we're adding some hooks and filters in here for processing any things just before redirects
3452 3452
         // (example: an admin page has done an insert or update and we want to run something after that).
3453
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3453
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
3454 3454
         $redirect_url = apply_filters(
3455
-            'FHEE_redirect_' . $classname . $this->_req_action,
3455
+            'FHEE_redirect_'.$classname.$this->_req_action,
3456 3456
             EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3457 3457
             $query_args
3458 3458
         );
3459 3459
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3460 3460
         if ($this->request->isAjax()) {
3461
-            $default_data                    = [
3461
+            $default_data = [
3462 3462
                 'close'        => true,
3463 3463
                 'redirect_url' => $redirect_url,
3464 3464
                 'where'        => 'main',
@@ -3508,7 +3508,7 @@  discard block
 block discarded – undo
3508 3508
         }
3509 3509
         $this->_template_args['notices'] = EE_Error::get_notices();
3510 3510
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3511
-        if (! $this->request->isAjax() || $sticky_notices) {
3511
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3512 3512
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3513 3513
             $this->_add_transient(
3514 3514
                 $route,
@@ -3548,7 +3548,7 @@  discard block
 block discarded – undo
3548 3548
         $exclude_nonce = false
3549 3549
     ) {
3550 3550
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3551
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3551
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3552 3552
             throw new EE_Error(
3553 3553
                 sprintf(
3554 3554
                     esc_html__(
@@ -3559,7 +3559,7 @@  discard block
 block discarded – undo
3559 3559
                 )
3560 3560
             );
3561 3561
         }
3562
-        if (! isset($this->_labels['buttons'][ $type ])) {
3562
+        if ( ! isset($this->_labels['buttons'][$type])) {
3563 3563
             throw new EE_Error(
3564 3564
                 sprintf(
3565 3565
                     esc_html__(
@@ -3572,7 +3572,7 @@  discard block
 block discarded – undo
3572 3572
         }
3573 3573
         // finally check user access for this button.
3574 3574
         $has_access = $this->check_user_access($action, true);
3575
-        if (! $has_access) {
3575
+        if ( ! $has_access) {
3576 3576
             return '';
3577 3577
         }
3578 3578
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3580,11 +3580,11 @@  discard block
 block discarded – undo
3580 3580
             'action' => $action,
3581 3581
         ];
3582 3582
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3583
-        if (! empty($extra_request)) {
3583
+        if ( ! empty($extra_request)) {
3584 3584
             $query_args = array_merge($extra_request, $query_args);
3585 3585
         }
3586 3586
         $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3587
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3587
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3588 3588
     }
3589 3589
 
3590 3590
 
@@ -3610,7 +3610,7 @@  discard block
 block discarded – undo
3610 3610
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3611 3611
                 20
3612 3612
             ),
3613
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3613
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3614 3614
         ];
3615 3615
         // ONLY add the screen option if the user has access to it.
3616 3616
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3631,18 +3631,18 @@  discard block
 block discarded – undo
3631 3631
     {
3632 3632
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3633 3633
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3634
-            if (! $user = wp_get_current_user()) {
3634
+            if ( ! $user = wp_get_current_user()) {
3635 3635
                 return;
3636 3636
             }
3637 3637
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3638
-            if (! $option) {
3638
+            if ( ! $option) {
3639 3639
                 return;
3640 3640
             }
3641
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3641
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3642 3642
             $map_option = $option;
3643 3643
             $option     = str_replace('-', '_', $option);
3644 3644
             switch ($map_option) {
3645
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3645
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3646 3646
                     $max_value = apply_filters(
3647 3647
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3648 3648
                         999,
@@ -3699,13 +3699,13 @@  discard block
 block discarded – undo
3699 3699
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3700 3700
     {
3701 3701
         $user_id = get_current_user_id();
3702
-        if (! $skip_route_verify) {
3702
+        if ( ! $skip_route_verify) {
3703 3703
             $this->_verify_route($route);
3704 3704
         }
3705 3705
         // now let's set the string for what kind of transient we're setting
3706 3706
         $transient = $notices
3707
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3708
-            : 'rte_tx_' . $route . '_' . $user_id;
3707
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3708
+            : 'rte_tx_'.$route.'_'.$user_id;
3709 3709
         $data      = $notices ? ['notices' => $data] : $data;
3710 3710
         // is there already a transient for this route?  If there is then let's ADD to that transient
3711 3711
         $existing = is_multisite() && is_network_admin()
@@ -3734,8 +3734,8 @@  discard block
 block discarded – undo
3734 3734
         $user_id   = get_current_user_id();
3735 3735
         $route     = ! $route ? $this->_req_action : $route;
3736 3736
         $transient = $notices
3737
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3738
-            : 'rte_tx_' . $route . '_' . $user_id;
3737
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3738
+            : 'rte_tx_'.$route.'_'.$user_id;
3739 3739
         $data      = is_multisite() && is_network_admin()
3740 3740
             ? get_site_transient($transient)
3741 3741
             : get_transient($transient);
@@ -3971,7 +3971,7 @@  discard block
 block discarded – undo
3971 3971
      */
3972 3972
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3973 3973
     {
3974
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3974
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3975 3975
     }
3976 3976
 
3977 3977
 
@@ -3984,7 +3984,7 @@  discard block
 block discarded – undo
3984 3984
      */
3985 3985
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3986 3986
     {
3987
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3987
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3988 3988
     }
3989 3989
 
3990 3990
 
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +926 added lines, -926 removed lines patch added patch discarded remove patch
@@ -6,36 +6,36 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\request\RequestInterface;
7 7
 
8 8
 if (! function_exists('espresso_get_template_part')) {
9
-    /**
10
-     * espresso_get_template_part
11
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
12
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
13
-     *
14
-     * @param string $slug The slug name for the generic template.
15
-     * @param string $name The name of the specialised template.
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
9
+	/**
10
+	 * espresso_get_template_part
11
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
12
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
13
+	 *
14
+	 * @param string $slug The slug name for the generic template.
15
+	 * @param string $name The name of the specialised template.
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param string        $prefix added to the beginning of the generated class
30
-     * @param string        $suffix added to the end of the generated class
31
-     * @return string
32
-     * @throws EE_Error
33
-     * @throws ReflectionException
34
-     */
35
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
36
-    {
37
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
38
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param string        $prefix added to the beginning of the generated class
30
+	 * @param string        $suffix added to the end of the generated class
31
+	 * @return string
32
+	 * @throws EE_Error
33
+	 * @throws ReflectionException
34
+	 */
35
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
36
+	{
37
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
38
+	}
39 39
 }
40 40
 
41 41
 
@@ -50,640 +50,640 @@  discard block
 block discarded – undo
50 50
 class EEH_Template
51 51
 {
52 52
 
53
-    private static $_espresso_themes = [];
54
-
55
-
56
-    /**
57
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
-     *
59
-     * @return boolean
60
-     */
61
-    public static function is_espresso_theme()
62
-    {
63
-        return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
-    }
65
-
66
-
67
-    /**
68
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
-     *    load its functions.php file ( if not already loaded )
70
-     *
71
-     * @return void
72
-     */
73
-    public static function load_espresso_theme_functions()
74
-    {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-    /**
84
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
-     *
86
-     * @return array
87
-     */
88
-    public static function get_espresso_themes()
89
-    {
90
-        if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
-            if (empty($espresso_themes)) {
93
-                return [];
94
-            }
95
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
97
-            }
98
-            EEH_Template::$_espresso_themes = [];
99
-            foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
-            }
102
-        }
103
-        return EEH_Template::$_espresso_themes;
104
-    }
105
-
106
-
107
-    /**
108
-     * EEH_Template::get_template_part
109
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
-     * filtering based off of the entire template part name
112
-     *
113
-     * @param string $slug The slug name for the generic template.
114
-     * @param string $name The name of the specialised template.
115
-     * @param array  $template_args
116
-     * @param bool   $return_string
117
-     * @return string        the html output for the formatted money value
118
-     */
119
-    public static function get_template_part(
120
-        $slug = null,
121
-        $name = null,
122
-        $template_args = [],
123
-        $return_string = false
124
-    ) {
125
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
-        $templates = [];
127
-        $name      = (string) $name;
128
-        if ($name != '') {
129
-            $templates[] = "{$slug}-{$name}.php";
130
-        }
131
-        // allow template parts to be turned off via something like:
132
-        // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
-            return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
-        }
136
-        return '';
137
-    }
138
-
139
-
140
-    /**
141
-     *    locate_template
142
-     *    locate a template file by looking in the following places, in the following order:
143
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
-     *        <assumed full absolute server path>
145
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
-     *        <server path up to>/wp-content/uploads/espresso/templates/
147
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
151
-     *        Example:
152
-     *          You are using the WordPress Twenty Sixteen theme,
153
-     *        and you want to customize the "some-event.template.php" template,
154
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
-     *        /relative/path/to/some-event.template.php
159
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
-     *          Had you passed an absolute path to your template that was in some other location,
165
-     *        ie: "/absolute/path/to/some-event.template.php"
166
-     *          then the search would have been :
167
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
-     *        /absolute/path/to/some-event.template.php
169
-     *          and stopped there upon finding it in the second location
170
-     *
171
-     * @param array|string $templates       array of template file names including extension (or just a single string)
172
-     * @param array        $template_args   an array of arguments to be extracted for use in the template
173
-     * @param boolean      $load            whether to pass the located template path on to the
174
-     *                                      EEH_Template::display_template() method or simply return it
175
-     * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
-     *                                      string
177
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
-     *                                      generate a custom template or not. Used in places where you don't actually
179
-     *                                      load the template, you just want to know if there's a custom version of it.
180
-     * @return mixed
181
-     * @throws DomainException
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public static function locate_template(
187
-        $templates = [],
188
-        $template_args = [],
189
-        $load = true,
190
-        $return_string = true,
191
-        $check_if_custom = false
192
-    ) {
193
-        // first use WP locate_template to check for template in the current theme folder
194
-        $template_path = locate_template($templates);
195
-
196
-        if ($check_if_custom && ! empty($template_path)) {
197
-            return true;
198
-        }
199
-
200
-        // not in the theme
201
-        if (empty($template_path)) {
202
-            // not even a template to look for ?
203
-            if (empty($templates)) {
204
-                $loader = LoaderFactory::getLoader();
205
-                /** @var RequestInterface $request */
206
-                $request = $loader->getShared(RequestInterface::class);
207
-                // get post_type
208
-                $post_type = $request->getRequestParam('post_type');
209
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
-                $custom_post_types = $loader->getShared(
211
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
-                );
213
-                // get array of EE Custom Post Types
214
-                $EE_CPTs = $custom_post_types->getDefinitions();
215
-                // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
217
-                    $archive_or_single = is_archive() ? 'archive' : '';
218
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
220
-                }
221
-            }
222
-            // currently active EE template theme
223
-            $current_theme = EE_Config::get_current_theme();
224
-
225
-            // array of paths to folders that may contain templates
226
-            $template_folder_paths = [
227
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
230
-                EVENT_ESPRESSO_TEMPLATE_DIR,
231
-            ];
232
-
233
-            // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
236
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
238
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
240
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
-                    EE_PLUGIN_DIR_PATH,
242
-                ];
243
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
-            }
245
-
246
-            // now filter that array
247
-            $template_folder_paths = apply_filters(
248
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
249
-                $template_folder_paths
250
-            );
251
-            $templates             = is_array($templates) ? $templates : [$templates];
252
-            $template_folder_paths =
253
-                is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
-            // array to hold all possible template paths
255
-            $full_template_paths = [];
256
-            $file_name           = '';
257
-
258
-            // loop through $templates
259
-            foreach ($templates as $template) {
260
-                // normalize directory separators
261
-                $template                      = EEH_File::standardise_directory_separators($template);
262
-                $file_name                     = basename($template);
263
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
-                // while looping through all template folder paths
265
-                foreach ($template_folder_paths as $template_folder_path) {
266
-                    // normalize directory separators
267
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
-                    // determine if any common base path exists between the two paths
269
-                    $common_base_path = EEH_Template::_find_common_base_path(
270
-                        [$template_folder_path, $template_path_minus_file_name]
271
-                    );
272
-                    if ($common_base_path !== '') {
273
-                        // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
-                    } else {
276
-                        // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
-                    }
279
-                    // build up our template locations array by adding our resolved paths
280
-                    $full_template_paths[] = $resolved_path;
281
-                }
282
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
-                array_unshift($full_template_paths, $template);
284
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
-            }
287
-            // filter final array of full template paths
288
-            $full_template_paths = apply_filters(
289
-                'FHEE__EEH_Template__locate_template__full_template_paths',
290
-                $full_template_paths,
291
-                $file_name
292
-            );
293
-            // now loop through our final array of template location paths and check each location
294
-            foreach ((array) $full_template_paths as $full_template_path) {
295
-                if (is_readable($full_template_path)) {
296
-                    $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
-                    break;
298
-                }
299
-            }
300
-        }
301
-
302
-        // hook that can be used to display the full template path that will be used
303
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
-
305
-        // if we got it and you want to see it...
306
-        if ($template_path && $load && ! $check_if_custom) {
307
-            if ($return_string) {
308
-                return EEH_Template::display_template($template_path, $template_args, true);
309
-            }
310
-            EEH_Template::display_template($template_path, $template_args);
311
-        }
312
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
-    }
314
-
315
-
316
-    /**
317
-     * _find_common_base_path
318
-     * given two paths, this determines if there is a common base path between the two
319
-     *
320
-     * @param array $paths
321
-     * @return string
322
-     */
323
-    protected static function _find_common_base_path($paths)
324
-    {
325
-        $last_offset      = 0;
326
-        $common_base_path = '';
327
-        while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
-            $dir_length = $index - $last_offset + 1;
329
-            $directory  = substr($paths[0], $last_offset, $dir_length);
330
-            foreach ($paths as $path) {
331
-                if (substr($path, $last_offset, $dir_length) != $directory) {
332
-                    return $common_base_path;
333
-                }
334
-            }
335
-            $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
337
-        }
338
-        return substr($common_base_path, 0, -1);
339
-    }
340
-
341
-
342
-    /**
343
-     * load and display a template
344
-     *
345
-     * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
-     * @param array       $template_args    an array of arguments to be extracted for use in the template
347
-     * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
-     *                                      string
349
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
-     *                                      not found or is not readable
351
-     * @return string
352
-     * @throws DomainException
353
-     */
354
-    public static function display_template(
355
-        $template_path = false,
356
-        $template_args = [],
357
-        $return_string = false,
358
-        $throw_exceptions = false
359
-    ) {
360
-
361
-        /**
362
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
-         * the display_template method are templates we DON'T want modified (usually because of js
365
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
-         * using this.
367
-         *
368
-         * @since 4.6.0
369
-         */
370
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
-
373
-        // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
375
-            // ignore whether template is accessible ?
376
-            if ($throw_exceptions) {
377
-                throw new DomainException(
378
-                    esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
-                );
380
-            }
381
-            return '';
382
-        }
383
-        // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
385
-            $template_args = [$template_args];
386
-        }
387
-        extract($template_args, EXTR_SKIP);
388
-
389
-        if ($return_string) {
390
-            // because we want to return a string, we are going to capture the output
391
-            ob_start();
392
-            include($template_path);
393
-            return ob_get_clean();
394
-        }
395
-        include($template_path);
396
-        return '';
397
-    }
398
-
399
-
400
-    /**
401
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
-     *
403
-     * @param EE_Base_Class $object the EE object the css class is being generated for
404
-     * @param string        $prefix added to the beginning of the generated class
405
-     * @param string        $suffix added to the end of the generated class
406
-     * @return string
407
-     * @throws EE_Error
408
-     * @throws ReflectionException
409
-     */
410
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
-    {
412
-        // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
-        // da muddle
415
-        $class = '';
416
-        // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
-        // is the passed object an EE object ?
419
-        if ($object instanceof EE_Base_Class) {
420
-            // grab the exact type of object
421
-            $obj_class = get_class($object);
422
-            // depending on the type of object...
423
-            switch ($obj_class) {
424
-                // no specifics just yet...
425
-                default:
426
-                    $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
-            }
429
-        }
430
-        return $prefix . $class . $suffix;
431
-    }
432
-
433
-
434
-    /**
435
-     * EEH_Template::format_currency
436
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
-     * the country currency settings from the supplied country ISO code
438
-     *
439
-     * @param float   $amount       raw money value
440
-     * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
-     * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
-     * @param string  $CNT_ISO      2 letter ISO code for a country
443
-     * @param string  $cur_code_span_class
444
-     * @return string        the html output for the formatted money value
445
-     */
446
-    public static function format_currency(
447
-        $amount = null,
448
-        $return_raw = false,
449
-        $display_code = true,
450
-        $CNT_ISO = '',
451
-        $cur_code_span_class = 'currency-code'
452
-    ) {
453
-        // ensure amount was received
454
-        if ($amount === null) {
455
-            $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
-            return '';
458
-        }
459
-        // ensure amount is float
460
-        $amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
463
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
-        // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
466
-            return esc_html($amount_formatted);
467
-        }
468
-        try {
469
-            // was a country ISO code passed ? if so generate currency config object for that country
470
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
-        } catch (Exception $e) {
472
-            // eat exception
473
-            $mny = null;
474
-        }
475
-        // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
477
-            // set default config country currency settings
478
-            $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
-                ? EE_Registry::instance()->CFG->currency
480
-                : new EE_Currency_Config();
481
-        }
482
-        // format float
483
-        $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
-        // add formatting ?
485
-        if (! $return_raw) {
486
-            // add currency sign
487
-            if ($mny->sign_b4) {
488
-                if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
490
-                } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
-                }
493
-            } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
495
-            }
496
-
497
-            // filter to allow global setting of display_code
498
-            $display_code = (bool) apply_filters(
499
-                'FHEE__EEH_Template__format_currency__display_code',
500
-                $display_code
501
-            );
502
-
503
-            // add currency code ?
504
-            $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
-                : $amount_formatted;
507
-        }
508
-        // filter results
509
-        $amount_formatted = apply_filters(
510
-            'FHEE__EEH_Template__format_currency__amount_formatted',
511
-            $amount_formatted,
512
-            $mny,
513
-            $return_raw
514
-        );
515
-        // clean up vars
516
-        unset($mny);
517
-        // return formatted currency amount
518
-        return $amount_formatted;
519
-    }
520
-
521
-
522
-    /**
523
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
524
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
-     * related status model or model object (i.e. in documentation etc.)
526
-     *
527
-     * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
-     *                            match, then 'Unknown' will be returned.
529
-     * @param boolean $plural     Whether to return plural or not
530
-     * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
-     * @return string             The localized label for the status id.
532
-     * @throws EE_Error
533
-     */
534
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
-    {
536
-        $status = EEM_Status::instance()->localized_status(
537
-            [$status_id => esc_html__('unknown', 'event_espresso')],
538
-            $plural,
539
-            $schema
540
-        );
541
-        return $status[ $status_id ];
542
-    }
543
-
544
-
545
-    /**
546
-     * This helper just returns a button or link for the given parameters
547
-     *
548
-     * @param string $url   the url for the link, note that `esc_url` will be called on it
549
-     * @param string $label What is the label you want displayed for the button
550
-     * @param string $class what class is used for the button (defaults to 'button-primary')
551
-     * @param string $icon
552
-     * @param string $title
553
-     * @return string the html output for the button
554
-     */
555
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
556
-    {
557
-        $icon_html = '';
558
-        if (! empty($icon)) {
559
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
-            $dashicons = array_filter($dashicons);
561
-            $count     = count($dashicons);
562
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
-            foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
-            }
567
-            $icon_html .= $count > 1 ? '</span>' : '';
568
-        }
569
-        // sanitize & escape
570
-        $id    = sanitize_title_with_dashes($label);
571
-        $url   = esc_url_raw($url);
572
-        $class = esc_attr($class);
573
-        $title = esc_attr($title);
574
-        $label = esc_html($label);
575
-        return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>";
576
-    }
577
-
578
-
579
-    /**
580
-     * This returns a generated link that will load the related help tab on admin pages.
581
-     *
582
-     * @param string      $help_tab_id the id for the connected help tab
583
-     * @param bool|string $page        The page identifier for the page the help tab is on
584
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
-     * @return string              generated link
588
-     */
589
-    public static function get_help_tab_link(
590
-        $help_tab_id,
591
-        $page = false,
592
-        $action = false,
593
-        $icon_style = false,
594
-        $help_text = false
595
-    ) {
596
-        global $allowedtags;
597
-        /** @var RequestInterface $request */
598
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
599
-        $page    = $page ?: $request->getRequestParam('page', '', 'key');
600
-        $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601
-
602
-
603
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
604
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605
-        $help_text    = ! $help_text ? '' : $help_text;
606
-        return '<a id="'
607
-               . esc_attr($help_tab_lnk)
608
-               . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
609
-               . esc_attr($icon)
610
-               . '" title="'
611
-               . esc_attr__(
612
-                   'Click to open the \'Help\' tab for more information about this feature.',
613
-                   'event_espresso'
614
-               )
615
-               . '" > '
616
-               . wp_kses($help_text, $allowedtags)
617
-               . ' </a>';
618
-    }
619
-
620
-
621
-    /**
622
-     * This is a helper method to generate a status legend for a given status array.
623
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
624
-     * status_array.
625
-     *
626
-     * @param array  $status_array   array of statuses that will make up the legend. In format:
627
-     *                               array(
628
-     *                               'status_item' => 'status_name'
629
-     *                               )
630
-     * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
631
-     *                               the legend.
632
-     * @return string               html structure for status.
633
-     * @throws EE_Error
634
-     */
635
-    public static function status_legend($status_array, $active_status = '')
636
-    {
637
-        if (! is_array($status_array)) {
638
-            throw new EE_Error(
639
-                esc_html__(
640
-                    'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
641
-                    'event_espresso'
642
-                )
643
-            );
644
-        }
645
-
646
-        $content = '
53
+	private static $_espresso_themes = [];
54
+
55
+
56
+	/**
57
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
+	 *
59
+	 * @return boolean
60
+	 */
61
+	public static function is_espresso_theme()
62
+	{
63
+		return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
+	}
65
+
66
+
67
+	/**
68
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
+	 *    load its functions.php file ( if not already loaded )
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public static function load_espresso_theme_functions()
74
+	{
75
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+	/**
84
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
+	 *
86
+	 * @return array
87
+	 */
88
+	public static function get_espresso_themes()
89
+	{
90
+		if (empty(EEH_Template::$_espresso_themes)) {
91
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
+			if (empty($espresso_themes)) {
93
+				return [];
94
+			}
95
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
+				unset($espresso_themes[ $key ]);
97
+			}
98
+			EEH_Template::$_espresso_themes = [];
99
+			foreach ($espresso_themes as $espresso_theme) {
100
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
+			}
102
+		}
103
+		return EEH_Template::$_espresso_themes;
104
+	}
105
+
106
+
107
+	/**
108
+	 * EEH_Template::get_template_part
109
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
+	 * filtering based off of the entire template part name
112
+	 *
113
+	 * @param string $slug The slug name for the generic template.
114
+	 * @param string $name The name of the specialised template.
115
+	 * @param array  $template_args
116
+	 * @param bool   $return_string
117
+	 * @return string        the html output for the formatted money value
118
+	 */
119
+	public static function get_template_part(
120
+		$slug = null,
121
+		$name = null,
122
+		$template_args = [],
123
+		$return_string = false
124
+	) {
125
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
+		$templates = [];
127
+		$name      = (string) $name;
128
+		if ($name != '') {
129
+			$templates[] = "{$slug}-{$name}.php";
130
+		}
131
+		// allow template parts to be turned off via something like:
132
+		// add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
+			return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
+		}
136
+		return '';
137
+	}
138
+
139
+
140
+	/**
141
+	 *    locate_template
142
+	 *    locate a template file by looking in the following places, in the following order:
143
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
+	 *        <assumed full absolute server path>
145
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
147
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
151
+	 *        Example:
152
+	 *          You are using the WordPress Twenty Sixteen theme,
153
+	 *        and you want to customize the "some-event.template.php" template,
154
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
+	 *        /relative/path/to/some-event.template.php
159
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
+	 *          Had you passed an absolute path to your template that was in some other location,
165
+	 *        ie: "/absolute/path/to/some-event.template.php"
166
+	 *          then the search would have been :
167
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
+	 *        /absolute/path/to/some-event.template.php
169
+	 *          and stopped there upon finding it in the second location
170
+	 *
171
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
172
+	 * @param array        $template_args   an array of arguments to be extracted for use in the template
173
+	 * @param boolean      $load            whether to pass the located template path on to the
174
+	 *                                      EEH_Template::display_template() method or simply return it
175
+	 * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
+	 *                                      string
177
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
+	 *                                      generate a custom template or not. Used in places where you don't actually
179
+	 *                                      load the template, you just want to know if there's a custom version of it.
180
+	 * @return mixed
181
+	 * @throws DomainException
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public static function locate_template(
187
+		$templates = [],
188
+		$template_args = [],
189
+		$load = true,
190
+		$return_string = true,
191
+		$check_if_custom = false
192
+	) {
193
+		// first use WP locate_template to check for template in the current theme folder
194
+		$template_path = locate_template($templates);
195
+
196
+		if ($check_if_custom && ! empty($template_path)) {
197
+			return true;
198
+		}
199
+
200
+		// not in the theme
201
+		if (empty($template_path)) {
202
+			// not even a template to look for ?
203
+			if (empty($templates)) {
204
+				$loader = LoaderFactory::getLoader();
205
+				/** @var RequestInterface $request */
206
+				$request = $loader->getShared(RequestInterface::class);
207
+				// get post_type
208
+				$post_type = $request->getRequestParam('post_type');
209
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
+				$custom_post_types = $loader->getShared(
211
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
+				);
213
+				// get array of EE Custom Post Types
214
+				$EE_CPTs = $custom_post_types->getDefinitions();
215
+				// build template name based on request
216
+				if (isset($EE_CPTs[ $post_type ])) {
217
+					$archive_or_single = is_archive() ? 'archive' : '';
218
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
219
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
220
+				}
221
+			}
222
+			// currently active EE template theme
223
+			$current_theme = EE_Config::get_current_theme();
224
+
225
+			// array of paths to folders that may contain templates
226
+			$template_folder_paths = [
227
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
230
+				EVENT_ESPRESSO_TEMPLATE_DIR,
231
+			];
232
+
233
+			// add core plugin folders for checking only if we're not $check_if_custom
234
+			if (! $check_if_custom) {
235
+				$core_paths            = [
236
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
+					EE_PUBLIC . $current_theme,
238
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
+					EE_TEMPLATES . $current_theme,
240
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
+					EE_PLUGIN_DIR_PATH,
242
+				];
243
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
+			}
245
+
246
+			// now filter that array
247
+			$template_folder_paths = apply_filters(
248
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
249
+				$template_folder_paths
250
+			);
251
+			$templates             = is_array($templates) ? $templates : [$templates];
252
+			$template_folder_paths =
253
+				is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
+			// array to hold all possible template paths
255
+			$full_template_paths = [];
256
+			$file_name           = '';
257
+
258
+			// loop through $templates
259
+			foreach ($templates as $template) {
260
+				// normalize directory separators
261
+				$template                      = EEH_File::standardise_directory_separators($template);
262
+				$file_name                     = basename($template);
263
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
+				// while looping through all template folder paths
265
+				foreach ($template_folder_paths as $template_folder_path) {
266
+					// normalize directory separators
267
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
+					// determine if any common base path exists between the two paths
269
+					$common_base_path = EEH_Template::_find_common_base_path(
270
+						[$template_folder_path, $template_path_minus_file_name]
271
+					);
272
+					if ($common_base_path !== '') {
273
+						// both paths have a common base, so just tack the filename onto our search path
274
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
+					} else {
276
+						// no common base path, so let's just concatenate
277
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
+					}
279
+					// build up our template locations array by adding our resolved paths
280
+					$full_template_paths[] = $resolved_path;
281
+				}
282
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
+				array_unshift($full_template_paths, $template);
284
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
+				array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
+			}
287
+			// filter final array of full template paths
288
+			$full_template_paths = apply_filters(
289
+				'FHEE__EEH_Template__locate_template__full_template_paths',
290
+				$full_template_paths,
291
+				$file_name
292
+			);
293
+			// now loop through our final array of template location paths and check each location
294
+			foreach ((array) $full_template_paths as $full_template_path) {
295
+				if (is_readable($full_template_path)) {
296
+					$template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
+					break;
298
+				}
299
+			}
300
+		}
301
+
302
+		// hook that can be used to display the full template path that will be used
303
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
+
305
+		// if we got it and you want to see it...
306
+		if ($template_path && $load && ! $check_if_custom) {
307
+			if ($return_string) {
308
+				return EEH_Template::display_template($template_path, $template_args, true);
309
+			}
310
+			EEH_Template::display_template($template_path, $template_args);
311
+		}
312
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
+	}
314
+
315
+
316
+	/**
317
+	 * _find_common_base_path
318
+	 * given two paths, this determines if there is a common base path between the two
319
+	 *
320
+	 * @param array $paths
321
+	 * @return string
322
+	 */
323
+	protected static function _find_common_base_path($paths)
324
+	{
325
+		$last_offset      = 0;
326
+		$common_base_path = '';
327
+		while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
+			$dir_length = $index - $last_offset + 1;
329
+			$directory  = substr($paths[0], $last_offset, $dir_length);
330
+			foreach ($paths as $path) {
331
+				if (substr($path, $last_offset, $dir_length) != $directory) {
332
+					return $common_base_path;
333
+				}
334
+			}
335
+			$common_base_path .= $directory;
336
+			$last_offset      = $index + 1;
337
+		}
338
+		return substr($common_base_path, 0, -1);
339
+	}
340
+
341
+
342
+	/**
343
+	 * load and display a template
344
+	 *
345
+	 * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
+	 * @param array       $template_args    an array of arguments to be extracted for use in the template
347
+	 * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
+	 *                                      string
349
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
+	 *                                      not found or is not readable
351
+	 * @return string
352
+	 * @throws DomainException
353
+	 */
354
+	public static function display_template(
355
+		$template_path = false,
356
+		$template_args = [],
357
+		$return_string = false,
358
+		$throw_exceptions = false
359
+	) {
360
+
361
+		/**
362
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
+		 * the display_template method are templates we DON'T want modified (usually because of js
365
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
+		 * using this.
367
+		 *
368
+		 * @since 4.6.0
369
+		 */
370
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
+
373
+		// you gimme nuttin - YOU GET NUTTIN !!
374
+		if (! $template_path || ! is_readable($template_path)) {
375
+			// ignore whether template is accessible ?
376
+			if ($throw_exceptions) {
377
+				throw new DomainException(
378
+					esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
+				);
380
+			}
381
+			return '';
382
+		}
383
+		// if $template_args are not in an array, then make it so
384
+		if (! is_array($template_args) && ! is_object($template_args)) {
385
+			$template_args = [$template_args];
386
+		}
387
+		extract($template_args, EXTR_SKIP);
388
+
389
+		if ($return_string) {
390
+			// because we want to return a string, we are going to capture the output
391
+			ob_start();
392
+			include($template_path);
393
+			return ob_get_clean();
394
+		}
395
+		include($template_path);
396
+		return '';
397
+	}
398
+
399
+
400
+	/**
401
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
+	 *
403
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
404
+	 * @param string        $prefix added to the beginning of the generated class
405
+	 * @param string        $suffix added to the end of the generated class
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 * @throws ReflectionException
409
+	 */
410
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
+	{
412
+		// in the beginning...
413
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
+		// da muddle
415
+		$class = '';
416
+		// the end
417
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
+		// is the passed object an EE object ?
419
+		if ($object instanceof EE_Base_Class) {
420
+			// grab the exact type of object
421
+			$obj_class = get_class($object);
422
+			// depending on the type of object...
423
+			switch ($obj_class) {
424
+				// no specifics just yet...
425
+				default:
426
+					$class = strtolower(str_replace('_', '-', $obj_class));
427
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
+			}
429
+		}
430
+		return $prefix . $class . $suffix;
431
+	}
432
+
433
+
434
+	/**
435
+	 * EEH_Template::format_currency
436
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
+	 * the country currency settings from the supplied country ISO code
438
+	 *
439
+	 * @param float   $amount       raw money value
440
+	 * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
+	 * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
+	 * @param string  $CNT_ISO      2 letter ISO code for a country
443
+	 * @param string  $cur_code_span_class
444
+	 * @return string        the html output for the formatted money value
445
+	 */
446
+	public static function format_currency(
447
+		$amount = null,
448
+		$return_raw = false,
449
+		$display_code = true,
450
+		$CNT_ISO = '',
451
+		$cur_code_span_class = 'currency-code'
452
+	) {
453
+		// ensure amount was received
454
+		if ($amount === null) {
455
+			$msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
+			return '';
458
+		}
459
+		// ensure amount is float
460
+		$amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
463
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
+		// still a number, or was amount converted to a string like "free" ?
465
+		if (! is_float($amount_formatted)) {
466
+			return esc_html($amount_formatted);
467
+		}
468
+		try {
469
+			// was a country ISO code passed ? if so generate currency config object for that country
470
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
+		} catch (Exception $e) {
472
+			// eat exception
473
+			$mny = null;
474
+		}
475
+		// verify results
476
+		if (! $mny instanceof EE_Currency_Config) {
477
+			// set default config country currency settings
478
+			$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
+				? EE_Registry::instance()->CFG->currency
480
+				: new EE_Currency_Config();
481
+		}
482
+		// format float
483
+		$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
+		// add formatting ?
485
+		if (! $return_raw) {
486
+			// add currency sign
487
+			if ($mny->sign_b4) {
488
+				if ($amount >= 0) {
489
+					$amount_formatted = $mny->sign . $amount_formatted;
490
+				} else {
491
+					$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
+				}
493
+			} else {
494
+				$amount_formatted = $amount_formatted . $mny->sign;
495
+			}
496
+
497
+			// filter to allow global setting of display_code
498
+			$display_code = (bool) apply_filters(
499
+				'FHEE__EEH_Template__format_currency__display_code',
500
+				$display_code
501
+			);
502
+
503
+			// add currency code ?
504
+			$amount_formatted = $display_code
505
+				? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
+				: $amount_formatted;
507
+		}
508
+		// filter results
509
+		$amount_formatted = apply_filters(
510
+			'FHEE__EEH_Template__format_currency__amount_formatted',
511
+			$amount_formatted,
512
+			$mny,
513
+			$return_raw
514
+		);
515
+		// clean up vars
516
+		unset($mny);
517
+		// return formatted currency amount
518
+		return $amount_formatted;
519
+	}
520
+
521
+
522
+	/**
523
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
524
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
+	 * related status model or model object (i.e. in documentation etc.)
526
+	 *
527
+	 * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
+	 *                            match, then 'Unknown' will be returned.
529
+	 * @param boolean $plural     Whether to return plural or not
530
+	 * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
+	 * @return string             The localized label for the status id.
532
+	 * @throws EE_Error
533
+	 */
534
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
+	{
536
+		$status = EEM_Status::instance()->localized_status(
537
+			[$status_id => esc_html__('unknown', 'event_espresso')],
538
+			$plural,
539
+			$schema
540
+		);
541
+		return $status[ $status_id ];
542
+	}
543
+
544
+
545
+	/**
546
+	 * This helper just returns a button or link for the given parameters
547
+	 *
548
+	 * @param string $url   the url for the link, note that `esc_url` will be called on it
549
+	 * @param string $label What is the label you want displayed for the button
550
+	 * @param string $class what class is used for the button (defaults to 'button-primary')
551
+	 * @param string $icon
552
+	 * @param string $title
553
+	 * @return string the html output for the button
554
+	 */
555
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
556
+	{
557
+		$icon_html = '';
558
+		if (! empty($icon)) {
559
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
+			$dashicons = array_filter($dashicons);
561
+			$count     = count($dashicons);
562
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
+			foreach ($dashicons as $dashicon) {
564
+				$type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
+			}
567
+			$icon_html .= $count > 1 ? '</span>' : '';
568
+		}
569
+		// sanitize & escape
570
+		$id    = sanitize_title_with_dashes($label);
571
+		$url   = esc_url_raw($url);
572
+		$class = esc_attr($class);
573
+		$title = esc_attr($title);
574
+		$label = esc_html($label);
575
+		return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>";
576
+	}
577
+
578
+
579
+	/**
580
+	 * This returns a generated link that will load the related help tab on admin pages.
581
+	 *
582
+	 * @param string      $help_tab_id the id for the connected help tab
583
+	 * @param bool|string $page        The page identifier for the page the help tab is on
584
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
+	 * @return string              generated link
588
+	 */
589
+	public static function get_help_tab_link(
590
+		$help_tab_id,
591
+		$page = false,
592
+		$action = false,
593
+		$icon_style = false,
594
+		$help_text = false
595
+	) {
596
+		global $allowedtags;
597
+		/** @var RequestInterface $request */
598
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
599
+		$page    = $page ?: $request->getRequestParam('page', '', 'key');
600
+		$action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601
+
602
+
603
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
604
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605
+		$help_text    = ! $help_text ? '' : $help_text;
606
+		return '<a id="'
607
+			   . esc_attr($help_tab_lnk)
608
+			   . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
609
+			   . esc_attr($icon)
610
+			   . '" title="'
611
+			   . esc_attr__(
612
+				   'Click to open the \'Help\' tab for more information about this feature.',
613
+				   'event_espresso'
614
+			   )
615
+			   . '" > '
616
+			   . wp_kses($help_text, $allowedtags)
617
+			   . ' </a>';
618
+	}
619
+
620
+
621
+	/**
622
+	 * This is a helper method to generate a status legend for a given status array.
623
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
624
+	 * status_array.
625
+	 *
626
+	 * @param array  $status_array   array of statuses that will make up the legend. In format:
627
+	 *                               array(
628
+	 *                               'status_item' => 'status_name'
629
+	 *                               )
630
+	 * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
631
+	 *                               the legend.
632
+	 * @return string               html structure for status.
633
+	 * @throws EE_Error
634
+	 */
635
+	public static function status_legend($status_array, $active_status = '')
636
+	{
637
+		if (! is_array($status_array)) {
638
+			throw new EE_Error(
639
+				esc_html__(
640
+					'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
641
+					'event_espresso'
642
+				)
643
+			);
644
+		}
645
+
646
+		$content = '
647 647
             <div class="ee-list-table-legend-container">
648 648
                 <h4 class="status-legend-title">
649 649
                     ' . esc_html__('Status Legend', 'event_espresso') . '
650 650
                 </h4>
651 651
                 <dl class="ee-list-table-legend">';
652 652
 
653
-        foreach ($status_array as $item => $status) {
654
-            $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
-            $content      .= '
653
+		foreach ($status_array as $item => $status) {
654
+			$active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
+			$content      .= '
656 656
                     <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
657 657
                         <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span>
658 658
                         <span class="ee-legend-description">
659 659
                             ' . EEH_Template::pretty_status($status, false, 'sentence') . '
660 660
                         </span>
661 661
                     </dt>';
662
-        }
662
+		}
663 663
 
664
-        $content .= '
664
+		$content .= '
665 665
                 </dl>
666 666
             </div>
667 667
 ';
668
-        return $content;
669
-    }
670
-
671
-
672
-    /**
673
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
674
-     * that's nice for presenting in the wp admin
675
-     *
676
-     * @param mixed $data
677
-     * @return string
678
-     */
679
-    public static function layout_array_as_table($data)
680
-    {
681
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
682
-            $data = (array) $data;
683
-        }
684
-        ob_start();
685
-        if (is_array($data)) {
686
-            if (EEH_Array::is_associative_array($data)) { ?>
668
+		return $content;
669
+	}
670
+
671
+
672
+	/**
673
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
674
+	 * that's nice for presenting in the wp admin
675
+	 *
676
+	 * @param mixed $data
677
+	 * @return string
678
+	 */
679
+	public static function layout_array_as_table($data)
680
+	{
681
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
682
+			$data = (array) $data;
683
+		}
684
+		ob_start();
685
+		if (is_array($data)) {
686
+			if (EEH_Array::is_associative_array($data)) { ?>
687 687
                 <table class="widefat">
688 688
                     <tbody>
689 689
                     <?php foreach ($data as $data_key => $data_values) { ?>
@@ -701,292 +701,292 @@  discard block
 block discarded – undo
701 701
             <?php } else { ?>
702 702
                 <ul>
703 703
                     <?php
704
-                    foreach ($data as $datum) {
705
-                        echo "<li>";
706
-                        echo self::layout_array_as_table($datum);
707
-                        echo "</li>";
708
-                    } ?>
704
+					foreach ($data as $datum) {
705
+						echo "<li>";
706
+						echo self::layout_array_as_table($datum);
707
+						echo "</li>";
708
+					} ?>
709 709
                 </ul>
710 710
             <?php }
711
-        } else {
712
-            // simple value
713
-            echo esc_html($data);
714
-        }
715
-        return ob_get_clean();
716
-    }
717
-
718
-
719
-    /**
720
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
721
-     *
722
-     * @param        $total_items
723
-     * @param        $current
724
-     * @param        $per_page
725
-     * @param        $url
726
-     * @param bool   $show_num_field
727
-     * @param string $paged_arg_name
728
-     * @param array  $items_label
729
-     * @see   self:get_paging_html() for argument docs.
730
-     * @since 4.4.0
731
-     */
732
-    public static function paging_html(
733
-        $total_items,
734
-        $current,
735
-        $per_page,
736
-        $url,
737
-        $show_num_field = true,
738
-        $paged_arg_name = 'paged',
739
-        $items_label = []
740
-    ) {
741
-        echo self::get_paging_html(
742
-            $total_items,
743
-            $current,
744
-            $per_page,
745
-            $url,
746
-            $show_num_field,
747
-            $paged_arg_name,
748
-            $items_label
749
-        );
750
-    }
751
-
752
-
753
-    /**
754
-     * A method for generating paging similar to WP_List_Table
755
-     *
756
-     * @param integer $total_items      How many total items there are to page.
757
-     * @param integer $current          What the current page is.
758
-     * @param integer $per_page         How many items per page.
759
-     * @param string  $url              What the base url for page links is.
760
-     * @param boolean $show_num_field   Whether to show the input for changing page number.
761
-     * @param string  $paged_arg_name   The name of the key for the paged query argument.
762
-     * @param array   $items_label      An array of singular/plural values for the items label:
763
-     *                                  array(
764
-     *                                  'single' => 'item',
765
-     *                                  'plural' => 'items'
766
-     *                                  )
767
-     * @return  string
768
-     * @since    4.4.0
769
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
770
-     */
771
-    public static function get_paging_html(
772
-        $total_items,
773
-        $current,
774
-        $per_page,
775
-        $url,
776
-        $show_num_field = true,
777
-        $paged_arg_name = 'paged',
778
-        $items_label = []
779
-    ) {
780
-        $page_links     = [];
781
-        $disable_first  = $disable_last = '';
782
-        $total_items    = (int) $total_items;
783
-        $per_page       = (int) $per_page;
784
-        $current        = (int) $current;
785
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
786
-
787
-        // filter items_label
788
-        $items_label = apply_filters(
789
-            'FHEE__EEH_Template__get_paging_html__items_label',
790
-            $items_label
791
-        );
792
-
793
-        if (
794
-            empty($items_label)
795
-            || ! is_array($items_label)
796
-            || ! isset($items_label['single'])
797
-            || ! isset($items_label['plural'])
798
-        ) {
799
-            $items_label = [
800
-                'single' => esc_html__('1 item', 'event_espresso'),
801
-                'plural' => esc_html__('%s items', 'event_espresso'),
802
-            ];
803
-        } else {
804
-            $items_label = [
805
-                'single' => '1 ' . esc_html($items_label['single']),
806
-                'plural' => '%s ' . esc_html($items_label['plural']),
807
-            ];
808
-        }
809
-
810
-        $total_pages = ceil($total_items / $per_page);
811
-
812
-        if ($total_pages <= 1) {
813
-            return '';
814
-        }
815
-
816
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817
-
818
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
819
-
820
-        if ($current === 1) {
821
-            $disable_first = ' disabled';
822
-        }
823
-        if ($current == $total_pages) {
824
-            $disable_last = ' disabled';
825
-        }
826
-
827
-        $page_links[] = sprintf(
828
-            "<a class='%s' title='%s' href='%s'>%s</a>",
829
-            'first-page' . $disable_first,
830
-            esc_attr__('Go to the first page', 'event_espresso'),
831
-            esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832
-            '&laquo;'
833
-        );
834
-
835
-        $page_links[] = sprintf(
836
-            '<a class="%s" title="%s" href="%s">%s</a>',
837
-            'prev-page' . $disable_first,
838
-            esc_attr__('Go to the previous page', 'event_espresso'),
839
-            esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840
-            '&lsaquo;'
841
-        );
842
-
843
-        if (! $show_num_field) {
844
-            $html_current_page = $current;
845
-        } else {
846
-            $html_current_page = sprintf(
847
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
848
-                esc_attr__('Current page', 'event_espresso'),
849
-                esc_attr($current),
850
-                strlen($total_pages)
851
-            );
852
-        }
853
-
854
-        $html_total_pages = sprintf(
855
-            '<span class="total-pages">%s</span>',
856
-            number_format_i18n($total_pages)
857
-        );
858
-        $page_links[]     = sprintf(
859
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860
-            $html_current_page,
861
-            $html_total_pages,
862
-            '<span class="paging-input">',
863
-            '</span>'
864
-        );
865
-
866
-        $page_links[] = sprintf(
867
-            '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'next-page' . $disable_last,
869
-            esc_attr__('Go to the next page', 'event_espresso'),
870
-            esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871
-            '&rsaquo;'
872
-        );
873
-
874
-        $page_links[] = sprintf(
875
-            '<a class="%s" title="%s" href="%s">%s</a>',
876
-            'last-page' . $disable_last,
877
-            esc_attr__('Go to the last page', 'event_espresso'),
878
-            esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879
-            '&raquo;'
880
-        );
881
-
882
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
883
-        // set page class
884
-        if ($total_pages) {
885
-            $page_class = $total_pages < 2 ? ' one-page' : '';
886
-        } else {
887
-            $page_class = ' no-pages';
888
-        }
889
-
890
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
891
-    }
892
-
893
-
894
-    /**
895
-     * @param string $wrap_class
896
-     * @param string $wrap_id
897
-     * @return string
898
-     */
899
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
900
-    {
901
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
902
-        if (
903
-            ! $admin
904
-            && ! apply_filters(
905
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
906
-                EE_Registry::instance()->CFG->admin->show_reg_footer
907
-            )
908
-        ) {
909
-            return '';
910
-        }
911
-        $tag        = $admin ? 'span' : 'div';
912
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
913
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
914
-        $attributes .= ! empty($wrap_class)
915
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
916
-            : ' class="powered-by-event-espresso-credit"';
917
-        $query_args = array_merge(
918
-            [
919
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
920
-                'utm_source'   => 'powered_by_event_espresso',
921
-                'utm_medium'   => 'link',
922
-                'utm_campaign' => 'powered_by',
923
-            ],
924
-            $query_args
925
-        );
926
-        $powered_by = apply_filters(
927
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
928
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
929
-        );
930
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
931
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
932
-        return (string) apply_filters(
933
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
934
-            sprintf(
935
-                esc_html_x(
936
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
937
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
938
-                    'event_espresso'
939
-                ),
940
-                "<{$tag}{$attributes}>",
941
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
942
-                $admin ? '' : '<br />'
943
-            ),
944
-            $wrap_class,
945
-            $wrap_id
946
-        );
947
-    }
948
-
949
-
950
-    /**
951
-     * @param string $image_name
952
-     * @return string|null
953
-     * @since   4.10.14.p
954
-     */
955
-    public static function getScreenshotUrl($image_name)
956
-    {
957
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
958
-    }
711
+		} else {
712
+			// simple value
713
+			echo esc_html($data);
714
+		}
715
+		return ob_get_clean();
716
+	}
717
+
718
+
719
+	/**
720
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
721
+	 *
722
+	 * @param        $total_items
723
+	 * @param        $current
724
+	 * @param        $per_page
725
+	 * @param        $url
726
+	 * @param bool   $show_num_field
727
+	 * @param string $paged_arg_name
728
+	 * @param array  $items_label
729
+	 * @see   self:get_paging_html() for argument docs.
730
+	 * @since 4.4.0
731
+	 */
732
+	public static function paging_html(
733
+		$total_items,
734
+		$current,
735
+		$per_page,
736
+		$url,
737
+		$show_num_field = true,
738
+		$paged_arg_name = 'paged',
739
+		$items_label = []
740
+	) {
741
+		echo self::get_paging_html(
742
+			$total_items,
743
+			$current,
744
+			$per_page,
745
+			$url,
746
+			$show_num_field,
747
+			$paged_arg_name,
748
+			$items_label
749
+		);
750
+	}
751
+
752
+
753
+	/**
754
+	 * A method for generating paging similar to WP_List_Table
755
+	 *
756
+	 * @param integer $total_items      How many total items there are to page.
757
+	 * @param integer $current          What the current page is.
758
+	 * @param integer $per_page         How many items per page.
759
+	 * @param string  $url              What the base url for page links is.
760
+	 * @param boolean $show_num_field   Whether to show the input for changing page number.
761
+	 * @param string  $paged_arg_name   The name of the key for the paged query argument.
762
+	 * @param array   $items_label      An array of singular/plural values for the items label:
763
+	 *                                  array(
764
+	 *                                  'single' => 'item',
765
+	 *                                  'plural' => 'items'
766
+	 *                                  )
767
+	 * @return  string
768
+	 * @since    4.4.0
769
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
770
+	 */
771
+	public static function get_paging_html(
772
+		$total_items,
773
+		$current,
774
+		$per_page,
775
+		$url,
776
+		$show_num_field = true,
777
+		$paged_arg_name = 'paged',
778
+		$items_label = []
779
+	) {
780
+		$page_links     = [];
781
+		$disable_first  = $disable_last = '';
782
+		$total_items    = (int) $total_items;
783
+		$per_page       = (int) $per_page;
784
+		$current        = (int) $current;
785
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
786
+
787
+		// filter items_label
788
+		$items_label = apply_filters(
789
+			'FHEE__EEH_Template__get_paging_html__items_label',
790
+			$items_label
791
+		);
792
+
793
+		if (
794
+			empty($items_label)
795
+			|| ! is_array($items_label)
796
+			|| ! isset($items_label['single'])
797
+			|| ! isset($items_label['plural'])
798
+		) {
799
+			$items_label = [
800
+				'single' => esc_html__('1 item', 'event_espresso'),
801
+				'plural' => esc_html__('%s items', 'event_espresso'),
802
+			];
803
+		} else {
804
+			$items_label = [
805
+				'single' => '1 ' . esc_html($items_label['single']),
806
+				'plural' => '%s ' . esc_html($items_label['plural']),
807
+			];
808
+		}
809
+
810
+		$total_pages = ceil($total_items / $per_page);
811
+
812
+		if ($total_pages <= 1) {
813
+			return '';
814
+		}
815
+
816
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817
+
818
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
819
+
820
+		if ($current === 1) {
821
+			$disable_first = ' disabled';
822
+		}
823
+		if ($current == $total_pages) {
824
+			$disable_last = ' disabled';
825
+		}
826
+
827
+		$page_links[] = sprintf(
828
+			"<a class='%s' title='%s' href='%s'>%s</a>",
829
+			'first-page' . $disable_first,
830
+			esc_attr__('Go to the first page', 'event_espresso'),
831
+			esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832
+			'&laquo;'
833
+		);
834
+
835
+		$page_links[] = sprintf(
836
+			'<a class="%s" title="%s" href="%s">%s</a>',
837
+			'prev-page' . $disable_first,
838
+			esc_attr__('Go to the previous page', 'event_espresso'),
839
+			esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840
+			'&lsaquo;'
841
+		);
842
+
843
+		if (! $show_num_field) {
844
+			$html_current_page = $current;
845
+		} else {
846
+			$html_current_page = sprintf(
847
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
848
+				esc_attr__('Current page', 'event_espresso'),
849
+				esc_attr($current),
850
+				strlen($total_pages)
851
+			);
852
+		}
853
+
854
+		$html_total_pages = sprintf(
855
+			'<span class="total-pages">%s</span>',
856
+			number_format_i18n($total_pages)
857
+		);
858
+		$page_links[]     = sprintf(
859
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860
+			$html_current_page,
861
+			$html_total_pages,
862
+			'<span class="paging-input">',
863
+			'</span>'
864
+		);
865
+
866
+		$page_links[] = sprintf(
867
+			'<a class="%s" title="%s" href="%s">%s</a>',
868
+			'next-page' . $disable_last,
869
+			esc_attr__('Go to the next page', 'event_espresso'),
870
+			esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871
+			'&rsaquo;'
872
+		);
873
+
874
+		$page_links[] = sprintf(
875
+			'<a class="%s" title="%s" href="%s">%s</a>',
876
+			'last-page' . $disable_last,
877
+			esc_attr__('Go to the last page', 'event_espresso'),
878
+			esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879
+			'&raquo;'
880
+		);
881
+
882
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
883
+		// set page class
884
+		if ($total_pages) {
885
+			$page_class = $total_pages < 2 ? ' one-page' : '';
886
+		} else {
887
+			$page_class = ' no-pages';
888
+		}
889
+
890
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
891
+	}
892
+
893
+
894
+	/**
895
+	 * @param string $wrap_class
896
+	 * @param string $wrap_id
897
+	 * @return string
898
+	 */
899
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
900
+	{
901
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
902
+		if (
903
+			! $admin
904
+			&& ! apply_filters(
905
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
906
+				EE_Registry::instance()->CFG->admin->show_reg_footer
907
+			)
908
+		) {
909
+			return '';
910
+		}
911
+		$tag        = $admin ? 'span' : 'div';
912
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
913
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
914
+		$attributes .= ! empty($wrap_class)
915
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
916
+			: ' class="powered-by-event-espresso-credit"';
917
+		$query_args = array_merge(
918
+			[
919
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
920
+				'utm_source'   => 'powered_by_event_espresso',
921
+				'utm_medium'   => 'link',
922
+				'utm_campaign' => 'powered_by',
923
+			],
924
+			$query_args
925
+		);
926
+		$powered_by = apply_filters(
927
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
928
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
929
+		);
930
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
931
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
932
+		return (string) apply_filters(
933
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
934
+			sprintf(
935
+				esc_html_x(
936
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
937
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
938
+					'event_espresso'
939
+				),
940
+				"<{$tag}{$attributes}>",
941
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
942
+				$admin ? '' : '<br />'
943
+			),
944
+			$wrap_class,
945
+			$wrap_id
946
+		);
947
+	}
948
+
949
+
950
+	/**
951
+	 * @param string $image_name
952
+	 * @return string|null
953
+	 * @since   4.10.14.p
954
+	 */
955
+	public static function getScreenshotUrl($image_name)
956
+	{
957
+		return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
958
+	}
959 959
 }
960 960
 
961 961
 
962 962
 if (! function_exists('espresso_pagination')) {
963
-    /**
964
-     *    espresso_pagination
965
-     *
966
-     * @access    public
967
-     * @return    void
968
-     */
969
-    function espresso_pagination()
970
-    {
971
-        global $wp_query;
972
-        $big        = 999999999; // need an unlikely integer
973
-        $pagination = paginate_links(
974
-            [
975
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
976
-                'format'       => '?paged=%#%',
977
-                'current'      => max(1, get_query_var('paged')),
978
-                'total'        => $wp_query->max_num_pages,
979
-                'show_all'     => true,
980
-                'end_size'     => 10,
981
-                'mid_size'     => 6,
982
-                'prev_next'    => true,
983
-                'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
984
-                'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
985
-                'type'         => 'plain',
986
-                'add_args'     => false,
987
-                'add_fragment' => '',
988
-            ]
989
-        );
990
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
991
-    }
963
+	/**
964
+	 *    espresso_pagination
965
+	 *
966
+	 * @access    public
967
+	 * @return    void
968
+	 */
969
+	function espresso_pagination()
970
+	{
971
+		global $wp_query;
972
+		$big        = 999999999; // need an unlikely integer
973
+		$pagination = paginate_links(
974
+			[
975
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
976
+				'format'       => '?paged=%#%',
977
+				'current'      => max(1, get_query_var('paged')),
978
+				'total'        => $wp_query->max_num_pages,
979
+				'show_all'     => true,
980
+				'end_size'     => 10,
981
+				'mid_size'     => 6,
982
+				'prev_next'    => true,
983
+				'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
984
+				'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
985
+				'type'         => 'plain',
986
+				'add_args'     => false,
987
+				'add_fragment' => '',
988
+			]
989
+		);
990
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
991
+	}
992 992
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 use EventEspresso\core\services\request\RequestInterface;
7 7
 
8
-if (! function_exists('espresso_get_template_part')) {
8
+if ( ! function_exists('espresso_get_template_part')) {
9 9
     /**
10 10
      * espresso_get_template_part
11 11
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public static function load_espresso_theme_functions()
74 74
     {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) {
77
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php');
78 78
             }
79 79
         }
80 80
     }
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
     public static function get_espresso_themes()
89 89
     {
90 90
         if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
91
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
92 92
             if (empty($espresso_themes)) {
93 93
                 return [];
94 94
             }
95 95
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
96
+                unset($espresso_themes[$key]);
97 97
             }
98 98
             EEH_Template::$_espresso_themes = [];
99 99
             foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
100
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
101 101
             }
102 102
         }
103 103
         return EEH_Template::$_espresso_themes;
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
                 // get array of EE Custom Post Types
214 214
                 $EE_CPTs = $custom_post_types->getDefinitions();
215 215
                 // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
216
+                if (isset($EE_CPTs[$post_type])) {
217 217
                     $archive_or_single = is_archive() ? 'archive' : '';
218 218
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
219
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
220 220
                 }
221 221
             }
222 222
             // currently active EE template theme
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
             // array of paths to folders that may contain templates
226 226
             $template_folder_paths = [
227 227
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
228
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
229 229
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
230 230
                 EVENT_ESPRESSO_TEMPLATE_DIR,
231 231
             ];
232 232
 
233 233
             // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
234
+            if ( ! $check_if_custom) {
235
+                $core_paths = [
236 236
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
237
+                    EE_PUBLIC.$current_theme,
238 238
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
239
+                    EE_TEMPLATES.$current_theme,
240 240
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241 241
                     EE_PLUGIN_DIR_PATH,
242 242
                 ];
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
                     );
272 272
                     if ($common_base_path !== '') {
273 273
                         // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
274
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
275 275
                     } else {
276 276
                         // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
277
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
278 278
                     }
279 279
                     // build up our template locations array by adding our resolved paths
280 280
                     $full_template_paths[] = $resolved_path;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283 283
                 array_unshift($full_template_paths, $template);
284 284
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
285
+                array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name);
286 286
             }
287 287
             // filter final array of full template paths
288 288
             $full_template_paths = apply_filters(
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                 }
334 334
             }
335 335
             $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
336
+            $last_offset = $index + 1;
337 337
         }
338 338
         return substr($common_base_path, 0, -1);
339 339
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372 372
 
373 373
         // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
374
+        if ( ! $template_path || ! is_readable($template_path)) {
375 375
             // ignore whether template is accessible ?
376 376
             if ($throw_exceptions) {
377 377
                 throw new DomainException(
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             return '';
382 382
         }
383 383
         // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
384
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
385 385
             $template_args = [$template_args];
386 386
         }
387 387
         extract($template_args, EXTR_SKIP);
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411 411
     {
412 412
         // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
413
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
414 414
         // da muddle
415 415
         $class = '';
416 416
         // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
417
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
418 418
         // is the passed object an EE object ?
419 419
         if ($object instanceof EE_Base_Class) {
420 420
             // grab the exact type of object
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
                 // no specifics just yet...
425 425
                 default:
426 426
                     $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
427
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
428 428
             }
429 429
         }
430
-        return $prefix . $class . $suffix;
430
+        return $prefix.$class.$suffix;
431 431
     }
432 432
 
433 433
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         // filter raw amount (allows 0.00 to be changed to "free" for example)
463 463
         $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464 464
         // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
465
+        if ( ! is_float($amount_formatted)) {
466 466
             return esc_html($amount_formatted);
467 467
         }
468 468
         try {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
             $mny = null;
474 474
         }
475 475
         // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
476
+        if ( ! $mny instanceof EE_Currency_Config) {
477 477
             // set default config country currency settings
478 478
             $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479 479
                 ? EE_Registry::instance()->CFG->currency
@@ -482,16 +482,16 @@  discard block
 block discarded – undo
482 482
         // format float
483 483
         $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484 484
         // add formatting ?
485
-        if (! $return_raw) {
485
+        if ( ! $return_raw) {
486 486
             // add currency sign
487 487
             if ($mny->sign_b4) {
488 488
                 if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
489
+                    $amount_formatted = $mny->sign.$amount_formatted;
490 490
                 } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
491
+                    $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
492 492
                 }
493 493
             } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
494
+                $amount_formatted = $amount_formatted.$mny->sign;
495 495
             }
496 496
 
497 497
             // filter to allow global setting of display_code
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 
503 503
             // add currency code ?
504 504
             $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
505
+                ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>'
506 506
                 : $amount_formatted;
507 507
         }
508 508
         // filter results
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             $plural,
539 539
             $schema
540 540
         );
541
-        return $status[ $status_id ];
541
+        return $status[$status_id];
542 542
     }
543 543
 
544 544
 
@@ -555,14 +555,14 @@  discard block
 block discarded – undo
555 555
     public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
556 556
     {
557 557
         $icon_html = '';
558
-        if (! empty($icon)) {
558
+        if ( ! empty($icon)) {
559 559
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560 560
             $dashicons = array_filter($dashicons);
561 561
             $count     = count($dashicons);
562 562
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563 563
             foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
564
+                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
566 566
             }
567 567
             $icon_html .= $count > 1 ? '</span>' : '';
568 568
         }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
         $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601 601
 
602 602
 
603
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
603
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
604 604
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605 605
         $help_text    = ! $help_text ? '' : $help_text;
606 606
         return '<a id="'
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
      */
635 635
     public static function status_legend($status_array, $active_status = '')
636 636
     {
637
-        if (! is_array($status_array)) {
637
+        if ( ! is_array($status_array)) {
638 638
             throw new EE_Error(
639 639
                 esc_html__(
640 640
                     'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
@@ -646,17 +646,17 @@  discard block
 block discarded – undo
646 646
         $content = '
647 647
             <div class="ee-list-table-legend-container">
648 648
                 <h4 class="status-legend-title">
649
-                    ' . esc_html__('Status Legend', 'event_espresso') . '
649
+                    ' . esc_html__('Status Legend', 'event_espresso').'
650 650
                 </h4>
651 651
                 <dl class="ee-list-table-legend">';
652 652
 
653 653
         foreach ($status_array as $item => $status) {
654 654
             $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
-            $content      .= '
656
-                    <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
657
-                        <span class="' . esc_attr('ee-status-legend ee-status-legend-' . $status) . '"></span>
655
+            $content .= '
656
+                    <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'>
657
+                        <span class="' . esc_attr('ee-status-legend ee-status-legend-'.$status).'"></span>
658 658
                         <span class="ee-legend-description">
659
-                            ' . EEH_Template::pretty_status($status, false, 'sentence') . '
659
+                            ' . EEH_Template::pretty_status($status, false, 'sentence').'
660 660
                         </span>
661 661
                     </dt>';
662 662
         }
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
             ];
803 803
         } else {
804 804
             $items_label = [
805
-                'single' => '1 ' . esc_html($items_label['single']),
806
-                'plural' => '%s ' . esc_html($items_label['plural']),
805
+                'single' => '1 '.esc_html($items_label['single']),
806
+                'plural' => '%s '.esc_html($items_label['plural']),
807 807
             ];
808 808
         }
809 809
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 
816 816
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817 817
 
818
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
818
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
819 819
 
820 820
         if ($current === 1) {
821 821
             $disable_first = ' disabled';
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 
827 827
         $page_links[] = sprintf(
828 828
             "<a class='%s' title='%s' href='%s'>%s</a>",
829
-            'first-page' . $disable_first,
829
+            'first-page'.$disable_first,
830 830
             esc_attr__('Go to the first page', 'event_espresso'),
831 831
             esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832 832
             '&laquo;'
@@ -834,13 +834,13 @@  discard block
 block discarded – undo
834 834
 
835 835
         $page_links[] = sprintf(
836 836
             '<a class="%s" title="%s" href="%s">%s</a>',
837
-            'prev-page' . $disable_first,
837
+            'prev-page'.$disable_first,
838 838
             esc_attr__('Go to the previous page', 'event_espresso'),
839 839
             esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840 840
             '&lsaquo;'
841 841
         );
842 842
 
843
-        if (! $show_num_field) {
843
+        if ( ! $show_num_field) {
844 844
             $html_current_page = $current;
845 845
         } else {
846 846
             $html_current_page = sprintf(
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
             '<span class="total-pages">%s</span>',
856 856
             number_format_i18n($total_pages)
857 857
         );
858
-        $page_links[]     = sprintf(
858
+        $page_links[] = sprintf(
859 859
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860 860
             $html_current_page,
861 861
             $html_total_pages,
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
         $page_links[] = sprintf(
867 867
             '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'next-page' . $disable_last,
868
+            'next-page'.$disable_last,
869 869
             esc_attr__('Go to the next page', 'event_espresso'),
870 870
             esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871 871
             '&rsaquo;'
@@ -873,13 +873,13 @@  discard block
 block discarded – undo
873 873
 
874 874
         $page_links[] = sprintf(
875 875
             '<a class="%s" title="%s" href="%s">%s</a>',
876
-            'last-page' . $disable_last,
876
+            'last-page'.$disable_last,
877 877
             esc_attr__('Go to the last page', 'event_espresso'),
878 878
             esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879 879
             '&raquo;'
880 880
         );
881 881
 
882
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
882
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
883 883
         // set page class
884 884
         if ($total_pages) {
885 885
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
             $page_class = ' no-pages';
888 888
         }
889 889
 
890
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
890
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
891 891
     }
892 892
 
893 893
 
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
         );
926 926
         $powered_by = apply_filters(
927 927
             'FHEE__EEH_Template__powered_by_event_espresso_text',
928
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
928
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
929 929
         );
930 930
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
931 931
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -954,12 +954,12 @@  discard block
 block discarded – undo
954 954
      */
955 955
     public static function getScreenshotUrl($image_name)
956 956
     {
957
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
957
+        return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg');
958 958
     }
959 959
 }
960 960
 
961 961
 
962
-if (! function_exists('espresso_pagination')) {
962
+if ( ! function_exists('espresso_pagination')) {
963 963
     /**
964 964
      *    espresso_pagination
965 965
      *
@@ -987,6 +987,6 @@  discard block
 block discarded – undo
987 987
                 'add_fragment' => '',
988 988
             ]
989 989
         );
990
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
990
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
991 991
     }
992 992
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1388 added lines, -1388 removed lines patch added patch discarded remove patch
@@ -16,1392 +16,1392 @@
 block discarded – undo
16 16
 class Extend_Events_Admin_Page extends Events_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Admin_Config
21
-     */
22
-    protected $admin_config;
23
-
24
-    /**
25
-     * @var AdvancedEditorAdminFormSection
26
-     */
27
-    protected $advanced_editor_admin_form;
28
-
29
-
30
-    /**
31
-     * Extend_Events_Admin_Page constructor.
32
-     *
33
-     * @param bool $routing
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
-        }
44
-        parent::__construct($routing);
45
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
-    }
47
-
48
-
49
-    /**
50
-     * Sets routes.
51
-     *
52
-     * @throws EE_Error
53
-     */
54
-    protected function _extend_page_config()
55
-    {
56
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
-        // is there a evt_id in the request?
58
-        $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
-        $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
-        $TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
-        $new_page_routes    = [
62
-            'duplicate_event'          => [
63
-                'func'       => '_duplicate_event',
64
-                'capability' => 'ee_edit_event',
65
-                'obj_id'     => $EVT_ID,
66
-                'noheader'   => true,
67
-            ],
68
-            'import_page'              => [
69
-                'func'       => '_import_page',
70
-                'capability' => 'import',
71
-            ],
72
-            'import'                   => [
73
-                'func'       => '_import_events',
74
-                'capability' => 'import',
75
-                'noheader'   => true,
76
-            ],
77
-            'import_events'            => [
78
-                'func'       => '_import_events',
79
-                'capability' => 'import',
80
-                'noheader'   => true,
81
-            ],
82
-            'export_events'            => [
83
-                'func'       => '_events_export',
84
-                'capability' => 'export',
85
-                'noheader'   => true,
86
-            ],
87
-            'export_categories'        => [
88
-                'func'       => '_categories_export',
89
-                'capability' => 'export',
90
-                'noheader'   => true,
91
-            ],
92
-            'sample_export_file'       => [
93
-                'func'       => '_sample_export_file',
94
-                'capability' => 'export',
95
-                'noheader'   => true,
96
-            ],
97
-            'update_template_settings' => [
98
-                'func'       => '_update_template_settings',
99
-                'capability' => 'manage_options',
100
-                'noheader'   => true,
101
-            ],
102
-            'ticket_list_table'        => [
103
-                'func'       => '_tickets_overview_list_table',
104
-                'capability' => 'ee_read_default_tickets',
105
-            ],
106
-        ];
107
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
-        $this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
-        // don't load these meta boxes if using the advanced editor
110
-        if (
111
-            ! $this->admin_config->useAdvancedEditor()
112
-            || ! $this->feature->allowed('use_default_ticket_manager')
113
-        ) {
114
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
-            $this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
-
117
-            $legacy_editor_page_routes = [
118
-                'trash_ticket'    => [
119
-                    'func'       => '_trash_or_restore_ticket',
120
-                    'capability' => 'ee_delete_default_ticket',
121
-                    'obj_id'     => $TKT_ID,
122
-                    'noheader'   => true,
123
-                    'args'       => ['trash' => true],
124
-                ],
125
-                'trash_tickets'   => [
126
-                    'func'       => '_trash_or_restore_ticket',
127
-                    'capability' => 'ee_delete_default_tickets',
128
-                    'noheader'   => true,
129
-                    'args'       => ['trash' => true],
130
-                ],
131
-                'restore_ticket'  => [
132
-                    'func'       => '_trash_or_restore_ticket',
133
-                    'capability' => 'ee_delete_default_ticket',
134
-                    'obj_id'     => $TKT_ID,
135
-                    'noheader'   => true,
136
-                ],
137
-                'restore_tickets' => [
138
-                    'func'       => '_trash_or_restore_ticket',
139
-                    'capability' => 'ee_delete_default_tickets',
140
-                    'noheader'   => true,
141
-                ],
142
-                'delete_ticket'   => [
143
-                    'func'       => '_delete_ticket',
144
-                    'capability' => 'ee_delete_default_ticket',
145
-                    'obj_id'     => $TKT_ID,
146
-                    'noheader'   => true,
147
-                ],
148
-                'delete_tickets'  => [
149
-                    'func'       => '_delete_ticket',
150
-                    'capability' => 'ee_delete_default_tickets',
151
-                    'noheader'   => true,
152
-                ],
153
-            ];
154
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
-        }
156
-
157
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
-        // partial route/config override
159
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
-        // add tickets tab but only if there are more than one default ticket!
162
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
-            [['TKT_is_default' => 1]],
164
-            'TKT_ID',
165
-            true
166
-        );
167
-        if ($ticket_count > 1) {
168
-            $new_page_config = [
169
-                'ticket_list_table' => [
170
-                    'nav'           => [
171
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
172
-                        'order' => 60,
173
-                    ],
174
-                    'list_table'    => 'Tickets_List_Table',
175
-                    'require_nonce' => false,
176
-                ],
177
-            ];
178
-        }
179
-        // template settings
180
-        $new_page_config['template_settings'] = [
181
-            'nav'           => [
182
-                'label' => esc_html__('Templates', 'event_espresso'),
183
-                'order' => 30,
184
-            ],
185
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
-            'help_tabs'     => [
187
-                'general_settings_templates_help_tab' => [
188
-                    'title'    => esc_html__('Templates', 'event_espresso'),
189
-                    'filename' => 'general_settings_templates',
190
-                ],
191
-            ],
192
-            'require_nonce' => false,
193
-        ];
194
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
195
-        // add filters and actions
196
-        // modifying _views
197
-        add_filter(
198
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
199
-            [$this, 'add_additional_datetime_button'],
200
-            10,
201
-            2
202
-        );
203
-        add_filter(
204
-            'FHEE_event_datetime_metabox_clone_button_template',
205
-            [$this, 'add_datetime_clone_button'],
206
-            10,
207
-            2
208
-        );
209
-        add_filter(
210
-            'FHEE_event_datetime_metabox_timezones_template',
211
-            [$this, 'datetime_timezones_template'],
212
-            10,
213
-            2
214
-        );
215
-        // filters for event list table
216
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
217
-        add_filter(
218
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
219
-            [$this, 'extra_list_table_actions'],
220
-            10,
221
-            2
222
-        );
223
-        // legend item
224
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
225
-        add_action('admin_init', [$this, 'admin_init']);
226
-        // load additional handlers
227
-        $this->handleActionRequest();
228
-    }
229
-
230
-
231
-    private function getRequestAction()
232
-    {
233
-        return $this->request->getRequestParam('action');
234
-    }
235
-
236
-
237
-    /**
238
-     * @throws Exception
239
-     */
240
-    private function handleActionRequest()
241
-    {
242
-        $action = $this->getRequestAction();
243
-        if ($action) {
244
-            // setup Advanced Editor ???
245
-            if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
246
-                $this->advanced_editor_admin_form = $this->loader->getShared(
247
-                    'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
248
-                );
249
-            }
250
-        }
251
-    }
252
-
253
-
254
-    /**
255
-     * admin_init
256
-     */
257
-    public function admin_init()
258
-    {
259
-        EE_Registry::$i18n_js_strings = array_merge(
260
-            EE_Registry::$i18n_js_strings,
261
-            [
262
-                'image_confirm'          => esc_html__(
263
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
264
-                    'event_espresso'
265
-                ),
266
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
267
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
268
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
269
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
270
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
271
-            ]
272
-        );
273
-    }
274
-
275
-
276
-    /**
277
-     * Add per page screen options to the default ticket list table view.
278
-     *
279
-     * @throws InvalidArgumentException
280
-     * @throws InvalidDataTypeException
281
-     * @throws InvalidInterfaceException
282
-     */
283
-    protected function _add_screen_options_ticket_list_table()
284
-    {
285
-        $this->_per_page_screen_option();
286
-    }
287
-
288
-
289
-    /**
290
-     * @param string $return
291
-     * @param int    $id
292
-     * @param string $new_title
293
-     * @param string $new_slug
294
-     * @return string
295
-     */
296
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
297
-    {
298
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
299
-        // make sure this is only when editing
300
-        if (! empty($id)) {
301
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
302
-                ['action' => 'duplicate_event', 'EVT_ID' => $id],
303
-                $this->_admin_base_url
304
-            );
305
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
306
-            $return .= '<a href="'
307
-                       . $href
308
-                       . '" title="'
309
-                       . $title
310
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
311
-                       . $title
312
-                       . '</a>';
313
-        }
314
-        return $return;
315
-    }
316
-
317
-
318
-    /**
319
-     * Set the list table views for the default ticket list table view.
320
-     */
321
-    public function _set_list_table_views_ticket_list_table()
322
-    {
323
-        $this->_views = [
324
-            'all'     => [
325
-                'slug'        => 'all',
326
-                'label'       => esc_html__('All', 'event_espresso'),
327
-                'count'       => 0,
328
-                'bulk_action' => [
329
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
330
-                ],
331
-            ],
332
-            'trashed' => [
333
-                'slug'        => 'trashed',
334
-                'label'       => esc_html__('Trash', 'event_espresso'),
335
-                'count'       => 0,
336
-                'bulk_action' => [
337
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
338
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
339
-                ],
340
-            ],
341
-        ];
342
-    }
343
-
344
-
345
-    /**
346
-     * Enqueue scripts and styles for the event editor.
347
-     */
348
-    public function load_scripts_styles_edit()
349
-    {
350
-        if (! $this->admin_config->useAdvancedEditor()) {
351
-            wp_register_script(
352
-                'ee-event-editor-heartbeat',
353
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
354
-                ['ee_admin_js', 'heartbeat'],
355
-                EVENT_ESPRESSO_VERSION,
356
-                true
357
-            );
358
-            wp_enqueue_script('ee-accounting');
359
-            wp_enqueue_script('ee-event-editor-heartbeat');
360
-        }
361
-        wp_enqueue_script('event_editor_js');
362
-        // styles
363
-        wp_enqueue_style('espresso-ui-theme');
364
-    }
365
-
366
-
367
-    /**
368
-     * Returns template for the additional datetime.
369
-     *
370
-     * @param string $template
371
-     * @param array  $template_args
372
-     * @return string
373
-     * @throws DomainException
374
-     */
375
-    public function add_additional_datetime_button($template, $template_args)
376
-    {
377
-        return EEH_Template::display_template(
378
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
379
-            $template_args,
380
-            true
381
-        );
382
-    }
383
-
384
-
385
-    /**
386
-     * Returns the template for cloning a datetime.
387
-     *
388
-     * @param $template
389
-     * @param $template_args
390
-     * @return string
391
-     * @throws DomainException
392
-     */
393
-    public function add_datetime_clone_button($template, $template_args)
394
-    {
395
-        return EEH_Template::display_template(
396
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
397
-            $template_args,
398
-            true
399
-        );
400
-    }
401
-
402
-
403
-    /**
404
-     * Returns the template for datetime timezones.
405
-     *
406
-     * @param $template
407
-     * @param $template_args
408
-     * @return string
409
-     * @throws DomainException
410
-     */
411
-    public function datetime_timezones_template($template, $template_args)
412
-    {
413
-        return EEH_Template::display_template(
414
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
415
-            $template_args,
416
-            true
417
-        );
418
-    }
419
-
420
-
421
-    /**
422
-     * Sets the views for the default list table view.
423
-     *
424
-     * @throws EE_Error
425
-     */
426
-    protected function _set_list_table_views_default()
427
-    {
428
-        parent::_set_list_table_views_default();
429
-        $new_views    = [
430
-            'today' => [
431
-                'slug'        => 'today',
432
-                'label'       => esc_html__('Today', 'event_espresso'),
433
-                'count'       => $this->total_events_today(),
434
-                'bulk_action' => [
435
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
436
-                ],
437
-            ],
438
-            'month' => [
439
-                'slug'        => 'month',
440
-                'label'       => esc_html__('This Month', 'event_espresso'),
441
-                'count'       => $this->total_events_this_month(),
442
-                'bulk_action' => [
443
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
444
-                ],
445
-            ],
446
-        ];
447
-        $this->_views = array_merge($this->_views, $new_views);
448
-    }
449
-
450
-
451
-    /**
452
-     * Returns the extra action links for the default list table view.
453
-     *
454
-     * @param array    $action_links
455
-     * @param EE_Event $event
456
-     * @return array
457
-     * @throws EE_Error
458
-     * @throws ReflectionException
459
-     */
460
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
461
-    {
462
-        if (
463
-            EE_Registry::instance()->CAP->current_user_can(
464
-                'ee_read_registrations',
465
-                'espresso_registrations_reports',
466
-                $event->ID()
467
-            )
468
-        ) {
469
-            $reports_query_args = [
470
-                'action' => 'reports',
471
-                'EVT_ID' => $event->ID(),
472
-            ];
473
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
474
-            $action_links[]     = '<a href="'
475
-                                  . $reports_link
476
-                                  . '" title="'
477
-                                  . esc_attr__('View Report', 'event_espresso')
478
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
479
-                                  . "\n\t";
480
-        }
481
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
482
-            EE_Registry::instance()->load_helper('MSG_Template');
483
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
484
-                'see_notifications_for',
485
-                null,
486
-                ['EVT_ID' => $event->ID()]
487
-            );
488
-        }
489
-        return $action_links;
490
-    }
491
-
492
-
493
-    /**
494
-     * @param $items
495
-     * @return mixed
496
-     */
497
-    public function additional_legend_items($items)
498
-    {
499
-        if (
500
-            EE_Registry::instance()->CAP->current_user_can(
501
-                'ee_read_registrations',
502
-                'espresso_registrations_reports'
503
-            )
504
-        ) {
505
-            $items['reports'] = [
506
-                'class' => 'dashicons dashicons-chart-bar',
507
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
508
-            ];
509
-        }
510
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
511
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
512
-            // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
513
-            // (can only use numeric offsets when treating strings as arrays)
514
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
515
-                $items['view_related_messages'] = [
516
-                    'class' => $related_for_icon['css_class'],
517
-                    'desc'  => $related_for_icon['label'],
518
-                ];
519
-            }
520
-        }
521
-        return $items;
522
-    }
523
-
524
-
525
-    /**
526
-     * This is the callback method for the duplicate event route
527
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
528
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
529
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
530
-     * After duplication the redirect is to the new event edit page.
531
-     *
532
-     * @return void
533
-     * @throws EE_Error If EE_Event is not available with given ID
534
-     * @throws ReflectionException
535
-     * @access protected
536
-     */
537
-    protected function _duplicate_event()
538
-    {
539
-        // first make sure the ID for the event is in the request.
540
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
541
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
542
-        if (! $EVT_ID) {
543
-            EE_Error::add_error(
544
-                esc_html__(
545
-                    'In order to duplicate an event an Event ID is required.  None was given.',
546
-                    'event_espresso'
547
-                ),
548
-                __FILE__,
549
-                __FUNCTION__,
550
-                __LINE__
551
-            );
552
-            $this->_redirect_after_action(false, '', '', [], true);
553
-            return;
554
-        }
555
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
556
-        $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
557
-        if (! $orig_event instanceof EE_Event) {
558
-            throw new EE_Error(
559
-                sprintf(
560
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
561
-                    $EVT_ID
562
-                )
563
-            );
564
-        }
565
-        // k now let's clone the $orig_event before getting relations
566
-        $new_event = clone $orig_event;
567
-        // original datetimes
568
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
569
-        // other original relations
570
-        $orig_ven = $orig_event->get_many_related('Venue');
571
-        // reset the ID and modify other details to make it clear this is a dupe
572
-        $new_event->set('EVT_ID', 0);
573
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
574
-        $new_event->set('EVT_name', $new_name);
575
-        $new_event->set(
576
-            'EVT_slug',
577
-            wp_unique_post_slug(
578
-                sanitize_title($orig_event->name()),
579
-                0,
580
-                'publish',
581
-                'espresso_events',
582
-                0
583
-            )
584
-        );
585
-        $new_event->set('status', 'draft');
586
-        // duplicate discussion settings
587
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
588
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
589
-        // save the new event
590
-        $new_event->save();
591
-        // venues
592
-        foreach ($orig_ven as $ven) {
593
-            $new_event->_add_relation_to($ven, 'Venue');
594
-        }
595
-        $new_event->save();
596
-        // now we need to get the question group relations and handle that
597
-        // first primary question groups
598
-        $orig_primary_qgs = $orig_event->get_many_related(
599
-            'Question_Group',
600
-            [['Event_Question_Group.EQG_primary' => true]]
601
-        );
602
-        if (! empty($orig_primary_qgs)) {
603
-            foreach ($orig_primary_qgs as $obj) {
604
-                if ($obj instanceof EE_Question_Group) {
605
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
606
-                }
607
-            }
608
-        }
609
-        // next additional attendee question groups
610
-        $orig_additional_qgs = $orig_event->get_many_related(
611
-            'Question_Group',
612
-            [['Event_Question_Group.EQG_additional' => true]]
613
-        );
614
-        if (! empty($orig_additional_qgs)) {
615
-            foreach ($orig_additional_qgs as $obj) {
616
-                if ($obj instanceof EE_Question_Group) {
617
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
618
-                }
619
-            }
620
-        }
621
-
622
-        $new_event->save();
623
-
624
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
625
-        $cloned_tickets = [];
626
-        foreach ($orig_datetimes as $orig_dtt) {
627
-            if (! $orig_dtt instanceof EE_Datetime) {
628
-                continue;
629
-            }
630
-            $new_dtt      = clone $orig_dtt;
631
-            $orig_tickets = $orig_dtt->tickets();
632
-            // save new dtt then add to event
633
-            $new_dtt->set('DTT_ID', 0);
634
-            $new_dtt->set('DTT_sold', 0);
635
-            $new_dtt->set_reserved(0);
636
-            $new_dtt->save();
637
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
638
-            $new_event->save();
639
-            // now let's get the ticket relations setup.
640
-            foreach ((array) $orig_tickets as $orig_ticket) {
641
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
642
-                if (! $orig_ticket instanceof EE_Ticket) {
643
-                    continue;
644
-                }
645
-                // is this ticket archived?  If it is then let's skip
646
-                if ($orig_ticket->get('TKT_deleted')) {
647
-                    continue;
648
-                }
649
-                // does this original ticket already exist in the clone_tickets cache?
650
-                //  If so we'll just use the new ticket from it.
651
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
652
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
653
-                } else {
654
-                    $new_ticket = clone $orig_ticket;
655
-                    // get relations on the $orig_ticket that we need to setup.
656
-                    $orig_prices = $orig_ticket->prices();
657
-                    $new_ticket->set('TKT_ID', 0);
658
-                    $new_ticket->set('TKT_sold', 0);
659
-                    $new_ticket->set('TKT_reserved', 0);
660
-                    $new_ticket->save(); // make sure new ticket has ID.
661
-                    // price relations on new ticket need to be setup.
662
-                    foreach ($orig_prices as $orig_price) {
663
-                        $new_price = clone $orig_price;
664
-                        $new_price->set('PRC_ID', 0);
665
-                        $new_price->save();
666
-                        $new_ticket->_add_relation_to($new_price, 'Price');
667
-                        $new_ticket->save();
668
-                    }
669
-
670
-                    do_action(
671
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
672
-                        $orig_ticket,
673
-                        $new_ticket,
674
-                        $orig_prices,
675
-                        $orig_event,
676
-                        $orig_dtt,
677
-                        $new_dtt
678
-                    );
679
-                }
680
-                // k now we can add the new ticket as a relation to the new datetime
681
-                // and make sure its added to our cached $cloned_tickets array
682
-                // for use with later datetimes that have the same ticket.
683
-                $new_dtt->_add_relation_to($new_ticket, 'Ticket');
684
-                $new_dtt->save();
685
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
686
-            }
687
-        }
688
-        // clone taxonomy information
689
-        $taxonomies_to_clone_with = apply_filters(
690
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
691
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
692
-        );
693
-        // get terms for original event (notice)
694
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
695
-        // loop through terms and add them to new event.
696
-        foreach ($orig_terms as $term) {
697
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
698
-        }
699
-
700
-        // duplicate other core WP_Post items for this event.
701
-        // post thumbnail (feature image).
702
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
703
-        if ($feature_image_id) {
704
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
705
-        }
706
-
707
-        // duplicate page_template setting
708
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
709
-        if ($page_template) {
710
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
711
-        }
712
-
713
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
714
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
715
-        if ($new_event->ID()) {
716
-            $redirect_args = [
717
-                'post'   => $new_event->ID(),
718
-                'action' => 'edit',
719
-            ];
720
-            EE_Error::add_success(
721
-                esc_html__(
722
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
723
-                    'event_espresso'
724
-                )
725
-            );
726
-        } else {
727
-            $redirect_args = [
728
-                'action' => 'default',
729
-            ];
730
-            EE_Error::add_error(
731
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
732
-                __FILE__,
733
-                __FUNCTION__,
734
-                __LINE__
735
-            );
736
-        }
737
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
738
-    }
739
-
740
-
741
-    /**
742
-     * Generates output for the import page.
743
-     *
744
-     * @throws EE_Error
745
-     */
746
-    protected function _import_page()
747
-    {
748
-        $title                                      = esc_html__('Import', 'event_espresso');
749
-        $intro                                      = esc_html__(
750
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
751
-            'event_espresso'
752
-        );
753
-
754
-        $form_url = EVENTS_ADMIN_URL;
755
-        $action   = 'import_events';
756
-        $type     = 'csv';
757
-
758
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
759
-            $title,
760
-            $intro,
761
-            $form_url,
762
-            $action,
763
-            $type
764
-        );
765
-
766
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
767
-            ['action' => 'sample_export_file'],
768
-            $this->_admin_base_url
769
-        );
770
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
771
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
772
-            $this->_template_args,
773
-            true
774
-        );
775
-        $this->display_admin_page_with_sidebar();
776
-    }
777
-
778
-
779
-    /**
780
-     * _import_events
781
-     * This handles displaying the screen and running imports for importing events.
782
-     *
783
-     * @return void
784
-     * @throws EE_Error
785
-     */
786
-    protected function _import_events()
787
-    {
788
-        require_once(EE_CLASSES . 'EE_Import.class.php');
789
-        $success = EE_Import::instance()->import();
790
-        $this->_redirect_after_action(
791
-            $success,
792
-            esc_html__('Import File', 'event_espresso'),
793
-            'ran',
794
-            ['action' => 'import_page'],
795
-            true
796
-        );
797
-    }
798
-
799
-
800
-    /**
801
-     * _events_export
802
-     * Will export all (or just the given event) to a Excel compatible file.
803
-     *
804
-     * @access protected
805
-     * @return void
806
-     */
807
-    protected function _events_export()
808
-    {
809
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
810
-        $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
811
-        $this->request->mergeRequestParams(
812
-            [
813
-                'export' => 'report',
814
-                'action' => 'all_event_data',
815
-                'EVT_ID' => $EVT_ID,
816
-            ]
817
-        );
818
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
819
-            require_once(EE_CLASSES . 'EE_Export.class.php');
820
-            $EE_Export = EE_Export::instance($this->request->requestParams());
821
-            $EE_Export->export();
822
-        }
823
-    }
824
-
825
-
826
-    /**
827
-     * handle category exports()
828
-     *
829
-     * @return void
830
-     */
831
-    protected function _categories_export()
832
-    {
833
-        $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
834
-        $this->request->mergeRequestParams(
835
-            [
836
-                'export' => 'report',
837
-                'action' => 'categories',
838
-                'EVT_ID' => $EVT_ID,
839
-            ]
840
-        );
841
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
842
-            require_once(EE_CLASSES . 'EE_Export.class.php');
843
-            $EE_Export = EE_Export::instance($this->request->requestParams());
844
-            $EE_Export->export();
845
-        }
846
-    }
847
-
848
-
849
-    /**
850
-     * Creates a sample CSV file for importing
851
-     */
852
-    protected function _sample_export_file()
853
-    {
854
-        $EE_Export = EE_Export::instance();
855
-        if ($EE_Export instanceof EE_Export) {
856
-            $EE_Export->export();
857
-        }
858
-    }
859
-
860
-
861
-    /*************        Template Settings        *************/
862
-    /**
863
-     * Generates template settings page output
864
-     *
865
-     * @throws DomainException
866
-     * @throws EE_Error
867
-     * @throws InvalidArgumentException
868
-     * @throws InvalidDataTypeException
869
-     * @throws InvalidInterfaceException
870
-     */
871
-    protected function _template_settings()
872
-    {
873
-        $this->_template_args['values'] = $this->_yes_no_values;
874
-        /**
875
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
876
-         * from General_Settings_Admin_Page to here.
877
-         */
878
-        $this->_template_args = apply_filters(
879
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
880
-            $this->_template_args
881
-        );
882
-        $this->_set_add_edit_form_tags('update_template_settings');
883
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
884
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
885
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
886
-            $this->_template_args,
887
-            true
888
-        );
889
-        $this->display_admin_page_with_sidebar();
890
-    }
891
-
892
-
893
-    /**
894
-     * Handler for updating template settings.
895
-     *
896
-     * @throws EE_Error
897
-     */
898
-    protected function _update_template_settings()
899
-    {
900
-        /**
901
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
902
-         * from General_Settings_Admin_Page to here.
903
-         */
904
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
905
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
906
-            EE_Registry::instance()->CFG->template_settings,
907
-            $this->request->requestParams()
908
-        );
909
-        // update custom post type slugs and detect if we need to flush rewrite rules
910
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
911
-
912
-        $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
913
-
914
-        EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
915
-            ? EEH_URL::slugify($event_cpt_slug, 'events')
916
-            : EE_Registry::instance()->CFG->core->event_cpt_slug;
917
-
918
-        $what    = esc_html__('Template Settings', 'event_espresso');
919
-        $success = $this->_update_espresso_configuration(
920
-            $what,
921
-            EE_Registry::instance()->CFG->template_settings,
922
-            __FILE__,
923
-            __FUNCTION__,
924
-            __LINE__
925
-        );
926
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
927
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
928
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
929
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
930
-            );
931
-            $rewrite_rules->flush();
932
-        }
933
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
934
-    }
935
-
936
-
937
-    /**
938
-     * _premium_event_editor_meta_boxes
939
-     * add all metaboxes related to the event_editor
940
-     *
941
-     * @access protected
942
-     * @return void
943
-     * @throws EE_Error
944
-     * @throws ReflectionException
945
-     */
946
-    protected function _premium_event_editor_meta_boxes()
947
-    {
948
-        $this->verify_cpt_object();
949
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
950
-        if (
951
-            ! $this->admin_config->useAdvancedEditor()
952
-            || ! $this->feature->allowed('use_reg_options_meta_box')
953
-        ) {
954
-            add_meta_box(
955
-                'espresso_event_editor_event_options',
956
-                esc_html__('Event Registration Options', 'event_espresso'),
957
-                [$this, 'registration_options_meta_box'],
958
-                $this->page_slug,
959
-                'side',
960
-                'core'
961
-            );
962
-        }
963
-    }
964
-
965
-
966
-    /**
967
-     * override caf metabox
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    public function registration_options_meta_box()
974
-    {
975
-        $yes_no_values = [
976
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
977
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
978
-        ];
979
-
980
-        $default_reg_status_values = EEM_Registration::reg_status_array(
981
-            [
982
-                EEM_Registration::status_id_cancelled,
983
-                EEM_Registration::status_id_declined,
984
-                EEM_Registration::status_id_incomplete,
985
-                EEM_Registration::status_id_wait_list,
986
-            ],
987
-            true
988
-        );
989
-
990
-        $template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
991
-        $template_args['_event']           = $this->_cpt_model_obj;
992
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
993
-
994
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
995
-            'default_reg_status',
996
-            $default_reg_status_values,
997
-            $this->_cpt_model_obj->default_registration_status()
998
-        );
999
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1000
-            'display_desc',
1001
-            $yes_no_values,
1002
-            $this->_cpt_model_obj->display_description()
1003
-        );
1004
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1005
-            'display_ticket_selector',
1006
-            $yes_no_values,
1007
-            $this->_cpt_model_obj->display_ticket_selector(),
1008
-            '',
1009
-            '',
1010
-            false
1011
-        );
1012
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1013
-            'EVT_default_registration_status',
1014
-            $default_reg_status_values,
1015
-            $this->_cpt_model_obj->default_registration_status()
1016
-        );
1017
-        $template_args['additional_registration_options'] = apply_filters(
1018
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1019
-            '',
1020
-            $template_args,
1021
-            $yes_no_values,
1022
-            $default_reg_status_values
1023
-        );
1024
-        EEH_Template::display_template(
1025
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1026
-            $template_args
1027
-        );
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     * wp_list_table_mods for caf
1034
-     * ============================
1035
-     */
1036
-    /**
1037
-     * hook into list table filters and provide filters for caffeinated list table
1038
-     *
1039
-     * @param array $old_filters    any existing filters present
1040
-     * @param array $list_table_obj the list table object
1041
-     * @return array                  new filters
1042
-     * @throws EE_Error
1043
-     * @throws ReflectionException
1044
-     */
1045
-    public function list_table_filters($old_filters, $list_table_obj)
1046
-    {
1047
-        $filters = [];
1048
-        // first month/year filters
1049
-        $filters[] = $this->espresso_event_months_dropdown();
1050
-        $status    = $this->request->getRequestParam('status');
1051
-        // active status dropdown
1052
-        if ($status !== 'draft') {
1053
-            $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1054
-            $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1055
-        }
1056
-        // category filter
1057
-        $filters[] = $this->category_dropdown();
1058
-        return array_merge($old_filters, $filters);
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * espresso_event_months_dropdown
1064
-     *
1065
-     * @access public
1066
-     * @return string                dropdown listing month/year selections for events.
1067
-     * @throws EE_Error
1068
-     */
1069
-    public function espresso_event_months_dropdown()
1070
-    {
1071
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1072
-        // Note we need to include any other filters that are set!
1073
-        return EEH_Form_Fields::generate_event_months_dropdown(
1074
-            $this->request->getRequestParam('month_range'),
1075
-            $this->request->getRequestParam('status'),
1076
-            $this->request->getRequestParam('EVT_CAT', 0, 'int'),
1077
-            $this->request->getRequestParam('active_status')
1078
-        );
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * returns a list of "active" statuses on the event
1084
-     *
1085
-     * @param string $current_value whatever the current active status is
1086
-     * @return string
1087
-     */
1088
-    public function active_status_dropdown($current_value = '')
1089
-    {
1090
-        $select_name = 'active_status';
1091
-        $values      = [
1092
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1093
-            'active'   => esc_html__('Active', 'event_espresso'),
1094
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1095
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1096
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1097
-        ];
1098
-
1099
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * returns a list of "venues"
1105
-     *
1106
-     * @param string $current_value whatever the current active status is
1107
-     * @return string
1108
-     * @throws EE_Error
1109
-     * @throws ReflectionException
1110
-     */
1111
-    protected function venuesDropdown($current_value = '')
1112
-    {
1113
-        $values = ['' => esc_html__('All Venues', 'event_espresso')];
1114
-        // populate the list of venues.
1115
-        $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1116
-
1117
-        foreach ($venues as $venue) {
1118
-            $values[ $venue->ID() ] = $venue->name();
1119
-        }
1120
-
1121
-        return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1122
-    }
1123
-
1124
-
1125
-    /**
1126
-     * output a dropdown of the categories for the category filter on the event admin list table
1127
-     *
1128
-     * @access  public
1129
-     * @return string html
1130
-     * @throws EE_Error
1131
-     * @throws ReflectionException
1132
-     */
1133
-    public function category_dropdown()
1134
-    {
1135
-        return EEH_Form_Fields::generate_event_category_dropdown(
1136
-            $this->request->getRequestParam('EVT_CAT', -1, 'int')
1137
-        );
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * get total number of events today
1143
-     *
1144
-     * @access public
1145
-     * @return int
1146
-     * @throws EE_Error
1147
-     * @throws InvalidArgumentException
1148
-     * @throws InvalidDataTypeException
1149
-     * @throws InvalidInterfaceException
1150
-     */
1151
-    public function total_events_today()
1152
-    {
1153
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1154
-            'DTT_EVT_start',
1155
-            date('Y-m-d') . ' 00:00:00',
1156
-            'Y-m-d H:i:s',
1157
-            'UTC'
1158
-        );
1159
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1160
-            'DTT_EVT_start',
1161
-            date('Y-m-d') . ' 23:59:59',
1162
-            'Y-m-d H:i:s',
1163
-            'UTC'
1164
-        );
1165
-        $where = [
1166
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1167
-        ];
1168
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1169
-    }
1170
-
1171
-
1172
-    /**
1173
-     * get total number of events this month
1174
-     *
1175
-     * @access public
1176
-     * @return int
1177
-     * @throws EE_Error
1178
-     * @throws InvalidArgumentException
1179
-     * @throws InvalidDataTypeException
1180
-     * @throws InvalidInterfaceException
1181
-     */
1182
-    public function total_events_this_month()
1183
-    {
1184
-        // Dates
1185
-        $this_year_r     = date('Y');
1186
-        $this_month_r    = date('m');
1187
-        $days_this_month = date('t');
1188
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1189
-            'DTT_EVT_start',
1190
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1191
-            'Y-m-d H:i:s',
1192
-            'UTC'
1193
-        );
1194
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1195
-            'DTT_EVT_start',
1196
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1197
-            'Y-m-d H:i:s',
1198
-            'UTC'
1199
-        );
1200
-        $where           = [
1201
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1202
-        ];
1203
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1204
-    }
1205
-
1206
-
1207
-    /** DEFAULT TICKETS STUFF **/
1208
-
1209
-    /**
1210
-     * Output default tickets list table view.
1211
-     *
1212
-     * @throws EE_Error
1213
-     */
1214
-    public function _tickets_overview_list_table()
1215
-    {
1216
-        if (
1217
-            $this->admin_config->useAdvancedEditor()
1218
-            && $this->feature->allowed('use_default_ticket_manager')
1219
-        ) {
1220
-            // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1221
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1222
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1223
-                [],
1224
-                true
1225
-            );
1226
-            $this->display_admin_page_with_no_sidebar();
1227
-        } else {
1228
-            $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1229
-            $this->display_admin_list_table_page_with_no_sidebar();
1230
-        }
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * @param int  $per_page
1236
-     * @param bool $count
1237
-     * @param bool $trashed
1238
-     * @return EE_Soft_Delete_Base_Class[]|int
1239
-     * @throws EE_Error
1240
-     */
1241
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1242
-    {
1243
-        $orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1244
-        $order   = $this->request->getRequestParam('order', 'ASC');
1245
-        switch ($orderby) {
1246
-            case 'TKT_name':
1247
-                $orderby = ['TKT_name' => $order];
1248
-                break;
1249
-            case 'TKT_price':
1250
-                $orderby = ['TKT_price' => $order];
1251
-                break;
1252
-            case 'TKT_uses':
1253
-                $orderby = ['TKT_uses' => $order];
1254
-                break;
1255
-            case 'TKT_min':
1256
-                $orderby = ['TKT_min' => $order];
1257
-                break;
1258
-            case 'TKT_max':
1259
-                $orderby = ['TKT_max' => $order];
1260
-                break;
1261
-            case 'TKT_qty':
1262
-                $orderby = ['TKT_qty' => $order];
1263
-                break;
1264
-        }
1265
-
1266
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1267
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1268
-        $offset       = ($current_page - 1) * $per_page;
1269
-
1270
-        $where = [
1271
-            'TKT_is_default' => 1,
1272
-            'TKT_deleted'    => $trashed,
1273
-        ];
1274
-
1275
-        $search_term = $this->request->getRequestParam('s');
1276
-        if ($search_term) {
1277
-            $search_term = '%' . $search_term . '%';
1278
-            $where['OR'] = [
1279
-                'TKT_name'        => ['LIKE', $search_term],
1280
-                'TKT_description' => ['LIKE', $search_term],
1281
-            ];
1282
-        }
1283
-
1284
-        return $count
1285
-            ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1286
-            : EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1287
-                [
1288
-                    $where,
1289
-                    'order_by' => $orderby,
1290
-                    'limit'    => [$offset, $per_page],
1291
-                    'group_by' => 'TKT_ID',
1292
-                ]
1293
-            );
1294
-    }
1295
-
1296
-
1297
-    /**
1298
-     * @param bool $trash
1299
-     * @throws EE_Error
1300
-     * @throws InvalidArgumentException
1301
-     * @throws InvalidDataTypeException
1302
-     * @throws InvalidInterfaceException
1303
-     */
1304
-    protected function _trash_or_restore_ticket($trash = false)
1305
-    {
1306
-        $success = 1;
1307
-        $TKT     = EEM_Ticket::instance();
1308
-        // checkboxes?
1309
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1310
-        if (! empty($checkboxes)) {
1311
-            // if array has more than one element then success message should be plural
1312
-            $success = count($checkboxes) > 1 ? 2 : 1;
1313
-            // cycle thru the boxes
1314
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1315
-                if ($trash) {
1316
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1317
-                        $success = 0;
1318
-                    }
1319
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1320
-                    $success = 0;
1321
-                }
1322
-            }
1323
-        } else {
1324
-            // grab single id and trash
1325
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1326
-            if ($trash) {
1327
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1328
-                    $success = 0;
1329
-                }
1330
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1331
-                $success = 0;
1332
-            }
1333
-        }
1334
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1335
-        $query_args  = [
1336
-            'action' => 'ticket_list_table',
1337
-            'status' => $trash ? '' : 'trashed',
1338
-        ];
1339
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1340
-    }
1341
-
1342
-
1343
-    /**
1344
-     * Handles trashing default ticket.
1345
-     *
1346
-     * @throws EE_Error
1347
-     * @throws ReflectionException
1348
-     */
1349
-    protected function _delete_ticket()
1350
-    {
1351
-        $success = 1;
1352
-        // checkboxes?
1353
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1354
-        if (! empty($checkboxes)) {
1355
-            // if array has more than one element then success message should be plural
1356
-            $success = count($checkboxes) > 1 ? 2 : 1;
1357
-            // cycle thru the boxes
1358
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1359
-                // delete
1360
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1361
-                    $success = 0;
1362
-                }
1363
-            }
1364
-        } else {
1365
-            // grab single id and trash
1366
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1367
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1368
-                $success = 0;
1369
-            }
1370
-        }
1371
-        $action_desc = 'deleted';
1372
-        $query_args  = [
1373
-            'action' => 'ticket_list_table',
1374
-            'status' => 'trashed',
1375
-        ];
1376
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1377
-        if (
1378
-            EEM_Ticket::instance()->count_deleted_and_undeleted(
1379
-                [['TKT_is_default' => 1]],
1380
-                'TKT_ID',
1381
-                true
1382
-            )
1383
-        ) {
1384
-            $query_args = [];
1385
-        }
1386
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * @param int $TKT_ID
1392
-     * @return bool|int
1393
-     * @throws EE_Error
1394
-     * @throws ReflectionException
1395
-     */
1396
-    protected function _delete_the_ticket($TKT_ID)
1397
-    {
1398
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1399
-        if (! $ticket instanceof EE_Ticket) {
1400
-            return false;
1401
-        }
1402
-        $ticket->_remove_relations('Datetime');
1403
-        // delete all related prices first
1404
-        $ticket->delete_related_permanently('Price');
1405
-        return $ticket->delete_permanently();
1406
-    }
19
+	/**
20
+	 * @var EE_Admin_Config
21
+	 */
22
+	protected $admin_config;
23
+
24
+	/**
25
+	 * @var AdvancedEditorAdminFormSection
26
+	 */
27
+	protected $advanced_editor_admin_form;
28
+
29
+
30
+	/**
31
+	 * Extend_Events_Admin_Page constructor.
32
+	 *
33
+	 * @param bool $routing
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
+		}
44
+		parent::__construct($routing);
45
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Sets routes.
51
+	 *
52
+	 * @throws EE_Error
53
+	 */
54
+	protected function _extend_page_config()
55
+	{
56
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
+		// is there a evt_id in the request?
58
+		$EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
+		$EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
+		$TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
+		$new_page_routes    = [
62
+			'duplicate_event'          => [
63
+				'func'       => '_duplicate_event',
64
+				'capability' => 'ee_edit_event',
65
+				'obj_id'     => $EVT_ID,
66
+				'noheader'   => true,
67
+			],
68
+			'import_page'              => [
69
+				'func'       => '_import_page',
70
+				'capability' => 'import',
71
+			],
72
+			'import'                   => [
73
+				'func'       => '_import_events',
74
+				'capability' => 'import',
75
+				'noheader'   => true,
76
+			],
77
+			'import_events'            => [
78
+				'func'       => '_import_events',
79
+				'capability' => 'import',
80
+				'noheader'   => true,
81
+			],
82
+			'export_events'            => [
83
+				'func'       => '_events_export',
84
+				'capability' => 'export',
85
+				'noheader'   => true,
86
+			],
87
+			'export_categories'        => [
88
+				'func'       => '_categories_export',
89
+				'capability' => 'export',
90
+				'noheader'   => true,
91
+			],
92
+			'sample_export_file'       => [
93
+				'func'       => '_sample_export_file',
94
+				'capability' => 'export',
95
+				'noheader'   => true,
96
+			],
97
+			'update_template_settings' => [
98
+				'func'       => '_update_template_settings',
99
+				'capability' => 'manage_options',
100
+				'noheader'   => true,
101
+			],
102
+			'ticket_list_table'        => [
103
+				'func'       => '_tickets_overview_list_table',
104
+				'capability' => 'ee_read_default_tickets',
105
+			],
106
+		];
107
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
+		$this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
+		// don't load these meta boxes if using the advanced editor
110
+		if (
111
+			! $this->admin_config->useAdvancedEditor()
112
+			|| ! $this->feature->allowed('use_default_ticket_manager')
113
+		) {
114
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
+			$this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
+
117
+			$legacy_editor_page_routes = [
118
+				'trash_ticket'    => [
119
+					'func'       => '_trash_or_restore_ticket',
120
+					'capability' => 'ee_delete_default_ticket',
121
+					'obj_id'     => $TKT_ID,
122
+					'noheader'   => true,
123
+					'args'       => ['trash' => true],
124
+				],
125
+				'trash_tickets'   => [
126
+					'func'       => '_trash_or_restore_ticket',
127
+					'capability' => 'ee_delete_default_tickets',
128
+					'noheader'   => true,
129
+					'args'       => ['trash' => true],
130
+				],
131
+				'restore_ticket'  => [
132
+					'func'       => '_trash_or_restore_ticket',
133
+					'capability' => 'ee_delete_default_ticket',
134
+					'obj_id'     => $TKT_ID,
135
+					'noheader'   => true,
136
+				],
137
+				'restore_tickets' => [
138
+					'func'       => '_trash_or_restore_ticket',
139
+					'capability' => 'ee_delete_default_tickets',
140
+					'noheader'   => true,
141
+				],
142
+				'delete_ticket'   => [
143
+					'func'       => '_delete_ticket',
144
+					'capability' => 'ee_delete_default_ticket',
145
+					'obj_id'     => $TKT_ID,
146
+					'noheader'   => true,
147
+				],
148
+				'delete_tickets'  => [
149
+					'func'       => '_delete_ticket',
150
+					'capability' => 'ee_delete_default_tickets',
151
+					'noheader'   => true,
152
+				],
153
+			];
154
+			$new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
+		}
156
+
157
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
+		// partial route/config override
159
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
+		// add tickets tab but only if there are more than one default ticket!
162
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
+			[['TKT_is_default' => 1]],
164
+			'TKT_ID',
165
+			true
166
+		);
167
+		if ($ticket_count > 1) {
168
+			$new_page_config = [
169
+				'ticket_list_table' => [
170
+					'nav'           => [
171
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
172
+						'order' => 60,
173
+					],
174
+					'list_table'    => 'Tickets_List_Table',
175
+					'require_nonce' => false,
176
+				],
177
+			];
178
+		}
179
+		// template settings
180
+		$new_page_config['template_settings'] = [
181
+			'nav'           => [
182
+				'label' => esc_html__('Templates', 'event_espresso'),
183
+				'order' => 30,
184
+			],
185
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
+			'help_tabs'     => [
187
+				'general_settings_templates_help_tab' => [
188
+					'title'    => esc_html__('Templates', 'event_espresso'),
189
+					'filename' => 'general_settings_templates',
190
+				],
191
+			],
192
+			'require_nonce' => false,
193
+		];
194
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
195
+		// add filters and actions
196
+		// modifying _views
197
+		add_filter(
198
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
199
+			[$this, 'add_additional_datetime_button'],
200
+			10,
201
+			2
202
+		);
203
+		add_filter(
204
+			'FHEE_event_datetime_metabox_clone_button_template',
205
+			[$this, 'add_datetime_clone_button'],
206
+			10,
207
+			2
208
+		);
209
+		add_filter(
210
+			'FHEE_event_datetime_metabox_timezones_template',
211
+			[$this, 'datetime_timezones_template'],
212
+			10,
213
+			2
214
+		);
215
+		// filters for event list table
216
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
217
+		add_filter(
218
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
219
+			[$this, 'extra_list_table_actions'],
220
+			10,
221
+			2
222
+		);
223
+		// legend item
224
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
225
+		add_action('admin_init', [$this, 'admin_init']);
226
+		// load additional handlers
227
+		$this->handleActionRequest();
228
+	}
229
+
230
+
231
+	private function getRequestAction()
232
+	{
233
+		return $this->request->getRequestParam('action');
234
+	}
235
+
236
+
237
+	/**
238
+	 * @throws Exception
239
+	 */
240
+	private function handleActionRequest()
241
+	{
242
+		$action = $this->getRequestAction();
243
+		if ($action) {
244
+			// setup Advanced Editor ???
245
+			if ($action === 'default_event_settings' || $action === 'update_default_event_settings') {
246
+				$this->advanced_editor_admin_form = $this->loader->getShared(
247
+					'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection'
248
+				);
249
+			}
250
+		}
251
+	}
252
+
253
+
254
+	/**
255
+	 * admin_init
256
+	 */
257
+	public function admin_init()
258
+	{
259
+		EE_Registry::$i18n_js_strings = array_merge(
260
+			EE_Registry::$i18n_js_strings,
261
+			[
262
+				'image_confirm'          => esc_html__(
263
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
264
+					'event_espresso'
265
+				),
266
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
267
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
268
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
269
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
270
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
271
+			]
272
+		);
273
+	}
274
+
275
+
276
+	/**
277
+	 * Add per page screen options to the default ticket list table view.
278
+	 *
279
+	 * @throws InvalidArgumentException
280
+	 * @throws InvalidDataTypeException
281
+	 * @throws InvalidInterfaceException
282
+	 */
283
+	protected function _add_screen_options_ticket_list_table()
284
+	{
285
+		$this->_per_page_screen_option();
286
+	}
287
+
288
+
289
+	/**
290
+	 * @param string $return
291
+	 * @param int    $id
292
+	 * @param string $new_title
293
+	 * @param string $new_slug
294
+	 * @return string
295
+	 */
296
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
297
+	{
298
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
299
+		// make sure this is only when editing
300
+		if (! empty($id)) {
301
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
302
+				['action' => 'duplicate_event', 'EVT_ID' => $id],
303
+				$this->_admin_base_url
304
+			);
305
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
306
+			$return .= '<a href="'
307
+					   . $href
308
+					   . '" title="'
309
+					   . $title
310
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
311
+					   . $title
312
+					   . '</a>';
313
+		}
314
+		return $return;
315
+	}
316
+
317
+
318
+	/**
319
+	 * Set the list table views for the default ticket list table view.
320
+	 */
321
+	public function _set_list_table_views_ticket_list_table()
322
+	{
323
+		$this->_views = [
324
+			'all'     => [
325
+				'slug'        => 'all',
326
+				'label'       => esc_html__('All', 'event_espresso'),
327
+				'count'       => 0,
328
+				'bulk_action' => [
329
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
330
+				],
331
+			],
332
+			'trashed' => [
333
+				'slug'        => 'trashed',
334
+				'label'       => esc_html__('Trash', 'event_espresso'),
335
+				'count'       => 0,
336
+				'bulk_action' => [
337
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
338
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
339
+				],
340
+			],
341
+		];
342
+	}
343
+
344
+
345
+	/**
346
+	 * Enqueue scripts and styles for the event editor.
347
+	 */
348
+	public function load_scripts_styles_edit()
349
+	{
350
+		if (! $this->admin_config->useAdvancedEditor()) {
351
+			wp_register_script(
352
+				'ee-event-editor-heartbeat',
353
+				EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
354
+				['ee_admin_js', 'heartbeat'],
355
+				EVENT_ESPRESSO_VERSION,
356
+				true
357
+			);
358
+			wp_enqueue_script('ee-accounting');
359
+			wp_enqueue_script('ee-event-editor-heartbeat');
360
+		}
361
+		wp_enqueue_script('event_editor_js');
362
+		// styles
363
+		wp_enqueue_style('espresso-ui-theme');
364
+	}
365
+
366
+
367
+	/**
368
+	 * Returns template for the additional datetime.
369
+	 *
370
+	 * @param string $template
371
+	 * @param array  $template_args
372
+	 * @return string
373
+	 * @throws DomainException
374
+	 */
375
+	public function add_additional_datetime_button($template, $template_args)
376
+	{
377
+		return EEH_Template::display_template(
378
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
379
+			$template_args,
380
+			true
381
+		);
382
+	}
383
+
384
+
385
+	/**
386
+	 * Returns the template for cloning a datetime.
387
+	 *
388
+	 * @param $template
389
+	 * @param $template_args
390
+	 * @return string
391
+	 * @throws DomainException
392
+	 */
393
+	public function add_datetime_clone_button($template, $template_args)
394
+	{
395
+		return EEH_Template::display_template(
396
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
397
+			$template_args,
398
+			true
399
+		);
400
+	}
401
+
402
+
403
+	/**
404
+	 * Returns the template for datetime timezones.
405
+	 *
406
+	 * @param $template
407
+	 * @param $template_args
408
+	 * @return string
409
+	 * @throws DomainException
410
+	 */
411
+	public function datetime_timezones_template($template, $template_args)
412
+	{
413
+		return EEH_Template::display_template(
414
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
415
+			$template_args,
416
+			true
417
+		);
418
+	}
419
+
420
+
421
+	/**
422
+	 * Sets the views for the default list table view.
423
+	 *
424
+	 * @throws EE_Error
425
+	 */
426
+	protected function _set_list_table_views_default()
427
+	{
428
+		parent::_set_list_table_views_default();
429
+		$new_views    = [
430
+			'today' => [
431
+				'slug'        => 'today',
432
+				'label'       => esc_html__('Today', 'event_espresso'),
433
+				'count'       => $this->total_events_today(),
434
+				'bulk_action' => [
435
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
436
+				],
437
+			],
438
+			'month' => [
439
+				'slug'        => 'month',
440
+				'label'       => esc_html__('This Month', 'event_espresso'),
441
+				'count'       => $this->total_events_this_month(),
442
+				'bulk_action' => [
443
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
444
+				],
445
+			],
446
+		];
447
+		$this->_views = array_merge($this->_views, $new_views);
448
+	}
449
+
450
+
451
+	/**
452
+	 * Returns the extra action links for the default list table view.
453
+	 *
454
+	 * @param array    $action_links
455
+	 * @param EE_Event $event
456
+	 * @return array
457
+	 * @throws EE_Error
458
+	 * @throws ReflectionException
459
+	 */
460
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
461
+	{
462
+		if (
463
+			EE_Registry::instance()->CAP->current_user_can(
464
+				'ee_read_registrations',
465
+				'espresso_registrations_reports',
466
+				$event->ID()
467
+			)
468
+		) {
469
+			$reports_query_args = [
470
+				'action' => 'reports',
471
+				'EVT_ID' => $event->ID(),
472
+			];
473
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
474
+			$action_links[]     = '<a href="'
475
+								  . $reports_link
476
+								  . '" title="'
477
+								  . esc_attr__('View Report', 'event_espresso')
478
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
479
+								  . "\n\t";
480
+		}
481
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
482
+			EE_Registry::instance()->load_helper('MSG_Template');
483
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
484
+				'see_notifications_for',
485
+				null,
486
+				['EVT_ID' => $event->ID()]
487
+			);
488
+		}
489
+		return $action_links;
490
+	}
491
+
492
+
493
+	/**
494
+	 * @param $items
495
+	 * @return mixed
496
+	 */
497
+	public function additional_legend_items($items)
498
+	{
499
+		if (
500
+			EE_Registry::instance()->CAP->current_user_can(
501
+				'ee_read_registrations',
502
+				'espresso_registrations_reports'
503
+			)
504
+		) {
505
+			$items['reports'] = [
506
+				'class' => 'dashicons dashicons-chart-bar',
507
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
508
+			];
509
+		}
510
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
511
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
512
+			// $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset
513
+			// (can only use numeric offsets when treating strings as arrays)
514
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
515
+				$items['view_related_messages'] = [
516
+					'class' => $related_for_icon['css_class'],
517
+					'desc'  => $related_for_icon['label'],
518
+				];
519
+			}
520
+		}
521
+		return $items;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This is the callback method for the duplicate event route
527
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
528
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
529
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
530
+	 * After duplication the redirect is to the new event edit page.
531
+	 *
532
+	 * @return void
533
+	 * @throws EE_Error If EE_Event is not available with given ID
534
+	 * @throws ReflectionException
535
+	 * @access protected
536
+	 */
537
+	protected function _duplicate_event()
538
+	{
539
+		// first make sure the ID for the event is in the request.
540
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
541
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
542
+		if (! $EVT_ID) {
543
+			EE_Error::add_error(
544
+				esc_html__(
545
+					'In order to duplicate an event an Event ID is required.  None was given.',
546
+					'event_espresso'
547
+				),
548
+				__FILE__,
549
+				__FUNCTION__,
550
+				__LINE__
551
+			);
552
+			$this->_redirect_after_action(false, '', '', [], true);
553
+			return;
554
+		}
555
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
556
+		$orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
557
+		if (! $orig_event instanceof EE_Event) {
558
+			throw new EE_Error(
559
+				sprintf(
560
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
561
+					$EVT_ID
562
+				)
563
+			);
564
+		}
565
+		// k now let's clone the $orig_event before getting relations
566
+		$new_event = clone $orig_event;
567
+		// original datetimes
568
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
569
+		// other original relations
570
+		$orig_ven = $orig_event->get_many_related('Venue');
571
+		// reset the ID and modify other details to make it clear this is a dupe
572
+		$new_event->set('EVT_ID', 0);
573
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
574
+		$new_event->set('EVT_name', $new_name);
575
+		$new_event->set(
576
+			'EVT_slug',
577
+			wp_unique_post_slug(
578
+				sanitize_title($orig_event->name()),
579
+				0,
580
+				'publish',
581
+				'espresso_events',
582
+				0
583
+			)
584
+		);
585
+		$new_event->set('status', 'draft');
586
+		// duplicate discussion settings
587
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
588
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
589
+		// save the new event
590
+		$new_event->save();
591
+		// venues
592
+		foreach ($orig_ven as $ven) {
593
+			$new_event->_add_relation_to($ven, 'Venue');
594
+		}
595
+		$new_event->save();
596
+		// now we need to get the question group relations and handle that
597
+		// first primary question groups
598
+		$orig_primary_qgs = $orig_event->get_many_related(
599
+			'Question_Group',
600
+			[['Event_Question_Group.EQG_primary' => true]]
601
+		);
602
+		if (! empty($orig_primary_qgs)) {
603
+			foreach ($orig_primary_qgs as $obj) {
604
+				if ($obj instanceof EE_Question_Group) {
605
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
606
+				}
607
+			}
608
+		}
609
+		// next additional attendee question groups
610
+		$orig_additional_qgs = $orig_event->get_many_related(
611
+			'Question_Group',
612
+			[['Event_Question_Group.EQG_additional' => true]]
613
+		);
614
+		if (! empty($orig_additional_qgs)) {
615
+			foreach ($orig_additional_qgs as $obj) {
616
+				if ($obj instanceof EE_Question_Group) {
617
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
618
+				}
619
+			}
620
+		}
621
+
622
+		$new_event->save();
623
+
624
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
625
+		$cloned_tickets = [];
626
+		foreach ($orig_datetimes as $orig_dtt) {
627
+			if (! $orig_dtt instanceof EE_Datetime) {
628
+				continue;
629
+			}
630
+			$new_dtt      = clone $orig_dtt;
631
+			$orig_tickets = $orig_dtt->tickets();
632
+			// save new dtt then add to event
633
+			$new_dtt->set('DTT_ID', 0);
634
+			$new_dtt->set('DTT_sold', 0);
635
+			$new_dtt->set_reserved(0);
636
+			$new_dtt->save();
637
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
638
+			$new_event->save();
639
+			// now let's get the ticket relations setup.
640
+			foreach ((array) $orig_tickets as $orig_ticket) {
641
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
642
+				if (! $orig_ticket instanceof EE_Ticket) {
643
+					continue;
644
+				}
645
+				// is this ticket archived?  If it is then let's skip
646
+				if ($orig_ticket->get('TKT_deleted')) {
647
+					continue;
648
+				}
649
+				// does this original ticket already exist in the clone_tickets cache?
650
+				//  If so we'll just use the new ticket from it.
651
+				if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
652
+					$new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
653
+				} else {
654
+					$new_ticket = clone $orig_ticket;
655
+					// get relations on the $orig_ticket that we need to setup.
656
+					$orig_prices = $orig_ticket->prices();
657
+					$new_ticket->set('TKT_ID', 0);
658
+					$new_ticket->set('TKT_sold', 0);
659
+					$new_ticket->set('TKT_reserved', 0);
660
+					$new_ticket->save(); // make sure new ticket has ID.
661
+					// price relations on new ticket need to be setup.
662
+					foreach ($orig_prices as $orig_price) {
663
+						$new_price = clone $orig_price;
664
+						$new_price->set('PRC_ID', 0);
665
+						$new_price->save();
666
+						$new_ticket->_add_relation_to($new_price, 'Price');
667
+						$new_ticket->save();
668
+					}
669
+
670
+					do_action(
671
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
672
+						$orig_ticket,
673
+						$new_ticket,
674
+						$orig_prices,
675
+						$orig_event,
676
+						$orig_dtt,
677
+						$new_dtt
678
+					);
679
+				}
680
+				// k now we can add the new ticket as a relation to the new datetime
681
+				// and make sure its added to our cached $cloned_tickets array
682
+				// for use with later datetimes that have the same ticket.
683
+				$new_dtt->_add_relation_to($new_ticket, 'Ticket');
684
+				$new_dtt->save();
685
+				$cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
686
+			}
687
+		}
688
+		// clone taxonomy information
689
+		$taxonomies_to_clone_with = apply_filters(
690
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
691
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
692
+		);
693
+		// get terms for original event (notice)
694
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
695
+		// loop through terms and add them to new event.
696
+		foreach ($orig_terms as $term) {
697
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
698
+		}
699
+
700
+		// duplicate other core WP_Post items for this event.
701
+		// post thumbnail (feature image).
702
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
703
+		if ($feature_image_id) {
704
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
705
+		}
706
+
707
+		// duplicate page_template setting
708
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
709
+		if ($page_template) {
710
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
711
+		}
712
+
713
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
714
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
715
+		if ($new_event->ID()) {
716
+			$redirect_args = [
717
+				'post'   => $new_event->ID(),
718
+				'action' => 'edit',
719
+			];
720
+			EE_Error::add_success(
721
+				esc_html__(
722
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
723
+					'event_espresso'
724
+				)
725
+			);
726
+		} else {
727
+			$redirect_args = [
728
+				'action' => 'default',
729
+			];
730
+			EE_Error::add_error(
731
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
732
+				__FILE__,
733
+				__FUNCTION__,
734
+				__LINE__
735
+			);
736
+		}
737
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
738
+	}
739
+
740
+
741
+	/**
742
+	 * Generates output for the import page.
743
+	 *
744
+	 * @throws EE_Error
745
+	 */
746
+	protected function _import_page()
747
+	{
748
+		$title                                      = esc_html__('Import', 'event_espresso');
749
+		$intro                                      = esc_html__(
750
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
751
+			'event_espresso'
752
+		);
753
+
754
+		$form_url = EVENTS_ADMIN_URL;
755
+		$action   = 'import_events';
756
+		$type     = 'csv';
757
+
758
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
759
+			$title,
760
+			$intro,
761
+			$form_url,
762
+			$action,
763
+			$type
764
+		);
765
+
766
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
767
+			['action' => 'sample_export_file'],
768
+			$this->_admin_base_url
769
+		);
770
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
771
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
772
+			$this->_template_args,
773
+			true
774
+		);
775
+		$this->display_admin_page_with_sidebar();
776
+	}
777
+
778
+
779
+	/**
780
+	 * _import_events
781
+	 * This handles displaying the screen and running imports for importing events.
782
+	 *
783
+	 * @return void
784
+	 * @throws EE_Error
785
+	 */
786
+	protected function _import_events()
787
+	{
788
+		require_once(EE_CLASSES . 'EE_Import.class.php');
789
+		$success = EE_Import::instance()->import();
790
+		$this->_redirect_after_action(
791
+			$success,
792
+			esc_html__('Import File', 'event_espresso'),
793
+			'ran',
794
+			['action' => 'import_page'],
795
+			true
796
+		);
797
+	}
798
+
799
+
800
+	/**
801
+	 * _events_export
802
+	 * Will export all (or just the given event) to a Excel compatible file.
803
+	 *
804
+	 * @access protected
805
+	 * @return void
806
+	 */
807
+	protected function _events_export()
808
+	{
809
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
810
+		$EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
811
+		$this->request->mergeRequestParams(
812
+			[
813
+				'export' => 'report',
814
+				'action' => 'all_event_data',
815
+				'EVT_ID' => $EVT_ID,
816
+			]
817
+		);
818
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
819
+			require_once(EE_CLASSES . 'EE_Export.class.php');
820
+			$EE_Export = EE_Export::instance($this->request->requestParams());
821
+			$EE_Export->export();
822
+		}
823
+	}
824
+
825
+
826
+	/**
827
+	 * handle category exports()
828
+	 *
829
+	 * @return void
830
+	 */
831
+	protected function _categories_export()
832
+	{
833
+		$EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
834
+		$this->request->mergeRequestParams(
835
+			[
836
+				'export' => 'report',
837
+				'action' => 'categories',
838
+				'EVT_ID' => $EVT_ID,
839
+			]
840
+		);
841
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
842
+			require_once(EE_CLASSES . 'EE_Export.class.php');
843
+			$EE_Export = EE_Export::instance($this->request->requestParams());
844
+			$EE_Export->export();
845
+		}
846
+	}
847
+
848
+
849
+	/**
850
+	 * Creates a sample CSV file for importing
851
+	 */
852
+	protected function _sample_export_file()
853
+	{
854
+		$EE_Export = EE_Export::instance();
855
+		if ($EE_Export instanceof EE_Export) {
856
+			$EE_Export->export();
857
+		}
858
+	}
859
+
860
+
861
+	/*************        Template Settings        *************/
862
+	/**
863
+	 * Generates template settings page output
864
+	 *
865
+	 * @throws DomainException
866
+	 * @throws EE_Error
867
+	 * @throws InvalidArgumentException
868
+	 * @throws InvalidDataTypeException
869
+	 * @throws InvalidInterfaceException
870
+	 */
871
+	protected function _template_settings()
872
+	{
873
+		$this->_template_args['values'] = $this->_yes_no_values;
874
+		/**
875
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
876
+		 * from General_Settings_Admin_Page to here.
877
+		 */
878
+		$this->_template_args = apply_filters(
879
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
880
+			$this->_template_args
881
+		);
882
+		$this->_set_add_edit_form_tags('update_template_settings');
883
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
884
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
885
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
886
+			$this->_template_args,
887
+			true
888
+		);
889
+		$this->display_admin_page_with_sidebar();
890
+	}
891
+
892
+
893
+	/**
894
+	 * Handler for updating template settings.
895
+	 *
896
+	 * @throws EE_Error
897
+	 */
898
+	protected function _update_template_settings()
899
+	{
900
+		/**
901
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
902
+		 * from General_Settings_Admin_Page to here.
903
+		 */
904
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
905
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
906
+			EE_Registry::instance()->CFG->template_settings,
907
+			$this->request->requestParams()
908
+		);
909
+		// update custom post type slugs and detect if we need to flush rewrite rules
910
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
911
+
912
+		$event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
913
+
914
+		EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
915
+			? EEH_URL::slugify($event_cpt_slug, 'events')
916
+			: EE_Registry::instance()->CFG->core->event_cpt_slug;
917
+
918
+		$what    = esc_html__('Template Settings', 'event_espresso');
919
+		$success = $this->_update_espresso_configuration(
920
+			$what,
921
+			EE_Registry::instance()->CFG->template_settings,
922
+			__FILE__,
923
+			__FUNCTION__,
924
+			__LINE__
925
+		);
926
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
927
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
928
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
929
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
930
+			);
931
+			$rewrite_rules->flush();
932
+		}
933
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
934
+	}
935
+
936
+
937
+	/**
938
+	 * _premium_event_editor_meta_boxes
939
+	 * add all metaboxes related to the event_editor
940
+	 *
941
+	 * @access protected
942
+	 * @return void
943
+	 * @throws EE_Error
944
+	 * @throws ReflectionException
945
+	 */
946
+	protected function _premium_event_editor_meta_boxes()
947
+	{
948
+		$this->verify_cpt_object();
949
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
950
+		if (
951
+			! $this->admin_config->useAdvancedEditor()
952
+			|| ! $this->feature->allowed('use_reg_options_meta_box')
953
+		) {
954
+			add_meta_box(
955
+				'espresso_event_editor_event_options',
956
+				esc_html__('Event Registration Options', 'event_espresso'),
957
+				[$this, 'registration_options_meta_box'],
958
+				$this->page_slug,
959
+				'side',
960
+				'core'
961
+			);
962
+		}
963
+	}
964
+
965
+
966
+	/**
967
+	 * override caf metabox
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	public function registration_options_meta_box()
974
+	{
975
+		$yes_no_values = [
976
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
977
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
978
+		];
979
+
980
+		$default_reg_status_values = EEM_Registration::reg_status_array(
981
+			[
982
+				EEM_Registration::status_id_cancelled,
983
+				EEM_Registration::status_id_declined,
984
+				EEM_Registration::status_id_incomplete,
985
+				EEM_Registration::status_id_wait_list,
986
+			],
987
+			true
988
+		);
989
+
990
+		$template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
991
+		$template_args['_event']           = $this->_cpt_model_obj;
992
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
993
+
994
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
995
+			'default_reg_status',
996
+			$default_reg_status_values,
997
+			$this->_cpt_model_obj->default_registration_status()
998
+		);
999
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1000
+			'display_desc',
1001
+			$yes_no_values,
1002
+			$this->_cpt_model_obj->display_description()
1003
+		);
1004
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1005
+			'display_ticket_selector',
1006
+			$yes_no_values,
1007
+			$this->_cpt_model_obj->display_ticket_selector(),
1008
+			'',
1009
+			'',
1010
+			false
1011
+		);
1012
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1013
+			'EVT_default_registration_status',
1014
+			$default_reg_status_values,
1015
+			$this->_cpt_model_obj->default_registration_status()
1016
+		);
1017
+		$template_args['additional_registration_options'] = apply_filters(
1018
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1019
+			'',
1020
+			$template_args,
1021
+			$yes_no_values,
1022
+			$default_reg_status_values
1023
+		);
1024
+		EEH_Template::display_template(
1025
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1026
+			$template_args
1027
+		);
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 * wp_list_table_mods for caf
1034
+	 * ============================
1035
+	 */
1036
+	/**
1037
+	 * hook into list table filters and provide filters for caffeinated list table
1038
+	 *
1039
+	 * @param array $old_filters    any existing filters present
1040
+	 * @param array $list_table_obj the list table object
1041
+	 * @return array                  new filters
1042
+	 * @throws EE_Error
1043
+	 * @throws ReflectionException
1044
+	 */
1045
+	public function list_table_filters($old_filters, $list_table_obj)
1046
+	{
1047
+		$filters = [];
1048
+		// first month/year filters
1049
+		$filters[] = $this->espresso_event_months_dropdown();
1050
+		$status    = $this->request->getRequestParam('status');
1051
+		// active status dropdown
1052
+		if ($status !== 'draft') {
1053
+			$filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1054
+			$filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1055
+		}
1056
+		// category filter
1057
+		$filters[] = $this->category_dropdown();
1058
+		return array_merge($old_filters, $filters);
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * espresso_event_months_dropdown
1064
+	 *
1065
+	 * @access public
1066
+	 * @return string                dropdown listing month/year selections for events.
1067
+	 * @throws EE_Error
1068
+	 */
1069
+	public function espresso_event_months_dropdown()
1070
+	{
1071
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1072
+		// Note we need to include any other filters that are set!
1073
+		return EEH_Form_Fields::generate_event_months_dropdown(
1074
+			$this->request->getRequestParam('month_range'),
1075
+			$this->request->getRequestParam('status'),
1076
+			$this->request->getRequestParam('EVT_CAT', 0, 'int'),
1077
+			$this->request->getRequestParam('active_status')
1078
+		);
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * returns a list of "active" statuses on the event
1084
+	 *
1085
+	 * @param string $current_value whatever the current active status is
1086
+	 * @return string
1087
+	 */
1088
+	public function active_status_dropdown($current_value = '')
1089
+	{
1090
+		$select_name = 'active_status';
1091
+		$values      = [
1092
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1093
+			'active'   => esc_html__('Active', 'event_espresso'),
1094
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1095
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1096
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1097
+		];
1098
+
1099
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * returns a list of "venues"
1105
+	 *
1106
+	 * @param string $current_value whatever the current active status is
1107
+	 * @return string
1108
+	 * @throws EE_Error
1109
+	 * @throws ReflectionException
1110
+	 */
1111
+	protected function venuesDropdown($current_value = '')
1112
+	{
1113
+		$values = ['' => esc_html__('All Venues', 'event_espresso')];
1114
+		// populate the list of venues.
1115
+		$venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1116
+
1117
+		foreach ($venues as $venue) {
1118
+			$values[ $venue->ID() ] = $venue->name();
1119
+		}
1120
+
1121
+		return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1122
+	}
1123
+
1124
+
1125
+	/**
1126
+	 * output a dropdown of the categories for the category filter on the event admin list table
1127
+	 *
1128
+	 * @access  public
1129
+	 * @return string html
1130
+	 * @throws EE_Error
1131
+	 * @throws ReflectionException
1132
+	 */
1133
+	public function category_dropdown()
1134
+	{
1135
+		return EEH_Form_Fields::generate_event_category_dropdown(
1136
+			$this->request->getRequestParam('EVT_CAT', -1, 'int')
1137
+		);
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * get total number of events today
1143
+	 *
1144
+	 * @access public
1145
+	 * @return int
1146
+	 * @throws EE_Error
1147
+	 * @throws InvalidArgumentException
1148
+	 * @throws InvalidDataTypeException
1149
+	 * @throws InvalidInterfaceException
1150
+	 */
1151
+	public function total_events_today()
1152
+	{
1153
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1154
+			'DTT_EVT_start',
1155
+			date('Y-m-d') . ' 00:00:00',
1156
+			'Y-m-d H:i:s',
1157
+			'UTC'
1158
+		);
1159
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1160
+			'DTT_EVT_start',
1161
+			date('Y-m-d') . ' 23:59:59',
1162
+			'Y-m-d H:i:s',
1163
+			'UTC'
1164
+		);
1165
+		$where = [
1166
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1167
+		];
1168
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1169
+	}
1170
+
1171
+
1172
+	/**
1173
+	 * get total number of events this month
1174
+	 *
1175
+	 * @access public
1176
+	 * @return int
1177
+	 * @throws EE_Error
1178
+	 * @throws InvalidArgumentException
1179
+	 * @throws InvalidDataTypeException
1180
+	 * @throws InvalidInterfaceException
1181
+	 */
1182
+	public function total_events_this_month()
1183
+	{
1184
+		// Dates
1185
+		$this_year_r     = date('Y');
1186
+		$this_month_r    = date('m');
1187
+		$days_this_month = date('t');
1188
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1189
+			'DTT_EVT_start',
1190
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1191
+			'Y-m-d H:i:s',
1192
+			'UTC'
1193
+		);
1194
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1195
+			'DTT_EVT_start',
1196
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1197
+			'Y-m-d H:i:s',
1198
+			'UTC'
1199
+		);
1200
+		$where           = [
1201
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1202
+		];
1203
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1204
+	}
1205
+
1206
+
1207
+	/** DEFAULT TICKETS STUFF **/
1208
+
1209
+	/**
1210
+	 * Output default tickets list table view.
1211
+	 *
1212
+	 * @throws EE_Error
1213
+	 */
1214
+	public function _tickets_overview_list_table()
1215
+	{
1216
+		if (
1217
+			$this->admin_config->useAdvancedEditor()
1218
+			&& $this->feature->allowed('use_default_ticket_manager')
1219
+		) {
1220
+			// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1221
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1222
+				EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1223
+				[],
1224
+				true
1225
+			);
1226
+			$this->display_admin_page_with_no_sidebar();
1227
+		} else {
1228
+			$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1229
+			$this->display_admin_list_table_page_with_no_sidebar();
1230
+		}
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * @param int  $per_page
1236
+	 * @param bool $count
1237
+	 * @param bool $trashed
1238
+	 * @return EE_Soft_Delete_Base_Class[]|int
1239
+	 * @throws EE_Error
1240
+	 */
1241
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1242
+	{
1243
+		$orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1244
+		$order   = $this->request->getRequestParam('order', 'ASC');
1245
+		switch ($orderby) {
1246
+			case 'TKT_name':
1247
+				$orderby = ['TKT_name' => $order];
1248
+				break;
1249
+			case 'TKT_price':
1250
+				$orderby = ['TKT_price' => $order];
1251
+				break;
1252
+			case 'TKT_uses':
1253
+				$orderby = ['TKT_uses' => $order];
1254
+				break;
1255
+			case 'TKT_min':
1256
+				$orderby = ['TKT_min' => $order];
1257
+				break;
1258
+			case 'TKT_max':
1259
+				$orderby = ['TKT_max' => $order];
1260
+				break;
1261
+			case 'TKT_qty':
1262
+				$orderby = ['TKT_qty' => $order];
1263
+				break;
1264
+		}
1265
+
1266
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1267
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1268
+		$offset       = ($current_page - 1) * $per_page;
1269
+
1270
+		$where = [
1271
+			'TKT_is_default' => 1,
1272
+			'TKT_deleted'    => $trashed,
1273
+		];
1274
+
1275
+		$search_term = $this->request->getRequestParam('s');
1276
+		if ($search_term) {
1277
+			$search_term = '%' . $search_term . '%';
1278
+			$where['OR'] = [
1279
+				'TKT_name'        => ['LIKE', $search_term],
1280
+				'TKT_description' => ['LIKE', $search_term],
1281
+			];
1282
+		}
1283
+
1284
+		return $count
1285
+			? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1286
+			: EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1287
+				[
1288
+					$where,
1289
+					'order_by' => $orderby,
1290
+					'limit'    => [$offset, $per_page],
1291
+					'group_by' => 'TKT_ID',
1292
+				]
1293
+			);
1294
+	}
1295
+
1296
+
1297
+	/**
1298
+	 * @param bool $trash
1299
+	 * @throws EE_Error
1300
+	 * @throws InvalidArgumentException
1301
+	 * @throws InvalidDataTypeException
1302
+	 * @throws InvalidInterfaceException
1303
+	 */
1304
+	protected function _trash_or_restore_ticket($trash = false)
1305
+	{
1306
+		$success = 1;
1307
+		$TKT     = EEM_Ticket::instance();
1308
+		// checkboxes?
1309
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1310
+		if (! empty($checkboxes)) {
1311
+			// if array has more than one element then success message should be plural
1312
+			$success = count($checkboxes) > 1 ? 2 : 1;
1313
+			// cycle thru the boxes
1314
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1315
+				if ($trash) {
1316
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1317
+						$success = 0;
1318
+					}
1319
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1320
+					$success = 0;
1321
+				}
1322
+			}
1323
+		} else {
1324
+			// grab single id and trash
1325
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1326
+			if ($trash) {
1327
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1328
+					$success = 0;
1329
+				}
1330
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1331
+				$success = 0;
1332
+			}
1333
+		}
1334
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1335
+		$query_args  = [
1336
+			'action' => 'ticket_list_table',
1337
+			'status' => $trash ? '' : 'trashed',
1338
+		];
1339
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1340
+	}
1341
+
1342
+
1343
+	/**
1344
+	 * Handles trashing default ticket.
1345
+	 *
1346
+	 * @throws EE_Error
1347
+	 * @throws ReflectionException
1348
+	 */
1349
+	protected function _delete_ticket()
1350
+	{
1351
+		$success = 1;
1352
+		// checkboxes?
1353
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1354
+		if (! empty($checkboxes)) {
1355
+			// if array has more than one element then success message should be plural
1356
+			$success = count($checkboxes) > 1 ? 2 : 1;
1357
+			// cycle thru the boxes
1358
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1359
+				// delete
1360
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1361
+					$success = 0;
1362
+				}
1363
+			}
1364
+		} else {
1365
+			// grab single id and trash
1366
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1367
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1368
+				$success = 0;
1369
+			}
1370
+		}
1371
+		$action_desc = 'deleted';
1372
+		$query_args  = [
1373
+			'action' => 'ticket_list_table',
1374
+			'status' => 'trashed',
1375
+		];
1376
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1377
+		if (
1378
+			EEM_Ticket::instance()->count_deleted_and_undeleted(
1379
+				[['TKT_is_default' => 1]],
1380
+				'TKT_ID',
1381
+				true
1382
+			)
1383
+		) {
1384
+			$query_args = [];
1385
+		}
1386
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * @param int $TKT_ID
1392
+	 * @return bool|int
1393
+	 * @throws EE_Error
1394
+	 * @throws ReflectionException
1395
+	 */
1396
+	protected function _delete_the_ticket($TKT_ID)
1397
+	{
1398
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1399
+		if (! $ticket instanceof EE_Ticket) {
1400
+			return false;
1401
+		}
1402
+		$ticket->_remove_relations('Datetime');
1403
+		// delete all related prices first
1404
+		$ticket->delete_related_permanently('Price');
1405
+		return $ticket->delete_permanently();
1406
+	}
1407 1407
 }
Please login to merge, or discard this patch.